示例#1
0
func (this *CreateAccount) execute(isSync bool) {
	var input string

	kp, err := keypair.Random()

	if err == nil {
		keyp := kp.(*keypair.Full)
		fmt.Printf("\r\n"+this.infoStrings[this.languageIndex][CA_INFO_SECRET_SEED]+" %s\r\n", keyp.Seed())
		fmt.Printf(this.infoStrings[this.languageIndex][CA_INFO_PUBLIC_ADDR]+" %s\r\n", keyp.Address())
		fmt.Printf("\r\n" + this.infoStrings[this.languageIndex][CA_INFO_MEMO_TEXT])
		fmt.Scanf("%s\n", &input)

		if input == "s" {
			err = this.savefile("account_info.txt", keyp.Seed(), keyp.Address())
			if err == nil {
				ConsoleColor.Printf(ConsoleColor.C_YELLOW,
					"\r\n"+this.infoStrings[this.languageIndex][CA_INFO_MEMO_SAVEFILE]+"\r\n\r\n", "account_info.txt")
				// fmt.Printf("\r\n"+this.infoStrings[this.languageIndex][CA_INFO_MEMO_SAVEFILE]+"\r\n\r\n", "account_info.txt")
			} else {
				ConsoleColor.Println(ConsoleColor.C_RED,
					"\r\n", this.infoStrings[this.languageIndex][CA_INFO_MEMO_SAVEFILE_ERR], "\r\n", err, "\r\n\r\n")
				// fmt.Println("\r\n", this.infoStrings[this.languageIndex][CA_INFO_MEMO_SAVEFILE_ERR], "\r\n", err, "\r\n\r\n")
			}
		}
	} else {
		fmt.Println(err.Error())
		fmt.Scanf("%s\n", &input)
	}

	if !isSync {
		this.ASyncChan <- 0
	}
}
func (a *AccountInfoOperationQuary) PrintResult(r *publicdefine.StellarAccOperationQuary) {
	fmt.Print("\r")
	for i := 0; i < len(r.Records); i++ {
		ConsoleColor.Printf(ConsoleColor.C_GREEN,
			" %02d --------------------------------------------------------------------------------\r\n", i+1)

		ConsoleColor.Println(ConsoleColor.C_BLUE,
			r.Records[i].ToString(), "\r\n\r\n")
	}
}
func (this *AccountInfoPayment) checkSourceAddr(addr string, amount float64) *publicdefine.StellarAccInfoDef {
	ret := this.checkPublicAddrExist(addr)
	if ret == nil {
		ConsoleColor.Printf(ConsoleColor.C_RED,
			this.infoStrings[this.languageIndex][AIP_INFO_SOURCE_ACCOUNT_NOT_EXIST]+"\r\n", addr)
	} else {
		balance, _ := strconv.ParseFloat(ret.Balance, 64)
		// 每个账户至少要保留20个币
		if balance < amount || balance-amount < 20 {
			ConsoleColor.Printf(ConsoleColor.C_RED,
				this.infoStrings[this.languageIndex][AIP_INFO_CREDIT_IS_LOW]+"\r\n", addr, ret.Balance)
			// fmt.Printf(this.infoStrings[this.languageIndex][AIP_INFO_CREDIT_IS_LOW]+"\r\n", addr, ret.Balance)
		} else {
			return ret
		}

	}
	return nil
}
func (this *AccountInfoOperationQuary) execute(isSync bool) {
	addr := this.input_addr()
	if len(addr) > 0 && publicdefine.VerifyGAddress(addr) == nil {
		this.quary(addr)
	} else {
		ConsoleColor.Printf(ConsoleColor.C_RED,
			"\r\n"+this.infoStrings[this.languageIndex][AIOQ_INFO_ADDR_FORMAT_ERR]+"\r\n\r\n", addr)
	}
	if !isSync {
		this.ASyncChan <- 0
	}
}
示例#5
0
func (this *MergeAccount) checkSeed(seed, srcAddr string) bool {
	pk, err := keypair.Parse(seed)
	if err == nil {
		if pk.Address() == srcAddr {
			return true
		}
		ConsoleColor.Printf(ConsoleColor.C_RED,
			this.infoStrings[this.languageIndex][MA_INFO_SEED_AND_ADDR_IS_NOT_PAIR]+"\r\n")
		// fmt.Printf(this.infoStrings[this.languageIndex][MA_INFO_SEED_AND_ADDR_IS_NOT_PAIR] + "\r\n")
	} else {
		ConsoleColor.Println(ConsoleColor.C_RED, err)
		// fmt.Println(err)
	}
	return false
}
func (this *AccountInfoPayment) inputConfirm(addr string) string {
	fmt.Println("")
	ConsoleColor.Printf(ConsoleColor.C_YELLOW,
		this.infoStrings[this.languageIndex][AIP_INFO_DEST_ADDR_NOT_EXIST], addr)

	var input string

	_, err := fmt.Scanf("%s\n", &input)
	if err == nil {
		if strings.Trim(input, " ") == "yes" {
			return input
		}
	}
	return ""

}
func (this *AccountInfoPayment) create_account(src *publicdefine.StellarAccInfoDef,
	srcSeed, destAddr string, amount float64) bool {

	if len(this.inputConfirm(destAddr)) == 0 {
		ConsoleColor.Println(ConsoleColor.C_RED,
			this.infoStrings[this.languageIndex][AIP_INFO_PAYMENT_ABORT])
		return false
	}

	ConsoleColor.Printf(ConsoleColor.C_BLUE,
		this.infoStrings[this.languageIndex][AIP_INFO_CREATE_DEST_ADDR], destAddr)

	if amount < 20 {
		ConsoleColor.Println(ConsoleColor.C_RED,
			this.infoStrings[this.languageIndex][AIP_INFO_PAYMENT_ABORT_LESS20])
		return false
	}

	cAcc := publicdefine.StellarAccountCreateInfo{
		SrcInfo:    src,
		Amount:     amount,
		Destinaton: destAddr,
	}

	signed := cAcc.GetSigned(srcSeed)

	if len(signed) > 0 {
		data := "tx=" + url.QueryEscape(signed)

		postUrl := publicdefine.STELLAR_DEFAULT_NETWORK + publicdefine.STELLAR_NETWORK_TRANSACTIONS
		ret, err := this.httppost_form(postUrl, data)
		// ret, err := this.httppost_json(postUrl, data)
		if err == nil {
			cAcc.PutResult(ret)
			if len(cAcc.ResultHash) > 0 {
				ConsoleColor.Println(ConsoleColor.C_BLUE,
					this.infoStrings[this.languageIndex][AIP_INFO_CREATE_DEST_ADDR_SUCCESS])
				return true
			}
		}
		ConsoleColor.Println(ConsoleColor.C_RED, err)
		// fmt.Println(err)
	}
	ConsoleColor.Println(ConsoleColor.C_RED,
		this.infoStrings[this.languageIndex][AIP_INFO_CHECK_TRANSACTION_ERROR])
	return false
}
func (this *AccountInfoBase) checkAddrs(addrs []string) []string {
	ret := make([]string, 0)
	for _, itm := range addrs {
		tmp := strings.TrimFunc(itm, func(r rune) bool {
			return r == '\n' || r == '\r' || r == ' '
		})
		if publicdefine.VerifyGAddress(tmp) == nil {
			ret = append(ret, tmp)
		} else {
			ConsoleColor.Printf(ConsoleColor.C_RED, this.infoStrings[this.languageIndex][AIB_INFO_ADDR_FORMAT_ERR],
				itm)
			// fmt.Printf(this.infoStrings[this.languageIndex][AIB_INFO_ADDR_FORMAT_ERR],
			// 	itm)
		}
	}
	return ret
}
示例#9
0
func (this *MergeAccount) execute(isSync bool) {
	fmt.Println("")
	var isError bool = true
	var srcAddr, srcSeed, destAddr string
	for i := 0; i < 5; i++ {
		switch i {
		case 0:
			srcAddr = this.input_SrcAddr()
			isError = len(srcAddr) == 0
		case 1:
			srcSeed = this.input_SrcSeed()
			isError = len(srcSeed) == 0
		case 2:
			destAddr = this.input_DestAddr()
			isError = len(destAddr) == 0
		case 3:
			ConsoleColor.Printf(ConsoleColor.C_BLUE,
				this.infoStrings[this.languageIndex][MA_INFO_CONFIRM_INFOS], srcAddr, destAddr)
			// fmt.Printf(this.infoStrings[this.languageIndex][MA_INFO_CONFIRM_INFOS], srcAddr, destAddr)
			confirm := this.input_Confirm()
			if confirm != "yes" {
				i = 5
				ConsoleColor.Println(ConsoleColor.C_YELLOW,
					this.infoStrings[this.languageIndex][MA_INFO_OPERATION_BREAK])
				// fmt.Println(this.infoStrings[this.languageIndex][MA_INFO_OPERATION_BREAK])
			}
		case 4:
			this.beginMerge(srcAddr, srcSeed, destAddr)
		}

		if isError {
			ConsoleColor.Println(ConsoleColor.C_RED,
				this.infoStrings[this.languageIndex][MA_INFO_ADDR_FORMAT_ERR])
			// fmt.Println(this.infoStrings[this.languageIndex][MA_INFO_ADDR_FORMAT_ERR])
			break
		}
	}

	if !isSync {
		this.ASyncChan <- 0
	}
}
示例#10
0
func (this *MergeAccount) checkSourceAddr(addr string) *publicdefine.StellarAccInfoDef {
	reqUrl := publicdefine.STELLAR_DEFAULT_NETWORK + publicdefine.STELLAR_NETWORK_ACCOUNTS + "/" + addr
	resMap, err := publicdefine.HttpGet(reqUrl)

	if err == nil {
		ret := &publicdefine.StellarAccInfoDef{}
		ret.PutMapBody(addr, resMap)
		if ret.IsExist() {
			return ret
		} else {
			ConsoleColor.Printf(ConsoleColor.C_RED,
				this.infoStrings[this.languageIndex][MA_INFO_SOURCE_ACCOUNT_NOT_EXIST]+"\r\n", addr)
			// fmt.Printf(this.infoStrings[this.languageIndex][MA_INFO_SOURCE_ACCOUNT_NOT_EXIST]+"\r\n", addr)
		}
	} else {
		ConsoleColor.Println(ConsoleColor.C_RED, err)
		// fmt.Println(err)
	}
	return nil
}