Skip to content

Commit 092835f

Browse files
committed
Added support for fetching internal transactions by address, as well as specifying start/end block and sort order
1 parent 17380e4 commit 092835f

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

lib/init.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,37 @@ module.exports = function (apiKey, chain) {
551551
},
552552
/**
553553
* Get a list of internal transactions
554-
* @param {string} txhash - Transaction hash
554+
* @param {string} txhash - Transaction hash. If specified then address will be ignored
555+
* @param {string} address - Transaction address
556+
* @param {string} startblock - start looking here
557+
* @param {string} endblock - end looking there
558+
* @param {string} sort - Sort asc/desc
555559
* @example
556560
* var txlist = api.account.txlistinternal('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170');
557561
* @returns {Promise.<object>}
558562
*/
559-
txlistinternal(txhash) {
563+
txlistinternal(txhash, address, startblock, endblock, sort) {
560564
const module = 'account';
561565
const action = 'txlistinternal';
562566

567+
if (!startblock) {
568+
startblock = 0;
569+
}
570+
571+
if (!endblock) {
572+
endblock = 'latest';
573+
}
574+
575+
if (!sort) {
576+
sort = 'asc';
577+
}
578+
579+
if (txhash) {
580+
address = undefined;
581+
}
582+
563583
var query = querystring.stringify({
564-
module, action, txhash, apiKey
584+
module, action, txhash, address, apiKey
565585
});
566586

567587
return getRequest(query);

test/methods-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ describe('api', function() {
4040
done();
4141
});
4242
});
43-
it('txlistinternal', function(done){
43+
it('txlistinternal by hash', function(done){
4444
var api = init();
4545
var txlist = api.account.txlistinternal('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170');
4646
txlist.then(function(res){
4747
assert.ok(res);
4848
done();
4949
});
5050
});
51+
it('txlistinternal b yaddress', function(done){
52+
var api = init();
53+
var txlist = api.account.txlistinternal(null, '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
54+
txlist.then(function(res){
55+
assert.ok(res);
56+
done();
57+
});
58+
});
5159

5260
it('balance', function(done){
5361
var api = init();

test/testnet-methods-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,22 @@ describe('testnet methods', function() {
4747
done();
4848
});
4949
});
50-
xit('txlistinternal', function(done){
50+
xit('txlistinternal by hash', function(done){
5151

5252
var txlist = api.account.txlistinternal('0xf2aa030a0b889706206d262377cd45489faa2ff7dedbccda3693bf6c5370ed0c');
5353
txlist.then(function(res){
5454
assert.ok(res);
5555
done();
5656
});
5757
});
58+
xit('txlistinternal by address', function(done){
59+
60+
var txlist = api.account.txlistinternal(null,'0x3FAcfa472e86E3EDaEaa837f6BA038ac01F7F539');
61+
txlist.then(function(res){
62+
assert.ok(res);
63+
done();
64+
});
65+
});
5866

5967
it('balance', function(done){
6068

0 commit comments

Comments
 (0)