@ckb-ccc/core 0.0.12 → 0.0.13-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +5 -2
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +17 -10
- package/dist/client/advanced.d.ts +1 -0
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +1 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +8 -2
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +5 -2
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +5 -2
- package/dist/client/clientTypes.d.ts +6 -1
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.d.ts +5 -4
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +5 -15
- package/dist/client/jsonRpc/transformers.d.ts +7 -2
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist/client/jsonRpc/transformers.js +7 -1
- package/dist/client/jsonRpc/types.d.ts +0 -6
- package/dist/client/jsonRpc/types.d.ts.map +1 -1
- package/dist/client/transports/advanced.d.ts +9 -0
- package/dist/client/transports/advanced.d.ts.map +1 -0
- package/dist/client/transports/advanced.js +11 -0
- package/dist/client/transports/http.d.ts +8 -0
- package/dist/client/transports/http.d.ts.map +1 -0
- package/dist/client/transports/http.js +20 -0
- package/dist/client/transports/transport.d.ts +10 -0
- package/dist/client/transports/transport.d.ts.map +1 -0
- package/dist/client/transports/transport.js +1 -0
- package/dist/client/transports/webSocket.d.ts +10 -0
- package/dist/client/transports/webSocket.d.ts.map +1 -0
- package/dist/client/transports/webSocket.js +61 -0
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +17 -10
- package/dist.commonjs/client/advanced.d.ts +1 -0
- package/dist.commonjs/client/advanced.d.ts.map +1 -1
- package/dist.commonjs/client/advanced.js +1 -0
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +8 -2
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +5 -2
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +5 -2
- package/dist.commonjs/client/clientTypes.d.ts +6 -1
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts +5 -4
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +15 -28
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +7 -2
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/transformers.js +35 -29
- package/dist.commonjs/client/jsonRpc/types.d.ts +0 -6
- package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -1
- package/dist.commonjs/client/transports/advanced.d.ts +9 -0
- package/dist.commonjs/client/transports/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/transports/advanced.js +29 -0
- package/dist.commonjs/client/transports/http.d.ts +8 -0
- package/dist.commonjs/client/transports/http.d.ts.map +1 -0
- package/dist.commonjs/client/transports/http.js +24 -0
- package/dist.commonjs/client/transports/transport.d.ts +10 -0
- package/dist.commonjs/client/transports/transport.d.ts.map +1 -0
- package/dist.commonjs/client/transports/transport.js +2 -0
- package/dist.commonjs/client/transports/webSocket.d.ts +10 -0
- package/dist.commonjs/client/transports/webSocket.d.ts.map +1 -0
- package/dist.commonjs/client/transports/webSocket.js +65 -0
- package/package.json +1 -1
- package/src/ckb/transaction.ts +24 -16
- package/src/client/advanced.ts +1 -0
- package/src/client/client.ts +9 -2
- package/src/client/clientPublicMainnet.ts +8 -2
- package/src/client/clientPublicTestnet.ts +8 -2
- package/src/client/clientTypes.ts +6 -0
- package/src/client/jsonRpc/index.ts +13 -19
- package/src/client/jsonRpc/transformers.ts +16 -3
- package/src/client/jsonRpc/types.ts +0 -7
- package/src/client/transports/advanced.ts +14 -0
- package/src/client/transports/http.ts +26 -0
- package/src/client/transports/transport.ts +10 -0
- package/src/client/transports/webSocket.ts +81 -0
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonRpcTransformers = void 0;
|
|
4
4
|
const index_js_1 = require("../../ckb/index.js");
|
|
5
|
-
const index_js_2 = require("../../
|
|
6
|
-
const index_js_3 = require("../../
|
|
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");
|
|
7
8
|
const clientTypes_js_1 = require("../clientTypes.js");
|
|
8
9
|
class JsonRpcTransformers {
|
|
9
10
|
static hashTypeFrom(hashType) {
|
|
@@ -46,7 +47,7 @@ class JsonRpcTransformers {
|
|
|
46
47
|
static outPointFrom(outPointLike) {
|
|
47
48
|
const outPoint = index_js_1.OutPoint.from(outPointLike);
|
|
48
49
|
return {
|
|
49
|
-
index: (0,
|
|
50
|
+
index: (0, index_js_3.numToHex)(outPoint.index),
|
|
50
51
|
tx_hash: outPoint.txHash,
|
|
51
52
|
};
|
|
52
53
|
}
|
|
@@ -60,7 +61,7 @@ class JsonRpcTransformers {
|
|
|
60
61
|
const cellInput = index_js_1.CellInput.from(cellInputLike);
|
|
61
62
|
return {
|
|
62
63
|
previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
|
|
63
|
-
since: (0,
|
|
64
|
+
since: (0, index_js_3.numToHex)(cellInput.since),
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
static cellInputTo(cellInput) {
|
|
@@ -71,16 +72,16 @@ class JsonRpcTransformers {
|
|
|
71
72
|
}
|
|
72
73
|
static cellOutputFrom(cellOutput) {
|
|
73
74
|
return {
|
|
74
|
-
capacity: (0,
|
|
75
|
+
capacity: (0, index_js_3.numToHex)(cellOutput.capacity),
|
|
75
76
|
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
76
|
-
type: (0,
|
|
77
|
+
type: (0, index_js_4.apply)(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
static cellOutputTo(cellOutput) {
|
|
80
81
|
return index_js_1.CellOutput.from({
|
|
81
82
|
capacity: cellOutput.capacity,
|
|
82
83
|
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
83
|
-
type: (0,
|
|
84
|
+
type: (0, index_js_4.apply)(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
static cellDepFrom(cellDep) {
|
|
@@ -98,7 +99,7 @@ class JsonRpcTransformers {
|
|
|
98
99
|
static transactionFrom(txLike) {
|
|
99
100
|
const tx = index_js_1.Transaction.from(txLike);
|
|
100
101
|
return {
|
|
101
|
-
version: (0,
|
|
102
|
+
version: (0, index_js_3.numToHex)(tx.version),
|
|
102
103
|
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
103
104
|
header_deps: tx.headerDeps,
|
|
104
105
|
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
@@ -118,29 +119,34 @@ class JsonRpcTransformers {
|
|
|
118
119
|
witnesses: tx.witnesses,
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
|
-
static transactionResponseTo({ tx_status: { status }, transaction, }) {
|
|
122
|
+
static transactionResponseTo({ cycles, tx_status: { status, block_number, block_hash, tx_index, reason }, transaction, }) {
|
|
122
123
|
if (transaction == null) {
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
return {
|
|
126
127
|
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
127
128
|
status,
|
|
129
|
+
cycles: (0, index_js_4.apply)(index_js_3.numFrom, cycles),
|
|
130
|
+
blockHash: (0, index_js_4.apply)(index_js_2.hexFrom, block_hash),
|
|
131
|
+
blockNumber: (0, index_js_4.apply)(index_js_3.numFrom, block_number),
|
|
132
|
+
txIndex: (0, index_js_4.apply)(index_js_3.numFrom, tx_index),
|
|
133
|
+
reason,
|
|
128
134
|
};
|
|
129
135
|
}
|
|
130
136
|
static blockHeaderTo(header) {
|
|
131
137
|
return {
|
|
132
|
-
compactTarget: (0,
|
|
138
|
+
compactTarget: (0, index_js_3.numFrom)(header.compact_target),
|
|
133
139
|
dao: header.dao,
|
|
134
|
-
epoch: (0,
|
|
140
|
+
epoch: (0, index_js_3.numFrom)(header.epoch),
|
|
135
141
|
extraHash: header.extra_hash,
|
|
136
142
|
hash: header.hash,
|
|
137
|
-
nonce: (0,
|
|
138
|
-
number: (0,
|
|
143
|
+
nonce: (0, index_js_3.numFrom)(header.nonce),
|
|
144
|
+
number: (0, index_js_3.numFrom)(header.number),
|
|
139
145
|
parentHash: header.parent_hash,
|
|
140
146
|
proposalsHash: header.proposals_hash,
|
|
141
|
-
timestamp: (0,
|
|
147
|
+
timestamp: (0, index_js_3.numFrom)(header.timestamp),
|
|
142
148
|
transactionsRoot: header.transactions_root,
|
|
143
|
-
version: (0,
|
|
149
|
+
version: (0, index_js_3.numFrom)(header.version),
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
152
|
static blockUncleTo(block) {
|
|
@@ -158,17 +164,17 @@ class JsonRpcTransformers {
|
|
|
158
164
|
};
|
|
159
165
|
}
|
|
160
166
|
static rangeFrom([a, b]) {
|
|
161
|
-
return [(0,
|
|
167
|
+
return [(0, index_js_3.numToHex)(a), (0, index_js_3.numToHex)(b)];
|
|
162
168
|
}
|
|
163
169
|
static indexerSearchKeyFilterFrom(filter) {
|
|
164
170
|
return {
|
|
165
|
-
script: (0,
|
|
166
|
-
script_len_range: (0,
|
|
171
|
+
script: (0, index_js_4.apply)(JsonRpcTransformers.scriptFrom, filter.script),
|
|
172
|
+
script_len_range: (0, index_js_4.apply)(JsonRpcTransformers.rangeFrom, filter.scriptLenRange),
|
|
167
173
|
output_data: filter.outputData,
|
|
168
174
|
output_data_filter_mode: filter.outputDataSearchMode,
|
|
169
|
-
output_data_len_range: (0,
|
|
170
|
-
output_capacity_range: (0,
|
|
171
|
-
block_range: (0,
|
|
175
|
+
output_data_len_range: (0, index_js_4.apply)(JsonRpcTransformers.rangeFrom, filter.outputDataLenRange),
|
|
176
|
+
output_capacity_range: (0, index_js_4.apply)(JsonRpcTransformers.rangeFrom, filter.outputCapacityRange),
|
|
177
|
+
block_range: (0, index_js_4.apply)(JsonRpcTransformers.rangeFrom, filter.blockRange),
|
|
172
178
|
};
|
|
173
179
|
}
|
|
174
180
|
static indexerSearchKeyFrom(keyLike) {
|
|
@@ -177,7 +183,7 @@ class JsonRpcTransformers {
|
|
|
177
183
|
script: JsonRpcTransformers.scriptFrom(key.script),
|
|
178
184
|
script_type: key.scriptType,
|
|
179
185
|
script_search_mode: key.scriptSearchMode,
|
|
180
|
-
filter: (0,
|
|
186
|
+
filter: (0, index_js_4.apply)(JsonRpcTransformers.indexerSearchKeyFilterFrom, key.filter),
|
|
181
187
|
with_data: key.withData,
|
|
182
188
|
};
|
|
183
189
|
}
|
|
@@ -197,7 +203,7 @@ class JsonRpcTransformers {
|
|
|
197
203
|
script: JsonRpcTransformers.scriptFrom(key.script),
|
|
198
204
|
script_type: key.scriptType,
|
|
199
205
|
script_search_mode: key.scriptSearchMode,
|
|
200
|
-
filter: (0,
|
|
206
|
+
filter: (0, index_js_4.apply)(JsonRpcTransformers.indexerSearchKeyFilterFrom, key.filter),
|
|
201
207
|
group_by_transaction: key.groupByTransaction,
|
|
202
208
|
};
|
|
203
209
|
}
|
|
@@ -213,9 +219,9 @@ class JsonRpcTransformers {
|
|
|
213
219
|
lastCursor: last_cursor,
|
|
214
220
|
transactions: objects.map((tx) => ({
|
|
215
221
|
txHash: tx.tx_hash,
|
|
216
|
-
blockNumber: (0,
|
|
217
|
-
txIndex: (0,
|
|
218
|
-
cellIndex: (0,
|
|
222
|
+
blockNumber: (0, index_js_3.numFrom)(tx.block_number),
|
|
223
|
+
txIndex: (0, index_js_3.numFrom)(tx.tx_index),
|
|
224
|
+
cellIndex: (0, index_js_3.numFrom)(tx.io_index),
|
|
219
225
|
isInput: tx.io_type === "input",
|
|
220
226
|
})),
|
|
221
227
|
};
|
|
@@ -224,11 +230,11 @@ class JsonRpcTransformers {
|
|
|
224
230
|
lastCursor: last_cursor,
|
|
225
231
|
transactions: objects.map((tx) => ({
|
|
226
232
|
txHash: tx.tx_hash,
|
|
227
|
-
blockNumber: (0,
|
|
228
|
-
txIndex: (0,
|
|
233
|
+
blockNumber: (0, index_js_3.numFrom)(tx.block_number),
|
|
234
|
+
txIndex: (0, index_js_3.numFrom)(tx.tx_index),
|
|
229
235
|
cells: tx.cells.map(([type, i]) => ({
|
|
230
236
|
isInput: type === "input",
|
|
231
|
-
cellIndex: (0,
|
|
237
|
+
cellIndex: (0, index_js_3.numFrom)(i),
|
|
232
238
|
})),
|
|
233
239
|
})),
|
|
234
240
|
};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { Hex } from "../../hex/index.js";
|
|
2
|
-
export type JsonRpcPayload = {
|
|
3
|
-
id: number;
|
|
4
|
-
jsonrpc: "2.0";
|
|
5
|
-
method: string;
|
|
6
|
-
params: unknown[] | Record<string, unknown>;
|
|
7
|
-
};
|
|
8
2
|
export type JsonRpcHashType = "type" | "data" | "data1" | "data2";
|
|
9
3
|
export type JsonRpcDepType = "dep_group" | "code";
|
|
10
4
|
export type JsonRpcScript = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,MAAM,MAAM,
|
|
1
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,MAAM,CAAC,EAAE,6BAA6B,CAAC;IACvC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;IACpD,MAAM,CAAC,EAAE,6BAA6B,CAAC;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QACP,OAAO,EAAE,GAAG,CAAC;QACb,YAAY,EAAE,GAAG,CAAC;QAClB,QAAQ,EAAE,GAAG,CAAC;QACd,OAAO,EAAE,OAAO,GAAG,QAAQ,CAAC;QAC5B,QAAQ,EAAE,GAAG,CAAC;KACf,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,6CAA6C,GAAG;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QACP,OAAO,EAAE,GAAG,CAAC;QACb,YAAY,EAAE,GAAG,CAAC;QAClB,QAAQ,EAAE,GAAG,CAAC;QACd,KAAK,EAAE,CAAC,OAAO,GAAG,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;KACpC,EAAE,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TransportHttp } from "./http.js";
|
|
2
|
+
import { TransportWebSocket } from "./webSocket.js";
|
|
3
|
+
export * from "./http.js";
|
|
4
|
+
export * from "./transport.js";
|
|
5
|
+
export * from "./webSocket.js";
|
|
6
|
+
export declare function transportFromUri(uri: string, config?: {
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}): TransportHttp | TransportWebSocket;
|
|
9
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../../src/client/transports/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,sCAM1E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
exports.transportFromUri = void 0;
|
|
18
|
+
const http_js_1 = require("./http.js");
|
|
19
|
+
const webSocket_js_1 = require("./webSocket.js");
|
|
20
|
+
__exportStar(require("./http.js"), exports);
|
|
21
|
+
__exportStar(require("./transport.js"), exports);
|
|
22
|
+
__exportStar(require("./webSocket.js"), exports);
|
|
23
|
+
function transportFromUri(uri, config) {
|
|
24
|
+
if (uri.startsWith("wss://")) {
|
|
25
|
+
return new webSocket_js_1.TransportWebSocket(uri, config?.timeout);
|
|
26
|
+
}
|
|
27
|
+
return new http_js_1.TransportHttp(uri, config?.timeout);
|
|
28
|
+
}
|
|
29
|
+
exports.transportFromUri = transportFromUri;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JsonRpcPayload, Transport } from "./transport.js";
|
|
2
|
+
export declare class TransportHttp implements Transport {
|
|
3
|
+
private readonly url;
|
|
4
|
+
private readonly timeout;
|
|
5
|
+
constructor(url: string, timeout?: number);
|
|
6
|
+
request(payload: JsonRpcPayload): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/client/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3D,qBAAa,aAAc,YAAW,SAAS;IAE3C,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,GAAG,EAAE,MAAM,EACX,OAAO,SAAQ;IAG5B,OAAO,CAAC,OAAO,EAAE,cAAc;CAiBtC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransportHttp = void 0;
|
|
4
|
+
class TransportHttp {
|
|
5
|
+
constructor(url, timeout = 30000) {
|
|
6
|
+
this.url = url;
|
|
7
|
+
this.timeout = timeout;
|
|
8
|
+
}
|
|
9
|
+
async request(payload) {
|
|
10
|
+
const aborter = new AbortController();
|
|
11
|
+
const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
|
|
12
|
+
const raw = await (await fetch(this.url, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: {
|
|
15
|
+
"content-type": "application/json",
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify(payload),
|
|
18
|
+
signal: aborter.signal,
|
|
19
|
+
})).json();
|
|
20
|
+
clearTimeout(abortTimer);
|
|
21
|
+
return raw;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TransportHttp = TransportHttp;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type JsonRpcPayload = {
|
|
2
|
+
id: number;
|
|
3
|
+
jsonrpc: "2.0";
|
|
4
|
+
method: string;
|
|
5
|
+
params: unknown[] | Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export interface Transport {
|
|
8
|
+
request(data: JsonRpcPayload): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/client/transports/transport.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JsonRpcPayload, Transport } from "./transport.js";
|
|
2
|
+
export declare class TransportWebSocket implements Transport {
|
|
3
|
+
private readonly url;
|
|
4
|
+
private readonly timeout;
|
|
5
|
+
private ongoing;
|
|
6
|
+
private socket?;
|
|
7
|
+
constructor(url: string, timeout?: number);
|
|
8
|
+
request(data: JsonRpcPayload): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=webSocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webSocket.d.ts","sourceRoot":"","sources":["../../../src/client/transports/webSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3D,qBAAa,kBAAmB,YAAW,SAAS;IAYhD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZ1B,OAAO,CAAC,OAAO,CAOD;IACd,OAAO,CAAC,MAAM,CAAC,CAAqB;gBAGjB,GAAG,EAAE,MAAM,EACX,OAAO,SAAQ;IAG5B,OAAO,CAAC,IAAI,EAAE,cAAc;CA8DnC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransportWebSocket = void 0;
|
|
4
|
+
class TransportWebSocket {
|
|
5
|
+
constructor(url, timeout = 30000) {
|
|
6
|
+
this.url = url;
|
|
7
|
+
this.timeout = timeout;
|
|
8
|
+
this.ongoing = new Map();
|
|
9
|
+
}
|
|
10
|
+
async request(data) {
|
|
11
|
+
const socket = (() => {
|
|
12
|
+
if (this.socket) {
|
|
13
|
+
return this.socket;
|
|
14
|
+
}
|
|
15
|
+
const socket = new WebSocket(this.url);
|
|
16
|
+
const onMessage = ({ data }) => {
|
|
17
|
+
const res = JSON.parse(data);
|
|
18
|
+
if (typeof res !== "object" || res === null) {
|
|
19
|
+
throw new Error(`Unknown response ${data}`);
|
|
20
|
+
}
|
|
21
|
+
const req = this.ongoing.get(res.id);
|
|
22
|
+
if (!req) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
clearTimeout(req[2]);
|
|
26
|
+
this.ongoing.delete(res.id);
|
|
27
|
+
req[0](res);
|
|
28
|
+
};
|
|
29
|
+
const onClose = (error) => {
|
|
30
|
+
this.socket = undefined;
|
|
31
|
+
this.ongoing.forEach(([_, onError]) => onError(error ?? new Error("Connection closed")));
|
|
32
|
+
this.ongoing.clear();
|
|
33
|
+
};
|
|
34
|
+
socket.onclose = onClose;
|
|
35
|
+
socket.onerror = onClose;
|
|
36
|
+
socket.onmessage = onMessage;
|
|
37
|
+
this.socket = new Promise((resolve) => {
|
|
38
|
+
if (socket.readyState === socket.CONNECTING) {
|
|
39
|
+
socket.onopen = resolve;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
resolve(undefined);
|
|
43
|
+
}
|
|
44
|
+
}).then(() => socket);
|
|
45
|
+
return this.socket;
|
|
46
|
+
})();
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
this.ongoing.set(data.id, [
|
|
49
|
+
resolve,
|
|
50
|
+
reject,
|
|
51
|
+
setTimeout(() => reject(new Error("Request timeout")), this.timeout),
|
|
52
|
+
]);
|
|
53
|
+
socket.then((socket) => {
|
|
54
|
+
if (socket.readyState === socket.CLOSED ||
|
|
55
|
+
socket.readyState === socket.CLOSING) {
|
|
56
|
+
reject(new Error("Connection closed"));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
socket.send(JSON.stringify(data));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.TransportWebSocket = TransportWebSocket;
|
package/package.json
CHANGED
package/src/ckb/transaction.ts
CHANGED
|
@@ -1538,8 +1538,9 @@ export class Transaction {
|
|
|
1538
1538
|
}> {
|
|
1539
1539
|
const scripts = (await from.getAddressObjs()).map(({ script }) => script);
|
|
1540
1540
|
const collectedCells = [];
|
|
1541
|
-
let acc: T = init;
|
|
1542
1541
|
|
|
1542
|
+
let acc: T = init;
|
|
1543
|
+
let fulfilled = false;
|
|
1543
1544
|
for (const script of scripts) {
|
|
1544
1545
|
for await (const cell of from.client.findCellsByCollectableSearchKey({
|
|
1545
1546
|
script,
|
|
@@ -1556,26 +1557,33 @@ export class Transaction {
|
|
|
1556
1557
|
continue;
|
|
1557
1558
|
}
|
|
1558
1559
|
const i = collectedCells.push(cell);
|
|
1559
|
-
const next
|
|
1560
|
+
const next = await Promise.resolve(
|
|
1560
1561
|
accumulator(acc, cell, i - 1, collectedCells),
|
|
1561
1562
|
);
|
|
1562
1563
|
if (next === undefined) {
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
CellInput.from({
|
|
1566
|
-
previousOutput: outPoint,
|
|
1567
|
-
since: 0,
|
|
1568
|
-
outputData,
|
|
1569
|
-
cellOutput,
|
|
1570
|
-
}),
|
|
1571
|
-
),
|
|
1572
|
-
);
|
|
1573
|
-
return {
|
|
1574
|
-
addedCount: collectedCells.length,
|
|
1575
|
-
};
|
|
1564
|
+
fulfilled = true;
|
|
1565
|
+
break;
|
|
1576
1566
|
}
|
|
1577
|
-
acc = next;
|
|
1578
1567
|
}
|
|
1568
|
+
if (fulfilled) {
|
|
1569
|
+
break;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
this.inputs.push(
|
|
1574
|
+
...collectedCells.map(({ outPoint, outputData, cellOutput }) =>
|
|
1575
|
+
CellInput.from({
|
|
1576
|
+
previousOutput: outPoint,
|
|
1577
|
+
since: 0,
|
|
1578
|
+
outputData,
|
|
1579
|
+
cellOutput,
|
|
1580
|
+
}),
|
|
1581
|
+
),
|
|
1582
|
+
);
|
|
1583
|
+
if (fulfilled) {
|
|
1584
|
+
return {
|
|
1585
|
+
addedCount: collectedCells.length,
|
|
1586
|
+
};
|
|
1579
1587
|
}
|
|
1580
1588
|
|
|
1581
1589
|
return {
|
package/src/client/advanced.ts
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -530,7 +530,7 @@ export abstract class Client {
|
|
|
530
530
|
): Promise<ClientTransactionResponse | undefined> {
|
|
531
531
|
const txHash = hexFrom(txHashLike);
|
|
532
532
|
const res = await this.getTransactionNoCache(txHash);
|
|
533
|
-
if (res
|
|
533
|
+
if (res?.transaction) {
|
|
534
534
|
return res;
|
|
535
535
|
}
|
|
536
536
|
|
|
@@ -539,9 +539,16 @@ export abstract class Client {
|
|
|
539
539
|
return;
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
+
if (!res) {
|
|
543
|
+
return {
|
|
544
|
+
transaction: tx,
|
|
545
|
+
status: "sent",
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
542
549
|
return {
|
|
550
|
+
...res,
|
|
543
551
|
transaction: tx,
|
|
544
|
-
status: "proposed",
|
|
545
552
|
};
|
|
546
553
|
}
|
|
547
554
|
}
|
|
@@ -8,11 +8,17 @@ import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export class ClientPublicMainnet extends ClientJsonRpc {
|
|
10
10
|
constructor(
|
|
11
|
-
url
|
|
11
|
+
url?: string,
|
|
12
12
|
timeout?: number,
|
|
13
13
|
private readonly scripts = MAINNET_SCRIPTS,
|
|
14
14
|
) {
|
|
15
|
-
super(
|
|
15
|
+
super(
|
|
16
|
+
url ??
|
|
17
|
+
(typeof WebSocket !== "undefined"
|
|
18
|
+
? "wss://mainnet.ckb.dev/ws"
|
|
19
|
+
: "https://mainnet.ckb.dev/"),
|
|
20
|
+
timeout,
|
|
21
|
+
);
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
get addressPrefix(): string {
|
|
@@ -8,11 +8,17 @@ import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export class ClientPublicTestnet extends ClientJsonRpc {
|
|
10
10
|
constructor(
|
|
11
|
-
url
|
|
11
|
+
url?: string,
|
|
12
12
|
timeout?: number,
|
|
13
13
|
private readonly scripts = TESTNET_SCRIPTS,
|
|
14
14
|
) {
|
|
15
|
-
super(
|
|
15
|
+
super(
|
|
16
|
+
url ??
|
|
17
|
+
(typeof WebSocket !== "undefined"
|
|
18
|
+
? "wss://testnet.ckb.dev/ws"
|
|
19
|
+
: "https://testnet.ckb.dev/"),
|
|
20
|
+
timeout,
|
|
21
|
+
);
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
get addressPrefix(): string {
|
|
@@ -17,6 +17,7 @@ export type OutputsValidator = "passthrough" | "well_known_scripts_only";
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export type TransactionStatus =
|
|
20
|
+
| "sent"
|
|
20
21
|
| "pending"
|
|
21
22
|
| "proposed"
|
|
22
23
|
| "committed"
|
|
@@ -28,6 +29,11 @@ export type TransactionStatus =
|
|
|
28
29
|
export type ClientTransactionResponse = {
|
|
29
30
|
transaction: Transaction;
|
|
30
31
|
status: TransactionStatus;
|
|
32
|
+
cycles?: Num;
|
|
33
|
+
blockHash?: Hex;
|
|
34
|
+
blockNumber?: Num;
|
|
35
|
+
txIndex?: Num;
|
|
36
|
+
reason?: string;
|
|
31
37
|
};
|
|
32
38
|
|
|
33
39
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fetch from "cross-fetch";
|
|
2
1
|
import { apply } from "../../barrel.js";
|
|
3
2
|
import { TransactionLike } from "../../ckb/index.js";
|
|
4
3
|
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
@@ -10,7 +9,12 @@ import {
|
|
|
10
9
|
ClientTransactionResponse,
|
|
11
10
|
OutputsValidator,
|
|
12
11
|
} from "../clientTypes.js";
|
|
13
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
JsonRpcPayload,
|
|
14
|
+
Transport,
|
|
15
|
+
transportFromUri,
|
|
16
|
+
} from "../transports/advanced.js";
|
|
17
|
+
import { JsonRpcTransformers } from "./advanced.js";
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* Applies a transformation function to a value if the transformer is provided.
|
|
@@ -42,18 +46,22 @@ async function transform(
|
|
|
42
46
|
*/
|
|
43
47
|
|
|
44
48
|
export abstract class ClientJsonRpc extends Client {
|
|
49
|
+
private readonly transport: Transport;
|
|
50
|
+
|
|
45
51
|
/**
|
|
46
52
|
* Creates an instance of ClientJsonRpc.
|
|
47
53
|
*
|
|
48
54
|
* @param url_ - The URL of the JSON-RPC server.
|
|
49
|
-
* @param timeout - The timeout for requests in milliseconds
|
|
55
|
+
* @param timeout - The timeout for requests in milliseconds
|
|
50
56
|
*/
|
|
51
57
|
|
|
52
58
|
constructor(
|
|
53
59
|
private readonly url_: string,
|
|
54
|
-
private readonly timeout
|
|
60
|
+
private readonly timeout?: number,
|
|
55
61
|
) {
|
|
56
62
|
super();
|
|
63
|
+
|
|
64
|
+
this.transport = transportFromUri(url_);
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
/**
|
|
@@ -232,22 +240,8 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
232
240
|
*
|
|
233
241
|
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
234
242
|
*/
|
|
235
|
-
|
|
236
243
|
async send(payload: JsonRpcPayload): Promise<unknown> {
|
|
237
|
-
const
|
|
238
|
-
const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
|
|
239
|
-
|
|
240
|
-
const raw = await fetch(this.url, {
|
|
241
|
-
method: "POST",
|
|
242
|
-
headers: {
|
|
243
|
-
"content-type": "application/json",
|
|
244
|
-
},
|
|
245
|
-
body: JSON.stringify(payload),
|
|
246
|
-
signal: aborter.signal,
|
|
247
|
-
});
|
|
248
|
-
clearTimeout(abortTimer);
|
|
249
|
-
|
|
250
|
-
const res = (await raw.json()) as {
|
|
244
|
+
const res = (await this.transport.request(payload)) as {
|
|
251
245
|
id: number;
|
|
252
246
|
error: unknown;
|
|
253
247
|
result: unknown;
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
depTypeFrom,
|
|
20
20
|
hashTypeFrom,
|
|
21
21
|
} from "../../ckb/index.js";
|
|
22
|
-
import { Hex } from "../../hex/index.js";
|
|
22
|
+
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
23
23
|
import { NumLike, numFrom, numToHex } from "../../num/index.js";
|
|
24
24
|
import { apply } from "../../utils/index.js";
|
|
25
25
|
import {
|
|
@@ -172,10 +172,18 @@ export class JsonRpcTransformers {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
static transactionResponseTo({
|
|
175
|
-
|
|
175
|
+
cycles,
|
|
176
|
+
tx_status: { status, block_number, block_hash, tx_index, reason },
|
|
176
177
|
transaction,
|
|
177
178
|
}: {
|
|
178
|
-
|
|
179
|
+
cycles?: NumLike;
|
|
180
|
+
tx_status: {
|
|
181
|
+
status: TransactionStatus;
|
|
182
|
+
block_hash?: HexLike;
|
|
183
|
+
tx_index?: NumLike;
|
|
184
|
+
block_number?: NumLike;
|
|
185
|
+
reason?: string;
|
|
186
|
+
};
|
|
179
187
|
transaction: JsonRpcTransaction | null;
|
|
180
188
|
}): ClientTransactionResponse | undefined {
|
|
181
189
|
if (transaction == null) {
|
|
@@ -185,6 +193,11 @@ export class JsonRpcTransformers {
|
|
|
185
193
|
return {
|
|
186
194
|
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
187
195
|
status,
|
|
196
|
+
cycles: apply(numFrom, cycles),
|
|
197
|
+
blockHash: apply(hexFrom, block_hash),
|
|
198
|
+
blockNumber: apply(numFrom, block_number),
|
|
199
|
+
txIndex: apply(numFrom, tx_index),
|
|
200
|
+
reason,
|
|
188
201
|
};
|
|
189
202
|
}
|
|
190
203
|
static blockHeaderTo(header: JsonRpcBlockHeader): ClientBlockHeader {
|