@bigmi/core 0.0.1
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/CHANGELOG.md +11 -0
- package/LICENSE.md +21 -0
- package/README.md +137 -0
- package/dist/cjs/actions/getBalance.d.ts +7 -0
- package/dist/cjs/actions/getBalance.js +11 -0
- package/dist/cjs/actions/getBalance.js.map +1 -0
- package/dist/cjs/actions/getBlock.d.ts +12 -0
- package/dist/cjs/actions/getBlock.js +31 -0
- package/dist/cjs/actions/getBlock.js.map +1 -0
- package/dist/cjs/actions/getBlockCount.d.ts +4 -0
- package/dist/cjs/actions/getBlockCount.js +11 -0
- package/dist/cjs/actions/getBlockCount.js.map +1 -0
- package/dist/cjs/actions/getBlockStats.d.ts +14 -0
- package/dist/cjs/actions/getBlockStats.js +27 -0
- package/dist/cjs/actions/getBlockStats.js.map +1 -0
- package/dist/cjs/actions/getUTXOTransaction.d.ts +9 -0
- package/dist/cjs/actions/getUTXOTransaction.js +24 -0
- package/dist/cjs/actions/getUTXOTransaction.js.map +1 -0
- package/dist/cjs/actions/sendUTXOTransaction.d.ts +8 -0
- package/dist/cjs/actions/sendUTXOTransaction.js +15 -0
- package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -0
- package/dist/cjs/actions/signPsbt.d.ts +3 -0
- package/dist/cjs/actions/signPsbt.js +11 -0
- package/dist/cjs/actions/signPsbt.js.map +1 -0
- package/dist/cjs/actions/waitForTransaction.d.ts +32 -0
- package/dist/cjs/actions/waitForTransaction.js +185 -0
- package/dist/cjs/actions/waitForTransaction.js.map +1 -0
- package/dist/cjs/actions/watchBlockNumber.d.ts +14 -0
- package/dist/cjs/actions/watchBlockNumber.js +45 -0
- package/dist/cjs/actions/watchBlockNumber.js.map +1 -0
- package/dist/cjs/chains/bitcoin.d.ts +36 -0
- package/dist/cjs/chains/bitcoin.js +21 -0
- package/dist/cjs/chains/bitcoin.js.map +1 -0
- package/dist/cjs/clients/types.d.ts +27 -0
- package/dist/cjs/clients/types.js +3 -0
- package/dist/cjs/clients/types.js.map +1 -0
- package/dist/cjs/decorators/UTXOAPIActions.d.ts +6 -0
- package/dist/cjs/decorators/UTXOAPIActions.js +10 -0
- package/dist/cjs/decorators/UTXOAPIActions.js.map +1 -0
- package/dist/cjs/decorators/UTXOActions.d.ts +10 -0
- package/dist/cjs/decorators/UTXOActions.js +14 -0
- package/dist/cjs/decorators/UTXOActions.js.map +1 -0
- package/dist/cjs/index.d.ts +38 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transports/ankr.d.ts +2 -0
- package/dist/cjs/transports/ankr.js +21 -0
- package/dist/cjs/transports/ankr.js.map +1 -0
- package/dist/cjs/transports/blockchair.d.ts +2 -0
- package/dist/cjs/transports/blockchair.js +24 -0
- package/dist/cjs/transports/blockchair.js.map +1 -0
- package/dist/cjs/transports/blockcypher.d.ts +2 -0
- package/dist/cjs/transports/blockcypher.js +21 -0
- package/dist/cjs/transports/blockcypher.js.map +1 -0
- package/dist/cjs/transports/getHttpRpcClient.d.ts +19 -0
- package/dist/cjs/transports/getHttpRpcClient.js +77 -0
- package/dist/cjs/transports/getHttpRpcClient.js.map +1 -0
- package/dist/cjs/transports/getRpcProviderMethods.d.ts +2 -0
- package/dist/cjs/transports/getRpcProviderMethods.js +22 -0
- package/dist/cjs/transports/getRpcProviderMethods.js.map +1 -0
- package/dist/cjs/transports/mempool.d.ts +2 -0
- package/dist/cjs/transports/mempool.js +17 -0
- package/dist/cjs/transports/mempool.js.map +1 -0
- package/dist/cjs/transports/types.d.ts +60 -0
- package/dist/cjs/transports/types.js +3 -0
- package/dist/cjs/transports/types.js.map +1 -0
- package/dist/cjs/transports/utxo.d.ts +6 -0
- package/dist/cjs/transports/utxo.js +56 -0
- package/dist/cjs/transports/utxo.js.map +1 -0
- package/dist/cjs/types/blockStats.d.ts +34 -0
- package/dist/cjs/types/blockStats.js +3 -0
- package/dist/cjs/types/blockStats.js.map +1 -0
- package/dist/cjs/types/transaction.d.ts +41 -0
- package/dist/cjs/types/transaction.js +3 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/utils/cancelTransaction.d.ts +2 -0
- package/dist/cjs/utils/cancelTransaction.js +51 -0
- package/dist/cjs/utils/cancelTransaction.js.map +1 -0
- package/dist/cjs/utils/getUTXOAddress.d.ts +19 -0
- package/dist/cjs/utils/getUTXOAddress.js +120 -0
- package/dist/cjs/utils/getUTXOAddress.js.map +1 -0
- package/dist/cjs/utils/isUTXOAddress.d.ts +2 -0
- package/dist/cjs/utils/isUTXOAddress.js +18 -0
- package/dist/cjs/utils/isUTXOAddress.js.map +1 -0
- package/dist/cjs/utils/modifyFee.d.ts +2 -0
- package/dist/cjs/utils/modifyFee.js +50 -0
- package/dist/cjs/utils/modifyFee.js.map +1 -0
- package/dist/cjs/utils/observe.d.ts +11 -0
- package/dist/cjs/utils/observe.js +48 -0
- package/dist/cjs/utils/observe.js.map +1 -0
- package/dist/cjs/utils/poll.d.ts +9 -0
- package/dist/cjs/utils/poll.js +30 -0
- package/dist/cjs/utils/poll.js.map +1 -0
- package/dist/cjs/utils/sleep.d.ts +1 -0
- package/dist/cjs/utils/sleep.js +9 -0
- package/dist/cjs/utils/sleep.js.map +1 -0
- package/dist/esm/actions/getBalance.d.ts +8 -0
- package/dist/esm/actions/getBalance.js +8 -0
- package/dist/esm/actions/getBalance.js.map +1 -0
- package/dist/esm/actions/getBlock.d.ts +12 -0
- package/dist/esm/actions/getBlock.js +28 -0
- package/dist/esm/actions/getBlock.js.map +1 -0
- package/dist/esm/actions/getBlockCount.d.ts +4 -0
- package/dist/esm/actions/getBlockCount.js +8 -0
- package/dist/esm/actions/getBlockCount.js.map +1 -0
- package/dist/esm/actions/getBlockStats.d.ts +14 -0
- package/dist/esm/actions/getBlockStats.js +24 -0
- package/dist/esm/actions/getBlockStats.js.map +1 -0
- package/dist/esm/actions/getUTXOTransaction.d.ts +11 -0
- package/dist/esm/actions/getUTXOTransaction.js +21 -0
- package/dist/esm/actions/getUTXOTransaction.js.map +1 -0
- package/dist/esm/actions/sendUTXOTransaction.d.ts +10 -0
- package/dist/esm/actions/sendUTXOTransaction.js +12 -0
- package/dist/esm/actions/sendUTXOTransaction.js.map +1 -0
- package/dist/esm/actions/signPsbt.d.ts +3 -0
- package/dist/esm/actions/signPsbt.js +8 -0
- package/dist/esm/actions/signPsbt.js.map +1 -0
- package/dist/esm/actions/waitForTransaction.d.ts +75 -0
- package/dist/esm/actions/waitForTransaction.js +230 -0
- package/dist/esm/actions/waitForTransaction.js.map +1 -0
- package/dist/esm/actions/watchBlockNumber.d.ts +25 -0
- package/dist/esm/actions/watchBlockNumber.js +58 -0
- package/dist/esm/actions/watchBlockNumber.js.map +1 -0
- package/dist/esm/chains/bitcoin.d.ts +36 -0
- package/dist/esm/chains/bitcoin.js +18 -0
- package/dist/esm/chains/bitcoin.js.map +1 -0
- package/dist/esm/clients/types.d.ts +43 -0
- package/dist/esm/clients/types.js +2 -0
- package/dist/esm/clients/types.js.map +1 -0
- package/dist/esm/decorators/UTXOAPIActions.d.ts +6 -0
- package/dist/esm/decorators/UTXOAPIActions.js +7 -0
- package/dist/esm/decorators/UTXOAPIActions.js.map +1 -0
- package/dist/esm/decorators/UTXOActions.d.ts +10 -0
- package/dist/esm/decorators/UTXOActions.js +11 -0
- package/dist/esm/decorators/UTXOActions.js.map +1 -0
- package/dist/esm/index.d.ts +38 -0
- package/dist/esm/index.js +31 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/transports/ankr.d.ts +2 -0
- package/dist/esm/transports/ankr.js +18 -0
- package/dist/esm/transports/ankr.js.map +1 -0
- package/dist/esm/transports/blockchair.d.ts +2 -0
- package/dist/esm/transports/blockchair.js +21 -0
- package/dist/esm/transports/blockchair.js.map +1 -0
- package/dist/esm/transports/blockcypher.d.ts +2 -0
- package/dist/esm/transports/blockcypher.js +18 -0
- package/dist/esm/transports/blockcypher.js.map +1 -0
- package/dist/esm/transports/getHttpRpcClient.d.ts +24 -0
- package/dist/esm/transports/getHttpRpcClient.js +74 -0
- package/dist/esm/transports/getHttpRpcClient.js.map +1 -0
- package/dist/esm/transports/getRpcProviderMethods.d.ts +2 -0
- package/dist/esm/transports/getRpcProviderMethods.js +19 -0
- package/dist/esm/transports/getRpcProviderMethods.js.map +1 -0
- package/dist/esm/transports/mempool.d.ts +2 -0
- package/dist/esm/transports/mempool.js +14 -0
- package/dist/esm/transports/mempool.js.map +1 -0
- package/dist/esm/transports/types.d.ts +60 -0
- package/dist/esm/transports/types.js +2 -0
- package/dist/esm/transports/types.js.map +1 -0
- package/dist/esm/transports/utxo.d.ts +6 -0
- package/dist/esm/transports/utxo.js +53 -0
- package/dist/esm/transports/utxo.js.map +1 -0
- package/dist/esm/types/blockStats.d.ts +34 -0
- package/dist/esm/types/blockStats.js +2 -0
- package/dist/esm/types/blockStats.js.map +1 -0
- package/dist/esm/types/transaction.d.ts +41 -0
- package/dist/esm/types/transaction.js +2 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/utils/cancelTransaction.d.ts +2 -0
- package/dist/esm/utils/cancelTransaction.js +55 -0
- package/dist/esm/utils/cancelTransaction.js.map +1 -0
- package/dist/esm/utils/getUTXOAddress.d.ts +19 -0
- package/dist/esm/utils/getUTXOAddress.js +116 -0
- package/dist/esm/utils/getUTXOAddress.js.map +1 -0
- package/dist/esm/utils/isUTXOAddress.d.ts +2 -0
- package/dist/esm/utils/isUTXOAddress.js +14 -0
- package/dist/esm/utils/isUTXOAddress.js.map +1 -0
- package/dist/esm/utils/modifyFee.d.ts +2 -0
- package/dist/esm/utils/modifyFee.js +53 -0
- package/dist/esm/utils/modifyFee.js.map +1 -0
- package/dist/esm/utils/observe.d.ts +18 -0
- package/dist/esm/utils/observe.js +51 -0
- package/dist/esm/utils/observe.js.map +1 -0
- package/dist/esm/utils/poll.d.ts +12 -0
- package/dist/esm/utils/poll.js +30 -0
- package/dist/esm/utils/poll.js.map +1 -0
- package/dist/esm/utils/sleep.d.ts +1 -0
- package/dist/esm/utils/sleep.js +6 -0
- package/dist/esm/utils/sleep.js.map +1 -0
- package/dist/types/actions/getBalance.d.ts +9 -0
- package/dist/types/actions/getBalance.d.ts.map +1 -0
- package/dist/types/actions/getBlock.d.ts +13 -0
- package/dist/types/actions/getBlock.d.ts.map +1 -0
- package/dist/types/actions/getBlockCount.d.ts +5 -0
- package/dist/types/actions/getBlockCount.d.ts.map +1 -0
- package/dist/types/actions/getBlockStats.d.ts +15 -0
- package/dist/types/actions/getBlockStats.d.ts.map +1 -0
- package/dist/types/actions/getUTXOTransaction.d.ts +12 -0
- package/dist/types/actions/getUTXOTransaction.d.ts.map +1 -0
- package/dist/types/actions/sendUTXOTransaction.d.ts +11 -0
- package/dist/types/actions/sendUTXOTransaction.d.ts.map +1 -0
- package/dist/types/actions/signPsbt.d.ts +4 -0
- package/dist/types/actions/signPsbt.d.ts.map +1 -0
- package/dist/types/actions/waitForTransaction.d.ts +76 -0
- package/dist/types/actions/waitForTransaction.d.ts.map +1 -0
- package/dist/types/actions/watchBlockNumber.d.ts +26 -0
- package/dist/types/actions/watchBlockNumber.d.ts.map +1 -0
- package/dist/types/chains/bitcoin.d.ts +37 -0
- package/dist/types/chains/bitcoin.d.ts.map +1 -0
- package/dist/types/clients/types.d.ts +44 -0
- package/dist/types/clients/types.d.ts.map +1 -0
- package/dist/types/decorators/UTXOAPIActions.d.ts +7 -0
- package/dist/types/decorators/UTXOAPIActions.d.ts.map +1 -0
- package/dist/types/decorators/UTXOActions.d.ts +11 -0
- package/dist/types/decorators/UTXOActions.d.ts.map +1 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/transports/ankr.d.ts +3 -0
- package/dist/types/transports/ankr.d.ts.map +1 -0
- package/dist/types/transports/blockchair.d.ts +3 -0
- package/dist/types/transports/blockchair.d.ts.map +1 -0
- package/dist/types/transports/blockcypher.d.ts +3 -0
- package/dist/types/transports/blockcypher.d.ts.map +1 -0
- package/dist/types/transports/getHttpRpcClient.d.ts +25 -0
- package/dist/types/transports/getHttpRpcClient.d.ts.map +1 -0
- package/dist/types/transports/getRpcProviderMethods.d.ts +3 -0
- package/dist/types/transports/getRpcProviderMethods.d.ts.map +1 -0
- package/dist/types/transports/mempool.d.ts +3 -0
- package/dist/types/transports/mempool.d.ts.map +1 -0
- package/dist/types/transports/types.d.ts +61 -0
- package/dist/types/transports/types.d.ts.map +1 -0
- package/dist/types/transports/utxo.d.ts +7 -0
- package/dist/types/transports/utxo.d.ts.map +1 -0
- package/dist/types/types/blockStats.d.ts +35 -0
- package/dist/types/types/blockStats.d.ts.map +1 -0
- package/dist/types/types/transaction.d.ts +42 -0
- package/dist/types/types/transaction.d.ts.map +1 -0
- package/dist/types/utils/cancelTransaction.d.ts +3 -0
- package/dist/types/utils/cancelTransaction.d.ts.map +1 -0
- package/dist/types/utils/getUTXOAddress.d.ts +20 -0
- package/dist/types/utils/getUTXOAddress.d.ts.map +1 -0
- package/dist/types/utils/isUTXOAddress.d.ts +3 -0
- package/dist/types/utils/isUTXOAddress.d.ts.map +1 -0
- package/dist/types/utils/modifyFee.d.ts +3 -0
- package/dist/types/utils/modifyFee.d.ts.map +1 -0
- package/dist/types/utils/observe.d.ts +19 -0
- package/dist/types/utils/observe.d.ts.map +1 -0
- package/dist/types/utils/poll.d.ts +13 -0
- package/dist/types/utils/poll.d.ts.map +1 -0
- package/dist/types/utils/sleep.d.ts +2 -0
- package/dist/types/utils/sleep.d.ts.map +1 -0
- package/package.json +50 -0
- package/src/actions/getBalance.ts +26 -0
- package/src/actions/getBlock.ts +58 -0
- package/src/actions/getBlockCount.ts +20 -0
- package/src/actions/getBlockStats.ts +55 -0
- package/src/actions/getUTXOTransaction.ts +43 -0
- package/src/actions/sendUTXOTransaction.ts +29 -0
- package/src/actions/signPsbt.ts +23 -0
- package/src/actions/waitForTransaction.ts +387 -0
- package/src/actions/watchBlockNumber.ts +105 -0
- package/src/chains/bitcoin.ts +18 -0
- package/src/clients/types.ts +48 -0
- package/src/decorators/UTXOAPIActions.ts +20 -0
- package/src/decorators/UTXOActions.ts +37 -0
- package/src/index.ts +97 -0
- package/src/transports/ankr.ts +30 -0
- package/src/transports/blockchair.ts +27 -0
- package/src/transports/blockcypher.ts +32 -0
- package/src/transports/getHttpRpcClient.ts +122 -0
- package/src/transports/getRpcProviderMethods.ts +22 -0
- package/src/transports/mempool.ts +34 -0
- package/src/transports/types.ts +71 -0
- package/src/transports/utxo.ts +84 -0
- package/src/types/blockStats.ts +35 -0
- package/src/types/transaction.ts +43 -0
- package/src/utils/cancelTransaction.ts +75 -0
- package/src/utils/getUTXOAddress.ts +148 -0
- package/src/utils/isUTXOAddress.ts +18 -0
- package/src/utils/modifyFee.ts +78 -0
- package/src/utils/observe.ts +81 -0
- package/src/utils/poll.ts +48 -0
- package/src/utils/sleep.ts +5 -0
- package/tsconfig.json +10 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Exporting actions
|
|
2
|
+
export { getBalance } from './actions/getBalance.js'
|
|
3
|
+
export { getBlock } from './actions/getBlock.js'
|
|
4
|
+
export type {
|
|
5
|
+
GetBlockParameters,
|
|
6
|
+
GetBlockReturnType,
|
|
7
|
+
} from './actions/getBlock.js'
|
|
8
|
+
export { getBlockCount } from './actions/getBlockCount.js'
|
|
9
|
+
export type { GetBlockCountReturnType } from './actions/getBlockCount.js'
|
|
10
|
+
export { getBlockStats } from './actions/getBlockStats.js'
|
|
11
|
+
export type {
|
|
12
|
+
GetBlockStatsParameters,
|
|
13
|
+
GetBlockStatsReturnType,
|
|
14
|
+
} from './actions/getBlockStats.js'
|
|
15
|
+
export { getUTXOTransaction } from './actions/getUTXOTransaction.js'
|
|
16
|
+
export type {
|
|
17
|
+
GetUTXOTransactionParameters,
|
|
18
|
+
GetUTXOTransactionReturnType,
|
|
19
|
+
} from './actions/getUTXOTransaction.js'
|
|
20
|
+
export { sendUTXOTransaction } from './actions/sendUTXOTransaction.js'
|
|
21
|
+
export type {
|
|
22
|
+
SendUTXOTransactionParameters,
|
|
23
|
+
SendUTXOTransactionReturnType,
|
|
24
|
+
} from './actions/sendUTXOTransaction.js'
|
|
25
|
+
export { signPsbt } from './actions/signPsbt.js'
|
|
26
|
+
export { waitForTransaction } from './actions/waitForTransaction.js'
|
|
27
|
+
export type {
|
|
28
|
+
ReplacementReason,
|
|
29
|
+
ReplacementReturnType,
|
|
30
|
+
WaitForTransactionReceiptParameters,
|
|
31
|
+
WaitForTransactionReceiptReturnType,
|
|
32
|
+
WithRetryParameters,
|
|
33
|
+
} from './actions/waitForTransaction.js'
|
|
34
|
+
export { watchBlockNumber } from './actions/watchBlockNumber.js'
|
|
35
|
+
export type {
|
|
36
|
+
OnBlockNumberFn,
|
|
37
|
+
OnBlockNumberParameter,
|
|
38
|
+
WatchBlockNumberParameters,
|
|
39
|
+
WatchBlockNumberReturnType,
|
|
40
|
+
} from './actions/watchBlockNumber.js'
|
|
41
|
+
|
|
42
|
+
// Exporting clients
|
|
43
|
+
export type {
|
|
44
|
+
BtcAccount,
|
|
45
|
+
SignPsbtParameters,
|
|
46
|
+
SignPsbtReturnType,
|
|
47
|
+
UTXOWalletProvider,
|
|
48
|
+
UTXOWalletSchema,
|
|
49
|
+
} from './clients/types.js'
|
|
50
|
+
|
|
51
|
+
// Exporting decorators
|
|
52
|
+
export { UTXOActions } from './decorators/UTXOActions.js'
|
|
53
|
+
export { UTXOAPIActions } from './decorators/UTXOAPIActions.js'
|
|
54
|
+
|
|
55
|
+
// Exporting transports
|
|
56
|
+
export { ankrMethods } from './transports/ankr.js'
|
|
57
|
+
export { blockchairMethods } from './transports/blockchair.js'
|
|
58
|
+
export { blockcypherMethods } from './transports/blockcypher.js'
|
|
59
|
+
export { getHttpRpcClient } from './transports/getHttpRpcClient.js'
|
|
60
|
+
export type {
|
|
61
|
+
HttpRequestParameters,
|
|
62
|
+
HttpRpcClient,
|
|
63
|
+
RpcRequest,
|
|
64
|
+
} from './transports/getHttpRpcClient.js'
|
|
65
|
+
export { getRpcProviderMethods } from './transports/getRpcProviderMethods.js'
|
|
66
|
+
export { mempoolMethods } from './transports/mempool.js'
|
|
67
|
+
export type {
|
|
68
|
+
ErrorResult,
|
|
69
|
+
RpcMethodHandler,
|
|
70
|
+
RpcMethods,
|
|
71
|
+
RpcResponse,
|
|
72
|
+
SuccessResult,
|
|
73
|
+
UTXOAPIMethod,
|
|
74
|
+
UTXOAPISchema,
|
|
75
|
+
UTXOSchema,
|
|
76
|
+
} from './transports/types.js'
|
|
77
|
+
export { utxo } from './transports/utxo.js'
|
|
78
|
+
|
|
79
|
+
// Exporting types
|
|
80
|
+
export type { BlockStats, BlockStatsKeys } from './types/blockStats.js'
|
|
81
|
+
export type { UTXOTransaction } from './types/transaction.js'
|
|
82
|
+
|
|
83
|
+
// Exporting utils
|
|
84
|
+
export { cancelTransaction } from './utils/cancelTransaction.js'
|
|
85
|
+
export {
|
|
86
|
+
UTXOAddressType,
|
|
87
|
+
UTXONetwork,
|
|
88
|
+
getUTXOAddress,
|
|
89
|
+
} from './utils/getUTXOAddress.js'
|
|
90
|
+
export type { UTXOAddress } from './utils/getUTXOAddress.js'
|
|
91
|
+
export { isUTXOAddress } from './utils/isUTXOAddress.js'
|
|
92
|
+
export { modifyFee } from './utils/modifyFee.js'
|
|
93
|
+
export { cleanupCache, listenersCache, observe } from './utils/observe.js'
|
|
94
|
+
export { poll } from './utils/poll.js'
|
|
95
|
+
|
|
96
|
+
// Exporting chains
|
|
97
|
+
export { bitcoin } from './chains/bitcoin.js'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RpcMethods } from './types.js'
|
|
2
|
+
|
|
3
|
+
type AnkrBalanceResponse = {
|
|
4
|
+
address: string
|
|
5
|
+
balance: string
|
|
6
|
+
totalReceived: string
|
|
7
|
+
totalSent: string
|
|
8
|
+
unconfirmedBalance: string
|
|
9
|
+
unconfirmedTxs: number
|
|
10
|
+
txs: number
|
|
11
|
+
error: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ankrMethods: RpcMethods = {
|
|
15
|
+
getBalance: async (client, baseUrl, { address }) => {
|
|
16
|
+
const apiUrl = `${baseUrl}/address/${address}?details=basic`
|
|
17
|
+
const response = (await client.request({
|
|
18
|
+
url: apiUrl,
|
|
19
|
+
fetchOptions: { method: 'GET' },
|
|
20
|
+
})) as unknown as AnkrBalanceResponse
|
|
21
|
+
if (response.error) {
|
|
22
|
+
return {
|
|
23
|
+
error: { code: -1, message: response.error },
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
result: BigInt(response.balance),
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RpcMethods } from './types.js'
|
|
2
|
+
|
|
3
|
+
type BlockchairBalanceResponse = {
|
|
4
|
+
data: Record<string, any>
|
|
5
|
+
context: { code: number; error: string }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const blockchairMethods: RpcMethods = {
|
|
9
|
+
getBalance: async (client, baseUrl, { address }) => {
|
|
10
|
+
const apiUrl = `${baseUrl}/addresses/balances/?addresses=${address}`
|
|
11
|
+
const response = (await client.request({
|
|
12
|
+
url: apiUrl,
|
|
13
|
+
fetchOptions: { method: 'GET' },
|
|
14
|
+
})) as unknown as BlockchairBalanceResponse
|
|
15
|
+
if (response.context?.code !== 200) {
|
|
16
|
+
return {
|
|
17
|
+
error: {
|
|
18
|
+
code: response.context?.code,
|
|
19
|
+
message: response.context?.error,
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
result: BigInt(response.data[address]),
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RpcMethods } from './types.js'
|
|
2
|
+
|
|
3
|
+
type BlockcypherBalanceResponse = {
|
|
4
|
+
address: string
|
|
5
|
+
total_received: number
|
|
6
|
+
total_sent: number
|
|
7
|
+
balance: number
|
|
8
|
+
unconfirmed_balance: number
|
|
9
|
+
final_balance: number
|
|
10
|
+
n_tx: number
|
|
11
|
+
unconfirmed_n_tx: number
|
|
12
|
+
final_n_tx: number
|
|
13
|
+
error?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const blockcypherMethods: RpcMethods = {
|
|
17
|
+
getBalance: async (client, baseUrl, { address }) => {
|
|
18
|
+
const apiUrl = `${baseUrl}/addrs/${address}`
|
|
19
|
+
const response = (await client.request({
|
|
20
|
+
url: apiUrl,
|
|
21
|
+
fetchOptions: { method: 'GET' },
|
|
22
|
+
})) as unknown as BlockcypherBalanceResponse
|
|
23
|
+
if (response.error) {
|
|
24
|
+
return {
|
|
25
|
+
error: { code: -1, message: response.error },
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
result: BigInt(response.balance),
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { HttpRequestError, TimeoutError, stringify, withTimeout } from 'viem'
|
|
2
|
+
import type { HttpRequestReturnType, HttpRpcClientOptions } from 'viem/utils'
|
|
3
|
+
|
|
4
|
+
export type RpcRequest = {
|
|
5
|
+
jsonrpc?: '2.0'
|
|
6
|
+
method: string
|
|
7
|
+
params?: any
|
|
8
|
+
id?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type HttpRequestParameters<
|
|
12
|
+
body extends RpcRequest | RpcRequest[] = RpcRequest,
|
|
13
|
+
> = {
|
|
14
|
+
url?: string
|
|
15
|
+
/** The RPC request body. */
|
|
16
|
+
body?: body
|
|
17
|
+
/** Request configuration to pass to `fetch`. */
|
|
18
|
+
fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined
|
|
19
|
+
/** A callback to handle the response. */
|
|
20
|
+
onRequest?: ((request: Request) => Promise<void> | void) | undefined
|
|
21
|
+
/** A callback to handle the response. */
|
|
22
|
+
onResponse?: ((response: Response) => Promise<void> | void) | undefined
|
|
23
|
+
/** The timeout (in ms) for the request. */
|
|
24
|
+
timeout?: HttpRpcClientOptions['timeout'] | undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type HttpRpcClient = {
|
|
28
|
+
request<body extends RpcRequest | RpcRequest[]>(
|
|
29
|
+
params: HttpRequestParameters<body>
|
|
30
|
+
): Promise<HttpRequestReturnType<body>>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getHttpRpcClient(
|
|
34
|
+
url: string,
|
|
35
|
+
options: HttpRpcClientOptions = {}
|
|
36
|
+
): HttpRpcClient {
|
|
37
|
+
return {
|
|
38
|
+
async request(params) {
|
|
39
|
+
const {
|
|
40
|
+
body,
|
|
41
|
+
onRequest = options.onRequest,
|
|
42
|
+
onResponse = options.onResponse,
|
|
43
|
+
timeout = options.timeout ?? 10_000,
|
|
44
|
+
} = params
|
|
45
|
+
|
|
46
|
+
const fetchOptions = {
|
|
47
|
+
...(options.fetchOptions ?? {}),
|
|
48
|
+
...(params.fetchOptions ?? {}),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { headers, method, signal: signal_ } = fetchOptions
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const response = await withTimeout(
|
|
55
|
+
async ({ signal }) => {
|
|
56
|
+
const init: RequestInit = {
|
|
57
|
+
...fetchOptions,
|
|
58
|
+
body: body ? stringify(body) : undefined,
|
|
59
|
+
headers: {
|
|
60
|
+
...(method !== 'GET'
|
|
61
|
+
? { 'Content-Type': 'application/json' }
|
|
62
|
+
: undefined),
|
|
63
|
+
...headers,
|
|
64
|
+
},
|
|
65
|
+
method: method,
|
|
66
|
+
signal: signal_ || (timeout > 0 ? signal : null),
|
|
67
|
+
}
|
|
68
|
+
const request = new Request(params.url ?? url, init)
|
|
69
|
+
if (onRequest) {
|
|
70
|
+
await onRequest(request, init)
|
|
71
|
+
}
|
|
72
|
+
const response = await fetch(params.url ?? url, init)
|
|
73
|
+
return response
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
errorInstance: new TimeoutError({ body: body ?? {}, url }),
|
|
77
|
+
timeout,
|
|
78
|
+
signal: true,
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (onResponse) {
|
|
83
|
+
await onResponse(response)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let data: any
|
|
87
|
+
if (
|
|
88
|
+
response.headers.get('Content-Type')?.startsWith('application/json')
|
|
89
|
+
) {
|
|
90
|
+
data = await response.json()
|
|
91
|
+
} else {
|
|
92
|
+
data = await response.text()
|
|
93
|
+
data = JSON.parse(data || '{}')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
throw new HttpRequestError({
|
|
98
|
+
body,
|
|
99
|
+
details: stringify(data.error) || response.statusText,
|
|
100
|
+
headers: response.headers,
|
|
101
|
+
status: response.status,
|
|
102
|
+
url,
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return data
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (err instanceof HttpRequestError) {
|
|
109
|
+
throw err
|
|
110
|
+
}
|
|
111
|
+
if (err instanceof TimeoutError) {
|
|
112
|
+
throw err
|
|
113
|
+
}
|
|
114
|
+
throw new HttpRequestError({
|
|
115
|
+
body,
|
|
116
|
+
cause: err as Error,
|
|
117
|
+
url,
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ankrMethods } from './ankr.js'
|
|
2
|
+
import { blockchairMethods } from './blockchair.js'
|
|
3
|
+
import { blockcypherMethods } from './blockcypher.js'
|
|
4
|
+
import { mempoolMethods } from './mempool.js'
|
|
5
|
+
import type { RpcMethods } from './types.js'
|
|
6
|
+
|
|
7
|
+
export function getRpcProviderMethods(
|
|
8
|
+
key: 'blockchair' | 'ankr' | 'blockcypher' | 'mempool' | string
|
|
9
|
+
): RpcMethods | null {
|
|
10
|
+
switch (key) {
|
|
11
|
+
case 'blockchair':
|
|
12
|
+
return blockchairMethods
|
|
13
|
+
case 'ankr':
|
|
14
|
+
return ankrMethods
|
|
15
|
+
case 'blockcypher':
|
|
16
|
+
return blockcypherMethods
|
|
17
|
+
case 'mempool':
|
|
18
|
+
return mempoolMethods
|
|
19
|
+
default:
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RpcMethods } from './types.js'
|
|
2
|
+
|
|
3
|
+
type MempoolBalanceResponse = {
|
|
4
|
+
address: string
|
|
5
|
+
chain_stats: {
|
|
6
|
+
funded_txo_count: number
|
|
7
|
+
funded_txo_sum: number
|
|
8
|
+
spent_txo_count: number
|
|
9
|
+
spent_txo_sum: number
|
|
10
|
+
tx_count: number
|
|
11
|
+
}
|
|
12
|
+
mempool_stats: {
|
|
13
|
+
funded_txo_count: number
|
|
14
|
+
funded_txo_sum: number
|
|
15
|
+
spent_txo_count: number
|
|
16
|
+
spent_txo_sum: number
|
|
17
|
+
tx_count: number
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const mempoolMethods: RpcMethods = {
|
|
22
|
+
getBalance: async (client, baseUrl, { address }) => {
|
|
23
|
+
const apiUrl = `${baseUrl}/address/${address}`
|
|
24
|
+
const response = (await client.request({
|
|
25
|
+
url: apiUrl,
|
|
26
|
+
fetchOptions: { method: 'GET' },
|
|
27
|
+
})) as unknown as MempoolBalanceResponse
|
|
28
|
+
const balance =
|
|
29
|
+
response.chain_stats.funded_txo_sum - response.chain_stats.spent_txo_sum
|
|
30
|
+
return {
|
|
31
|
+
result: BigInt(balance),
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { BlockStats, BlockStatsKeys } from '../types/blockStats.js'
|
|
2
|
+
import type { UTXOTransaction } from '../types/transaction.js'
|
|
3
|
+
import type { HttpRpcClient } from './getHttpRpcClient.js'
|
|
4
|
+
|
|
5
|
+
export type UTXOSchema = [
|
|
6
|
+
{
|
|
7
|
+
Method: 'getblockcount'
|
|
8
|
+
Parameters: []
|
|
9
|
+
ReturnType: number
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
Method: 'getblockhash'
|
|
13
|
+
Parameters: [number]
|
|
14
|
+
ReturnType: string
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
Method: 'getblock'
|
|
18
|
+
Parameters: [string, number]
|
|
19
|
+
ReturnType: string
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
Method: 'getblockstats'
|
|
23
|
+
Parameters: [string | number, Array<BlockStatsKeys>?]
|
|
24
|
+
ReturnType: BlockStats
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
Method: 'sendrawtransaction'
|
|
28
|
+
Parameters: [string, number?]
|
|
29
|
+
ReturnType: string
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
Method: 'getrawtransaction'
|
|
33
|
+
Parameters: [string, boolean, string?]
|
|
34
|
+
ReturnType: UTXOTransaction
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
export type UTXOAPISchema = [
|
|
39
|
+
{
|
|
40
|
+
Method: 'getBalance'
|
|
41
|
+
Parameters: { address: string }
|
|
42
|
+
ReturnType: bigint
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
export type UTXOAPIMethod = UTXOAPISchema[number]['Method']
|
|
47
|
+
|
|
48
|
+
export type SuccessResult<result> = {
|
|
49
|
+
method?: undefined
|
|
50
|
+
result: result
|
|
51
|
+
error?: undefined
|
|
52
|
+
}
|
|
53
|
+
export type ErrorResult<error> = {
|
|
54
|
+
method?: undefined
|
|
55
|
+
result?: undefined
|
|
56
|
+
error: error
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type RpcResponse<result = any, error = any> =
|
|
60
|
+
| SuccessResult<result>
|
|
61
|
+
| ErrorResult<error>
|
|
62
|
+
|
|
63
|
+
export type RpcMethodHandler = (
|
|
64
|
+
client: HttpRpcClient,
|
|
65
|
+
baseUrl: string,
|
|
66
|
+
params: any
|
|
67
|
+
) => Promise<RpcResponse>
|
|
68
|
+
|
|
69
|
+
export type RpcMethods = {
|
|
70
|
+
[key in UTXOAPIMethod]: RpcMethodHandler
|
|
71
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type HttpTransport,
|
|
3
|
+
type HttpTransportConfig,
|
|
4
|
+
RpcRequestError,
|
|
5
|
+
UrlRequiredError,
|
|
6
|
+
createTransport,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import { getHttpRpcClient } from './getHttpRpcClient.js'
|
|
9
|
+
import { getRpcProviderMethods } from './getRpcProviderMethods.js'
|
|
10
|
+
import type { UTXOAPIMethod } from './types.js'
|
|
11
|
+
|
|
12
|
+
type UTXOHttpTransportConfig = HttpTransportConfig & {
|
|
13
|
+
includeChainToURL?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function utxo(
|
|
17
|
+
url?: string,
|
|
18
|
+
config: UTXOHttpTransportConfig = {}
|
|
19
|
+
): HttpTransport {
|
|
20
|
+
const {
|
|
21
|
+
fetchOptions,
|
|
22
|
+
key = 'utxo',
|
|
23
|
+
name = 'UTXO HTTP API',
|
|
24
|
+
onFetchRequest,
|
|
25
|
+
onFetchResponse,
|
|
26
|
+
retryDelay,
|
|
27
|
+
} = config
|
|
28
|
+
return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
|
|
29
|
+
const retryCount = config.retryCount ?? retryCount_
|
|
30
|
+
const timeout = timeout_ ?? config.timeout ?? 10_000
|
|
31
|
+
let url_ = url
|
|
32
|
+
if (config.includeChainToURL) {
|
|
33
|
+
const chainName = chain?.name.replace(' ', '-').toLowerCase()
|
|
34
|
+
url_ = `${url}${chainName ? `/${chainName}` : ''}`
|
|
35
|
+
}
|
|
36
|
+
if (!url_) {
|
|
37
|
+
throw new UrlRequiredError()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const client = getHttpRpcClient(url_, {
|
|
41
|
+
fetchOptions,
|
|
42
|
+
onRequest: onFetchRequest,
|
|
43
|
+
onResponse: onFetchResponse,
|
|
44
|
+
timeout,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const rpcMethods = getRpcProviderMethods(key)
|
|
48
|
+
|
|
49
|
+
return createTransport(
|
|
50
|
+
{
|
|
51
|
+
key,
|
|
52
|
+
name,
|
|
53
|
+
async request({ method, params }) {
|
|
54
|
+
const body = { method, params }
|
|
55
|
+
const methodHandler = rpcMethods?.[method as UTXOAPIMethod]
|
|
56
|
+
const { error, result } = await (methodHandler?.(
|
|
57
|
+
client,
|
|
58
|
+
url_,
|
|
59
|
+
params
|
|
60
|
+
) ??
|
|
61
|
+
client.request({
|
|
62
|
+
body,
|
|
63
|
+
}))
|
|
64
|
+
if (error) {
|
|
65
|
+
throw new RpcRequestError({
|
|
66
|
+
body,
|
|
67
|
+
error,
|
|
68
|
+
url: url_,
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
return result
|
|
72
|
+
},
|
|
73
|
+
retryCount,
|
|
74
|
+
retryDelay,
|
|
75
|
+
timeout,
|
|
76
|
+
type: 'http',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
fetchOptions,
|
|
80
|
+
url: url_,
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type BlockStats = Partial<{
|
|
2
|
+
avgfee: number
|
|
3
|
+
avgfeerate: number
|
|
4
|
+
avgtxsize: number
|
|
5
|
+
blockhash: string
|
|
6
|
+
feerate_percentiles: number[]
|
|
7
|
+
height: number
|
|
8
|
+
ins: number
|
|
9
|
+
maxfee: number
|
|
10
|
+
maxfeerate: number
|
|
11
|
+
maxtxsize: number
|
|
12
|
+
medianfee: number
|
|
13
|
+
mediantime: number
|
|
14
|
+
mediantxsize: number
|
|
15
|
+
minfee: number
|
|
16
|
+
minfeerate: number
|
|
17
|
+
mintxsize: number
|
|
18
|
+
outs: number
|
|
19
|
+
subsidy: number
|
|
20
|
+
swtotal_size: number
|
|
21
|
+
swtotal_weight: number
|
|
22
|
+
swtxs: number
|
|
23
|
+
time: number
|
|
24
|
+
total_out: number
|
|
25
|
+
total_size: number
|
|
26
|
+
total_weight: number
|
|
27
|
+
totalfee: number
|
|
28
|
+
txs: number
|
|
29
|
+
utxo_increase: number
|
|
30
|
+
utxo_size_inc: number
|
|
31
|
+
utxo_increase_actual: number
|
|
32
|
+
utxo_size_inc_actual: number
|
|
33
|
+
}>
|
|
34
|
+
|
|
35
|
+
export type BlockStatsKeys = keyof BlockStats
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type UTXOTransaction = {
|
|
2
|
+
blockhash?: string
|
|
3
|
+
blocktime?: number
|
|
4
|
+
confirmations?: number
|
|
5
|
+
hash: string
|
|
6
|
+
hex: string
|
|
7
|
+
in_active_chain?: boolean
|
|
8
|
+
locktime: number
|
|
9
|
+
size: number
|
|
10
|
+
time?: number
|
|
11
|
+
txid: string
|
|
12
|
+
version: number
|
|
13
|
+
vsize: number
|
|
14
|
+
weight: number
|
|
15
|
+
vin: {
|
|
16
|
+
scriptSig: {
|
|
17
|
+
asm: string
|
|
18
|
+
hex: string
|
|
19
|
+
}
|
|
20
|
+
sequence: number
|
|
21
|
+
txid: string
|
|
22
|
+
txinwitness: string[]
|
|
23
|
+
vout: number
|
|
24
|
+
}[]
|
|
25
|
+
vout: {
|
|
26
|
+
n: 0
|
|
27
|
+
scriptPubKey:
|
|
28
|
+
| {
|
|
29
|
+
address: string
|
|
30
|
+
asm: string
|
|
31
|
+
desc: string
|
|
32
|
+
hex: string
|
|
33
|
+
type: string
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
asm: string
|
|
37
|
+
desc: string
|
|
38
|
+
hex: string
|
|
39
|
+
type: string
|
|
40
|
+
}
|
|
41
|
+
value: number
|
|
42
|
+
}[]
|
|
43
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Psbt, address } from 'bitcoinjs-lib'
|
|
2
|
+
|
|
3
|
+
interface InputData {
|
|
4
|
+
hash: Uint8Array
|
|
5
|
+
index: number
|
|
6
|
+
nonWitnessUtxo?: Uint8Array
|
|
7
|
+
witnessUtxo?: {
|
|
8
|
+
script: Uint8Array
|
|
9
|
+
value: bigint
|
|
10
|
+
}
|
|
11
|
+
redeemScript?: Uint8Array
|
|
12
|
+
witnessScript?: Uint8Array
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function cancelTransaction(psbt: Psbt, accountAddress: string): Psbt {
|
|
16
|
+
const newPsbt = new Psbt()
|
|
17
|
+
const inputs = psbt.data.inputs
|
|
18
|
+
const txInputs = psbt.txInputs
|
|
19
|
+
|
|
20
|
+
// Add inputs to the new PSBT
|
|
21
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
22
|
+
const input = inputs[i]
|
|
23
|
+
const txInput = txInputs[i]
|
|
24
|
+
const inputData: InputData = {
|
|
25
|
+
hash: txInput.hash,
|
|
26
|
+
index: txInput.index,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Include UTXO information
|
|
30
|
+
if (input.nonWitnessUtxo) {
|
|
31
|
+
inputData.nonWitnessUtxo = input.nonWitnessUtxo
|
|
32
|
+
} else if (input.witnessUtxo) {
|
|
33
|
+
inputData.witnessUtxo = input.witnessUtxo
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error('Input UTXO information is missing')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Include scripts if necessary
|
|
39
|
+
if (input.redeemScript) {
|
|
40
|
+
inputData.redeemScript = input.redeemScript
|
|
41
|
+
}
|
|
42
|
+
if (input.witnessScript) {
|
|
43
|
+
inputData.witnessScript = input.witnessScript
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
newPsbt.addInput(inputData)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Compute total output amount from the original transaction
|
|
50
|
+
const outputs = psbt.txOutputs
|
|
51
|
+
let totalOutputValue = BigInt(0)
|
|
52
|
+
|
|
53
|
+
for (const output of outputs) {
|
|
54
|
+
totalOutputValue += output.value
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (totalOutputValue <= BigInt(0)) {
|
|
58
|
+
throw new Error('Total output value must be greater than zero')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Create the output to send funds back to sender's address
|
|
62
|
+
const outputScript = address.toOutputScript(accountAddress)
|
|
63
|
+
newPsbt.addOutput({
|
|
64
|
+
script: outputScript,
|
|
65
|
+
value: totalOutputValue,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Modify the input sequence number to enable RBF
|
|
69
|
+
newPsbt.txInputs.forEach((_, index) => {
|
|
70
|
+
// Set sequence number to less than 0xfffffffe, e.g., 0xfffffffd
|
|
71
|
+
newPsbt.setInputSequence(index, 0xfffffffd)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
return newPsbt
|
|
75
|
+
}
|