• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

handshake-org / hsd / 15042451478

15 May 2025 10:16AM UTC coverage: 19.792% (-51.5%) from 71.269%
15042451478

Pull #928

github

web-flow
Merge fa1d30da4 into 5f11d622b
Pull Request #928: Wallet coinselection

1570 of 13236 branches covered (11.86%)

Branch coverage included in aggregate %.

217 of 388 new or added lines in 6 files covered. (55.93%)

17866 existing lines in 127 files now uncovered.

7855 of 34384 relevant lines covered (22.84%)

129.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.94
/lib/client/node.js
1
/*!
2
 * client.js - http client for wallets
3
 * Copyright (c) 2017, Christopher Jeffrey (MIT License).
4
 * https://github.com/bcoin-org/bcoin
5
 */
6

7
'use strict';
8

9
// NOTE: This is part of generated `hs-client`.
10
// Don't introduce any unnecessary dependencies to this.
11

12
const assert = require('bsert');
1✔
13
const bcurl = require('bcurl');
1✔
14

15
/**
16
 * Node Client
17
 * @alias module:client.NodeClient
18
 * @extends {bcurl.Client}
19
 */
20

21
class NodeClient extends bcurl.Client {
22
  /**
23
   * Creat a node client.
24
   * @param {Object?} options
25
   */
26

27
  constructor(options) {
28
    super(options);
11✔
29
  }
30

31
  /**
32
   * Auth with server.
33
   * @returns {Promise}
34
   */
35

36
  async auth() {
UNCOV
37
    await this.call('auth', this.password);
×
UNCOV
38
    await this.watchChain();
×
UNCOV
39
    await this.watchMempool();
×
40
  }
41

42
  /**
43
   * Make an RPC call.
44
   * @returns {Promise}
45
   */
46

47
  execute(name, params) {
UNCOV
48
    return super.execute('/', name, params);
×
49
  }
50

51
  /**
52
   * Get a mempool snapshot.
53
   * @returns {Promise}
54
   */
55

56
  getMempool() {
UNCOV
57
    return this.get('/mempool');
×
58
  }
59

60
  /**
61
   * Get a mempool rejection filter.
62
   * @param {Object} options
63
   * @returns {Promise}
64
   */
65

66
  getMempoolRejectionFilter(options) {
UNCOV
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) {
UNCOV
77
    return this.get(`/mempool/invalid/${hash}`);
×
78
  }
79

80
  /**
81
   * Get some info about the server (network and version).
82
   * @returns {Promise}
83
   */
84

85
  getInfo() {
UNCOV
86
    return this.get('/');
×
87
  }
88

89
  /**
90
   * Get coins that pertain to an address from the mempool or chain database.
91
   * Takes into account spent coins in the mempool.
92
   * @param {String} address
93
   * @returns {Promise}
94
   */
95

96
  getCoinsByAddress(address) {
97
    assert(typeof address === 'string');
×
98
    return this.get(`/coin/address/${address}`);
×
99
  }
100

101
  /**
102
   * Get coins that pertain to addresses from the mempool or chain database.
103
   * Takes into account spent coins in the mempool.
104
   * @param {String[]} addresses
105
   * @returns {Promise}
106
   */
107

108
  getCoinsByAddresses(addresses) {
UNCOV
109
    assert(Array.isArray(addresses));
×
UNCOV
110
    return this.post('/coin/address', { addresses });
×
111
  }
112

113
  /**
114
   * Retrieve a coin from the mempool or chain database.
115
   * Takes into account spent coins in the mempool.
116
   * @param {Hash} hash
117
   * @param {Number} index
118
   * @returns {Promise}
119
   */
120

121
  getCoin(hash, index) {
UNCOV
122
    assert(typeof hash === 'string');
×
UNCOV
123
    assert((index >>> 0) === index);
×
UNCOV
124
    return this.get(`/coin/${hash}/${index}`);
×
125
  }
126

127
  /**
128
   * Retrieve transactions pertaining to an
129
   * address from the mempool or chain database.
130
   * @param {String} address
131
   * @returns {Promise}
132
   */
133

134
  getTXByAddress(address) {
135
    assert(typeof address === 'string');
×
136
    return this.get(`/tx/address/${address}`);
×
137
  }
138

139
  /**
140
   * Retrieve transactions pertaining to
141
   * addresses from the mempool or chain database.
142
   * @param {String[]} addresses
143
   * @returns {Promise}
144
   */
145

146
  getTXByAddresses(addresses) {
147
    assert(Array.isArray(addresses));
×
148
    return this.post('/tx/address', { addresses });
×
149
  }
150

151
  /**
152
   * Retrieve a transaction from the mempool or chain database.
153
   * @param {Hash} hash
154
   * @returns {Promise}
155
   */
156

157
  getTX(hash) {
158
    assert(typeof hash === 'string');
×
159
    return this.get(`/tx/${hash}`);
×
160
  }
161

162
  /**
163
   * Retrieve a block from the chain database.
164
   * @param {Hash|Number} block
165
   * @returns {Promise}
166
   */
167

168
  getBlock(block) {
UNCOV
169
    assert(typeof block === 'string' || typeof block === 'number');
×
UNCOV
170
    return this.get(`/block/${block}`);
×
171
  }
172

173
  /**
174
   * Retrieve a block header.
175
   * @param {Hash|Number} block
176
   * @returns {Promise}
177
   */
178

179
  getBlockHeader(block) {
UNCOV
180
    assert(typeof block === 'string' || typeof block === 'number');
×
UNCOV
181
    return this.get(`/header/${block}`);
×
182
  }
183

184
  /**
185
   * Add a transaction to the mempool and broadcast it.
186
   * @param {TX} tx
187
   * @returns {Promise}
188
   */
189

190
  broadcast(tx) {
UNCOV
191
    assert(typeof tx === 'string');
×
UNCOV
192
    return this.post('/broadcast', { tx });
×
193
  }
194

195
  /**
196
   * Add a claim to the mempool and broadcast it.
197
   * @param {Claim} claim
198
   * @returns {Promise}
199
   */
200

201
  broadcastClaim(claim) {
202
    assert(typeof claim === 'string');
×
203
    return this.post('/claim', { claim });
×
204
  }
205

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

217
  /**
218
   * Reset the chain.
219
   * @param {Number} height
220
   * @returns {Promise}
221
   */
222

223
  reset(height) {
224
    return this.post('/reset', { height });
×
225
  }
226

227
  /**
228
   * Watch the blockchain.
229
   * @private
230
   * @returns {Promise}
231
   */
232

233
  watchChain() {
UNCOV
234
    return this.call('watch chain');
×
235
  }
236

237
  /**
238
   * Watch the blockchain.
239
   * @private
240
   * @returns {Promise}
241
   */
242

243
  watchMempool() {
UNCOV
244
    return this.call('watch mempool');
×
245
  }
246

247
  /**
248
   * Get chain tip.
249
   * @returns {Promise}
250
   */
251

252
  getTip() {
UNCOV
253
    return this.call('get tip');
×
254
  }
255

256
  /**
257
   * Get chain entry.
258
   * @param {Hash} blockhash
259
   * @returns {Promise<Buffer>} - {@link ChainEntry}
260
   */
261

262
  getEntry(blockhash) {
UNCOV
263
    return this.call('get entry', blockhash);
×
264
  }
265

266
  /**
267
   * Get hashes.
268
   * @param {Number} [start=-1]
269
   * @param {Number} [end=-1]
270
   * @returns {Promise<Hash[]>}
271
   */
272

273
  getHashes(start, end) {
UNCOV
274
    return this.call('get hashes', start, end);
×
275
  }
276

277
  /**
278
   * Get entries.
279
   * @param {Number} [start=-1]
280
   * @param {Number} [end=-1]
281
   * @returns {Promise<Buffer[]>} - {@link ChainEntry}
282
   */
283

284
  getEntries(start, end) {
UNCOV
285
    return this.call('get entries', start, end);
×
286
  }
287

288
  /**
289
   * Send a transaction. Do not wait for promise.
290
   * @param {TX} tx
291
   * @returns {Promise}
292
   */
293

294
  send(tx) {
UNCOV
295
    assert(Buffer.isBuffer(tx));
×
UNCOV
296
    return this.call('send', tx);
×
297
  }
298

299
  /**
300
   * Send a claim. Do not wait for promise.
301
   * @param {Claim} claim
302
   * @returns {Promise}
303
   */
304

305
  sendClaim(claim) {
306
    assert(Buffer.isBuffer(claim));
×
307
    return this.call('send claim', claim);
×
308
  }
309

310
  /**
311
   * Get name state.
312
   * @param {Buffer} nameHash
313
   * @returns {Promise}
314
   */
315

316
  getNameStatus(nameHash) {
317
    assert(Buffer.isBuffer(nameHash));
×
318
    return this.call('get name', nameHash);
×
319
  }
320

321
  /**
322
   * Set bloom filter.
323
   * @param {Bloom} filter
324
   * @returns {Promise}
325
   */
326

327
  setFilter(filter) {
UNCOV
328
    assert(Buffer.isBuffer(filter));
×
UNCOV
329
    return this.call('set filter', filter);
×
330
  }
331

332
  /**
333
   * Add data to filter.
334
   * @param {Buffer} data
335
   * @returns {Promise}
336
   */
337

338
  addFilter(chunks) {
UNCOV
339
    if (!Array.isArray(chunks))
×
UNCOV
340
      chunks = [chunks];
×
341

UNCOV
342
    return this.call('add filter', chunks);
×
343
  }
344

345
  /**
346
   * Reset filter.
347
   * @returns {Promise}
348
   */
349

350
  resetFilter() {
351
    return this.call('reset filter');
×
352
  }
353

354
  /**
355
   * Esimate smart fee.
356
   * @param {Number?} blocks
357
   * @returns {Promise}
358
   */
359

360
  estimateFee(blocks) {
UNCOV
361
    assert(blocks == null || typeof blocks === 'number');
×
UNCOV
362
    return this.call('estimate fee', blocks);
×
363
  }
364

365
  /**
366
   * Rescan for any missed transactions.
367
   * @param {Number|Hash} start - Start block.
368
   * @returns {Promise}
369
   */
370

371
  rescan(start) {
372
    if (start == null)
×
373
      start = 0;
×
374

375
    assert(typeof start === 'number' || Buffer.isBuffer(start));
×
376

377
    return this.call('rescan', start);
×
378
  }
379

380
  /**
381
   * Rescan for any missed transactions. (Interactive)
382
   * @param {Number|Hash} start - Start block.
383
   * @param {BloomFilter} [filter]
384
   * @param {Boolean} [fullLock=false]
385
   * @returns {Promise}
386
   */
387

388
  rescanInteractive(start, filter = null, fullLock = false) {
×
UNCOV
389
    if (start == null)
×
390
      start = 0;
×
391

UNCOV
392
    assert(typeof start === 'number' || Buffer.isBuffer(start));
×
393

UNCOV
394
    return this.call('rescan interactive', start, filter, fullLock);
×
395
  }
396
}
397

398
/*
399
 * Expose
400
 */
401

402
module.exports = NodeClient;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc