Brother even blockchain tutorial basic development through the interface query the currency of the withdrawal situation-dash:
Package Main
Import (
"Encoding/json"
"FMT"
"Math"
"github.com/buger/jsonparser""github.com/levigross/grequests"
)
Const MIN = 0.000000000001
Func isequal (F1, F2 float64) bool {
If F1 < F2 {
Return isequal (F2, F1)
}
return Math. Dim (F1, F2) < min
}
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
}
Dashblockschaincheck check whether the coin has been confirmed based on the number of coins, the address of the coin and the destination address.
There are two return values: The status of the coin and the number of coins received (minus the handling fee)
Func Dashblockschaincheck (Withrawamount float64, originaladdress string, targetAddress string) (Status string, Netwithdrawamount float64, confirmations int64, err error) {
TargetUrl: = Fmt. Sprintf ("Https://api.blockcypher.com/v1/dash/main/addrs/%s/full", targetAddress)
Bdata, err: = HttpGet (TargetUrl, nil)
If err! = Nil {
Fmt. Println ("Error:httpget TargetUrl failed.")
Return
}
Transactions,, , err: = Jsonparser. Get (bdata, "TXs")
If err! = Nil {
Fmt. Println ("error:transaction.")
Return
}
Fmt. Println (String (transactions))
_, Err = Jsonparser. Arrayeach (Transactions, func (Value []byte, DataType Jsonparser. ValueType, offset int, e error) {
Outs,, _, E: = Jsonparser. Get (value, "outputs")
fees,, _, E: = Jsonparser. Get (value, "fees")
confirmations,, _, E: = Jsonparser. Get (value, "confirmations")
Fees, E: = Jsonparser. GetInt (_fees)
Confirmations, E = Jsonparser. GetInt (_confirmations)
status = "online" jsonparser.ArrayEach(_outs, func(out []byte, dataType jsonparser.ValueType, offset int, e error) { _addr, _, _, e := jsonparser.Get(out, "addresses") _value, _, _, e := jsonparser.Get(out, "value") var outsAddr []string e = json.Unmarshal(_addr, &outsAddr) v, e := jsonparser.GetFloat(_value) if outsAddr[0] == targetAddress && v == withrawAmount { fmt.Println("fees: ", fees) status = "comfirmed" netWithdrawAmount = v } })})return
}
Func Main () {
Status, Netreceiveamount, confirmations, err: = Dashblockschaincheck (10000000, "Xrbttsarpggaqu3rsltryfxdmagknpzdf8", "Xnwjlmm2ygek9tcsawdkadjiguaeotxanv")
If err! = Nil {
Fmt. PRINTLN ("Request failed ...")
Return
}
Fmt. Println (FMT. Sprintf ("Status:%s, Net_withdraw_amount:%f, confirmations:%d", status, Netreceiveamount, confirmations))
}
Block chain tutorial Basic development through the interface query the currency of the withdrawal situation-dash