Skip to content

Commit 509ffe5

Browse files
committed
Merge PR #882 from 'nodech/update-clients'
2 parents 1daebd8 + 501f529 commit 509ffe5

File tree

7 files changed

+82
-18
lines changed

7 files changed

+82
-18
lines changed

.eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"env": {
3-
"es2022": true,
3+
"es2024": true,
44
"node": true
55
},
66
"extends": "eslint:recommended",
@@ -35,7 +35,7 @@
3535
}
3636
],
3737
"parserOptions": {
38-
"ecmaVersion": 13,
38+
"ecmaVersion": "latest",
3939
"ecmaFeatures": {
4040
"globalReturn": true
4141
},

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ process and allows parallel rescans.
3838
- expects ws hook for `block rescan interactive` params `rawEntry, rawTXs`
3939
that returns scanAction object.
4040
- expects ws hook for `block rescan interactive abort` param `message`.
41+
- Add `getMempoolRejectionFilter` and `checkMempoolRejectionFilter` NodeClient
42+
aliases.
43+
- Add `getFee`, an HTTP alternative to estimateFee socket call.
4144

4245
### Wallet Changes
4346
#### Configuration
@@ -58,11 +61,13 @@ process and allows parallel rescans.
5861
- `open()` no longer calls scan, instead only rollbacks and waits for
5962
sync to do the rescan.
6063
- emits events for: `open`, `close`, `connect`, `disconnect`, `sync done`.
61-
- HTTP Changes:
64+
65+
### Wallet HTTP Client
6266
- All transaction creating endpoints now accept `hardFee` for specifying the
6367
exact fee.
6468
- All transaction sending endpoints now fundlock/queue tx creation. (no more
6569
conflicting transactions)
70+
- Add options to `getNames` for passing `own`.
6671

6772
## v6.0.0
6873

lib/client/node.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ class NodeClient extends Client {
5757
return this.get('/mempool');
5858
}
5959

60+
/**
61+
* Get a mempool rejection filter.
62+
* @param {Object} options
63+
* @returns {Promise}
64+
*/
65+
66+
getMempoolRejectionFilter(options) {
67+
return this.get('/mempool/invalid', options);
68+
}
69+
70+
/**
71+
* Check against mempool rejection filter.
72+
* @param {Hash} hash - transaction hash
73+
* @returns {Promise}
74+
*/
75+
76+
checkMempoolRejectionFilter(hash) {
77+
return this.get(`/mempool/invalid/${hash}`);
78+
}
79+
6080
/**
6181
* Get some info about the server (network and version).
6282
* @returns {Promise}
@@ -183,6 +203,17 @@ class NodeClient extends Client {
183203
return this.post('/claim', { claim });
184204
}
185205

206+
/**
207+
* Estimate smart fee. Same as estimateFee, but
208+
* an HTTP call instead of websocket call.
209+
* @param {Number} blocks
210+
* @returns {Promise}
211+
*/
212+
213+
getSmartFee(blocks) {
214+
return this.get('/fee', { blocks });
215+
}
216+
186217
/**
187218
* Reset the chain.
188219
* @param {Number} height

lib/client/wallet.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class WalletClient extends Client {
118118

119119
/**
120120
* Create a wallet object.
121+
* @param {String} id
122+
* @param {String} [token]
123+
* @returns {Wallet}
121124
*/
122125

123126
wallet(id, token) {
@@ -339,11 +342,13 @@ class WalletClient extends Client {
339342
* that the wallet is managing.
340343
* {@see hsd.NameState}
341344
* @param {String} id
345+
* @param {Object} options
346+
* @param {Boolean} [optoins.own=false]
342347
* @returns {Promise}
343348
*/
344349

345-
getNames(id) {
346-
return this.get(`/wallet/${id}/name`);
350+
getNames(id, options) {
351+
return this.get(`/wallet/${id}/name`, options);
347352
}
348353

349354
/**
@@ -893,6 +898,18 @@ class WalletClient extends Client {
893898
*/
894899

895900
class Wallet extends EventEmitter {
901+
/** @type {WalletClient} */
902+
client;
903+
904+
/** @type {WalletClient} */
905+
parent;
906+
907+
/** @type {String} */
908+
id;
909+
910+
/** @type {String} */
911+
token;
912+
896913
/**
897914
* Create a wallet client.
898915
* @param {Object?} options
@@ -1051,11 +1068,13 @@ class Wallet extends EventEmitter {
10511068
* Get name state for all names
10521069
* that the wallet is managing.
10531070
* {@see hsd.NameState}
1071+
* @param {Object} options
1072+
* @param {Boolean} [optoins.own=false]
10541073
* @returns {Promise}
10551074
*/
10561075

1057-
getNames() {
1058-
return this.client.getNames(this.id);
1076+
getNames(options) {
1077+
return this.client.getNames(this.id, options);
10591078
}
10601079

10611080
/**

test/node-http-test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ describe('Node HTTP', function() {
3939
});
4040

4141
it('should get mempool rejection filter', async () => {
42-
const filterInfo = await nclient.get('/mempool/invalid', { verbose: true });
42+
const filterInfo = await nclient.getMempoolRejectionFilter({
43+
verbose: true
44+
});
4345

4446
assert.ok('items' in filterInfo);
4547
assert.ok('filter' in filterInfo);
@@ -59,10 +61,10 @@ describe('Node HTTP', function() {
5961
const raw = mtx.toHex();
6062
const txid = await nclient.execute('sendrawtransaction', [raw]);
6163

62-
const json = await nclient.get(`/mempool/invalid/${txid}`);
64+
const json = await nclient.checkMempoolRejectionFilter(txid);
6365
assert.equal(json.invalid, true);
6466

65-
const filterInfo = await nclient.get('/mempool/invalid');
67+
const filterInfo = await nclient.getMempoolRejectionFilter();
6668
assert.equal(filterInfo.entries, 1);
6769
});
6870
});
@@ -90,7 +92,7 @@ describe('Node HTTP', function() {
9092

9193
// fetch corresponding header and block
9294
const height = 7;
93-
const header = await nclient.get(`/header/${height}`);
95+
const header = await nclient.getBlockHeader(height);
9496
assert.equal(header.height, height);
9597

9698
const properties = [
@@ -116,7 +118,7 @@ describe('Node HTTP', function() {
116118

117119
it('should fetch null for block header that does not exist', async () => {
118120
// many blocks in the future
119-
const header = await nclient.get(`/header/${40000}`);
121+
const header = await nclient.getBlockHeader(40000);
120122
assert.equal(header, null);
121123
});
122124

@@ -130,7 +132,7 @@ describe('Node HTTP', function() {
130132
let prevBlock = '0000000000000000000000000000000000000000000000000000000000000000';
131133

132134
for (let i = 0; i < 10; i++) {
133-
const header = await nclient.get(`/header/${i}`);
135+
const header = await nclient.getBlockHeader(i);
134136

135137
assert.equal(prevBlock, header.prevBlock);
136138
prevBlock = header.hash;
@@ -140,8 +142,8 @@ describe('Node HTTP', function() {
140142
it('should fetch block header by hash', async () => {
141143
const info = await nclient.getInfo();
142144

143-
const headerByHash = await nclient.get(`/header/${info.chain.tip}`);
144-
const headerByHeight = await nclient.get(`/header/${info.chain.height}`);
145+
const headerByHash = await nclient.getBlockHeader(info.chain.tip);
146+
const headerByHeight = await nclient.getBlockHeader(info.chain.height);
145147

146148
assert.deepEqual(headerByHash, headerByHeight);
147149
});

test/util/node-context.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ const {NodeClient, WalletClient} = require('../../lib/client');
1111
const Logger = require('blgr');
1212

1313
class NodeContext {
14+
/** @type {FullNode|SPVNode} */
15+
node;
16+
17+
/** @type {WalletClient} */
18+
wclient;
19+
20+
/** @type {NodeClient} */
21+
nclient;
22+
1423
constructor(options = {}) {
1524
this.name = 'node-test';
1625
this.options = {};

test/wallet-http-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,9 +1787,7 @@ describe('Wallet HTTP', function() {
17871787
});
17881788

17891789
it('should only get wallet-owned names', async () => {
1790-
// TODO: convert to using hs-client method
1791-
// when wallet.getNames() allows `options`
1792-
const names = await wallet.client.get(`/wallet/${wallet.id}/name`, {own: true});
1790+
const names = await wallet.getNames({ own: true });
17931791

17941792
assert.equal(names.length, ownedNames.length);
17951793

0 commit comments

Comments
 (0)