@mr-zwets/bchn-api-wrapper 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +8 -0
- package/.github/workflows/ci.yaml +36 -0
- package/CLAUDE.md +70 -0
- package/README.md +121 -129
- package/dist/interfaces/interfaces.d.ts +13 -0
- package/dist/interfaces/restInterfaces/interfaces.d.ts +124 -18
- package/dist/interfaces/rpcInterfaces/blockchain.d.ts +293 -102
- package/dist/interfaces/rpcInterfaces/control.d.ts +6 -0
- package/dist/interfaces/rpcInterfaces/generating.d.ts +2 -0
- package/dist/interfaces/rpcInterfaces/mining.d.ts +9 -0
- package/dist/interfaces/rpcInterfaces/network.d.ts +18 -0
- package/dist/interfaces/rpcInterfaces/rawtransactions.d.ts +21 -0
- package/dist/interfaces/rpcInterfaces/util.d.ts +5 -0
- package/dist/interfaces/rpcInterfaces/wallet.d.ts +54 -0
- package/dist/interfaces/rpcInterfaces/zmq.d.ts +1 -0
- package/dist/restClient.d.ts +13 -1
- package/dist/restClient.js +19 -6
- package/dist/rpcClient.d.ts +7 -0
- package/dist/rpcClient.js +7 -0
- package/package.json +7 -8
- package/pnpm-lock.yaml +1279 -0
- package/src/index.ts +3 -3
- package/src/interfaces/interfaces.ts +96 -86
- package/src/interfaces/restInterfaces/interfaces.ts +235 -116
- package/src/interfaces/rpcInterfaces/blockchain.ts +932 -758
- package/src/interfaces/rpcInterfaces/control.ts +68 -62
- package/src/interfaces/rpcInterfaces/generating.ts +23 -21
- package/src/interfaces/rpcInterfaces/index.ts +13 -13
- package/src/interfaces/rpcInterfaces/mining.ts +151 -143
- package/src/interfaces/rpcInterfaces/network.ts +213 -195
- package/src/interfaces/rpcInterfaces/rawtransactions.ts +332 -314
- package/src/interfaces/rpcInterfaces/util.ts +56 -52
- package/src/interfaces/rpcInterfaces/wallet.ts +728 -674
- package/src/interfaces/rpcInterfaces/zmq.ts +12 -11
- package/src/restClient.ts +134 -119
- package/src/rpcClient.ts +100 -93
- package/src/utils/errors.ts +6 -6
- package/src/utils/utils.ts +55 -55
- package/test/restClient.test.ts +33 -31
- package/test/rpcClient.test.ts +119 -115
- package/test/setupTests.ts +56 -54
- package/test/tsconfig.json +4 -4
- package/tsconfig.json +13 -13
- package/vitest.config.ts +8 -8
- package/CHANGELOG.md +0 -7
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TokenData } from "../interfaces.js";
|
|
2
|
+
/** Marks an in-wallet transaction as abandoned (only works on unconfirmed tx). */
|
|
2
3
|
export interface AbandonTransaction {
|
|
3
4
|
method: 'abandontransaction';
|
|
4
5
|
params: [
|
|
@@ -6,11 +7,13 @@ export interface AbandonTransaction {
|
|
|
6
7
|
];
|
|
7
8
|
response: null;
|
|
8
9
|
}
|
|
10
|
+
/** Stops current wallet rescan. */
|
|
9
11
|
export interface AbortRescan {
|
|
10
12
|
method: 'abortrescan';
|
|
11
13
|
params: [];
|
|
12
14
|
response: null;
|
|
13
15
|
}
|
|
16
|
+
/** Adds a multisig address to the wallet. */
|
|
14
17
|
export interface AddMultisigAddress {
|
|
15
18
|
method: 'addmultisigaddress';
|
|
16
19
|
params: [
|
|
@@ -23,6 +26,7 @@ export interface AddMultisigAddress {
|
|
|
23
26
|
redeemScript: string;
|
|
24
27
|
};
|
|
25
28
|
}
|
|
29
|
+
/** Backs up wallet to specified file. */
|
|
26
30
|
export interface BackupWallet {
|
|
27
31
|
method: 'backupwallet';
|
|
28
32
|
params: [
|
|
@@ -30,6 +34,7 @@ export interface BackupWallet {
|
|
|
30
34
|
];
|
|
31
35
|
response: null;
|
|
32
36
|
}
|
|
37
|
+
/** Creates a new wallet. */
|
|
33
38
|
export interface CreateWallet {
|
|
34
39
|
method: 'createwallet';
|
|
35
40
|
params: [
|
|
@@ -42,6 +47,7 @@ export interface CreateWallet {
|
|
|
42
47
|
warning?: string;
|
|
43
48
|
};
|
|
44
49
|
}
|
|
50
|
+
/** Dumps all wallet keys to a file. */
|
|
45
51
|
export interface DumpWallet {
|
|
46
52
|
method: 'dumpwallet';
|
|
47
53
|
params: [
|
|
@@ -51,6 +57,7 @@ export interface DumpWallet {
|
|
|
51
57
|
filename: string;
|
|
52
58
|
};
|
|
53
59
|
}
|
|
60
|
+
/** Returns private key for an address. */
|
|
54
61
|
export interface DumpPrivKey {
|
|
55
62
|
method: 'dumpprivkey';
|
|
56
63
|
params: [
|
|
@@ -58,6 +65,7 @@ export interface DumpPrivKey {
|
|
|
58
65
|
];
|
|
59
66
|
response: string;
|
|
60
67
|
}
|
|
68
|
+
/** Encrypts wallet with passphrase (requires restart). */
|
|
61
69
|
export interface EncryptWallet {
|
|
62
70
|
method: 'encryptwallet';
|
|
63
71
|
params: [
|
|
@@ -65,6 +73,7 @@ export interface EncryptWallet {
|
|
|
65
73
|
];
|
|
66
74
|
response: string;
|
|
67
75
|
}
|
|
76
|
+
/** Returns addresses assigned to a label. */
|
|
68
77
|
export interface GetAddressesByLabel {
|
|
69
78
|
method: 'getaddressesbylabel';
|
|
70
79
|
params: [
|
|
@@ -76,6 +85,7 @@ export interface GetAddressesByLabel {
|
|
|
76
85
|
};
|
|
77
86
|
};
|
|
78
87
|
}
|
|
88
|
+
/** Returns detailed information about an address. */
|
|
79
89
|
export interface GetAddressInfo {
|
|
80
90
|
method: 'getaddressinfo';
|
|
81
91
|
params: [string];
|
|
@@ -104,6 +114,7 @@ export interface GetAddressInfo {
|
|
|
104
114
|
}[];
|
|
105
115
|
};
|
|
106
116
|
}
|
|
117
|
+
/** Returns wallet balance. */
|
|
107
118
|
export interface GetBalance {
|
|
108
119
|
method: 'getbalance';
|
|
109
120
|
params: [
|
|
@@ -113,6 +124,7 @@ export interface GetBalance {
|
|
|
113
124
|
];
|
|
114
125
|
response: number;
|
|
115
126
|
}
|
|
127
|
+
/** Generates a new address for receiving payments. */
|
|
116
128
|
export interface GetNewAddress {
|
|
117
129
|
method: 'getnewaddress';
|
|
118
130
|
params: [
|
|
@@ -120,11 +132,13 @@ export interface GetNewAddress {
|
|
|
120
132
|
];
|
|
121
133
|
response: string;
|
|
122
134
|
}
|
|
135
|
+
/** Returns a new address for receiving change. */
|
|
123
136
|
export interface GetRawChangeAddress {
|
|
124
137
|
method: 'getrawchangeaddress';
|
|
125
138
|
params: [];
|
|
126
139
|
response: string;
|
|
127
140
|
}
|
|
141
|
+
/** Returns total amount received by an address. */
|
|
128
142
|
export interface GetReceivedByAddress {
|
|
129
143
|
method: 'getreceivedbyaddress';
|
|
130
144
|
params: [
|
|
@@ -133,6 +147,7 @@ export interface GetReceivedByAddress {
|
|
|
133
147
|
];
|
|
134
148
|
response: number;
|
|
135
149
|
}
|
|
150
|
+
/** Returns total amount received by addresses with a label. */
|
|
136
151
|
export interface GetReceivedByLabel {
|
|
137
152
|
method: 'getreceivedbylabel';
|
|
138
153
|
params: [
|
|
@@ -141,6 +156,7 @@ export interface GetReceivedByLabel {
|
|
|
141
156
|
];
|
|
142
157
|
response: number;
|
|
143
158
|
}
|
|
159
|
+
/** Returns detailed information about an in-wallet transaction. */
|
|
144
160
|
export interface GetTransaction {
|
|
145
161
|
method: 'gettransaction';
|
|
146
162
|
params: [
|
|
@@ -170,11 +186,13 @@ export interface GetTransaction {
|
|
|
170
186
|
hex: string;
|
|
171
187
|
};
|
|
172
188
|
}
|
|
189
|
+
/** Returns unconfirmed balance. */
|
|
173
190
|
export interface GetUnconfirmedBalance {
|
|
174
191
|
method: 'getunconfirmedbalance';
|
|
175
192
|
params: [];
|
|
176
193
|
response: number;
|
|
177
194
|
}
|
|
195
|
+
/** Returns wallet state info. */
|
|
178
196
|
export interface GetWalletInfo {
|
|
179
197
|
method: 'getwalletinfo';
|
|
180
198
|
params: [];
|
|
@@ -195,6 +213,7 @@ export interface GetWalletInfo {
|
|
|
195
213
|
private_keys_enabled: boolean;
|
|
196
214
|
};
|
|
197
215
|
}
|
|
216
|
+
/** Imports an address or script for watching (without private key). */
|
|
198
217
|
export interface ImportAddress {
|
|
199
218
|
method: 'importaddress';
|
|
200
219
|
params: [
|
|
@@ -205,6 +224,7 @@ export interface ImportAddress {
|
|
|
205
224
|
];
|
|
206
225
|
response: number;
|
|
207
226
|
}
|
|
227
|
+
/** Imports multiple addresses/scripts/keys. */
|
|
208
228
|
export interface ImportMulti {
|
|
209
229
|
method: 'importmulti';
|
|
210
230
|
params: [
|
|
@@ -232,6 +252,7 @@ export interface ImportMulti {
|
|
|
232
252
|
};
|
|
233
253
|
}[];
|
|
234
254
|
}
|
|
255
|
+
/** Imports a private key. */
|
|
235
256
|
export interface ImportPrivKey {
|
|
236
257
|
method: 'importprivkey';
|
|
237
258
|
params: [
|
|
@@ -241,6 +262,7 @@ export interface ImportPrivKey {
|
|
|
241
262
|
];
|
|
242
263
|
response: null;
|
|
243
264
|
}
|
|
265
|
+
/** Imports funds without rescan (requires merkle proof). */
|
|
244
266
|
export interface ImportPrunedFunds {
|
|
245
267
|
method: 'importprunedfunds';
|
|
246
268
|
params: [
|
|
@@ -249,6 +271,7 @@ export interface ImportPrunedFunds {
|
|
|
249
271
|
];
|
|
250
272
|
response: null;
|
|
251
273
|
}
|
|
274
|
+
/** Imports a public key for watching. */
|
|
252
275
|
export interface ImportPubKey {
|
|
253
276
|
method: 'importpubkey';
|
|
254
277
|
params: [
|
|
@@ -258,6 +281,7 @@ export interface ImportPubKey {
|
|
|
258
281
|
];
|
|
259
282
|
response: null;
|
|
260
283
|
}
|
|
284
|
+
/** Imports keys from a wallet dump file. */
|
|
261
285
|
export interface ImportWallet {
|
|
262
286
|
method: 'importwallet';
|
|
263
287
|
params: [
|
|
@@ -265,6 +289,7 @@ export interface ImportWallet {
|
|
|
265
289
|
];
|
|
266
290
|
response: null;
|
|
267
291
|
}
|
|
292
|
+
/** Refills the keypool. */
|
|
268
293
|
export interface KeyPoolRefill {
|
|
269
294
|
method: 'keypoolrefill';
|
|
270
295
|
params: [
|
|
@@ -272,6 +297,7 @@ export interface KeyPoolRefill {
|
|
|
272
297
|
];
|
|
273
298
|
response: null;
|
|
274
299
|
}
|
|
300
|
+
/** Returns addresses grouped by common ownership. */
|
|
275
301
|
export interface ListAddressGroupings {
|
|
276
302
|
method: 'listaddressgroupings';
|
|
277
303
|
params: [];
|
|
@@ -285,6 +311,7 @@ export interface ListAddressGroupings {
|
|
|
285
311
|
][]
|
|
286
312
|
];
|
|
287
313
|
}
|
|
314
|
+
/** Returns all labels in the wallet. */
|
|
288
315
|
export interface ListLabels {
|
|
289
316
|
method: 'listlabels';
|
|
290
317
|
params: [
|
|
@@ -292,6 +319,7 @@ export interface ListLabels {
|
|
|
292
319
|
];
|
|
293
320
|
response: string[];
|
|
294
321
|
}
|
|
322
|
+
/** Returns list of locked unspent outputs. */
|
|
295
323
|
export interface ListLockUnspent {
|
|
296
324
|
method: 'listlockunspent';
|
|
297
325
|
params: [];
|
|
@@ -300,6 +328,7 @@ export interface ListLockUnspent {
|
|
|
300
328
|
vout: number;
|
|
301
329
|
}[];
|
|
302
330
|
}
|
|
331
|
+
/** Lists transactions received by address. */
|
|
303
332
|
export interface ListReceivedByAddress {
|
|
304
333
|
method: 'listreceivedbyaddress';
|
|
305
334
|
params: [
|
|
@@ -317,6 +346,7 @@ export interface ListReceivedByAddress {
|
|
|
317
346
|
txids: string[];
|
|
318
347
|
}[];
|
|
319
348
|
}
|
|
349
|
+
/** Lists transactions received by label. */
|
|
320
350
|
export interface ListReceivedByLabel {
|
|
321
351
|
method: 'listreceivedbylabel';
|
|
322
352
|
params: [
|
|
@@ -331,6 +361,7 @@ export interface ListReceivedByLabel {
|
|
|
331
361
|
label: string;
|
|
332
362
|
}[];
|
|
333
363
|
}
|
|
364
|
+
/** Wallet transaction representation. */
|
|
334
365
|
interface TransactionWallet {
|
|
335
366
|
address?: string;
|
|
336
367
|
category: 'send' | 'receive';
|
|
@@ -349,6 +380,7 @@ interface TransactionWallet {
|
|
|
349
380
|
label?: string;
|
|
350
381
|
to?: string;
|
|
351
382
|
}
|
|
383
|
+
/** Returns transactions since a block. */
|
|
352
384
|
export interface ListSinceBlock {
|
|
353
385
|
method: 'listsinceblock';
|
|
354
386
|
params: [
|
|
@@ -363,6 +395,7 @@ export interface ListSinceBlock {
|
|
|
363
395
|
lastblock: string;
|
|
364
396
|
};
|
|
365
397
|
}
|
|
398
|
+
/** Returns recent transactions for the wallet. */
|
|
366
399
|
export interface ListTransactions {
|
|
367
400
|
method: 'listtransactions';
|
|
368
401
|
params: [
|
|
@@ -373,6 +406,7 @@ export interface ListTransactions {
|
|
|
373
406
|
];
|
|
374
407
|
response: TransactionWallet[];
|
|
375
408
|
}
|
|
409
|
+
/** Returns unspent outputs in the wallet. */
|
|
376
410
|
export interface ListUnspent {
|
|
377
411
|
method: 'listunspent';
|
|
378
412
|
params: [
|
|
@@ -391,6 +425,7 @@ export interface ListUnspent {
|
|
|
391
425
|
];
|
|
392
426
|
response: ListUnspentItem[];
|
|
393
427
|
}
|
|
428
|
+
/** Single UTXO from listunspent. */
|
|
394
429
|
export interface ListUnspentItem {
|
|
395
430
|
txid: string;
|
|
396
431
|
vout: number;
|
|
@@ -405,6 +440,7 @@ export interface ListUnspentItem {
|
|
|
405
440
|
solvable: boolean;
|
|
406
441
|
safe: boolean;
|
|
407
442
|
}
|
|
443
|
+
/** Returns list of available wallets. */
|
|
408
444
|
export interface ListWalletDir {
|
|
409
445
|
method: 'listwalletdir';
|
|
410
446
|
params: [];
|
|
@@ -414,11 +450,13 @@ export interface ListWalletDir {
|
|
|
414
450
|
}[];
|
|
415
451
|
};
|
|
416
452
|
}
|
|
453
|
+
/** Returns list of loaded wallets. */
|
|
417
454
|
export interface ListWallets {
|
|
418
455
|
method: 'importaddress';
|
|
419
456
|
params: [];
|
|
420
457
|
response: string[];
|
|
421
458
|
}
|
|
459
|
+
/** Loads a wallet from file. */
|
|
422
460
|
export interface LoadWallet {
|
|
423
461
|
method: 'loadwallet';
|
|
424
462
|
params: [
|
|
@@ -429,6 +467,7 @@ export interface LoadWallet {
|
|
|
429
467
|
warning?: string;
|
|
430
468
|
};
|
|
431
469
|
}
|
|
470
|
+
/** Locks or unlocks unspent outputs. */
|
|
432
471
|
export interface LockUnspent {
|
|
433
472
|
method: 'lockunspent';
|
|
434
473
|
params: [
|
|
@@ -440,6 +479,7 @@ export interface LockUnspent {
|
|
|
440
479
|
];
|
|
441
480
|
response: boolean;
|
|
442
481
|
}
|
|
482
|
+
/** Removes imported pruned funds from wallet. */
|
|
443
483
|
export interface RemovePrunedFunds {
|
|
444
484
|
method: 'removeprunedfunds';
|
|
445
485
|
params: [
|
|
@@ -447,6 +487,7 @@ export interface RemovePrunedFunds {
|
|
|
447
487
|
];
|
|
448
488
|
response: null;
|
|
449
489
|
}
|
|
490
|
+
/** Rescans blockchain for wallet transactions. */
|
|
450
491
|
export interface RescanBlockchain {
|
|
451
492
|
method: 'rescanblockchain';
|
|
452
493
|
params: [
|
|
@@ -458,6 +499,7 @@ export interface RescanBlockchain {
|
|
|
458
499
|
stop_height: number;
|
|
459
500
|
};
|
|
460
501
|
}
|
|
502
|
+
/** Sends to multiple recipients. */
|
|
461
503
|
export interface SendMany {
|
|
462
504
|
method: 'sendmany';
|
|
463
505
|
params: [
|
|
@@ -473,6 +515,7 @@ export interface SendMany {
|
|
|
473
515
|
];
|
|
474
516
|
response: string;
|
|
475
517
|
}
|
|
518
|
+
/** Sends to a single address. */
|
|
476
519
|
export interface SendToAddress {
|
|
477
520
|
method: 'sendtoaddress';
|
|
478
521
|
params: [
|
|
@@ -486,6 +529,7 @@ export interface SendToAddress {
|
|
|
486
529
|
];
|
|
487
530
|
response: string;
|
|
488
531
|
}
|
|
532
|
+
/** Sets the HD seed for the wallet. */
|
|
489
533
|
export interface SetHdSeed {
|
|
490
534
|
method: 'sethdseed';
|
|
491
535
|
params: [
|
|
@@ -494,6 +538,7 @@ export interface SetHdSeed {
|
|
|
494
538
|
];
|
|
495
539
|
response: null;
|
|
496
540
|
}
|
|
541
|
+
/** Sets the label for an address. */
|
|
497
542
|
export interface SetLabel {
|
|
498
543
|
method: 'setlabel';
|
|
499
544
|
params: [
|
|
@@ -502,6 +547,7 @@ export interface SetLabel {
|
|
|
502
547
|
];
|
|
503
548
|
response: null;
|
|
504
549
|
}
|
|
550
|
+
/** Sets the transaction fee per kB. */
|
|
505
551
|
export interface SetTxFee {
|
|
506
552
|
method: 'settxfee';
|
|
507
553
|
params: [
|
|
@@ -509,6 +555,7 @@ export interface SetTxFee {
|
|
|
509
555
|
];
|
|
510
556
|
response: boolean;
|
|
511
557
|
}
|
|
558
|
+
/** Signs a message with an address's private key. */
|
|
512
559
|
export interface SignMessage {
|
|
513
560
|
method: 'signmessage';
|
|
514
561
|
params: [
|
|
@@ -517,6 +564,7 @@ export interface SignMessage {
|
|
|
517
564
|
];
|
|
518
565
|
response: string;
|
|
519
566
|
}
|
|
567
|
+
/** Signs a raw transaction with wallet keys. */
|
|
520
568
|
export interface SignRawTransactionWithWallet {
|
|
521
569
|
method: 'signrawtransactionwithwallet';
|
|
522
570
|
params: [
|
|
@@ -543,6 +591,7 @@ export interface SignRawTransactionWithWallet {
|
|
|
543
591
|
}[];
|
|
544
592
|
};
|
|
545
593
|
}
|
|
594
|
+
/** Unloads a wallet. */
|
|
546
595
|
export interface UnloadWallet {
|
|
547
596
|
method: 'unloadwallet';
|
|
548
597
|
params: [
|
|
@@ -550,6 +599,7 @@ export interface UnloadWallet {
|
|
|
550
599
|
];
|
|
551
600
|
response: null;
|
|
552
601
|
}
|
|
602
|
+
/** Creates and funds a PSBT. */
|
|
553
603
|
export interface WalletCreateFundedPsbt {
|
|
554
604
|
method: 'walletcreatefundedpsbt';
|
|
555
605
|
params: [
|
|
@@ -583,11 +633,13 @@ export interface WalletCreateFundedPsbt {
|
|
|
583
633
|
changepos: number;
|
|
584
634
|
};
|
|
585
635
|
}
|
|
636
|
+
/** Locks the encrypted wallet. */
|
|
586
637
|
export interface WalletLock {
|
|
587
638
|
method: 'walletlock';
|
|
588
639
|
params: [];
|
|
589
640
|
response: null;
|
|
590
641
|
}
|
|
642
|
+
/** Unlocks the wallet for a specified time. */
|
|
591
643
|
export interface WalletPassphrase {
|
|
592
644
|
method: 'walletpassphrase';
|
|
593
645
|
params: [
|
|
@@ -596,6 +648,7 @@ export interface WalletPassphrase {
|
|
|
596
648
|
];
|
|
597
649
|
response: null;
|
|
598
650
|
}
|
|
651
|
+
/** Changes the wallet passphrase. */
|
|
599
652
|
export interface WalletPassphraseChange {
|
|
600
653
|
method: 'walletpassphrasechange';
|
|
601
654
|
params: [
|
|
@@ -604,6 +657,7 @@ export interface WalletPassphraseChange {
|
|
|
604
657
|
];
|
|
605
658
|
response: null;
|
|
606
659
|
}
|
|
660
|
+
/** Processes a PSBT with wallet data. */
|
|
607
661
|
export interface WalletProcessPsbt {
|
|
608
662
|
method: 'walletprocesspsbt';
|
|
609
663
|
params: [
|
package/dist/restClient.d.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import type { RestClientConfig, formatOptions, ResponseType } from "./interfaces/interfaces.js";
|
|
2
|
-
import type { BlockInfoNoTxDetails, BlockInfoTxDetails, ChainInfo, HeaderInfo, MempoolContent, MempoolInfo, TxDetails, UtxosInfo } from "./interfaces/restInterfaces/interfaces.js";
|
|
2
|
+
import type { BlockInfoNoTxDetails, BlockInfoTxDetails, BlockInfoWithPatterns, ChainInfo, HeaderInfo, MempoolContent, MempoolInfo, TxDetails, TxDetailsWithPatterns, UtxosInfo } from "./interfaces/restInterfaces/interfaces.js";
|
|
3
|
+
/** REST client for read-only BCHN blockchain access via the REST interface. */
|
|
3
4
|
export declare class BchnRestClient {
|
|
4
5
|
private baseUrl;
|
|
5
6
|
private timeoutMs;
|
|
6
7
|
private logger;
|
|
7
8
|
constructor(config: RestClientConfig);
|
|
8
9
|
private fetchFromNode;
|
|
10
|
+
/** Returns transaction details by txid. */
|
|
9
11
|
getTransaction<TFormat extends formatOptions = 'json'>(txid: string, format?: TFormat): Promise<ResponseType<TFormat, TxDetails>>;
|
|
12
|
+
/** Returns block data. Use includeTxDetails=true for full transaction objects. */
|
|
10
13
|
getBlock<TFormat extends formatOptions = 'json'>(blockhash: string, includeTxDetails: true, format?: TFormat): Promise<TFormat extends 'json' ? BlockInfoTxDetails : string>;
|
|
11
14
|
getBlock<TFormat extends formatOptions = 'json'>(blockhash: string, includeTxDetails: false, format?: TFormat): Promise<TFormat extends 'json' ? BlockInfoNoTxDetails : string>;
|
|
15
|
+
/** Returns block headers starting from a specific block hash. */
|
|
12
16
|
getBlockHeaders<TFormat extends formatOptions = 'json'>(count: number, blockhash: string, format?: TFormat): Promise<ResponseType<TFormat, HeaderInfo>>;
|
|
17
|
+
/** Returns current chain state (network, sync progress, best block). */
|
|
13
18
|
getChainInfo(): Promise<ChainInfo>;
|
|
19
|
+
/** Queries UTXO set for specific outpoints. Outpoints format: "txid-vout". */
|
|
14
20
|
getUTXOs<TFormat extends formatOptions = 'json'>(checkmempool: boolean, outpoints: string[], format?: TFormat): Promise<ResponseType<TFormat, UtxosInfo>>;
|
|
21
|
+
/** Returns mempool statistics (size, bytes, fee rates). */
|
|
15
22
|
getMempoolInfo(): Promise<MempoolInfo>;
|
|
23
|
+
/** Returns all transactions currently in the mempool. */
|
|
16
24
|
getMempoolContents(): Promise<MempoolContent>;
|
|
25
|
+
/** Returns block with bytecode pattern data (v29.0.0+). */
|
|
26
|
+
getBlockWithPatterns(blockhash: string): Promise<BlockInfoWithPatterns>;
|
|
27
|
+
/** Returns transaction with bytecode pattern data (v29.0.0+). */
|
|
28
|
+
getTransactionWithPatterns(txid: string): Promise<TxDetailsWithPatterns>;
|
|
17
29
|
}
|
package/dist/restClient.js
CHANGED
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { validateUrl } from "./utils/utils.js";
|
|
11
|
+
/** REST client for read-only BCHN blockchain access via the REST interface. */
|
|
11
12
|
export class BchnRestClient {
|
|
12
13
|
constructor(config) {
|
|
13
14
|
var _a, _b;
|
|
@@ -52,7 +53,7 @@ export class BchnRestClient {
|
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
/** Returns transaction details by txid. */
|
|
56
57
|
getTransaction(txid_1) {
|
|
57
58
|
return __awaiter(this, arguments, void 0, function* (txid, format = 'json') {
|
|
58
59
|
return this.fetchFromNode(`tx/${txid}.${format}`, format);
|
|
@@ -65,19 +66,19 @@ export class BchnRestClient {
|
|
|
65
66
|
return this.fetchFromNode(`${path}/${blockhash}.${format}`, format);
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
/** Returns block headers starting from a specific block hash. */
|
|
69
70
|
getBlockHeaders(count_1, blockhash_1) {
|
|
70
71
|
return __awaiter(this, arguments, void 0, function* (count, blockhash, format = 'json') {
|
|
71
72
|
return this.fetchFromNode(`headers/${count}/${blockhash}.${format}`, format);
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
+
/** Returns current chain state (network, sync progress, best block). */
|
|
75
76
|
getChainInfo() {
|
|
76
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
78
|
return this.fetchFromNode('chaininfo.json', 'json');
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
+
/** Queries UTXO set for specific outpoints. Outpoints format: "txid-vout". */
|
|
81
82
|
getUTXOs(checkmempool_1, outpoints_1) {
|
|
82
83
|
return __awaiter(this, arguments, void 0, function* (checkmempool, outpoints, format = 'json') {
|
|
83
84
|
const path = (checkmempool ? 'checkmempool/' : '') + outpoints.join('/');
|
|
@@ -85,16 +86,28 @@ export class BchnRestClient {
|
|
|
85
86
|
return this.fetchFromNode(endpoint, format);
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
+
/** Returns mempool statistics (size, bytes, fee rates). */
|
|
89
90
|
getMempoolInfo() {
|
|
90
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
92
|
return this.fetchFromNode('mempool/info.json', 'json');
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
/** Returns all transactions currently in the mempool. */
|
|
95
96
|
getMempoolContents() {
|
|
96
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
98
|
return this.fetchFromNode('mempool/contents.json', 'json');
|
|
98
99
|
});
|
|
99
100
|
}
|
|
101
|
+
/** Returns block with bytecode pattern data (v29.0.0+). */
|
|
102
|
+
getBlockWithPatterns(blockhash) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
return this.fetchFromNode(`block/withpatterns/${blockhash}.json`, 'json');
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** Returns transaction with bytecode pattern data (v29.0.0+). */
|
|
108
|
+
getTransactionWithPatterns(txid) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
return this.fetchFromNode(`tx/withpatterns/${txid}.json`, 'json');
|
|
111
|
+
});
|
|
112
|
+
}
|
|
100
113
|
}
|
package/dist/rpcClient.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RpcClientConfig, RpcRequest } from "./interfaces/interfaces.js";
|
|
2
|
+
/** RPC client for full BCHN node interaction via JSON-RPC. */
|
|
2
3
|
export declare class BchnRpcClient {
|
|
3
4
|
private url;
|
|
4
5
|
private rpcUser;
|
|
@@ -8,5 +9,11 @@ export declare class BchnRpcClient {
|
|
|
8
9
|
private logger;
|
|
9
10
|
private timeoutMs;
|
|
10
11
|
constructor(config: RpcClientConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Sends a typed RPC request to the BCHN node.
|
|
14
|
+
* @example
|
|
15
|
+
* const result = await client.request<GetBlockCount>("getblockcount");
|
|
16
|
+
* const block = await client.request<GetBlockVerbosity1>("getblock", hash, 1);
|
|
17
|
+
*/
|
|
11
18
|
request<T extends RpcRequest>(endpoint: T['method'], ...params: T['params']): Promise<T['response']>;
|
|
12
19
|
}
|
package/dist/rpcClient.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { getRandomId, validateAndConstructUrl } from "./utils/utils.js";
|
|
11
11
|
import { RetryLimitExceededError } from "./utils/errors.js";
|
|
12
|
+
/** RPC client for full BCHN node interaction via JSON-RPC. */
|
|
12
13
|
export class BchnRpcClient {
|
|
13
14
|
constructor(config) {
|
|
14
15
|
var _a, _b, _c, _d;
|
|
@@ -25,6 +26,12 @@ export class BchnRpcClient {
|
|
|
25
26
|
this.logger = (_c = config.logger) !== null && _c !== void 0 ? _c : console;
|
|
26
27
|
this.timeoutMs = (_d = config.timeoutMs) !== null && _d !== void 0 ? _d : 5000;
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Sends a typed RPC request to the BCHN node.
|
|
31
|
+
* @example
|
|
32
|
+
* const result = await client.request<GetBlockCount>("getblockcount");
|
|
33
|
+
* const block = await client.request<GetBlockVerbosity1>("getblock", hash, 1);
|
|
34
|
+
*/
|
|
28
35
|
request(endpoint, ...params) {
|
|
29
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
37
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mr-zwets/bchn-api-wrapper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "a Typescript wrapper for interacting with the Bitcoin Cash Node (BCHN) API ",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,12 +11,10 @@
|
|
|
11
11
|
},
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@types/node": "^
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"typescript": "^5.6.3",
|
|
19
|
-
"vitest": "^2.1.3"
|
|
14
|
+
"@types/node": "^24.10.4",
|
|
15
|
+
"msw": "^2.12.4",
|
|
16
|
+
"typescript": "^5.9.3",
|
|
17
|
+
"vitest": "^4.0.16"
|
|
20
18
|
},
|
|
21
19
|
"directories": {
|
|
22
20
|
"test": "test"
|
|
@@ -36,5 +34,6 @@
|
|
|
36
34
|
"bugs": {
|
|
37
35
|
"url": "https://github.com/mr-zwets/bchn-api-wrapper/issues"
|
|
38
36
|
},
|
|
39
|
-
"homepage": "https://github.com/mr-zwets/bchn-api-wrapper#readme"
|
|
37
|
+
"homepage": "https://github.com/mr-zwets/bchn-api-wrapper#readme",
|
|
38
|
+
"packageManager": "pnpm@10.12.1"
|
|
40
39
|
}
|