@ckb-ccc/core 1.2.3 → 1.3.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 (140) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/advancedBarrel.d.ts +1 -0
  3. package/dist/advancedBarrel.d.ts.map +1 -1
  4. package/dist/advancedBarrel.js +1 -0
  5. package/dist/barrel.d.ts +1 -0
  6. package/dist/barrel.d.ts.map +1 -1
  7. package/dist/barrel.js +1 -0
  8. package/dist/ckb/script.d.ts +1 -0
  9. package/dist/ckb/script.d.ts.map +1 -1
  10. package/dist/ckb/script.js +1 -0
  11. package/dist/ckb/transaction.d.ts +3 -1
  12. package/dist/ckb/transaction.d.ts.map +1 -1
  13. package/dist/ckb/transaction.js +25 -2
  14. package/dist/client/advanced.d.ts +0 -1
  15. package/dist/client/advanced.d.ts.map +1 -1
  16. package/dist/client/advanced.js +0 -1
  17. package/dist/client/clientPublicMainnet.d.ts +3 -9
  18. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  19. package/dist/client/clientPublicTestnet.d.ts +3 -9
  20. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  21. package/dist/client/jsonRpc/client.d.ts +160 -0
  22. package/dist/client/jsonRpc/client.d.ts.map +1 -0
  23. package/dist/client/jsonRpc/client.js +220 -0
  24. package/dist/client/jsonRpc/index.d.ts +1 -182
  25. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  26. package/dist/client/jsonRpc/index.js +1 -293
  27. package/dist/jsonRpc/advanced.d.ts +2 -0
  28. package/dist/jsonRpc/advanced.d.ts.map +1 -0
  29. package/dist/jsonRpc/advanced.js +1 -0
  30. package/dist/jsonRpc/index.d.ts +2 -0
  31. package/dist/jsonRpc/index.d.ts.map +1 -0
  32. package/dist/jsonRpc/index.js +1 -0
  33. package/dist/jsonRpc/requestor.d.ts +48 -0
  34. package/dist/jsonRpc/requestor.d.ts.map +1 -0
  35. package/dist/jsonRpc/requestor.js +107 -0
  36. package/dist/jsonRpc/transports/advanced.d.ts +5 -0
  37. package/dist/jsonRpc/transports/advanced.d.ts.map +1 -0
  38. package/dist/jsonRpc/transports/advanced.js +4 -0
  39. package/dist/{client/transports/advanced.d.ts → jsonRpc/transports/factory.d.ts} +1 -4
  40. package/dist/jsonRpc/transports/factory.d.ts.map +1 -0
  41. package/dist/{client/transports/advanced.js → jsonRpc/transports/factory.js} +0 -3
  42. package/dist/jsonRpc/transports/http.d.ts.map +1 -0
  43. package/dist/jsonRpc/transports/transport.d.ts +18 -0
  44. package/dist/jsonRpc/transports/transport.d.ts.map +1 -0
  45. package/dist/jsonRpc/transports/webSocket.d.ts.map +1 -0
  46. package/dist/molecule/predefined.d.ts +12 -0
  47. package/dist/molecule/predefined.d.ts.map +1 -1
  48. package/dist/molecule/predefined.js +28 -0
  49. package/dist/num/index.d.ts.map +1 -1
  50. package/dist/num/index.js +5 -1
  51. package/dist.commonjs/advancedBarrel.d.ts +1 -0
  52. package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
  53. package/dist.commonjs/advancedBarrel.js +1 -0
  54. package/dist.commonjs/barrel.d.ts +1 -0
  55. package/dist.commonjs/barrel.d.ts.map +1 -1
  56. package/dist.commonjs/barrel.js +1 -0
  57. package/dist.commonjs/ckb/script.d.ts +1 -0
  58. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  59. package/dist.commonjs/ckb/script.js +2 -1
  60. package/dist.commonjs/ckb/transaction.d.ts +3 -1
  61. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  62. package/dist.commonjs/ckb/transaction.js +25 -2
  63. package/dist.commonjs/client/advanced.d.ts +0 -1
  64. package/dist.commonjs/client/advanced.d.ts.map +1 -1
  65. package/dist.commonjs/client/advanced.js +0 -1
  66. package/dist.commonjs/client/clientPublicMainnet.d.ts +3 -9
  67. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  68. package/dist.commonjs/client/clientPublicTestnet.d.ts +3 -9
  69. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  70. package/dist.commonjs/client/jsonRpc/client.d.ts +160 -0
  71. package/dist.commonjs/client/jsonRpc/client.d.ts.map +1 -0
  72. package/dist.commonjs/client/jsonRpc/client.js +224 -0
  73. package/dist.commonjs/client/jsonRpc/index.d.ts +1 -182
  74. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  75. package/dist.commonjs/client/jsonRpc/index.js +15 -295
  76. package/dist.commonjs/jsonRpc/advanced.d.ts +2 -0
  77. package/dist.commonjs/jsonRpc/advanced.d.ts.map +1 -0
  78. package/dist.commonjs/jsonRpc/advanced.js +17 -0
  79. package/dist.commonjs/jsonRpc/index.d.ts +2 -0
  80. package/dist.commonjs/jsonRpc/index.d.ts.map +1 -0
  81. package/dist.commonjs/jsonRpc/index.js +17 -0
  82. package/dist.commonjs/jsonRpc/requestor.d.ts +48 -0
  83. package/dist.commonjs/jsonRpc/requestor.d.ts.map +1 -0
  84. package/dist.commonjs/jsonRpc/requestor.js +111 -0
  85. package/dist.commonjs/jsonRpc/transports/advanced.d.ts +5 -0
  86. package/dist.commonjs/jsonRpc/transports/advanced.d.ts.map +1 -0
  87. package/dist.commonjs/{client → jsonRpc}/transports/advanced.js +1 -9
  88. package/dist.commonjs/{client/transports/advanced.d.ts → jsonRpc/transports/factory.d.ts} +1 -4
  89. package/dist.commonjs/jsonRpc/transports/factory.d.ts.map +1 -0
  90. package/dist.commonjs/jsonRpc/transports/factory.js +11 -0
  91. package/dist.commonjs/jsonRpc/transports/http.d.ts.map +1 -0
  92. package/dist.commonjs/jsonRpc/transports/transport.d.ts +18 -0
  93. package/dist.commonjs/jsonRpc/transports/transport.d.ts.map +1 -0
  94. package/dist.commonjs/jsonRpc/transports/webSocket.d.ts.map +1 -0
  95. package/dist.commonjs/molecule/predefined.d.ts +12 -0
  96. package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
  97. package/dist.commonjs/molecule/predefined.js +30 -1
  98. package/dist.commonjs/num/index.d.ts.map +1 -1
  99. package/dist.commonjs/num/index.js +5 -1
  100. package/package.json +1 -1
  101. package/src/advancedBarrel.ts +1 -0
  102. package/src/barrel.ts +1 -0
  103. package/src/ckb/script.ts +1 -0
  104. package/src/ckb/transaction.ts +52 -2
  105. package/src/client/advanced.ts +0 -1
  106. package/src/client/clientPublicMainnet.ts +2 -8
  107. package/src/client/clientPublicTestnet.ts +2 -8
  108. package/src/client/jsonRpc/client.ts +395 -0
  109. package/src/client/jsonRpc/index.ts +1 -490
  110. package/src/jsonRpc/advanced.ts +1 -0
  111. package/src/jsonRpc/index.ts +1 -0
  112. package/src/jsonRpc/requestor.ts +157 -0
  113. package/src/jsonRpc/transports/advanced.ts +4 -0
  114. package/src/{client/transports/advanced.ts → jsonRpc/transports/factory.ts} +0 -4
  115. package/src/jsonRpc/transports/transport.ts +18 -0
  116. package/src/molecule/predefined.ts +32 -0
  117. package/src/num/index.ts +5 -1
  118. package/dist/client/transports/advanced.d.ts.map +0 -1
  119. package/dist/client/transports/http.d.ts.map +0 -1
  120. package/dist/client/transports/transport.d.ts +0 -10
  121. package/dist/client/transports/transport.d.ts.map +0 -1
  122. package/dist/client/transports/webSocket.d.ts.map +0 -1
  123. package/dist.commonjs/client/transports/advanced.d.ts.map +0 -1
  124. package/dist.commonjs/client/transports/http.d.ts.map +0 -1
  125. package/dist.commonjs/client/transports/transport.d.ts +0 -10
  126. package/dist.commonjs/client/transports/transport.d.ts.map +0 -1
  127. package/dist.commonjs/client/transports/webSocket.d.ts.map +0 -1
  128. package/src/client/transports/transport.ts +0 -10
  129. /package/dist/{client → jsonRpc}/transports/http.d.ts +0 -0
  130. /package/dist/{client → jsonRpc}/transports/http.js +0 -0
  131. /package/dist/{client → jsonRpc}/transports/transport.js +0 -0
  132. /package/dist/{client → jsonRpc}/transports/webSocket.d.ts +0 -0
  133. /package/dist/{client → jsonRpc}/transports/webSocket.js +0 -0
  134. /package/dist.commonjs/{client → jsonRpc}/transports/http.d.ts +0 -0
  135. /package/dist.commonjs/{client → jsonRpc}/transports/http.js +0 -0
  136. /package/dist.commonjs/{client → jsonRpc}/transports/transport.js +0 -0
  137. /package/dist.commonjs/{client → jsonRpc}/transports/webSocket.d.ts +0 -0
  138. /package/dist.commonjs/{client → jsonRpc}/transports/webSocket.js +0 -0
  139. /package/src/{client → jsonRpc}/transports/http.ts +0 -0
  140. /package/src/{client → jsonRpc}/transports/webSocket.ts +0 -0
@@ -1,183 +1,2 @@
1
- import { Cell, OutPointLike, TransactionLike } from "../../ckb/index.js";
2
- import { Hex, HexLike } from "../../hex/index.js";
3
- import { Num, NumLike } from "../../num/index.js";
4
- import { ClientCache } from "../cache/index.js";
5
- import { Client } from "../client.js";
6
- import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, OutputsValidator } from "../clientTypes.js";
7
- import { JsonRpcPayload, Transport } from "../transports/advanced.js";
8
- /**
9
- * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
10
- * Provides methods for sending transactions and building JSON-RPC payloads.
11
- */
12
- export declare abstract class ClientJsonRpc extends Client {
13
- private readonly url_;
14
- private readonly maxConcurrent?;
15
- private concurrent;
16
- private readonly pending;
17
- private id;
18
- private readonly transport;
19
- /**
20
- * Creates an instance of ClientJsonRpc.
21
- *
22
- * @param url_ - The URL of the JSON-RPC server.
23
- * @param timeout - The timeout for requests in milliseconds
24
- */
25
- constructor(url_: string, config?: {
26
- timeout?: number;
27
- cache?: ClientCache;
28
- maxConcurrent?: number;
29
- transport?: Transport;
30
- });
31
- /**
32
- * Returns the URL of the JSON-RPC server.
33
- *
34
- * @returns The URL of the JSON-RPC server.
35
- */
36
- get url(): string;
37
- /**
38
- * Get fee rate statistics
39
- *
40
- * @returns Fee rate statistics
41
- */
42
- getFeeRateStatistics: Client["getFeeRateStatistics"];
43
- /**
44
- * Get tip block number
45
- *
46
- * @returns Tip block number
47
- */
48
- getTip: () => Promise<Num>;
49
- /**
50
- * Get tip block header
51
- *
52
- * @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
53
- * @returns BlockHeader
54
- */
55
- getTipHeader: Client["getTipHeader"];
56
- /**
57
- * Get block by block number
58
- *
59
- * @param blockNumber - The block number.
60
- * @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
61
- * @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
62
- * @returns Block
63
- */
64
- getBlockByNumber: Client["getBlockByNumber"];
65
- /**
66
- * Get block by block hash
67
- *
68
- * @param blockHash - The block hash.
69
- * @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
70
- * @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
71
- * @returns Block
72
- */
73
- getBlockByHash: Client["getBlockByHash"];
74
- /**
75
- * Get header by block number
76
- *
77
- * @param blockNumber - The block number.
78
- * @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
79
- * @returns BlockHeader
80
- */
81
- getHeaderByNumber: Client["getHeaderByNumber"];
82
- /**
83
- * Get header by block hash
84
- *
85
- * @param blockHash - The block hash.
86
- * @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
87
- * @returns BlockHeader
88
- */
89
- getHeaderByHash: Client["getHeaderByHash"];
90
- /**
91
- * Estimate cycles of a transaction.
92
- *
93
- * @param transaction - The transaction to estimate.
94
- * @returns Consumed cycles
95
- */
96
- estimateCycles: Client["estimateCycles"];
97
- /**
98
- * Test a transaction.
99
- *
100
- * @param transaction - The transaction to test.
101
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
102
- * @returns Consumed cycles
103
- */
104
- sendTransactionDry: Client["sendTransactionDry"];
105
- /**
106
- * Send a transaction to node.
107
- *
108
- * @param transaction - The transaction to send.
109
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
110
- * @returns Transaction hash.
111
- */
112
- sendTransactionNoCache: (transaction: TransactionLike, validator?: OutputsValidator | undefined) => Promise<Hex>;
113
- /**
114
- * Get a transaction from node.
115
- *
116
- * @param txHash - The hash of the transaction.
117
- * @returns The transaction with status.
118
- */
119
- getTransactionNoCache: (txHash: HexLike) => Promise<ClientTransactionResponse | undefined>;
120
- /**
121
- * Get a live cell from node.
122
- *
123
- * @param outPoint - The out point of the cell.
124
- * @param withData - Include data in the response.
125
- * @param includeTxPool - Include cells in the tx pool.
126
- * @returns The cell
127
- */
128
- getCellLiveNoCache(outPoint: OutPointLike, withData?: boolean | null, includeTxPool?: boolean | null): Promise<Cell | undefined>;
129
- /**
130
- * find cells from node.
131
- *
132
- * @param key - The search key of cells.
133
- * @param order - The order of cells.
134
- * @param limit - The max return size of cells.
135
- * @param after - Pagination parameter.
136
- * @returns The found cells.
137
- */
138
- findCellsPagedNoCache: (key: ClientIndexerSearchKeyLike, order?: "asc" | "desc", limit?: NumLike, after?: string) => Promise<ClientFindCellsResponse>;
139
- /**
140
- * find transactions from node.
141
- *
142
- * @param key - The search key of transactions.
143
- * @param order - The order of transactions.
144
- * @param limit - The max return size of transactions.
145
- * @param after - Pagination parameter.
146
- * @returns The found transactions.
147
- */
148
- findTransactionsPaged: Client["findTransactionsPaged"];
149
- /**
150
- * get cells capacity from node.
151
- *
152
- * @param key - The search key of cells.
153
- * @returns The sum of cells capacity.
154
- */
155
- getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<Num>;
156
- /**
157
- * Builds a sender function for a JSON-RPC method.
158
- *
159
- * @param rpcMethod - The JSON-RPC method.
160
- * @param inTransformers - An array of input transformers.
161
- * @param outTransformer - An output transformer function.
162
- * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
163
- */
164
- buildSender(rpcMethod: string, inTransformers: (((_: any) => unknown) | undefined)[], outTransformer?: (_: any) => unknown): (...req: unknown[]) => Promise<unknown>;
165
- /**
166
- * Sends a JSON-RPC request to the server.
167
- *
168
- * @param payload - The JSON-RPC payload to send.
169
- * @returns The result of the JSON-RPC request.
170
- *
171
- * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
172
- */
173
- send(payload: JsonRpcPayload): Promise<unknown>;
174
- /**
175
- * Builds a JSON-RPC payload for the given method and parameters.
176
- *
177
- * @param method - The JSON-RPC method name.
178
- * @param req - The parameters for the JSON-RPC method.
179
- * @returns The JSON-RPC payload.
180
- */
181
- buildPayload(method: string, req: unknown[]): JsonRpcPayload;
182
- }
1
+ export * from "./client.js";
183
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -1,297 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientJsonRpc = void 0;
4
- const index_js_1 = require("../../ckb/index.js");
5
- const index_js_2 = require("../../hex/index.js");
6
- const index_js_3 = require("../../num/index.js");
7
- const index_js_4 = require("../../utils/index.js");
8
- const client_js_1 = require("../client.js");
9
- const clientTypes_js_1 = require("../clientTypes.js");
10
- const advanced_js_1 = require("../transports/advanced.js");
11
- const advanced_js_2 = require("./advanced.js");
12
- /**
13
- * Applies a transformation function to a value if the transformer is provided.
14
- *
15
- * @param value - The value to be transformed.
16
- * @param transformer - An optional transformation function.
17
- * @returns The transformed value if a transformer is provided, otherwise the original value.
18
- *
19
- * @example
20
- * ```typescript
21
- * const result = transform(5, (x) => x * 2); // Outputs 10
22
- * const resultWithoutTransformer = transform(5); // Outputs 5
23
- * ```
24
- */
25
- function transform(value, transformer) {
26
- if (transformer) {
27
- return transformer(value);
28
- }
29
- return value;
30
- }
31
- const ERROR_PARSERS = [
32
- [
33
- "Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)",
34
- (error, match) => new clientTypes_js_1.ErrorClientResolveUnknown(error, index_js_1.OutPoint.fromBytes(match[1])),
35
- ],
36
- [
37
- "Verification\\(Error { kind: Script, inner: TransactionScriptError { source: (Inputs|Outputs)\\[([0-9]*)\\].(Lock|Type), cause: ValidationFailure: see error code (-?[0-9])* on page https://nervosnetwork\\.github\\.io/ckb-script-error-codes/by-(type|data)-hash/(.*)\\.html",
38
- (error, match) => new clientTypes_js_1.ErrorClientVerification(error, match[3] === "Lock"
39
- ? "lock"
40
- : match[1] === "Inputs"
41
- ? "inputType"
42
- : "outputType", match[2], Number(match[4]), match[5] === "data" ? "data" : "type", match[6]),
43
- ],
44
- [
45
- "Duplicated\\(Byte32\\((0x.*)\\)\\)",
46
- (error, match) => new clientTypes_js_1.ErrorClientDuplicatedTransaction(error, match[1]),
47
- ],
48
- [
49
- 'RBFRejected\\("Tx\'s current fee is ([0-9]*), expect it to >= ([0-9]*) to replace old txs"\\)',
50
- (error, match) => new clientTypes_js_1.ErrorClientRBFRejected(error, match[1], match[2]),
51
- ],
52
- ];
53
- /**
54
- * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
55
- * Provides methods for sending transactions and building JSON-RPC payloads.
56
- */
57
- class ClientJsonRpc extends client_js_1.Client {
58
- /**
59
- * Creates an instance of ClientJsonRpc.
60
- *
61
- * @param url_ - The URL of the JSON-RPC server.
62
- * @param timeout - The timeout for requests in milliseconds
63
- */
64
- constructor(url_, config) {
65
- super(config);
66
- this.url_ = url_;
67
- this.concurrent = 0;
68
- this.pending = [];
69
- this.id = 0;
70
- /**
71
- * Get fee rate statistics
72
- *
73
- * @returns Fee rate statistics
74
- */
75
- this.getFeeRateStatistics = this.buildSender("get_fee_rate_statistics", [(n) => (0, index_js_4.apply)(index_js_3.numFrom, n)], ({ mean, median }) => ({
76
- mean: (0, index_js_3.numFrom)(mean),
77
- median: (0, index_js_3.numFrom)(median),
78
- }));
79
- /**
80
- * Get tip block number
81
- *
82
- * @returns Tip block number
83
- */
84
- this.getTip = this.buildSender("get_tip_block_number", [], index_js_3.numFrom);
85
- /**
86
- * Get tip block header
87
- *
88
- * @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
89
- * @returns BlockHeader
90
- */
91
- this.getTipHeader = this.buildSender("get_tip_header", [], (b) => (0, index_js_4.apply)(advanced_js_2.JsonRpcTransformers.blockHeaderTo, b));
92
- /**
93
- * Get block by block number
94
- *
95
- * @param blockNumber - The block number.
96
- * @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
97
- * @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
98
- * @returns Block
99
- */
100
- this.getBlockByNumber = this.buildSender("get_block_by_number", [(v) => (0, index_js_3.numToHex)((0, index_js_3.numFrom)(v))], (b) => (0, index_js_4.apply)(advanced_js_2.JsonRpcTransformers.blockTo, b));
101
- /**
102
- * Get block by block hash
103
- *
104
- * @param blockHash - The block hash.
105
- * @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
106
- * @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
107
- * @returns Block
108
- */
109
- this.getBlockByHash = this.buildSender("get_block", [index_js_2.hexFrom], (b) => (0, index_js_4.apply)(advanced_js_2.JsonRpcTransformers.blockTo, b));
110
- /**
111
- * Get header by block number
112
- *
113
- * @param blockNumber - The block number.
114
- * @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
115
- * @returns BlockHeader
116
- */
117
- this.getHeaderByNumber = this.buildSender("get_header_by_number", [(v) => (0, index_js_3.numToHex)((0, index_js_3.numFrom)(v))], (b) => (0, index_js_4.apply)(advanced_js_2.JsonRpcTransformers.blockHeaderTo, b));
118
- /**
119
- * Get header by block hash
120
- *
121
- * @param blockHash - The block hash.
122
- * @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
123
- * @returns BlockHeader
124
- */
125
- this.getHeaderByHash = this.buildSender("get_header", [index_js_2.hexFrom], (b) => (0, index_js_4.apply)(advanced_js_2.JsonRpcTransformers.blockHeaderTo, b));
126
- /**
127
- * Estimate cycles of a transaction.
128
- *
129
- * @param transaction - The transaction to estimate.
130
- * @returns Consumed cycles
131
- */
132
- this.estimateCycles = this.buildSender("estimate_cycles", [advanced_js_2.JsonRpcTransformers.transactionFrom], ({ cycles }) => (0, index_js_3.numFrom)(cycles));
133
- /**
134
- * Test a transaction.
135
- *
136
- * @param transaction - The transaction to test.
137
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
138
- * @returns Consumed cycles
139
- */
140
- this.sendTransactionDry = this.buildSender("test_tx_pool_accept", [advanced_js_2.JsonRpcTransformers.transactionFrom], ({ cycles }) => (0, index_js_3.numFrom)(cycles));
141
- /**
142
- * Send a transaction to node.
143
- *
144
- * @param transaction - The transaction to send.
145
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
146
- * @returns Transaction hash.
147
- */
148
- this.sendTransactionNoCache = this.buildSender("send_transaction", [advanced_js_2.JsonRpcTransformers.transactionFrom], index_js_2.hexFrom);
149
- /**
150
- * Get a transaction from node.
151
- *
152
- * @param txHash - The hash of the transaction.
153
- * @returns The transaction with status.
154
- */
155
- this.getTransactionNoCache = this.buildSender("get_transaction", [index_js_2.hexFrom], advanced_js_2.JsonRpcTransformers.transactionResponseTo);
156
- /**
157
- * find cells from node.
158
- *
159
- * @param key - The search key of cells.
160
- * @param order - The order of cells.
161
- * @param limit - The max return size of cells.
162
- * @param after - Pagination parameter.
163
- * @returns The found cells.
164
- */
165
- this.findCellsPagedNoCache = this.buildSender("get_cells", [
166
- advanced_js_2.JsonRpcTransformers.indexerSearchKeyFrom,
167
- (order) => order ?? "asc",
168
- (limit) => (0, index_js_3.numToHex)(limit ?? 10),
169
- ], advanced_js_2.JsonRpcTransformers.findCellsResponseTo);
170
- /**
171
- * find transactions from node.
172
- *
173
- * @param key - The search key of transactions.
174
- * @param order - The order of transactions.
175
- * @param limit - The max return size of transactions.
176
- * @param after - Pagination parameter.
177
- * @returns The found transactions.
178
- */
179
- this.findTransactionsPaged = this.buildSender("get_transactions", [
180
- advanced_js_2.JsonRpcTransformers.indexerSearchKeyTransactionFrom,
181
- (order) => order ?? "asc",
182
- (limit) => (0, index_js_3.numToHex)(limit ?? 10),
183
- ], advanced_js_2.JsonRpcTransformers.findTransactionsResponseTo);
184
- /**
185
- * get cells capacity from node.
186
- *
187
- * @param key - The search key of cells.
188
- * @returns The sum of cells capacity.
189
- */
190
- this.getCellsCapacity = this.buildSender("get_cells_capacity", [advanced_js_2.JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => (0, index_js_3.numFrom)(capacity));
191
- this.maxConcurrent = config?.maxConcurrent;
192
- this.transport = config?.transport ?? (0, advanced_js_1.transportFromUri)(url_, config);
193
- }
194
- /**
195
- * Returns the URL of the JSON-RPC server.
196
- *
197
- * @returns The URL of the JSON-RPC server.
198
- */
199
- get url() {
200
- return this.url_;
201
- }
202
- /**
203
- * Get a live cell from node.
204
- *
205
- * @param outPoint - The out point of the cell.
206
- * @param withData - Include data in the response.
207
- * @param includeTxPool - Include cells in the tx pool.
208
- * @returns The cell
209
- */
210
- getCellLiveNoCache(outPoint, withData, includeTxPool) {
211
- return this.buildSender("get_live_cell", [advanced_js_2.JsonRpcTransformers.outPointFrom], ({ cell, }) => (0, index_js_4.apply)(({ output, data, }) => index_js_1.Cell.from({
212
- cellOutput: advanced_js_2.JsonRpcTransformers.cellOutputTo(output),
213
- outputData: data?.content ?? "0x",
214
- outPoint,
215
- }), cell))(outPoint, withData ?? true, includeTxPool);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
216
7
  }
217
- /**
218
- * Builds a sender function for a JSON-RPC method.
219
- *
220
- * @param rpcMethod - The JSON-RPC method.
221
- * @param inTransformers - An array of input transformers.
222
- * @param outTransformer - An output transformer function.
223
- * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
224
- */
225
- buildSender(rpcMethod,
226
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
- inTransformers,
228
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
- outTransformer) {
230
- return async (...req) => {
231
- const payload = this.buildPayload(rpcMethod, req
232
- .concat(Array.from(new Array(Math.max(inTransformers.length - req.length, 0))))
233
- .map((v, i) => transform(v, inTransformers[i])));
234
- try {
235
- return transform(await this.send(payload), outTransformer);
236
- }
237
- catch (errAny) {
238
- if (typeof errAny !== "object" ||
239
- errAny === null ||
240
- !("data" in errAny) ||
241
- typeof errAny.data !== "string") {
242
- throw errAny;
243
- }
244
- const err = errAny;
245
- for (const [regexp, builder] of ERROR_PARSERS) {
246
- const match = err.data.match(regexp);
247
- if (match) {
248
- throw builder(err, match);
249
- }
250
- }
251
- throw new clientTypes_js_1.ErrorClientBase(err);
252
- }
253
- };
254
- }
255
- /**
256
- * Sends a JSON-RPC request to the server.
257
- *
258
- * @param payload - The JSON-RPC payload to send.
259
- * @returns The result of the JSON-RPC request.
260
- *
261
- * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
262
- */
263
- async send(payload) {
264
- if (this.maxConcurrent !== undefined &&
265
- this.concurrent >= this.maxConcurrent) {
266
- const pending = new Promise((resolve) => this.pending.push(resolve));
267
- await pending;
268
- }
269
- this.concurrent += 1;
270
- const res = (await this.transport.request(payload));
271
- this.concurrent -= 1;
272
- this.pending.shift()?.();
273
- if (res.id !== payload.id) {
274
- throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
275
- }
276
- if (res.error) {
277
- throw res.error;
278
- }
279
- return res.result;
280
- }
281
- /**
282
- * Builds a JSON-RPC payload for the given method and parameters.
283
- *
284
- * @param method - The JSON-RPC method name.
285
- * @param req - The parameters for the JSON-RPC method.
286
- * @returns The JSON-RPC payload.
287
- */
288
- buildPayload(method, req) {
289
- return {
290
- id: this.id++,
291
- method,
292
- params: req,
293
- jsonrpc: "2.0",
294
- };
295
- }
296
- }
297
- exports.ClientJsonRpc = ClientJsonRpc;
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client.js"), exports);
@@ -0,0 +1,2 @@
1
+ export * from "./transports/advanced.js";
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/jsonRpc/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./transports/advanced.js"), exports);
@@ -0,0 +1,2 @@
1
+ export * from "./requestor.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./requestor.js"), exports);
@@ -0,0 +1,48 @@
1
+ import { JsonRpcPayload, Transport } from "./transports/advanced.js";
2
+ export type RequestorJsonRpcConfig = {
3
+ timeout?: number;
4
+ maxConcurrent?: number;
5
+ transport?: Transport;
6
+ };
7
+ export declare class RequestorJsonRpc {
8
+ private readonly url_;
9
+ private readonly onError?;
10
+ readonly maxConcurrent?: number;
11
+ private concurrent;
12
+ private readonly pending;
13
+ readonly transport: Transport;
14
+ private id;
15
+ /**
16
+ * Creates an instance of ClientJsonRpc.
17
+ *
18
+ * @param url_ - The URL of the JSON-RPC server.
19
+ * @param timeout - The timeout for requests in milliseconds
20
+ */
21
+ constructor(url_: string, config?: RequestorJsonRpcConfig, onError?: ((err: unknown) => Promise<void> | void) | undefined);
22
+ /**
23
+ * Returns the URL of the JSON-RPC server.
24
+ *
25
+ * @returns The URL of the JSON-RPC server.
26
+ */
27
+ get url(): string;
28
+ /**
29
+ * request a JSON-RPC method.
30
+ *
31
+ * @param rpcMethod - The JSON-RPC method.
32
+ * @param params - Params for the method.
33
+ * @param inTransformers - An array of input transformers.
34
+ * @param outTransformer - An output transformer function.
35
+ * @returns Method response.
36
+ */
37
+ request(rpcMethod: string, params: unknown[], inTransformers?: (((_: any) => unknown) | undefined)[], outTransformer?: (_: any) => unknown): Promise<unknown>;
38
+ requestPayload(payload: JsonRpcPayload): Promise<unknown>;
39
+ /**
40
+ * Builds a JSON-RPC payload for the given method and parameters.
41
+ *
42
+ * @param method - The JSON-RPC method name.
43
+ * @param req - The parameters for the JSON-RPC method.
44
+ * @returns The JSON-RPC payload.
45
+ */
46
+ buildPayload(method: string, req: unknown[]): JsonRpcPayload;
47
+ }
48
+ //# sourceMappingURL=requestor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestor.d.ts","sourceRoot":"","sources":["../../src/jsonRpc/requestor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAsBlC,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,qBAAa,gBAAgB;IAgBzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAjB3B,SAAgB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAE9C,SAAgB,SAAS,EAAE,SAAS,CAAC;IAErC,OAAO,CAAC,EAAE,CAAK;IAEf;;;;;OAKG;gBAEgB,IAAI,EAAE,MAAM,EAC7B,MAAM,CAAC,EAAE,sBAAsB,EACd,OAAO,CAAC,GAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,aAAA;IAMnE;;;;OAIG;IAEH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;;;;;OAQG;IACG,OAAO,CACX,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,EAAE,EAEjB,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC,EAAE,EAEtD,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,GACnC,OAAO,CAAC,OAAO,CAAC;IA6Bb,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IA6B/D;;;;;;OAMG;IAEH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQ7D"}