Brother even Blockchain tutorial Exchange basic development through the interface query the currency of the withdrawal situation-ETC
Package Main
Import (
"FMT"
"github.com/buger/jsonparser""github.com/levigross/grequests"
)
HttpGet.
Func httpget (URL string, Requestoptions *grequests. requestoptions) (response []byte, err Error) {
HttpResponse, err: = Grequests. Get (URL, requestoptions)
If Err = = Nil {
if Httpresponse.statuscode = = 200 {
Response = Httpresponse.bytes ()
}
}
Return
}
The
//Etcblockschaincheck checks whether the coin has been confirmed based on the number of coins, the address of the sender and the destination. The
//return value has two: the status of the coin and the number of coins received (minus the handling fee)
Func etcblockschaincheck (withrawamount float64, originaladdress string, TargetAddress string) (status string, Netwithdrawamount float64, confirmations int64, err error) {
Status = "Online"
targeturl: = Fmt. Sprintf ("Https://etcchain.com/api/v1/getTransactionsByAddress?address=%s&sort=asc", targetAddress)
Bdata , Err: = HttpGet (TargetUrl, nil)
If err! = Nil {
FMT. Println ("Error:httpget TargetUrl failed.")
Return
}
//FMT. Println (String (bdata))
_, err = jsonparser.ArrayEach(bData, func(value []byte, dataType jsonparser.ValueType, offset int, e error) { _from, _, _, e := jsonparser.Get(value, "from") _to, _, _, e := jsonparser.Get(value, "to") _value, _, _, e := jsonparser.Get(value, "valueEther") _confirmations, _, _, e := jsonparser.Get(value, "confirmations") _fees, _, _, e := jsonparser.Get(value, "feeEther") from := string(_from) to := string(_to) v, e := jsonparser.GetFloat(_value) fees, e := jsonparser.GetFloat(_fees) if from == originalAddress && to == targetAddress && v == withrawAmount { fmt.Println("fees: ", fees) status = "comfirmed" netWithdrawAmount = v confirmations, e = jsonparser.GetInt(_confirmations) //fmt.Println(status) return }})return
}
Func Main () {
Status, Netreceiveamount, confirmations, err: = Etcblockschaincheck (0.931847144, " 0x6b83f808fce08f51adb2e9e35a21a601e702785f "," 0x4f0d74ecdceb209213ecc0cce6366c3bef1fce57 ")
If err! = Nil {
Fmt. PRINTLN ("Request failed ...")
Return
}
Fmt. Println (FMT. Sprintf ("Status:%s, Net_withdraw_amount:%f, confirmations:%d", status, Netreceiveamount, confirmations))
}
The effect is as follows:
Blockchain tutorial Exchange Basic development through the interface query the currency of the withdrawal situation-ETC