Esempio n. 1
0
func GetAddresses() []byte {
	values := Wallet.GetAddresses()

	ecKeys := make([]string, 0, len(values))
	fctKeys := make([]string, 0, len(values))
	ecBalances := make([]string, 0, len(values))
	fctBalances := make([]string, 0, len(values))
	fctAddresses := make([]string, 0, len(values))
	ecAddresses := make([]string, 0, len(values))

	var maxlen int
	for _, we := range values {
		if len(we.GetName()) > maxlen {
			maxlen = len(we.GetName())
		}
		var adr string
		if we.GetType() == "ec" {
			address, err := we.GetAddress()
			if err != nil {
				continue
			}
			adr = fct.ConvertECAddressToUserStr(address)
			ecAddresses = append(ecAddresses, adr)
			ecKeys = append(ecKeys, string(we.GetName()))
			bal, _ := ECBalance(adr)
			ecBalances = append(ecBalances, strconv.FormatInt(bal, 10))
		} else {
			address, err := we.GetAddress()
			if err != nil {
				continue
			}
			adr = fct.ConvertFctAddressToUserStr(address)
			fctAddresses = append(fctAddresses, adr)
			fctKeys = append(fctKeys, string(we.GetName()))
			bal, _ := FctBalance(adr)
			sbal := fct.ConvertDecimal(uint64(bal))
			fctBalances = append(fctBalances, sbal)
		}
	}
	var out bytes.Buffer
	if len(fctKeys) > 0 {
		out.WriteString("\n  Factoid Addresses\n\n")
	}
	fstr := fmt.Sprintf("%s%vs    %s38s %s14s\n", "%", maxlen+4, "%", "%")
	for i, key := range fctKeys {
		str := fmt.Sprintf(fstr, key, fctAddresses[i], fctBalances[i])
		out.WriteString(str)
	}
	if len(ecKeys) > 0 {
		out.WriteString("\n  Entry Credit Addresses\n\n")
	}
	for i, key := range ecKeys {
		str := fmt.Sprintf(fstr, key, ecAddresses[i], ecBalances[i])
		out.WriteString(str)
	}

	return out.Bytes()
}
Esempio n. 2
0
func GetAddresses() (*Addresses, error) {
	addresses := Wallet.GetAddresses()

	answer := new(Addresses)
	for _, we := range addresses {
		tmp := Address{}
		tmp.Type = we.GetType()
		if we.GetType() == "ec" {
			address, err := we.GetAddress()
			if err != nil {
				return nil, err
			}

			tmp.Address = factoid.ConvertECAddressToUserStr(address)
			tmp.Name = string(we.GetName())
			bal, err := Wallet.ECBalance(tmp.Address)
			if err != nil {
				return nil, err
			}
			tmp.Balance = float64(bal)
			answer.ECAddresses = append(answer.ECAddresses, tmp)
		} else {
			address, err := we.GetAddress()
			if err != nil {
				return nil, err
			}

			tmp.Address = factoid.ConvertFctAddressToUserStr(address)
			tmp.Name = string(we.GetName())
			bal, err := Wallet.FactoidBalance(tmp.Address)
			if err != nil {
				return nil, err
			}
			tmp.Balance = factoid.ConvertDecimalToFloat(uint64(bal))
			answer.FactoidAddresses = append(answer.FactoidAddresses, tmp)
		}
	}
	return answer, nil
}