區塊鏈教程證券交易所基礎開發通過介面查詢幣種的提幣情況-etc

來源:互聯網
上載者:User

標籤:raw   float   hub   json   block   string   type   情況   err   

兄弟連區塊鏈教程證券交易所基礎開發通過介面查詢幣種的提幣情況-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
}

// EtcBlocksChainCheck 根據提幣的數量,提幣方地址以及目標方地址來檢查提幣是否已經confirmed.
// 傳回值有兩個:提幣狀態以及已收到的提幣數量(扣除手續約)
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))
}
效果如下:

區塊鏈教程證券交易所基礎開發通過介面查詢幣種的提幣情況-etc

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.