@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.
- package/CHANGELOG.md +16 -0
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +1 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/ckb/script.d.ts +1 -0
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +1 -0
- package/dist/ckb/transaction.d.ts +3 -1
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +25 -2
- package/dist/client/advanced.d.ts +0 -1
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +0 -1
- package/dist/client/clientPublicMainnet.d.ts +3 -9
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +3 -9
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/jsonRpc/client.d.ts +160 -0
- package/dist/client/jsonRpc/client.d.ts.map +1 -0
- package/dist/client/jsonRpc/client.js +220 -0
- package/dist/client/jsonRpc/index.d.ts +1 -182
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +1 -293
- package/dist/jsonRpc/advanced.d.ts +2 -0
- package/dist/jsonRpc/advanced.d.ts.map +1 -0
- package/dist/jsonRpc/advanced.js +1 -0
- package/dist/jsonRpc/index.d.ts +2 -0
- package/dist/jsonRpc/index.d.ts.map +1 -0
- package/dist/jsonRpc/index.js +1 -0
- package/dist/jsonRpc/requestor.d.ts +48 -0
- package/dist/jsonRpc/requestor.d.ts.map +1 -0
- package/dist/jsonRpc/requestor.js +107 -0
- package/dist/jsonRpc/transports/advanced.d.ts +5 -0
- package/dist/jsonRpc/transports/advanced.d.ts.map +1 -0
- package/dist/jsonRpc/transports/advanced.js +4 -0
- package/dist/{client/transports/advanced.d.ts → jsonRpc/transports/factory.d.ts} +1 -4
- package/dist/jsonRpc/transports/factory.d.ts.map +1 -0
- package/dist/{client/transports/advanced.js → jsonRpc/transports/factory.js} +0 -3
- package/dist/jsonRpc/transports/http.d.ts.map +1 -0
- package/dist/jsonRpc/transports/transport.d.ts +18 -0
- package/dist/jsonRpc/transports/transport.d.ts.map +1 -0
- package/dist/jsonRpc/transports/webSocket.d.ts.map +1 -0
- package/dist/molecule/predefined.d.ts +12 -0
- package/dist/molecule/predefined.d.ts.map +1 -1
- package/dist/molecule/predefined.js +28 -0
- package/dist/num/index.d.ts.map +1 -1
- package/dist/num/index.js +5 -1
- package/dist.commonjs/advancedBarrel.d.ts +1 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -0
- package/dist.commonjs/barrel.d.ts +1 -0
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +1 -0
- package/dist.commonjs/ckb/script.d.ts +1 -0
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.js +2 -1
- package/dist.commonjs/ckb/transaction.d.ts +3 -1
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +25 -2
- package/dist.commonjs/client/advanced.d.ts +0 -1
- package/dist.commonjs/client/advanced.d.ts.map +1 -1
- package/dist.commonjs/client/advanced.js +0 -1
- package/dist.commonjs/client/clientPublicMainnet.d.ts +3 -9
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts +3 -9
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/client.d.ts +160 -0
- package/dist.commonjs/client/jsonRpc/client.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/client.js +224 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +1 -182
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +15 -295
- package/dist.commonjs/jsonRpc/advanced.d.ts +2 -0
- package/dist.commonjs/jsonRpc/advanced.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/advanced.js +17 -0
- package/dist.commonjs/jsonRpc/index.d.ts +2 -0
- package/dist.commonjs/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/index.js +17 -0
- package/dist.commonjs/jsonRpc/requestor.d.ts +48 -0
- package/dist.commonjs/jsonRpc/requestor.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/requestor.js +111 -0
- package/dist.commonjs/jsonRpc/transports/advanced.d.ts +5 -0
- package/dist.commonjs/jsonRpc/transports/advanced.d.ts.map +1 -0
- package/dist.commonjs/{client → jsonRpc}/transports/advanced.js +1 -9
- package/dist.commonjs/{client/transports/advanced.d.ts → jsonRpc/transports/factory.d.ts} +1 -4
- package/dist.commonjs/jsonRpc/transports/factory.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/factory.js +11 -0
- package/dist.commonjs/jsonRpc/transports/http.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/transport.d.ts +18 -0
- package/dist.commonjs/jsonRpc/transports/transport.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/webSocket.d.ts.map +1 -0
- package/dist.commonjs/molecule/predefined.d.ts +12 -0
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
- package/dist.commonjs/molecule/predefined.js +30 -1
- package/dist.commonjs/num/index.d.ts.map +1 -1
- package/dist.commonjs/num/index.js +5 -1
- package/package.json +1 -1
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +1 -0
- package/src/ckb/script.ts +1 -0
- package/src/ckb/transaction.ts +52 -2
- package/src/client/advanced.ts +0 -1
- package/src/client/clientPublicMainnet.ts +2 -8
- package/src/client/clientPublicTestnet.ts +2 -8
- package/src/client/jsonRpc/client.ts +395 -0
- package/src/client/jsonRpc/index.ts +1 -490
- package/src/jsonRpc/advanced.ts +1 -0
- package/src/jsonRpc/index.ts +1 -0
- package/src/jsonRpc/requestor.ts +157 -0
- package/src/jsonRpc/transports/advanced.ts +4 -0
- package/src/{client/transports/advanced.ts → jsonRpc/transports/factory.ts} +0 -4
- package/src/jsonRpc/transports/transport.ts +18 -0
- package/src/molecule/predefined.ts +32 -0
- package/src/num/index.ts +5 -1
- package/dist/client/transports/advanced.d.ts.map +0 -1
- package/dist/client/transports/http.d.ts.map +0 -1
- package/dist/client/transports/transport.d.ts +0 -10
- package/dist/client/transports/transport.d.ts.map +0 -1
- package/dist/client/transports/webSocket.d.ts.map +0 -1
- package/dist.commonjs/client/transports/advanced.d.ts.map +0 -1
- package/dist.commonjs/client/transports/http.d.ts.map +0 -1
- package/dist.commonjs/client/transports/transport.d.ts +0 -10
- package/dist.commonjs/client/transports/transport.d.ts.map +0 -1
- package/dist.commonjs/client/transports/webSocket.d.ts.map +0 -1
- package/src/client/transports/transport.ts +0 -10
- /package/dist/{client → jsonRpc}/transports/http.d.ts +0 -0
- /package/dist/{client → jsonRpc}/transports/http.js +0 -0
- /package/dist/{client → jsonRpc}/transports/transport.js +0 -0
- /package/dist/{client → jsonRpc}/transports/webSocket.d.ts +0 -0
- /package/dist/{client → jsonRpc}/transports/webSocket.js +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/http.d.ts +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/http.js +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/transport.js +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/webSocket.d.ts +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/webSocket.js +0 -0
- /package/src/{client → jsonRpc}/transports/http.ts +0 -0
- /package/src/{client → jsonRpc}/transports/webSocket.ts +0 -0
|
@@ -1,183 +1,2 @@
|
|
|
1
|
-
|
|
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":"AAAA,
|
|
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.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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 @@
|
|
|
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 @@
|
|
|
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"}
|