diff --git a/README.md b/README.md index 4087c3a..982b19e 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ func main() { tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress") // check ERC20 transactions from/to a specified address - transfers, err := client.ERC20Transfers("contractAddress", "address", startBlock, endBlock, page, offset) + transfers, err := client.ERC20Transfers("contractAddress", "address","asc", startBlock, endBlock, page, offset) } ``` @@ -53,7 +53,7 @@ You may find full method list at [GoDoc](https://godoc.org/github.com/nanmu42/et You may apply for an API key on [etherscan](https://etherscan.io/apis). -> The Etherscan Ethereum Developer APIs are provided as a community service and without warranty, so please just use what you need and no more. They support both GET/POST requests and a rate limit of 5 requests/sec (exceed and you will be blocked). +> The Etherscan Ethereum Developer APIs are provided as a community service and without warranty, so please just use what you need and no more. They support both GET/POST requests and a rate limit of 5 requests/sec (exceed and you will be blocked). # Paperwork Things diff --git a/README_ZH.md b/README_ZH.md index 1e38dae..59287fa 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -45,7 +45,7 @@ func main() { tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress") // 查询出入指定地址的ERC20转账列表 - transfers, err := client.ERC20Transfers("contractAddress", "address", startBlock, endBlock, page, offset) + transfers, err := client.ERC20Transfers("contractAddress", "address","asc", startBlock, endBlock, page, offset) } ``` @@ -66,4 +66,4 @@ API的调用速率不能高于5次/秒,否则会遭到封禁。 MIT -请自由享受开源,欢迎贡献开源。 \ No newline at end of file +请自由享受开源,欢迎贡献开源。 diff --git a/account.go b/account.go index 0effe2c..f6a9a59 100644 --- a/account.go +++ b/account.go @@ -87,7 +87,7 @@ func (c *Client) InternalTxByAddress(address string, startBlock *int, endBlock * // // More information can be found at: // https://github.com/nanmu42/etherscan-api/issues/8 -func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int) (txs []ERC20Transfer, err error) { +func (c *Client) ERC20Transfers(contractAddress, address,sort *string, startBlock *int, endBlock *int, page int, offset int) (txs []ERC20Transfer, err error) { param := M{ "page": page, "offset": offset, @@ -96,6 +96,7 @@ func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *in compose(param, "address", address) compose(param, "startblock", startBlock) compose(param, "endblock", endBlock) + compose(param, "sort", sort) // asc - 升序,desc - 降序 err = c.call("account", "tokentx", param, &txs) return diff --git a/account_e2e_test.go b/account_e2e_test.go index f3272ed..6c30c58 100644 --- a/account_e2e_test.go +++ b/account_e2e_test.go @@ -77,8 +77,8 @@ func TestClient_ERC20Transfers(t *testing.T) { ) var a, b = 3273004, 3328071 - var contract, address = "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a", "0x4e83362442b8d1bec281594cea3050c8eb01311c" - txs, err := api.ERC20Transfers(&contract, &address, &a, &b, 1, 500) + var contract, address,sort = "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a", "0x4e83362442b8d1bec281594cea3050c8eb01311c","asc" + txs, err := api.ERC20Transfers(&contract, &address,&sort, &a, &b, 1, 500) noError(t, err, "api.ERC20Transfers 1") //j, _ := json.MarshalIndent(txs, "", " ") @@ -88,7 +88,7 @@ func TestClient_ERC20Transfers(t *testing.T) { t.Errorf("got txs length %v, want %v", len(txs), wantLen1) } - txs, err = api.ERC20Transfers(nil, &address, nil, &b, 1, 500) + txs, err = api.ERC20Transfers(nil, &address,&sort, nil, &b, 1, 500) noError(t, err, "api.ERC20Transfers 2") if len(txs) != wantLen2 { t.Errorf("got txs length %v, want %v", len(txs), wantLen2) @@ -99,7 +99,7 @@ func TestClient_ERC20Transfers(t *testing.T) { var specialContract = "0x5eac95ad5b287cf44e058dcf694419333b796123" var specialStartHeight = 6024142 var specialEndHeight = 6485274 - txs, err = api.ERC20Transfers(&specialContract, nil, &specialStartHeight, &specialEndHeight, 1, 500) + txs, err = api.ERC20Transfers(&specialContract, nil,&sort, &specialStartHeight, &specialEndHeight, 1, 500) noError(t, err, "api.ERC20Transfers 2") if len(txs) != wantLen3 { t.Errorf("got txs length %v, want %v", len(txs), wantLen3)