@lifi/sdk 3.3.0-beta.2 → 3.3.0-beta.3
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/package.json +4 -3
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +10 -0
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/UTXO/UTXO.js +2 -2
- package/src/_cjs/core/UTXO/UTXO.js.map +1 -1
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js +3 -4
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_cjs/core/UTXO/getUTXOAPIPublicClient.js +7 -7
- package/src/_cjs/core/UTXO/getUTXOAPIPublicClient.js.map +1 -1
- package/src/_cjs/core/UTXO/getUTXOPublicClient.js +2 -2
- package/src/_cjs/core/UTXO/getUTXOPublicClient.js.map +1 -1
- package/src/_cjs/index.js +2 -4
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +10 -0
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/UTXO/UTXO.js +1 -1
- package/src/_esm/core/UTXO/UTXO.js.map +1 -1
- package/src/_esm/core/UTXO/UTXOStepExecutor.js +1 -2
- package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js +2 -2
- package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js.map +1 -1
- package/src/_esm/core/UTXO/getUTXOPublicClient.js +1 -1
- package/src/_esm/core/UTXO/getUTXOPublicClient.js.map +1 -1
- package/src/_esm/index.js +0 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
- package/src/_types/core/UTXO/UTXOStepExecutor.d.ts.map +1 -1
- package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts +2 -2
- package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts.map +1 -1
- package/src/_types/core/UTXO/getUTXOPublicClient.d.ts +2 -2
- package/src/_types/core/UTXO/getUTXOPublicClient.d.ts.map +1 -1
- package/src/_types/index.d.ts +0 -2
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/core/Solana/SolanaStepExecutor.ts +12 -0
- package/src/core/UTXO/UTXO.ts +1 -1
- package/src/core/UTXO/UTXOStepExecutor.ts +2 -5
- package/src/core/UTXO/getUTXOAPIPublicClient.ts +3 -3
- package/src/core/UTXO/getUTXOPublicClient.ts +2 -2
- package/src/index.ts +0 -8
- package/src/version.ts +1 -1
- package/src/_cjs/core/UTXO/isUTXOAddress.js +0 -133
- package/src/_cjs/core/UTXO/isUTXOAddress.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBalance.js +0 -11
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBalance.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js +0 -31
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockCount.js +0 -11
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockCount.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js +0 -27
- package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +0 -24
- package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js +0 -15
- package/src/_cjs/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/signPsbt.js +0 -11
- package/src/_cjs/core/UTXO/utxo-stack/actions/signPsbt.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js +0 -185
- package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js +0 -45
- package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/clients/types.js +0 -3
- package/src/_cjs/core/UTXO/utxo-stack/clients/types.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js +0 -10
- package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOActions.js +0 -14
- package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOActions.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/ankr.js +0 -21
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/ankr.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockchair.js +0 -24
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockchair.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockcypher.js +0 -21
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockcypher.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js +0 -77
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js +0 -22
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/mempool.js +0 -17
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/mempool.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/types.js +0 -3
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/types.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/utxo.js +0 -56
- package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/utxo.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js +0 -3
- package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/types/transaction.js +0 -3
- package/src/_cjs/core/UTXO/utxo-stack/types/transaction.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js +0 -51
- package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js +0 -50
- package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js +0 -48
- package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js.map +0 -1
- package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js +0 -30
- package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js.map +0 -1
- package/src/_esm/core/UTXO/isUTXOAddress.js +0 -128
- package/src/_esm/core/UTXO/isUTXOAddress.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/getBalance.js +0 -8
- package/src/_esm/core/UTXO/utxo-stack/actions/getBalance.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js +0 -28
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlockCount.js +0 -8
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlockCount.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js +0 -24
- package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +0 -21
- package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js +0 -12
- package/src/_esm/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/signPsbt.js +0 -8
- package/src/_esm/core/UTXO/utxo-stack/actions/signPsbt.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js +0 -230
- package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js +0 -58
- package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/clients/types.js +0 -2
- package/src/_esm/core/UTXO/utxo-stack/clients/types.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js +0 -7
- package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOActions.js +0 -11
- package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOActions.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/ankr.js +0 -18
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/ankr.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockchair.js +0 -21
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockchair.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockcypher.js +0 -18
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockcypher.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js +0 -74
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js +0 -19
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/mempool.js +0 -14
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/mempool.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/types.js +0 -2
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/types.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/utxo.js +0 -53
- package/src/_esm/core/UTXO/utxo-stack/transports/utxo/utxo.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js +0 -2
- package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/types/transaction.js +0 -2
- package/src/_esm/core/UTXO/utxo-stack/types/transaction.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js +0 -55
- package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js +0 -53
- package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/utils/observe.js +0 -51
- package/src/_esm/core/UTXO/utxo-stack/utils/observe.js.map +0 -1
- package/src/_esm/core/UTXO/utxo-stack/utils/poll.js +0 -30
- package/src/_esm/core/UTXO/utxo-stack/utils/poll.js.map +0 -1
- package/src/_types/core/UTXO/isUTXOAddress.d.ts +0 -21
- package/src/_types/core/UTXO/isUTXOAddress.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/getBalance.d.ts +0 -9
- package/src/_types/core/UTXO/utxo-stack/actions/getBalance.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts +0 -13
- package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/getBlockCount.d.ts +0 -5
- package/src/_types/core/UTXO/utxo-stack/actions/getBlockCount.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts +0 -15
- package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts +0 -12
- package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts +0 -11
- package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/signPsbt.d.ts +0 -4
- package/src/_types/core/UTXO/utxo-stack/actions/signPsbt.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts +0 -76
- package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts +0 -26
- package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/clients/types.d.ts +0 -44
- package/src/_types/core/UTXO/utxo-stack/clients/types.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/decorators/UTXOAPIActions.d.ts +0 -7
- package/src/_types/core/UTXO/utxo-stack/decorators/UTXOAPIActions.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/decorators/UTXOActions.d.ts +0 -11
- package/src/_types/core/UTXO/utxo-stack/decorators/UTXOActions.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/ankr.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/ankr.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockchair.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockchair.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockcypher.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockcypher.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.d.ts +0 -25
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/mempool.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/mempool.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts +0 -61
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/utxo.d.ts +0 -7
- package/src/_types/core/UTXO/utxo-stack/transports/utxo/utxo.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts +0 -35
- package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/types/transaction.d.ts +0 -42
- package/src/_types/core/UTXO/utxo-stack/types/transaction.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts +0 -3
- package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts +0 -19
- package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts.map +0 -1
- package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts +0 -13
- package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts.map +0 -1
- package/src/core/UTXO/isUTXOAddress.ts +0 -165
- package/src/core/UTXO/utxo-stack/actions/getBalance.ts +0 -26
- package/src/core/UTXO/utxo-stack/actions/getBlock.ts +0 -58
- package/src/core/UTXO/utxo-stack/actions/getBlockCount.ts +0 -20
- package/src/core/UTXO/utxo-stack/actions/getBlockStats.ts +0 -55
- package/src/core/UTXO/utxo-stack/actions/getUTXOTransaction.ts +0 -43
- package/src/core/UTXO/utxo-stack/actions/sendUTXOTransaction.ts +0 -29
- package/src/core/UTXO/utxo-stack/actions/signPsbt.ts +0 -23
- package/src/core/UTXO/utxo-stack/actions/waitForTransaction.ts +0 -387
- package/src/core/UTXO/utxo-stack/actions/watchBlockNumber.ts +0 -105
- package/src/core/UTXO/utxo-stack/clients/types.ts +0 -48
- package/src/core/UTXO/utxo-stack/decorators/UTXOAPIActions.ts +0 -20
- package/src/core/UTXO/utxo-stack/decorators/UTXOActions.ts +0 -37
- package/src/core/UTXO/utxo-stack/transports/utxo/ankr.ts +0 -30
- package/src/core/UTXO/utxo-stack/transports/utxo/blockchair.ts +0 -27
- package/src/core/UTXO/utxo-stack/transports/utxo/blockcypher.ts +0 -32
- package/src/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.ts +0 -122
- package/src/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.ts +0 -22
- package/src/core/UTXO/utxo-stack/transports/utxo/mempool.ts +0 -34
- package/src/core/UTXO/utxo-stack/transports/utxo/types.ts +0 -71
- package/src/core/UTXO/utxo-stack/transports/utxo/utxo.ts +0 -84
- package/src/core/UTXO/utxo-stack/types/blockStats.ts +0 -35
- package/src/core/UTXO/utxo-stack/types/transaction.ts +0 -43
- package/src/core/UTXO/utxo-stack/utils/cancelTransaction.ts +0 -75
- package/src/core/UTXO/utxo-stack/utils/modifyFee.ts +0 -78
- package/src/core/UTXO/utxo-stack/utils/observe.ts +0 -81
- package/src/core/UTXO/utxo-stack/utils/poll.ts +0 -48
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { Transaction, address } from 'bitcoinjs-lib'
|
|
2
|
-
import {
|
|
3
|
-
type Chain,
|
|
4
|
-
type Client,
|
|
5
|
-
TransactionNotFoundError,
|
|
6
|
-
TransactionReceiptNotFoundError,
|
|
7
|
-
type Transport,
|
|
8
|
-
WaitForTransactionReceiptTimeoutError,
|
|
9
|
-
stringify,
|
|
10
|
-
withRetry,
|
|
11
|
-
} from 'viem'
|
|
12
|
-
import { getAction } from 'viem/utils'
|
|
13
|
-
import type { UTXOTransaction } from '../types/transaction.js'
|
|
14
|
-
import { observe } from '../utils/observe.js'
|
|
15
|
-
import { getBlock } from './getBlock.js'
|
|
16
|
-
import { getBlockStats } from './getBlockStats.js'
|
|
17
|
-
import { getUTXOTransaction } from './getUTXOTransaction.js'
|
|
18
|
-
import { watchBlockNumber } from './watchBlockNumber.js'
|
|
19
|
-
|
|
20
|
-
export type ReplacementReason = 'cancelled' | 'replaced' | 'repriced'
|
|
21
|
-
export type ReplacementReturnType = {
|
|
22
|
-
reason: ReplacementReason
|
|
23
|
-
replacedTransaction: Transaction
|
|
24
|
-
transaction: UTXOTransaction
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type WaitForTransactionReceiptReturnType = UTXOTransaction
|
|
28
|
-
|
|
29
|
-
export type WithRetryParameters = {
|
|
30
|
-
// The delay (in ms) between retries.
|
|
31
|
-
delay?:
|
|
32
|
-
| ((config: { count: number; error: Error }) => number)
|
|
33
|
-
| number
|
|
34
|
-
| undefined
|
|
35
|
-
// The max number of times to retry.
|
|
36
|
-
retryCount?: number | undefined
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type WaitForTransactionReceiptParameters = {
|
|
40
|
-
/** The Id of the transaction. */
|
|
41
|
-
txId: string
|
|
42
|
-
/** The hex string of the raw transaction. */
|
|
43
|
-
txHex: string
|
|
44
|
-
/** The sender address of the transaction. */
|
|
45
|
-
senderAddress?: string
|
|
46
|
-
/**
|
|
47
|
-
* The number of confirmations (blocks that have passed) to wait before resolving.
|
|
48
|
-
* @default 1
|
|
49
|
-
*/
|
|
50
|
-
confirmations?: number | undefined
|
|
51
|
-
/** Optional callback to emit if the transaction has been replaced. */
|
|
52
|
-
onReplaced?: ((response: ReplacementReturnType) => void) | undefined
|
|
53
|
-
/**
|
|
54
|
-
* Polling frequency (in ms). Defaults to the client's pollingInterval config.
|
|
55
|
-
* @default client.pollingInterval
|
|
56
|
-
*/
|
|
57
|
-
pollingInterval?: number | undefined
|
|
58
|
-
/**
|
|
59
|
-
* Number of times to retry if the transaction or block is not found.
|
|
60
|
-
* @default 6 (exponential backoff)
|
|
61
|
-
*/
|
|
62
|
-
retryCount?: number
|
|
63
|
-
/**
|
|
64
|
-
* Time to wait (in ms) between retries.
|
|
65
|
-
*/
|
|
66
|
-
retryDelay?: ((config: { count: number; error: Error }) => number) | number
|
|
67
|
-
/** Optional timeout (in milliseconds) to wait before stopping polling. */
|
|
68
|
-
timeout?: number | undefined
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Waits for the transaction to be included on a block (one confirmation), and then returns the transaction.
|
|
73
|
-
* - JSON-RPC Methods:
|
|
74
|
-
* - Polls getrawtransaction on each block until it has been processed.
|
|
75
|
-
* - If a transaction has been replaced:
|
|
76
|
-
* - Calls getblock and extracts the transactions
|
|
77
|
-
* - Checks if one of the transactions is a replacement
|
|
78
|
-
* - If so, calls getrawtransaction.
|
|
79
|
-
*
|
|
80
|
-
* The `waitForTransaction` action additionally supports replacement detection (e.g. RBF - transactions replaced-by-fee ).
|
|
81
|
-
*
|
|
82
|
-
* Transactions can be replaced when a user modifies their transaction in their wallet (to speed up or cancel).
|
|
83
|
-
* https://bitcoinops.org/en/topics/replace-by-fee/
|
|
84
|
-
*
|
|
85
|
-
* There are 3 types of Transaction Replacement reasons:
|
|
86
|
-
*
|
|
87
|
-
* - `repriced`: The fee has been modified (e.g. same outputs, different amounts)
|
|
88
|
-
* - `cancelled`: The Transaction has been cancelled (e.g. output is sender address)
|
|
89
|
-
* - `replaced`: The Transaction has been replaced (e.g. different outputs)
|
|
90
|
-
* @param client - Client to use
|
|
91
|
-
* @param parameters - {@link WaitForTransactionReceiptParameters}
|
|
92
|
-
* @returns The UTXO transaction. {@link WaitForTransactionReceiptReturnType}
|
|
93
|
-
*/
|
|
94
|
-
export async function waitForTransaction<chain extends Chain | undefined>(
|
|
95
|
-
client: Client<Transport, chain>,
|
|
96
|
-
{
|
|
97
|
-
confirmations = 1,
|
|
98
|
-
txId,
|
|
99
|
-
txHex,
|
|
100
|
-
senderAddress,
|
|
101
|
-
onReplaced,
|
|
102
|
-
pollingInterval = client.pollingInterval,
|
|
103
|
-
retryCount = 10,
|
|
104
|
-
retryDelay = 3_000,
|
|
105
|
-
timeout,
|
|
106
|
-
}: WaitForTransactionReceiptParameters
|
|
107
|
-
): Promise<WaitForTransactionReceiptReturnType> {
|
|
108
|
-
const observerId = stringify(['waitForTransaction', client.uid, txId])
|
|
109
|
-
|
|
110
|
-
let count = 0
|
|
111
|
-
let transaction: UTXOTransaction | undefined
|
|
112
|
-
let replacedTransaction: Transaction | undefined
|
|
113
|
-
let retrying = false
|
|
114
|
-
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
if (timeout) {
|
|
117
|
-
setTimeout(
|
|
118
|
-
() =>
|
|
119
|
-
reject(
|
|
120
|
-
new WaitForTransactionReceiptTimeoutError({ hash: txId as never })
|
|
121
|
-
),
|
|
122
|
-
timeout
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const _unobserve = observe(
|
|
127
|
-
observerId,
|
|
128
|
-
{ onReplaced, resolve, reject },
|
|
129
|
-
(emit) => {
|
|
130
|
-
const _unwatch = getAction(
|
|
131
|
-
client,
|
|
132
|
-
watchBlockNumber,
|
|
133
|
-
'watchBlockNumber'
|
|
134
|
-
)({
|
|
135
|
-
emitMissed: true,
|
|
136
|
-
emitOnBegin: true,
|
|
137
|
-
pollingInterval,
|
|
138
|
-
async onBlockNumber(blockNumber_) {
|
|
139
|
-
const done = (fn: () => void) => {
|
|
140
|
-
_unwatch()
|
|
141
|
-
fn()
|
|
142
|
-
_unobserve()
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
let blockNumber = blockNumber_
|
|
146
|
-
|
|
147
|
-
if (retrying) {
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
if (count > retryCount) {
|
|
151
|
-
done(() =>
|
|
152
|
-
emit.reject(
|
|
153
|
-
new WaitForTransactionReceiptTimeoutError({
|
|
154
|
-
hash: txId as never,
|
|
155
|
-
})
|
|
156
|
-
)
|
|
157
|
-
)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
// If we already have a valid receipt, let's check if we have enough
|
|
162
|
-
// confirmations. If we do, then we can resolve.
|
|
163
|
-
if (transaction?.blockhash) {
|
|
164
|
-
const blockStats = await getAction(
|
|
165
|
-
client,
|
|
166
|
-
getBlockStats,
|
|
167
|
-
'getBlockStats'
|
|
168
|
-
)({
|
|
169
|
-
blockHash: transaction.blockhash,
|
|
170
|
-
stats: ['height'],
|
|
171
|
-
})
|
|
172
|
-
if (
|
|
173
|
-
confirmations > 1 &&
|
|
174
|
-
(!blockStats.height ||
|
|
175
|
-
blockNumber - blockStats.height + 1 < confirmations)
|
|
176
|
-
) {
|
|
177
|
-
return
|
|
178
|
-
}
|
|
179
|
-
done(() => emit.resolve(transaction!))
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Get the transaction to check if it's been replaced.
|
|
184
|
-
// We need to retry as some RPC Providers may be slow to sync
|
|
185
|
-
// up mined transactions.
|
|
186
|
-
retrying = true
|
|
187
|
-
transaction = await withRetry(
|
|
188
|
-
() =>
|
|
189
|
-
getAction(
|
|
190
|
-
client,
|
|
191
|
-
getUTXOTransaction,
|
|
192
|
-
'getUTXOTransaction'
|
|
193
|
-
// If transaction exists it might be the replaced one with different txId
|
|
194
|
-
)({ txId: transaction?.txid || txId }),
|
|
195
|
-
{
|
|
196
|
-
delay: retryDelay,
|
|
197
|
-
retryCount,
|
|
198
|
-
}
|
|
199
|
-
)
|
|
200
|
-
if (transaction.blockhash) {
|
|
201
|
-
const blockStats = await getAction(
|
|
202
|
-
client,
|
|
203
|
-
getBlockStats,
|
|
204
|
-
'getBlockStats'
|
|
205
|
-
)({
|
|
206
|
-
blockHash: transaction.blockhash,
|
|
207
|
-
stats: ['height'],
|
|
208
|
-
})
|
|
209
|
-
if (blockStats.height) {
|
|
210
|
-
blockNumber = blockStats.height
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
retrying = false
|
|
214
|
-
|
|
215
|
-
// Check if transaction has been processed.
|
|
216
|
-
if (!transaction?.confirmations) {
|
|
217
|
-
throw new TransactionReceiptNotFoundError({
|
|
218
|
-
hash: txId as never,
|
|
219
|
-
})
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Check if we have enough confirmations. If not, continue polling.
|
|
223
|
-
if (transaction.confirmations < confirmations) {
|
|
224
|
-
return
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
done(() => emit.resolve(transaction!))
|
|
228
|
-
} catch (err) {
|
|
229
|
-
// If the receipt is not found, the transaction will be pending.
|
|
230
|
-
// We need to check if it has potentially been replaced.
|
|
231
|
-
if (
|
|
232
|
-
err instanceof TransactionNotFoundError ||
|
|
233
|
-
err instanceof TransactionReceiptNotFoundError
|
|
234
|
-
) {
|
|
235
|
-
try {
|
|
236
|
-
replacedTransaction = Transaction.fromHex(
|
|
237
|
-
transaction?.hex || txHex
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
// Let's retrieve the transactions from the current block.
|
|
241
|
-
// We need to retry as some RPC Providers may be slow to sync
|
|
242
|
-
// up mined blocks.
|
|
243
|
-
retrying = true
|
|
244
|
-
const block = await withRetry(
|
|
245
|
-
() =>
|
|
246
|
-
getAction(
|
|
247
|
-
client,
|
|
248
|
-
getBlock,
|
|
249
|
-
'getBlock'
|
|
250
|
-
)({
|
|
251
|
-
blockNumber,
|
|
252
|
-
}),
|
|
253
|
-
{
|
|
254
|
-
delay: retryDelay,
|
|
255
|
-
retryCount,
|
|
256
|
-
// shouldRetry: ({ error }) =>
|
|
257
|
-
// error instanceof BlockNotFoundError,
|
|
258
|
-
}
|
|
259
|
-
)
|
|
260
|
-
retrying = false
|
|
261
|
-
|
|
262
|
-
// Create a set of input identifiers for mempool transaction
|
|
263
|
-
const replacedTransactionInputs = new Set<string>()
|
|
264
|
-
|
|
265
|
-
for (const input of replacedTransaction.ins) {
|
|
266
|
-
const txid = Array.from(input.hash)
|
|
267
|
-
.reverse()
|
|
268
|
-
.map((byte) => `00${byte.toString(16)}`.slice(-2))
|
|
269
|
-
.join('')
|
|
270
|
-
const vout = input.index
|
|
271
|
-
const inputId = `${txid}:${vout}`
|
|
272
|
-
replacedTransactionInputs.add(inputId)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
let replacementTransaction: Transaction | undefined
|
|
276
|
-
|
|
277
|
-
for (const tx of block.transactions!) {
|
|
278
|
-
if (tx.isCoinbase()) {
|
|
279
|
-
continue
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Check if any input of this transaction matches an input of mempool transaction
|
|
283
|
-
for (const input of tx.ins) {
|
|
284
|
-
const txid = Array.from(input.hash)
|
|
285
|
-
.reverse()
|
|
286
|
-
.map((byte) => `00${byte.toString(16)}`.slice(-2))
|
|
287
|
-
.join('')
|
|
288
|
-
const vout = input.index
|
|
289
|
-
const inputId = `${txid}:${vout}`
|
|
290
|
-
if (replacedTransactionInputs.has(inputId)) {
|
|
291
|
-
replacementTransaction = tx
|
|
292
|
-
break
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (replacementTransaction) {
|
|
296
|
-
break
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// If we couldn't find a replacement transaction, continue polling.
|
|
301
|
-
if (!replacementTransaction) {
|
|
302
|
-
return
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// If we found a replacement transaction, return it's receipt.
|
|
306
|
-
transaction = await getAction(
|
|
307
|
-
client,
|
|
308
|
-
getUTXOTransaction,
|
|
309
|
-
'getUTXOTransaction'
|
|
310
|
-
)({
|
|
311
|
-
txId: replacementTransaction.getId(),
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
// Check if we have enough confirmations. If not, continue polling.
|
|
315
|
-
if (
|
|
316
|
-
transaction.confirmations &&
|
|
317
|
-
transaction.confirmations < confirmations
|
|
318
|
-
) {
|
|
319
|
-
return
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
let reason: ReplacementReason = 'replaced'
|
|
323
|
-
|
|
324
|
-
// Function to get output addresses
|
|
325
|
-
function getOutputAddresses(tx: Transaction): string[] {
|
|
326
|
-
const addresses: string[] = []
|
|
327
|
-
for (const output of tx.outs) {
|
|
328
|
-
try {
|
|
329
|
-
const outputAddress = address.fromOutputScript(
|
|
330
|
-
output.script
|
|
331
|
-
)
|
|
332
|
-
addresses.push(outputAddress)
|
|
333
|
-
} catch (_e) {
|
|
334
|
-
// Handle non-standard scripts (e.g., OP_RETURN)
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return addresses
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Get the recipient addresses from the original transaction
|
|
341
|
-
const originalOutputAddresses =
|
|
342
|
-
getOutputAddresses(replacedTransaction)
|
|
343
|
-
|
|
344
|
-
// Get the recipient addresses from the replacement transaction
|
|
345
|
-
const replacementOutputAddresses = getOutputAddresses(
|
|
346
|
-
replacementTransaction
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
if (
|
|
350
|
-
originalOutputAddresses.length ===
|
|
351
|
-
replacementOutputAddresses.length &&
|
|
352
|
-
originalOutputAddresses.every((address) =>
|
|
353
|
-
replacementOutputAddresses.includes(address)
|
|
354
|
-
)
|
|
355
|
-
) {
|
|
356
|
-
reason = 'repriced'
|
|
357
|
-
} else if (
|
|
358
|
-
senderAddress &&
|
|
359
|
-
replacementOutputAddresses.length === 1 &&
|
|
360
|
-
replacementOutputAddresses.includes(senderAddress)
|
|
361
|
-
) {
|
|
362
|
-
reason = 'cancelled'
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
done(() => {
|
|
366
|
-
emit.onReplaced?.({
|
|
367
|
-
reason,
|
|
368
|
-
replacedTransaction: replacedTransaction!,
|
|
369
|
-
transaction: transaction!,
|
|
370
|
-
})
|
|
371
|
-
emit.resolve(transaction!)
|
|
372
|
-
})
|
|
373
|
-
} catch (err_) {
|
|
374
|
-
done(() => emit.reject(err_))
|
|
375
|
-
}
|
|
376
|
-
} else {
|
|
377
|
-
done(() => emit.reject(err))
|
|
378
|
-
}
|
|
379
|
-
} finally {
|
|
380
|
-
count++
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
})
|
|
384
|
-
}
|
|
385
|
-
)
|
|
386
|
-
})
|
|
387
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { type Chain, type Client, type Transport, stringify } from 'viem'
|
|
2
|
-
import { getAction } from 'viem/utils'
|
|
3
|
-
import { observe } from '../utils/observe.js'
|
|
4
|
-
import { poll } from '../utils/poll.js'
|
|
5
|
-
import { type GetBlockCountReturnType, getBlockCount } from './getBlockCount.js'
|
|
6
|
-
|
|
7
|
-
export type OnBlockNumberParameter = GetBlockCountReturnType
|
|
8
|
-
export type OnBlockNumberFn = (
|
|
9
|
-
blockNumber: OnBlockNumberParameter,
|
|
10
|
-
prevBlockNumber: OnBlockNumberParameter | undefined
|
|
11
|
-
) => Promise<void>
|
|
12
|
-
|
|
13
|
-
export type WatchBlockNumberParameters = {
|
|
14
|
-
/** The callback to call when a new block number is received. */
|
|
15
|
-
onBlockNumber: OnBlockNumberFn
|
|
16
|
-
/** The callback to call when an error occurred when trying to get for a new block. */
|
|
17
|
-
onError?: ((error: Error) => void) | undefined
|
|
18
|
-
} & {
|
|
19
|
-
/** Whether or not to emit the missed block numbers to the callback. */
|
|
20
|
-
emitMissed?: boolean | undefined
|
|
21
|
-
/** Whether or not to emit the latest block number to the callback when the subscription opens. */
|
|
22
|
-
emitOnBegin?: boolean | undefined
|
|
23
|
-
/** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
|
|
24
|
-
pollingInterval?: number | undefined
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type WatchBlockNumberReturnType = () => void
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Watches and returns incoming block numbers.
|
|
31
|
-
* @param client - Client to use
|
|
32
|
-
* @param parameters - {@link WatchBlockNumberParameters}
|
|
33
|
-
* @returns A function that can be invoked to stop watching for new block numbers. {@link WatchBlockNumberReturnType}
|
|
34
|
-
*/
|
|
35
|
-
export function watchBlockNumber<
|
|
36
|
-
chain extends Chain | undefined,
|
|
37
|
-
transport extends Transport,
|
|
38
|
-
>(
|
|
39
|
-
client: Client<transport, chain>,
|
|
40
|
-
{
|
|
41
|
-
emitOnBegin = false,
|
|
42
|
-
emitMissed = false,
|
|
43
|
-
onBlockNumber,
|
|
44
|
-
onError,
|
|
45
|
-
pollingInterval = client.pollingInterval,
|
|
46
|
-
}: WatchBlockNumberParameters
|
|
47
|
-
): WatchBlockNumberReturnType {
|
|
48
|
-
let prevBlockNumber: GetBlockCountReturnType | undefined
|
|
49
|
-
|
|
50
|
-
const observerId = stringify([
|
|
51
|
-
'watchBlockNumber',
|
|
52
|
-
client.uid,
|
|
53
|
-
emitOnBegin,
|
|
54
|
-
emitMissed,
|
|
55
|
-
pollingInterval,
|
|
56
|
-
])
|
|
57
|
-
|
|
58
|
-
// TODO (edge cases):
|
|
59
|
-
// 1) Stop iterating block numbers if we are happy with the result of one onBlockNumber execution but there is more in the queue.
|
|
60
|
-
// 2) If we missed some time - user closed the page and came back when the block is already mined.
|
|
61
|
-
// In this case we probably want to save the block when we send the transaction and track the currently checked blocks until we find the relevant one.
|
|
62
|
-
return observe(observerId, { onBlockNumber, onError }, (emit) =>
|
|
63
|
-
poll(
|
|
64
|
-
async () => {
|
|
65
|
-
try {
|
|
66
|
-
const blockNumber = await getAction(
|
|
67
|
-
client,
|
|
68
|
-
getBlockCount,
|
|
69
|
-
'getBlockCount'
|
|
70
|
-
)({ cacheTime: 0 })
|
|
71
|
-
|
|
72
|
-
if (prevBlockNumber) {
|
|
73
|
-
// If the current block number is the same as the previous,
|
|
74
|
-
// we can skip.
|
|
75
|
-
if (blockNumber === prevBlockNumber) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// If we have missed out on some previous blocks, and the
|
|
80
|
-
// `emitMissed` flag is truthy, let's emit those blocks.
|
|
81
|
-
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
|
|
82
|
-
for (let i = prevBlockNumber + 1; i < blockNumber; i++) {
|
|
83
|
-
await emit.onBlockNumber(i, prevBlockNumber)
|
|
84
|
-
prevBlockNumber = i
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// If the next block number is greater than the previous,
|
|
90
|
-
// it is not in the past, and we can emit the new block number.
|
|
91
|
-
if (!prevBlockNumber || blockNumber > prevBlockNumber) {
|
|
92
|
-
await emit.onBlockNumber(blockNumber, prevBlockNumber)
|
|
93
|
-
prevBlockNumber = blockNumber
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
emit.onError?.(err as Error)
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
emitOnBegin,
|
|
101
|
-
interval: pollingInterval,
|
|
102
|
-
}
|
|
103
|
-
)
|
|
104
|
-
)
|
|
105
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { EIP1193RequestFn } from 'viem'
|
|
2
|
-
|
|
3
|
-
export type UTXOWalletSchema = readonly [
|
|
4
|
-
{
|
|
5
|
-
Method: 'signPsbt'
|
|
6
|
-
Parameters: SignPsbtParameters
|
|
7
|
-
ReturnType: SignPsbtReturnType
|
|
8
|
-
},
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
export type SignPsbtParameters = {
|
|
12
|
-
/** The PSBT encoded as a hexadecimal string */
|
|
13
|
-
psbt: string
|
|
14
|
-
/**
|
|
15
|
-
* Array of objects specifying details about the inputs to be signed
|
|
16
|
-
*/
|
|
17
|
-
inputsToSign: {
|
|
18
|
-
/**
|
|
19
|
-
* The SigHash type to use for signing (e.g., SIGHASH_ALL).
|
|
20
|
-
* If not specified, a default value is used.
|
|
21
|
-
*/
|
|
22
|
-
sigHash?: number
|
|
23
|
-
/** The Bitcoin address associated with the input that will be signed */
|
|
24
|
-
address: string
|
|
25
|
-
/** An array of indexes in the PSBT corresponding to the inputs that need to be signed */
|
|
26
|
-
signingIndexes: number[]
|
|
27
|
-
}[]
|
|
28
|
-
/**
|
|
29
|
-
* Whether to finalize the PSBT after signing.
|
|
30
|
-
* If `true`, the PSBT will be completed and ready for broadcasting.
|
|
31
|
-
* If `false` or omitted, the PSBT remains partially signed.
|
|
32
|
-
* Some wallets does not support it.
|
|
33
|
-
*/
|
|
34
|
-
finalize?: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type SignPsbtReturnType = string
|
|
38
|
-
|
|
39
|
-
export type UTXOWalletProvider = {
|
|
40
|
-
request: EIP1193RequestFn<UTXOWalletSchema>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type BtcAccount = {
|
|
44
|
-
address: string
|
|
45
|
-
addressType: 'p2tr' | 'p2wpkh' | 'p2wsh' | 'p2sh' | 'p2pkh'
|
|
46
|
-
publicKey: string
|
|
47
|
-
purpose: 'payment' | 'ordinals'
|
|
48
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
-
import {
|
|
3
|
-
type GetBalanceParameters,
|
|
4
|
-
type GetBalanceReturnType,
|
|
5
|
-
getBalance,
|
|
6
|
-
} from '../actions/getBalance.js'
|
|
7
|
-
|
|
8
|
-
export type UTXOAPIActions = {
|
|
9
|
-
getBalance: (args: GetBalanceParameters) => Promise<GetBalanceReturnType>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function UTXOAPIActions<
|
|
13
|
-
transport extends Transport = Transport,
|
|
14
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
15
|
-
account extends Account | undefined = Account | undefined,
|
|
16
|
-
>(client: Client<transport, chain, account>): UTXOAPIActions {
|
|
17
|
-
return {
|
|
18
|
-
getBalance: (args) => getBalance(client, args),
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
-
import {
|
|
3
|
-
type GetBlockCountReturnType,
|
|
4
|
-
getBlockCount,
|
|
5
|
-
} from '../actions/getBlockCount.js'
|
|
6
|
-
import {
|
|
7
|
-
type GetUTXOTransactionParameters,
|
|
8
|
-
type GetUTXOTransactionReturnType,
|
|
9
|
-
getUTXOTransaction,
|
|
10
|
-
} from '../actions/getUTXOTransaction.js'
|
|
11
|
-
import {
|
|
12
|
-
type SendUTXOTransactionParameters,
|
|
13
|
-
type SendUTXOTransactionReturnType,
|
|
14
|
-
sendUTXOTransaction,
|
|
15
|
-
} from '../actions/sendUTXOTransaction.js'
|
|
16
|
-
|
|
17
|
-
export type UTXOActions = {
|
|
18
|
-
getBlockCount: () => Promise<GetBlockCountReturnType>
|
|
19
|
-
sendUTXOTransaction: (
|
|
20
|
-
args: SendUTXOTransactionParameters
|
|
21
|
-
) => Promise<SendUTXOTransactionReturnType>
|
|
22
|
-
getUTXOTransaction: (
|
|
23
|
-
args: GetUTXOTransactionParameters
|
|
24
|
-
) => Promise<GetUTXOTransactionReturnType>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function UTXOActions<
|
|
28
|
-
transport extends Transport = Transport,
|
|
29
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
30
|
-
account extends Account | undefined = Account | undefined,
|
|
31
|
-
>(client: Client<transport, chain, account>): UTXOActions {
|
|
32
|
-
return {
|
|
33
|
-
getBlockCount: () => getBlockCount(client),
|
|
34
|
-
sendUTXOTransaction: (args) => sendUTXOTransaction(client, args),
|
|
35
|
-
getUTXOTransaction: (args) => getUTXOTransaction(client, args),
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|