From 6fa86c779acbe873297968302e2f3d56ab1eff09 Mon Sep 17 00:00:00 2001 From: fengzie <526567244@qq.com> Date: Wed, 27 Mar 2024 10:11:47 +0800 Subject: [PATCH 1/2] Update for Conflux scan --- account.go | 8 ++++++++ client.go | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/account.go b/account.go index e6a9ac1..002a6a9 100644 --- a/account.go +++ b/account.go @@ -13,6 +13,10 @@ func (c *Client) AccountBalance(address string) (balance *BigInt, err error) { "tag": "latest", "address": address, } + if c.isConfluxScan() { + param["tag"] = "latest_state" + } + balance = new(BigInt) err = c.call("account", "balance", param, balance) return @@ -24,6 +28,10 @@ func (c *Client) MultiAccountBalance(addresses ...string) (balances []AccountBal "tag": "latest", "address": addresses, } + if c.isConfluxScan() { + param["tag"] = "latest_state" + } + balances = make([]AccountBalance, 0, len(addresses)) err = c.call("account", "balancemulti", param, &balances) return diff --git a/client.go b/client.go index e69679a..bcf60f4 100644 --- a/client.go +++ b/client.go @@ -15,15 +15,17 @@ import ( "net/http" "net/http/httputil" "net/url" + "strings" "time" ) // Client etherscan API client // Clients are safe for concurrent use by multiple goroutines. type Client struct { - coon *http.Client - key string - baseURL string + coon *http.Client + key string + baseURL string + ChainName string // Verbose when true, talks a lot Verbose bool @@ -61,6 +63,8 @@ type Customization struct { // Set your own timeout. Client *http.Client + ChainName string + // BeforeRequest runs before every client request, in the same goroutine. // May be used in rate limit. // Request will be aborted, if BeforeRequest returns non-nil err. @@ -85,6 +89,7 @@ func NewCustomized(config Customization) *Client { coon: httpClient, key: config.Key, baseURL: config.BaseURL, + ChainName: config.ChainName, Verbose: config.Verbose, BeforeRequest: config.BeforeRequest, AfterRequest: config.AfterRequest, @@ -206,3 +211,8 @@ func (c *Client) craftURL(module, action string, param map[string]interface{}) ( URL = c.baseURL + q.Encode() return } + +// isConfluxScan returns whether conflux scan API which has some API update +func (c *Client) isConfluxScan() bool { + return strings.EqualFold(c.ChainName, "Conflux") +} From 89f433775df366f6a9dca3e43192d32a89efb659 Mon Sep 17 00:00:00 2001 From: fengzie <526567244@qq.com> Date: Sun, 31 Mar 2024 16:29:28 +0800 Subject: [PATCH 2/2] Fix issue of unmarshal --- response.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/response.go b/response.go index 5c418cf..9d531c4 100644 --- a/response.go +++ b/response.go @@ -41,14 +41,14 @@ type NormalTx struct { From string `json:"from"` To string `json:"to"` Value *BigInt `json:"value"` - Gas int `json:"gas,string"` + Gas *BigInt `json:"gas"` GasPrice *BigInt `json:"gasPrice"` IsError int `json:"isError,string"` TxReceiptStatus string `json:"txreceipt_status"` Input string `json:"input"` ContractAddress string `json:"contractAddress"` - CumulativeGasUsed int `json:"cumulativeGasUsed,string"` - GasUsed int `json:"gasUsed,string"` + CumulativeGasUsed *BigInt `json:"cumulativeGasUsed"` + GasUsed *BigInt `json:"gasUsed"` Confirmations int `json:"confirmations,string"` FunctionName string `json:"functionName"` MethodId string `json:"methodId"`