Skip to content

Commit 15ad4ff

Browse files
committed
feat(etherscan-api): added Paging to txlist
1 parent b3e4c8f commit 15ad4ff

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

packages/etherscan-api/Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# etherscan-api
2+

packages/etherscan-api/src/Client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Address } from './entities/Address'
3838
import { ApiKey } from './entities/Apikey'
3939
import { Clienttype } from './entities/Clienttype'
4040
import { Network } from './entities/Network'
41+
import { Paging } from './entities/Paging'
4142
import { PositiveNumber } from './entities/PositiveNumber'
4243
import { Sort } from './entities/Sort'
4344
import { Syncmode } from './entities/Syncmode'
@@ -487,10 +488,17 @@ export class Client {
487488
json,
488489
).then((response) => response.json())
489490
},
490-
txlist(address: string, startblock: string, endblock: string, sort?: string): Promise<any> {
491+
txlist(
492+
address: string,
493+
startblock: string,
494+
endblock: string,
495+
sort?: string,
496+
page?: string,
497+
offset?: string): Promise<any> {
491498
const oAddress = new Address(address)
492499
const oSort = !!sort ? new Sort(sort) : undefined
493-
const client = new ClientAccountTxlist(oAddress, startblock, endblock, oSort)
500+
const paging = !!page && !!offset ? new Paging(new PositiveNumber(page), new PositiveNumber(offset)) : undefined
501+
const client = new ClientAccountTxlist(oAddress, startblock, endblock, oSort, paging)
494502
const json = client.toJson()
495503
json.apiKey = apiKey.toString()
496504
return performRequest(

packages/integration-test-browser/test/account-test.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ describe('client', function () {
2323
throw new Error(err)
2424
})
2525
})
26-
27-
it('balance', function (done) {
26+
it('balancemulti', function (done) {
2827
this.retries(3)
2928
const client = new EtherscanClient.Client(validApiKey);
30-
const promise = client.account('balance')('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', 'latest')
29+
const promise = client.account('balancemulti')([
30+
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
31+
], 'latest')
3132
promise.then(res => {
3233
assert.ok(res)
3334
assert.ok(res.status)
@@ -37,12 +38,14 @@ describe('client', function () {
3738
throw new Error(err)
3839
})
3940
})
40-
it('balancemulti', function (done) {
41+
it('txlist', function (done) {
4142
this.retries(3)
4243
const client = new EtherscanClient.Client(validApiKey);
43-
const promise = client.account('balancemulti')([
44-
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
45-
], 'latest')
44+
const address = '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
45+
const startblock = 0
46+
const endblock = 99999999
47+
const sort = 'asc'
48+
const promise = client.account('txlist')(address, startblock, endblock, sort)
4649
promise.then(res => {
4750
assert.ok(res)
4851
assert.ok(res.status)
@@ -51,7 +54,24 @@ describe('client', function () {
5154
}).catch(err => {
5255
throw new Error(err)
5356
})
54-
})
57+
})
58+
it('txlist paged', function (done) {
59+
this.retries(3)
60+
const client = new EtherscanClient.Client(validApiKey);
61+
const address = '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
62+
const startblock = 0
63+
const endblock = 99999999
64+
const sort = 'asc'
65+
const promise = client.account('txlist')(address, startblock, endblock, sort, 1, 100)
66+
promise.then(res => {
67+
assert.ok(res)
68+
assert.ok(res.status)
69+
assert.equal(res.status, 1)
70+
done()
71+
}).catch(err => {
72+
throw new Error(err)
73+
})
74+
})
5575
})
5676

5777
describe('contract', ()=> {

0 commit comments

Comments
 (0)