@ckb-ccc/core 0.0.5-alpha.8 → 0.0.7-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/dist/address/address.advanced.d.ts.map +1 -1
  2. package/dist/address/address.advanced.js +2 -5
  3. package/dist/address/index.d.ts +1 -1
  4. package/dist/address/index.d.ts.map +1 -1
  5. package/dist/address/index.js +2 -5
  6. package/dist/ckb/script.d.ts +43 -1
  7. package/dist/ckb/script.d.ts.map +1 -1
  8. package/dist/ckb/script.js +51 -0
  9. package/dist/ckb/transaction.d.ts +215 -27
  10. package/dist/ckb/transaction.d.ts.map +1 -1
  11. package/dist/ckb/transaction.js +472 -32
  12. package/dist/client/advanced.d.ts +2 -0
  13. package/dist/client/advanced.d.ts.map +1 -1
  14. package/dist/client/advanced.js +2 -0
  15. package/dist/client/client.advanced.d.ts +10 -0
  16. package/dist/client/client.advanced.d.ts.map +1 -0
  17. package/dist/client/client.advanced.js +80 -0
  18. package/dist/client/client.d.ts +50 -13
  19. package/dist/client/client.d.ts.map +1 -1
  20. package/dist/client/client.js +145 -15
  21. package/dist/client/clientPublicMainnet.advanced.d.ts +4 -2
  22. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  23. package/dist/client/clientPublicMainnet.advanced.js +103 -0
  24. package/dist/client/clientPublicMainnet.d.ts +4 -2
  25. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  26. package/dist/client/clientPublicMainnet.js +9 -1
  27. package/dist/client/clientPublicTestnet.advanced.d.ts +4 -2
  28. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  29. package/dist/client/clientPublicTestnet.advanced.js +155 -0
  30. package/dist/client/clientPublicTestnet.d.ts +4 -2
  31. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  32. package/dist/client/clientPublicTestnet.js +6 -1
  33. package/dist/client/clientTypes.advanced.d.ts +23 -0
  34. package/dist/client/clientTypes.advanced.d.ts.map +1 -0
  35. package/dist/client/clientTypes.advanced.js +4 -0
  36. package/dist/client/clientTypes.d.ts +22 -36
  37. package/dist/client/clientTypes.d.ts.map +1 -1
  38. package/dist/client/clientTypes.js +15 -12
  39. package/dist/client/jsonRpc/index.d.ts +3 -3
  40. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  41. package/dist/client/jsonRpc/index.js +3 -3
  42. package/dist/client/jsonRpc/transformers.d.ts +5 -7
  43. package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
  44. package/dist/client/jsonRpc/transformers.js +8 -6
  45. package/dist/hasher/index.d.ts +1 -1
  46. package/dist/hasher/index.d.ts.map +1 -1
  47. package/dist/hasher/index.js +4 -2
  48. package/dist/num/index.d.ts +12 -0
  49. package/dist/num/index.d.ts.map +1 -1
  50. package/dist/num/index.js +21 -0
  51. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  52. package/dist/signer/btc/signerBtc.js +6 -3
  53. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
  54. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  55. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
  56. package/dist/signer/btc/verify.d.ts.map +1 -1
  57. package/dist/signer/btc/verify.js +5 -2
  58. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +0 -6
  59. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  60. package/dist/signer/ckb/signerCkbScriptReadonly.js +0 -8
  61. package/dist/signer/dummy/alwaysError.d.ts +0 -1
  62. package/dist/signer/dummy/alwaysError.d.ts.map +1 -1
  63. package/dist/signer/dummy/alwaysError.js +0 -3
  64. package/dist/signer/dummy/openLink.d.ts +0 -1
  65. package/dist/signer/dummy/openLink.d.ts.map +1 -1
  66. package/dist/signer/dummy/openLink.js +0 -3
  67. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  68. package/dist/signer/evm/signerEvm.js +7 -5
  69. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  70. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  71. package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
  72. package/dist/signer/index.d.ts +1 -0
  73. package/dist/signer/index.d.ts.map +1 -1
  74. package/dist/signer/index.js +1 -0
  75. package/dist/signer/nostr/index.d.ts +2 -0
  76. package/dist/signer/nostr/index.d.ts.map +1 -0
  77. package/dist/signer/nostr/index.js +1 -0
  78. package/dist/signer/nostr/signerNostr.d.ts +66 -0
  79. package/dist/signer/nostr/signerNostr.d.ts.map +1 -0
  80. package/dist/signer/nostr/signerNostr.js +85 -0
  81. package/dist/signer/nostr/verify.d.ts +5 -0
  82. package/dist/signer/nostr/verify.d.ts.map +1 -0
  83. package/dist/signer/nostr/verify.js +48 -0
  84. package/dist/signer/signer/index.d.ts +7 -12
  85. package/dist/signer/signer/index.d.ts.map +1 -1
  86. package/dist/signer/signer/index.js +11 -4
  87. package/dist/utils/index.d.ts +59 -0
  88. package/dist/utils/index.d.ts.map +1 -1
  89. package/dist/utils/index.js +17 -0
  90. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  91. package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
  92. package/dist.commonjs/address/address.advanced.js +115 -92
  93. package/dist.commonjs/address/advanced.d.ts +1 -1
  94. package/dist.commonjs/address/advanced.js +30 -14
  95. package/dist.commonjs/address/index.d.ts +51 -44
  96. package/dist.commonjs/address/index.d.ts.map +1 -1
  97. package/dist.commonjs/address/index.js +84 -68
  98. package/dist.commonjs/advanced.d.ts +1 -1
  99. package/dist.commonjs/advanced.js +47 -22
  100. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  101. package/dist.commonjs/advancedBarrel.js +30 -14
  102. package/dist.commonjs/barrel.d.ts +1 -1
  103. package/dist.commonjs/barrel.js +30 -14
  104. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  105. package/dist.commonjs/bytes/index.d.ts +9 -3
  106. package/dist.commonjs/bytes/index.js +28 -26
  107. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  108. package/dist.commonjs/ckb/advanced.js +47 -22
  109. package/dist.commonjs/ckb/index.d.ts +1 -1
  110. package/dist.commonjs/ckb/index.js +30 -14
  111. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  112. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  113. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  114. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  115. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  116. package/dist.commonjs/ckb/script.advanced.js +12 -9
  117. package/dist.commonjs/ckb/script.d.ts +123 -77
  118. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  119. package/dist.commonjs/ckb/script.js +221 -126
  120. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  121. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  122. package/dist.commonjs/ckb/transaction.d.ts +796 -533
  123. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  124. package/dist.commonjs/ckb/transaction.js +1372 -702
  125. package/dist.commonjs/client/advanced.d.ts +3 -1
  126. package/dist.commonjs/client/advanced.d.ts.map +1 -1
  127. package/dist.commonjs/client/advanced.js +32 -14
  128. package/dist.commonjs/client/client.advanced.d.ts +27 -0
  129. package/dist.commonjs/client/client.advanced.d.ts.map +1 -0
  130. package/dist.commonjs/client/client.advanced.js +116 -0
  131. package/dist.commonjs/client/client.d.ts +118 -21
  132. package/dist.commonjs/client/client.d.ts.map +1 -1
  133. package/dist.commonjs/client/client.js +219 -55
  134. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +9 -3
  135. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  136. package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -24
  137. package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -5
  138. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  139. package/dist.commonjs/client/clientPublicMainnet.js +18 -8
  140. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +8 -3
  141. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  142. package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -24
  143. package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -5
  144. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  145. package/dist.commonjs/client/clientPublicTestnet.js +14 -9
  146. package/dist.commonjs/client/clientTypes.advanced.d.ts +23 -0
  147. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -0
  148. package/dist.commonjs/client/clientTypes.advanced.js +8 -0
  149. package/dist.commonjs/client/clientTypes.d.ts +57 -46
  150. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  151. package/dist.commonjs/client/clientTypes.js +60 -22
  152. package/dist.commonjs/client/index.d.ts +1 -1
  153. package/dist.commonjs/client/index.js +30 -14
  154. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  155. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  156. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  157. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  158. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  159. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -38
  160. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
  161. package/dist.commonjs/client/jsonRpc/transformers.js +174 -150
  162. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  163. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  164. package/dist.commonjs/fixedPoint/index.js +26 -20
  165. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  166. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  167. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  168. package/dist.commonjs/hasher/index.d.ts +37 -37
  169. package/dist.commonjs/hasher/index.d.ts.map +1 -1
  170. package/dist.commonjs/hasher/index.js +55 -46
  171. package/dist.commonjs/hex/index.d.ts +1 -1
  172. package/dist.commonjs/hex/index.js +1 -1
  173. package/dist.commonjs/index.d.ts +1 -1
  174. package/dist.commonjs/index.js +47 -22
  175. package/dist.commonjs/num/index.d.ts +13 -1
  176. package/dist.commonjs/num/index.d.ts.map +1 -1
  177. package/dist.commonjs/num/index.js +53 -19
  178. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  179. package/dist.commonjs/signer/btc/index.js +30 -14
  180. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  181. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  182. package/dist.commonjs/signer/btc/signerBtc.js +89 -63
  183. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -51
  184. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  185. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -60
  186. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  187. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  188. package/dist.commonjs/signer/btc/verify.js +13 -3
  189. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  190. package/dist.commonjs/signer/ckb/index.js +30 -14
  191. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -51
  192. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  193. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -64
  194. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  195. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  196. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -5
  197. package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -1
  198. package/dist.commonjs/signer/dummy/alwaysError.js +7 -10
  199. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  200. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  201. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  202. package/dist.commonjs/signer/dummy/index.js +30 -14
  203. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -5
  204. package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -1
  205. package/dist.commonjs/signer/dummy/openLink.js +7 -10
  206. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  207. package/dist.commonjs/signer/evm/index.js +30 -14
  208. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  209. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  210. package/dist.commonjs/signer/evm/signerEvm.js +106 -69
  211. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -43
  212. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  213. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -50
  214. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  215. package/dist.commonjs/signer/evm/verify.js +7 -2
  216. package/dist.commonjs/signer/index.d.ts +2 -1
  217. package/dist.commonjs/signer/index.d.ts.map +1 -1
  218. package/dist.commonjs/signer/index.js +31 -14
  219. package/dist.commonjs/signer/nostr/index.d.ts +2 -0
  220. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -0
  221. package/dist.commonjs/signer/nostr/index.js +33 -0
  222. package/dist.commonjs/signer/nostr/signerNostr.d.ts +66 -0
  223. package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -0
  224. package/dist.commonjs/signer/nostr/signerNostr.js +118 -0
  225. package/dist.commonjs/signer/nostr/verify.d.ts +11 -0
  226. package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -0
  227. package/dist.commonjs/signer/nostr/verify.js +64 -0
  228. package/dist.commonjs/signer/signer/index.d.ts +156 -155
  229. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  230. package/dist.commonjs/signer/signer/index.js +209 -175
  231. package/dist.commonjs/utils/index.d.ts +95 -6
  232. package/dist.commonjs/utils/index.d.ts.map +1 -1
  233. package/dist.commonjs/utils/index.js +30 -6
  234. package/package.json +4 -3
  235. package/src/address/address.advanced.ts +2 -5
  236. package/src/address/index.ts +2 -5
  237. package/src/ckb/script.ts +62 -2
  238. package/src/ckb/transaction.ts +678 -58
  239. package/src/client/advanced.ts +2 -0
  240. package/src/client/client.advanced.ts +134 -0
  241. package/src/client/client.ts +236 -25
  242. package/src/client/clientPublicMainnet.advanced.ts +117 -2
  243. package/src/client/clientPublicMainnet.ts +14 -3
  244. package/src/client/clientPublicTestnet.advanced.ts +176 -2
  245. package/src/client/clientPublicTestnet.ts +9 -3
  246. package/src/client/clientTypes.advanced.ts +26 -0
  247. package/src/client/clientTypes.ts +41 -43
  248. package/src/client/jsonRpc/index.ts +4 -4
  249. package/src/client/jsonRpc/transformers.ts +13 -11
  250. package/src/hasher/index.ts +4 -2
  251. package/src/num/index.ts +22 -0
  252. package/src/signer/btc/signerBtc.ts +6 -8
  253. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
  254. package/src/signer/btc/verify.ts +6 -3
  255. package/src/signer/ckb/signerCkbScriptReadonly.ts +0 -9
  256. package/src/signer/dummy/alwaysError.ts +0 -4
  257. package/src/signer/dummy/openLink.ts +0 -4
  258. package/src/signer/evm/signerEvm.ts +11 -11
  259. package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
  260. package/src/signer/index.ts +1 -0
  261. package/src/signer/nostr/index.ts +1 -0
  262. package/src/signer/nostr/signerNostr.ts +135 -0
  263. package/src/signer/nostr/verify.ts +63 -0
  264. package/src/signer/signer/index.ts +15 -11
  265. package/src/utils/index.ts +108 -0
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  exports.ClientJsonRpc = void 0;
7
9
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
@@ -23,130 +25,155 @@ const advanced_1 = require("./advanced");
23
25
  * ```
24
26
  */
25
27
  async function transform(value, transformer) {
26
- if (transformer) {
27
- return transformer(value);
28
- }
29
- return value;
28
+ if (transformer) {
29
+ return transformer(value);
30
+ }
31
+ return value;
30
32
  }
31
33
  /**
32
34
  * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
33
35
  * Provides methods for sending transactions and building JSON-RPC payloads.
34
36
  */
35
37
  class ClientJsonRpc extends client_1.Client {
38
+ /**
39
+ * Creates an instance of ClientJsonRpc.
40
+ *
41
+ * @param url - The URL of the JSON-RPC server.
42
+ * @param timeout - The timeout for requests in milliseconds, default is 30000.
43
+ */
44
+ constructor(url_, timeout = 30000) {
45
+ super();
46
+ this.url_ = url_;
47
+ this.timeout = timeout;
36
48
  /**
37
- * Creates an instance of ClientJsonRpc.
49
+ * Send a transaction to node.
38
50
  *
39
- * @param url - The URL of the JSON-RPC server.
40
- * @param timeout - The timeout for requests in milliseconds, default is 30000.
51
+ * @param transaction - The transaction to send.
52
+ * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
53
+ * @returns Transaction hash.
41
54
  */
42
- constructor(url_, timeout = 30000) {
43
- super();
44
- this.url_ = url_;
45
- this.timeout = timeout;
46
- /**
47
- * Send a transaction to node.
48
- *
49
- * @param transaction - The transaction to send.
50
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
51
- * @returns Transaction hash.
52
- */
53
- this.sendTransaction = this.buildSender("send_transaction", [advanced_1.JsonRpcTransformers.transactionFrom], hex_1.hexFrom);
54
- /**
55
- * Get a transaction from node.
56
- *
57
- * @param txHash - The hash of the transaction.
58
- * @returns The transaction with status.
59
- */
60
- this.getTransaction = this.buildSender("get_transaction", [hex_1.hexFrom], advanced_1.JsonRpcTransformers.transactionResponseTo);
61
- /**
62
- * find cells from node.
63
- *
64
- * @param key - The search key of cells.
65
- * @param order - The order of cells.
66
- * @param limit - The max return size of cells.
67
- * @param after - Pagination parameter.
68
- * @returns The found cells.
69
- */
70
- this.findCellsPaged = this.buildSender("get_cells", [
71
- advanced_1.JsonRpcTransformers.indexerSearchKeyFrom,
72
- (order) => order ?? "asc",
73
- (limit) => (0, num_1.numToHex)(limit ?? 10),
74
- ], advanced_1.JsonRpcTransformers.findCellsResponseTo);
75
- /**
76
- * get cells capacity from node.
77
- *
78
- * @param key - The search key of cells.
79
- * @returns The sum of cells capacity.
80
- */
81
- this.getCellsCapacity = this.buildSender("get_cells_capacity", [advanced_1.JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => (0, num_1.numFrom)(capacity));
82
- }
55
+ this.sendTransactionNoCache = this.buildSender(
56
+ "send_transaction",
57
+ [advanced_1.JsonRpcTransformers.transactionFrom],
58
+ hex_1.hexFrom,
59
+ );
83
60
  /**
84
- * Returns the URL of the JSON-RPC server.
61
+ * Get a transaction from node.
85
62
  *
86
- * @returns The URL of the JSON-RPC server.
63
+ * @param txHash - The hash of the transaction.
64
+ * @returns The transaction with status.
87
65
  */
88
- get url() {
89
- return this.url_;
90
- }
66
+ this.getTransactionNoCache = this.buildSender(
67
+ "get_transaction",
68
+ [hex_1.hexFrom],
69
+ advanced_1.JsonRpcTransformers.transactionResponseTo,
70
+ );
91
71
  /**
92
- * Builds a sender function for a JSON-RPC method.
72
+ * find cells from node.
93
73
  *
94
- * @param rpcMethod - The JSON-RPC method.
95
- * @param inTransformers - An array of input transformers.
96
- * @param outTransformer - An output transformer function.
97
- * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
74
+ * @param key - The search key of cells.
75
+ * @param order - The order of cells.
76
+ * @param limit - The max return size of cells.
77
+ * @param after - Pagination parameter.
78
+ * @returns The found cells.
98
79
  */
99
- buildSender(rpcMethod, inTransformers, outTransformer) {
100
- return async (...req) => {
101
- const payload = ClientJsonRpc.buildPayload(rpcMethod, await Promise.all(req
102
- .concat(Array.from(new Array(Math.max(inTransformers.length - req.length, 0))))
103
- .map((v, i) => transform(v, inTransformers[i]))));
104
- return transform(await this.send(payload), outTransformer);
105
- };
106
- }
80
+ this.findCellsPagedNoCache = this.buildSender(
81
+ "get_cells",
82
+ [
83
+ advanced_1.JsonRpcTransformers.indexerSearchKeyFrom,
84
+ (order) => order ?? "asc",
85
+ (limit) => (0, num_1.numToHex)(limit ?? 10),
86
+ ],
87
+ advanced_1.JsonRpcTransformers.findCellsResponseTo,
88
+ );
107
89
  /**
108
- * Sends a JSON-RPC request to the server.
90
+ * get cells capacity from node.
109
91
  *
110
- * @param payload - The JSON-RPC payload to send.
111
- * @returns The result of the JSON-RPC request.
112
- *
113
- * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
92
+ * @param key - The search key of cells.
93
+ * @returns The sum of cells capacity.
114
94
  */
115
- async send(payload) {
116
- const aborter = new AbortController();
117
- const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
118
- const raw = await (0, cross_fetch_1.default)(this.url, {
119
- method: "POST",
120
- headers: {
121
- "content-type": "application/json",
122
- },
123
- body: JSON.stringify(payload),
124
- signal: aborter.signal,
125
- });
126
- clearTimeout(abortTimer);
127
- const res = (await raw.json());
128
- if (res.id !== payload.id) {
129
- throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
130
- }
131
- if (res.error) {
132
- throw res.error;
133
- }
134
- return res.result;
95
+ this.getCellsCapacity = this.buildSender(
96
+ "get_cells_capacity",
97
+ [advanced_1.JsonRpcTransformers.indexerSearchKeyFrom],
98
+ ({ capacity }) => (0, num_1.numFrom)(capacity),
99
+ );
100
+ }
101
+ /**
102
+ * Returns the URL of the JSON-RPC server.
103
+ *
104
+ * @returns The URL of the JSON-RPC server.
105
+ */
106
+ get url() {
107
+ return this.url_;
108
+ }
109
+ /**
110
+ * Builds a sender function for a JSON-RPC method.
111
+ *
112
+ * @param rpcMethod - The JSON-RPC method.
113
+ * @param inTransformers - An array of input transformers.
114
+ * @param outTransformer - An output transformer function.
115
+ * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
116
+ */
117
+ buildSender(rpcMethod, inTransformers, outTransformer) {
118
+ return async (...req) => {
119
+ const payload = ClientJsonRpc.buildPayload(
120
+ rpcMethod,
121
+ await Promise.all(
122
+ req
123
+ .concat(
124
+ Array.from(
125
+ new Array(Math.max(inTransformers.length - req.length, 0)),
126
+ ),
127
+ )
128
+ .map((v, i) => transform(v, inTransformers[i])),
129
+ ),
130
+ );
131
+ return transform(await this.send(payload), outTransformer);
132
+ };
133
+ }
134
+ /**
135
+ * Sends a JSON-RPC request to the server.
136
+ *
137
+ * @param payload - The JSON-RPC payload to send.
138
+ * @returns The result of the JSON-RPC request.
139
+ *
140
+ * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
141
+ */
142
+ async send(payload) {
143
+ const aborter = new AbortController();
144
+ const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
145
+ const raw = await (0, cross_fetch_1.default)(this.url, {
146
+ method: "POST",
147
+ headers: {
148
+ "content-type": "application/json",
149
+ },
150
+ body: JSON.stringify(payload),
151
+ signal: aborter.signal,
152
+ });
153
+ clearTimeout(abortTimer);
154
+ const res = await raw.json();
155
+ if (res.id !== payload.id) {
156
+ throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
135
157
  }
136
- /**
137
- * Builds a JSON-RPC payload for the given method and parameters.
138
- *
139
- * @param method - The JSON-RPC method name.
140
- * @param req - The parameters for the JSON-RPC method.
141
- * @returns The JSON-RPC payload.
142
- */
143
- static buildPayload(method, req) {
144
- return {
145
- id: Math.round(Math.random() * 10000),
146
- method,
147
- params: req,
148
- jsonrpc: "2.0",
149
- };
158
+ if (res.error) {
159
+ throw res.error;
150
160
  }
161
+ return res.result;
162
+ }
163
+ /**
164
+ * Builds a JSON-RPC payload for the given method and parameters.
165
+ *
166
+ * @param method - The JSON-RPC method name.
167
+ * @param req - The parameters for the JSON-RPC method.
168
+ * @returns The JSON-RPC payload.
169
+ */
170
+ static buildPayload(method, req) {
171
+ return {
172
+ id: Math.round(Math.random() * 10000),
173
+ method,
174
+ params: req,
175
+ jsonrpc: "2.0",
176
+ };
177
+ }
151
178
  }
152
179
  exports.ClientJsonRpc = ClientJsonRpc;
@@ -1,42 +1,80 @@
1
- import { CellDep, CellDepLike, CellInput, CellInputLike, CellOutput, CellOutputLike, DepType, DepTypeLike, HashType, HashTypeLike, OutPoint, OutPointLike, Script, ScriptLike, Transaction, TransactionLike } from "../../ckb";
1
+ import {
2
+ CellDep,
3
+ CellDepLike,
4
+ CellInput,
5
+ CellInputLike,
6
+ CellOutput,
7
+ CellOutputLike,
8
+ DepType,
9
+ DepTypeLike,
10
+ HashType,
11
+ HashTypeLike,
12
+ OutPoint,
13
+ OutPointLike,
14
+ Script,
15
+ ScriptLike,
16
+ Transaction,
17
+ TransactionLike,
18
+ } from "../../ckb";
2
19
  import { Hex } from "../../hex";
3
20
  import { NumLike } from "../../num";
4
- import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, TransactionStatus } from "../clientTypes";
5
- import { JsonRpcCellDep, JsonRpcCellInput, JsonRpcCellOutput, JsonRpcDepType, JsonRpcHashType, JsonRpcIndexerSearchKey, JsonRpcOutPoint, JsonRpcScript, JsonRpcTransaction } from "./types";
21
+ import {
22
+ ClientFindCellsResponse,
23
+ ClientIndexerSearchKeyLike,
24
+ ClientTransactionResponse,
25
+ TransactionStatus,
26
+ } from "../clientTypes";
27
+ import {
28
+ JsonRpcCellDep,
29
+ JsonRpcCellInput,
30
+ JsonRpcCellOutput,
31
+ JsonRpcDepType,
32
+ JsonRpcHashType,
33
+ JsonRpcIndexerSearchKey,
34
+ JsonRpcOutPoint,
35
+ JsonRpcScript,
36
+ JsonRpcTransaction,
37
+ } from "./types";
6
38
  export declare class JsonRpcTransformers {
7
- static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType;
8
- static hashTypeTo(hashType: JsonRpcHashType): HashType;
9
- static depTypeFrom(depType: DepTypeLike): JsonRpcDepType;
10
- static depTypeTo(depType: JsonRpcDepType): DepType;
11
- static scriptFrom(scriptLike: ScriptLike): JsonRpcScript;
12
- static scriptTo(script: JsonRpcScript): Script;
13
- static outPointFrom(outPointLike: OutPointLike): JsonRpcOutPoint;
14
- static outPointTo(outPoint: JsonRpcOutPoint): OutPoint;
15
- static cellInputFrom(cellInput: CellInputLike): JsonRpcCellInput;
16
- static cellInputTo(cellInput: JsonRpcCellInput): CellInput;
17
- static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput;
18
- static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput;
19
- static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep;
20
- static cellDepTo(cellDep: JsonRpcCellDep): CellDep;
21
- static transactionFrom(txLike: TransactionLike): JsonRpcTransaction;
22
- static transactionTo(tx: JsonRpcTransaction): Transaction;
23
- static transactionResponseTo({ tx_status: { status, block_number }, transaction, }: {
24
- tx_status: {
25
- status: TransactionStatus;
26
- block_number: Hex;
27
- };
28
- transaction: JsonRpcTransaction;
29
- }): ClientTransactionResponse;
30
- static rangeFrom([a, b]: [NumLike, NumLike]): [Hex, Hex];
31
- static indexerSearchKeyFrom(keyLike: ClientIndexerSearchKeyLike): JsonRpcIndexerSearchKey;
32
- static findCellsResponseTo({ last_cursor, objects, }: {
33
- last_cursor: string;
34
- objects: {
35
- block_number: Hex;
36
- out_point: JsonRpcOutPoint;
37
- output: JsonRpcCellOutput;
38
- output_data: Hex;
39
- }[];
40
- }): ClientFindCellsResponse;
39
+ static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType;
40
+ static hashTypeTo(hashType: JsonRpcHashType): HashType;
41
+ static depTypeFrom(depType: DepTypeLike): JsonRpcDepType;
42
+ static depTypeTo(depType: JsonRpcDepType): DepType;
43
+ static scriptFrom(scriptLike: ScriptLike): JsonRpcScript;
44
+ static scriptTo(script: JsonRpcScript): Script;
45
+ static outPointFrom(outPointLike: OutPointLike): JsonRpcOutPoint;
46
+ static outPointTo(outPoint: JsonRpcOutPoint): OutPoint;
47
+ static cellInputFrom(cellInputLike: CellInputLike): JsonRpcCellInput;
48
+ static cellInputTo(cellInput: JsonRpcCellInput): CellInput;
49
+ static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput;
50
+ static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput;
51
+ static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep;
52
+ static cellDepTo(cellDep: JsonRpcCellDep): CellDep;
53
+ static transactionFrom(txLike: TransactionLike): JsonRpcTransaction;
54
+ static transactionTo(tx: JsonRpcTransaction): Transaction;
55
+ static transactionResponseTo({
56
+ tx_status: { status },
57
+ transaction,
58
+ }: {
59
+ tx_status: {
60
+ status: TransactionStatus;
61
+ };
62
+ transaction: JsonRpcTransaction | null;
63
+ }): ClientTransactionResponse | null;
64
+ static rangeFrom([a, b]: [NumLike, NumLike]): [Hex, Hex];
65
+ static indexerSearchKeyFrom(
66
+ keyLike: ClientIndexerSearchKeyLike,
67
+ ): JsonRpcIndexerSearchKey;
68
+ static findCellsResponseTo({
69
+ last_cursor,
70
+ objects,
71
+ }: {
72
+ last_cursor: string;
73
+ objects: {
74
+ out_point: JsonRpcOutPoint;
75
+ output: JsonRpcCellOutput;
76
+ output_data?: Hex;
77
+ }[];
78
+ }): ClientFindCellsResponse;
41
79
  }
42
- //# sourceMappingURL=transformers.d.ts.map
80
+ //# sourceMappingURL=transformers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,MAA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