Exemple #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!")
	}

}
Exemple #2
0
func TopupECAddress() {
	//fmt.Printf("TopupECAddress - %v, %v\n", FAddressStr, ECAddressStr)
	const ecBalanceThreshold uint64 = 10

	tx, err := factom.BuyExactEC(FAddressStr, ECAddressStr, uint64(ecBalanceThreshold))
	//tx, err := factom.BuyExactEC(FaucetAddress, ECAddressStr, uint64(ecBalanceThreshold))
	if err != nil {
		panic(err)
	}

	fmt.Printf("EC 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
	}

	_, ecBalance, err := CheckFactomBalance()
	if err != nil {
		panic(err)
	}
	if uint64(ecBalance) < ecBalanceThreshold {
		panic("Balance was not increased!")
	}
}
Exemple #3
0
func CreateEntry() {
	e := CreateNewEntry()

	tx1, tx2, err := JustFactomize(e)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Created entry %v - %v, %v\n", e.GetChainID(), tx1, tx2)

	for i := 0; ; i++ {
		i = i % 3
		time.Sleep(5 * time.Second)
		ack, err := factom.FactoidACK(tx1, "")
		if err != nil {
			panic(err)
		}
		str, err := primitives.EncodeJSONString(ack)
		if err != nil {
			panic(err)
		}
		fmt.Printf("ack1 - %v", str)
		for j := 0; j < i+1; j++ {
			fmt.Printf(".")
		}
		fmt.Printf("  \r")

		if ack.Status != "DBlockConfirmed" {
			continue
		}
		fmt.Printf("ack1 - %v\n", str)

		break
	}

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

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

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

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

		break
	}

}
Exemple #4
0
		if len(tx) == 64 && err == nil {
			txID = tx
		} else {
			if len(tx) < 64 || err != nil {
				h, err := factom.TransactionHash(tx)
				if err != nil {
					errorln(err)
					return
				}
				txID = h
			} else {
				fullTx = strings.Replace(tx, "\"", "", -1)
			}
		}

		resp1, err1 := factom.FactoidACK(txID, fullTx)
		resp2, err2 := factom.EntryACK(txID, fullTx)
		if err1 != nil && err2 != nil {
			errorln(err1)
			return
		}

		if resp1 != nil {
			if resp1.Status != "Unknown" {
				str, err := json.MarshalIndent(resp1, "", "\t")
				if err != nil {
					errorln(err)
					return
				}
				fmt.Printf("%s\n", str)
				return