Brother even Blockchain tutorial Exchange basic development through the interface to query the currency of the coin situation-eth
Package Main
Import (
"errors""fmt""math""strconv""strings""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
}
HttpGet ASFDADSF.
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
}
Ethblockschaincheck 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 Ethblockschaincheck (Withdrawamount float64, originaladdress string, targetAddress string) (Status string, Netwithdrawamount float64, confirmations int64, err error) {
URL: = fmt. Sprintf ("https://api.etherscan.io/api?module=account&action=txlist&address=%s&startblock=0& Endblock=99999999&page=1&offset=10&sort=asc&apikey=yourapikeytoken ", 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"} Netwithdrawamoun T = IV confirmations, _ = StrConv. parseint (SC, ten, Max)} else {e = errors. New ("This is a new error")}) return
}
Func Main () {
status, netReceiveAmount, confirmations, err := EthBlocksChainCheck(10000000000000000000, "0xe026434251afc388882d82969126ec4569aa74cf", "0x7725e0bc98e61c47dceb1906be968492e8cd9080")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 to query the various currencies of the withdrawal situation-eth