@bigmi/core 0.1.1 → 0.2.0-beta.0
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/README.md +6 -4
- package/dist/cjs/actions/getBalance.d.ts +6 -3
- package/dist/cjs/actions/getBalance.js.map +1 -1
- package/dist/cjs/actions/getBlock.d.ts +4 -1
- package/dist/cjs/actions/getBlock.js +3 -3
- package/dist/cjs/actions/getBlock.js.map +1 -1
- package/dist/cjs/actions/getBlockCount.d.ts +4 -1
- package/dist/cjs/actions/getBlockCount.js.map +1 -1
- package/dist/cjs/actions/getBlockStats.d.ts +4 -1
- package/dist/cjs/actions/getBlockStats.js +3 -3
- package/dist/cjs/actions/getBlockStats.js.map +1 -1
- package/dist/cjs/actions/getUTXOTransaction.d.ts +4 -1
- package/dist/cjs/actions/getUTXOTransaction.js +2 -2
- package/dist/cjs/actions/getUTXOTransaction.js.map +1 -1
- package/dist/cjs/actions/sendUTXOTransaction.d.ts +4 -1
- package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -1
- package/dist/cjs/actions/signPsbt.d.ts +5 -2
- package/dist/cjs/actions/signPsbt.js.map +1 -1
- package/dist/cjs/actions/waitForTransaction.d.ts +3 -1
- package/dist/cjs/actions/waitForTransaction.js +16 -14
- package/dist/cjs/actions/waitForTransaction.js.map +1 -1
- package/dist/cjs/actions/watchBlockNumber.d.ts +3 -1
- package/dist/cjs/actions/watchBlockNumber.js +4 -4
- package/dist/cjs/actions/watchBlockNumber.js.map +1 -1
- package/dist/cjs/chains/bitcoin.d.ts +5 -17
- package/dist/cjs/chains/bitcoin.js +2 -2
- package/dist/cjs/chains/bitcoin.js.map +1 -1
- package/dist/cjs/chains/defineChain.d.ts +3 -0
- package/dist/cjs/chains/defineChain.js +12 -0
- package/dist/cjs/chains/defineChain.js.map +1 -0
- package/dist/cjs/clients/decorators/public.d.ts +18 -0
- package/dist/cjs/clients/decorators/public.js +18 -0
- package/dist/cjs/clients/decorators/public.js.map +1 -0
- package/dist/cjs/clients/decorators/wallet.d.ts +11 -0
- package/dist/cjs/clients/decorators/wallet.js +12 -0
- package/dist/cjs/clients/decorators/wallet.js.map +1 -0
- package/dist/cjs/errors/address.d.ts +9 -0
- package/dist/cjs/errors/address.js +17 -0
- package/dist/cjs/errors/address.js.map +1 -0
- package/dist/cjs/errors/base.d.ts +27 -0
- package/dist/cjs/errors/base.js +55 -0
- package/dist/cjs/errors/base.js.map +1 -0
- package/dist/cjs/errors/block.d.ts +11 -0
- package/dist/cjs/errors/block.js +18 -0
- package/dist/cjs/errors/block.js.map +1 -0
- package/dist/cjs/errors/config.d.ts +61 -0
- package/dist/cjs/errors/config.js +65 -0
- package/dist/cjs/errors/config.js.map +1 -0
- package/dist/cjs/errors/provider.d.ts +4 -0
- package/dist/cjs/errors/provider.js +15 -0
- package/dist/cjs/errors/provider.js.map +1 -0
- package/dist/cjs/errors/request.d.ts +80 -0
- package/dist/cjs/errors/request.js +72 -0
- package/dist/cjs/errors/request.js.map +1 -0
- package/dist/cjs/errors/rpc.d.ts +23 -0
- package/dist/cjs/errors/rpc.js +49 -0
- package/dist/cjs/errors/rpc.js.map +1 -0
- package/dist/cjs/errors/transaction.d.ts +31 -0
- package/dist/cjs/errors/transaction.js +40 -0
- package/dist/cjs/errors/transaction.js.map +1 -0
- package/dist/cjs/errors/transport.d.ts +7 -0
- package/dist/cjs/errors/transport.js +13 -0
- package/dist/cjs/errors/transport.js.map +1 -0
- package/dist/cjs/errors/utils.d.ts +6 -0
- package/dist/cjs/errors/utils.js +8 -0
- package/dist/cjs/errors/utils.js.map +1 -0
- package/dist/cjs/factories/createClient.d.ts +50 -0
- package/dist/cjs/factories/createClient.js +45 -0
- package/dist/cjs/factories/createClient.js.map +1 -0
- package/dist/cjs/factories/createTransport.d.ts +31 -0
- package/dist/cjs/factories/createTransport.js +23 -0
- package/dist/cjs/factories/createTransport.js.map +1 -0
- package/dist/cjs/index.d.ts +37 -4
- package/dist/cjs/index.js +63 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/transports/custom.d.ts +16 -0
- package/dist/cjs/transports/custom.js +17 -0
- package/dist/cjs/transports/custom.js.map +1 -0
- package/dist/cjs/transports/fallback.d.ts +56 -0
- package/dist/cjs/transports/fallback.js +165 -0
- package/dist/cjs/transports/fallback.js.map +1 -0
- package/dist/cjs/transports/getHttpRpcClient.d.ts +11 -1
- package/dist/cjs/transports/getHttpRpcClient.js +12 -10
- package/dist/cjs/transports/getHttpRpcClient.js.map +1 -1
- package/dist/cjs/transports/http.d.ts +28 -0
- package/dist/cjs/transports/http.js +72 -0
- package/dist/cjs/transports/http.js.map +1 -0
- package/dist/cjs/transports/types.d.ts +20 -5
- package/dist/cjs/transports/utxo.d.ts +1 -1
- package/dist/cjs/transports/utxo.js +6 -4
- package/dist/cjs/transports/utxo.js.map +1 -1
- package/dist/cjs/types/account.d.ts +9 -0
- package/dist/cjs/types/account.js +3 -0
- package/dist/cjs/types/account.js.map +1 -0
- package/dist/cjs/types/actions.d.ts +17 -0
- package/dist/cjs/types/actions.js +3 -0
- package/dist/cjs/types/actions.js.map +1 -0
- package/dist/cjs/types/address.d.ts +1 -0
- package/dist/cjs/types/address.js +3 -0
- package/dist/cjs/types/address.js.map +1 -0
- package/dist/cjs/types/base.d.ts +0 -0
- package/dist/cjs/types/base.js +2 -0
- package/dist/cjs/types/base.js.map +1 -0
- package/dist/cjs/types/block.d.ts +1 -0
- package/dist/cjs/{clients/types.js → types/block.js} +1 -1
- package/dist/cjs/types/block.js.map +1 -0
- package/dist/cjs/types/chain.d.ts +37 -0
- package/dist/cjs/types/chain.js +3 -0
- package/dist/cjs/types/chain.js.map +1 -0
- package/dist/cjs/types/client.d.ts +41 -0
- package/dist/cjs/types/client.js +3 -0
- package/dist/cjs/types/client.js.map +1 -0
- package/dist/cjs/types/hash.d.ts +1 -0
- package/dist/cjs/types/hash.js +3 -0
- package/dist/cjs/types/hash.js.map +1 -0
- package/dist/cjs/types/request.d.ts +43 -0
- package/dist/cjs/types/request.js +3 -0
- package/dist/cjs/types/request.js.map +1 -0
- package/dist/cjs/types/rpc.d.ts +34 -0
- package/dist/cjs/types/rpc.js +3 -0
- package/dist/cjs/types/rpc.js.map +1 -0
- package/dist/cjs/types/storage.d.ts +22 -0
- package/dist/cjs/types/storage.js +3 -0
- package/dist/cjs/types/storage.js.map +1 -0
- package/dist/cjs/types/transport.d.ts +29 -0
- package/dist/cjs/types/transport.js +3 -0
- package/dist/cjs/types/transport.js.map +1 -0
- package/dist/cjs/types/utils.d.ts +36 -0
- package/dist/cjs/types/utils.js +3 -0
- package/dist/cjs/types/utils.js.map +1 -0
- package/dist/cjs/utils/buildRequest.d.ts +5 -0
- package/dist/cjs/utils/buildRequest.js +102 -0
- package/dist/cjs/utils/buildRequest.js.map +1 -0
- package/dist/cjs/utils/converter.d.ts +3 -0
- package/dist/cjs/utils/converter.js +28 -0
- package/dist/cjs/utils/converter.js.map +1 -0
- package/dist/cjs/utils/createBatchScheduler.d.ts +20 -0
- package/dist/cjs/utils/createBatchScheduler.js +54 -0
- package/dist/cjs/utils/createBatchScheduler.js.map +1 -0
- package/dist/cjs/utils/deepEqual.d.ts +1 -0
- package/dist/cjs/utils/deepEqual.js +52 -0
- package/dist/cjs/utils/deepEqual.js.map +1 -0
- package/dist/cjs/utils/getAction.d.ts +10 -0
- package/dist/cjs/utils/getAction.js +15 -0
- package/dist/cjs/utils/getAction.js.map +1 -0
- package/dist/cjs/utils/getUTXOAddress.d.ts +3 -2
- package/dist/cjs/utils/getUTXOAddress.js.map +1 -1
- package/dist/cjs/utils/isUTXOAddress.js.map +1 -1
- package/dist/cjs/utils/lru.d.ts +6 -0
- package/dist/cjs/utils/lru.js +29 -0
- package/dist/cjs/utils/lru.js.map +1 -0
- package/dist/cjs/utils/observe.d.ts +1 -1
- package/dist/cjs/utils/parseAccount.d.ts +5 -0
- package/dist/cjs/utils/parseAccount.js +10 -0
- package/dist/cjs/utils/parseAccount.js.map +1 -0
- package/dist/cjs/utils/stringify.d.ts +3 -0
- package/dist/cjs/utils/stringify.js +9 -0
- package/dist/cjs/utils/stringify.js.map +1 -0
- package/dist/cjs/utils/uid.d.ts +1 -0
- package/dist/cjs/utils/uid.js +17 -0
- package/dist/cjs/utils/uid.js.map +1 -0
- package/dist/cjs/utils/wait.d.ts +1 -0
- package/dist/cjs/utils/wait.js +7 -0
- package/dist/cjs/utils/wait.js.map +1 -0
- package/dist/cjs/utils/withDedupe.d.ts +8 -0
- package/dist/cjs/utils/withDedupe.js +18 -0
- package/dist/cjs/utils/withDedupe.js.map +1 -0
- package/dist/cjs/utils/withResolvers.d.ts +6 -0
- package/dist/cjs/utils/withResolvers.js +13 -0
- package/dist/cjs/utils/withResolvers.js.map +1 -0
- package/dist/cjs/utils/withRetry.d.ts +14 -0
- package/dist/cjs/utils/withRetry.js +30 -0
- package/dist/cjs/utils/withRetry.js.map +1 -0
- package/dist/cjs/utils/withTimeout.d.ts +9 -0
- package/dist/cjs/utils/withTimeout.js +35 -0
- package/dist/cjs/utils/withTimeout.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/actions/getBalance.d.ts +6 -3
- package/dist/esm/actions/getBalance.js.map +1 -1
- package/dist/esm/actions/getBlock.d.ts +4 -1
- package/dist/esm/actions/getBlock.js +1 -1
- package/dist/esm/actions/getBlock.js.map +1 -1
- package/dist/esm/actions/getBlockCount.d.ts +4 -1
- package/dist/esm/actions/getBlockCount.js.map +1 -1
- package/dist/esm/actions/getBlockStats.d.ts +4 -1
- package/dist/esm/actions/getBlockStats.js +1 -1
- package/dist/esm/actions/getBlockStats.js.map +1 -1
- package/dist/esm/actions/getUTXOTransaction.d.ts +4 -1
- package/dist/esm/actions/getUTXOTransaction.js +1 -1
- package/dist/esm/actions/getUTXOTransaction.js.map +1 -1
- package/dist/esm/actions/sendUTXOTransaction.d.ts +4 -1
- package/dist/esm/actions/sendUTXOTransaction.js.map +1 -1
- package/dist/esm/actions/signPsbt.d.ts +5 -2
- package/dist/esm/actions/signPsbt.js.map +1 -1
- package/dist/esm/actions/waitForTransaction.d.ts +3 -1
- package/dist/esm/actions/waitForTransaction.js +4 -2
- package/dist/esm/actions/waitForTransaction.js.map +1 -1
- package/dist/esm/actions/watchBlockNumber.d.ts +3 -1
- package/dist/esm/actions/watchBlockNumber.js +2 -2
- package/dist/esm/actions/watchBlockNumber.js.map +1 -1
- package/dist/esm/chains/bitcoin.d.ts +5 -17
- package/dist/esm/chains/bitcoin.js +1 -1
- package/dist/esm/chains/bitcoin.js.map +1 -1
- package/dist/esm/chains/defineChain.d.ts +3 -0
- package/dist/esm/chains/defineChain.js +9 -0
- package/dist/esm/chains/defineChain.js.map +1 -0
- package/dist/esm/clients/decorators/public.d.ts +18 -0
- package/dist/esm/clients/decorators/public.js +15 -0
- package/dist/esm/clients/decorators/public.js.map +1 -0
- package/dist/esm/clients/decorators/wallet.d.ts +14 -0
- package/dist/esm/clients/decorators/wallet.js +9 -0
- package/dist/esm/clients/decorators/wallet.js.map +1 -0
- package/dist/esm/errors/address.d.ts +9 -0
- package/dist/esm/errors/address.js +13 -0
- package/dist/esm/errors/address.js.map +1 -0
- package/dist/esm/errors/base.d.ts +27 -0
- package/dist/esm/errors/base.js +50 -0
- package/dist/esm/errors/base.js.map +1 -0
- package/dist/esm/errors/block.d.ts +11 -0
- package/dist/esm/errors/block.js +14 -0
- package/dist/esm/errors/block.js.map +1 -0
- package/dist/esm/errors/config.d.ts +61 -0
- package/dist/esm/errors/config.js +55 -0
- package/dist/esm/errors/config.js.map +1 -0
- package/dist/esm/errors/provider.d.ts +4 -0
- package/dist/esm/errors/provider.js +11 -0
- package/dist/esm/errors/provider.js.map +1 -0
- package/dist/esm/errors/request.d.ts +80 -0
- package/dist/esm/errors/request.js +64 -0
- package/dist/esm/errors/request.js.map +1 -0
- package/dist/esm/errors/rpc.d.ts +53 -0
- package/dist/esm/errors/rpc.js +73 -0
- package/dist/esm/errors/rpc.js.map +1 -0
- package/dist/esm/errors/transaction.d.ts +31 -0
- package/dist/esm/errors/transaction.js +34 -0
- package/dist/esm/errors/transaction.js.map +1 -0
- package/dist/esm/errors/transport.d.ts +7 -0
- package/dist/esm/errors/transport.js +9 -0
- package/dist/esm/errors/transport.js.map +1 -0
- package/dist/esm/errors/utils.d.ts +6 -0
- package/dist/esm/errors/utils.js +3 -0
- package/dist/esm/errors/utils.js.map +1 -0
- package/dist/esm/factories/createClient.d.ts +85 -0
- package/dist/esm/factories/createClient.js +45 -0
- package/dist/esm/factories/createClient.js.map +1 -0
- package/dist/esm/factories/createTransport.d.ts +42 -0
- package/dist/esm/factories/createTransport.js +23 -0
- package/dist/esm/factories/createTransport.js.map +1 -0
- package/dist/esm/index.d.ts +37 -4
- package/dist/esm/index.js +26 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/transports/custom.d.ts +24 -0
- package/dist/esm/transports/custom.js +17 -0
- package/dist/esm/transports/custom.js.map +1 -0
- package/dist/esm/transports/fallback.d.ts +89 -0
- package/dist/esm/transports/fallback.js +172 -0
- package/dist/esm/transports/fallback.js.map +1 -0
- package/dist/esm/transports/getHttpRpcClient.d.ts +15 -1
- package/dist/esm/transports/getHttpRpcClient.js +4 -2
- package/dist/esm/transports/getHttpRpcClient.js.map +1 -1
- package/dist/esm/transports/http.d.ts +53 -0
- package/dist/esm/transports/http.js +74 -0
- package/dist/esm/transports/http.js.map +1 -0
- package/dist/esm/transports/types.d.ts +36 -5
- package/dist/esm/transports/utxo.d.ts +1 -1
- package/dist/esm/transports/utxo.js +3 -1
- package/dist/esm/transports/utxo.js.map +1 -1
- package/dist/esm/types/account.d.ts +9 -0
- package/dist/esm/types/account.js +2 -0
- package/dist/esm/types/account.js.map +1 -0
- package/dist/esm/types/actions.d.ts +20 -0
- package/dist/esm/types/actions.js +2 -0
- package/dist/esm/types/actions.js.map +1 -0
- package/dist/esm/types/address.d.ts +1 -0
- package/dist/esm/types/address.js +2 -0
- package/dist/esm/types/address.js.map +1 -0
- package/dist/esm/types/base.d.ts +0 -0
- package/dist/esm/types/base.js +2 -0
- package/dist/esm/types/base.js.map +1 -0
- package/dist/esm/types/block.d.ts +19 -0
- package/dist/esm/types/block.js +2 -0
- package/dist/esm/types/block.js.map +1 -0
- package/dist/esm/types/chain.d.ts +48 -0
- package/dist/esm/types/chain.js +2 -0
- package/dist/esm/types/chain.js.map +1 -0
- package/dist/esm/types/client.d.ts +68 -0
- package/dist/esm/types/client.js +2 -0
- package/dist/esm/types/client.js.map +1 -0
- package/dist/esm/types/hash.d.ts +1 -0
- package/dist/esm/types/hash.js +2 -0
- package/dist/esm/types/hash.js.map +1 -0
- package/dist/esm/types/request.d.ts +48 -0
- package/dist/esm/types/request.js +2 -0
- package/dist/esm/types/request.js.map +1 -0
- package/dist/esm/types/rpc.d.ts +34 -0
- package/dist/esm/types/rpc.js +2 -0
- package/dist/esm/types/rpc.js.map +1 -0
- package/dist/esm/types/storage.d.ts +22 -0
- package/dist/esm/types/storage.js +2 -0
- package/dist/esm/types/storage.js.map +1 -0
- package/dist/esm/types/transport.d.ts +37 -0
- package/dist/esm/types/transport.js +2 -0
- package/dist/esm/types/transport.js.map +1 -0
- package/dist/esm/types/utils.d.ts +72 -0
- package/dist/esm/types/utils.js +2 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/utils/buildRequest.d.ts +6 -0
- package/dist/esm/utils/buildRequest.js +111 -0
- package/dist/esm/utils/buildRequest.js.map +1 -0
- package/dist/esm/utils/converter.d.ts +3 -0
- package/dist/esm/utils/converter.js +23 -0
- package/dist/esm/utils/converter.js.map +1 -0
- package/dist/esm/utils/createBatchScheduler.d.ts +21 -0
- package/dist/esm/utils/createBatchScheduler.js +52 -0
- package/dist/esm/utils/createBatchScheduler.js.map +1 -0
- package/dist/esm/utils/deepEqual.d.ts +2 -0
- package/dist/esm/utils/deepEqual.js +52 -0
- package/dist/esm/utils/deepEqual.js.map +1 -0
- package/dist/esm/utils/getAction.d.ts +17 -0
- package/dist/esm/utils/getAction.js +23 -0
- package/dist/esm/utils/getAction.js.map +1 -0
- package/dist/esm/utils/getUTXOAddress.d.ts +3 -2
- package/dist/esm/utils/getUTXOAddress.js.map +1 -1
- package/dist/esm/utils/isUTXOAddress.js.map +1 -1
- package/dist/esm/utils/lru.d.ts +11 -0
- package/dist/esm/utils/lru.js +30 -0
- package/dist/esm/utils/lru.js.map +1 -0
- package/dist/esm/utils/observe.d.ts +1 -1
- package/dist/esm/utils/parseAccount.d.ts +5 -0
- package/dist/esm/utils/parseAccount.js +7 -0
- package/dist/esm/utils/parseAccount.js.map +1 -0
- package/dist/esm/utils/stringify.d.ts +3 -0
- package/dist/esm/utils/stringify.js +5 -0
- package/dist/esm/utils/stringify.js.map +1 -0
- package/dist/esm/utils/uid.d.ts +1 -0
- package/dist/esm/utils/uid.js +14 -0
- package/dist/esm/utils/uid.js.map +1 -0
- package/dist/esm/utils/wait.d.ts +1 -0
- package/dist/esm/utils/wait.js +4 -0
- package/dist/esm/utils/wait.js.map +1 -0
- package/dist/esm/utils/withDedupe.d.ts +10 -0
- package/dist/esm/utils/withDedupe.js +16 -0
- package/dist/esm/utils/withDedupe.js.map +1 -0
- package/dist/esm/utils/withResolvers.d.ts +8 -0
- package/dist/esm/utils/withResolvers.js +11 -0
- package/dist/esm/utils/withResolvers.js.map +1 -0
- package/dist/esm/utils/withRetry.d.ts +14 -0
- package/dist/esm/utils/withRetry.js +27 -0
- package/dist/esm/utils/withRetry.js.map +1 -0
- package/dist/esm/utils/withTimeout.d.ts +9 -0
- package/dist/esm/utils/withTimeout.js +32 -0
- package/dist/esm/utils/withTimeout.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/actions/getBalance.d.ts +6 -3
- package/dist/types/actions/getBalance.d.ts.map +1 -1
- package/dist/types/actions/getBlock.d.ts +4 -1
- package/dist/types/actions/getBlock.d.ts.map +1 -1
- package/dist/types/actions/getBlockCount.d.ts +4 -1
- package/dist/types/actions/getBlockCount.d.ts.map +1 -1
- package/dist/types/actions/getBlockStats.d.ts +4 -1
- package/dist/types/actions/getBlockStats.d.ts.map +1 -1
- package/dist/types/actions/getUTXOTransaction.d.ts +4 -1
- package/dist/types/actions/getUTXOTransaction.d.ts.map +1 -1
- package/dist/types/actions/sendUTXOTransaction.d.ts +4 -1
- package/dist/types/actions/sendUTXOTransaction.d.ts.map +1 -1
- package/dist/types/actions/signPsbt.d.ts +5 -2
- package/dist/types/actions/signPsbt.d.ts.map +1 -1
- package/dist/types/actions/waitForTransaction.d.ts +3 -1
- package/dist/types/actions/waitForTransaction.d.ts.map +1 -1
- package/dist/types/actions/watchBlockNumber.d.ts +3 -1
- package/dist/types/actions/watchBlockNumber.d.ts.map +1 -1
- package/dist/types/chains/bitcoin.d.ts +5 -17
- package/dist/types/chains/bitcoin.d.ts.map +1 -1
- package/dist/types/chains/defineChain.d.ts +4 -0
- package/dist/types/chains/defineChain.d.ts.map +1 -0
- package/dist/types/clients/decorators/public.d.ts +19 -0
- package/dist/types/clients/decorators/public.d.ts.map +1 -0
- package/dist/types/clients/decorators/wallet.d.ts +15 -0
- package/dist/types/clients/decorators/wallet.d.ts.map +1 -0
- package/dist/types/errors/address.d.ts +10 -0
- package/dist/types/errors/address.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +28 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/block.d.ts +12 -0
- package/dist/types/errors/block.d.ts.map +1 -0
- package/dist/types/errors/config.d.ts +62 -0
- package/dist/types/errors/config.d.ts.map +1 -0
- package/dist/types/errors/provider.d.ts +5 -0
- package/dist/types/errors/provider.d.ts.map +1 -0
- package/dist/types/errors/request.d.ts +81 -0
- package/dist/types/errors/request.d.ts.map +1 -0
- package/dist/types/errors/rpc.d.ts +54 -0
- package/dist/types/errors/rpc.d.ts.map +1 -0
- package/dist/types/errors/transaction.d.ts +32 -0
- package/dist/types/errors/transaction.d.ts.map +1 -0
- package/dist/types/errors/transport.d.ts +8 -0
- package/dist/types/errors/transport.d.ts.map +1 -0
- package/dist/types/errors/utils.d.ts +7 -0
- package/dist/types/errors/utils.d.ts.map +1 -0
- package/dist/types/factories/createClient.d.ts +86 -0
- package/dist/types/factories/createClient.d.ts.map +1 -0
- package/dist/types/factories/createTransport.d.ts +43 -0
- package/dist/types/factories/createTransport.d.ts.map +1 -0
- package/dist/types/index.d.ts +37 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/transports/custom.d.ts +25 -0
- package/dist/types/transports/custom.d.ts.map +1 -0
- package/dist/types/transports/fallback.d.ts +90 -0
- package/dist/types/transports/fallback.d.ts.map +1 -0
- package/dist/types/transports/getHttpRpcClient.d.ts +15 -1
- package/dist/types/transports/getHttpRpcClient.d.ts.map +1 -1
- package/dist/types/transports/http.d.ts +54 -0
- package/dist/types/transports/http.d.ts.map +1 -0
- package/dist/types/transports/types.d.ts +36 -5
- package/dist/types/transports/types.d.ts.map +1 -1
- package/dist/types/transports/utxo.d.ts +1 -1
- package/dist/types/transports/utxo.d.ts.map +1 -1
- package/dist/types/types/account.d.ts +10 -0
- package/dist/types/types/account.d.ts.map +1 -0
- package/dist/types/types/actions.d.ts +21 -0
- package/dist/types/types/actions.d.ts.map +1 -0
- package/dist/types/types/address.d.ts +2 -0
- package/dist/types/types/address.d.ts.map +1 -0
- package/dist/types/types/base.d.ts +1 -0
- package/dist/types/types/base.d.ts.map +1 -0
- package/dist/types/types/block.d.ts +20 -0
- package/dist/types/types/block.d.ts.map +1 -0
- package/dist/types/types/chain.d.ts +49 -0
- package/dist/types/types/chain.d.ts.map +1 -0
- package/dist/types/types/client.d.ts +69 -0
- package/dist/types/types/client.d.ts.map +1 -0
- package/dist/types/types/hash.d.ts +2 -0
- package/dist/types/types/hash.d.ts.map +1 -0
- package/dist/types/types/request.d.ts +49 -0
- package/dist/types/types/request.d.ts.map +1 -0
- package/dist/types/types/rpc.d.ts +35 -0
- package/dist/types/types/rpc.d.ts.map +1 -0
- package/dist/types/types/storage.d.ts +23 -0
- package/dist/types/types/storage.d.ts.map +1 -0
- package/dist/types/types/transport.d.ts +38 -0
- package/dist/types/types/transport.d.ts.map +1 -0
- package/dist/types/types/utils.d.ts +73 -0
- package/dist/types/types/utils.d.ts.map +1 -0
- package/dist/types/utils/buildRequest.d.ts +7 -0
- package/dist/types/utils/buildRequest.d.ts.map +1 -0
- package/dist/types/utils/converter.d.ts +4 -0
- package/dist/types/utils/converter.d.ts.map +1 -0
- package/dist/types/utils/createBatchScheduler.d.ts +22 -0
- package/dist/types/utils/createBatchScheduler.d.ts.map +1 -0
- package/dist/types/utils/deepEqual.d.ts +3 -0
- package/dist/types/utils/deepEqual.d.ts.map +1 -0
- package/dist/types/utils/getAction.d.ts +18 -0
- package/dist/types/utils/getAction.d.ts.map +1 -0
- package/dist/types/utils/getUTXOAddress.d.ts +3 -2
- package/dist/types/utils/getUTXOAddress.d.ts.map +1 -1
- package/dist/types/utils/isUTXOAddress.d.ts.map +1 -1
- package/dist/types/utils/lru.d.ts +12 -0
- package/dist/types/utils/lru.d.ts.map +1 -0
- package/dist/types/utils/observe.d.ts +1 -1
- package/dist/types/utils/observe.d.ts.map +1 -1
- package/dist/types/utils/parseAccount.d.ts +6 -0
- package/dist/types/utils/parseAccount.d.ts.map +1 -0
- package/dist/types/utils/stringify.d.ts +4 -0
- package/dist/types/utils/stringify.d.ts.map +1 -0
- package/dist/types/utils/uid.d.ts +2 -0
- package/dist/types/utils/uid.d.ts.map +1 -0
- package/dist/types/utils/wait.d.ts +2 -0
- package/dist/types/utils/wait.d.ts.map +1 -0
- package/dist/types/utils/withDedupe.d.ts +11 -0
- package/dist/types/utils/withDedupe.d.ts.map +1 -0
- package/dist/types/utils/withResolvers.d.ts +9 -0
- package/dist/types/utils/withResolvers.d.ts.map +1 -0
- package/dist/types/utils/withRetry.d.ts +15 -0
- package/dist/types/utils/withRetry.d.ts.map +1 -0
- package/dist/types/utils/withTimeout.d.ts +10 -0
- package/dist/types/utils/withTimeout.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +4 -3
- package/package.json.tmp +4 -3
- package/src/actions/getBalance.ts +6 -3
- package/src/actions/getBlock.ts +7 -7
- package/src/actions/getBlockCount.ts +4 -1
- package/src/actions/getBlockStats.ts +5 -7
- package/src/actions/getUTXOTransaction.ts +5 -7
- package/src/actions/sendUTXOTransaction.ts +4 -1
- package/src/actions/signPsbt.ts +5 -2
- package/src/actions/waitForTransaction.ts +9 -7
- package/src/actions/watchBlockNumber.ts +5 -2
- package/src/chains/bitcoin.ts +1 -1
- package/src/chains/defineChain.ts +14 -0
- package/src/clients/decorators/public.ts +62 -0
- package/src/clients/decorators/wallet.ts +37 -0
- package/src/errors/address.ts +16 -0
- package/src/errors/base.ts +85 -0
- package/src/errors/block.ts +24 -0
- package/src/errors/config.ts +102 -0
- package/src/errors/provider.ts +11 -0
- package/src/errors/request.ts +134 -0
- package/src/errors/rpc.ts +77 -0
- package/src/errors/transaction.ts +67 -0
- package/src/errors/transport.ts +15 -0
- package/src/errors/utils.ts +6 -0
- package/src/factories/createClient.ts +199 -0
- package/src/factories/createTransport.ts +93 -0
- package/src/index.ts +114 -13
- package/src/transports/custom.ts +56 -0
- package/src/transports/fallback.ts +332 -0
- package/src/transports/getHttpRpcClient.ts +28 -4
- package/src/transports/http.ts +176 -0
- package/src/transports/types.ts +38 -5
- package/src/transports/utxo.ts +6 -9
- package/src/types/account.ts +10 -0
- package/src/types/actions.ts +38 -0
- package/src/types/address.ts +1 -0
- package/src/types/base.ts +0 -0
- package/src/types/block.ts +19 -0
- package/src/types/chain.ts +72 -0
- package/src/types/client.ts +108 -0
- package/src/types/hash.ts +1 -0
- package/src/types/request.ts +87 -0
- package/src/types/rpc.ts +37 -0
- package/src/types/storage.ts +44 -0
- package/src/types/transport.ts +54 -0
- package/src/types/utils.ts +131 -0
- package/src/utils/buildRequest.ts +145 -0
- package/src/utils/converter.ts +25 -0
- package/src/utils/createBatchScheduler.ts +116 -0
- package/src/utils/deepEqual.ts +62 -0
- package/src/utils/getAction.ts +45 -0
- package/src/utils/getUTXOAddress.ts +4 -3
- package/src/utils/isUTXOAddress.ts +2 -1
- package/src/utils/lru.ts +35 -0
- package/src/utils/observe.ts +1 -1
- package/src/utils/parseAccount.ts +14 -0
- package/src/utils/stringify.ts +13 -0
- package/src/utils/uid.ts +14 -0
- package/src/utils/wait.ts +3 -0
- package/src/utils/withDedupe.ts +25 -0
- package/src/utils/withResolvers.ts +19 -0
- package/src/utils/withRetry.ts +60 -0
- package/src/utils/withTimeout.ts +47 -0
- package/src/version.ts +1 -0
- package/tsconfig.json +2 -1
- package/dist/cjs/clients/types.d.ts +0 -27
- package/dist/cjs/clients/types.js.map +0 -1
- package/dist/cjs/decorators/UTXOAPIActions.d.ts +0 -6
- package/dist/cjs/decorators/UTXOAPIActions.js +0 -10
- package/dist/cjs/decorators/UTXOAPIActions.js.map +0 -1
- package/dist/cjs/decorators/UTXOActions.d.ts +0 -10
- package/dist/cjs/decorators/UTXOActions.js +0 -14
- package/dist/cjs/decorators/UTXOActions.js.map +0 -1
- package/dist/esm/clients/types.d.ts +0 -43
- package/dist/esm/clients/types.js +0 -2
- package/dist/esm/clients/types.js.map +0 -1
- package/dist/esm/decorators/UTXOAPIActions.d.ts +0 -6
- package/dist/esm/decorators/UTXOAPIActions.js +0 -7
- package/dist/esm/decorators/UTXOAPIActions.js.map +0 -1
- package/dist/esm/decorators/UTXOActions.d.ts +0 -10
- package/dist/esm/decorators/UTXOActions.js +0 -11
- package/dist/esm/decorators/UTXOActions.js.map +0 -1
- package/dist/types/clients/types.d.ts +0 -44
- package/dist/types/clients/types.d.ts.map +0 -1
- package/dist/types/decorators/UTXOAPIActions.d.ts +0 -7
- package/dist/types/decorators/UTXOAPIActions.d.ts.map +0 -1
- package/dist/types/decorators/UTXOActions.d.ts +0 -11
- package/dist/types/decorators/UTXOActions.d.ts.map +0 -1
- package/src/clients/types.ts +0 -48
- package/src/decorators/UTXOAPIActions.ts +0 -20
- package/src/decorators/UTXOActions.ts +0 -37
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { RpcErrorCode } from '../errors/rpc.js'
|
|
2
|
+
import type { ErrorType } from '../errors/utils.js'
|
|
3
|
+
import { createTransport } from '../factories/createTransport.js'
|
|
4
|
+
import type { Chain } from '../types/chain.js'
|
|
5
|
+
import type {
|
|
6
|
+
CreateTransportErrorType,
|
|
7
|
+
Transport,
|
|
8
|
+
TransportConfig,
|
|
9
|
+
} from '../types/transport.js'
|
|
10
|
+
import { wait } from '../utils/wait.js'
|
|
11
|
+
|
|
12
|
+
// TODO: Narrow `method` & `params` types.
|
|
13
|
+
export type OnResponseFn = (
|
|
14
|
+
args: {
|
|
15
|
+
method: string
|
|
16
|
+
params: unknown[]
|
|
17
|
+
transport: ReturnType<Transport>
|
|
18
|
+
} & (
|
|
19
|
+
| {
|
|
20
|
+
error?: undefined
|
|
21
|
+
response: unknown
|
|
22
|
+
status: 'success'
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
error: Error
|
|
26
|
+
response?: undefined
|
|
27
|
+
status: 'error'
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
) => void
|
|
31
|
+
|
|
32
|
+
type RankOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* The polling interval (in ms) at which the ranker should ping the RPC URL.
|
|
35
|
+
* @default client.pollingInterval
|
|
36
|
+
*/
|
|
37
|
+
interval?: number | undefined
|
|
38
|
+
/**
|
|
39
|
+
* Ping method to determine latency.
|
|
40
|
+
*/
|
|
41
|
+
ping?: (parameters: { transport: ReturnType<Transport> }) =>
|
|
42
|
+
| Promise<unknown>
|
|
43
|
+
| undefined
|
|
44
|
+
/**
|
|
45
|
+
* The number of previous samples to perform ranking on.
|
|
46
|
+
* @default 10
|
|
47
|
+
*/
|
|
48
|
+
sampleCount?: number | undefined
|
|
49
|
+
/**
|
|
50
|
+
* Timeout when sampling transports.
|
|
51
|
+
* @default 1_000
|
|
52
|
+
*/
|
|
53
|
+
timeout?: number | undefined
|
|
54
|
+
/**
|
|
55
|
+
* Weights to apply to the scores. Weight values are proportional.
|
|
56
|
+
*/
|
|
57
|
+
weights?:
|
|
58
|
+
| {
|
|
59
|
+
/**
|
|
60
|
+
* The weight to apply to the latency score.
|
|
61
|
+
* @default 0.3
|
|
62
|
+
*/
|
|
63
|
+
latency?: number | undefined
|
|
64
|
+
/**
|
|
65
|
+
* The weight to apply to the stability score.
|
|
66
|
+
* @default 0.7
|
|
67
|
+
*/
|
|
68
|
+
stability?: number | undefined
|
|
69
|
+
}
|
|
70
|
+
| undefined
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type FallbackTransportConfig = {
|
|
74
|
+
/** The key of the Fallback transport. */
|
|
75
|
+
key?: TransportConfig['key'] | undefined
|
|
76
|
+
/** The name of the Fallback transport. */
|
|
77
|
+
name?: TransportConfig['name'] | undefined
|
|
78
|
+
/** Toggle to enable ranking, or rank options. */
|
|
79
|
+
rank?: boolean | RankOptions | undefined
|
|
80
|
+
/** The max number of times to retry. */
|
|
81
|
+
retryCount?: TransportConfig['retryCount'] | undefined
|
|
82
|
+
/** The base delay (in ms) between retries. */
|
|
83
|
+
retryDelay?: TransportConfig['retryDelay'] | undefined
|
|
84
|
+
/** Callback on whether an error should throw or try the next transport in the fallback. */
|
|
85
|
+
shouldThrow?: (error: Error) => boolean | undefined
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type FallbackTransport<
|
|
89
|
+
transports extends readonly Transport[] = readonly Transport[],
|
|
90
|
+
> = Transport<
|
|
91
|
+
'fallback',
|
|
92
|
+
{
|
|
93
|
+
onResponse: (fn: OnResponseFn) => void
|
|
94
|
+
transports: {
|
|
95
|
+
[key in keyof transports]: ReturnType<transports[key]>
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
>
|
|
99
|
+
|
|
100
|
+
export type FallbackTransportErrorType = CreateTransportErrorType | ErrorType
|
|
101
|
+
|
|
102
|
+
export function fallback<const transports extends readonly Transport[]>(
|
|
103
|
+
transports_: transports,
|
|
104
|
+
config: FallbackTransportConfig = {}
|
|
105
|
+
): FallbackTransport<transports> {
|
|
106
|
+
const {
|
|
107
|
+
key = 'fallback',
|
|
108
|
+
name = 'Fallback',
|
|
109
|
+
rank = false,
|
|
110
|
+
shouldThrow: shouldThrow_ = shouldThrow,
|
|
111
|
+
retryCount,
|
|
112
|
+
retryDelay,
|
|
113
|
+
} = config
|
|
114
|
+
return (({ chain, pollingInterval = 4_000, timeout, ...rest }) => {
|
|
115
|
+
let transports = transports_
|
|
116
|
+
|
|
117
|
+
let onResponse: OnResponseFn = () => {}
|
|
118
|
+
|
|
119
|
+
const transport = createTransport(
|
|
120
|
+
{
|
|
121
|
+
key,
|
|
122
|
+
name,
|
|
123
|
+
async request({ method, params }) {
|
|
124
|
+
let includes: boolean | undefined
|
|
125
|
+
|
|
126
|
+
const fetch = async (i = 0): Promise<any> => {
|
|
127
|
+
const transport = transports[i]({
|
|
128
|
+
...rest,
|
|
129
|
+
chain,
|
|
130
|
+
retryCount: 0,
|
|
131
|
+
timeout,
|
|
132
|
+
})
|
|
133
|
+
try {
|
|
134
|
+
const response = await transport.request({
|
|
135
|
+
method,
|
|
136
|
+
params,
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
onResponse({
|
|
140
|
+
method,
|
|
141
|
+
params: params as unknown[],
|
|
142
|
+
response,
|
|
143
|
+
transport,
|
|
144
|
+
status: 'success',
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
return response
|
|
148
|
+
} catch (err) {
|
|
149
|
+
onResponse({
|
|
150
|
+
error: err as Error,
|
|
151
|
+
method,
|
|
152
|
+
params: params as unknown[],
|
|
153
|
+
transport,
|
|
154
|
+
status: 'error',
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
if (shouldThrow_(err as Error)) {
|
|
158
|
+
throw err
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// If we've reached the end of the fallbacks, throw the error.
|
|
162
|
+
if (i === transports.length - 1) {
|
|
163
|
+
throw err
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Check if at least one other transport includes the method
|
|
167
|
+
includes ??= transports.slice(i + 1).some((transport) => {
|
|
168
|
+
const { include, exclude } =
|
|
169
|
+
transport({ chain }).config.methods || {}
|
|
170
|
+
if (include) {
|
|
171
|
+
return include.includes(method)
|
|
172
|
+
}
|
|
173
|
+
if (exclude) {
|
|
174
|
+
return !exclude.includes(method)
|
|
175
|
+
}
|
|
176
|
+
return true
|
|
177
|
+
})
|
|
178
|
+
if (!includes) {
|
|
179
|
+
throw err
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Otherwise, try the next fallback.
|
|
183
|
+
return fetch(i + 1)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return fetch()
|
|
187
|
+
},
|
|
188
|
+
retryCount,
|
|
189
|
+
retryDelay,
|
|
190
|
+
type: 'fallback',
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
onResponse: (fn: OnResponseFn) => {
|
|
194
|
+
onResponse = fn
|
|
195
|
+
},
|
|
196
|
+
transports: transports.map((fn) => fn({ chain, retryCount: 0 })),
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
if (rank) {
|
|
201
|
+
const rankOptions = (typeof rank === 'object' ? rank : {}) as RankOptions
|
|
202
|
+
rankTransports({
|
|
203
|
+
chain,
|
|
204
|
+
interval: rankOptions.interval ?? pollingInterval,
|
|
205
|
+
onTransports: (transports_) => {
|
|
206
|
+
transports = transports_ as transports
|
|
207
|
+
},
|
|
208
|
+
ping: rankOptions.ping,
|
|
209
|
+
sampleCount: rankOptions.sampleCount,
|
|
210
|
+
timeout: rankOptions.timeout,
|
|
211
|
+
transports,
|
|
212
|
+
weights: rankOptions.weights,
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
return transport
|
|
216
|
+
}) as FallbackTransport<transports>
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function shouldThrow(error: Error) {
|
|
220
|
+
if ('code' in error && typeof error.code === 'number') {
|
|
221
|
+
if (
|
|
222
|
+
error.code === RpcErrorCode.INTERNAL_ERROR ||
|
|
223
|
+
error.code === RpcErrorCode.USER_REJECTION ||
|
|
224
|
+
error.code === 5000 // CAIP UserRejectedRequestError
|
|
225
|
+
) {
|
|
226
|
+
return true
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** @internal */
|
|
233
|
+
export function rankTransports({
|
|
234
|
+
chain,
|
|
235
|
+
interval = 4_000,
|
|
236
|
+
onTransports,
|
|
237
|
+
ping,
|
|
238
|
+
sampleCount = 10,
|
|
239
|
+
timeout = 1_000,
|
|
240
|
+
transports,
|
|
241
|
+
weights = {},
|
|
242
|
+
}: {
|
|
243
|
+
chain?: Chain | undefined
|
|
244
|
+
interval: RankOptions['interval']
|
|
245
|
+
onTransports: (transports: readonly Transport[]) => void
|
|
246
|
+
ping?: RankOptions['ping'] | undefined
|
|
247
|
+
sampleCount?: RankOptions['sampleCount'] | undefined
|
|
248
|
+
timeout?: RankOptions['timeout'] | undefined
|
|
249
|
+
transports: readonly Transport[]
|
|
250
|
+
weights?: RankOptions['weights'] | undefined
|
|
251
|
+
}) {
|
|
252
|
+
const { stability: stabilityWeight = 0.7, latency: latencyWeight = 0.3 } =
|
|
253
|
+
weights
|
|
254
|
+
|
|
255
|
+
type SampleData = { latency: number; success: number }
|
|
256
|
+
type Sample = SampleData[]
|
|
257
|
+
const samples: Sample[] = []
|
|
258
|
+
|
|
259
|
+
const rankTransports_ = async () => {
|
|
260
|
+
// 1. Take a sample from each Transport.
|
|
261
|
+
const sample: Sample = await Promise.all(
|
|
262
|
+
transports.map(async (transport) => {
|
|
263
|
+
const transport_ = transport({ chain, retryCount: 0, timeout })
|
|
264
|
+
|
|
265
|
+
const start = Date.now()
|
|
266
|
+
let end: number
|
|
267
|
+
let success: number
|
|
268
|
+
try {
|
|
269
|
+
await (ping
|
|
270
|
+
? ping({ transport: transport_ })
|
|
271
|
+
: transport_.request({
|
|
272
|
+
method: 'net_listening',
|
|
273
|
+
params: undefined,
|
|
274
|
+
}))
|
|
275
|
+
success = 1
|
|
276
|
+
} catch {
|
|
277
|
+
success = 0
|
|
278
|
+
} finally {
|
|
279
|
+
end = Date.now()
|
|
280
|
+
}
|
|
281
|
+
const latency = end - start
|
|
282
|
+
return { latency, success }
|
|
283
|
+
})
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
// 2. Store the sample. If we have more than `sampleCount` samples, remove
|
|
287
|
+
// the oldest sample.
|
|
288
|
+
samples.push(sample)
|
|
289
|
+
if (samples.length > sampleCount) {
|
|
290
|
+
samples.shift()
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// 3. Calculate the max latency from samples.
|
|
294
|
+
const maxLatency = Math.max(
|
|
295
|
+
...samples.map((sample) =>
|
|
296
|
+
Math.max(...sample.map(({ latency }) => latency))
|
|
297
|
+
)
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
// 4. Calculate the score for each Transport.
|
|
301
|
+
const scores = transports
|
|
302
|
+
.map((_, i) => {
|
|
303
|
+
const latencies = samples.map((sample) => sample[i].latency)
|
|
304
|
+
const meanLatency =
|
|
305
|
+
latencies.reduce((acc, latency) => acc + latency, 0) /
|
|
306
|
+
latencies.length
|
|
307
|
+
const latencyScore = 1 - meanLatency / maxLatency
|
|
308
|
+
|
|
309
|
+
const successes = samples.map((sample) => sample[i].success)
|
|
310
|
+
const stabilityScore =
|
|
311
|
+
successes.reduce((acc, success) => acc + success, 0) /
|
|
312
|
+
successes.length
|
|
313
|
+
|
|
314
|
+
if (stabilityScore === 0) {
|
|
315
|
+
return [0, i]
|
|
316
|
+
}
|
|
317
|
+
return [
|
|
318
|
+
latencyWeight * latencyScore + stabilityWeight * stabilityScore,
|
|
319
|
+
i,
|
|
320
|
+
]
|
|
321
|
+
})
|
|
322
|
+
.sort((a, b) => b[0] - a[0])
|
|
323
|
+
|
|
324
|
+
// 5. Sort the Transports by score.
|
|
325
|
+
onTransports(scores.map(([, i]) => transports[i]))
|
|
326
|
+
|
|
327
|
+
// 6. Wait, and then rank again.
|
|
328
|
+
await wait(interval)
|
|
329
|
+
rankTransports_()
|
|
330
|
+
}
|
|
331
|
+
rankTransports_()
|
|
332
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { HttpRequestError, TimeoutError
|
|
2
|
-
import type {
|
|
1
|
+
import { HttpRequestError, TimeoutError } from '../errors/request.js'
|
|
2
|
+
import type { RpcResponse } from '../types/rpc.js'
|
|
3
|
+
import type { MaybePromise } from '../types/utils.js'
|
|
4
|
+
import { stringify } from '../utils/stringify.js'
|
|
5
|
+
import { withTimeout } from '../utils/withTimeout.js'
|
|
3
6
|
|
|
4
7
|
export type RpcRequest = {
|
|
5
8
|
jsonrpc?: '2.0'
|
|
@@ -8,6 +11,28 @@ export type RpcRequest = {
|
|
|
8
11
|
id?: number
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
export type HttpRequestReturnType<
|
|
15
|
+
body extends RpcRequest | RpcRequest[] = RpcRequest,
|
|
16
|
+
> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse
|
|
17
|
+
|
|
18
|
+
export type HttpRpcClientOptions = {
|
|
19
|
+
/** Request configuration to pass to `fetch`. */
|
|
20
|
+
fetchOptions?: Omit<RequestInit, 'body'> | undefined
|
|
21
|
+
/** A callback to handle the request. */
|
|
22
|
+
onRequest?:
|
|
23
|
+
| ((
|
|
24
|
+
request: Request,
|
|
25
|
+
init: RequestInit
|
|
26
|
+
) => MaybePromise<
|
|
27
|
+
void | undefined | (RequestInit & { url?: string | undefined })
|
|
28
|
+
>)
|
|
29
|
+
| undefined
|
|
30
|
+
/** A callback to handle the response. */
|
|
31
|
+
onResponse?: ((response: Response) => Promise<void> | void) | undefined
|
|
32
|
+
/** The timeout (in ms) for the request. */
|
|
33
|
+
timeout?: number | undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
export type HttpRequestParameters<
|
|
12
37
|
body extends RpcRequest | RpcRequest[] = RpcRequest,
|
|
13
38
|
> = {
|
|
@@ -62,7 +87,7 @@ export function getHttpRpcClient(
|
|
|
62
87
|
: undefined),
|
|
63
88
|
...headers,
|
|
64
89
|
},
|
|
65
|
-
method: method,
|
|
90
|
+
method: method || 'POST',
|
|
66
91
|
signal: signal_ || (timeout > 0 ? signal : null),
|
|
67
92
|
}
|
|
68
93
|
const request = new Request(params.url ?? url, init)
|
|
@@ -102,7 +127,6 @@ export function getHttpRpcClient(
|
|
|
102
127
|
url,
|
|
103
128
|
})
|
|
104
129
|
}
|
|
105
|
-
|
|
106
130
|
return data
|
|
107
131
|
} catch (err) {
|
|
108
132
|
if (err instanceof HttpRequestError) {
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { RpcRequestError } from '../errors/request.js'
|
|
2
|
+
import {
|
|
3
|
+
UrlRequiredError,
|
|
4
|
+
type UrlRequiredErrorType,
|
|
5
|
+
} from '../errors/transport.js'
|
|
6
|
+
import type { ErrorType } from '../errors/utils.js'
|
|
7
|
+
import {
|
|
8
|
+
type CreateTransportErrorType,
|
|
9
|
+
type Transport,
|
|
10
|
+
type TransportConfig,
|
|
11
|
+
createTransport,
|
|
12
|
+
} from '../factories/createTransport.js'
|
|
13
|
+
import type { BtcRpcRequestFn, RpcSchema } from '../types/request.js'
|
|
14
|
+
import { createBatchScheduler } from '../utils/createBatchScheduler.js'
|
|
15
|
+
import {
|
|
16
|
+
type HttpRpcClientOptions,
|
|
17
|
+
type RpcRequest,
|
|
18
|
+
getHttpRpcClient,
|
|
19
|
+
} from './getHttpRpcClient.js'
|
|
20
|
+
|
|
21
|
+
export type HttpTransportConfig<
|
|
22
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
23
|
+
raw extends boolean = false,
|
|
24
|
+
> = {
|
|
25
|
+
/**
|
|
26
|
+
* Whether to enable Batch JSON-RPC.
|
|
27
|
+
* @link https://www.jsonrpc.org/specification#batch
|
|
28
|
+
*/
|
|
29
|
+
batch?:
|
|
30
|
+
| boolean
|
|
31
|
+
| {
|
|
32
|
+
/** The maximum number of JSON-RPC requests to send in a batch. @default 1_000 */
|
|
33
|
+
batchSize?: number | undefined
|
|
34
|
+
/** The maximum number of milliseconds to wait before sending a batch. @default 0 */
|
|
35
|
+
wait?: number | undefined
|
|
36
|
+
}
|
|
37
|
+
| undefined
|
|
38
|
+
/**
|
|
39
|
+
* Request configuration to pass to `fetch`.
|
|
40
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
|
41
|
+
*/
|
|
42
|
+
fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined
|
|
43
|
+
/** A callback to handle the response from `fetch`. */
|
|
44
|
+
onFetchRequest?: HttpRpcClientOptions['onRequest'] | undefined
|
|
45
|
+
/** A callback to handle the response from `fetch`. */
|
|
46
|
+
onFetchResponse?: HttpRpcClientOptions['onResponse'] | undefined
|
|
47
|
+
/** The key of the HTTP transport. */
|
|
48
|
+
key?: TransportConfig['key'] | undefined
|
|
49
|
+
/** Methods to include or exclude from executing RPC requests. */
|
|
50
|
+
methods?: TransportConfig['methods'] | undefined
|
|
51
|
+
/** The name of the HTTP transport. */
|
|
52
|
+
name?: TransportConfig['name'] | undefined
|
|
53
|
+
/** Whether to return JSON RPC errors as responses instead of throwing. */
|
|
54
|
+
raw?: raw | boolean | undefined
|
|
55
|
+
/** The max number of times to retry. */
|
|
56
|
+
retryCount?: TransportConfig['retryCount'] | undefined
|
|
57
|
+
/** The base delay (in ms) between retries. */
|
|
58
|
+
retryDelay?: TransportConfig['retryDelay'] | undefined
|
|
59
|
+
/** Typed JSON-RPC schema for the transport. */
|
|
60
|
+
rpcSchema?: rpcSchema | RpcSchema | undefined
|
|
61
|
+
/** The timeout (in ms) for the HTTP request. Default: 10_000 */
|
|
62
|
+
timeout?: TransportConfig['timeout'] | undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type HttpTransport<
|
|
66
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
67
|
+
raw extends boolean = false,
|
|
68
|
+
> = Transport<
|
|
69
|
+
'http',
|
|
70
|
+
{
|
|
71
|
+
fetchOptions?: HttpTransportConfig['fetchOptions'] | undefined
|
|
72
|
+
url?: string | undefined
|
|
73
|
+
},
|
|
74
|
+
BtcRpcRequestFn<rpcSchema, raw>
|
|
75
|
+
>
|
|
76
|
+
|
|
77
|
+
export type HttpTransportErrorType =
|
|
78
|
+
| CreateTransportErrorType
|
|
79
|
+
| UrlRequiredErrorType
|
|
80
|
+
| ErrorType
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @description Creates a HTTP transport that connects to a JSON-RPC API.
|
|
84
|
+
*/
|
|
85
|
+
export function http<
|
|
86
|
+
rpcSchema extends RpcSchema | undefined = undefined,
|
|
87
|
+
raw extends boolean = false,
|
|
88
|
+
>(
|
|
89
|
+
/** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */
|
|
90
|
+
url?: string | undefined,
|
|
91
|
+
config: HttpTransportConfig<rpcSchema, raw> = {}
|
|
92
|
+
): HttpTransport<rpcSchema, raw> {
|
|
93
|
+
const {
|
|
94
|
+
batch,
|
|
95
|
+
fetchOptions,
|
|
96
|
+
key = 'http',
|
|
97
|
+
methods,
|
|
98
|
+
name = 'HTTP JSON-RPC',
|
|
99
|
+
onFetchRequest,
|
|
100
|
+
onFetchResponse,
|
|
101
|
+
retryDelay,
|
|
102
|
+
raw,
|
|
103
|
+
} = config
|
|
104
|
+
return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
|
|
105
|
+
const { batchSize = 1000, wait = 0 } =
|
|
106
|
+
typeof batch === 'object' ? batch : {}
|
|
107
|
+
const retryCount = config.retryCount ?? retryCount_
|
|
108
|
+
const timeout = timeout_ ?? config.timeout ?? 10_000
|
|
109
|
+
const url_ = url || chain?.rpcUrls.default.http[0]
|
|
110
|
+
if (!url_) {
|
|
111
|
+
throw new UrlRequiredError()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const rpcClient = getHttpRpcClient(url_, {
|
|
115
|
+
fetchOptions,
|
|
116
|
+
onRequest: onFetchRequest,
|
|
117
|
+
onResponse: onFetchResponse,
|
|
118
|
+
timeout,
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
return createTransport(
|
|
122
|
+
{
|
|
123
|
+
key,
|
|
124
|
+
methods,
|
|
125
|
+
name,
|
|
126
|
+
async request({ method, params }) {
|
|
127
|
+
const body = { method, params }
|
|
128
|
+
|
|
129
|
+
const { schedule } = createBatchScheduler({
|
|
130
|
+
id: url_,
|
|
131
|
+
wait,
|
|
132
|
+
shouldSplitBatch(requests) {
|
|
133
|
+
return requests.length > batchSize
|
|
134
|
+
},
|
|
135
|
+
fn: (body: RpcRequest[]) =>
|
|
136
|
+
rpcClient.request({
|
|
137
|
+
body,
|
|
138
|
+
}),
|
|
139
|
+
sort: (a, b) => a.id - b.id,
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const fn = async (body: RpcRequest) =>
|
|
143
|
+
batch
|
|
144
|
+
? schedule(body)
|
|
145
|
+
: [
|
|
146
|
+
await rpcClient.request({
|
|
147
|
+
body,
|
|
148
|
+
}),
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
const [{ error, result }] = await fn(body)
|
|
152
|
+
|
|
153
|
+
if (raw) {
|
|
154
|
+
return { error, result }
|
|
155
|
+
}
|
|
156
|
+
if (error) {
|
|
157
|
+
throw new RpcRequestError({
|
|
158
|
+
body,
|
|
159
|
+
error,
|
|
160
|
+
url: url_,
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
return result
|
|
164
|
+
},
|
|
165
|
+
retryCount,
|
|
166
|
+
retryDelay,
|
|
167
|
+
timeout,
|
|
168
|
+
type: 'http',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
fetchOptions,
|
|
172
|
+
url: url_,
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
}
|
package/src/transports/types.ts
CHANGED
|
@@ -33,9 +33,6 @@ export type UTXOSchema = [
|
|
|
33
33
|
Parameters: [string, boolean, string?]
|
|
34
34
|
ReturnType: UTXOTransaction
|
|
35
35
|
},
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
export type UTXOAPISchema = [
|
|
39
36
|
{
|
|
40
37
|
Method: 'getBalance'
|
|
41
38
|
Parameters: { address: string }
|
|
@@ -43,7 +40,43 @@ export type UTXOAPISchema = [
|
|
|
43
40
|
},
|
|
44
41
|
]
|
|
45
42
|
|
|
46
|
-
export type
|
|
43
|
+
export type SignPsbtParameters = {
|
|
44
|
+
/** The PSBT encoded as a hexadecimal string */
|
|
45
|
+
psbt: string
|
|
46
|
+
/**
|
|
47
|
+
* Array of objects specifying details about the inputs to be signed
|
|
48
|
+
*/
|
|
49
|
+
inputsToSign: {
|
|
50
|
+
/**
|
|
51
|
+
* The SigHash type to use for signing (e.g., SIGHASH_ALL).
|
|
52
|
+
* If not specified, a default value is used.
|
|
53
|
+
*/
|
|
54
|
+
sigHash?: number
|
|
55
|
+
/** The Bitcoin address associated with the input that will be signed */
|
|
56
|
+
address: string
|
|
57
|
+
/** An array of indexes in the PSBT corresponding to the inputs that need to be signed */
|
|
58
|
+
signingIndexes: number[]
|
|
59
|
+
}[]
|
|
60
|
+
/**
|
|
61
|
+
* Whether to finalize the PSBT after signing.
|
|
62
|
+
* If `true`, the PSBT will be completed and ready for broadcasting.
|
|
63
|
+
* If `false` or omitted, the PSBT remains partially signed.
|
|
64
|
+
* Some wallets does not support it.
|
|
65
|
+
*/
|
|
66
|
+
finalize?: boolean
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type SignPsbtReturnType = string
|
|
70
|
+
|
|
71
|
+
export type UTXOWalletSchema = readonly [
|
|
72
|
+
{
|
|
73
|
+
Method: 'signPsbt'
|
|
74
|
+
Parameters: SignPsbtParameters
|
|
75
|
+
ReturnType: SignPsbtReturnType
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
export type UTXOMethod = UTXOSchema[number]['Method']
|
|
47
80
|
|
|
48
81
|
export type SuccessResult<result> = {
|
|
49
82
|
method?: undefined
|
|
@@ -67,5 +100,5 @@ export type RpcMethodHandler = (
|
|
|
67
100
|
) => Promise<RpcResponse>
|
|
68
101
|
|
|
69
102
|
export type RpcMethods = {
|
|
70
|
-
[key in
|
|
103
|
+
[key in UTXOMethod]?: RpcMethodHandler
|
|
71
104
|
}
|
package/src/transports/utxo.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
RpcRequestError,
|
|
5
|
-
UrlRequiredError,
|
|
6
|
-
createTransport,
|
|
7
|
-
} from 'viem'
|
|
1
|
+
import { RpcRequestError } from '../errors/request.js'
|
|
2
|
+
import { UrlRequiredError } from '../errors/transport.js'
|
|
3
|
+
import { createTransport } from '../factories/createTransport.js'
|
|
8
4
|
import { getHttpRpcClient } from './getHttpRpcClient.js'
|
|
9
5
|
import { getRpcProviderMethods } from './getRpcProviderMethods.js'
|
|
10
|
-
import type {
|
|
6
|
+
import type { HttpTransport, HttpTransportConfig } from './http.js'
|
|
7
|
+
import type { UTXOMethod } from './types.js'
|
|
11
8
|
|
|
12
9
|
type UTXOHttpTransportConfig = HttpTransportConfig & {
|
|
13
10
|
includeChainToURL?: boolean
|
|
@@ -52,7 +49,7 @@ export function utxo(
|
|
|
52
49
|
name,
|
|
53
50
|
async request({ method, params }) {
|
|
54
51
|
const body = { method, params }
|
|
55
|
-
const methodHandler = rpcMethods?.[method as
|
|
52
|
+
const methodHandler = rpcMethods?.[method as UTXOMethod]
|
|
56
53
|
const { error, result } = await (methodHandler?.(
|
|
57
54
|
client,
|
|
58
55
|
url_,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Address } from './address.js'
|
|
2
|
+
|
|
3
|
+
export interface Account {
|
|
4
|
+
address: Address
|
|
5
|
+
addressType: 'p2tr' | 'p2wpkh' | 'p2wsh' | 'p2sh' | 'p2pkh'
|
|
6
|
+
publicKey: string
|
|
7
|
+
purpose: 'payment' | 'ordinals'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface BtcAccount extends Account {}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SendUTXOTransactionParameters,
|
|
3
|
+
SendUTXOTransactionReturnType,
|
|
4
|
+
} from '../actions/sendUTXOTransaction'
|
|
5
|
+
|
|
6
|
+
import type { WaitForTransactionReceiptParameters } from '../actions/waitForTransaction'
|
|
7
|
+
import type {
|
|
8
|
+
SignPsbtParameters,
|
|
9
|
+
SignPsbtReturnType,
|
|
10
|
+
} from '../transports/types'
|
|
11
|
+
import type { UTXOTransaction } from './transaction'
|
|
12
|
+
|
|
13
|
+
export type WaitForTransactionReceiptReturnType = UTXOTransaction
|
|
14
|
+
|
|
15
|
+
export type WithRetryParameters = {
|
|
16
|
+
// The delay (in ms) between retries.
|
|
17
|
+
delay?:
|
|
18
|
+
| ((config: { count: number; error: Error }) => number)
|
|
19
|
+
| number
|
|
20
|
+
| undefined
|
|
21
|
+
// The max number of times to retry.
|
|
22
|
+
retryCount?: number | undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type WalletActions = {
|
|
26
|
+
/**
|
|
27
|
+
* Creates, signs, and sends a new transaction to the network.
|
|
28
|
+
*/
|
|
29
|
+
sendUTXOTransaction: (
|
|
30
|
+
args: SendUTXOTransactionParameters
|
|
31
|
+
) => Promise<SendUTXOTransactionReturnType>
|
|
32
|
+
|
|
33
|
+
signPbst: (args: SignPsbtParameters) => Promise<SignPsbtReturnType>
|
|
34
|
+
|
|
35
|
+
waitForTransactionReceipt: (
|
|
36
|
+
args: WaitForTransactionReceiptParameters
|
|
37
|
+
) => Promise<WaitForTransactionReceiptReturnType>
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Address = string
|
|
File without changes
|