Skip to content

Commit 586884d

Browse files
authored
Merge pull request nanmu42#19 from nanmu42/develop
add desc param to ERC20Transfers()
2 parents 3c11586 + e549689 commit 586884d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
language: go
22

3+
env:
4+
- GO111MODULE=on
5+
36
script:
4-
- go test -v -coverprofile=coverage.txt -covermode=count ./...
7+
- go test -v -coverprofile=coverage.txt -covermode=count ./...
58

69
after_success:
7-
- bash <(curl -s https://codecov.io/bash)
10+
- bash <(curl -s https://codecov.io/bash)

account.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *Client) InternalTxByAddress(address string, startBlock *int, endBlock *
8787
//
8888
// More information can be found at:
8989
// https://github.com/nanmu42/etherscan-api/issues/8
90-
func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int) (txs []ERC20Transfer, err error) {
90+
func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC20Transfer, err error) {
9191
param := M{
9292
"page": page,
9393
"offset": offset,
@@ -97,6 +97,12 @@ func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *in
9797
compose(param, "startblock", startBlock)
9898
compose(param, "endblock", endBlock)
9999

100+
if desc {
101+
param["sort"] = "desc"
102+
} else {
103+
param["sort"] = "asc"
104+
}
105+
100106
err = c.call("account", "tokentx", param, &txs)
101107
return
102108
}

account_e2e_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestClient_ERC20Transfers(t *testing.T) {
7878

7979
var a, b = 3273004, 3328071
8080
var contract, address = "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a", "0x4e83362442b8d1bec281594cea3050c8eb01311c"
81-
txs, err := api.ERC20Transfers(&contract, &address, &a, &b, 1, 500)
81+
txs, err := api.ERC20Transfers(&contract, &address, &a, &b, 1, 500, false)
8282
noError(t, err, "api.ERC20Transfers 1")
8383

8484
//j, _ := json.MarshalIndent(txs, "", " ")
@@ -88,8 +88,15 @@ func TestClient_ERC20Transfers(t *testing.T) {
8888
t.Errorf("got txs length %v, want %v", len(txs), wantLen1)
8989
}
9090

91-
txs, err = api.ERC20Transfers(nil, &address, nil, &b, 1, 500)
92-
noError(t, err, "api.ERC20Transfers 2")
91+
txs, err = api.ERC20Transfers(nil, &address, nil, &b, 1, 500, false)
92+
noError(t, err, "api.ERC20Transfers 2 asc")
93+
if len(txs) != wantLen2 {
94+
t.Errorf("got txs length %v, want %v", len(txs), wantLen2)
95+
}
96+
97+
txs, err = api.ERC20Transfers(nil, &address, nil, &b, 1, 500, true)
98+
noError(t, err, "api.ERC20Transfers 2 desc")
99+
93100
if len(txs) != wantLen2 {
94101
t.Errorf("got txs length %v, want %v", len(txs), wantLen2)
95102
}
@@ -99,7 +106,7 @@ func TestClient_ERC20Transfers(t *testing.T) {
99106
var specialContract = "0x5eac95ad5b287cf44e058dcf694419333b796123"
100107
var specialStartHeight = 6024142
101108
var specialEndHeight = 6485274
102-
txs, err = api.ERC20Transfers(&specialContract, nil, &specialStartHeight, &specialEndHeight, 1, 500)
109+
txs, err = api.ERC20Transfers(&specialContract, nil, &specialStartHeight, &specialEndHeight, 1, 500, false)
103110
noError(t, err, "api.ERC20Transfers 2")
104111
if len(txs) != wantLen3 {
105112
t.Errorf("got txs length %v, want %v", len(txs), wantLen3)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/nanmu42/etherscan-api
2+
3+
go 1.13

0 commit comments

Comments
 (0)