@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.
Files changed (270) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/actions/getBalance.js.map +1 -1
  3. package/dist/cjs/actions/getBlock.js +0 -1
  4. package/dist/cjs/actions/getBlock.js.map +1 -1
  5. package/dist/cjs/actions/getBlockCount.js.map +1 -1
  6. package/dist/cjs/actions/getBlockStats.js.map +1 -1
  7. package/dist/cjs/actions/getTransactionFee.js.map +1 -1
  8. package/dist/cjs/actions/getTransactions.js.map +1 -1
  9. package/dist/cjs/actions/getUTXOTransaction.js.map +1 -1
  10. package/dist/cjs/actions/getUTXOs.js.map +1 -1
  11. package/dist/cjs/actions/getXPubAddresses.js.map +1 -1
  12. package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -1
  13. package/dist/cjs/actions/signPsbt.js.map +1 -1
  14. package/dist/cjs/actions/waitForTransaction.js +0 -1
  15. package/dist/cjs/actions/waitForTransaction.js.map +1 -1
  16. package/dist/cjs/actions/watchBlockNumber.js.map +1 -1
  17. package/dist/cjs/chains/bitcoin.js +3 -3
  18. package/dist/cjs/chains/bitcoin.js.map +1 -1
  19. package/dist/cjs/chains/defineChain.js.map +1 -1
  20. package/dist/cjs/chains/signet.js +3 -3
  21. package/dist/cjs/chains/signet.js.map +1 -1
  22. package/dist/cjs/clients/decorators/public.js.map +1 -1
  23. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  24. package/dist/cjs/errors/address.js.map +1 -1
  25. package/dist/cjs/errors/base.js.map +1 -1
  26. package/dist/cjs/errors/block.js.map +1 -1
  27. package/dist/cjs/errors/provider.js.map +1 -1
  28. package/dist/cjs/errors/request.js.map +1 -1
  29. package/dist/cjs/errors/rpc.js +3 -3
  30. package/dist/cjs/errors/rpc.js.map +1 -1
  31. package/dist/cjs/errors/transaction.js.map +1 -1
  32. package/dist/cjs/errors/transport.js.map +1 -1
  33. package/dist/cjs/errors/utxo.js.map +1 -1
  34. package/dist/cjs/factories/createClient.js.map +1 -1
  35. package/dist/cjs/factories/createTransport.js.map +1 -1
  36. package/dist/cjs/test/utils.js.map +1 -1
  37. package/dist/cjs/transports/ankr/ankr.js.map +1 -1
  38. package/dist/cjs/transports/ankr/getBalance.js +2 -2
  39. package/dist/cjs/transports/ankr/getBalance.js.map +1 -1
  40. package/dist/cjs/transports/ankr/getTransactionFee.js.map +1 -1
  41. package/dist/cjs/transports/ankr/getTransactions.js.map +1 -1
  42. package/dist/cjs/transports/ankr/methods.js.map +1 -1
  43. package/dist/cjs/transports/ankr/utils.js.map +1 -1
  44. package/dist/cjs/transports/blockchair/blockchair.js.map +1 -1
  45. package/dist/cjs/transports/blockchair/getBalance.js +2 -2
  46. package/dist/cjs/transports/blockchair/getBalance.js.map +1 -1
  47. package/dist/cjs/transports/blockchair/getTransactionFee.js +2 -2
  48. package/dist/cjs/transports/blockchair/getTransactionFee.js.map +1 -1
  49. package/dist/cjs/transports/blockchair/getUTXOs.js +2 -2
  50. package/dist/cjs/transports/blockchair/getUTXOs.js.map +1 -1
  51. package/dist/cjs/transports/blockchair/getXPubAddresses.js +2 -2
  52. package/dist/cjs/transports/blockchair/getXPubAddresses.js.map +1 -1
  53. package/dist/cjs/transports/blockchair/methods.js.map +1 -1
  54. package/dist/cjs/transports/blockcypher/blockcypher.js.map +1 -1
  55. package/dist/cjs/transports/blockcypher/getBalance.js.map +1 -1
  56. package/dist/cjs/transports/blockcypher/getTransactionFee.js.map +1 -1
  57. package/dist/cjs/transports/blockcypher/getUTXOs.js.map +1 -1
  58. package/dist/cjs/transports/blockcypher/methods.js.map +1 -1
  59. package/dist/cjs/transports/blockcypher/utils.js +3 -3
  60. package/dist/cjs/transports/blockcypher/utils.js.map +1 -1
  61. package/dist/cjs/transports/custom.js.map +1 -1
  62. package/dist/cjs/transports/fallback.js +2 -2
  63. package/dist/cjs/transports/fallback.js.map +1 -1
  64. package/dist/cjs/transports/getHttpRpcClient.js.map +1 -1
  65. package/dist/cjs/transports/getRpcProviderMethods.js.map +1 -1
  66. package/dist/cjs/transports/http.js.map +1 -1
  67. package/dist/cjs/transports/mempool/getBalance.js.map +1 -1
  68. package/dist/cjs/transports/mempool/getTransactionFee.js.map +1 -1
  69. package/dist/cjs/transports/mempool/getTransactions.js.map +1 -1
  70. package/dist/cjs/transports/mempool/mempool.js.map +1 -1
  71. package/dist/cjs/transports/mempool/methods.js.map +1 -1
  72. package/dist/cjs/transports/mempool/utils.js.map +1 -1
  73. package/dist/cjs/transports/types.js.map +1 -1
  74. package/dist/cjs/transports/utxo.js.map +1 -1
  75. package/dist/cjs/types/address.js.map +1 -1
  76. package/dist/cjs/types/chain.js.map +1 -1
  77. package/dist/cjs/utils/buildRequest.js +3 -3
  78. package/dist/cjs/utils/buildRequest.js.map +1 -1
  79. package/dist/cjs/utils/cancelTransaction.js +0 -1
  80. package/dist/cjs/utils/cancelTransaction.js.map +1 -1
  81. package/dist/cjs/utils/converter.js.map +1 -1
  82. package/dist/cjs/utils/createBatchScheduler.js +1 -1
  83. package/dist/cjs/utils/createBatchScheduler.js.map +1 -1
  84. package/dist/cjs/utils/deepEqual.js.map +1 -1
  85. package/dist/cjs/utils/getAction.js.map +1 -1
  86. package/dist/cjs/utils/getAddressInfo.js +26 -26
  87. package/dist/cjs/utils/getAddressInfo.js.map +1 -1
  88. package/dist/cjs/utils/idCache.js.map +1 -1
  89. package/dist/cjs/utils/isAddress.js.map +1 -1
  90. package/dist/cjs/utils/lru.js.map +1 -1
  91. package/dist/cjs/utils/modifyFee.js +0 -1
  92. package/dist/cjs/utils/modifyFee.js.map +1 -1
  93. package/dist/cjs/utils/observe.js +2 -2
  94. package/dist/cjs/utils/observe.js.map +1 -1
  95. package/dist/cjs/utils/parseAccount.js.map +1 -1
  96. package/dist/cjs/utils/poll.js.map +1 -1
  97. package/dist/cjs/utils/retryUntil.js.map +1 -1
  98. package/dist/cjs/utils/sleep.js.map +1 -1
  99. package/dist/cjs/utils/stringify.js.map +1 -1
  100. package/dist/cjs/utils/uid.js.map +1 -1
  101. package/dist/cjs/utils/url.js.map +1 -1
  102. package/dist/cjs/utils/wait.js.map +1 -1
  103. package/dist/cjs/utils/withDedupe.js +1 -1
  104. package/dist/cjs/utils/withDedupe.js.map +1 -1
  105. package/dist/cjs/utils/withResolvers.js.map +1 -1
  106. package/dist/cjs/utils/withRetry.js.map +1 -1
  107. package/dist/cjs/utils/withTimeout.js.map +1 -1
  108. package/dist/cjs/version.d.ts +1 -1
  109. package/dist/cjs/version.js +1 -1
  110. package/dist/cjs/version.js.map +1 -1
  111. package/dist/esm/actions/getBalance.d.ts.map +1 -1
  112. package/dist/esm/actions/getBalance.js.map +1 -1
  113. package/dist/esm/actions/getBlock.d.ts.map +1 -1
  114. package/dist/esm/actions/getBlock.js.map +1 -1
  115. package/dist/esm/actions/getBlockCount.d.ts.map +1 -1
  116. package/dist/esm/actions/getBlockCount.js.map +1 -1
  117. package/dist/esm/actions/getBlockStats.d.ts.map +1 -1
  118. package/dist/esm/actions/getBlockStats.js.map +1 -1
  119. package/dist/esm/actions/getTransactionFee.d.ts.map +1 -1
  120. package/dist/esm/actions/getTransactionFee.js.map +1 -1
  121. package/dist/esm/actions/getTransactions.d.ts.map +1 -1
  122. package/dist/esm/actions/getTransactions.js.map +1 -1
  123. package/dist/esm/actions/getUTXOTransaction.d.ts.map +1 -1
  124. package/dist/esm/actions/getUTXOTransaction.js.map +1 -1
  125. package/dist/esm/actions/getUTXOs.d.ts.map +1 -1
  126. package/dist/esm/actions/getUTXOs.js.map +1 -1
  127. package/dist/esm/actions/getXPubAddresses.d.ts.map +1 -1
  128. package/dist/esm/actions/getXPubAddresses.js.map +1 -1
  129. package/dist/esm/actions/sendUTXOTransaction.d.ts.map +1 -1
  130. package/dist/esm/actions/sendUTXOTransaction.js.map +1 -1
  131. package/dist/esm/actions/signPsbt.d.ts.map +1 -1
  132. package/dist/esm/actions/signPsbt.js.map +1 -1
  133. package/dist/esm/actions/waitForTransaction.d.ts.map +1 -1
  134. package/dist/esm/actions/waitForTransaction.js.map +1 -1
  135. package/dist/esm/actions/watchBlockNumber.d.ts.map +1 -1
  136. package/dist/esm/actions/watchBlockNumber.js.map +1 -1
  137. package/dist/esm/chains/bitcoin.js +3 -3
  138. package/dist/esm/chains/bitcoin.js.map +1 -1
  139. package/dist/esm/chains/defineChain.d.ts.map +1 -1
  140. package/dist/esm/chains/defineChain.js.map +1 -1
  141. package/dist/esm/chains/signet.js +3 -3
  142. package/dist/esm/chains/signet.js.map +1 -1
  143. package/dist/esm/clients/decorators/public.d.ts.map +1 -1
  144. package/dist/esm/clients/decorators/public.js.map +1 -1
  145. package/dist/esm/clients/decorators/wallet.d.ts.map +1 -1
  146. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  147. package/dist/esm/errors/address.d.ts.map +1 -1
  148. package/dist/esm/errors/address.js.map +1 -1
  149. package/dist/esm/errors/base.d.ts.map +1 -1
  150. package/dist/esm/errors/base.js.map +1 -1
  151. package/dist/esm/errors/block.d.ts.map +1 -1
  152. package/dist/esm/errors/block.js.map +1 -1
  153. package/dist/esm/errors/provider.js.map +1 -1
  154. package/dist/esm/errors/request.d.ts.map +1 -1
  155. package/dist/esm/errors/request.js.map +1 -1
  156. package/dist/esm/errors/rpc.d.ts.map +1 -1
  157. package/dist/esm/errors/rpc.js +3 -3
  158. package/dist/esm/errors/rpc.js.map +1 -1
  159. package/dist/esm/errors/transaction.d.ts.map +1 -1
  160. package/dist/esm/errors/transaction.js.map +1 -1
  161. package/dist/esm/errors/transport.d.ts.map +1 -1
  162. package/dist/esm/errors/transport.js.map +1 -1
  163. package/dist/esm/errors/utxo.d.ts.map +1 -1
  164. package/dist/esm/errors/utxo.js.map +1 -1
  165. package/dist/esm/factories/createClient.d.ts.map +1 -1
  166. package/dist/esm/factories/createClient.js.map +1 -1
  167. package/dist/esm/factories/createTransport.d.ts.map +1 -1
  168. package/dist/esm/factories/createTransport.js.map +1 -1
  169. package/dist/esm/test/utils.js.map +1 -1
  170. package/dist/esm/transports/ankr/ankr.js.map +1 -1
  171. package/dist/esm/transports/ankr/getBalance.js +2 -2
  172. package/dist/esm/transports/ankr/getBalance.js.map +1 -1
  173. package/dist/esm/transports/ankr/getTransactionFee.js.map +1 -1
  174. package/dist/esm/transports/ankr/getTransactions.js.map +1 -1
  175. package/dist/esm/transports/ankr/methods.js.map +1 -1
  176. package/dist/esm/transports/ankr/utils.js.map +1 -1
  177. package/dist/esm/transports/blockchair/blockchair.js.map +1 -1
  178. package/dist/esm/transports/blockchair/getBalance.js +2 -2
  179. package/dist/esm/transports/blockchair/getBalance.js.map +1 -1
  180. package/dist/esm/transports/blockchair/getTransactionFee.js +2 -2
  181. package/dist/esm/transports/blockchair/getTransactionFee.js.map +1 -1
  182. package/dist/esm/transports/blockchair/getUTXOs.js +2 -2
  183. package/dist/esm/transports/blockchair/getUTXOs.js.map +1 -1
  184. package/dist/esm/transports/blockchair/getXPubAddresses.js +2 -2
  185. package/dist/esm/transports/blockchair/getXPubAddresses.js.map +1 -1
  186. package/dist/esm/transports/blockchair/methods.js.map +1 -1
  187. package/dist/esm/transports/blockcypher/blockcypher.js.map +1 -1
  188. package/dist/esm/transports/blockcypher/getBalance.js.map +1 -1
  189. package/dist/esm/transports/blockcypher/getTransactionFee.js.map +1 -1
  190. package/dist/esm/transports/blockcypher/getUTXOs.js.map +1 -1
  191. package/dist/esm/transports/blockcypher/methods.js.map +1 -1
  192. package/dist/esm/transports/blockcypher/utils.js +3 -3
  193. package/dist/esm/transports/blockcypher/utils.js.map +1 -1
  194. package/dist/esm/transports/custom.d.ts.map +1 -1
  195. package/dist/esm/transports/custom.js.map +1 -1
  196. package/dist/esm/transports/fallback.d.ts.map +1 -1
  197. package/dist/esm/transports/fallback.js +2 -2
  198. package/dist/esm/transports/fallback.js.map +1 -1
  199. package/dist/esm/transports/getHttpRpcClient.d.ts.map +1 -1
  200. package/dist/esm/transports/getHttpRpcClient.js.map +1 -1
  201. package/dist/esm/transports/getRpcProviderMethods.js.map +1 -1
  202. package/dist/esm/transports/http.d.ts.map +1 -1
  203. package/dist/esm/transports/http.js.map +1 -1
  204. package/dist/esm/transports/mempool/getBalance.js.map +1 -1
  205. package/dist/esm/transports/mempool/getTransactionFee.js.map +1 -1
  206. package/dist/esm/transports/mempool/getTransactions.js.map +1 -1
  207. package/dist/esm/transports/mempool/mempool.js.map +1 -1
  208. package/dist/esm/transports/mempool/methods.js.map +1 -1
  209. package/dist/esm/transports/mempool/utils.js.map +1 -1
  210. package/dist/esm/transports/types.d.ts.map +1 -1
  211. package/dist/esm/transports/types.js.map +1 -1
  212. package/dist/esm/transports/utxo.js.map +1 -1
  213. package/dist/esm/types/address.js.map +1 -1
  214. package/dist/esm/types/block.d.ts.map +1 -1
  215. package/dist/esm/types/chain.js.map +1 -1
  216. package/dist/esm/types/client.d.ts.map +1 -1
  217. package/dist/esm/types/request.d.ts.map +1 -1
  218. package/dist/esm/types/utils.d.ts.map +1 -1
  219. package/dist/esm/utils/buildRequest.d.ts.map +1 -1
  220. package/dist/esm/utils/buildRequest.js +4 -4
  221. package/dist/esm/utils/buildRequest.js.map +1 -1
  222. package/dist/esm/utils/cancelTransaction.js.map +1 -1
  223. package/dist/esm/utils/converter.js.map +1 -1
  224. package/dist/esm/utils/createBatchScheduler.d.ts.map +1 -1
  225. package/dist/esm/utils/createBatchScheduler.js +1 -1
  226. package/dist/esm/utils/createBatchScheduler.js.map +1 -1
  227. package/dist/esm/utils/deepEqual.js.map +1 -1
  228. package/dist/esm/utils/getAction.d.ts.map +1 -1
  229. package/dist/esm/utils/getAction.js.map +1 -1
  230. package/dist/esm/utils/getAddressInfo.js +25 -25
  231. package/dist/esm/utils/getAddressInfo.js.map +1 -1
  232. package/dist/esm/utils/idCache.js.map +1 -1
  233. package/dist/esm/utils/isAddress.js.map +1 -1
  234. package/dist/esm/utils/lru.js.map +1 -1
  235. package/dist/esm/utils/modifyFee.js.map +1 -1
  236. package/dist/esm/utils/observe.d.ts.map +1 -1
  237. package/dist/esm/utils/observe.js +2 -2
  238. package/dist/esm/utils/observe.js.map +1 -1
  239. package/dist/esm/utils/parseAccount.d.ts.map +1 -1
  240. package/dist/esm/utils/parseAccount.js.map +1 -1
  241. package/dist/esm/utils/poll.d.ts.map +1 -1
  242. package/dist/esm/utils/poll.js.map +1 -1
  243. package/dist/esm/utils/retryUntil.d.ts.map +1 -1
  244. package/dist/esm/utils/retryUntil.js.map +1 -1
  245. package/dist/esm/utils/sleep.js.map +1 -1
  246. package/dist/esm/utils/stringify.js.map +1 -1
  247. package/dist/esm/utils/uid.js.map +1 -1
  248. package/dist/esm/utils/url.js.map +1 -1
  249. package/dist/esm/utils/wait.js.map +1 -1
  250. package/dist/esm/utils/withDedupe.d.ts.map +1 -1
  251. package/dist/esm/utils/withDedupe.js +1 -1
  252. package/dist/esm/utils/withDedupe.js.map +1 -1
  253. package/dist/esm/utils/withResolvers.d.ts.map +1 -1
  254. package/dist/esm/utils/withResolvers.js.map +1 -1
  255. package/dist/esm/utils/withRetry.d.ts.map +1 -1
  256. package/dist/esm/utils/withRetry.js.map +1 -1
  257. package/dist/esm/utils/withTimeout.d.ts.map +1 -1
  258. package/dist/esm/utils/withTimeout.js.map +1 -1
  259. package/dist/esm/version.d.ts +1 -1
  260. package/dist/esm/version.js +1 -1
  261. package/dist/esm/version.js.map +1 -1
  262. package/package.json +3 -2
  263. package/src/version.ts +1 -1
  264. package/dist/cjs/transports/__mocks__/getTransactionFee.d.ts +0 -7
  265. package/dist/cjs/transports/__mocks__/getTransactionFee.js +0 -11
  266. package/dist/cjs/transports/__mocks__/getTransactionFee.js.map +0 -1
  267. package/dist/esm/transports/__mocks__/getTransactionFee.d.ts +0 -7
  268. package/dist/esm/transports/__mocks__/getTransactionFee.d.ts.map +0 -1
  269. package/dist/esm/transports/__mocks__/getTransactionFee.js +0 -8
  270. package/dist/esm/transports/__mocks__/getTransactionFee.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createTransport.js","names":["uid","uid_","buildRequest"],"sources":["../../../src/factories/createTransport.ts"],"sourcesContent":["import type { Transport, TransportConfig } from '../types/transport.js'\nimport { buildRequest } from '../utils/buildRequest.js'\nimport { uid as uid_ } from '../utils/uid.js'\n\n/**\n * @description Creates an transport intended to be used with a client.\n */\nexport function createTransport<\n type extends string,\n rpcAttributes extends Record<string, any>,\n>(\n {\n key,\n methods,\n name,\n request,\n retryCount = 3,\n retryDelay = 150,\n timeout,\n type,\n }: TransportConfig<type>,\n value?: rpcAttributes | undefined\n): ReturnType<Transport<type, rpcAttributes>> {\n const uid = uid_()\n return {\n config: {\n key,\n methods,\n name,\n request,\n retryCount,\n retryDelay,\n timeout,\n type,\n },\n request: buildRequest(request, { methods, retryCount, retryDelay, uid }),\n value,\n }\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,gBAId,EACE,KACA,SACA,MACA,SACA,aAAa,GACb,aAAa,KACb,SACA,QAEF,OAC4C;CAC5C,MAAMA,QAAMC,kBAAAA,KAAM;AAClB,QAAO;EACL,QAAQ;GACN;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,SAASC,2BAAAA,aAAa,SAAS;GAAE;GAAS;GAAY;GAAY,KAAA;GAAK,CAAC;EACxE;EACD"}
1
+ {"version":3,"file":"createTransport.js","names":["uid","uid_","buildRequest"],"sources":["../../../src/factories/createTransport.ts"],"sourcesContent":["import type { Transport, TransportConfig } from '../types/transport.js'\nimport { buildRequest } from '../utils/buildRequest.js'\nimport { uid as uid_ } from '../utils/uid.js'\n\n/**\n * @description Creates an transport intended to be used with a client.\n */\nexport function createTransport<\n type extends string,\n rpcAttributes extends Record<string, any>,\n>(\n {\n key,\n methods,\n name,\n request,\n retryCount = 3,\n retryDelay = 150,\n timeout,\n type,\n }: TransportConfig<type>,\n value?: rpcAttributes | undefined\n): ReturnType<Transport<type, rpcAttributes>> {\n const uid = uid_()\n return {\n config: {\n key,\n methods,\n name,\n request,\n retryCount,\n retryDelay,\n timeout,\n type,\n },\n request: buildRequest(request, { methods, retryCount, retryDelay, uid }),\n value,\n }\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,gBAId,EACE,KACA,SACA,MACA,SACA,aAAa,GACb,aAAa,KACb,SACA,QAEF,OAC4C;CAC5C,MAAMA,QAAMC,kBAAAA,IAAK;CACjB,OAAO;EACL,QAAQ;GACN;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF;EACA,SAASC,2BAAAA,aAAa,SAAS;GAAE;GAAS;GAAY;GAAY,KAAA;EAAI,CAAC;EACvE;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../../src/test/utils.ts"],"sourcesContent":["export const createMockResponse = <T>(\n data: T,\n options?: Partial<Response>\n): Response =>\n ({\n ok: true,\n json: () => Promise.resolve(data),\n headers: new Headers({\n 'Content-type': 'application/json',\n }),\n ...options,\n }) as Response\n"],"mappings":";;AAAA,MAAa,sBACX,MACA,aAEC;CACC,IAAI;CACJ,YAAY,QAAQ,QAAQ,KAAK;CACjC,SAAS,IAAI,QAAQ,EACnB,gBAAgB,oBACjB,CAAC;CACF,GAAG;CACJ"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../src/test/utils.ts"],"sourcesContent":["export const createMockResponse = <T>(\n data: T,\n options?: Partial<Response>\n): Response =>\n ({\n ok: true,\n json: () => Promise.resolve(data),\n headers: new Headers({\n 'Content-type': 'application/json',\n }),\n ...options,\n }) as Response\n"],"mappings":";;AAAA,MAAa,sBACX,MACA,aAEC;CACC,IAAI;CACJ,YAAY,QAAQ,QAAQ,IAAI;CAChC,SAAS,IAAI,QAAQ,EACnB,gBAAgB,mBAClB,CAAC;CACD,GAAG;AACL"}
@@ -1 +1 @@
1
- {"version":3,"file":"ankr.js","names":["ankrMethods","utxo"],"sources":["../../../../src/transports/ankr/ankr.ts"],"sourcesContent":["import type { TransportConfig } from '../../types/transport.js'\nimport type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { ankrMethods } from './methods.js'\n\ntype AnkrConfig = { baseUrl?: string; apiKey?: string } & HttpTransportConfig\n\nexport const ankr = (config?: AnkrConfig): HttpTransport => {\n const methods: TransportConfig['methods'] = {\n include: Object.keys(ankrMethods) as UTXOMethod[],\n }\n if (config?.baseUrl) {\n return utxo(config.baseUrl, { key: 'ankr', ...config, methods })\n }\n\n if (!config?.apiKey) {\n throw Error('Ankr API KEY is required')\n }\n return utxo(\n `https://rpc.ankr.com/premium-http/btc_blockbook/${config.apiKey}/api/v2`,\n {\n name: 'Ankr API',\n key: 'ankr',\n methods,\n ...config,\n }\n )\n}\n"],"mappings":";;;;AAQA,MAAa,QAAQ,WAAuC;CAC1D,MAAM,UAAsC,EAC1C,SAAS,OAAO,KAAKA,gCAAAA,YAAY,EAClC;AACD,KAAI,QAAQ,QACV,QAAOC,wBAAAA,KAAK,OAAO,SAAS;EAAE,KAAK;EAAQ,GAAG;EAAQ;EAAS,CAAC;AAGlE,KAAI,CAAC,QAAQ,OACX,OAAM,MAAM,2BAA2B;AAEzC,QAAOA,wBAAAA,KACL,mDAAmD,OAAO,OAAO,UACjE;EACE,MAAM;EACN,KAAK;EACL;EACA,GAAG;EACJ,CACF"}
1
+ {"version":3,"file":"ankr.js","names":["ankrMethods","utxo"],"sources":["../../../../src/transports/ankr/ankr.ts"],"sourcesContent":["import type { TransportConfig } from '../../types/transport.js'\nimport type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { ankrMethods } from './methods.js'\n\ntype AnkrConfig = { baseUrl?: string; apiKey?: string } & HttpTransportConfig\n\nexport const ankr = (config?: AnkrConfig): HttpTransport => {\n const methods: TransportConfig['methods'] = {\n include: Object.keys(ankrMethods) as UTXOMethod[],\n }\n if (config?.baseUrl) {\n return utxo(config.baseUrl, { key: 'ankr', ...config, methods })\n }\n\n if (!config?.apiKey) {\n throw Error('Ankr API KEY is required')\n }\n return utxo(\n `https://rpc.ankr.com/premium-http/btc_blockbook/${config.apiKey}/api/v2`,\n {\n name: 'Ankr API',\n key: 'ankr',\n methods,\n ...config,\n }\n )\n}\n"],"mappings":";;;;AAQA,MAAa,QAAQ,WAAuC;CAC1D,MAAM,UAAsC,EAC1C,SAAS,OAAO,KAAKA,gCAAAA,WAAW,EAClC;CACA,IAAI,QAAQ,SACV,OAAOC,wBAAAA,KAAK,OAAO,SAAS;EAAE,KAAK;EAAQ,GAAG;EAAQ;CAAQ,CAAC;CAGjE,IAAI,CAAC,QAAQ,QACX,MAAM,MAAM,0BAA0B;CAExC,OAAOA,wBAAAA,KACL,mDAAmD,OAAO,OAAO,UACjE;EACE,MAAM;EACN,KAAK;EACL;EACA,GAAG;CACL,CACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  //#region src/transports/ankr/getBalance.ts
4
4
  const getBalance = async (client, { baseUrl }, { address }) => {
5
5
  const apiUrl = `${baseUrl}/address/${address}?details=basic`;
@@ -8,7 +8,7 @@ const getBalance = async (client, { baseUrl }, { address }) => {
8
8
  fetchOptions: { method: "GET" }
9
9
  });
10
10
  if (response.error) return { error: {
11
- code: require_errors_rpc.RpcErrorCode.MISC_ERROR,
11
+ code: -1,
12
12
  message: response.error
13
13
  } };
14
14
  return { result: BigInt(response.balance) };
@@ -1 +1 @@
1
- {"version":3,"file":"getBalance.js","names":["RpcErrorCode"],"sources":["../../../../src/transports/ankr/getBalance.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { AnkrBalanceResponse } from './ankr.types.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl },\n { address }\n) => {\n const apiUrl = `${baseUrl}/address/${address}?details=basic`\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: {\n method: 'GET',\n },\n })) as unknown as AnkrBalanceResponse\n if (response.error) {\n return {\n error: { code: RpcErrorCode.MISC_ERROR, message: response.error },\n }\n }\n return {\n result: BigInt(response.balance),\n }\n}\n"],"mappings":";;;AAIA,MAAa,aAA6C,OACxD,QACA,EAAE,WACF,EAAE,cACC;CACH,MAAM,SAAS,GAAG,QAAQ,WAAW,QAAQ;CAE7C,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EACZ,QAAQ,OACT;EACF,CAAC;AACF,KAAI,SAAS,MACX,QAAO,EACL,OAAO;EAAE,MAAMA,mBAAAA,aAAa;EAAY,SAAS,SAAS;EAAO,EAClE;AAEH,QAAO,EACL,QAAQ,OAAO,SAAS,QAAQ,EACjC"}
1
+ {"version":3,"file":"getBalance.js","names":[],"sources":["../../../../src/transports/ankr/getBalance.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { AnkrBalanceResponse } from './ankr.types.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl },\n { address }\n) => {\n const apiUrl = `${baseUrl}/address/${address}?details=basic`\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: {\n method: 'GET',\n },\n })) as unknown as AnkrBalanceResponse\n if (response.error) {\n return {\n error: { code: RpcErrorCode.MISC_ERROR, message: response.error },\n }\n }\n return {\n result: BigInt(response.balance),\n }\n}\n"],"mappings":";;;AAIA,MAAa,aAA6C,OACxD,QACA,EAAE,WACF,EAAE,cACC;CACH,MAAM,SAAS,GAAG,QAAQ,WAAW,QAAQ;CAE7C,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EACZ,QAAQ,MACV;CACF,CAAC;CACD,IAAI,SAAS,OACX,OAAO,EACL,OAAO;EAAE,MAAA;EAA+B,SAAS,SAAS;CAAM,EAClE;CAEF,OAAO,EACL,QAAQ,OAAO,SAAS,OAAO,EACjC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTransactionFee.js","names":[],"sources":["../../../../src/transports/ankr/getTransactionFee.ts"],"sourcesContent":["import type { RpcMethodHandler } from '../types.js'\nimport type { AnkrTxnResponse } from './ankr.types.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl },\n { txId }\n) => {\n const apiUrl = `${baseUrl}/tx/${txId}`\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as AnkrTxnResponse\n if (response.error) {\n return { error: response.error }\n }\n\n return {\n result: BigInt(response.fees),\n }\n}\n"],"mappings":";;AAGA,MAAa,oBAA2D,OACtE,QACA,EAAE,WACF,EAAE,WACC;CACH,MAAM,SAAS,GAAG,QAAQ,MAAM;CAChC,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AACF,KAAI,SAAS,MACX,QAAO,EAAE,OAAO,SAAS,OAAO;AAGlC,QAAO,EACL,QAAQ,OAAO,SAAS,KAAK,EAC9B"}
1
+ {"version":3,"file":"getTransactionFee.js","names":[],"sources":["../../../../src/transports/ankr/getTransactionFee.ts"],"sourcesContent":["import type { RpcMethodHandler } from '../types.js'\nimport type { AnkrTxnResponse } from './ankr.types.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl },\n { txId }\n) => {\n const apiUrl = `${baseUrl}/tx/${txId}`\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as AnkrTxnResponse\n if (response.error) {\n return { error: response.error }\n }\n\n return {\n result: BigInt(response.fees),\n }\n}\n"],"mappings":";;AAGA,MAAa,oBAA2D,OACtE,QACA,EAAE,WACF,EAAE,WACC;CACH,MAAM,SAAS,GAAG,QAAQ,MAAM;CAChC,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CACD,IAAI,SAAS,OACX,OAAO,EAAE,OAAO,SAAS,MAAM;CAGjC,OAAO,EACL,QAAQ,OAAO,SAAS,IAAI,EAC9B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTransactions.js","names":["urlWithParams","ankrTransactionTransformer"],"sources":["../../../../src/transports/ankr/getTransactions.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { AnkrAddressWithTxnsResponse } from './ankr.types.js'\nimport { ankrTransactionTransformer } from './utils.js'\n\nexport const getTransactions: RpcMethodHandler<'getTransactions'> = async (\n client,\n { baseUrl },\n { address, limit = 50, offset = 0, lastBlock }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/address/${address}`, {\n details: 'txs',\n pageSize: limit,\n to: lastBlock,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as AnkrAddressWithTxnsResponse\n\n if (response.error) {\n return { error: response.error }\n }\n\n const total = response.txs || 0\n const page = Math.floor(offset / limit) + 1\n const hasMore = total > offset + response.transactions.length\n\n const data = {\n transactions: response.transactions.map(ankrTransactionTransformer),\n total,\n page,\n itemsPerPage: limit,\n hasMore,\n }\n\n return { result: data }\n}\n"],"mappings":";;;;AAKA,MAAa,kBAAuD,OAClE,QACA,EAAE,WACF,EAAE,SAAS,QAAQ,IAAI,SAAS,GAAG,gBAChC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,WAAW,WAAW;EAC5D,SAAS;EACT,UAAU;EACV,IAAI;EACL,CAAC;CAEF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AAEF,KAAI,SAAS,MACX,QAAO,EAAE,OAAO,SAAS,OAAO;CAGlC,MAAM,QAAQ,SAAS,OAAO;CAC9B,MAAM,OAAO,KAAK,MAAM,SAAS,MAAM,GAAG;CAC1C,MAAM,UAAU,QAAQ,SAAS,SAAS,aAAa;AAUvD,QAAO,EAAE,QARI;EACX,cAAc,SAAS,aAAa,IAAIC,8BAAAA,2BAA2B;EACnE;EACA;EACA,cAAc;EACd;EACD,EAEsB"}
1
+ {"version":3,"file":"getTransactions.js","names":["urlWithParams","ankrTransactionTransformer"],"sources":["../../../../src/transports/ankr/getTransactions.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { AnkrAddressWithTxnsResponse } from './ankr.types.js'\nimport { ankrTransactionTransformer } from './utils.js'\n\nexport const getTransactions: RpcMethodHandler<'getTransactions'> = async (\n client,\n { baseUrl },\n { address, limit = 50, offset = 0, lastBlock }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/address/${address}`, {\n details: 'txs',\n pageSize: limit,\n to: lastBlock,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as AnkrAddressWithTxnsResponse\n\n if (response.error) {\n return { error: response.error }\n }\n\n const total = response.txs || 0\n const page = Math.floor(offset / limit) + 1\n const hasMore = total > offset + response.transactions.length\n\n const data = {\n transactions: response.transactions.map(ankrTransactionTransformer),\n total,\n page,\n itemsPerPage: limit,\n hasMore,\n }\n\n return { result: data }\n}\n"],"mappings":";;;;AAKA,MAAa,kBAAuD,OAClE,QACA,EAAE,WACF,EAAE,SAAS,QAAQ,IAAI,SAAS,GAAG,gBAChC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,WAAW,WAAW;EAC5D,SAAS;EACT,UAAU;EACV,IAAI;CACN,CAAC;CAED,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,IAAI,SAAS,OACX,OAAO,EAAE,OAAO,SAAS,MAAM;CAGjC,MAAM,QAAQ,SAAS,OAAO;CAC9B,MAAM,OAAO,KAAK,MAAM,SAAS,KAAK,IAAI;CAC1C,MAAM,UAAU,QAAQ,SAAS,SAAS,aAAa;CAUvD,OAAO,EAAE,QAAQ;EAPf,cAAc,SAAS,aAAa,IAAIC,8BAAAA,0BAA0B;EAClE;EACA;EACA,cAAc;EACd;CAGkB,EAAE;AACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/ankr/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 ankrMethods: RpcMethods = {\n getBalance,\n getTransactions,\n getTransactionFee,\n}\n"],"mappings":";;;;;AAKA,MAAa,cAA0B;CACrC,YAAA,mCAAA;CACA,iBAAA,wCAAA;CACA,mBAAA,0CAAA;CACD"}
1
+ {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/ankr/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 ankrMethods: RpcMethods = {\n getBalance,\n getTransactions,\n getTransactionFee,\n}\n"],"mappings":";;;;;AAKA,MAAa,cAA0B;CACrC,YAAA,mCAAA;CACA,iBAAA,wCAAA;CACA,mBAAA,0CAAA;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/transports/ankr/utils.ts"],"sourcesContent":["import type { UTXOTransaction } from '../../types/transaction.js'\nimport type { AnkrTransaction } from './ankr.types.js'\n\nexport const ankrTransactionTransformer = (\n txn: AnkrTransaction\n): Partial<UTXOTransaction> => ({\n blockhash: txn?.blockHash,\n blocktime: txn.blockTime,\n confirmations: txn.confirmations,\n hex: txn.hex,\n locktime: txn?.coinSpecificData?.locktime,\n hash: txn.coinSpecificData?.hash,\n size: txn.size,\n txid: txn.txid,\n version: txn.version,\n vin: txn.vin.map((vin) => ({\n scriptSig: vin.scriptSig,\n sequence: vin.sequence,\n txid: vin.txid,\n vout: vin.vout,\n txinwitness: vin.addresses,\n })),\n vsize: txn.vsize,\n vout: txn.vout.map((vout) => ({\n n: vout.n,\n scriptPubKey: vout.scriptPubKey,\n value: vout.value,\n })),\n})\n"],"mappings":";;AAGA,MAAa,8BACX,SAC8B;CAC9B,WAAW,KAAK;CAChB,WAAW,IAAI;CACf,eAAe,IAAI;CACnB,KAAK,IAAI;CACT,UAAU,KAAK,kBAAkB;CACjC,MAAM,IAAI,kBAAkB;CAC5B,MAAM,IAAI;CACV,MAAM,IAAI;CACV,SAAS,IAAI;CACb,KAAK,IAAI,IAAI,KAAK,SAAS;EACzB,WAAW,IAAI;EACf,UAAU,IAAI;EACd,MAAM,IAAI;EACV,MAAM,IAAI;EACV,aAAa,IAAI;EAClB,EAAE;CACH,OAAO,IAAI;CACX,MAAM,IAAI,KAAK,KAAK,UAAU;EAC5B,GAAG,KAAK;EACR,cAAc,KAAK;EACnB,OAAO,KAAK;EACb,EAAE;CACJ"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/transports/ankr/utils.ts"],"sourcesContent":["import type { UTXOTransaction } from '../../types/transaction.js'\nimport type { AnkrTransaction } from './ankr.types.js'\n\nexport const ankrTransactionTransformer = (\n txn: AnkrTransaction\n): Partial<UTXOTransaction> => ({\n blockhash: txn?.blockHash,\n blocktime: txn.blockTime,\n confirmations: txn.confirmations,\n hex: txn.hex,\n locktime: txn?.coinSpecificData?.locktime,\n hash: txn.coinSpecificData?.hash,\n size: txn.size,\n txid: txn.txid,\n version: txn.version,\n vin: txn.vin.map((vin) => ({\n scriptSig: vin.scriptSig,\n sequence: vin.sequence,\n txid: vin.txid,\n vout: vin.vout,\n txinwitness: vin.addresses,\n })),\n vsize: txn.vsize,\n vout: txn.vout.map((vout) => ({\n n: vout.n,\n scriptPubKey: vout.scriptPubKey,\n value: vout.value,\n })),\n})\n"],"mappings":";;AAGA,MAAa,8BACX,SAC8B;CAC9B,WAAW,KAAK;CAChB,WAAW,IAAI;CACf,eAAe,IAAI;CACnB,KAAK,IAAI;CACT,UAAU,KAAK,kBAAkB;CACjC,MAAM,IAAI,kBAAkB;CAC5B,MAAM,IAAI;CACV,MAAM,IAAI;CACV,SAAS,IAAI;CACb,KAAK,IAAI,IAAI,KAAK,SAAS;EACzB,WAAW,IAAI;EACf,UAAU,IAAI;EACd,MAAM,IAAI;EACV,MAAM,IAAI;EACV,aAAa,IAAI;CACnB,EAAE;CACF,OAAO,IAAI;CACX,MAAM,IAAI,KAAK,KAAK,UAAU;EAC5B,GAAG,KAAK;EACR,cAAc,KAAK;EACnB,OAAO,KAAK;CACd,EAAE;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"blockchair.js","names":["utxo","blockchairMethods"],"sources":["../../../../src/transports/blockchair/blockchair.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { blockchairMethods } from './methods.js'\n\ntype BlockchairConfig = {\n baseUrl?: string\n apiKey?: string\n} & HttpTransportConfig\n\nexport const blockchair = (config?: BlockchairConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://api.blockchair.com', {\n name: 'Blockchair API',\n key: 'blockchair',\n includeChainToURL: true,\n methods: {\n include: Object.keys(blockchairMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;;AAUA,MAAa,cAAc,WACzBA,wBAAAA,KAAK,QAAQ,WAAW,8BAA8B;CACpD,MAAM;CACN,KAAK;CACL,mBAAmB;CACnB,SAAS,EACP,SAAS,OAAO,KAAKC,sCAAAA,kBAAkB,EACxC;CACD,GAAG;CACJ,CAAC"}
1
+ {"version":3,"file":"blockchair.js","names":["utxo","blockchairMethods"],"sources":["../../../../src/transports/blockchair/blockchair.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { blockchairMethods } from './methods.js'\n\ntype BlockchairConfig = {\n baseUrl?: string\n apiKey?: string\n} & HttpTransportConfig\n\nexport const blockchair = (config?: BlockchairConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://api.blockchair.com', {\n name: 'Blockchair API',\n key: 'blockchair',\n includeChainToURL: true,\n methods: {\n include: Object.keys(blockchairMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;;AAUA,MAAa,cAAc,WACzBA,wBAAAA,KAAK,QAAQ,WAAW,8BAA8B;CACpD,MAAM;CACN,KAAK;CACL,mBAAmB;CACnB,SAAS,EACP,SAAS,OAAO,KAAKC,sCAAAA,iBAAiB,EACxC;CACA,GAAG;AACL,CAAC"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  const require_utils_url = require("../../utils/url.js");
4
4
  //#region src/transports/blockchair/getBalance.ts
5
5
  const getBalance = async (client, { baseUrl, apiKey }, { address }) => {
@@ -12,7 +12,7 @@ const getBalance = async (client, { baseUrl, apiKey }, { address }) => {
12
12
  fetchOptions: { method: "GET" }
13
13
  });
14
14
  if (response.data[address] === void 0 || response.context.error || response.context?.code !== 200) return { error: {
15
- code: response.context.code === 429 ? require_errors_rpc.RpcErrorCode.ACCESS_DENIED : require_errors_rpc.RpcErrorCode.MISC_ERROR,
15
+ code: response.context.code === 429 ? -32002 : -1,
16
16
  message: response.context?.error
17
17
  } };
18
18
  return { result: BigInt(response.data[address]) };
@@ -1 +1 @@
1
- {"version":3,"file":"getBalance.js","names":["urlWithParams","RpcErrorCode"],"sources":["../../../../src/transports/blockchair/getBalance.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockchairAddressBalanceData,\n BlockchairResponse,\n} from './blockchair.types.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl, apiKey },\n { address }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/addresses/balances`, {\n key: apiKey,\n addresses: address,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockchairAddressBalanceData>\n\n if (\n response.data[address] === undefined ||\n response.context.error ||\n response.context?.code !== 200\n ) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n return {\n result: BigInt(response.data[address]),\n }\n}\n"],"mappings":";;;;AAQA,MAAa,aAA6C,OACxD,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,sBAAsB;EAC5D,KAAK;EACL,WAAW;EACZ,CAAC;CACF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AAEF,KACE,SAAS,KAAK,aAAa,KAAA,KAC3B,SAAS,QAAQ,SACjB,SAAS,SAAS,SAAS,IAE3B,QAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MACtBC,mBAAAA,aAAa,gBACbA,mBAAAA,aAAa;EACnB,SAAS,SAAS,SAAS;EAC5B,EACF;AAGH,QAAO,EACL,QAAQ,OAAO,SAAS,KAAK,SAAS,EACvC"}
1
+ {"version":3,"file":"getBalance.js","names":["urlWithParams"],"sources":["../../../../src/transports/blockchair/getBalance.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockchairAddressBalanceData,\n BlockchairResponse,\n} from './blockchair.types.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl, apiKey },\n { address }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/addresses/balances`, {\n key: apiKey,\n addresses: address,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockchairAddressBalanceData>\n\n if (\n response.data[address] === undefined ||\n response.context.error ||\n response.context?.code !== 200\n ) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n return {\n result: BigInt(response.data[address]),\n }\n}\n"],"mappings":";;;;AAQA,MAAa,aAA6C,OACxD,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,sBAAsB;EAC5D,KAAK;EACL,WAAW;CACb,CAAC;CACD,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,IACE,SAAS,KAAK,aAAa,KAAA,KAC3B,SAAS,QAAQ,SACjB,SAAS,SAAS,SAAS,KAE3B,OAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MAAA,SAAA;EAG5B,SAAS,SAAS,SAAS;CAC7B,EACF;CAGF,OAAO,EACL,QAAQ,OAAO,SAAS,KAAK,QAAQ,EACvC;AACF"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  const require_utils_url = require("../../utils/url.js");
4
4
  //#region src/transports/blockchair/getTransactionFee.ts
5
5
  const getTransactionFee = async (client, { baseUrl, apiKey }, { txId }) => {
@@ -9,7 +9,7 @@ const getTransactionFee = async (client, { baseUrl, apiKey }, { txId }) => {
9
9
  fetchOptions: { method: "GET" }
10
10
  });
11
11
  if (!response.data[txId] || response.context.error || response.context?.code !== 200) return { error: {
12
- code: response.context.code === 429 ? require_errors_rpc.RpcErrorCode.ACCESS_DENIED : require_errors_rpc.RpcErrorCode.MISC_ERROR,
12
+ code: response.context.code === 429 ? -32002 : -1,
13
13
  message: response.context?.error
14
14
  } };
15
15
  return { result: BigInt(response.data[txId].transaction.fee) };
@@ -1 +1 @@
1
- {"version":3,"file":"getTransactionFee.js","names":["urlWithParams","RpcErrorCode"],"sources":["../../../../src/transports/blockchair/getTransactionFee.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockchairTransactionResponse } from './blockchair.types.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl, apiKey },\n { txId }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/dashboards/transaction/${txId}`, {\n key: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: {\n method: 'GET',\n },\n })) as unknown as BlockchairTransactionResponse\n\n if (\n !response.data[txId] ||\n response.context.error ||\n response.context?.code !== 200\n ) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n return {\n result: BigInt(response.data[txId].transaction.fee),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,oBAA2D,OACtE,QACA,EAAE,SAAS,UACX,EAAE,WACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,0BAA0B,QAAQ,EACxE,KAAK,QACN,CAAC;CACF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EACZ,QAAQ,OACT;EACF,CAAC;AAEF,KACE,CAAC,SAAS,KAAK,SACf,SAAS,QAAQ,SACjB,SAAS,SAAS,SAAS,IAE3B,QAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MACtBC,mBAAAA,aAAa,gBACbA,mBAAAA,aAAa;EACnB,SAAS,SAAS,SAAS;EAC5B,EACF;AAGH,QAAO,EACL,QAAQ,OAAO,SAAS,KAAK,MAAM,YAAY,IAAI,EACpD"}
1
+ {"version":3,"file":"getTransactionFee.js","names":["urlWithParams"],"sources":["../../../../src/transports/blockchair/getTransactionFee.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockchairTransactionResponse } from './blockchair.types.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl, apiKey },\n { txId }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/dashboards/transaction/${txId}`, {\n key: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: {\n method: 'GET',\n },\n })) as unknown as BlockchairTransactionResponse\n\n if (\n !response.data[txId] ||\n response.context.error ||\n response.context?.code !== 200\n ) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n return {\n result: BigInt(response.data[txId].transaction.fee),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,oBAA2D,OACtE,QACA,EAAE,SAAS,UACX,EAAE,WACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,0BAA0B,QAAQ,EACxE,KAAK,OACP,CAAC;CACD,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EACZ,QAAQ,MACV;CACF,CAAC;CAED,IACE,CAAC,SAAS,KAAK,SACf,SAAS,QAAQ,SACjB,SAAS,SAAS,SAAS,KAE3B,OAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MAAA,SAAA;EAG5B,SAAS,SAAS,SAAS;CAC7B,EACF;CAGF,OAAO,EACL,QAAQ,OAAO,SAAS,KAAK,MAAM,YAAY,GAAG,EACpD;AACF"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_errors_base = require("../../errors/base.js");
3
3
  const require_errors_request = require("../../errors/request.js");
4
- const require_errors_rpc = require("../../errors/rpc.js");
4
+ require("../../errors/rpc.js");
5
5
  const require_errors_utxo = require("../../errors/utxo.js");
6
6
  const require_utils_url = require("../../utils/url.js");
7
7
  const require_transports_blockchair_getBalance = require("./getBalance.js");
@@ -38,7 +38,7 @@ const getUTXOs = async (client, { baseUrl, apiKey }, { address, minValue }) => {
38
38
  }
39
39
  },
40
40
  error: {
41
- code: response.context.code === 429 ? require_errors_rpc.RpcErrorCode.ACCESS_DENIED : require_errors_rpc.RpcErrorCode.MISC_ERROR,
41
+ code: response.context.code === 429 ? -32002 : -1,
42
42
  message: response.context.error || "Error fetching utxos"
43
43
  }
44
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","RpcErrorCode","getBalance","BaseError","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockchair/getUTXOs.ts"],"sourcesContent":["import { BaseError } from '../../errors/base.js'\nimport { RpcRequestError } from '../../errors/request.js'\nimport { RpcErrorCode } from '../../errors/rpc.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\n\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockChairDashboardAddressResponse,\n BlockchairResponse,\n BlockchairUTXO,\n} from './blockchair.types.js'\nimport { getBalance } from './getBalance.js'\n\nconst blockChairUTXOTransformer =\n (scriptHex: string) =>\n (data: BlockchairUTXO): UTXO => ({\n blockHeight: data.block_id,\n scriptHex,\n txId: data.transaction_hash,\n value: data.value,\n vout: data.index,\n })\n\nconst MAX_API_LIMIT = '100,100'\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let offset = 0\n let hasMore = true\n\n while (hasMore) {\n const apiUrl = urlWithParams(\n `${baseUrl}/dashboards/addresses/${address}`,\n {\n key: apiKey,\n offset: `0,${offset}`,\n limit: MAX_API_LIMIT,\n }\n )\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockChairDashboardAddressResponse>\n\n if (response.context?.code !== 200 && response.context?.code !== 404) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context.error || 'Error fetching utxos',\n },\n })\n }\n\n if (!response.data || response.data.utxo.length === 0) {\n hasMore = false\n continue\n }\n\n const { limit } = response.context\n const totalRows = response.data.addresses[address].unspent_output_count\n if (limit && totalRows) {\n const [, utxoLimit] = String(limit)\n .split(',')\n .map((val) => Number(val))\n hasMore = offset + utxoLimit < totalRows\n offset += utxoLimit\n } else {\n hasMore = false\n offset += 0\n }\n\n yield response.data\n }\n }\n\n if (minValue) {\n const { error, result: balance } = await getBalance(\n client,\n { baseUrl, apiKey },\n { address }\n )\n\n if (error) {\n throw new BaseError('Error fetching balance', {\n cause: error,\n })\n }\n\n if (balance === undefined) {\n throw new BaseError('Balance is undefined', {\n cause: new Error('Unable to determine balance'),\n })\n }\n\n if (minValue > Number(balance)) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: Number(balance),\n })\n }\n }\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const addressScriptHex = batch.addresses[address].script_hex\n const utxoBatch = batch.utxo.map(\n blockChairUTXOTransformer(addressScriptHex)\n )\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BACH,eACA,UAAgC;CAC/B,aAAa,KAAK;CAClB;CACA,MAAM,KAAK;CACX,OAAO,KAAK;CACZ,MAAM,KAAK;CACZ;AAEH,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,SAAS;EACb,IAAI,UAAU;AAEd,SAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cACb,GAAG,QAAQ,wBAAwB,WACnC;IACE,KAAK;IACL,QAAQ,KAAK;IACb,OAAO;IACR,CACF;GACD,MAAM,WAAY,MAAM,OAAO,QAAQ;IACrC,KAAK;IACL,cAAc,EAAE,QAAQ,OAAO;IAChC,CAAC;AAEF,OAAI,SAAS,SAAS,SAAS,OAAO,SAAS,SAAS,SAAS,IAC/D,OAAM,IAAIC,uBAAAA,gBAAgB;IACxB,KAAK;IACL,MAAM;KACJ,QAAQ;KACR,QAAQ;MACN;MACA;MACD;KACF;IACD,OAAO;KACL,MACE,SAAS,QAAQ,SAAS,MACtBC,mBAAAA,aAAa,gBACbA,mBAAAA,aAAa;KACnB,SAAS,SAAS,QAAQ,SAAS;KACpC;IACF,CAAC;AAGJ,OAAI,CAAC,SAAS,QAAQ,SAAS,KAAK,KAAK,WAAW,GAAG;AACrD,cAAU;AACV;;GAGF,MAAM,EAAE,UAAU,SAAS;GAC3B,MAAM,YAAY,SAAS,KAAK,UAAU,SAAS;AACnD,OAAI,SAAS,WAAW;IACtB,MAAM,GAAG,aAAa,OAAO,MAAM,CAChC,MAAM,IAAI,CACV,KAAK,QAAQ,OAAO,IAAI,CAAC;AAC5B,cAAU,SAAS,YAAY;AAC/B,cAAU;UACL;AACL,cAAU;AACV,cAAU;;AAGZ,SAAM,SAAS;;;AAInB,KAAI,UAAU;EACZ,MAAM,EAAE,OAAO,QAAQ,YAAY,MAAMC,yCAAAA,WACvC,QACA;GAAE;GAAS;GAAQ,EACnB,EAAE,SAAS,CACZ;AAED,MAAI,MACF,OAAM,IAAIC,oBAAAA,UAAU,0BAA0B,EAC5C,OAAO,OACR,CAAC;AAGJ,MAAI,YAAY,KAAA,EACd,OAAM,IAAIA,oBAAAA,UAAU,wBAAwB,EAC1C,uBAAO,IAAI,MAAM,8BAA8B,EAChD,CAAC;AAGJ,MAAI,WAAW,OAAO,QAAQ,CAC5B,OAAM,IAAIC,oBAAAA,6BAA6B;GACrC;GACA;GACA,SAAS,OAAO,QAAQ;GACzB,CAAC;;CAGN,MAAM,QAAgB,EAAE;CACxB,IAAI,aAAa;AAEjB,YAAW,MAAM,SAAS,YAAY,EAAE;EACtC,MAAM,mBAAmB,MAAM,UAAU,SAAS;EAClD,MAAM,YAAY,MAAM,KAAK,IAC3B,0BAA0B,iBAAiB,CAC5C;AACD,QAAM,KAAK,GAAG,UAAU;AAExB,MAAI,UAAU;AACZ,iBAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,EAAE;AAClE,OAAI,cAAc,SAChB;;;AAKN,QAAO,EAAE,QAAQ,OAAO"}
1
+ {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","getBalance","BaseError","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockchair/getUTXOs.ts"],"sourcesContent":["import { BaseError } from '../../errors/base.js'\nimport { RpcRequestError } from '../../errors/request.js'\nimport { RpcErrorCode } from '../../errors/rpc.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\n\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockChairDashboardAddressResponse,\n BlockchairResponse,\n BlockchairUTXO,\n} from './blockchair.types.js'\nimport { getBalance } from './getBalance.js'\n\nconst blockChairUTXOTransformer =\n (scriptHex: string) =>\n (data: BlockchairUTXO): UTXO => ({\n blockHeight: data.block_id,\n scriptHex,\n txId: data.transaction_hash,\n value: data.value,\n vout: data.index,\n })\n\nconst MAX_API_LIMIT = '100,100'\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let offset = 0\n let hasMore = true\n\n while (hasMore) {\n const apiUrl = urlWithParams(\n `${baseUrl}/dashboards/addresses/${address}`,\n {\n key: apiKey,\n offset: `0,${offset}`,\n limit: MAX_API_LIMIT,\n }\n )\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockChairDashboardAddressResponse>\n\n if (response.context?.code !== 200 && response.context?.code !== 404) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context.error || 'Error fetching utxos',\n },\n })\n }\n\n if (!response.data || response.data.utxo.length === 0) {\n hasMore = false\n continue\n }\n\n const { limit } = response.context\n const totalRows = response.data.addresses[address].unspent_output_count\n if (limit && totalRows) {\n const [, utxoLimit] = String(limit)\n .split(',')\n .map((val) => Number(val))\n hasMore = offset + utxoLimit < totalRows\n offset += utxoLimit\n } else {\n hasMore = false\n offset += 0\n }\n\n yield response.data\n }\n }\n\n if (minValue) {\n const { error, result: balance } = await getBalance(\n client,\n { baseUrl, apiKey },\n { address }\n )\n\n if (error) {\n throw new BaseError('Error fetching balance', {\n cause: error,\n })\n }\n\n if (balance === undefined) {\n throw new BaseError('Balance is undefined', {\n cause: new Error('Unable to determine balance'),\n })\n }\n\n if (minValue > Number(balance)) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: Number(balance),\n })\n }\n }\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const addressScriptHex = batch.addresses[address].script_hex\n const utxoBatch = batch.utxo.map(\n blockChairUTXOTransformer(addressScriptHex)\n )\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BACH,eACA,UAAgC;CAC/B,aAAa,KAAK;CAClB;CACA,MAAM,KAAK;CACX,OAAO,KAAK;CACZ,MAAM,KAAK;AACb;AAEF,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,SAAS;EACb,IAAI,UAAU;EAEd,OAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cACb,GAAG,QAAQ,wBAAwB,WACnC;IACE,KAAK;IACL,QAAQ,KAAK;IACb,OAAO;GACT,CACF;GACA,MAAM,WAAY,MAAM,OAAO,QAAQ;IACrC,KAAK;IACL,cAAc,EAAE,QAAQ,MAAM;GAChC,CAAC;GAED,IAAI,SAAS,SAAS,SAAS,OAAO,SAAS,SAAS,SAAS,KAC/D,MAAM,IAAIC,uBAAAA,gBAAgB;IACxB,KAAK;IACL,MAAM;KACJ,QAAQ;KACR,QAAQ;MACN;MACA;KACF;IACF;IACA,OAAO;KACL,MACE,SAAS,QAAQ,SAAS,MAAA,SAAA;KAG5B,SAAS,SAAS,QAAQ,SAAS;IACrC;GACF,CAAC;GAGH,IAAI,CAAC,SAAS,QAAQ,SAAS,KAAK,KAAK,WAAW,GAAG;IACrD,UAAU;IACV;GACF;GAEA,MAAM,EAAE,UAAU,SAAS;GAC3B,MAAM,YAAY,SAAS,KAAK,UAAU,SAAS;GACnD,IAAI,SAAS,WAAW;IACtB,MAAM,GAAG,aAAa,OAAO,KAAK,EAC/B,MAAM,GAAG,EACT,KAAK,QAAQ,OAAO,GAAG,CAAC;IAC3B,UAAU,SAAS,YAAY;IAC/B,UAAU;GACZ,OAAO;IACL,UAAU;IACV,UAAU;GACZ;GAEA,MAAM,SAAS;EACjB;CACF;CAEA,IAAI,UAAU;EACZ,MAAM,EAAE,OAAO,QAAQ,YAAY,MAAMC,yCAAAA,WACvC,QACA;GAAE;GAAS;EAAO,GAClB,EAAE,QAAQ,CACZ;EAEA,IAAI,OACF,MAAM,IAAIC,oBAAAA,UAAU,0BAA0B,EAC5C,OAAO,MACT,CAAC;EAGH,IAAI,YAAY,KAAA,GACd,MAAM,IAAIA,oBAAAA,UAAU,wBAAwB,EAC1C,uBAAO,IAAI,MAAM,6BAA6B,EAChD,CAAC;EAGH,IAAI,WAAW,OAAO,OAAO,GAC3B,MAAM,IAAIC,oBAAAA,6BAA6B;GACrC;GACA;GACA,SAAS,OAAO,OAAO;EACzB,CAAC;CAEL;CACA,MAAM,QAAgB,CAAC;CACvB,IAAI,aAAa;CAEjB,WAAW,MAAM,SAAS,WAAW,GAAG;EACtC,MAAM,mBAAmB,MAAM,UAAU,SAAS;EAClD,MAAM,YAAY,MAAM,KAAK,IAC3B,0BAA0B,gBAAgB,CAC5C;EACA,MAAM,KAAK,GAAG,SAAS;EAEvB,IAAI,UAAU;GACZ,cAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,CAAC;GACjE,IAAI,cAAc,UAChB;EAEJ;CACF;CAEA,OAAO,EAAE,QAAQ,MAAM;AACzB"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  const require_utils_url = require("../../utils/url.js");
4
4
  //#region src/transports/blockchair/getXPubAddresses.ts
5
5
  const getXPubAddresses = async (client, { baseUrl, apiKey }, { xPubKey }) => {
@@ -9,7 +9,7 @@ const getXPubAddresses = async (client, { baseUrl, apiKey }, { xPubKey }) => {
9
9
  fetchOptions: { method: "GET" }
10
10
  });
11
11
  if (response.context.error || response.context?.code !== 200) return { error: {
12
- code: response.context.code === 429 ? require_errors_rpc.RpcErrorCode.ACCESS_DENIED : require_errors_rpc.RpcErrorCode.MISC_ERROR,
12
+ code: response.context.code === 429 ? -32002 : -1,
13
13
  message: response.context?.error
14
14
  } };
15
15
  if (response.data[xPubKey] === void 0) return { result: {
@@ -1 +1 @@
1
- {"version":3,"file":"getXPubAddresses.js","names":["urlWithParams","RpcErrorCode"],"sources":["../../../../src/transports/blockchair/getXPubAddresses.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockchairResponse,\n BlockchairXpubResponse,\n} from './blockchair.types.js'\n\nexport const getXPubAddresses: RpcMethodHandler<'getXPubAddresses'> = async (\n client,\n { baseUrl, apiKey },\n { xPubKey }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/dashboards/xpub/${xPubKey}`, {\n key: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockchairXpubResponse>\n\n if (response.context.error || response.context?.code !== 200) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n if (response.data[xPubKey] === undefined) {\n return {\n result: {\n balance: 0n,\n addresses: [],\n },\n }\n }\n\n const xpubData = response.data[xPubKey]\n\n const result = {\n balance: BigInt(xpubData.xpub.balance),\n addresses: Object.entries(xpubData.addresses).map(([address, data]) => ({\n address,\n balance: BigInt(data.balance),\n path: data.path,\n scriptHex: data.script_hex,\n })),\n }\n\n return {\n result,\n }\n}\n"],"mappings":";;;;AAQA,MAAa,mBAAyD,OACpE,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,mBAAmB,WAAW,EACpE,KAAK,QACN,CAAC;CACF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AAEF,KAAI,SAAS,QAAQ,SAAS,SAAS,SAAS,SAAS,IACvD,QAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MACtBC,mBAAAA,aAAa,gBACbA,mBAAAA,aAAa;EACnB,SAAS,SAAS,SAAS;EAC5B,EACF;AAGH,KAAI,SAAS,KAAK,aAAa,KAAA,EAC7B,QAAO,EACL,QAAQ;EACN,SAAS;EACT,WAAW,EAAE;EACd,EACF;CAGH,MAAM,WAAW,SAAS,KAAK;AAY/B,QAAO,EACL,QAXa;EACb,SAAS,OAAO,SAAS,KAAK,QAAQ;EACtC,WAAW,OAAO,QAAQ,SAAS,UAAU,CAAC,KAAK,CAAC,SAAS,WAAW;GACtE;GACA,SAAS,OAAO,KAAK,QAAQ;GAC7B,MAAM,KAAK;GACX,WAAW,KAAK;GACjB,EAAE;EACJ,EAIA"}
1
+ {"version":3,"file":"getXPubAddresses.js","names":["urlWithParams"],"sources":["../../../../src/transports/blockchair/getXPubAddresses.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockchairResponse,\n BlockchairXpubResponse,\n} from './blockchair.types.js'\n\nexport const getXPubAddresses: RpcMethodHandler<'getXPubAddresses'> = async (\n client,\n { baseUrl, apiKey },\n { xPubKey }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/dashboards/xpub/${xPubKey}`, {\n key: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockchairXpubResponse>\n\n if (response.context.error || response.context?.code !== 200) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n if (response.data[xPubKey] === undefined) {\n return {\n result: {\n balance: 0n,\n addresses: [],\n },\n }\n }\n\n const xpubData = response.data[xPubKey]\n\n const result = {\n balance: BigInt(xpubData.xpub.balance),\n addresses: Object.entries(xpubData.addresses).map(([address, data]) => ({\n address,\n balance: BigInt(data.balance),\n path: data.path,\n scriptHex: data.script_hex,\n })),\n }\n\n return {\n result,\n }\n}\n"],"mappings":";;;;AAQA,MAAa,mBAAyD,OACpE,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,mBAAmB,WAAW,EACpE,KAAK,OACP,CAAC;CACD,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,IAAI,SAAS,QAAQ,SAAS,SAAS,SAAS,SAAS,KACvD,OAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MAAA,SAAA;EAG5B,SAAS,SAAS,SAAS;CAC7B,EACF;CAGF,IAAI,SAAS,KAAK,aAAa,KAAA,GAC7B,OAAO,EACL,QAAQ;EACN,SAAS;EACT,WAAW,CAAC;CACd,EACF;CAGF,MAAM,WAAW,SAAS,KAAK;CAY/B,OAAO,EACL,QAAA;EAVA,SAAS,OAAO,SAAS,KAAK,OAAO;EACrC,WAAW,OAAO,QAAQ,SAAS,SAAS,EAAE,KAAK,CAAC,SAAS,WAAW;GACtE;GACA,SAAS,OAAO,KAAK,OAAO;GAC5B,MAAM,KAAK;GACX,WAAW,KAAK;EAClB,EAAE;CAIG,EACP;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockchair/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\nimport { getXPubAddresses } from './getXPubAddresses.js'\n\nexport const blockchairMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n getXPubAddresses,\n}\n"],"mappings":";;;;;;AAMA,MAAa,oBAAgC;CAC3C,YAAA,yCAAA;CACA,UAAA,uCAAA;CACA,mBAAA,gDAAA;CACA,kBAAA,+CAAA;CACD"}
1
+ {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockchair/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\nimport { getXPubAddresses } from './getXPubAddresses.js'\n\nexport const blockchairMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n getXPubAddresses,\n}\n"],"mappings":";;;;;;AAMA,MAAa,oBAAgC;CAC3C,YAAA,yCAAA;CACA,UAAA,uCAAA;CACA,mBAAA,gDAAA;CACA,kBAAA,+CAAA;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"blockcypher.js","names":["utxo","blockcypherMethods"],"sources":["../../../../src/transports/blockcypher/blockcypher.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { blockcypherMethods } from './methods.js'\n\ntype BlockcypherConfig = {\n baseUrl?: string\n apiKey?: string\n} & HttpTransportConfig\n\nexport const blockcypher = (config?: BlockcypherConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://api.blockcypher.com/v1/btc/main', {\n name: 'Blockcypher API',\n key: 'blockcypher',\n methods: {\n include: Object.keys(blockcypherMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;;AAUA,MAAa,eAAe,WAC1BA,wBAAAA,KAAK,QAAQ,WAAW,2CAA2C;CACjE,MAAM;CACN,KAAK;CACL,SAAS,EACP,SAAS,OAAO,KAAKC,uCAAAA,mBAAmB,EACzC;CACD,GAAG;CACJ,CAAC"}
1
+ {"version":3,"file":"blockcypher.js","names":["utxo","blockcypherMethods"],"sources":["../../../../src/transports/blockcypher/blockcypher.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { blockcypherMethods } from './methods.js'\n\ntype BlockcypherConfig = {\n baseUrl?: string\n apiKey?: string\n} & HttpTransportConfig\n\nexport const blockcypher = (config?: BlockcypherConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://api.blockcypher.com/v1/btc/main', {\n name: 'Blockcypher API',\n key: 'blockcypher',\n methods: {\n include: Object.keys(blockcypherMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;;AAUA,MAAa,eAAe,WAC1BA,wBAAAA,KAAK,QAAQ,WAAW,2CAA2C;CACjE,MAAM;CACN,KAAK;CACL,SAAS,EACP,SAAS,OAAO,KAAKC,uCAAAA,kBAAkB,EACzC;CACA,GAAG;AACL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getBalance.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getBalance.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherBalanceResponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl, apiKey },\n { address }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherBalanceResponse\n if (response.error) {\n return {\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n }\n }\n return {\n result: BigInt(response.balance),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,aAA6C,OACxD,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW,EAC1D,OAAO,QACR,CAAC;CACF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AACF,KAAI,SAAS,MACX,QAAO,EACL,OAAO;EACL,MAAMC,qCAAAA,gBAAgB,SAAS,MAAM;EACrC,SAAS,SAAS;EACnB,EACF;AAEH,QAAO,EACL,QAAQ,OAAO,SAAS,QAAQ,EACjC"}
1
+ {"version":3,"file":"getBalance.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getBalance.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherBalanceResponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl, apiKey },\n { address }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherBalanceResponse\n if (response.error) {\n return {\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n }\n }\n return {\n result: BigInt(response.balance),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,aAA6C,OACxD,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW,EAC1D,OAAO,OACT,CAAC;CACD,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CACD,IAAI,SAAS,OACX,OAAO,EACL,OAAO;EACL,MAAMC,qCAAAA,gBAAgB,SAAS,KAAK;EACpC,SAAS,SAAS;CACpB,EACF;CAEF,OAAO,EACL,QAAQ,OAAO,SAAS,OAAO,EACjC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTransactionFee.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getTransactionFee.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherTransactionReponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl, apiKey },\n { txId }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/txs/${txId}`, {\n token: apiKey,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherTransactionReponse\n\n if (response.error) {\n return {\n error: { code: getRpcErrorCode(response.error), message: response.error },\n }\n }\n\n return {\n result: BigInt(response.fees),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,oBAA2D,OACtE,QACA,EAAE,SAAS,UACX,EAAE,WACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,OAAO,QAAQ,EACrD,OAAO,QACR,CAAC;CAEF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AAEF,KAAI,SAAS,MACX,QAAO,EACL,OAAO;EAAE,MAAMC,qCAAAA,gBAAgB,SAAS,MAAM;EAAE,SAAS,SAAS;EAAO,EAC1E;AAGH,QAAO,EACL,QAAQ,OAAO,SAAS,KAAK,EAC9B"}
1
+ {"version":3,"file":"getTransactionFee.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getTransactionFee.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherTransactionReponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl, apiKey },\n { txId }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/txs/${txId}`, {\n token: apiKey,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherTransactionReponse\n\n if (response.error) {\n return {\n error: { code: getRpcErrorCode(response.error), message: response.error },\n }\n }\n\n return {\n result: BigInt(response.fees),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,oBAA2D,OACtE,QACA,EAAE,SAAS,UACX,EAAE,WACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,OAAO,QAAQ,EACrD,OAAO,OACT,CAAC;CAED,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,IAAI,SAAS,OACX,OAAO,EACL,OAAO;EAAE,MAAMC,qCAAAA,gBAAgB,SAAS,KAAK;EAAG,SAAS,SAAS;CAAM,EAC1E;CAGF,OAAO,EACL,QAAQ,OAAO,SAAS,IAAI,EAC9B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","getRpcErrorCode","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockcypher/getUTXOs.ts"],"sourcesContent":["import { RpcRequestError } from '../../errors/request.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockcypherUTXO,\n BlockcypherUTXOsResponse,\n} from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nconst blockcypherUTXOTransformer = (utxo: BlockcypherUTXO): UTXO => ({\n blockHeight: utxo.block_height,\n isConfirmed: Boolean(utxo.confirmations),\n confirmations: utxo.confirmations,\n value: utxo.value,\n vout: utxo.tx_output_n,\n txId: utxo.tx_hash,\n scriptHex: utxo.script,\n})\n\nconst MAX_API_LIMIT = 2000\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let hasMore = true\n let beforeBlock: number | undefined\n\n while (hasMore) {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n unspentOnly: 'true',\n includeScript: 'true',\n before: beforeBlock,\n limit: MAX_API_LIMIT,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherUTXOsResponse\n\n if (response.error) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n })\n }\n\n if (minValue && minValue > response.final_balance) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: response.final_balance,\n })\n }\n\n if (!response.txrefs || response.txrefs.length === 0) {\n hasMore = false\n continue\n }\n\n const { hasMore: apiHasMore } = response\n\n hasMore = Boolean(apiHasMore)\n beforeBlock = response.txrefs[response.txrefs.length - 1].block_height\n\n yield response.txrefs\n }\n }\n\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const utxoBatch = batch.map(blockcypherUTXOTransformer)\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;AAWA,MAAM,8BAA8B,UAAiC;CACnE,aAAa,KAAK;CAClB,aAAa,QAAQ,KAAK,cAAc;CACxC,eAAe,KAAK;CACpB,OAAO,KAAK;CACZ,MAAM,KAAK;CACX,MAAM,KAAK;CACX,WAAW,KAAK;CACjB;AAED,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,UAAU;EACd,IAAI;AAEJ,SAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW;IAC1D,OAAO;IACP,aAAa;IACb,eAAe;IACf,QAAQ;IACR,OAAO;IACR,CAAC;GACF,MAAM,WAAY,MAAM,OAAO,QAAQ;IACrC,KAAK;IACL,cAAc,EAAE,QAAQ,OAAO;IAChC,CAAC;AAEF,OAAI,SAAS,MACX,OAAM,IAAIC,uBAAAA,gBAAgB;IACxB,KAAK;IACL,MAAM;KACJ,QAAQ;KACR,QAAQ;MACN;MACA;MACD;KACF;IACD,OAAO;KACL,MAAMC,qCAAAA,gBAAgB,SAAS,MAAM;KACrC,SAAS,SAAS;KACnB;IACF,CAAC;AAGJ,OAAI,YAAY,WAAW,SAAS,cAClC,OAAM,IAAIC,oBAAAA,6BAA6B;IACrC;IACA;IACA,SAAS,SAAS;IACnB,CAAC;AAGJ,OAAI,CAAC,SAAS,UAAU,SAAS,OAAO,WAAW,GAAG;AACpD,cAAU;AACV;;GAGF,MAAM,EAAE,SAAS,eAAe;AAEhC,aAAU,QAAQ,WAAW;AAC7B,iBAAc,SAAS,OAAO,SAAS,OAAO,SAAS,GAAG;AAE1D,SAAM,SAAS;;;CAInB,MAAM,QAAgB,EAAE;CACxB,IAAI,aAAa;AAEjB,YAAW,MAAM,SAAS,YAAY,EAAE;EACtC,MAAM,YAAY,MAAM,IAAI,2BAA2B;AACvD,QAAM,KAAK,GAAG,UAAU;AAExB,MAAI,UAAU;AACZ,iBAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,EAAE;AAClE,OAAI,cAAc,SAChB;;;AAKN,QAAO,EAAE,QAAQ,OAAO"}
1
+ {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","getRpcErrorCode","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockcypher/getUTXOs.ts"],"sourcesContent":["import { RpcRequestError } from '../../errors/request.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockcypherUTXO,\n BlockcypherUTXOsResponse,\n} from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nconst blockcypherUTXOTransformer = (utxo: BlockcypherUTXO): UTXO => ({\n blockHeight: utxo.block_height,\n isConfirmed: Boolean(utxo.confirmations),\n confirmations: utxo.confirmations,\n value: utxo.value,\n vout: utxo.tx_output_n,\n txId: utxo.tx_hash,\n scriptHex: utxo.script,\n})\n\nconst MAX_API_LIMIT = 2000\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let hasMore = true\n let beforeBlock: number | undefined\n\n while (hasMore) {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n unspentOnly: 'true',\n includeScript: 'true',\n before: beforeBlock,\n limit: MAX_API_LIMIT,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherUTXOsResponse\n\n if (response.error) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n })\n }\n\n if (minValue && minValue > response.final_balance) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: response.final_balance,\n })\n }\n\n if (!response.txrefs || response.txrefs.length === 0) {\n hasMore = false\n continue\n }\n\n const { hasMore: apiHasMore } = response\n\n hasMore = Boolean(apiHasMore)\n beforeBlock = response.txrefs[response.txrefs.length - 1].block_height\n\n yield response.txrefs\n }\n }\n\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const utxoBatch = batch.map(blockcypherUTXOTransformer)\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;AAWA,MAAM,8BAA8B,UAAiC;CACnE,aAAa,KAAK;CAClB,aAAa,QAAQ,KAAK,aAAa;CACvC,eAAe,KAAK;CACpB,OAAO,KAAK;CACZ,MAAM,KAAK;CACX,MAAM,KAAK;CACX,WAAW,KAAK;AAClB;AAEA,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,UAAU;EACd,IAAI;EAEJ,OAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW;IAC1D,OAAO;IACP,aAAa;IACb,eAAe;IACf,QAAQ;IACR,OAAO;GACT,CAAC;GACD,MAAM,WAAY,MAAM,OAAO,QAAQ;IACrC,KAAK;IACL,cAAc,EAAE,QAAQ,MAAM;GAChC,CAAC;GAED,IAAI,SAAS,OACX,MAAM,IAAIC,uBAAAA,gBAAgB;IACxB,KAAK;IACL,MAAM;KACJ,QAAQ;KACR,QAAQ;MACN;MACA;KACF;IACF;IACA,OAAO;KACL,MAAMC,qCAAAA,gBAAgB,SAAS,KAAK;KACpC,SAAS,SAAS;IACpB;GACF,CAAC;GAGH,IAAI,YAAY,WAAW,SAAS,eAClC,MAAM,IAAIC,oBAAAA,6BAA6B;IACrC;IACA;IACA,SAAS,SAAS;GACpB,CAAC;GAGH,IAAI,CAAC,SAAS,UAAU,SAAS,OAAO,WAAW,GAAG;IACpD,UAAU;IACV;GACF;GAEA,MAAM,EAAE,SAAS,eAAe;GAEhC,UAAU,QAAQ,UAAU;GAC5B,cAAc,SAAS,OAAO,SAAS,OAAO,SAAS,GAAG;GAE1D,MAAM,SAAS;EACjB;CACF;CAEA,MAAM,QAAgB,CAAC;CACvB,IAAI,aAAa;CAEjB,WAAW,MAAM,SAAS,WAAW,GAAG;EACtC,MAAM,YAAY,MAAM,IAAI,0BAA0B;EACtD,MAAM,KAAK,GAAG,SAAS;EAEvB,IAAI,UAAU;GACZ,cAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,CAAC;GACjE,IAAI,cAAc,UAChB;EAEJ;CACF;CAEA,OAAO,EAAE,QAAQ,MAAM;AACzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockcypher/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\n\nexport const blockcypherMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n}\n"],"mappings":";;;;;AAKA,MAAa,qBAAiC;CAC5C,YAAA,0CAAA;CACA,UAAA,wCAAA;CACA,mBAAA,iDAAA;CACD"}
1
+ {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockcypher/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\n\nexport const blockcypherMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n}\n"],"mappings":";;;;;AAKA,MAAa,qBAAiC;CAC5C,YAAA,0CAAA;CACA,UAAA,wCAAA;CACA,mBAAA,iDAAA;AACF"}
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  //#region src/transports/blockcypher/utils.ts
4
4
  function getRpcErrorCode(error) {
5
- if (error.toLowerCase().startsWith("rate limit exceeded")) return require_errors_rpc.RpcErrorCode.ACCESS_DENIED;
6
- return require_errors_rpc.RpcErrorCode.MISC_ERROR;
5
+ if (error.toLowerCase().startsWith("rate limit exceeded")) return -32002;
6
+ return -1;
7
7
  }
8
8
  //#endregion
9
9
  exports.getRpcErrorCode = getRpcErrorCode;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["RpcErrorCode"],"sources":["../../../../src/transports/blockcypher/utils.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\n\nexport function getRpcErrorCode(error: string): RpcErrorCode {\n if (error.toLowerCase().startsWith('rate limit exceeded')) {\n return RpcErrorCode.ACCESS_DENIED\n }\n return RpcErrorCode.MISC_ERROR\n}\n"],"mappings":";;;AAEA,SAAgB,gBAAgB,OAA6B;AAC3D,KAAI,MAAM,aAAa,CAAC,WAAW,sBAAsB,CACvD,QAAOA,mBAAAA,aAAa;AAEtB,QAAOA,mBAAAA,aAAa"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/transports/blockcypher/utils.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\n\nexport function getRpcErrorCode(error: string): RpcErrorCode {\n if (error.toLowerCase().startsWith('rate limit exceeded')) {\n return RpcErrorCode.ACCESS_DENIED\n }\n return RpcErrorCode.MISC_ERROR\n}\n"],"mappings":";;;AAEA,SAAgB,gBAAgB,OAA6B;CAC3D,IAAI,MAAM,YAAY,EAAE,WAAW,qBAAqB,GACtD,OAAA;CAEF,OAAA;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","names":["createTransport"],"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,EAAE,EACjB;CACjB,MAAM,EACJ,MAAM,UACN,SACA,OAAO,mBACP,eACE;AACJ,SAAQ,EAAE,YAAY,wBACpBA,kCAAAA,gBAAgB;EACd;EACA;EACA;EACA,SAAS,SAAS,QAAQ,KAAK,SAAS;EACxC,YAAY,OAAO,cAAc;EACjC;EACA,MAAM;EACP,CAAC"}
1
+ {"version":3,"file":"custom.js","names":["createTransport"],"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,wBACpBA,kCAAAA,gBAAgB;EACd;EACA;EACA;EACA,SAAS,SAAS,QAAQ,KAAK,QAAQ;EACvC,YAAY,OAAO,cAAc;EACjC;EACA,MAAM;CACR,CAAC;AACL"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_wait = require("../utils/wait.js");
3
- const require_errors_rpc = require("../errors/rpc.js");
3
+ require("../errors/rpc.js");
4
4
  const require_errors_transport = require("../errors/transport.js");
5
5
  const require_errors_utxo = require("../errors/utxo.js");
6
6
  const require_factories_createTransport = require("../factories/createTransport.js");
@@ -108,7 +108,7 @@ function fallback(transports_, config = {}) {
108
108
  function shouldThrow(error) {
109
109
  if (error instanceof require_errors_utxo.InsufficientUTXOBalanceError) return true;
110
110
  if ("code" in error && typeof error.code === "number") {
111
- if (error.code === require_errors_rpc.RpcErrorCode.INTERNAL_ERROR || error.code === require_errors_rpc.RpcErrorCode.USER_REJECTION || error.code === 5e3) return true;
111
+ if (error.code === -32603 || error.code === -32e3 || error.code === 5e3) return true;
112
112
  }
113
113
  return false;
114
114
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fallback.js","names":["createTransport","TransportMethodNotSupportedError","AllTransportsFailedError","InsufficientUTXOBalanceError","RpcErrorCode","wait"],"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":"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"}
1
+ {"version":3,"file":"fallback.js","names":["createTransport","TransportMethodNotSupportedError","AllTransportsFailedError","InsufficientUTXOBalanceError","wait"],"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,YAAYA,kCAAAA,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,IAAIC,yBAAAA,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;OACA;OACA,QAAQ;MACV,CAAC;MAED,OAAO;KACT,SAAS,KAAK;MACZ,WAAW;OACT,OAAO;OACP;OACQ;OACR;OACA,QAAQ;MACV,CAAC;MAED,IAAI,aAAa,GAAY,GAC3B,MAAM;MAGR,gBAAgB,KAAK;OACnB,WAAW,UAAU,OAAO;OAC5B,OAAO;OACP,SAAS,IAAI;MACf,CAAC;MAGD,IAAI,MAAM,oBAAoB,SAAS,GACrC,MAAM,IAAIC,yBAAAA,yBAAyB;OACjC;OACA;OACA,QAAQ;OACR,eAAe,IAAI;MACrB,CAAC;MAIH,OAAO,MAAM,IAAI,CAAC;KACpB;IACF;IACA,OAAO,MAAM;GACf;GACA;GACA;GACA,MAAM;EACR,GACA;GACE,aAAa,OAAqB;IAChC,aAAa;GACf;GACA,YAAY,WAAW,KAAK,OAAO,GAAG;IAAE;IAAO,YAAY;GAAE,CAAC,CAAC;EACjE,CACF;EAEA,IAAI,MAAM;GACR,MAAM,cAAe,OAAO,SAAS,WAAW,OAAO,CAAC;GACxD,eAAe;IACb;IACA,UAAU,YAAY,YAAY;IAClC,eAAe,gBAAgB;KAC7B,aAAa;IACf;IACA,MAAM,YAAY;IAClB,aAAa,YAAY;IACzB,SAAS,YAAY;IACrB;IACA,SAAS,YAAY;GACvB,CAAC;EACH;EACA,OAAO;CACT;AACF;AAEA,SAAgB,YAAY,OAAuB;CACjD,IAAI,iBAAiBC,oBAAAA,8BACnB,OAAO;CAGT,IAAI,UAAU,SAAS,OAAO,MAAM,SAAS;MAEzC,MAAM,SAAA,UACN,MAAM,SAAA,SACN,MAAM,SAAS,KAEf,OAAO;CAAA;CAIX,OAAO;AACT;;AAGA,SAAgB,eAAe,EAC7B,OACA,WAAW,KACX,cACA,MACA,cAAc,IACd,UAAU,KACV,YACA,UAAU,CAAC,KAUJ;CACP,MAAM,EAAE,WAAW,kBAAkB,IAAK,SAAS,gBAAgB,OACjE;CAIF,MAAM,UAAoB,CAAC;CAE3B,MAAM,kBAAkB,YAAY;EAElC,MAAM,SAAiB,MAAM,QAAQ,IACnC,WAAW,IAAI,OAAO,cAAc;GAClC,MAAM,aAAa,UAAU;IAAE;IAAO,YAAY;IAAG;GAAQ,CAAC;GAE9D,MAAM,QAAQ,KAAK,IAAI;GACvB,IAAI;GACJ,IAAI;GACJ,IAAI;IACF,OAAO,OACH,KAAK,EAAE,WAAW,WAAW,CAAC,IAC9B,WAAW,QAAQ;KACjB,QAAQ;KACR,QAAQ,KAAA;IACV,CAAC;IACL,UAAU;GACZ,QAAQ;IACN,UAAU;GACZ,UAAU;IACR,MAAM,KAAK,IAAI;GACjB;GAEA,OAAO;IAAE,SADO,MAAM;IACJ;GAAQ;EAC5B,CAAC,CACH;EAIA,QAAQ,KAAK,MAAM;EACnB,IAAI,QAAQ,SAAS,aACnB,QAAQ,MAAM;EAIhB,MAAM,aAAa,KAAK,IACtB,GAAG,QAAQ,KAAK,WACd,KAAK,IAAI,GAAG,OAAO,KAAK,EAAE,cAAc,OAAO,CAAC,CAClD,CACF;EA2BA,aAxBe,WACZ,KAAK,GAAG,MAAM;GACb,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,GAAG,OAAO;GAI3D,MAAM,eAAe,IAFnB,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IACnD,UAAU,SAC2B;GAEvC,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,GAAG,OAAO;GAC3D,MAAM,iBACJ,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IACnD,UAAU;GAEZ,IAAI,mBAAmB,GACrB,OAAO,CAAC,GAAG,CAAC;GAEd,OAAO,CACL,gBAAgB,eAAe,kBAAkB,gBACjD,CACF;EACF,CAAC,EACA,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,EAGT,EAAE,KAAK,GAAG,OAAO,WAAW,EAAE,CAAC;EAGjD,MAAMC,mBAAAA,KAAK,QAAQ;EACnB,gBAAgB;CAClB;CACA,gBAAgB;AAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"getHttpRpcClient.js","names":["withTimeout","idCache","stringify","TimeoutError","HttpRequestError"],"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,EAAE,EACnB;AACf,QAAO,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,EAAE;GAC9B,GAAI,OAAO,gBAAgB,EAAE;GAC9B;EAED,MAAM,EAAE,SAAS,QAAQ,QAAQ,YAAY;AAE7C,MAAI;GACF,MAAM,WAAW,MAAMA,0BAAAA,YACrB,OAAO,EAAE,aAAa;IACpB,MAAM,eAAe,OACjB,MAAM,QAAQ,KAAK,GACjB,KAAK,KAAK,OAAO;KACf,SAAS;KACT,IAAI,EAAE,MAAMC,sBAAAA,QAAQ,MAAM;KAC1B,GAAG;KACJ,EAAE,GACH;KACE,SAAS;KACT,IAAI,KAAK,MAAMA,sBAAAA,QAAQ,MAAM;KAC7B,GAAG;KACJ,GACH,KAAA;IACJ,MAAM,OAAoB;KACxB,GAAG;KACH,MAAM,eAAeC,wBAAAA,UAAU,aAAa,GAAG,KAAA;KAC/C,SAAS;MACP,GAAI,WAAW,QACX,EAAE,gBAAgB,oBAAoB,GACtC,KAAA;MACJ,GAAG;MACJ;KACD,QAAQ,UAAU;KAClB,QAAQ,YAAY,UAAU,IAAI,SAAS;KAC5C;IACD,MAAM,UAAU,IAAI,QAAQ,OAAO,OAAO,KAAK,KAAK;AACpD,QAAI,UACF,OAAM,UAAU,SAAS,KAAK;AAGhC,WADiB,MAAM,MAAM,OAAO,OAAO,KAAK,KAAK;MAGvD;IACE,eAAe,IAAIC,uBAAAA,aAAa;KAC9B,MAAM,QAAQ,EAAE;KAChB,KAAK,OAAO,OAAO;KACnB;KACD,CAAC;IACF;IACA,QAAQ;IACT,CACF;AAED,OAAI,WACF,OAAM,WAAW,SAAS;GAG5B,IAAI;AACJ,OACE,SAAS,QAAQ,IAAI,eAAe,EAAE,WAAW,mBAAmB,CAEpE,QAAO,MAAM,SAAS,MAAM;QACvB;AACL,WAAO,MAAM,SAAS,MAAM;AAC5B,WAAO,KAAK,MAAM,QAAQ,KAAK;;AAGjC,OAAI,CAAC,SAAS,GACZ,OAAM,IAAIC,uBAAAA,iBAAiB;IACzB;IACA,SAASF,wBAAAA,UAAU,KAAK,MAAM,IAAI,SAAS;IAC3C,SAAS,SAAS;IAClB,QAAQ,SAAS;IACjB;IACD,CAAC;AAEJ,UAAO;WACA,KAAK;AACZ,OAAI,eAAeE,uBAAAA,iBACjB,OAAM;AAER,OAAI,eAAeD,uBAAAA,aACjB,OAAM;AAER,SAAM,IAAIC,uBAAAA,iBAAiB;IACzB;IACA,OAAO;IACP;IACD,CAAC;;IAGP"}
1
+ {"version":3,"file":"getHttpRpcClient.js","names":["withTimeout","idCache","stringify","TimeoutError","HttpRequestError"],"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;EAE7C,IAAI;GACF,MAAM,WAAW,MAAMA,0BAAAA,YACrB,OAAO,EAAE,aAAa;IACpB,MAAM,eAAe,OACjB,MAAM,QAAQ,IAAI,IAChB,KAAK,KAAK,OAAO;KACf,SAAS;KACT,IAAI,EAAE,MAAMC,sBAAAA,QAAQ,KAAK;KACzB,GAAG;IACL,EAAE,IACF;KACE,SAAS;KACT,IAAI,KAAK,MAAMA,sBAAAA,QAAQ,KAAK;KAC5B,GAAG;IACL,IACF,KAAA;IACJ,MAAM,OAAoB;KACxB,GAAG;KACH,MAAM,eAAeC,wBAAAA,UAAU,YAAY,IAAI,KAAA;KAC/C,SAAS;MACP,GAAI,WAAW,QACX,EAAE,gBAAgB,mBAAmB,IACrC,KAAA;MACJ,GAAG;KACL;KACA,QAAQ,UAAU;KAClB,QAAQ,YAAY,UAAU,IAAI,SAAS;IAC7C;IACA,MAAM,UAAU,IAAI,QAAQ,OAAO,OAAO,KAAK,IAAI;IACnD,IAAI,WACF,MAAM,UAAU,SAAS,IAAI;IAG/B,OAAO,MADgB,MAAM,OAAO,OAAO,KAAK,IAAI;GAEtD,GACA;IACE,eAAe,IAAIC,uBAAAA,aAAa;KAC9B,MAAM,QAAQ,CAAC;KACf,KAAK,OAAO,OAAO;KACnB;IACF,CAAC;IACD;IACA,QAAQ;GACV,CACF;GAEA,IAAI,YACF,MAAM,WAAW,QAAQ;GAG3B,IAAI;GACJ,IACE,SAAS,QAAQ,IAAI,cAAc,GAAG,WAAW,kBAAkB,GAEnE,OAAO,MAAM,SAAS,KAAK;QACtB;IACL,OAAO,MAAM,SAAS,KAAK;IAC3B,OAAO,KAAK,MAAM,QAAQ,IAAI;GAChC;GAEA,IAAI,CAAC,SAAS,IACZ,MAAM,IAAIC,uBAAAA,iBAAiB;IACzB;IACA,SAASF,wBAAAA,UAAU,KAAK,KAAK,KAAK,SAAS;IAC3C,SAAS,SAAS;IAClB,QAAQ,SAAS;IACjB;GACF,CAAC;GAEH,OAAO;EACT,SAAS,KAAK;GACZ,IAAI,eAAeE,uBAAAA,kBACjB,MAAM;GAER,IAAI,eAAeD,uBAAAA,cACjB,MAAM;GAER,MAAM,IAAIC,uBAAAA,iBAAiB;IACzB;IACA,OAAO;IACP;GACF,CAAC;EACH;CACF,EACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getRpcProviderMethods.js","names":["blockchairMethods","ankrMethods","blockcypherMethods","mempoolMethods"],"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;AACvE,SAAQ,KAAR;EACE,KAAK,aACH,QAAOA,sCAAAA;EACT,KAAK,OACH,QAAOC,gCAAAA;EACT,KAAK,cACH,QAAOC,uCAAAA;EACT,KAAK,UACH,QAAOC,mCAAAA;EACT,QACE,QAAO"}
1
+ {"version":3,"file":"getRpcProviderMethods.js","names":["blockchairMethods","ankrMethods","blockcypherMethods","mempoolMethods"],"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,OAAOA,sCAAAA;EACT,KAAK,QACH,OAAOC,gCAAAA;EACT,KAAK,eACH,OAAOC,uCAAAA;EACT,KAAK,WACH,OAAOC,mCAAAA;EACT,SACE,OAAO;CACX;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","names":["UTXOAPISchemaMethods","UrlRequiredError","getHttpRpcClient","createTransport","idCache","createBatchScheduler","RpcRequestError"],"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,EAAE,EACjB;CAC/B,MAAM,EACJ,OACA,cACA,MAAM,QACN,UAAU,EAAE,SAASA,yBAAAA,sBAAsB,EAC3C,OAAO,iBACP,gBACA,iBACA,YACA,QACE;AACJ,SAAQ,EAAE,OAAO,YAAY,aAAa,SAAS,eAAe;EAChE,MAAM,EAAE,YAAY,KAAM,OAAO,MAC/B,OAAO,UAAU,WAAW,QAAQ,EAAE;EACxC,MAAM,aAAa,OAAO,cAAc;EACxC,MAAM,UAAU,YAAY,OAAO,WAAW;EAC9C,MAAM,OAAO,OAAO,OAAO,QAAQ,QAAQ,KAAK;AAChD,MAAI,CAAC,KACH,OAAM,IAAIC,yBAAAA,kBAAkB;EAG9B,MAAM,YAAYC,oCAAAA,iBAAiB,MAAM;GACvC;GACA,WAAW;GACX,YAAY;GACZ;GACD,CAAC;AAEF,SAAOC,kCAAAA,gBACL;GACE;GACA;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,UAAU;IAChC,MAAM,OAAO;KACX,SAAS;KACT,IAAIC,sBAAAA,QAAQ,MAAM;KAClB;KACA;KACD;IAED,MAAM,EAAE,aAAaC,mCAAAA,qBAAqB;KACxC,IAAI;KACJ;KACA,iBAAiB,UAAU;AACzB,aAAO,SAAS,SAAS;;KAE3B,KAAK,SACH,UAAU,QAAQ,EAChB,MACD,CAAC;KACJ,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE;KAC1B,CAAC;IAEF,MAAM,KAAK,OAAO,SAChB,QACI,SAAS,KAAK,GACd,CACE,MAAM,UAAU,QAAQ,EACtB,MACD,CAAC,CACH;IAEP,MAAM,CAAC,EAAE,OAAO,YAAY,MAAM,GAAG,KAAK;AAE1C,QAAI,IACF,QAAO;KAAE;KAAO;KAAQ;AAE1B,QAAI,MACF,OAAM,IAAIC,uBAAAA,gBAAgB;KACxB;KACA;KACA,KAAK;KACN,CAAC;AAEJ,WAAO;;GAET;GACA;GACA;GACA,MAAM;GACP,EACD;GACE;GACA,KAAK;GACN,CACF"}
1
+ {"version":3,"file":"http.js","names":["UTXOAPISchemaMethods","UrlRequiredError","getHttpRpcClient","createTransport","idCache","createBatchScheduler","RpcRequestError"],"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,SAASA,yBAAAA,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,IAAIC,yBAAAA,iBAAiB;EAG7B,MAAM,YAAYC,oCAAAA,iBAAiB,MAAM;GACvC;GACA,WAAW;GACX,YAAY;GACZ;EACF,CAAC;EAED,OAAOC,kCAAAA,gBACL;GACE;GACA;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,UAAU;IAChC,MAAM,OAAO;KACX,SAAS;KACT,IAAIC,sBAAAA,QAAQ,KAAK;KACjB;KACA;IACF;IAEA,MAAM,EAAE,aAAaC,mCAAAA,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,IAAIC,uBAAAA,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,OAAO;EAChC,CAAC;CACF,MAAM,UACJ,SAAS,YAAY,iBAAiB,SAAS,YAAY;AAC7D,QAAO,EACL,QAAQ,OAAO,QAAQ,EACxB"}
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,OAAO;EAChC,CAAC;AAEF,QAAO,EACL,QAAQ,OAAO,SAAS,IAAI,EAC7B"}
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":["urlWithParams","mempoolTransactionTransformer"],"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,OAAO;EAChC,CAAC;CACF,MAAM,YACJ,gBAAgB,YAAY,WAC5B,gBAAgB,cAAc;CAEhC,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,WAAW,QAAQ,OAAO,EAChE,YAAY,WACb,CAAC;CAOF,MAAM,gBALY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC,EAE4B,IAAIC,iCAAAA,8BAA8B;AAShE,QAAO,EACL,QARa;EACb;EACA,OAAO;EACP,cAAc;EACd,SAAS,SAAS,aAAa,SAAS;EACzC,EAIA"}
1
+ {"version":3,"file":"getTransactions.js","names":["urlWithParams","mempoolTransactionTransformer"],"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,SAASA,kBAAAA,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,IAAIC,iCAAAA,6BAA6B;CAS/D,OAAO,EACL,QAAA;EAPA;EACA,OAAO;EACP,cAAc;EACd,SAAS,SAAS,aAAa,SAAS;CAInC,EACP;AACF"}