Esempio n. 1
0
func TopupFAddress() {
	const fBalanceThreshold uint64 = 20000000 //0.2

	fBalance, err := factom.GetFactoidBalance(FaucetAddress)
	if err != nil {
		panic(err)
	}
	if fBalance < int64(fBalanceThreshold) {
		panic(fmt.Sprintf("Balance is too low - %v vs %v", fBalance/100000000.0, fBalanceThreshold/100000000.0))
	}

	tx, err := factom.SendFactoid(FaucetAddress, FAddressStr, fBalanceThreshold)
	if err != nil {
		panic(err)
	}

	fmt.Printf("F Topup tx - %v\n", tx)

	for i := 0; ; i++ {
		i = i % 3
		time.Sleep(5 * time.Second)
		ack, err := factom.FactoidACK(tx, "")
		if err != nil {
			panic(err)
		}

		str, err := primitives.EncodeJSONString(ack)
		if err != nil {
			panic(err)
		}
		fmt.Printf("Topup ack - %v", str)
		for j := 0; j < i+1; j++ {
			fmt.Printf(".")
		}
		fmt.Printf("  \r")

		if ack.Status != "DBlockConfirmed" {
			continue
		}

		fmt.Printf("Topup ack - %v\n", str)

		break
	}

	fBalance, _, err = CheckFactomBalance()
	if err != nil {
		panic(err)
	}
	if uint64(fBalance) < fBalanceThreshold {
		panic("Balance was not increased!")
	}

}
Esempio n. 2
0
func CheckFactomBalance() (int64, int64, error) {
	ecBalance, err := factom.GetECBalance(ECAddressStr)
	if err != nil {
		return 0, 0, err
	}

	fBalance, err := factom.GetFactoidBalance(FAddressStr)
	if err != nil {
		return 0, 0, err
	}
	return fBalance, ecBalance, nil
}
Esempio n. 3
0
	cmd.description = "If this is an EC Address, returns number of Entry Credits. If this is a Factoid Address, returns the Factoid balance."
	cmd.execFunc = func(args []string) {
		os.Args = args
		var res = flag.Bool("r", false, "resolve dns address")
		flag.Parse()
		args = flag.Args()

		if len(args) < 1 {
			fmt.Println(cmd.helpMsg)
			return
		}
		addr := args[0]

		switch factom.AddressStringType(addr) {
		case factom.FactoidPub:
			b, err := factom.GetFactoidBalance(addr)
			if err != nil {
				errorln(err)
			} else {
				fmt.Println(factoshiToFactoid(b))
			}
			return
		case factom.ECPub:
			c, err := factom.GetECBalance(addr)
			if err != nil {
				errorln(err)
			} else {
				fmt.Println(c)
			}
			return
		}