The basic development of the block chain starter Tutorial to inquire about currency withdrawal by interface BCH

Source: Internet
Author: User

The code is as follows
  
  
Package Main
  
Import (
"Encoding/json"
"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
}
  
Bchblockschaincheck 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 Bchblockschaincheck (Withdrawamount float64, originaladdress string, targetAddress string) (Status string, Netwithdrawamount float64, confirmations int64, err error) {
TargetUrl: = Fmt. Sprintf ("Https://bch-chain.api.btc.com/v3/address/%s/tx", 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) {
   Outs,, _, E: = Jsonparser. Get (value, "outputs")
   confirmations,, _, E: = Jsonparser. Get (value, "confirmations")
   fees,, _, E: = Jsonparser. Get (value, "fee")
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 outputs []string
E = json. Unmarshal (_ADDR, &outputs)
V, e: = Jsonparser. GetFloat (_value)
  
If outputs[0] = = TargetAddress && v = = Withdrawamount {
Fmt. PRINTLN ("Fees:", fees)
Status = "Confirmed"
Netwithdrawamount = V
}
})
})
Return
}
  
Func Main () {
Status, Netreceiveamount, confirmations, err: = Bchblockschaincheck (1567646685, "1JNCVNG5JAVSMPXTM3WJKUXVDV2HXZBJJW" , "15um5nfhm39xpdnnxwbey4lesmc9ce9cky")
If err! = Nil {
Fmt. PRINTLN ("Request failed ...")
Return
}
Fmt. Println (FMT. Sprintf ("Status:%s, Net_withdraw_amount:%f, confirmations:%d", status, Netreceiveamount, confirmations))
}
  

The basic development of the block chain starter Tutorial to inquire about currency withdrawal by interface BCH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.