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") +} 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"`