@bigmi/core 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/actions/getBalance.js.map +1 -1
- package/dist/cjs/actions/getBlock.js +0 -1
- package/dist/cjs/actions/getBlock.js.map +1 -1
- package/dist/cjs/actions/getBlockCount.js.map +1 -1
- package/dist/cjs/actions/getBlockStats.js.map +1 -1
- package/dist/cjs/actions/getTransactionFee.js.map +1 -1
- package/dist/cjs/actions/getTransactions.js.map +1 -1
- package/dist/cjs/actions/getUTXOTransaction.js.map +1 -1
- package/dist/cjs/actions/getUTXOs.js.map +1 -1
- package/dist/cjs/actions/getXPubAddresses.js.map +1 -1
- package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -1
- package/dist/cjs/actions/signPsbt.js.map +1 -1
- package/dist/cjs/actions/waitForTransaction.js +0 -1
- package/dist/cjs/actions/waitForTransaction.js.map +1 -1
- package/dist/cjs/actions/watchBlockNumber.js.map +1 -1
- package/dist/cjs/chains/bitcoin.js +3 -3
- package/dist/cjs/chains/bitcoin.js.map +1 -1
- package/dist/cjs/chains/defineChain.js.map +1 -1
- package/dist/cjs/chains/signet.js +3 -3
- package/dist/cjs/chains/signet.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/decorators/wallet.js.map +1 -1
- package/dist/cjs/errors/address.js.map +1 -1
- package/dist/cjs/errors/base.js.map +1 -1
- package/dist/cjs/errors/block.js.map +1 -1
- package/dist/cjs/errors/provider.js.map +1 -1
- package/dist/cjs/errors/request.js.map +1 -1
- package/dist/cjs/errors/rpc.js +3 -3
- package/dist/cjs/errors/rpc.js.map +1 -1
- package/dist/cjs/errors/transaction.js.map +1 -1
- package/dist/cjs/errors/transport.js.map +1 -1
- package/dist/cjs/errors/utxo.js.map +1 -1
- package/dist/cjs/factories/createClient.js.map +1 -1
- package/dist/cjs/factories/createTransport.js.map +1 -1
- package/dist/cjs/test/utils.js.map +1 -1
- package/dist/cjs/transports/ankr/ankr.js.map +1 -1
- package/dist/cjs/transports/ankr/getBalance.js +2 -2
- package/dist/cjs/transports/ankr/getBalance.js.map +1 -1
- package/dist/cjs/transports/ankr/getTransactionFee.js.map +1 -1
- package/dist/cjs/transports/ankr/getTransactions.js.map +1 -1
- package/dist/cjs/transports/ankr/methods.js.map +1 -1
- package/dist/cjs/transports/ankr/utils.js.map +1 -1
- package/dist/cjs/transports/blockchair/blockchair.js.map +1 -1
- package/dist/cjs/transports/blockchair/getBalance.js +2 -2
- package/dist/cjs/transports/blockchair/getBalance.js.map +1 -1
- package/dist/cjs/transports/blockchair/getTransactionFee.js +2 -2
- package/dist/cjs/transports/blockchair/getTransactionFee.js.map +1 -1
- package/dist/cjs/transports/blockchair/getUTXOs.js +2 -2
- package/dist/cjs/transports/blockchair/getUTXOs.js.map +1 -1
- package/dist/cjs/transports/blockchair/getXPubAddresses.js +2 -2
- package/dist/cjs/transports/blockchair/getXPubAddresses.js.map +1 -1
- package/dist/cjs/transports/blockchair/methods.js.map +1 -1
- package/dist/cjs/transports/blockcypher/blockcypher.js.map +1 -1
- package/dist/cjs/transports/blockcypher/getBalance.js.map +1 -1
- package/dist/cjs/transports/blockcypher/getTransactionFee.js.map +1 -1
- package/dist/cjs/transports/blockcypher/getUTXOs.js.map +1 -1
- package/dist/cjs/transports/blockcypher/methods.js.map +1 -1
- package/dist/cjs/transports/blockcypher/utils.js +3 -3
- package/dist/cjs/transports/blockcypher/utils.js.map +1 -1
- package/dist/cjs/transports/custom.js.map +1 -1
- package/dist/cjs/transports/fallback.js +2 -2
- package/dist/cjs/transports/fallback.js.map +1 -1
- package/dist/cjs/transports/getHttpRpcClient.js.map +1 -1
- package/dist/cjs/transports/getRpcProviderMethods.js.map +1 -1
- package/dist/cjs/transports/http.js.map +1 -1
- package/dist/cjs/transports/mempool/getBalance.js.map +1 -1
- package/dist/cjs/transports/mempool/getTransactionFee.js.map +1 -1
- package/dist/cjs/transports/mempool/getTransactions.js.map +1 -1
- package/dist/cjs/transports/mempool/mempool.js.map +1 -1
- package/dist/cjs/transports/mempool/methods.js.map +1 -1
- package/dist/cjs/transports/mempool/utils.js.map +1 -1
- package/dist/cjs/transports/types.js.map +1 -1
- package/dist/cjs/transports/utxo.js.map +1 -1
- package/dist/cjs/types/address.js.map +1 -1
- package/dist/cjs/types/chain.js.map +1 -1
- package/dist/cjs/utils/buildRequest.js +3 -3
- package/dist/cjs/utils/buildRequest.js.map +1 -1
- package/dist/cjs/utils/cancelTransaction.js +0 -1
- package/dist/cjs/utils/cancelTransaction.js.map +1 -1
- package/dist/cjs/utils/converter.js.map +1 -1
- package/dist/cjs/utils/createBatchScheduler.js +1 -1
- package/dist/cjs/utils/createBatchScheduler.js.map +1 -1
- package/dist/cjs/utils/deepEqual.js.map +1 -1
- package/dist/cjs/utils/getAction.js.map +1 -1
- package/dist/cjs/utils/getAddressInfo.js +26 -26
- package/dist/cjs/utils/getAddressInfo.js.map +1 -1
- package/dist/cjs/utils/idCache.js.map +1 -1
- package/dist/cjs/utils/isAddress.js.map +1 -1
- package/dist/cjs/utils/lru.js.map +1 -1
- package/dist/cjs/utils/modifyFee.js +0 -1
- package/dist/cjs/utils/modifyFee.js.map +1 -1
- package/dist/cjs/utils/observe.js +2 -2
- package/dist/cjs/utils/observe.js.map +1 -1
- package/dist/cjs/utils/parseAccount.js.map +1 -1
- package/dist/cjs/utils/poll.js.map +1 -1
- package/dist/cjs/utils/retryUntil.js.map +1 -1
- package/dist/cjs/utils/sleep.js.map +1 -1
- package/dist/cjs/utils/stringify.js.map +1 -1
- package/dist/cjs/utils/uid.js.map +1 -1
- package/dist/cjs/utils/url.js.map +1 -1
- package/dist/cjs/utils/wait.js.map +1 -1
- package/dist/cjs/utils/withDedupe.js +1 -1
- package/dist/cjs/utils/withDedupe.js.map +1 -1
- package/dist/cjs/utils/withResolvers.js.map +1 -1
- package/dist/cjs/utils/withRetry.js.map +1 -1
- package/dist/cjs/utils/withTimeout.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/getBalance.d.ts.map +1 -1
- package/dist/esm/actions/getBalance.js.map +1 -1
- package/dist/esm/actions/getBlock.d.ts.map +1 -1
- package/dist/esm/actions/getBlock.js.map +1 -1
- package/dist/esm/actions/getBlockCount.d.ts.map +1 -1
- package/dist/esm/actions/getBlockCount.js.map +1 -1
- package/dist/esm/actions/getBlockStats.d.ts.map +1 -1
- package/dist/esm/actions/getBlockStats.js.map +1 -1
- package/dist/esm/actions/getTransactionFee.d.ts.map +1 -1
- package/dist/esm/actions/getTransactionFee.js.map +1 -1
- package/dist/esm/actions/getTransactions.d.ts.map +1 -1
- package/dist/esm/actions/getTransactions.js.map +1 -1
- package/dist/esm/actions/getUTXOTransaction.d.ts.map +1 -1
- package/dist/esm/actions/getUTXOTransaction.js.map +1 -1
- package/dist/esm/actions/getUTXOs.d.ts.map +1 -1
- package/dist/esm/actions/getUTXOs.js.map +1 -1
- package/dist/esm/actions/getXPubAddresses.d.ts.map +1 -1
- package/dist/esm/actions/getXPubAddresses.js.map +1 -1
- package/dist/esm/actions/sendUTXOTransaction.d.ts.map +1 -1
- package/dist/esm/actions/sendUTXOTransaction.js.map +1 -1
- package/dist/esm/actions/signPsbt.d.ts.map +1 -1
- package/dist/esm/actions/signPsbt.js.map +1 -1
- package/dist/esm/actions/waitForTransaction.d.ts.map +1 -1
- package/dist/esm/actions/waitForTransaction.js.map +1 -1
- package/dist/esm/actions/watchBlockNumber.d.ts.map +1 -1
- package/dist/esm/actions/watchBlockNumber.js.map +1 -1
- package/dist/esm/chains/bitcoin.js +3 -3
- package/dist/esm/chains/bitcoin.js.map +1 -1
- package/dist/esm/chains/defineChain.d.ts.map +1 -1
- package/dist/esm/chains/defineChain.js.map +1 -1
- package/dist/esm/chains/signet.js +3 -3
- package/dist/esm/chains/signet.js.map +1 -1
- package/dist/esm/clients/decorators/public.d.ts.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/decorators/wallet.d.ts.map +1 -1
- package/dist/esm/clients/decorators/wallet.js.map +1 -1
- package/dist/esm/errors/address.d.ts.map +1 -1
- package/dist/esm/errors/address.js.map +1 -1
- package/dist/esm/errors/base.d.ts.map +1 -1
- package/dist/esm/errors/base.js.map +1 -1
- package/dist/esm/errors/block.d.ts.map +1 -1
- package/dist/esm/errors/block.js.map +1 -1
- package/dist/esm/errors/provider.js.map +1 -1
- package/dist/esm/errors/request.d.ts.map +1 -1
- package/dist/esm/errors/request.js.map +1 -1
- package/dist/esm/errors/rpc.d.ts.map +1 -1
- package/dist/esm/errors/rpc.js +3 -3
- package/dist/esm/errors/rpc.js.map +1 -1
- package/dist/esm/errors/transaction.d.ts.map +1 -1
- package/dist/esm/errors/transaction.js.map +1 -1
- package/dist/esm/errors/transport.d.ts.map +1 -1
- package/dist/esm/errors/transport.js.map +1 -1
- package/dist/esm/errors/utxo.d.ts.map +1 -1
- package/dist/esm/errors/utxo.js.map +1 -1
- package/dist/esm/factories/createClient.d.ts.map +1 -1
- package/dist/esm/factories/createClient.js.map +1 -1
- package/dist/esm/factories/createTransport.d.ts.map +1 -1
- package/dist/esm/factories/createTransport.js.map +1 -1
- package/dist/esm/test/utils.js.map +1 -1
- package/dist/esm/transports/ankr/ankr.js.map +1 -1
- package/dist/esm/transports/ankr/getBalance.js +2 -2
- package/dist/esm/transports/ankr/getBalance.js.map +1 -1
- package/dist/esm/transports/ankr/getTransactionFee.js.map +1 -1
- package/dist/esm/transports/ankr/getTransactions.js.map +1 -1
- package/dist/esm/transports/ankr/methods.js.map +1 -1
- package/dist/esm/transports/ankr/utils.js.map +1 -1
- package/dist/esm/transports/blockchair/blockchair.js.map +1 -1
- package/dist/esm/transports/blockchair/getBalance.js +2 -2
- package/dist/esm/transports/blockchair/getBalance.js.map +1 -1
- package/dist/esm/transports/blockchair/getTransactionFee.js +2 -2
- package/dist/esm/transports/blockchair/getTransactionFee.js.map +1 -1
- package/dist/esm/transports/blockchair/getUTXOs.js +2 -2
- package/dist/esm/transports/blockchair/getUTXOs.js.map +1 -1
- package/dist/esm/transports/blockchair/getXPubAddresses.js +2 -2
- package/dist/esm/transports/blockchair/getXPubAddresses.js.map +1 -1
- package/dist/esm/transports/blockchair/methods.js.map +1 -1
- package/dist/esm/transports/blockcypher/blockcypher.js.map +1 -1
- package/dist/esm/transports/blockcypher/getBalance.js.map +1 -1
- package/dist/esm/transports/blockcypher/getTransactionFee.js.map +1 -1
- package/dist/esm/transports/blockcypher/getUTXOs.js.map +1 -1
- package/dist/esm/transports/blockcypher/methods.js.map +1 -1
- package/dist/esm/transports/blockcypher/utils.js +3 -3
- package/dist/esm/transports/blockcypher/utils.js.map +1 -1
- package/dist/esm/transports/custom.d.ts.map +1 -1
- package/dist/esm/transports/custom.js.map +1 -1
- package/dist/esm/transports/fallback.d.ts.map +1 -1
- package/dist/esm/transports/fallback.js +2 -2
- package/dist/esm/transports/fallback.js.map +1 -1
- package/dist/esm/transports/getHttpRpcClient.d.ts.map +1 -1
- package/dist/esm/transports/getHttpRpcClient.js.map +1 -1
- package/dist/esm/transports/getRpcProviderMethods.js.map +1 -1
- package/dist/esm/transports/http.d.ts.map +1 -1
- package/dist/esm/transports/http.js.map +1 -1
- package/dist/esm/transports/mempool/getBalance.js.map +1 -1
- package/dist/esm/transports/mempool/getTransactionFee.js.map +1 -1
- package/dist/esm/transports/mempool/getTransactions.js.map +1 -1
- package/dist/esm/transports/mempool/mempool.js.map +1 -1
- package/dist/esm/transports/mempool/methods.js.map +1 -1
- package/dist/esm/transports/mempool/utils.js.map +1 -1
- package/dist/esm/transports/types.d.ts.map +1 -1
- package/dist/esm/transports/types.js.map +1 -1
- package/dist/esm/transports/utxo.js.map +1 -1
- package/dist/esm/types/address.js.map +1 -1
- package/dist/esm/types/block.d.ts.map +1 -1
- package/dist/esm/types/chain.js.map +1 -1
- package/dist/esm/types/client.d.ts.map +1 -1
- package/dist/esm/types/request.d.ts.map +1 -1
- package/dist/esm/types/utils.d.ts.map +1 -1
- package/dist/esm/utils/buildRequest.d.ts.map +1 -1
- package/dist/esm/utils/buildRequest.js +4 -4
- package/dist/esm/utils/buildRequest.js.map +1 -1
- package/dist/esm/utils/cancelTransaction.js.map +1 -1
- package/dist/esm/utils/converter.js.map +1 -1
- package/dist/esm/utils/createBatchScheduler.d.ts.map +1 -1
- package/dist/esm/utils/createBatchScheduler.js +1 -1
- package/dist/esm/utils/createBatchScheduler.js.map +1 -1
- package/dist/esm/utils/deepEqual.js.map +1 -1
- package/dist/esm/utils/getAction.d.ts.map +1 -1
- package/dist/esm/utils/getAction.js.map +1 -1
- package/dist/esm/utils/getAddressInfo.js +25 -25
- package/dist/esm/utils/getAddressInfo.js.map +1 -1
- package/dist/esm/utils/idCache.js.map +1 -1
- package/dist/esm/utils/isAddress.js.map +1 -1
- package/dist/esm/utils/lru.js.map +1 -1
- package/dist/esm/utils/modifyFee.js.map +1 -1
- package/dist/esm/utils/observe.d.ts.map +1 -1
- package/dist/esm/utils/observe.js +2 -2
- package/dist/esm/utils/observe.js.map +1 -1
- package/dist/esm/utils/parseAccount.d.ts.map +1 -1
- package/dist/esm/utils/parseAccount.js.map +1 -1
- package/dist/esm/utils/poll.d.ts.map +1 -1
- package/dist/esm/utils/poll.js.map +1 -1
- package/dist/esm/utils/retryUntil.d.ts.map +1 -1
- package/dist/esm/utils/retryUntil.js.map +1 -1
- package/dist/esm/utils/sleep.js.map +1 -1
- package/dist/esm/utils/stringify.js.map +1 -1
- package/dist/esm/utils/uid.js.map +1 -1
- package/dist/esm/utils/url.js.map +1 -1
- package/dist/esm/utils/wait.js.map +1 -1
- package/dist/esm/utils/withDedupe.d.ts.map +1 -1
- package/dist/esm/utils/withDedupe.js +1 -1
- package/dist/esm/utils/withDedupe.js.map +1 -1
- package/dist/esm/utils/withResolvers.d.ts.map +1 -1
- package/dist/esm/utils/withResolvers.js.map +1 -1
- package/dist/esm/utils/withRetry.d.ts.map +1 -1
- package/dist/esm/utils/withRetry.js.map +1 -1
- package/dist/esm/utils/withTimeout.d.ts.map +1 -1
- package/dist/esm/utils/withTimeout.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -2
- package/src/version.ts +1 -1
- package/dist/cjs/transports/__mocks__/getTransactionFee.d.ts +0 -7
- package/dist/cjs/transports/__mocks__/getTransactionFee.js +0 -11
- package/dist/cjs/transports/__mocks__/getTransactionFee.js.map +0 -1
- package/dist/esm/transports/__mocks__/getTransactionFee.d.ts +0 -7
- package/dist/esm/transports/__mocks__/getTransactionFee.d.ts.map +0 -1
- package/dist/esm/transports/__mocks__/getTransactionFee.js +0 -8
- package/dist/esm/transports/__mocks__/getTransactionFee.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.js","names":[],"sources":["../../../src/transports/custom.ts"],"sourcesContent":["import type { ErrorType } from '../errors/utils.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\n\ntype BitcoinProvider = { request(...args: any): Promise<any> }\n\nexport type CustomTransportConfig = {\n /** The key of the transport. */\n key?: TransportConfig['key'] | undefined\n /** Methods to include or exclude from executing RPC requests. */\n methods?: TransportConfig['methods'] | undefined\n /** The name of the transport. */\n name?: TransportConfig['name'] | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n}\n\nexport type CustomTransport = Transport<\n 'custom',\n // biome-ignore lint/complexity/noBannedTypes: part of the types\n {},\n BitcoinProvider['request']\n>\n\nexport type CustomTransportErrorType = CreateTransportErrorType | ErrorType\n\n/**\n * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.\n */\nexport function custom<provider extends BitcoinProvider>(\n provider: provider,\n config: CustomTransportConfig = {}\n): CustomTransport {\n const {\n key = 'custom',\n methods,\n name = 'Custom Provider',\n retryDelay,\n } = config\n return ({ retryCount: defaultRetryCount }) =>\n createTransport({\n key,\n methods,\n name,\n request: provider.request.bind(provider),\n retryCount: config.retryCount ?? defaultRetryCount,\n retryDelay,\n type: 'custom',\n })\n}\n"],"mappings":";;;;;AAmCA,SAAgB,OACd,UACA,SAAgC,
|
|
1
|
+
{"version":3,"file":"custom.js","names":[],"sources":["../../../src/transports/custom.ts"],"sourcesContent":["import type { ErrorType } from '../errors/utils.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\n\ntype BitcoinProvider = { request(...args: any): Promise<any> }\n\nexport type CustomTransportConfig = {\n /** The key of the transport. */\n key?: TransportConfig['key'] | undefined\n /** Methods to include or exclude from executing RPC requests. */\n methods?: TransportConfig['methods'] | undefined\n /** The name of the transport. */\n name?: TransportConfig['name'] | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n}\n\nexport type CustomTransport = Transport<\n 'custom',\n // biome-ignore lint/complexity/noBannedTypes: part of the types\n {},\n BitcoinProvider['request']\n>\n\nexport type CustomTransportErrorType = CreateTransportErrorType | ErrorType\n\n/**\n * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.\n */\nexport function custom<provider extends BitcoinProvider>(\n provider: provider,\n config: CustomTransportConfig = {}\n): CustomTransport {\n const {\n key = 'custom',\n methods,\n name = 'Custom Provider',\n retryDelay,\n } = config\n return ({ retryCount: defaultRetryCount }) =>\n createTransport({\n key,\n methods,\n name,\n request: provider.request.bind(provider),\n retryCount: config.retryCount ?? defaultRetryCount,\n retryDelay,\n type: 'custom',\n })\n}\n"],"mappings":";;;;;AAmCA,SAAgB,OACd,UACA,SAAgC,CAAC,GAChB;CACjB,MAAM,EACJ,MAAM,UACN,SACA,OAAO,mBACP,eACE;CACJ,QAAQ,EAAE,YAAY,wBACpB,gBAAgB;EACd;EACA;EACA;EACA,SAAS,SAAS,QAAQ,KAAK,QAAQ;EACvC,YAAY,OAAO,cAAc;EACjC;EACA,MAAM;CACR,CAAC;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.d.ts","names":[],"sources":["../../../src/transports/fallback.ts"],"mappings":";;;;;KAiBY,YAAA,IACV,IAAA;EACE,MAAA;EACA,MAAA;EACA,SAAA,EAAW,UAAA,CAAW,SAAA;AAAA;EAGlB,KAAA;EACA,QAAA;EACA,MAAA;AAAA;EAGA,KAAA,EAAO,KAAA;EACP,QAAA;EACA,MAAA;AAAA;AAAA,KAKH,WAAA;;;;;EAKH,QAAA;;;;EAIA,IAAA,IAAQ,UAAA;IACN,SAAA,EAAW,UAAA,CAAW,SAAA;EAAA,MAClB,OAAA
|
|
1
|
+
{"version":3,"file":"fallback.d.ts","names":[],"sources":["../../../src/transports/fallback.ts"],"mappings":";;;;;KAiBY,YAAA,IACV,IAAA;EACE,MAAA;EACA,MAAA;EACA,SAAA,EAAW,UAAA,CAAW,SAAA;AAAA;EAGlB,KAAA;EACA,QAAA;EACA,MAAA;AAAA;EAGA,KAAA,EAAO,KAAA;EACP,QAAA;EACA,MAAA;AAAA;AAAA,KAKH,WAAA;;;;;EAKH,QAAA;;;;EAIA,IAAA,IAAQ,UAAA;IACN,SAAA,EAAW,UAAA,CAAW,SAAA;EAAA,MAClB,OAAA;EAfF;;;;EAoBJ,WAAA;;;;;EAKA,OAAA;;;;EAIA,OAAA;IAdM;;;;IAoBA,OAAA;IAKA;;AAAA;AAKR;IALQ,SAAA;EAAA;AAAA;AAAA,KAKI,uBAAA;2CAEV,GAAA,GAAM,eAAA;EAEN,IAAA,GAAO,eAAA,sBAQe;EANtB,IAAA,aAAiB,WAAA;EAEjB,UAAA,GAAa,eAAA;EAEb,UAAA,GAAa,eAAA;EAEb,WAAA,IAAe,KAAA,EAAO,KAAA;AAAA;AAAA,KAGZ,iBAAA,6BACkB,SAAA,cAAuB,SAAA,MACjD,SAAA;EAGA,UAAA,GAAa,EAAA,EAAI,YAAA;EACjB,UAAA,kBACgB,UAAA,GAAa,UAAA,CAAW,UAAA,CAAW,GAAA;AAAA;AAAA,KAK3C,0BAAA,GAA6B,wBAAA,GAA2B,SAAA;AAAA,iBAEpD,QAAA,mCAA2C,SAAA,IACzD,WAAA,EAAa,UAAA,EACb,MAAA,GAAQ,uBAAA,GACP,iBAAA,CAAkB,UAAA;AAAA,iBA2IL,WAAA,CAAY,KAAO,EAAA,KAAA;AA/JX;AAAA,iBAkLR,cAAA;EACd,KAAA;EACA,QAAA;EACA,YAAA;EACA,IAAA;EACA,WAAA;EACA,OAAA;EACA,UAAA;EACA;AAAA;EAEA,KAAA,GAAQ,KAAA;EACR,QAAA,EAAU,WAAA;EACV,YAAA,GAAe,UAAA,WAAqB,SAAA;EACpC,IAAA,GAAO,WAAA;EACP,WAAA,GAAc,WAAA;EACd,OAAA,GAAU,WAAA;EACV,UAAA,WAAqB,SAAA;EACrB,OAAA,GAAU,WAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { wait } from "../utils/wait.js";
|
|
2
|
-
import
|
|
2
|
+
import "../errors/rpc.js";
|
|
3
3
|
import { AllTransportsFailedError, TransportMethodNotSupportedError } from "../errors/transport.js";
|
|
4
4
|
import { InsufficientUTXOBalanceError } from "../errors/utxo.js";
|
|
5
5
|
import { createTransport } from "../factories/createTransport.js";
|
|
@@ -107,7 +107,7 @@ function fallback(transports_, config = {}) {
|
|
|
107
107
|
function shouldThrow(error) {
|
|
108
108
|
if (error instanceof InsufficientUTXOBalanceError) return true;
|
|
109
109
|
if ("code" in error && typeof error.code === "number") {
|
|
110
|
-
if (error.code ===
|
|
110
|
+
if (error.code === -32603 || error.code === -32e3 || error.code === 5e3) return true;
|
|
111
111
|
}
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.js","names":[],"sources":["../../../src/transports/fallback.ts"],"sourcesContent":["import { RpcErrorCode } from '../errors/rpc.js'\nimport {\n AllTransportsFailedError,\n TransportMethodNotSupportedError,\n} from '../errors/transport.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport { InsufficientUTXOBalanceError } from '../errors/utxo.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type { Chain } from '../types/chain.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\nimport { wait } from '../utils/wait.js'\n\n// TODO: Narrow `method` & `params` types.\nexport type OnResponseFn = (\n args: {\n method: string\n params: unknown[]\n transport: ReturnType<Transport>\n } & (\n | {\n error?: undefined\n response: unknown\n status: 'success'\n }\n | {\n error: Error\n response?: undefined\n status: 'error'\n }\n )\n) => void\n\ntype RankOptions = {\n /**\n * The polling interval (in ms) at which the ranker should ping the RPC URL.\n * @default client.pollingInterval\n */\n interval?: number | undefined\n /**\n * Ping method to determine latency.\n */\n ping?: (parameters: {\n transport: ReturnType<Transport>\n }) => Promise<unknown> | undefined\n /**\n * The number of previous samples to perform ranking on.\n * @default 10\n */\n sampleCount?: number | undefined\n /**\n * Timeout when sampling transports.\n * @default 1_000\n */\n timeout?: number | undefined\n /**\n * Weights to apply to the scores. Weight values are proportional.\n */\n weights?:\n | {\n /**\n * The weight to apply to the latency score.\n * @default 0.3\n */\n latency?: number | undefined\n /**\n * The weight to apply to the stability score.\n * @default 0.7\n */\n stability?: number | undefined\n }\n | undefined\n}\n\nexport type FallbackTransportConfig = {\n /** The key of the Fallback transport. */\n key?: TransportConfig['key'] | undefined\n /** The name of the Fallback transport. */\n name?: TransportConfig['name'] | undefined\n /** Toggle to enable ranking, or rank options. */\n rank?: boolean | RankOptions | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n /** Callback on whether an error should throw or try the next transport in the fallback. */\n shouldThrow?: (error: Error) => boolean | undefined\n}\n\nexport type FallbackTransport<\n transports extends readonly Transport[] = readonly Transport[],\n> = Transport<\n 'fallback',\n {\n onResponse: (fn: OnResponseFn) => void\n transports: {\n [key in keyof transports]: ReturnType<transports[key]>\n }\n }\n>\n\nexport type FallbackTransportErrorType = CreateTransportErrorType | ErrorType\n\nexport function fallback<const transports extends readonly Transport[]>(\n transports_: transports,\n config: FallbackTransportConfig = {}\n): FallbackTransport<transports> {\n const {\n key = 'fallback',\n name = 'Fallback',\n rank = false,\n shouldThrow: shouldThrow_ = shouldThrow,\n retryCount,\n retryDelay,\n } = config\n return (({ chain, pollingInterval = 4_000, timeout, ...rest }) => {\n let transports = transports_\n\n let onResponse: OnResponseFn = () => {}\n\n const transport = createTransport(\n {\n key,\n name,\n async request({ method, params }) {\n // Filter transports to only those that support the requested method\n const supportedTransports = transports.reduce<\n ReturnType<Transport>[]\n >((supportedTransports, transport) => {\n const instance = transport({\n ...rest,\n chain,\n retryCount: 0,\n timeout,\n })\n const { include, exclude } = instance.config.methods || {}\n if (include) {\n if (include.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n if (exclude) {\n if (!exclude.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n supportedTransports.push(instance)\n return supportedTransports\n }, [])\n\n if (!supportedTransports.length) {\n throw new TransportMethodNotSupportedError({ method })\n }\n\n const collectedErrors: Array<{\n transport: string\n error: Error\n attempt: number\n }> = []\n\n const fetch = async (i = 0): Promise<any> => {\n const transport = supportedTransports[i]\n try {\n const response = await transport.request({\n method,\n params,\n })\n\n onResponse({\n method,\n params: params as unknown[],\n response,\n transport,\n status: 'success',\n })\n\n return response\n } catch (err) {\n onResponse({\n error: err as Error,\n method,\n params: params as unknown[],\n transport,\n status: 'error',\n })\n\n if (shouldThrow_(err as Error)) {\n throw err\n }\n\n collectedErrors.push({\n transport: transport.config.name,\n error: err as Error,\n attempt: i + 1,\n })\n\n // If we've reached the end of the fallbacks, throw all collected errors.\n if (i === supportedTransports.length - 1) {\n throw new AllTransportsFailedError({\n method,\n params,\n errors: collectedErrors,\n totalAttempts: i + 1,\n })\n }\n\n // Otherwise, try the next fallback.\n return fetch(i + 1)\n }\n }\n return fetch()\n },\n retryCount,\n retryDelay,\n type: 'fallback',\n },\n {\n onResponse: (fn: OnResponseFn) => {\n onResponse = fn\n },\n transports: transports.map((fn) => fn({ chain, retryCount: 0 })),\n }\n )\n\n if (rank) {\n const rankOptions = (typeof rank === 'object' ? rank : {}) as RankOptions\n rankTransports({\n chain,\n interval: rankOptions.interval ?? pollingInterval,\n onTransports: (transports_) => {\n transports = transports_ as transports\n },\n ping: rankOptions.ping,\n sampleCount: rankOptions.sampleCount,\n timeout: rankOptions.timeout,\n transports,\n weights: rankOptions.weights,\n })\n }\n return transport\n }) as FallbackTransport<transports>\n}\n\nexport function shouldThrow(error: Error): boolean {\n if (error instanceof InsufficientUTXOBalanceError) {\n return true\n }\n\n if ('code' in error && typeof error.code === 'number') {\n if (\n error.code === RpcErrorCode.INTERNAL_ERROR ||\n error.code === RpcErrorCode.USER_REJECTION ||\n error.code === 5000 // CAIP UserRejectedRequestError\n ) {\n return true\n }\n }\n\n return false\n}\n\n/** @internal */\nexport function rankTransports({\n chain,\n interval = 4_000,\n onTransports,\n ping,\n sampleCount = 10,\n timeout = 1_000,\n transports,\n weights = {},\n}: {\n chain?: Chain | undefined\n interval: RankOptions['interval']\n onTransports: (transports: readonly Transport[]) => void\n ping?: RankOptions['ping'] | undefined\n sampleCount?: RankOptions['sampleCount'] | undefined\n timeout?: RankOptions['timeout'] | undefined\n transports: readonly Transport[]\n weights?: RankOptions['weights'] | undefined\n}): void {\n const { stability: stabilityWeight = 0.7, latency: latencyWeight = 0.3 } =\n weights\n\n type SampleData = { latency: number; success: number }\n type Sample = SampleData[]\n const samples: Sample[] = []\n\n const rankTransports_ = async () => {\n // 1. Take a sample from each Transport.\n const sample: Sample = await Promise.all(\n transports.map(async (transport) => {\n const transport_ = transport({ chain, retryCount: 0, timeout })\n\n const start = Date.now()\n let end: number\n let success: number\n try {\n await (ping\n ? ping({ transport: transport_ })\n : transport_.request({\n method: 'net_listening',\n params: undefined,\n }))\n success = 1\n } catch {\n success = 0\n } finally {\n end = Date.now()\n }\n const latency = end - start\n return { latency, success }\n })\n )\n\n // 2. Store the sample. If we have more than `sampleCount` samples, remove\n // the oldest sample.\n samples.push(sample)\n if (samples.length > sampleCount) {\n samples.shift()\n }\n\n // 3. Calculate the max latency from samples.\n const maxLatency = Math.max(\n ...samples.map((sample) =>\n Math.max(...sample.map(({ latency }) => latency))\n )\n )\n\n // 4. Calculate the score for each Transport.\n const scores = transports\n .map((_, i) => {\n const latencies = samples.map((sample) => sample[i].latency)\n const meanLatency =\n latencies.reduce((acc, latency) => acc + latency, 0) /\n latencies.length\n const latencyScore = 1 - meanLatency / maxLatency\n\n const successes = samples.map((sample) => sample[i].success)\n const stabilityScore =\n successes.reduce((acc, success) => acc + success, 0) /\n successes.length\n\n if (stabilityScore === 0) {\n return [0, i]\n }\n return [\n latencyWeight * latencyScore + stabilityWeight * stabilityScore,\n i,\n ]\n })\n .sort((a, b) => b[0] - a[0])\n\n // 5. Sort the Transports by score.\n onTransports(scores.map(([, i]) => transports[i]))\n\n // 6. Wait, and then rank again.\n await wait(interval)\n rankTransports_()\n }\n rankTransports_()\n}\n"],"mappings":";;;;;;AA0GA,SAAgB,SACd,aACA,SAAkC,EAAE,EACL;CAC/B,MAAM,EACJ,MAAM,YACN,OAAO,YACP,OAAO,OACP,aAAa,eAAe,aAC5B,YACA,eACE;AACJ,UAAS,EAAE,OAAO,kBAAkB,KAAO,SAAS,GAAG,WAAW;EAChE,IAAI,aAAa;EAEjB,IAAI,mBAAiC;EAErC,MAAM,YAAY,gBAChB;GACE;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,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Q,CAAC,CAClD,CACF;AA2BD,eAxBe,WACZ,KAAK,GAAG,MAAM;GACb,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,GAAG,QAAQ;GAI5D,MAAM,eAAe,IAFnB,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,EAAE,GACpD,UAAU,SAC2B;GAEvC,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,GAAG,QAAQ;GAC5D,MAAM,iBACJ,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,EAAE,GACpD,UAAU;AAEZ,OAAI,mBAAmB,EACrB,QAAO,CAAC,GAAG,EAAE;AAEf,UAAO,CACL,gBAAgB,eAAe,kBAAkB,gBACjD,EACD;IACD,CACD,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,CAGV,KAAK,GAAG,OAAO,WAAW,GAAG,CAAC;AAGlD,QAAM,KAAK,SAAS;AACpB,mBAAiB;;AAEnB,kBAAiB"}
|
|
1
|
+
{"version":3,"file":"fallback.js","names":[],"sources":["../../../src/transports/fallback.ts"],"sourcesContent":["import { RpcErrorCode } from '../errors/rpc.js'\nimport {\n AllTransportsFailedError,\n TransportMethodNotSupportedError,\n} from '../errors/transport.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport { InsufficientUTXOBalanceError } from '../errors/utxo.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type { Chain } from '../types/chain.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\nimport { wait } from '../utils/wait.js'\n\n// TODO: Narrow `method` & `params` types.\nexport type OnResponseFn = (\n args: {\n method: string\n params: unknown[]\n transport: ReturnType<Transport>\n } & (\n | {\n error?: undefined\n response: unknown\n status: 'success'\n }\n | {\n error: Error\n response?: undefined\n status: 'error'\n }\n )\n) => void\n\ntype RankOptions = {\n /**\n * The polling interval (in ms) at which the ranker should ping the RPC URL.\n * @default client.pollingInterval\n */\n interval?: number | undefined\n /**\n * Ping method to determine latency.\n */\n ping?: (parameters: {\n transport: ReturnType<Transport>\n }) => Promise<unknown> | undefined\n /**\n * The number of previous samples to perform ranking on.\n * @default 10\n */\n sampleCount?: number | undefined\n /**\n * Timeout when sampling transports.\n * @default 1_000\n */\n timeout?: number | undefined\n /**\n * Weights to apply to the scores. Weight values are proportional.\n */\n weights?:\n | {\n /**\n * The weight to apply to the latency score.\n * @default 0.3\n */\n latency?: number | undefined\n /**\n * The weight to apply to the stability score.\n * @default 0.7\n */\n stability?: number | undefined\n }\n | undefined\n}\n\nexport type FallbackTransportConfig = {\n /** The key of the Fallback transport. */\n key?: TransportConfig['key'] | undefined\n /** The name of the Fallback transport. */\n name?: TransportConfig['name'] | undefined\n /** Toggle to enable ranking, or rank options. */\n rank?: boolean | RankOptions | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n /** Callback on whether an error should throw or try the next transport in the fallback. */\n shouldThrow?: (error: Error) => boolean | undefined\n}\n\nexport type FallbackTransport<\n transports extends readonly Transport[] = readonly Transport[],\n> = Transport<\n 'fallback',\n {\n onResponse: (fn: OnResponseFn) => void\n transports: {\n [key in keyof transports]: ReturnType<transports[key]>\n }\n }\n>\n\nexport type FallbackTransportErrorType = CreateTransportErrorType | ErrorType\n\nexport function fallback<const transports extends readonly Transport[]>(\n transports_: transports,\n config: FallbackTransportConfig = {}\n): FallbackTransport<transports> {\n const {\n key = 'fallback',\n name = 'Fallback',\n rank = false,\n shouldThrow: shouldThrow_ = shouldThrow,\n retryCount,\n retryDelay,\n } = config\n return (({ chain, pollingInterval = 4_000, timeout, ...rest }) => {\n let transports = transports_\n\n let onResponse: OnResponseFn = () => {}\n\n const transport = createTransport(\n {\n key,\n name,\n async request({ method, params }) {\n // Filter transports to only those that support the requested method\n const supportedTransports = transports.reduce<\n ReturnType<Transport>[]\n >((supportedTransports, transport) => {\n const instance = transport({\n ...rest,\n chain,\n retryCount: 0,\n timeout,\n })\n const { include, exclude } = instance.config.methods || {}\n if (include) {\n if (include.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n if (exclude) {\n if (!exclude.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n supportedTransports.push(instance)\n return supportedTransports\n }, [])\n\n if (!supportedTransports.length) {\n throw new TransportMethodNotSupportedError({ method })\n }\n\n const collectedErrors: Array<{\n transport: string\n error: Error\n attempt: number\n }> = []\n\n const fetch = async (i = 0): Promise<any> => {\n const transport = supportedTransports[i]\n try {\n const response = await transport.request({\n method,\n params,\n })\n\n onResponse({\n method,\n params: params as unknown[],\n response,\n transport,\n status: 'success',\n })\n\n return response\n } catch (err) {\n onResponse({\n error: err as Error,\n method,\n params: params as unknown[],\n transport,\n status: 'error',\n })\n\n if (shouldThrow_(err as Error)) {\n throw err\n }\n\n collectedErrors.push({\n transport: transport.config.name,\n error: err as Error,\n attempt: i + 1,\n })\n\n // If we've reached the end of the fallbacks, throw all collected errors.\n if (i === supportedTransports.length - 1) {\n throw new AllTransportsFailedError({\n method,\n params,\n errors: collectedErrors,\n totalAttempts: i + 1,\n })\n }\n\n // Otherwise, try the next fallback.\n return fetch(i + 1)\n }\n }\n return fetch()\n },\n retryCount,\n retryDelay,\n type: 'fallback',\n },\n {\n onResponse: (fn: OnResponseFn) => {\n onResponse = fn\n },\n transports: transports.map((fn) => fn({ chain, retryCount: 0 })),\n }\n )\n\n if (rank) {\n const rankOptions = (typeof rank === 'object' ? rank : {}) as RankOptions\n rankTransports({\n chain,\n interval: rankOptions.interval ?? pollingInterval,\n onTransports: (transports_) => {\n transports = transports_ as transports\n },\n ping: rankOptions.ping,\n sampleCount: rankOptions.sampleCount,\n timeout: rankOptions.timeout,\n transports,\n weights: rankOptions.weights,\n })\n }\n return transport\n }) as FallbackTransport<transports>\n}\n\nexport function shouldThrow(error: Error): boolean {\n if (error instanceof InsufficientUTXOBalanceError) {\n return true\n }\n\n if ('code' in error && typeof error.code === 'number') {\n if (\n error.code === RpcErrorCode.INTERNAL_ERROR ||\n error.code === RpcErrorCode.USER_REJECTION ||\n error.code === 5000 // CAIP UserRejectedRequestError\n ) {\n return true\n }\n }\n\n return false\n}\n\n/** @internal */\nexport function rankTransports({\n chain,\n interval = 4_000,\n onTransports,\n ping,\n sampleCount = 10,\n timeout = 1_000,\n transports,\n weights = {},\n}: {\n chain?: Chain | undefined\n interval: RankOptions['interval']\n onTransports: (transports: readonly Transport[]) => void\n ping?: RankOptions['ping'] | undefined\n sampleCount?: RankOptions['sampleCount'] | undefined\n timeout?: RankOptions['timeout'] | undefined\n transports: readonly Transport[]\n weights?: RankOptions['weights'] | undefined\n}): void {\n const { stability: stabilityWeight = 0.7, latency: latencyWeight = 0.3 } =\n weights\n\n type SampleData = { latency: number; success: number }\n type Sample = SampleData[]\n const samples: Sample[] = []\n\n const rankTransports_ = async () => {\n // 1. Take a sample from each Transport.\n const sample: Sample = await Promise.all(\n transports.map(async (transport) => {\n const transport_ = transport({ chain, retryCount: 0, timeout })\n\n const start = Date.now()\n let end: number\n let success: number\n try {\n await (ping\n ? ping({ transport: transport_ })\n : transport_.request({\n method: 'net_listening',\n params: undefined,\n }))\n success = 1\n } catch {\n success = 0\n } finally {\n end = Date.now()\n }\n const latency = end - start\n return { latency, success }\n })\n )\n\n // 2. Store the sample. If we have more than `sampleCount` samples, remove\n // the oldest sample.\n samples.push(sample)\n if (samples.length > sampleCount) {\n samples.shift()\n }\n\n // 3. Calculate the max latency from samples.\n const maxLatency = Math.max(\n ...samples.map((sample) =>\n Math.max(...sample.map(({ latency }) => latency))\n )\n )\n\n // 4. Calculate the score for each Transport.\n const scores = transports\n .map((_, i) => {\n const latencies = samples.map((sample) => sample[i].latency)\n const meanLatency =\n latencies.reduce((acc, latency) => acc + latency, 0) /\n latencies.length\n const latencyScore = 1 - meanLatency / maxLatency\n\n const successes = samples.map((sample) => sample[i].success)\n const stabilityScore =\n successes.reduce((acc, success) => acc + success, 0) /\n successes.length\n\n if (stabilityScore === 0) {\n return [0, i]\n }\n return [\n latencyWeight * latencyScore + stabilityWeight * stabilityScore,\n i,\n ]\n })\n .sort((a, b) => b[0] - a[0])\n\n // 5. Sort the Transports by score.\n onTransports(scores.map(([, i]) => transports[i]))\n\n // 6. Wait, and then rank again.\n await wait(interval)\n rankTransports_()\n }\n rankTransports_()\n}\n"],"mappings":";;;;;;AA0GA,SAAgB,SACd,aACA,SAAkC,CAAC,GACJ;CAC/B,MAAM,EACJ,MAAM,YACN,OAAO,YACP,OAAO,OACP,aAAa,eAAe,aAC5B,YACA,eACE;CACJ,SAAS,EAAE,OAAO,kBAAkB,KAAO,SAAS,GAAG,WAAW;EAChE,IAAI,aAAa;EAEjB,IAAI,mBAAiC,CAAC;EAEtC,MAAM,YAAY,gBAChB;GACE;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,UAAU;IAEhC,MAAM,sBAAsB,WAAW,QAEpC,qBAAqB,cAAc;KACpC,MAAM,WAAW,UAAU;MACzB,GAAG;MACH;MACA,YAAY;MACZ;KACF,CAAC;KACD,MAAM,EAAE,SAAS,YAAY,SAAS,OAAO,WAAW,CAAC;KACzD,IAAI,SAAS;MACX,IAAI,QAAQ,SAAS,MAAM,GACzB,oBAAoB,KAAK,QAAQ;MAEnC,OAAO;KACT;KACA,IAAI,SAAS;MACX,IAAI,CAAC,QAAQ,SAAS,MAAM,GAC1B,oBAAoB,KAAK,QAAQ;MAEnC,OAAO;KACT;KACA,oBAAoB,KAAK,QAAQ;KACjC,OAAO;IACT,GAAG,CAAC,CAAC;IAEL,IAAI,CAAC,oBAAoB,QACvB,MAAM,IAAI,iCAAiC,EAAE,OAAO,CAAC;IAGvD,MAAM,kBAID,CAAC;IAEN,MAAM,QAAQ,OAAO,IAAI,MAAoB;KAC3C,MAAM,YAAY,oBAAoB;KACtC,IAAI;MACF,MAAM,WAAW,MAAM,UAAU,QAAQ;OACvC;OACA;MACF,CAAC;MAED,WAAW;OACT;OACQ;OACR;OAC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,"file":"getHttpRpcClient.d.ts","names":[],"sources":["../../../src/transports/getHttpRpcClient.ts"],"mappings":";;;;KAOY,UAAA;EACV,OAAA;EACA,MAAA;EACA,MAAA;EACA,EAAA;AAAA;AAAA,KAGU,qBAAA,cACG,UAAA,GAAa,UAAA,KAAe,UAAA,IACvC,IAAA,SAAa,UAAA,KAAe,WAAA,KAAgB,WAAA;AAAA,KAEpC,oBAAA;kDAEV,YAAA,GAAe,IAAA,CAAK,WAAA;
|
|
1
|
+
{"version":3,"file":"getHttpRpcClient.d.ts","names":[],"sources":["../../../src/transports/getHttpRpcClient.ts"],"mappings":";;;;KAOY,UAAA;EACV,OAAA;EACA,MAAA;EACA,MAAA;EACA,EAAA;AAAA;AAAA,KAGU,qBAAA,cACG,UAAA,GAAa,UAAA,KAAe,UAAA,IACvC,IAAA,SAAa,UAAA,KAAe,WAAA,KAAgB,WAAA;AAAA,KAEpC,oBAAA;kDAEV,YAAA,GAAe,IAAA,CAAK,WAAA,uBATpB;EAWA,SAAA,KAEM,OAAA,EAAS,OAAA,EACT,IAAA,EAAM,WAAA,KACH,YAAA,qBACiB,WAAA;IAAgB,GAAA;EAAA;EAI1C,UAAA,KAAe,QAAA,EAAU,QAAA,KAAa,OAAA;EAEtC,OAAA;AAAA;AAAA,KAGU,qBAAA,cACG,UAAA,GAAa,UAAA,KAAe,UAAA;EAEzC,GAAA;EAEA,IAAA,GAAO,IAAA,EAzBuC;EA2B9C,YAAA,GAAe,oBAAA;EAEf,SAAA,KAAc,OAAA,EAAS,OAAA,KAAY,OAAA;EAEnC,UAAA,KAAe,QAAA,EAAU,QAAA,KAAa,OAAA;EAEtC,OAAA,GAAU,oBAAA;AAAA;AAAA,KAGA,aAAA;EACV,OAAA,cAAqB,UAAA,GAAa,UAAA,IAChC,MAAA,EAAQ,qBAAA,CAAsB,IAAA,IAC7B,OAAA,CAAQ,qBAAA,CAAsB,IAAA;AAAA;AAAA,iBAGnB,gBAAA,CACd,GAAA,UACA,OAAA,GAAS,oBAAA,GACR,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHttpRpcClient.js","names":[],"sources":["../../../src/transports/getHttpRpcClient.ts"],"sourcesContent":["import { HttpRequestError, TimeoutError } from '../errors/request.js'\nimport type { RpcResponse } from '../types/rpc.js'\nimport type { MaybePromise } from '../types/utils.js'\nimport { idCache } from '../utils/idCache.js'\nimport { stringify } from '../utils/stringify.js'\nimport { withTimeout } from '../utils/withTimeout.js'\n\nexport type RpcRequest = {\n jsonrpc?: '2.0'\n method: string\n params?: any\n id?: number\n}\n\nexport type HttpRequestReturnType<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse\n\nexport type HttpRpcClientOptions = {\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: Omit<RequestInit, 'body'> | undefined\n /** A callback to handle the request. */\n onRequest?:\n | ((\n request: Request,\n init: RequestInit\n ) => MaybePromise<\n void | undefined | (RequestInit & { url?: string | undefined })\n >)\n | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: number | undefined\n}\n\nexport type HttpRequestParameters<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = {\n url?: string\n /** The RPC request body. */\n body?: body\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined\n /** A callback to handle the response. */\n onRequest?: ((request: Request) => Promise<void> | void) | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: HttpRpcClientOptions['timeout'] | undefined\n}\n\nexport type HttpRpcClient = {\n request<body extends RpcRequest | RpcRequest[]>(\n params: HttpRequestParameters<body>\n ): Promise<HttpRequestReturnType<body>>\n}\n\nexport function getHttpRpcClient(\n url: string,\n options: HttpRpcClientOptions = {}\n): HttpRpcClient {\n return {\n async request(params) {\n const {\n body,\n onRequest = options.onRequest,\n onResponse = options.onResponse,\n timeout = options.timeout ?? 10_000,\n } = params\n\n const fetchOptions = {\n ...(options.fetchOptions ?? {}),\n ...(params.fetchOptions ?? {}),\n }\n\n const { headers, method, signal: signal_ } = fetchOptions\n\n try {\n const response = await withTimeout(\n async ({ signal }) => {\n const preparedBody = body\n ? Array.isArray(body)\n ? body.map((b) => ({\n jsonrpc: '2.0' as const,\n id: b.id ?? idCache.take(),\n ...b,\n }))\n : {\n jsonrpc: '2.0' as const,\n id: body.id ?? idCache.take(),\n ...body,\n }\n : undefined\n const init: RequestInit = {\n ...fetchOptions,\n body: preparedBody ? stringify(preparedBody) : undefined,\n headers: {\n ...(method !== 'GET'\n ? { 'Content-Type': 'application/json' }\n : undefined),\n ...headers,\n },\n method: method || 'POST',\n signal: signal_ || (timeout > 0 ? signal : null),\n }\n const request = new Request(params.url ?? url, init)\n if (onRequest) {\n await onRequest(request, init)\n }\n const response = await fetch(params.url ?? url, init)\n return response\n },\n {\n errorInstance: new TimeoutError({\n body: body ?? {},\n url: params.url ?? url,\n timeout,\n }),\n timeout,\n signal: true,\n }\n )\n\n if (onResponse) {\n await onResponse(response)\n }\n\n let data: any\n if (\n response.headers.get('Content-Type')?.startsWith('application/json')\n ) {\n data = await response.json()\n } else {\n data = await response.text()\n data = JSON.parse(data || '{}')\n }\n\n if (!response.ok) {\n throw new HttpRequestError({\n body,\n details: stringify(data.error) || response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n })\n }\n return data\n } catch (err) {\n if (err instanceof HttpRequestError) {\n throw err\n }\n if (err instanceof TimeoutError) {\n throw err\n }\n throw new HttpRequestError({\n body,\n cause: err as Error,\n url,\n })\n }\n },\n }\n}\n"],"mappings":";;;;;AA0DA,SAAgB,iBACd,KACA,UAAgC,
|
|
1
|
+
{"version":3,"file":"getHttpRpcClient.js","names":[],"sources":["../../../src/transports/getHttpRpcClient.ts"],"sourcesContent":["import { HttpRequestError, TimeoutError } from '../errors/request.js'\nimport type { RpcResponse } from '../types/rpc.js'\nimport type { MaybePromise } from '../types/utils.js'\nimport { idCache } from '../utils/idCache.js'\nimport { stringify } from '../utils/stringify.js'\nimport { withTimeout } from '../utils/withTimeout.js'\n\nexport type RpcRequest = {\n jsonrpc?: '2.0'\n method: string\n params?: any\n id?: number\n}\n\nexport type HttpRequestReturnType<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse\n\nexport type HttpRpcClientOptions = {\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: Omit<RequestInit, 'body'> | undefined\n /** A callback to handle the request. */\n onRequest?:\n | ((\n request: Request,\n init: RequestInit\n ) => MaybePromise<\n void | undefined | (RequestInit & { url?: string | undefined })\n >)\n | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: number | undefined\n}\n\nexport type HttpRequestParameters<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = {\n url?: string\n /** The RPC request body. */\n body?: body\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined\n /** A callback to handle the response. */\n onRequest?: ((request: Request) => Promise<void> | void) | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: HttpRpcClientOptions['timeout'] | undefined\n}\n\nexport type HttpRpcClient = {\n request<body extends RpcRequest | RpcRequest[]>(\n params: HttpRequestParameters<body>\n ): Promise<HttpRequestReturnType<body>>\n}\n\nexport function getHttpRpcClient(\n url: string,\n options: HttpRpcClientOptions = {}\n): HttpRpcClient {\n return {\n async request(params) {\n const {\n body,\n onRequest = options.onRequest,\n onResponse = options.onResponse,\n timeout = options.timeout ?? 10_000,\n } = params\n\n const fetchOptions = {\n ...(options.fetchOptions ?? {}),\n ...(params.fetchOptions ?? {}),\n }\n\n const { headers, method, signal: signal_ } = fetchOptions\n\n try {\n const response = await withTimeout(\n async ({ signal }) => {\n const preparedBody = body\n ? Array.isArray(body)\n ? body.map((b) => ({\n jsonrpc: '2.0' as const,\n id: b.id ?? idCache.take(),\n ...b,\n }))\n : {\n jsonrpc: '2.0' as const,\n id: body.id ?? idCache.take(),\n ...body,\n }\n : undefined\n const init: RequestInit = {\n ...fetchOptions,\n body: preparedBody ? stringify(preparedBody) : undefined,\n headers: {\n ...(method !== 'GET'\n ? { 'Content-Type': 'application/json' }\n : undefined),\n ...headers,\n },\n method: method || 'POST',\n signal: signal_ || (timeout > 0 ? signal : null),\n }\n const request = new Request(params.url ?? url, init)\n if (onRequest) {\n await onRequest(request, init)\n }\n const response = await fetch(params.url ?? url, init)\n return response\n },\n {\n errorInstance: new TimeoutError({\n body: body ?? {},\n url: params.url ?? url,\n timeout,\n }),\n timeout,\n signal: true,\n }\n )\n\n if (onResponse) {\n await onResponse(response)\n }\n\n let data: any\n if (\n response.headers.get('Content-Type')?.startsWith('application/json')\n ) {\n data = await response.json()\n } else {\n data = await response.text()\n data = JSON.parse(data || '{}')\n }\n\n if (!response.ok) {\n throw new HttpRequestError({\n body,\n details: stringify(data.error) || response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n })\n }\n return data\n } catch (err) {\n if (err instanceof HttpRequestError) {\n throw err\n }\n if (err instanceof TimeoutError) {\n throw err\n }\n throw new HttpRequestError({\n body,\n cause: err as Error,\n url,\n })\n }\n },\n }\n}\n"],"mappings":";;;;;AA0DA,SAAgB,iBACd,KACA,UAAgC,CAAC,GAClB;CACf,OAAO,EACL,MAAM,QAAQ,QAAQ;EACpB,MAAM,EACJ,MACA,YAAY,QAAQ,WACpB,aAAa,QAAQ,YACrB,UAAU,QAAQ,WAAW,QAC3B;EAEJ,MAAM,eAAe;GACnB,GAAI,QAAQ,gBAAgB,CAAC;GAC7B,GAAI,OAAO,gBAAgB,CAAC;EAC9B;EAEA,MAAM,EAAE,SAAS,QAAQ,QAAQ,YAAY;EAE7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AM,IAAI,iBAAiB;IACzB;IACA,OAAO;IACP;GACF,CAAC;EACH;CACF,EACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRpcProviderMethods.js","names":[],"sources":["../../../src/transports/getRpcProviderMethods.ts"],"sourcesContent":["import { ankrMethods } from './ankr/methods.js'\nimport { blockchairMethods } from './blockchair/methods.js'\nimport { blockcypherMethods } from './blockcypher/methods.js'\nimport { mempoolMethods } from './mempool/methods.js'\nimport type { RpcMethods } from './types.js'\n\ntype providers = 'blockchair' | 'ankr' | 'blockcypher' | 'mempool' | string\n\nexport function getRpcProviderMethods(key: providers): RpcMethods | null {\n switch (key) {\n case 'blockchair':\n return blockchairMethods\n case 'ankr':\n return ankrMethods\n case 'blockcypher':\n return blockcypherMethods\n case 'mempool':\n return mempoolMethods\n default:\n return null\n }\n}\n"],"mappings":";;;;;AAQA,SAAgB,sBAAsB,KAAmC;
|
|
1
|
+
{"version":3,"file":"getRpcProviderMethods.js","names":[],"sources":["../../../src/transports/getRpcProviderMethods.ts"],"sourcesContent":["import { ankrMethods } from './ankr/methods.js'\nimport { blockchairMethods } from './blockchair/methods.js'\nimport { blockcypherMethods } from './blockcypher/methods.js'\nimport { mempoolMethods } from './mempool/methods.js'\nimport type { RpcMethods } from './types.js'\n\ntype providers = 'blockchair' | 'ankr' | 'blockcypher' | 'mempool' | string\n\nexport function getRpcProviderMethods(key: providers): RpcMethods | null {\n switch (key) {\n case 'blockchair':\n return blockchairMethods\n case 'ankr':\n return ankrMethods\n case 'blockcypher':\n return blockcypherMethods\n case 'mempool':\n return mempoolMethods\n default:\n return null\n }\n}\n"],"mappings":";;;;;AAQA,SAAgB,sBAAsB,KAAmC;CACvE,QAAQ,KAAR;EACE,KAAK,cACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,eACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","names":[],"sources":["../../../src/transports/http.ts"],"mappings":";;;;;;;KAsBY,mBAAA,mBACQ,SAAA;;;;;EAOlB,KAAA;IAmBM,iFAfA,SAAA,uBAmBC;IAjBD,IAAA;EAAA;;;;;EAON,YAAA,GAAe,oBAAA,8BAoBL;EAlBV,cAAA,GAAiB,oBAAA;EAEjB,eAAA,GAAkB,oBAAA;EAElB,GAAA,GAAM,eAAA;EAEN,OAAA,GAAU,eAAA;EAEV,IAAA,GAAO,eAAA;EAEP,GAAA,GAAM,GAAA;EAEN,UAAA,GAAa,eAAA;EAEb,UAAA,GAAa,eAAA;EAEb,SAAA,GAAY,SAAA,GAAY,SAAA;EAExB,OAAA,GAAU,eAAA;AAAA;AAAA,KAGA,aAAA,mBACQ,SAAA,yDAEhB,SAAA;EAGA,YAAA,GAAe,mBAAA;EACf,GAAA;AAAA,GAEF,eAAA,CAAgB,SAAA,EAAW,GAAA;AAAA,KAGjB,sBAAA,GACR,wBAAA,GACA,oBAAA,GACA,SAAA
|
|
1
|
+
{"version":3,"file":"http.d.ts","names":[],"sources":["../../../src/transports/http.ts"],"mappings":";;;;;;;KAsBY,mBAAA,mBACQ,SAAA;;;;;EAOlB,KAAA;IAmBM,iFAfA,SAAA,uBAmBC;IAjBD,IAAA;EAAA;;;;;EAON,YAAA,GAAe,oBAAA,8BAoBL;EAlBV,cAAA,GAAiB,oBAAA;EAEjB,eAAA,GAAkB,oBAAA;EAElB,GAAA,GAAM,eAAA;EAEN,OAAA,GAAU,eAAA;EAEV,IAAA,GAAO,eAAA;EAEP,GAAA,GAAM,GAAA;EAEN,UAAA,GAAa,eAAA;EAEb,UAAA,GAAa,eAAA;EAEb,SAAA,GAAY,SAAA,GAAY,SAAA;EAExB,OAAA,GAAU,eAAA;AAAA;AAAA,KAGA,aAAA,mBACQ,SAAA,yDAEhB,SAAA;EAGA,YAAA,GAAe,mBAAA;EACf,GAAA;AAAA,GAEF,eAAA,CAAgB,SAAA,EAAW,GAAA;AAAA,KAGjB,sBAAA,GACR,wBAAA,GACA,oBAAA,GACA,SAAA;;;AAlBQ;iBAuBI,IAAA,mBACI,SAAA,uDAIlB,GAAA,uBACA,MAAA,GAAQ,mBAAA,CAAoB,SAAA,EAAW,GAAA,IACtC,aAAA,CAAc,SAAA,EAAW,GAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","names":[],"sources":["../../../src/transports/http.ts"],"sourcesContent":["import { RpcRequestError } from '../errors/request.js'\nimport {\n UrlRequiredError,\n type UrlRequiredErrorType,\n} from '../errors/transport.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type { BtcRpcRequestFn, RpcSchema } from '../types/request.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\nimport { createBatchScheduler } from '../utils/createBatchScheduler.js'\nimport { idCache } from '../utils/idCache.js'\nimport {\n getHttpRpcClient,\n type HttpRpcClientOptions,\n type RpcRequest,\n} from './getHttpRpcClient.js'\nimport { UTXOAPISchemaMethods } from './types.js'\n\nexport type HttpTransportConfig<\n rpcSchema extends RpcSchema | undefined = undefined,\n raw extends boolean = false,\n> = {\n /**\n * Whether to enable Batch JSON-RPC.\n * @link https://www.jsonrpc.org/specification#batch\n */\n batch?:\n | boolean\n | {\n /** The maximum number of JSON-RPC requests to send in a batch. @default 1_000 */\n batchSize?: number | undefined\n /** The maximum number of milliseconds to wait before sending a batch. @default 0 */\n wait?: number | undefined\n }\n | undefined\n /**\n * Request configuration to pass to `fetch`.\n * @link https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined\n /** A callback to handle the response from `fetch`. */\n onFetchRequest?: HttpRpcClientOptions['onRequest'] | undefined\n /** A callback to handle the response from `fetch`. */\n onFetchResponse?: HttpRpcClientOptions['onResponse'] | undefined\n /** The key of the HTTP transport. */\n key?: TransportConfig['key'] | undefined\n /** Methods to include or exclude from executing RPC requests. */\n methods?: TransportConfig['methods'] | undefined\n /** The name of the HTTP transport. */\n name?: TransportConfig['name'] | undefined\n /** Whether to return JSON RPC errors as responses instead of throwing. */\n raw?: raw | boolean | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n /** Typed JSON-RPC schema for the transport. */\n rpcSchema?: rpcSchema | RpcSchema | undefined\n /** The timeout (in ms) for the HTTP request. Default: 10_000 */\n timeout?: TransportConfig['timeout'] | undefined\n}\n\nexport type HttpTransport<\n rpcSchema extends RpcSchema | undefined = undefined,\n raw extends boolean = false,\n> = Transport<\n 'http',\n {\n fetchOptions?: HttpTransportConfig['fetchOptions'] | undefined\n url?: string | undefined\n },\n BtcRpcRequestFn<rpcSchema, raw>\n>\n\nexport type HttpTransportErrorType =\n | CreateTransportErrorType\n | UrlRequiredErrorType\n | ErrorType\n\n/**\n * @description Creates a HTTP transport that connects to a JSON-RPC API.\n */\nexport function http<\n rpcSchema extends RpcSchema | undefined = undefined,\n raw extends boolean = false,\n>(\n /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */\n url?: string | undefined,\n config: HttpTransportConfig<rpcSchema, raw> = {}\n): HttpTransport<rpcSchema, raw> {\n const {\n batch,\n fetchOptions,\n key = 'http',\n methods = { exclude: UTXOAPISchemaMethods },\n name = 'HTTP JSON-RPC',\n onFetchRequest,\n onFetchResponse,\n retryDelay,\n raw,\n } = config\n return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {\n const { batchSize = 1000, wait = 0 } =\n typeof batch === 'object' ? batch : {}\n const retryCount = config.retryCount ?? retryCount_\n const timeout = timeout_ ?? config.timeout ?? 10_000\n const url_ = url || chain?.rpcUrls.default.http[0]\n if (!url_) {\n throw new UrlRequiredError()\n }\n\n const rpcClient = getHttpRpcClient(url_, {\n fetchOptions,\n onRequest: onFetchRequest,\n onResponse: onFetchResponse,\n timeout,\n })\n\n return createTransport(\n {\n key,\n methods,\n name,\n async request({ method, params }) {\n const body = {\n jsonrpc: '2.0' as const,\n id: idCache.take(),\n method,\n params,\n }\n\n const { schedule } = createBatchScheduler({\n id: url_,\n wait,\n shouldSplitBatch(requests) {\n return requests.length > batchSize\n },\n fn: (body: RpcRequest[]) =>\n rpcClient.request({\n body,\n }),\n sort: (a, b) => a.id - b.id,\n })\n\n const fn = async (body: RpcRequest) =>\n batch\n ? schedule(body)\n : [\n await rpcClient.request({\n body,\n }),\n ]\n\n const [{ error, result }] = await fn(body)\n\n if (raw) {\n return { error, result }\n }\n if (error) {\n throw new RpcRequestError({\n body,\n error,\n url: url_,\n })\n }\n return result\n },\n retryCount,\n retryDelay,\n timeout,\n type: 'http',\n },\n {\n fetchOptions,\n url: url_,\n }\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AAsFA,SAAgB,KAKd,KACA,SAA8C,
|
|
1
|
+
{"version":3,"file":"http.js","names":[],"sources":["../../../src/transports/http.ts"],"sourcesContent":["import { RpcRequestError } from '../errors/request.js'\nimport {\n UrlRequiredError,\n type UrlRequiredErrorType,\n} from '../errors/transport.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type { BtcRpcRequestFn, RpcSchema } from '../types/request.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\nimport { createBatchScheduler } from '../utils/createBatchScheduler.js'\nimport { idCache } from '../utils/idCache.js'\nimport {\n getHttpRpcClient,\n type HttpRpcClientOptions,\n type RpcRequest,\n} from './getHttpRpcClient.js'\nimport { UTXOAPISchemaMethods } from './types.js'\n\nexport type HttpTransportConfig<\n rpcSchema extends RpcSchema | undefined = undefined,\n raw extends boolean = false,\n> = {\n /**\n * Whether to enable Batch JSON-RPC.\n * @link https://www.jsonrpc.org/specification#batch\n */\n batch?:\n | boolean\n | {\n /** The maximum number of JSON-RPC requests to send in a batch. @default 1_000 */\n batchSize?: number | undefined\n /** The maximum number of milliseconds to wait before sending a batch. @default 0 */\n wait?: number | undefined\n }\n | undefined\n /**\n * Request configuration to pass to `fetch`.\n * @link https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined\n /** A callback to handle the response from `fetch`. */\n onFetchRequest?: HttpRpcClientOptions['onRequest'] | undefined\n /** A callback to handle the response from `fetch`. */\n onFetchResponse?: HttpRpcClientOptions['onResponse'] | undefined\n /** The key of the HTTP transport. */\n key?: TransportConfig['key'] | undefined\n /** Methods to include or exclude from executing RPC requests. */\n methods?: TransportConfig['methods'] | undefined\n /** The name of the HTTP transport. */\n name?: TransportConfig['name'] | undefined\n /** Whether to return JSON RPC errors as responses instead of throwing. */\n raw?: raw | boolean | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n /** Typed JSON-RPC schema for the transport. */\n rpcSchema?: rpcSchema | RpcSchema | undefined\n /** The timeout (in ms) for the HTTP request. Default: 10_000 */\n timeout?: TransportConfig['timeout'] | undefined\n}\n\nexport type HttpTransport<\n rpcSchema extends RpcSchema | undefined = undefined,\n raw extends boolean = false,\n> = Transport<\n 'http',\n {\n fetchOptions?: HttpTransportConfig['fetchOptions'] | undefined\n url?: string | undefined\n },\n BtcRpcRequestFn<rpcSchema, raw>\n>\n\nexport type HttpTransportErrorType =\n | CreateTransportErrorType\n | UrlRequiredErrorType\n | ErrorType\n\n/**\n * @description Creates a HTTP transport that connects to a JSON-RPC API.\n */\nexport function http<\n rpcSchema extends RpcSchema | undefined = undefined,\n raw extends boolean = false,\n>(\n /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */\n url?: string | undefined,\n config: HttpTransportConfig<rpcSchema, raw> = {}\n): HttpTransport<rpcSchema, raw> {\n const {\n batch,\n fetchOptions,\n key = 'http',\n methods = { exclude: UTXOAPISchemaMethods },\n name = 'HTTP JSON-RPC',\n onFetchRequest,\n onFetchResponse,\n retryDelay,\n raw,\n } = config\n return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {\n const { batchSize = 1000, wait = 0 } =\n typeof batch === 'object' ? batch : {}\n const retryCount = config.retryCount ?? retryCount_\n const timeout = timeout_ ?? config.timeout ?? 10_000\n const url_ = url || chain?.rpcUrls.default.http[0]\n if (!url_) {\n throw new UrlRequiredError()\n }\n\n const rpcClient = getHttpRpcClient(url_, {\n fetchOptions,\n onRequest: onFetchRequest,\n onResponse: onFetchResponse,\n timeout,\n })\n\n return createTransport(\n {\n key,\n methods,\n name,\n async request({ method, params }) {\n const body = {\n jsonrpc: '2.0' as const,\n id: idCache.take(),\n method,\n params,\n }\n\n const { schedule } = createBatchScheduler({\n id: url_,\n wait,\n shouldSplitBatch(requests) {\n return requests.length > batchSize\n },\n fn: (body: RpcRequest[]) =>\n rpcClient.request({\n body,\n }),\n sort: (a, b) => a.id - b.id,\n })\n\n const fn = async (body: RpcRequest) =>\n batch\n ? schedule(body)\n : [\n await rpcClient.request({\n body,\n }),\n ]\n\n const [{ error, result }] = await fn(body)\n\n if (raw) {\n return { error, result }\n }\n if (error) {\n throw new RpcRequestError({\n body,\n error,\n url: url_,\n })\n }\n return result\n },\n retryCount,\n retryDelay,\n timeout,\n type: 'http',\n },\n {\n fetchOptions,\n url: url_,\n }\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AAsFA,SAAgB,KAKd,KACA,SAA8C,CAAC,GAChB;CAC/B,MAAM,EACJ,OACA,cACA,MAAM,QACN,UAAU,EAAE,SAAS,qBAAqB,GAC1C,OAAO,iBACP,gBACA,iBACA,YACA,QACE;CACJ,QAAQ,EAAE,OAAO,YAAY,aAAa,SAAS,eAAe;EAChE,MAAM,EAAE,YAAY,KAAM,OAAO,MAC/B,OAAO,UAAU,WAAW,QAAQ,CAAC;EACvC,MAAM,aAAa,OAAO,cAAc;EACxC,MAAM,UAAU,YAAY,OAAO,WAAW;EAC9C,MAAM,OAAO,OAAO,OAAO,QAAQ,QAAQ,KAAK;EAChD,IAAI,CAAC,MACH,MAAM,IAAI,iBAAiB;EAG7B,MAAM,YAAY,iBAAiB,MAAM;GACvC;GACA,WAAW;GACX,YAAY;GACZ;EACF,CAAC;EAED,OAAO,gBACL;GACE;GACA;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,UAAU;IAChC,MAAM,OAAO;KACX,SAAS;KACT,IAAI,QAAQ,KAAK;KACjB;KACA;IACF;IAEA,MAAM,EAAE,aAAa,qBAAqB;KACxC,IAAI;KACJ;KACA,iBAAiB,UAAU;MACzB,OAAO,SAAS,SAAS;KAC3B;KACA,KAAK,SACH,UAAU,QAAQ,EAChB,KACF,CAAC;KACH,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE;IAC3B,CAAC;IAED,MAAM,KAAK,OAAO,SAChB,QACI,SAAS,IAAI,IACb,CACE,MAAM,UAAU,QAAQ,EACtB,KACF,CAAC,CACH;IAEN,MAAM,CAAC,EAAE,OAAO,YAAY,MAAM,GAAG,IAAI;IAEzC,IAAI,KACF,OAAO;KAAE;KAAO;IAAO;IAEzB,IAAI,OACF,MAAM,IAAI,gBAAgB;KACxB;KACA;KACA,KAAK;IACP,CAAC;IAEH,OAAO;GACT;GACA;GACA;GACA;GACA,MAAM;EACR,GACA;GACE;GACA,KAAK;EACP,CACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBalance.js","names":[],"sources":["../../../../src/transports/mempool/getBalance.ts"],"sourcesContent":["import type { RpcMethodHandler } from '../types.js'\nimport type { MempoolBalanceResponse } from './mempool.types.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl },\n { address }\n) => {\n const apiUrl = `${baseUrl}/address/${address}`\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolBalanceResponse\n const balance =\n response.chain_stats.funded_txo_sum - response.chain_stats.spent_txo_sum\n return {\n result: BigInt(balance),\n }\n}\n"],"mappings":";AAGA,MAAa,aAA6C,OACxD,QACA,EAAE,WACF,EAAE,cACC;CACH,MAAM,SAAS,GAAG,QAAQ,WAAW;CACrC,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"getBalance.js","names":[],"sources":["../../../../src/transports/mempool/getBalance.ts"],"sourcesContent":["import type { RpcMethodHandler } from '../types.js'\nimport type { MempoolBalanceResponse } from './mempool.types.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl },\n { address }\n) => {\n const apiUrl = `${baseUrl}/address/${address}`\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolBalanceResponse\n const balance =\n response.chain_stats.funded_txo_sum - response.chain_stats.spent_txo_sum\n return {\n result: BigInt(balance),\n }\n}\n"],"mappings":";AAGA,MAAa,aAA6C,OACxD,QACA,EAAE,WACF,EAAE,cACC;CACH,MAAM,SAAS,GAAG,QAAQ,WAAW;CACrC,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CACD,MAAM,UACJ,SAAS,YAAY,iBAAiB,SAAS,YAAY;CAC7D,OAAO,EACL,QAAQ,OAAO,OAAO,EACxB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionFee.js","names":[],"sources":["../../../../src/transports/mempool/getTransactionFee.ts"],"sourcesContent":["import type { RpcMethodHandler } from '../types.js'\nimport type { MempoolTransaction } from './mempool.types.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl },\n { txId }\n) => {\n const apiUrl = `${baseUrl}/tx/${txId}`\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolTransaction\n\n return {\n result: BigInt(response.fee),\n }\n}\n"],"mappings":";AAGA,MAAa,oBAA2D,OACtE,QACA,EAAE,WACF,EAAE,WACC;CACH,MAAM,SAAS,GAAG,QAAQ,MAAM;CAEhC,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"getTransactionFee.js","names":[],"sources":["../../../../src/transports/mempool/getTransactionFee.ts"],"sourcesContent":["import type { RpcMethodHandler } from '../types.js'\nimport type { MempoolTransaction } from './mempool.types.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl },\n { txId }\n) => {\n const apiUrl = `${baseUrl}/tx/${txId}`\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolTransaction\n\n return {\n result: BigInt(response.fee),\n }\n}\n"],"mappings":";AAGA,MAAa,oBAA2D,OACtE,QACA,EAAE,WACF,EAAE,WACC;CACH,MAAM,SAAS,GAAG,QAAQ,MAAM;CAEhC,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,OAAO,EACL,QAAQ,OAAO,SAAS,GAAG,EAC7B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactions.js","names":[],"sources":["../../../../src/transports/mempool/getTransactions.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n MempoolBalanceResponse,\n MempoolUTXOTransactionsResponse,\n} from './mempool.types.js'\nimport { mempoolTransactionTransformer } from './utils.js'\n\nexport const getTransactions: RpcMethodHandler<'getTransactions'> = async (\n client,\n { baseUrl },\n { address, limit = 50, offset = 0, afterTxId }\n) => {\n const apiUrlAddress = `${baseUrl}/address/${address}`\n const balanceResponse = (await client.request({\n url: apiUrlAddress,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolBalanceResponse\n const totalTxns =\n balanceResponse.chain_stats.tx_count +\n balanceResponse.mempool_stats.tx_count\n\n const apiUrl = urlWithParams(`${baseUrl}/address/${address}/txs`, {\n after_txid: afterTxId,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolUTXOTransactionsResponse\n\n const transactions = response.map(mempoolTransactionTransformer)\n\n const result = {\n transactions,\n total: totalTxns,\n itemsPerPage: limit,\n hasMore: offset + transactions.length < totalTxns,\n }\n\n return {\n result,\n }\n}\n"],"mappings":";;;AAQA,MAAa,kBAAuD,OAClE,QACA,EAAE,WACF,EAAE,SAAS,QAAQ,IAAI,SAAS,GAAG,gBAChC;CACH,MAAM,gBAAgB,GAAG,QAAQ,WAAW;CAC5C,MAAM,kBAAmB,MAAM,OAAO,QAAQ;EAC5C,KAAK;EACL,cAAc,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"getTransactions.js","names":[],"sources":["../../../../src/transports/mempool/getTransactions.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n MempoolBalanceResponse,\n MempoolUTXOTransactionsResponse,\n} from './mempool.types.js'\nimport { mempoolTransactionTransformer } from './utils.js'\n\nexport const getTransactions: RpcMethodHandler<'getTransactions'> = async (\n client,\n { baseUrl },\n { address, limit = 50, offset = 0, afterTxId }\n) => {\n const apiUrlAddress = `${baseUrl}/address/${address}`\n const balanceResponse = (await client.request({\n url: apiUrlAddress,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolBalanceResponse\n const totalTxns =\n balanceResponse.chain_stats.tx_count +\n balanceResponse.mempool_stats.tx_count\n\n const apiUrl = urlWithParams(`${baseUrl}/address/${address}/txs`, {\n after_txid: afterTxId,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as MempoolUTXOTransactionsResponse\n\n const transactions = response.map(mempoolTransactionTransformer)\n\n const result = {\n transactions,\n total: totalTxns,\n itemsPerPage: limit,\n hasMore: offset + transactions.length < totalTxns,\n }\n\n return {\n result,\n }\n}\n"],"mappings":";;;AAQA,MAAa,kBAAuD,OAClE,QACA,EAAE,WACF,EAAE,SAAS,QAAQ,IAAI,SAAS,GAAG,gBAChC;CACH,MAAM,gBAAgB,GAAG,QAAQ,WAAW;CAC5C,MAAM,kBAAmB,MAAM,OAAO,QAAQ;EAC5C,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CACD,MAAM,YACJ,gBAAgB,YAAY,WAC5B,gBAAgB,cAAc;CAEhC,MAAM,SAAS,cAAc,GAAG,QAAQ,WAAW,QAAQ,OAAO,EAChE,YAAY,UACd,CAAC;CAOD,MAAM,gBAAe,MALG,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC,GAE6B,IAAI,6BAA6B;CAS/D,OAAO,EACL,QAAA;EAPA;EACA,OAAO;EACP,cAAc;EACd,SAAS,SAAS,aAAa,SAAS;CAInC,EACP;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mempool.js","names":[],"sources":["../../../../src/transports/mempool/mempool.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { mempoolMethods } from './methods.js'\n\ntype MempoolConfig = {\n baseUrl?: string\n} & HttpTransportConfig\n\nexport const mempool = (config?: MempoolConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://mempool.space/api', {\n name: 'Mempool.space API',\n key: 'mempool',\n methods: {\n include: Object.keys(mempoolMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;AASA,MAAa,WAAW,WACtB,KAAK,QAAQ,WAAW,6BAA6B;CACnD,MAAM;CACN,KAAK;CACL,SAAS,EACP,SAAS,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mempool.js","names":[],"sources":["../../../../src/transports/mempool/mempool.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { mempoolMethods } from './methods.js'\n\ntype MempoolConfig = {\n baseUrl?: string\n} & HttpTransportConfig\n\nexport const mempool = (config?: MempoolConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://mempool.space/api', {\n name: 'Mempool.space API',\n key: 'mempool',\n methods: {\n include: Object.keys(mempoolMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;AASA,MAAa,WAAW,WACtB,KAAK,QAAQ,WAAW,6BAA6B;CACnD,MAAM;CACN,KAAK;CACL,SAAS,EACP,SAAS,OAAO,KAAK,cAAc,EACrC;CACA,GAAG;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/mempool/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getTransactions } from './getTransactions.js'\n\nexport const mempoolMethods: RpcMethods = {\n getBalance,\n getTransactions,\n getTransactionFee,\n}\n"],"mappings":";;;;AAKA,MAAa,iBAA6B;CACxC;CACA;CACA;
|
|
1
|
+
{"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/mempool/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getTransactions } from './getTransactions.js'\n\nexport const mempoolMethods: RpcMethods = {\n getBalance,\n getTransactions,\n getTransactionFee,\n}\n"],"mappings":";;;;AAKA,MAAa,iBAA6B;CACxC;CACA;CACA;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/transports/mempool/utils.ts"],"sourcesContent":["import type { UTXOTransaction } from '../../types/transaction.js'\nimport type { MempoolTransaction } from './mempool.types.js'\n\nexport const mempoolTransactionTransformer = (\n txn: MempoolTransaction\n): Partial<UTXOTransaction> => ({\n hash: txn.txid,\n txid: txn.txid,\n vout: txn.vout.map((vout, index) => ({\n n: index,\n scriptPubKey: {\n address: vout.scriptpubkey_address,\n asm: vout.scriptpubkey_asm,\n type: vout.scriptpubkey_type,\n desc: vout.scriptpubkey,\n hex: vout.scriptpubkey,\n },\n value: vout.value,\n })),\n vin: txn.vin.map((vin) => ({\n scriptSig: {\n asm: vin.scriptsig_asm,\n hex: vin.scriptsig,\n },\n sequence: vin.sequence,\n txinwitness: vin.witness,\n txid: vin.txid,\n vout: vin.vout,\n })),\n})\n"],"mappings":";AAGA,MAAa,iCACX,SAC8B;CAC9B,MAAM,IAAI;CACV,MAAM,IAAI;CACV,MAAM,IAAI,KAAK,KAAK,MAAM,WAAW;EACnC,GAAG;EACH,cAAc;GACZ,SAAS,KAAK;GACd,KAAK,KAAK;GACV,MAAM,KAAK;GACX,MAAM,KAAK;GACX,KAAK,KAAK;
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/transports/mempool/utils.ts"],"sourcesContent":["import type { UTXOTransaction } from '../../types/transaction.js'\nimport type { MempoolTransaction } from './mempool.types.js'\n\nexport const mempoolTransactionTransformer = (\n txn: MempoolTransaction\n): Partial<UTXOTransaction> => ({\n hash: txn.txid,\n txid: txn.txid,\n vout: txn.vout.map((vout, index) => ({\n n: index,\n scriptPubKey: {\n address: vout.scriptpubkey_address,\n asm: vout.scriptpubkey_asm,\n type: vout.scriptpubkey_type,\n desc: vout.scriptpubkey,\n hex: vout.scriptpubkey,\n },\n value: vout.value,\n })),\n vin: txn.vin.map((vin) => ({\n scriptSig: {\n asm: vin.scriptsig_asm,\n hex: vin.scriptsig,\n },\n sequence: vin.sequence,\n txinwitness: vin.witness,\n txid: vin.txid,\n vout: vin.vout,\n })),\n})\n"],"mappings":";AAGA,MAAa,iCACX,SAC8B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AzBA;IA2BA,OAAA,UAzBA;IA2BA,cAAA;EAAA;;;;;AApBC;AAGL;EAyBE,QAAA;AAAA;AAAA,KAGU,kBAAA;AAAA,KAEA,gBAAA;EAER,MAAA;EACA,UAAA,EAAY,kBAAA;EACZ,UAAA,EAAY,kBAAA;AAAA;AAAA,KAIJ,aAAA;EACV,MAAA;EACA,MAAA,EAAQ,MAAA;EACR,KAAA;AAAA;AAAA,KAEU,WAAA;EACV,MAAA;EACA,MAAA;EACA,KAAA,EAAO,KAAA;AAAA;AAAA,KAGG,WAAA,8BACR,aAAA,CAAc,MAAA,IACd,WAAA,CAAY,KAAA;AAAA,KAEJ,gBAAA,WAA2B,UAAA,GAAa,UAAA,KAClD,MAAA,EAAQ,aAAA,EACR,MAAA;EAAU,OAAA;EAAiB,MAAA;AAAA,GAC3B,MAAA,EAAQ,OAAA,CAAQ,UAAA;EAAsB,MAAA,EAAQ,CAAA;AAAA,qBAC3C,OAAA,CACH,WAAA,CAAY,OAAA,CAAQ,UAAA;EAAsB,MAAA,EAAQ,CAAA;AAAA;AAAA,KAGxC,UAAA,aACF,UAAA,IAAc,gBAAA,CAAiB,GAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/transports/types.ts"],"sourcesContent":["import type { BlockStats, BlockStatsKeys } from '../types/blockStats.js'\nimport type { UTXO, UTXOTransaction } from '../types/transaction.js'\nimport type { xPubAccount } from '../types/xpub.js'\nimport type { HttpRpcClient } from './getHttpRpcClient.js'\n\nexport const UTXOAPISchemaMethods: UTXOMethod[] = [\n 'getBalance',\n 'getTransactions',\n 'getUTXOs',\n 'getTransactionFee',\n 'getXPubAddresses',\n]\n\nexport type UTXOAPISchema = [\n {\n Method: 'getBalance'\n Parameters: { address: string }\n ReturnType: bigint\n },\n {\n Method: 'getTransactions'\n Parameters: {\n address: string\n offset?: number\n limit?: number\n lastBlock?: string\n afterTxId?: string\n }\n ReturnType: {\n transactions: Array<Partial<UTXOTransaction>>\n total: number\n hasMore?: boolean\n }\n },\n {\n Method: 'getTransactionFee'\n Parameters: {\n txId: string\n }\n ReturnType: bigint\n },\n {\n Method: 'getUTXOs'\n Parameters: {\n address: string\n minValue?: number\n }\n ReturnType: Array<UTXO>\n },\n {\n Method: 'getXPubAddresses'\n Parameters: {\n xPubKey: string\n }\n ReturnType: xPubAccount\n },\n]\n\nexport type UTXOSchema = [\n {\n Method: 'getblockcount'\n Parameters: []\n ReturnType: number\n },\n {\n Method: 'getblockhash'\n Parameters: [number]\n ReturnType: string\n },\n {\n Method: 'getblock'\n Parameters: [string, number]\n ReturnType: string\n },\n {\n Method: 'getblockstats'\n Parameters: [string | number, Array<BlockStatsKeys>?]\n ReturnType: BlockStats\n },\n {\n Method: 'sendrawtransaction'\n Parameters: [string, number?]\n ReturnType: string\n },\n {\n Method: 'getrawtransaction'\n Parameters: [string, boolean, string?]\n ReturnType: UTXOTransaction\n },\n ...UTXOAPISchema,\n]\n\nexport type UTXOMethod = UTXOSchema[number]['Method']\n\nexport type SignPsbtParameters = {\n /** The PSBT encoded as a hexadecimal string */\n psbt: string\n /**\n * Array of objects specifying details about the inputs to be signed\n */\n inputsToSign: {\n /**\n * The SigHash type to use for signing (e.g., SIGHASH_ALL).\n * If not specified, a default value is used.\n */\n sigHash?: number\n /** The Bitcoin address associated with the input that will be signed */\n address: string\n /** An array of indexes in the PSBT corresponding to the inputs that need to be signed */\n signingIndexes: number[]\n }[]\n /**\n * Whether to finalize the PSBT after signing.\n * If `true`, the PSBT will be completed and ready for broadcasting.\n * If `false` or omitted, the PSBT remains partially signed.\n * Some wallets does not support it.\n */\n finalize?: boolean\n}\n\nexport type SignPsbtReturnType = string\n\nexport type UTXOWalletSchema = readonly [\n {\n Method: 'signPsbt'\n Parameters: SignPsbtParameters\n ReturnType: SignPsbtReturnType\n },\n]\n\nexport type SuccessResult<result> = {\n method?: undefined\n result: result\n error?: undefined\n}\nexport type ErrorResult<error> = {\n method?: undefined\n result?: undefined\n error: error\n}\n\nexport type RpcResponse<result = any, error = any> =\n | SuccessResult<result>\n | ErrorResult<error>\n\nexport type RpcMethodHandler<M extends UTXOMethod = UTXOMethod> = (\n client: HttpRpcClient,\n config: { baseUrl: string; apiKey?: string },\n params: Extract<UTXOSchema[number], { Method: M }>['Parameters']\n) => Promise<\n RpcResponse<Extract<UTXOSchema[number], { Method: M }>['ReturnType']>\n>\n\nexport type RpcMethods = {\n [key in UTXOMethod]?: RpcMethodHandler<key>\n}\n"],"mappings":";AAKA,MAAa,uBAAqC;CAChD;CACA;CACA;CACA;CACA;
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/transports/types.ts"],"sourcesContent":["import type { BlockStats, BlockStatsKeys } from '../types/blockStats.js'\nimport type { UTXO, UTXOTransaction } from '../types/transaction.js'\nimport type { xPubAccount } from '../types/xpub.js'\nimport type { HttpRpcClient } from './getHttpRpcClient.js'\n\nexport const UTXOAPISchemaMethods: UTXOMethod[] = [\n 'getBalance',\n 'getTransactions',\n 'getUTXOs',\n 'getTransactionFee',\n 'getXPubAddresses',\n]\n\nexport type UTXOAPISchema = [\n {\n Method: 'getBalance'\n Parameters: { address: string }\n ReturnType: bigint\n },\n {\n Method: 'getTransactions'\n Parameters: {\n address: string\n offset?: number\n limit?: number\n lastBlock?: string\n afterTxId?: string\n }\n ReturnType: {\n transactions: Array<Partial<UTXOTransaction>>\n total: number\n hasMore?: boolean\n }\n },\n {\n Method: 'getTransactionFee'\n Parameters: {\n txId: string\n }\n ReturnType: bigint\n },\n {\n Method: 'getUTXOs'\n Parameters: {\n address: string\n minValue?: number\n }\n ReturnType: Array<UTXO>\n },\n {\n Method: 'getXPubAddresses'\n Parameters: {\n xPubKey: string\n }\n ReturnType: xPubAccount\n },\n]\n\nexport type UTXOSchema = [\n {\n Method: 'getblockcount'\n Parameters: []\n ReturnType: number\n },\n {\n Method: 'getblockhash'\n Parameters: [number]\n ReturnType: string\n },\n {\n Method: 'getblock'\n Parameters: [string, number]\n ReturnType: string\n },\n {\n Method: 'getblockstats'\n Parameters: [string | number, Array<BlockStatsKeys>?]\n ReturnType: BlockStats\n },\n {\n Method: 'sendrawtransaction'\n Parameters: [string, number?]\n ReturnType: string\n },\n {\n Method: 'getrawtransaction'\n Parameters: [string, boolean, string?]\n ReturnType: UTXOTransaction\n },\n ...UTXOAPISchema,\n]\n\nexport type UTXOMethod = UTXOSchema[number]['Method']\n\nexport type SignPsbtParameters = {\n /** The PSBT encoded as a hexadecimal string */\n psbt: string\n /**\n * Array of objects specifying details about the inputs to be signed\n */\n inputsToSign: {\n /**\n * The SigHash type to use for signing (e.g., SIGHASH_ALL).\n * If not specified, a default value is used.\n */\n sigHash?: number\n /** The Bitcoin address associated with the input that will be signed */\n address: string\n /** An array of indexes in the PSBT corresponding to the inputs that need to be signed */\n signingIndexes: number[]\n }[]\n /**\n * Whether to finalize the PSBT after signing.\n * If `true`, the PSBT will be completed and ready for broadcasting.\n * If `false` or omitted, the PSBT remains partially signed.\n * Some wallets does not support it.\n */\n finalize?: boolean\n}\n\nexport type SignPsbtReturnType = string\n\nexport type UTXOWalletSchema = readonly [\n {\n Method: 'signPsbt'\n Parameters: SignPsbtParameters\n ReturnType: SignPsbtReturnType\n },\n]\n\nexport type SuccessResult<result> = {\n method?: undefined\n result: result\n error?: undefined\n}\nexport type ErrorResult<error> = {\n method?: undefined\n result?: undefined\n error: error\n}\n\nexport type RpcResponse<result = any, error = any> =\n | SuccessResult<result>\n | ErrorResult<error>\n\nexport type RpcMethodHandler<M extends UTXOMethod = UTXOMethod> = (\n client: HttpRpcClient,\n config: { baseUrl: string; apiKey?: string },\n params: Extract<UTXOSchema[number], { Method: M }>['Parameters']\n) => Promise<\n RpcResponse<Extract<UTXOSchema[number], { Method: M }>['ReturnType']>\n>\n\nexport type RpcMethods = {\n [key in UTXOMethod]?: RpcMethodHandler<key>\n}\n"],"mappings":";AAKA,MAAa,uBAAqC;CAChD;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utxo.js","names":[],"sources":["../../../src/transports/utxo.ts"],"sourcesContent":["import { RpcRequestError } from '../errors/request.js'\nimport { UrlRequiredError } from '../errors/transport.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport { idCache } from '../utils/idCache.js'\nimport { getHttpRpcClient } from './getHttpRpcClient.js'\nimport { getRpcProviderMethods } from './getRpcProviderMethods.js'\nimport type { HttpTransport, HttpTransportConfig } from './http.js'\nimport type { UTXOMethod } from './types.js'\n\ntype UTXOHttpTransportConfig = HttpTransportConfig & {\n includeChainToURL?: boolean\n apiKey?: string\n}\n\nexport function utxo(\n url?: string,\n config: UTXOHttpTransportConfig = {}\n): HttpTransport {\n const {\n fetchOptions,\n key = 'utxo',\n name = 'UTXO HTTP API',\n onFetchRequest,\n onFetchResponse,\n retryDelay,\n apiKey,\n methods,\n } = config\n\n return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {\n const retryCount = config.retryCount ?? retryCount_\n const timeout = timeout_ ?? config.timeout ?? 10_000\n let url_ = url\n if (config.includeChainToURL) {\n const chainName = chain?.name.replace(' ', '-').toLowerCase()\n url_ = `${url}${chainName ? `/${chainName}` : ''}`\n }\n if (!url_) {\n throw new UrlRequiredError()\n }\n\n const client = getHttpRpcClient(url_, {\n fetchOptions,\n onRequest: onFetchRequest,\n onResponse: onFetchResponse,\n timeout,\n })\n\n const rpcMethods = getRpcProviderMethods(key)\n\n return createTransport(\n {\n key,\n name,\n methods,\n async request({ method, params }) {\n const body = {\n jsonrpc: '2.0' as const,\n id: idCache.take(),\n method,\n params,\n }\n const methodHandler = rpcMethods?.[method as UTXOMethod]\n const { error, result } = await (methodHandler?.(\n client,\n { baseUrl: url_, apiKey },\n params\n ) ??\n client.request({\n body,\n }))\n if (error) {\n throw new RpcRequestError({\n body,\n error,\n url: url_,\n })\n }\n return result\n },\n retryCount,\n retryDelay,\n timeout,\n type: 'http',\n },\n {\n fetchOptions,\n url: url_,\n }\n )\n }\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,KACd,KACA,SAAkC,
|
|
1
|
+
{"version":3,"file":"utxo.js","names":[],"sources":["../../../src/transports/utxo.ts"],"sourcesContent":["import { RpcRequestError } from '../errors/request.js'\nimport { UrlRequiredError } from '../errors/transport.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport { idCache } from '../utils/idCache.js'\nimport { getHttpRpcClient } from './getHttpRpcClient.js'\nimport { getRpcProviderMethods } from './getRpcProviderMethods.js'\nimport type { HttpTransport, HttpTransportConfig } from './http.js'\nimport type { UTXOMethod } from './types.js'\n\ntype UTXOHttpTransportConfig = HttpTransportConfig & {\n includeChainToURL?: boolean\n apiKey?: string\n}\n\nexport function utxo(\n url?: string,\n config: UTXOHttpTransportConfig = {}\n): HttpTransport {\n const {\n fetchOptions,\n key = 'utxo',\n name = 'UTXO HTTP API',\n onFetchRequest,\n onFetchResponse,\n retryDelay,\n apiKey,\n methods,\n } = config\n\n return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {\n const retryCount = config.retryCount ?? retryCount_\n const timeout = timeout_ ?? config.timeout ?? 10_000\n let url_ = url\n if (config.includeChainToURL) {\n const chainName = chain?.name.replace(' ', '-').toLowerCase()\n url_ = `${url}${chainName ? `/${chainName}` : ''}`\n }\n if (!url_) {\n throw new UrlRequiredError()\n }\n\n const client = getHttpRpcClient(url_, {\n fetchOptions,\n onRequest: onFetchRequest,\n onResponse: onFetchResponse,\n timeout,\n })\n\n const rpcMethods = getRpcProviderMethods(key)\n\n return createTransport(\n {\n key,\n name,\n methods,\n async request({ method, params }) {\n const body = {\n jsonrpc: '2.0' as const,\n id: idCache.take(),\n method,\n params,\n }\n const methodHandler = rpcMethods?.[method as UTXOMethod]\n const { error, result } = await (methodHandler?.(\n client,\n { baseUrl: url_, apiKey },\n params\n ) ??\n client.request({\n body,\n }))\n if (error) {\n throw new RpcRequestError({\n body,\n error,\n url: url_,\n })\n }\n return result\n },\n retryCount,\n retryDelay,\n timeout,\n type: 'http',\n },\n {\n fetchOptions,\n url: url_,\n }\n )\n }\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,KACd,KACA,SAAkC,CAAC,GACpB;CACf,MAAM,EACJ,cACA,MAAM,QACN,OAAO,iBACP,gBACA,iBACA,YACA,QACA,YACE;CAEJ,QAAQ,EAAE,OAAO,YAAY,aAAa,SAAS,eAAe;EAChE,MAAM,aAAa,OAAO,cAAc;EACxC,MAAM,UAAU,YAAY,OAAO,WAAW;EAC9C,IAAI,OAAO;EACX,IAAI,OAAO,mBAAmB;GAC5B,MAAM,YAAY,OAAO,KAAK,QAAQ,KAAK,GAAG,EAAE,YAAY;GAC5D,OAAO,GAAG,MAAM,YAAY,IAAI,cAAc;EAChD;EACA,IAAI,CAAC,MACH,MAAM,IAAI,iBAAiB;EAG7B,MAAM,SAAS,iBAAiB,MAAM;GACpC;GACA,WAAW;GACX,YAAY;GACZ;EACF,CAAC;EAED,MAAM,aAAa,sBAAsB,GAAG;EAE5C,OAAO,gBACL;GACE;GACA;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,UAAU;IAChC,MAAM,OAAO;KACX,SAAS;KACT,IAAI,QAAQ,KAAK;KACjB;KACA;IACF;IACA,MAAM,gBAAgB,aAAa;IACnC,MAAM,EAAE,OAAO,WAAW,OAAO,gBAC/B,QACA;KAAE,SAAS;KAAM;IAAO,GACxB,MACF,KACE,OAAO,QAAQ,EACb,KACF,CAAC;IACH,IAAI,OACF,MAAM,IAAI,gBAAgB;KACxB;KACA;KACA,KAAK;IACP,CAAC;IAEH,OAAO;GACT;GACA;GACA;GACA;GACA,MAAM;EACR,GACA;GACE;GACA,KAAK;EACP,CACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","names":[],"sources":["../../../src/types/address.ts"],"sourcesContent":["import type { Network } from './chain.js'\n\nexport type Address = string\n\nexport type AddressPurpose = 'payment' | 'ordinals' | 'stacks'\n\nexport enum AddressType {\n p2pkh = 'p2pkh',\n p2sh = 'p2sh',\n p2wpkh = 'p2wpkh',\n p2wsh = 'p2wsh',\n p2tr = 'p2tr',\n}\n\nexport type AddressInfo = {\n bech32: boolean\n network: Network\n address: Address\n type: AddressType\n purpose: AddressPurpose\n}\n"],"mappings":";AAMA,IAAY,cAAL,yBAAA,aAAA;
|
|
1
|
+
{"version":3,"file":"address.js","names":[],"sources":["../../../src/types/address.ts"],"sourcesContent":["import type { Network } from './chain.js'\n\nexport type Address = string\n\nexport type AddressPurpose = 'payment' | 'ordinals' | 'stacks'\n\nexport enum AddressType {\n p2pkh = 'p2pkh',\n p2sh = 'p2sh',\n p2wpkh = 'p2wpkh',\n p2wsh = 'p2wsh',\n p2tr = 'p2tr',\n}\n\nexport type AddressInfo = {\n bech32: boolean\n network: Network\n address: Address\n type: AddressType\n purpose: AddressPurpose\n}\n"],"mappings":";AAMA,IAAY,cAAL,yBAAA,aAAA;CACL,YAAA,WAAA;CACA,YAAA,UAAA;CACA,YAAA,YAAA;CACA,YAAA,WAAA;CACA,YAAA,UAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","names":[],"sources":["../../../src/types/block.ts"],"mappings":";;AAkBA
|
|
1
|
+
{"version":3,"file":"block.d.ts","names":[],"sources":["../../../src/types/block.ts"],"mappings":";;AAkBA;;;;AAAY;;;;;;;;;;;;;KAAA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","names":[],"sources":["../../../src/types/chain.ts"],"sourcesContent":["export enum ChainId {\n BITCOIN_MAINNET = 'bitcoin:mainnet',\n BITCOIN_TESTNET = 'bitcoin:testnet',\n BITCOIN_TESTNET4 = 'bitcoin:testnet4',\n BITCOIN_SIGNET = 'bitcoin:signet',\n FRACTAL_BITCOIN_MAINNET = 'fractal:mainnet',\n FRACTAL_BITCOIN_TESTNET = 'fractal:testnet',\n STACKS_MAINNET = 'stacks:mainnet',\n STACKS_TESTNET = 'stacks:testnet',\n}\n\nexport enum Network {\n Mainnet = 'mainnet',\n Testnet = 'testnet',\n Regtest = 'regtest',\n}\n\nexport type Chain<\n formatters extends ChainFormatters | undefined = ChainFormatters | undefined,\n custom extends Record<string, unknown> | undefined =\n | Record<string, unknown>\n | undefined,\n> = {\n /** Collection of block explorers */\n blockExplorers?:\n | {\n [key: string]: ChainBlockExplorer\n default: ChainBlockExplorer\n }\n | undefined\n /** ID in number form */\n id: ChainId\n /** Human-readable name */\n name: string\n /** Collection of RPC endpoints */\n rpcUrls: {\n [key: string]: ChainRpcUrls\n default: ChainRpcUrls\n }\n /** Flag for test networks */\n testnet?: boolean | undefined\n} & ChainConfig<formatters, custom>\n\nexport type ChainConfig<\n formatters extends ChainFormatters | undefined = ChainFormatters | undefined,\n custom extends Record<string, unknown> | undefined =\n | Record<string, unknown>\n | undefined,\n> = {\n /** Custom chain data. */\n custom?: custom | undefined\n /** Modifies how data is formatted and typed (e.g. blocks and transactions) */\n formatters?: formatters | undefined\n}\n\n/////////////////////////////////////////////////////////////////////\n// Formatters\n/////////////////////////////////////////////////////////////////////\n\nexport type ChainFormatters = {\n /** Modifies how the Block structure is formatted & typed. */\n block?: ChainFormatter<'block'> | undefined\n /** Modifies how the Transaction structure is formatted & typed. */\n transaction?: ChainFormatter<'transaction'> | undefined\n /** Modifies how the TransactionReceipt structure is formatted & typed. */\n transactionReceipt?: ChainFormatter<'transactionReceipt'> | undefined\n /** Modifies how the TransactionRequest structure is formatted & typed. */\n transactionRequest?: ChainFormatter<'transactionRequest'> | undefined\n}\n\nexport type ChainFormatter<type extends string = string> = {\n format: (args: any) => any\n type: type\n}\n\n/////////////////////////////////////////////////////////////////////\n// Constants\n/////////////////////////////////////////////////////////////////////\n\ntype ChainBlockExplorer = {\n name: string\n url: string\n apiUrl?: string | undefined\n}\n\ntype ChainRpcUrls = {\n http: readonly string[]\n webSocket?: readonly string[] | undefined\n}\n"],"mappings":";AAAA,IAAY,UAAL,yBAAA,SAAA;
|
|
1
|
+
{"version":3,"file":"chain.js","names":[],"sources":["../../../src/types/chain.ts"],"sourcesContent":["export enum ChainId {\n BITCOIN_MAINNET = 'bitcoin:mainnet',\n BITCOIN_TESTNET = 'bitcoin:testnet',\n BITCOIN_TESTNET4 = 'bitcoin:testnet4',\n BITCOIN_SIGNET = 'bitcoin:signet',\n FRACTAL_BITCOIN_MAINNET = 'fractal:mainnet',\n FRACTAL_BITCOIN_TESTNET = 'fractal:testnet',\n STACKS_MAINNET = 'stacks:mainnet',\n STACKS_TESTNET = 'stacks:testnet',\n}\n\nexport enum Network {\n Mainnet = 'mainnet',\n Testnet = 'testnet',\n Regtest = 'regtest',\n}\n\nexport type Chain<\n formatters extends ChainFormatters | undefined = ChainFormatters | undefined,\n custom extends Record<string, unknown> | undefined =\n | Record<string, unknown>\n | undefined,\n> = {\n /** Collection of block explorers */\n blockExplorers?:\n | {\n [key: string]: ChainBlockExplorer\n default: ChainBlockExplorer\n }\n | undefined\n /** ID in number form */\n id: ChainId\n /** Human-readable name */\n name: string\n /** Collection of RPC endpoints */\n rpcUrls: {\n [key: string]: ChainRpcUrls\n default: ChainRpcUrls\n }\n /** Flag for test networks */\n testnet?: boolean | undefined\n} & ChainConfig<formatters, custom>\n\nexport type ChainConfig<\n formatters extends ChainFormatters | undefined = ChainFormatters | undefined,\n custom extends Record<string, unknown> | undefined =\n | Record<string, unknown>\n | undefined,\n> = {\n /** Custom chain data. */\n custom?: custom | undefined\n /** Modifies how data is formatted and typed (e.g. blocks and transactions) */\n formatters?: formatters | undefined\n}\n\n/////////////////////////////////////////////////////////////////////\n// Formatters\n/////////////////////////////////////////////////////////////////////\n\nexport type ChainFormatters = {\n /** Modifies how the Block structure is formatted & typed. */\n block?: ChainFormatter<'block'> | undefined\n /** Modifies how the Transaction structure is formatted & typed. */\n transaction?: ChainFormatter<'transaction'> | undefined\n /** Modifies how the TransactionReceipt structure is formatted & typed. */\n transactionReceipt?: ChainFormatter<'transactionReceipt'> | undefined\n /** Modifies how the TransactionRequest structure is formatted & typed. */\n transactionRequest?: ChainFormatter<'transactionRequest'> | undefined\n}\n\nexport type ChainFormatter<type extends string = string> = {\n format: (args: any) => any\n type: type\n}\n\n/////////////////////////////////////////////////////////////////////\n// Constants\n/////////////////////////////////////////////////////////////////////\n\ntype ChainBlockExplorer = {\n name: string\n url: string\n apiUrl?: string | undefined\n}\n\ntype ChainRpcUrls = {\n http: readonly string[]\n webSocket?: readonly string[] | undefined\n}\n"],"mappings":";AAAA,IAAY,UAAL,yBAAA,SAAA;CACL,QAAA,qBAAA;CACA,QAAA,qBAAA;CACA,QAAA,sBAAA;CACA,QAAA,oBAAA;CACA,QAAA,6BAAA;CACA,QAAA,6BAAA;CACA,QAAA,oBAAA;CACA,QAAA,oBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,UAAL,yBAAA,SAAA;CACL,QAAA,aAAA;CACA,QAAA,aAAA;CACA,QAAA,aAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","names":[],"sources":["../../../src/types/client.ts"],"mappings":";;;;;;;;;;KAUY,YAAA,mBACQ,SAAA,GAAY,SAAA,gBAChB,KAAA,eAAoB,KAAA,uCACT,OAAA,GAAU,OAAA,eAC/B,OAAA,GACA,OAAA,gCAEc,SAAA;iHAGlB,OAAA,GAAU,gBAAA,GAAmB,OAAA,GAAU,OAAA;;;;;EAKvC,SAAA;EAEA,KAAA,GAAQ,KAAA,eAAoB,KAAA;EAE5B,GAAA;EAEA,IAAA;;;;;EAKA,eAAA;;;;EAIA,SAAA,GAAY,SAAA;EAEZ,SAAA,EAAW,SAAA;EAEX,IAAA;AAAA;AAAA,KAKU,MAAA,mBACQ,SAAA,GAAY,SAAA,gBAChB,KAAA,eAAoB,KAAA,8BAClB,OAAA,eAAsB,OAAA,gCACpB,SAAA,2CACD,QAAA,eAAuB,QAAA,gBACtC,WAAA,CAAY,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;;KAO5B,SAAA,8BAAuC,IAAA,CACjD,IAAA,EACA,OAAA,OAAc,IAAA,EAAM,IAAA;AAAA,KAMV,YAAA,SAAqB,IAAA,kBAAsB,OAAA,CAAQ,IAAA,IAAQ,IAAA;AAAA,KAE3D,cAAA,8BAA4C,IAAA,eACpD,SAAA,CAAU,IAAA,EAAM,IAAA;AAAA,KAGR,eAAA,0BAAyC,IAAA,IAAQ,IAAA,eACzD,UAAA,CAAW,IAAA,EAAM,IAAA;AAAA,KAGT,iBAAA,SAA0B,IAAA,kBAClC,YAAA,CAAa,IAAA,IACb,IAAA;;;;AAjE0C;AAG9C;;;;KAwEY,QAAA,oBACE,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;;KAUR,MAAA,SAAe,OAAA,CAAQ,CAAA,EAAG,CAAA,IAAK,CAAA;AAAA,KACtC,OAAA,uBACS,CAAA,IAAK,CAAA,eAAgB,CAAA,GAC7B,CAAA,CAAE,CAAA,yBAEA,CAAA,GACF,CAAA,GAAI,CAAA,eAAgB,CAAA,GAAI,CAAA,CAAE,CAAA,IAAK,CAAA,CAAE,CAAA;AAAA,KAG3B,YAAA,MAAkB,CAAA,GAAI,OAAA,CAAQ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRequest.d.ts","names":[],"sources":["../../../src/utils/buildRequest.ts"],"mappings":";;;;KAkBY,gBAAA,GAAmB,SAAA;AAAA,iBAEf,YAAA,iBAA6B,eAAA,CAAgB,SAAA,
|
|
1
|
+
{"version":3,"file":"buildRequest.d.ts","names":[],"sources":["../../../src/utils/buildRequest.ts"],"mappings":";;;;KAkBY,gBAAA,GAAmB,SAAA;AAAA,iBAEf,YAAA,iBAA6B,eAAA,CAAgB,SAAA,GAC3D,OAAA,EAAS,OAAA,EACT,OAAA,GAAS,oBAAA,GACR,eAAA;AALH;AAAA,iBAgFgB,WAAA,CAAY,KAAO,EAAA,KAAA"}
|
|
@@ -2,7 +2,7 @@ import { BaseError } from "../errors/base.js";
|
|
|
2
2
|
import { stringify } from "./stringify.js";
|
|
3
3
|
import { withRetry } from "./withRetry.js";
|
|
4
4
|
import { HttpRequestError } from "../errors/request.js";
|
|
5
|
-
import { MethodNotSupportedRpcError,
|
|
5
|
+
import { MethodNotSupportedRpcError, UserRejectedRequestError } from "../errors/rpc.js";
|
|
6
6
|
import { stringToHex } from "./converter.js";
|
|
7
7
|
import { withDedupe } from "./withDedupe.js";
|
|
8
8
|
//#region src/utils/buildRequest.ts
|
|
@@ -21,8 +21,8 @@ function buildRequest(request, options = {}) {
|
|
|
21
21
|
} catch (err_) {
|
|
22
22
|
const err = err_;
|
|
23
23
|
switch (err.code) {
|
|
24
|
-
case
|
|
25
|
-
case
|
|
24
|
+
case -32001: throw new MethodNotSupportedRpcError(method);
|
|
25
|
+
case -32e3: throw new UserRejectedRequestError(err.message);
|
|
26
26
|
case 5e3: throw new UserRejectedRequestError(err.message);
|
|
27
27
|
default:
|
|
28
28
|
if (err_ instanceof BaseError) throw err_;
|
|
@@ -49,7 +49,7 @@ function buildRequest(request, options = {}) {
|
|
|
49
49
|
function shouldRetry(error) {
|
|
50
50
|
if ("code" in error && typeof error.code === "number") {
|
|
51
51
|
if (error.code === -1) return true;
|
|
52
|
-
if (error.code ===
|
|
52
|
+
if (error.code === -32603) return true;
|
|
53
53
|
return false;
|
|
54
54
|
}
|
|
55
55
|
if (error instanceof HttpRequestError && error.status) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRequest.js","names":[],"sources":["../../../src/utils/buildRequest.ts"],"sourcesContent":["import { BaseError } from '../errors/base.js'\nimport { HttpRequestError } from '../errors/request.js'\nimport {\n MethodNotSupportedRpcError,\n RpcErrorCode,\n UserRejectedRequestError,\n} from '../errors/rpc.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport type {\n BtcRpcRequestFn,\n BtcRpcRequestOptions,\n RpcSchema,\n} from '../types/request.js'\nimport { stringToHex } from './converter.js'\nimport { stringify } from './stringify.js'\nimport { withDedupe } from './withDedupe.js'\nimport { withRetry } from './withRetry.js'\n\nexport type RequestErrorType = ErrorType\n\nexport function buildRequest<request extends BtcRpcRequestFn<RpcSchema>>(\n request: request,\n options: BtcRpcRequestOptions = {}\n): BtcRpcRequestFn {\n return async (args, overrideOptions = {}) => {\n const {\n dedupe = false,\n methods,\n retryDelay = 150,\n retryCount = 3,\n uid,\n } = {\n ...options,\n ...overrideOptions,\n }\n\n const { method } = args\n if (methods?.exclude?.includes(method)) {\n throw new MethodNotSupportedRpcError(method)\n }\n if (methods?.include && !methods.include.includes(method)) {\n throw new MethodNotSupportedRpcError(method)\n }\n\n const requestId = dedupe\n ? stringToHex(`${uid}.${stringify(args)}`)\n : undefined\n return withDedupe(\n () =>\n withRetry(\n async () => {\n try {\n return await request(args)\n } catch (err_) {\n const err = err_ as unknown as BaseError\n switch (err.code) {\n case RpcErrorCode.METHOD_NOT_SUPPORTED:\n throw new MethodNotSupportedRpcError(method)\n\n case RpcErrorCode.USER_REJECTION:\n throw new UserRejectedRequestError(err.message)\n\n // CAIP-25: User Rejected Error\n // https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes#rejected-caip-25\n case 5000:\n throw new UserRejectedRequestError(err.message)\n\n default:\n if (err_ instanceof BaseError) {\n throw err_\n }\n throw new BaseError('Unknown Error', { cause: err_ as Error })\n }\n }\n },\n {\n delay: ({ count, error }) => {\n // If we find a Retry-After header, let's retry after the given time.\n if (error && error instanceof HttpRequestError) {\n const retryAfter = error?.headers?.get('Retry-After')\n if (retryAfter?.match(/\\d/)) {\n return Number.parseInt(retryAfter, 10) * 1000\n }\n }\n\n // Otherwise, let's retry with an exponential backoff.\n return ~~(1 << count) * retryDelay\n },\n retryCount,\n shouldRetry: ({ error }) => shouldRetry(error),\n }\n ),\n { enabled: dedupe, id: requestId }\n )\n }\n}\n\n/** @internal */\nexport function shouldRetry(error: Error): boolean {\n if ('code' in error && typeof error.code === 'number') {\n if (error.code === -1) {\n return true // Unknown error\n }\n if (error.code === RpcErrorCode.INTERNAL_ERROR) {\n return true\n }\n return false\n }\n if (error instanceof HttpRequestError && error.status) {\n // Forbidden\n if (error.status === 403) {\n return true\n }\n // Request Timeout\n if (error.status === 408) {\n return true\n }\n // Request Entity Too Large\n if (error.status === 413) {\n return true\n }\n // Too Many Requests\n if (error.status === 429) {\n return true\n }\n // Internal Server Error\n if (error.status === 500) {\n return true\n }\n // Bad Gateway\n if (error.status === 502) {\n return true\n }\n // Service Unavailable\n if (error.status === 503) {\n return true\n }\n // Gateway Timeout\n if (error.status === 504) {\n return true\n }\n return false\n }\n return true\n}\n"],"mappings":";;;;;;;;AAoBA,SAAgB,aACd,SACA,UAAgC,
|
|
1
|
+
{"version":3,"file":"buildRequest.js","names":[],"sources":["../../../src/utils/buildRequest.ts"],"sourcesContent":["import { BaseError } from '../errors/base.js'\nimport { HttpRequestError } from '../errors/request.js'\nimport {\n MethodNotSupportedRpcError,\n RpcErrorCode,\n UserRejectedRequestError,\n} from '../errors/rpc.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport type {\n BtcRpcRequestFn,\n BtcRpcRequestOptions,\n RpcSchema,\n} from '../types/request.js'\nimport { stringToHex } from './converter.js'\nimport { stringify } from './stringify.js'\nimport { withDedupe } from './withDedupe.js'\nimport { withRetry } from './withRetry.js'\n\nexport type RequestErrorType = ErrorType\n\nexport function buildRequest<request extends BtcRpcRequestFn<RpcSchema>>(\n request: request,\n options: BtcRpcRequestOptions = {}\n): BtcRpcRequestFn {\n return async (args, overrideOptions = {}) => {\n const {\n dedupe = false,\n methods,\n retryDelay = 150,\n retryCount = 3,\n uid,\n } = {\n ...options,\n ...overrideOptions,\n }\n\n const { method } = args\n if (methods?.exclude?.includes(method)) {\n throw new MethodNotSupportedRpcError(method)\n }\n if (methods?.include && !methods.include.includes(method)) {\n throw new MethodNotSupportedRpcError(method)\n }\n\n const requestId = dedupe\n ? stringToHex(`${uid}.${stringify(args)}`)\n : undefined\n return withDedupe(\n () =>\n withRetry(\n async () => {\n try {\n return await request(args)\n } catch (err_) {\n const err = err_ as unknown as BaseError\n switch (err.code) {\n case RpcErrorCode.METHOD_NOT_SUPPORTED:\n throw new MethodNotSupportedRpcError(method)\n\n case RpcErrorCode.USER_REJECTION:\n throw new UserRejectedRequestError(err.message)\n\n // CAIP-25: User Rejected Error\n // https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes#rejected-caip-25\n case 5000:\n throw new UserRejectedRequestError(err.message)\n\n default:\n if (err_ instanceof BaseError) {\n throw err_\n }\n throw new BaseError('Unknown Error', { cause: err_ as Error })\n }\n }\n },\n {\n delay: ({ count, error }) => {\n // If we find a Retry-After header, let's retry after the given time.\n if (error && error instanceof HttpRequestError) {\n const retryAfter = error?.headers?.get('Retry-After')\n if (retryAfter?.match(/\\d/)) {\n return Number.parseInt(retryAfter, 10) * 1000\n }\n }\n\n // Otherwise, let's retry with an exponential backoff.\n return ~~(1 << count) * retryDelay\n },\n retryCount,\n shouldRetry: ({ error }) => shouldRetry(error),\n }\n ),\n { enabled: dedupe, id: requestId }\n )\n }\n}\n\n/** @internal */\nexport function shouldRetry(error: Error): boolean {\n if ('code' in error && typeof error.code === 'number') {\n if (error.code === -1) {\n return true // Unknown error\n }\n if (error.code === RpcErrorCode.INTERNAL_ERROR) {\n return true\n }\n return false\n }\n if (error instanceof HttpRequestError && error.status) {\n // Forbidden\n if (error.status === 403) {\n return true\n }\n // Request Timeout\n if (error.status === 408) {\n return true\n }\n // Request Entity Too Large\n if (error.status === 413) {\n return true\n }\n // Too Many Requests\n if (error.status === 429) {\n return true\n }\n // Internal Server Error\n if (error.status === 500) {\n return true\n }\n // Bad Gateway\n if (error.status === 502) {\n return true\n }\n // Service Unavailable\n if (error.status === 503) {\n return true\n }\n // Gateway Timeout\n if (error.status === 504) {\n return true\n }\n return false\n }\n return true\n}\n"],"mappings":";;;;;;;;AAoBA,SAAgB,aACd,SACA,UAAgC,CAAC,GAChB;CACjB,OAAO,OAAO,MAAM,kBAA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;CACT;CACA,IAAI,iBAAiB,oBAAoB,MAAM,QAAQ;EAErD,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAGT,IAAI,MAAM,WAAW,KACnB,OAAO;EAET,OAAO;CACT;CACA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancelTransaction.js","names":[],"sources":["../../../src/utils/cancelTransaction.ts"],"sourcesContent":["import { address, Psbt } from 'bitcoinjs-lib'\n\ninterface InputData {\n hash: Uint8Array\n index: number\n nonWitnessUtxo?: Uint8Array\n witnessUtxo?: {\n script: Uint8Array\n value: bigint\n }\n redeemScript?: Uint8Array\n witnessScript?: Uint8Array\n}\n\nexport function cancelTransaction(psbt: Psbt, accountAddress: string): Psbt {\n const newPsbt = new Psbt()\n const inputs = psbt.data.inputs\n const txInputs = psbt.txInputs\n\n // Add inputs to the new PSBT\n for (let i = 0; i < inputs.length; i++) {\n const input = inputs[i]\n const txInput = txInputs[i]\n const inputData: InputData = {\n hash: txInput.hash,\n index: txInput.index,\n }\n\n // Include UTXO information\n if (input.nonWitnessUtxo) {\n inputData.nonWitnessUtxo = input.nonWitnessUtxo\n } else if (input.witnessUtxo) {\n inputData.witnessUtxo = input.witnessUtxo\n } else {\n throw new Error('Input UTXO information is missing')\n }\n\n // Include scripts if necessary\n if (input.redeemScript) {\n inputData.redeemScript = input.redeemScript\n }\n if (input.witnessScript) {\n inputData.witnessScript = input.witnessScript\n }\n\n newPsbt.addInput(inputData)\n }\n\n // Compute total output amount from the original transaction\n const outputs = psbt.txOutputs\n let totalOutputValue = BigInt(0)\n\n for (const output of outputs) {\n totalOutputValue += output.value\n }\n\n if (totalOutputValue <= BigInt(0)) {\n throw new Error('Total output value must be greater than zero')\n }\n\n // Create the output to send funds back to sender's address\n const outputScript = address.toOutputScript(accountAddress)\n newPsbt.addOutput({\n script: outputScript,\n value: totalOutputValue,\n })\n\n // Modify the input sequence number to enable RBF\n newPsbt.txInputs.forEach((_, index) => {\n // Set sequence number to less than 0xfffffffe, e.g., 0xfffffffd\n newPsbt.setInputSequence(index, 0xfffffffd)\n })\n\n return newPsbt\n}\n"],"mappings":";;AAcA,SAAgB,kBAAkB,MAAY,gBAA8B;CAC1E,MAAM,UAAU,IAAI,
|
|
1
|
+
{"version":3,"file":"cancelTransaction.js","names":[],"sources":["../../../src/utils/cancelTransaction.ts"],"sourcesContent":["import { address, Psbt } from 'bitcoinjs-lib'\n\ninterface InputData {\n hash: Uint8Array\n index: number\n nonWitnessUtxo?: Uint8Array\n witnessUtxo?: {\n script: Uint8Array\n value: bigint\n }\n redeemScript?: Uint8Array\n witnessScript?: Uint8Array\n}\n\nexport function cancelTransaction(psbt: Psbt, accountAddress: string): Psbt {\n const newPsbt = new Psbt()\n const inputs = psbt.data.inputs\n const txInputs = psbt.txInputs\n\n // Add inputs to the new PSBT\n for (let i = 0; i < inputs.length; i++) {\n const input = inputs[i]\n const txInput = txInputs[i]\n const inputData: InputData = {\n hash: txInput.hash,\n index: txInput.index,\n }\n\n // Include UTXO information\n if (input.nonWitnessUtxo) {\n inputData.nonWitnessUtxo = input.nonWitnessUtxo\n } else if (input.witnessUtxo) {\n inputData.witnessUtxo = input.witnessUtxo\n } else {\n throw new Error('Input UTXO information is missing')\n }\n\n // Include scripts if necessary\n if (input.redeemScript) {\n inputData.redeemScript = input.redeemScript\n }\n if (input.witnessScript) {\n inputData.witnessScript = input.witnessScript\n }\n\n newPsbt.addInput(inputData)\n }\n\n // Compute total output amount from the original transaction\n const outputs = psbt.txOutputs\n let totalOutputValue = BigInt(0)\n\n for (const output of outputs) {\n totalOutputValue += output.value\n }\n\n if (totalOutputValue <= BigInt(0)) {\n throw new Error('Total output value must be greater than zero')\n }\n\n // Create the output to send funds back to sender's address\n const outputScript = address.toOutputScript(accountAddress)\n newPsbt.addOutput({\n script: outputScript,\n value: totalOutputValue,\n })\n\n // Modify the input sequence number to enable RBF\n newPsbt.txInputs.forEach((_, index) => {\n // Set sequence number to less than 0xfffffffe, e.g., 0xfffffffd\n newPsbt.setInputSequence(index, 0xfffffffd)\n })\n\n return newPsbt\n}\n"],"mappings":";;AAcA,SAAgB,kBAAkB,MAAY,gBAA8B;CAC1E,MAAM,UAAU,IAAI,KAAK;CACzB,MAAM,SAAS,KAAK,KAAK;CACzB,MAAM,WAAW,KAAK;CAGtB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,SAAS;EACzB,MAAM,YAAuB;GAC3B,MAAM,QAAQ;GACd,OAAO,QAAQ;EACjB;EAGA,IAAI,MAAM,gBACR,UAAU,iBAAiB,MAAM;OAC5B,IAAI,MAAM,aACf,UAAU,cAAc,MAAM;OAE9B,MAAM,IAAI,MAAM,mCAAmC;EAIrD,IAAI,MAAM,cACR,UAAU,eAAe,MAAM;EAEjC,IAAI,MAAM,eACR,UAAU,gBAAgB,MAAM;EAGlC,QAAQ,SAAS,SAAS;CAC5B;CAGA,MAAM,UAAU,KAAK;CACrB,IAAI,mBAAmB,OAAO,CAAC;CAE/B,KAAK,MAAM,UAAU,SACnB,oBAAoB,OAAO;CAG7B,IAAI,oBAAoB,OAAO,CAAC,GAC9B,MAAM,IAAI,MAAM,8CAA8C;CAIhE,MAAM,eAAe,QAAQ,eAAe,cAAc;CAC1D,QAAQ,UAAU;EAChB,QAAQ;EACR,OAAO;CACT,CAAC;CAGD,QAAQ,SAAS,SAAS,GAAG,UAAU;EAErC,QAAQ,iBAAiB,OAAO,UAAU;CAC5C,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","names":[],"sources":["../../../src/utils/converter.ts"],"sourcesContent":["export function hexToBase64(hex: string): string {\n const raw = hex\n .match(/.{1,2}/g)!\n .map((byte: string) => String.fromCharCode(Number.parseInt(byte, 16)))\n .join('')\n return btoa(raw)\n}\n\nexport function base64ToHex(base64: string): string {\n const raw = atob(base64)\n let hex = ''\n for (let i = 0; i < raw.length; i++) {\n const hexByte = raw.charCodeAt(i).toString(16)\n hex += hexByte.length === 2 ? hexByte : `0${hexByte}`\n }\n return hex\n}\n\nexport function base64urlEncode(str: string): string {\n const bytes = new TextEncoder().encode(str)\n const encodedString = btoa(String.fromCharCode(...bytes))\n return encodedString\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+$/, '')\n}\n\nexport function stringToHex(value: string): string {\n const hex = Array.from(value)\n .map((char: string) => char.charCodeAt(0).toString(16).padStart(2, '0'))\n .join('')\n\n return `0x${hex}`\n}\n\nexport function hexToUnit8Array(value: string): Uint8Array {\n return new Uint8Array(\n value.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []\n )\n}\n"],"mappings":";AAAA,SAAgB,YAAY,KAAqB;CAC/C,MAAM,MAAM,IACT,MAAM,
|
|
1
|
+
{"version":3,"file":"converter.js","names":[],"sources":["../../../src/utils/converter.ts"],"sourcesContent":["export function hexToBase64(hex: string): string {\n const raw = hex\n .match(/.{1,2}/g)!\n .map((byte: string) => String.fromCharCode(Number.parseInt(byte, 16)))\n .join('')\n return btoa(raw)\n}\n\nexport function base64ToHex(base64: string): string {\n const raw = atob(base64)\n let hex = ''\n for (let i = 0; i < raw.length; i++) {\n const hexByte = raw.charCodeAt(i).toString(16)\n hex += hexByte.length === 2 ? hexByte : `0${hexByte}`\n }\n return hex\n}\n\nexport function base64urlEncode(str: string): string {\n const bytes = new TextEncoder().encode(str)\n const encodedString = btoa(String.fromCharCode(...bytes))\n return encodedString\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+$/, '')\n}\n\nexport function stringToHex(value: string): string {\n const hex = Array.from(value)\n .map((char: string) => char.charCodeAt(0).toString(16).padStart(2, '0'))\n .join('')\n\n return `0x${hex}`\n}\n\nexport function hexToUnit8Array(value: string): Uint8Array {\n return new Uint8Array(\n value.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []\n )\n}\n"],"mappings":";AAAA,SAAgB,YAAY,KAAqB;CAC/C,MAAM,MAAM,IACT,MAAM,SAAS,EACf,KAAK,SAAiB,OAAO,aAAa,OAAO,SAAS,MAAM,EAAE,CAAC,CAAC,EACpE,KAAK,EAAE;CACV,OAAO,KAAK,GAAG;AACjB;AAEA,SAAgB,YAAY,QAAwB;CAClD,MAAM,MAAM,KAAK,MAAM;CACvB,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EACnC,MAAM,UAAU,IAAI,WAAW,CAAC,EAAE,SAAS,EAAE;EAC7C,OAAO,QAAQ,WAAW,IAAI,UAAU,IAAI;CAC9C;CACA,OAAO;AACT;AAEA,SAAgB,gBAAgB,KAAqB;CACnD,MAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,GAAG;CAE1C,OADsB,KAAK,OAAO,aAAa,GAAG,KAAK,CACpC,EAChB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,EAAE;AACtB;AAEA,SAAgB,YAAY,OAAuB;CAKjD,OAAO,KAJK,MAAM,KAAK,KAAK,EACzB,KAAK,SAAiB,KAAK,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACtE,KAAK,EAEM;AAChB;AAEA,SAAgB,gBAAgB,OAA2B;CACzD,OAAO,IAAI,WACT,MAAM,MAAM,SAAS,GAAG,KAAK,SAAS,OAAO,SAAS,MAAM,EAAE,CAAC,KAAK,CAAC,CACvE;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBatchScheduler.d.ts","names":[],"sources":["../../../src/utils/createBatchScheduler.ts"],"mappings":";;;KAGK,QAAA,iDACH,MAAA,EAAQ,UAAA,UACR,OAAA,EAAS,UAAA;AAAA,KASN,qBAAA,sBAA2C,CAAA,EAAG,MAAA,EAAQ,CAAA,EAAG,MAAA;AAAA,KAEzD,6BAAA;EAIH,EAAA,GAAK,IAAA,EAAM,UAAA,OAAiB,OAAA,CAAQ,UAAA;EACpC,EAAA;EACA,gBAAA,KAAqB,IAAA,EAAM,UAAA;EAC3B,IAAA;EACA,IAAA,GAAO,qBAAA,CAAsB,UAAA;AAAA;AAAA,KAG1B,8BAAA;EAIH,KAAA;EACA,QAAA,EAAU,UAAA,sBACL,IAAA,GAAO,UAAA,iBAA2B,OAAA,CAAQ,QAAA,CAAS,UAAA,MACnD,IAAA,EAAM,UAAA,KAAe,OAAA,CAAQ,QAAA,CAAS,UAAA;AAAA;AAAA,KAGjC,6BAAA,GAAgC,SAAA;;iBAK5B,oBAAA
|
|
1
|
+
{"version":3,"file":"createBatchScheduler.d.ts","names":[],"sources":["../../../src/utils/createBatchScheduler.ts"],"mappings":";;;KAGK,QAAA,iDACH,MAAA,EAAQ,UAAA,UACR,OAAA,EAAS,UAAA;AAAA,KASN,qBAAA,sBAA2C,CAAA,EAAG,MAAA,EAAQ,CAAA,EAAG,MAAA;AAAA,KAEzD,6BAAA;EAIH,EAAA,GAAK,IAAA,EAAM,UAAA,OAAiB,OAAA,CAAQ,UAAA;EACpC,EAAA;EACA,gBAAA,KAAqB,IAAA,EAAM,UAAA;EAC3B,IAAA;EACA,IAAA,GAAO,qBAAA,CAAsB,UAAA;AAAA;AAAA,KAG1B,8BAAA;EAIH,KAAA;EACA,QAAA,EAAU,UAAA,sBACL,IAAA,GAAO,UAAA,iBAA2B,OAAA,CAAQ,QAAA,CAAS,UAAA,MACnD,IAAA,EAAM,UAAA,KAAe,OAAA,CAAQ,QAAA,CAAS,UAAA;AAAA;AAAA,KAGjC,6BAAA,GAAgC,SAAA;;iBAK5B,oBAAA;EAId,EAAA;EACA,EAAA;EACA,gBAAA;EACA,IAAA;EACA;AAAA,GACC,6BAAA,CACD,UAAA,EACA,UAAA,IACE,8BAAA,CAA+B,UAAA,EAAY,UAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { withResolvers } from "./withResolvers.js";
|
|
2
2
|
//#region src/utils/createBatchScheduler.ts
|
|
3
|
-
const schedulerCache =
|
|
3
|
+
const schedulerCache = /*#__PURE__*/ new Map();
|
|
4
4
|
/** @internal */
|
|
5
5
|
function createBatchScheduler({ fn, id, shouldSplitBatch, wait = 0, sort }) {
|
|
6
6
|
const exec = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBatchScheduler.js","names":[],"sources":["../../../src/utils/createBatchScheduler.ts"],"sourcesContent":["import type { ErrorType } from '../errors/utils.js'\nimport { withResolvers } from './withResolvers.js'\n\ntype Resolved<returnType extends readonly unknown[] = any> = [\n result: returnType[number],\n results: returnType,\n]\n\ntype SchedulerItem = {\n args: unknown\n resolve: PromiseWithResolvers<unknown>['resolve']\n reject: PromiseWithResolvers<unknown>['reject']\n}\n\ntype BatchResultsCompareFn<result = unknown> = (a: result, b: result) => number\n\ntype CreateBatchSchedulerArguments<\n parameters = unknown,\n returnType extends readonly unknown[] = readonly unknown[],\n> = {\n fn: (args: parameters[]) => Promise<returnType>\n id: number | string\n shouldSplitBatch?: ((args: parameters[]) => boolean) | undefined\n wait?: number | undefined\n sort?: BatchResultsCompareFn<returnType[number]> | undefined\n}\n\ntype CreateBatchSchedulerReturnType<\n parameters = unknown,\n returnType extends readonly unknown[] = readonly unknown[],\n> = {\n flush: () => void\n schedule: parameters extends undefined\n ? (args?: parameters | undefined) => Promise<Resolved<returnType>>\n : (args: parameters) => Promise<Resolved<returnType>>\n}\n\nexport type CreateBatchSchedulerErrorType = ErrorType\n\nconst schedulerCache = /*#__PURE__*/ new Map<number | string, SchedulerItem[]>()\n\n/** @internal */\nexport function createBatchScheduler<\n parameters,\n returnType extends readonly unknown[],\n>({\n fn,\n id,\n shouldSplitBatch,\n wait = 0,\n sort,\n}: CreateBatchSchedulerArguments<\n parameters,\n returnType\n>): CreateBatchSchedulerReturnType<parameters, returnType> {\n const exec = async () => {\n const scheduler = getScheduler()\n flush()\n\n const args = scheduler.map(({ args }) => args)\n\n if (args.length === 0) {\n return\n }\n\n fn(args as parameters[])\n .then((data) => {\n if (sort && Array.isArray(data)) {\n data.sort(sort)\n }\n for (let i = 0; i < scheduler.length; i++) {\n const { resolve } = scheduler[i]\n resolve?.([data[i], data])\n }\n })\n .catch((err) => {\n for (let i = 0; i < scheduler.length; i++) {\n const { reject } = scheduler[i]\n reject?.(err)\n }\n })\n }\n\n const flush = () => schedulerCache.delete(id)\n\n const getBatchedArgs = () =>\n getScheduler().map(({ args }) => args) as parameters[]\n\n const getScheduler = () => schedulerCache.get(id) || []\n\n const setScheduler = (item: SchedulerItem) =>\n schedulerCache.set(id, [...getScheduler(), item])\n\n return {\n flush,\n async schedule(args: parameters) {\n const { promise, resolve, reject } = withResolvers()\n\n const split = shouldSplitBatch?.([...getBatchedArgs(), args])\n\n if (split) {\n exec()\n }\n\n const hasActiveScheduler = getScheduler().length > 0\n if (hasActiveScheduler) {\n setScheduler({ args, resolve, reject })\n return promise\n }\n\n setScheduler({ args, resolve, reject })\n setTimeout(exec, wait)\n return promise\n },\n } as unknown as CreateBatchSchedulerReturnType<parameters, returnType>\n}\n"],"mappings":";;AAuCA,MAAM
|
|
1
|
+
{"version":3,"file":"createBatchScheduler.js","names":[],"sources":["../../../src/utils/createBatchScheduler.ts"],"sourcesContent":["import type { ErrorType } from '../errors/utils.js'\nimport { withResolvers } from './withResolvers.js'\n\ntype Resolved<returnType extends readonly unknown[] = any> = [\n result: returnType[number],\n results: returnType,\n]\n\ntype SchedulerItem = {\n args: unknown\n resolve: PromiseWithResolvers<unknown>['resolve']\n reject: PromiseWithResolvers<unknown>['reject']\n}\n\ntype BatchResultsCompareFn<result = unknown> = (a: result, b: result) => number\n\ntype CreateBatchSchedulerArguments<\n parameters = unknown,\n returnType extends readonly unknown[] = readonly unknown[],\n> = {\n fn: (args: parameters[]) => Promise<returnType>\n id: number | string\n shouldSplitBatch?: ((args: parameters[]) => boolean) | undefined\n wait?: number | undefined\n sort?: BatchResultsCompareFn<returnType[number]> | undefined\n}\n\ntype CreateBatchSchedulerReturnType<\n parameters = unknown,\n returnType extends readonly unknown[] = readonly unknown[],\n> = {\n flush: () => void\n schedule: parameters extends undefined\n ? (args?: parameters | undefined) => Promise<Resolved<returnType>>\n : (args: parameters) => Promise<Resolved<returnType>>\n}\n\nexport type CreateBatchSchedulerErrorType = ErrorType\n\nconst schedulerCache = /*#__PURE__*/ new Map<number | string, SchedulerItem[]>()\n\n/** @internal */\nexport function createBatchScheduler<\n parameters,\n returnType extends readonly unknown[],\n>({\n fn,\n id,\n shouldSplitBatch,\n wait = 0,\n sort,\n}: CreateBatchSchedulerArguments<\n parameters,\n returnType\n>): CreateBatchSchedulerReturnType<parameters, returnType> {\n const exec = async () => {\n const scheduler = getScheduler()\n flush()\n\n const args = scheduler.map(({ args }) => args)\n\n if (args.length === 0) {\n return\n }\n\n fn(args as parameters[])\n .then((data) => {\n if (sort && Array.isArray(data)) {\n data.sort(sort)\n }\n for (let i = 0; i < scheduler.length; i++) {\n const { resolve } = scheduler[i]\n resolve?.([data[i], data])\n }\n })\n .catch((err) => {\n for (let i = 0; i < scheduler.length; i++) {\n const { reject } = scheduler[i]\n reject?.(err)\n }\n })\n }\n\n const flush = () => schedulerCache.delete(id)\n\n const getBatchedArgs = () =>\n getScheduler().map(({ args }) => args) as parameters[]\n\n const getScheduler = () => schedulerCache.get(id) || []\n\n const setScheduler = (item: SchedulerItem) =>\n schedulerCache.set(id, [...getScheduler(), item])\n\n return {\n flush,\n async schedule(args: parameters) {\n const { promise, resolve, reject } = withResolvers()\n\n const split = shouldSplitBatch?.([...getBatchedArgs(), args])\n\n if (split) {\n exec()\n }\n\n const hasActiveScheduler = getScheduler().length > 0\n if (hasActiveScheduler) {\n setScheduler({ args, resolve, reject })\n return promise\n }\n\n setScheduler({ args, resolve, reject })\n setTimeout(exec, wait)\n return promise\n },\n } as unknown as CreateBatchSchedulerReturnType<parameters, returnType>\n}\n"],"mappings":";;AAuCA,MAAM,+BAA+B,IAAI,IAAsC;;AAG/E,SAAgB,qBAGd,EACA,IACA,IACA,kBACA,OAAO,GACP,QAIyD;CACzD,MAAM,OAAO,YAAY;EACvB,MAAM,YAAY,aAAa;EAC/B,MAAM;EAEN,MAAM,OAAO,UAAU,KAAK,EAAE,WAAW,IAAI;EAE7C,IAAI,KAAK,WAAW,GAClB;EAGF,GAAG,IAAoB,EACpB,MAAM,SAAS;GACd,IAAI,QAAQ,MAAM,QAAQ,IAAI,GAC5B,KAAK,KAAK,IAAI;GAEhB,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;IACzC,MAAM,EAAE,YAAY,UAAU;IAC9B,UAAU,CAAC,KAAK,IAAI,IAAI,CAAC;GAC3B;EACF,CAAC,EACA,OAAO,QAAQ;GACd,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;IACzC,MAAM,EAAE,WAAW,UAAU;IAC7B,SAAS,GAAG;GACd;EACF,CAAC;CACL;CAEA,MAAM,cAAc,eAAe,OAAO,EAAE;CAE5C,MAAM,uBACJ,aAAa,EAAE,KAAK,EAAE,WAAW,IAAI;CAEvC,MAAM,qBAAqB,eAAe,IAAI,EAAE,KAAK,CAAC;CAEtD,MAAM,gBAAgB,SACpB,eAAe,IAAI,IAAI,CAAC,GAAG,aAAa,GAAG,IAAI,CAAC;CAElD,OAAO;EACL;EACA,MAAM,SAAS,MAAkB;GAC/B,MAAM,EAAE,SAAS,SAAS,WAAW,cAAc;GAInD,IAFc,mBAAmB,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,GAG1D,KAAK;GAIP,IAD2B,aAAa,EAAE,SAAS,GAC3B;IACtB,aAAa;KAAE;KAAM;KAAS;IAAO,CAAC;IACtC,OAAO;GACT;GAEA,aAAa;IAAE;IAAM;IAAS;GAAO,CAAC;GACtC,WAAW,MAAM,IAAI;GACrB,OAAO;EACT;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepEqual.js","names":[],"sources":["../../../src/utils/deepEqual.ts"],"sourcesContent":["/** Forked from https://github.com/epoberezkin/fast-deep-equal */\n\nexport function deepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n if (a.constructor !== b.constructor) {\n return false\n }\n\n let length: number\n let i: number\n\n if (Array.isArray(a) && Array.isArray(b)) {\n length = a.length\n if (length !== b.length) {\n return false\n }\n for (i = length; i-- !== 0; ) {\n if (!deepEqual(a[i], b[i])) {\n return false\n }\n }\n return true\n }\n\n if (a.valueOf !== Object.prototype.valueOf) {\n return a.valueOf() === b.valueOf()\n }\n if (a.toString !== Object.prototype.toString) {\n return a.toString() === b.toString()\n }\n\n const keys = Object.keys(a)\n length = keys.length\n if (length !== Object.keys(b).length) {\n return false\n }\n\n for (i = length; i-- !== 0; ) {\n if (!Object.hasOwn(b, keys[i]!)) {\n return false\n }\n }\n\n for (i = length; i-- !== 0; ) {\n const key = keys[i]\n\n if (key && !deepEqual(a[key], b[key])) {\n return false\n }\n }\n\n return true\n }\n\n // true if both NaN, false otherwise\n // biome-ignore lint/suspicious/noSelfCompare: allowed in utils\n return a !== a && b !== b\n}\n"],"mappings":";;AAEA,SAAgB,UAAU,GAAQ,GAAiB;
|
|
1
|
+
{"version":3,"file":"deepEqual.js","names":[],"sources":["../../../src/utils/deepEqual.ts"],"sourcesContent":["/** Forked from https://github.com/epoberezkin/fast-deep-equal */\n\nexport function deepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n if (a.constructor !== b.constructor) {\n return false\n }\n\n let length: number\n let i: number\n\n if (Array.isArray(a) && Array.isArray(b)) {\n length = a.length\n if (length !== b.length) {\n return false\n }\n for (i = length; i-- !== 0; ) {\n if (!deepEqual(a[i], b[i])) {\n return false\n }\n }\n return true\n }\n\n if (a.valueOf !== Object.prototype.valueOf) {\n return a.valueOf() === b.valueOf()\n }\n if (a.toString !== Object.prototype.toString) {\n return a.toString() === b.toString()\n }\n\n const keys = Object.keys(a)\n length = keys.length\n if (length !== Object.keys(b).length) {\n return false\n }\n\n for (i = length; i-- !== 0; ) {\n if (!Object.hasOwn(b, keys[i]!)) {\n return false\n }\n }\n\n for (i = length; i-- !== 0; ) {\n const key = keys[i]\n\n if (key && !deepEqual(a[key], b[key])) {\n return false\n }\n }\n\n return true\n }\n\n // true if both NaN, false otherwise\n // biome-ignore lint/suspicious/noSelfCompare: allowed in utils\n return a !== a && b !== b\n}\n"],"mappings":";;AAEA,SAAgB,UAAU,GAAQ,GAAiB;CACjD,IAAI,MAAM,GACR,OAAO;CAGT,IAAI,KAAK,KAAK,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAC5D,IAAI,EAAE,gBAAgB,EAAE,aACtB,OAAO;EAGT,IAAI;EACJ,IAAI;EAEJ,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GAAG;GACxC,SAAS,EAAE;GACX,IAAI,WAAW,EAAE,QACf,OAAO;GAET,KAAK,IAAI,QAAQ,QAAQ,IACvB,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GACvB,OAAO;GAGX,OAAO;EACT;EAEA,IAAI,EAAE,YAAY,OAAO,UAAU,SACjC,OAAO,EAAE,QAAQ,MAAM,EAAE,QAAQ;EAEnC,IAAI,EAAE,aAAa,OAAO,UAAU,UAClC,OAAO,EAAE,SAAS,MAAM,EAAE,SAAS;EAGrC,MAAM,OAAO,OAAO,KAAK,CAAC;EAC1B,SAAS,KAAK;EACd,IAAI,WAAW,OAAO,KAAK,CAAC,EAAE,QAC5B,OAAO;EAGT,KAAK,IAAI,QAAQ,QAAQ,IACvB,IAAI,CAAC,OAAO,OAAO,GAAG,KAAK,EAAG,GAC5B,OAAO;EAIX,KAAK,IAAI,QAAQ,QAAQ,IAAK;GAC5B,MAAM,MAAM,KAAK;GAEjB,IAAI,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,GAClC,OAAO;EAEX;EAEA,OAAO;CACT;CAIA,OAAO,MAAM,KAAK,MAAM;AAC1B"}
|