Skip to content

Commit 77b4ecc

Browse files
request stream
1 parent 58ca0d7 commit 77b4ecc

File tree

12 files changed

+10987
-12278
lines changed

12 files changed

+10987
-12278
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
const program = require('../lib/program');
4+
const Wallet = require('../lib/wallet');
5+
6+
program
7+
.version(require('../package.json').version)
8+
.option('--name <name>', 'REQUIRED - Wallet name')
9+
.option('--path [path]', 'optional - Custom wallet storage path')
10+
.option('--startDate [startDate]')
11+
.option('--endDate [endDate]')
12+
.parse(process.argv);
13+
14+
const main = async () => {
15+
const { name, path, startDate, endDate } = program;
16+
try {
17+
const wallet = await Wallet.loadWallet({ name, path });
18+
const txStream = wallet.listTransactions({ startDate, endDate });
19+
txStream.pipe(process.stdout);
20+
} catch (e) {
21+
console.error(e);
22+
}
23+
};
24+
25+
main();

packages/bitcore-client/lib/client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
const requestStream = require('request');
13
const request = require('request-promise-native');
24
const bitcoreLib = require('bitcore-lib');
35
const secp256k1 = require('secp256k1');
@@ -59,13 +61,23 @@ Client.prototype.getCoins = async function (params) {
5961
});
6062
};
6163

64+
Client.prototype.listTransactions = function (params) {
65+
const { payload, pubKey, startDate, endDate } = params;
66+
const url = `${this.baseUrl}/wallet/${pubKey}/transactions?startDate=${startDate}&endDate=${endDate}`;
67+
const signature = this.sign({ method: 'GET', url, payload });
68+
return requestStream.get(url, {
69+
headers: { 'x-signature': signature },
70+
json: true
71+
});
72+
};
73+
6274
Client.prototype.getFee = async function (params) {
6375
const { target } = params;
6476
const url = `${this.baseUrl}/fee/${target}`;
6577
return request.get(url, {
6678
json: true
6779
});
68-
}
80+
};
6981

7082
Client.prototype.importAddresses = async function(params) {
7183
const { payload, pubKey } = params;

packages/bitcore-client/lib/wallet.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ class Wallet {
141141
});
142142
}
143143

144+
listTransactions(params) {
145+
return this.client.listTransactions({
146+
...params,
147+
pubKey: this.xPubKey
148+
});
149+
}
150+
144151
async newTx(params) {
145152
const utxos = params.utxos || (await this.getUtxos(params));
146153
const payload = {

0 commit comments

Comments
 (0)