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

handshake-org / hsd / 7221071989

15 Dec 2023 10:45AM UTC coverage: 68.695% (+0.04%) from 68.654%
7221071989

push

github

nodech
Merge PR #856 from 'nodech/interactive-scan'

7544 of 12828 branches covered (0.0%)

Branch coverage included in aggregate %.

80 of 106 new or added lines in 10 files covered. (75.47%)

3 existing lines in 3 files now uncovered.

24071 of 33194 relevant lines covered (72.52%)

34072.66 hits per line

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

40.79
/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 {Client} = require('bcurl');
1✔
14

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

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

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

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

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

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

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

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

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

60
  /**
61
   * Get some info about the server (network and version).
62
   * @returns {Promise}
63
   */
64

65
  getInfo() {
66
    return this.get('/');
33✔
67
  }
68

69
  /**
70
   * Get coins that pertain to an address from the mempool or chain database.
71
   * Takes into account spent coins in the mempool.
72
   * @param {String} address
73
   * @returns {Promise}
74
   */
75

76
  getCoinsByAddress(address) {
77
    assert(typeof address === 'string');
×
78
    return this.get(`/coin/address/${address}`);
×
79
  }
80

81
  /**
82
   * Get coins that pertain to addresses from the mempool or chain database.
83
   * Takes into account spent coins in the mempool.
84
   * @param {String[]} addresses
85
   * @returns {Promise}
86
   */
87

88
  getCoinsByAddresses(addresses) {
89
    assert(Array.isArray(addresses));
1✔
90
    return this.post('/coin/address', { addresses });
1✔
91
  }
92

93
  /**
94
   * Retrieve a coin from the mempool or chain database.
95
   * Takes into account spent coins in the mempool.
96
   * @param {Hash} hash
97
   * @param {Number} index
98
   * @returns {Promise}
99
   */
100

101
  getCoin(hash, index) {
102
    assert(typeof hash === 'string');
1✔
103
    assert((index >>> 0) === index);
1✔
104
    return this.get(`/coin/${hash}/${index}`);
1✔
105
  }
106

107
  /**
108
   * Retrieve transactions pertaining to an
109
   * address from the mempool or chain database.
110
   * @param {String} address
111
   * @returns {Promise}
112
   */
113

114
  getTXByAddress(address) {
115
    assert(typeof address === 'string');
×
116
    return this.get(`/tx/address/${address}`);
×
117
  }
118

119
  /**
120
   * Retrieve transactions pertaining to
121
   * addresses from the mempool or chain database.
122
   * @param {String[]} addresses
123
   * @returns {Promise}
124
   */
125

126
  getTXByAddresses(addresses) {
127
    assert(Array.isArray(addresses));
×
128
    return this.post('/tx/address', { addresses });
×
129
  }
130

131
  /**
132
   * Retrieve a transaction from the mempool or chain database.
133
   * @param {Hash} hash
134
   * @returns {Promise}
135
   */
136

137
  getTX(hash) {
138
    assert(typeof hash === 'string');
×
139
    return this.get(`/tx/${hash}`);
×
140
  }
141

142
  /**
143
   * Retrieve a block from the chain database.
144
   * @param {Hash|Number} block
145
   * @returns {Promise}
146
   */
147

148
  getBlock(block) {
149
    assert(typeof block === 'string' || typeof block === 'number');
1✔
150
    return this.get(`/block/${block}`);
1✔
151
  }
152

153
  /**
154
   * Retrieve a block header.
155
   * @param {Hash|Number} block
156
   * @returns {Promise}
157
   */
158

159
  getBlockHeader(block) {
160
    assert(typeof block === 'string' || typeof block === 'number');
×
161
    return this.get(`/header/${block}`);
×
162
  }
163

164
  /**
165
   * Add a transaction to the mempool and broadcast it.
166
   * @param {TX} tx
167
   * @returns {Promise}
168
   */
169

170
  broadcast(tx) {
171
    assert(typeof tx === 'string');
1✔
172
    return this.post('/broadcast', { tx });
1✔
173
  }
174

175
  /**
176
   * Add a claim to the mempool and broadcast it.
177
   * @param {Claim} claim
178
   * @returns {Promise}
179
   */
180

181
  broadcastClaim(claim) {
182
    assert(typeof claim === 'string');
×
183
    return this.post('/claim', { claim });
×
184
  }
185

186
  /**
187
   * Reset the chain.
188
   * @param {Number} height
189
   * @returns {Promise}
190
   */
191

192
  reset(height) {
193
    return this.post('/reset', { height });
×
194
  }
195

196
  /**
197
   * Watch the blockchain.
198
   * @private
199
   * @returns {Promise}
200
   */
201

202
  watchChain() {
203
    return this.call('watch chain');
35✔
204
  }
205

206
  /**
207
   * Watch the blockchain.
208
   * @private
209
   * @returns {Promise}
210
   */
211

212
  watchMempool() {
213
    return this.call('watch mempool');
35✔
214
  }
215

216
  /**
217
   * Get chain tip.
218
   * @returns {Promise}
219
   */
220

221
  getTip() {
222
    return this.call('get tip');
×
223
  }
224

225
  /**
226
   * Get chain entry.
227
   * @param {Hash} hash
228
   * @returns {Promise}
229
   */
230

231
  getEntry(block) {
232
    return this.call('get entry', block);
×
233
  }
234

235
  /**
236
   * Get hashes.
237
   * @param {Number} [start=-1]
238
   * @param {Number} [end=-1]
239
   * @returns {Promise}
240
   */
241

242
  getHashes(start, end) {
243
    return this.call('get hashes', start, end);
×
244
  }
245

246
  /**
247
   * Send a transaction. Do not wait for promise.
248
   * @param {TX} tx
249
   * @returns {Promise}
250
   */
251

252
  send(tx) {
253
    assert(Buffer.isBuffer(tx));
×
254
    return this.call('send', tx);
×
255
  }
256

257
  /**
258
   * Send a claim. Do not wait for promise.
259
   * @param {Claim} claim
260
   * @returns {Promise}
261
   */
262

263
  sendClaim(claim) {
264
    assert(Buffer.isBuffer(claim));
×
265
    return this.call('send claim', claim);
×
266
  }
267

268
  /**
269
   * Get name state.
270
   * @param {Buffer} nameHash
271
   * @returns {Promise}
272
   */
273

274
  getNameStatus(nameHash) {
275
    assert(Buffer.isBuffer(nameHash));
×
276
    return this.call('get name', nameHash);
×
277
  }
278

279
  /**
280
   * Set bloom filter.
281
   * @param {Bloom} filter
282
   * @returns {Promise}
283
   */
284

285
  setFilter(filter) {
286
    assert(Buffer.isBuffer(filter));
13✔
287
    return this.call('set filter', filter);
13✔
288
  }
289

290
  /**
291
   * Add data to filter.
292
   * @param {Buffer} data
293
   * @returns {Promise}
294
   */
295

296
  addFilter(chunks) {
297
    if (!Array.isArray(chunks))
×
298
      chunks = [chunks];
×
299

300
    return this.call('add filter', chunks);
×
301
  }
302

303
  /**
304
   * Reset filter.
305
   * @returns {Promise}
306
   */
307

308
  resetFilter() {
309
    return this.call('reset filter');
×
310
  }
311

312
  /**
313
   * Esimate smart fee.
314
   * @param {Number?} blocks
315
   * @returns {Promise}
316
   */
317

318
  estimateFee(blocks) {
319
    assert(blocks == null || typeof blocks === 'number');
×
320
    return this.call('estimate fee', blocks);
×
321
  }
322

323
  /**
324
   * Rescan for any missed transactions.
325
   * @param {Number|Hash} start - Start block.
326
   * @returns {Promise}
327
   */
328

329
  rescan(start) {
330
    if (start == null)
×
331
      start = 0;
×
332

333
    assert(typeof start === 'number' || Buffer.isBuffer(start));
×
334

335
    return this.call('rescan', start);
×
336
  }
337

338
  /**
339
   * Rescan for any missed transactions. (Interactive)
340
   * @param {Number|Hash} start - Start block.
341
   * @param {BloomFilter} [filter]
342
   * @returns {Promise}
343
   */
344

345
  rescanInteractive(start, filter = null) {
16✔
346
    if (start == null)
38!
NEW
347
      start = 0;
×
348

349
    assert(typeof start === 'number' || Buffer.isBuffer(start));
38!
350

351
    return this.call('rescan interactive', start, filter);
38✔
352
  }
353
}
354

355
/*
356
 * Expose
357
 */
358

359
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

© 2025 Coveralls, Inc