Brother even the blockchain starter to master tutorial Basic development through the interface query XRP coin situation

Source: Internet
Author: User

Package Mainimport ("Errors" "FMT" "Math" "StrConv" "Strings" "Github.com/buger/jsonparser" "github.com/levigross/ Grequests ") Const MIN = 0.000000000001func isequal (f1, F2 float64) bool {if F1 < F2 {return isequal (F2, F1)} return M Ath. 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 = = $ {response = Httpresponse.bytes ()}} return}// Xmrblockschaincheck according to the number of coins, the address of the coin and the destination address to check whether the coin has been confirmed.//return value of two: the status of the coin and the number of coins received (minus the handling fee) func Xrpblockschaincheck (Withdrawamount float64, originaladdress string, targetAddress string) (Status string, Netwithdrawamount float64, confirmations int64, err error) {URL: = fmt. Sprintf ("http://api.etherscan.io/api?module=account&action=txlist&address=%s&startblock=0& endblock=99999999 ", targetAddress) bdata, err: = HttpGet (URL, nil) if err! = Nil {return} transactions, _, _, Err: = Jsonparser. Get (bdata, "result") _, Err = Jsonparser. Arrayeach (Transactions, 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, "value") _txreceiptstatus, _, _, E: = Jsonparser. Get (Value, "Txreceipt_status") _gasprice, _, _, E: = Jsonparser. Get (Value, "Gasprice") _gasused, _, _, E: = Jsonparser. Get (Value, "gasused") _confirmations, _, _, E: = Jsonparser. Get (value, "confirmations") SF: = Strings. ToLower (String (_from)) ST: = Strings. ToLower (String (_to)) SV: = Strings. ToLower (String (_value)) IV, _: = StrConv. Parsefloat (SV, +) sts: = String (_txreceiptstatus) SGP: = String (_gasprice) IGP, _: = StrConv. Parsefloat (SGP) SGU: = String (_gasused) Igu, _: = StrConv. Parsefloat (SGU) SC: = string (_confirmations) If SF = = strings. ToLower (originaladdress) && st = = Strings. ToLower (targetAddress) && isequal (iv, WITHDRawamount) {//FMT. Println (SF, St, SV, IV, SGP, IGP, SGU, Igu, SC)//The number of coins completed, without deduction of the fee for the withdrawal of the currency FMT. Println ("Gas:", Igp*igu)//The actual number of coins received, minus the handling fee of the NZD FMT. Println ("Net_receive_amount:", iv) if STS = = "" | | STS = = "1" {status = "confirmed"} else {status = "online"} Netwithdrawamount = IV confirmations, _ = StrConv. parseint (SC, ten, Max)} else {e = errors. New ("This is a new error")}) Return}func Main () {status, Netreceiveamount, confirmations, err: = Xrpblockschaincheck (5 3000000000000000, "0x8a62f1bad85d968c218abf0f44156a48f4b5512c", "0xf24246e0d5399ea85dbdadcfdbc9e8f14490db58") 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:

Brother even the blockchain starter to master tutorial Basic development through the interface query XRP coin situation

Related Article

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.