@ckb-ccc/core 0.1.0-alpha.7 → 0.1.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 +27 -0
- package/dist/ckb/transactionLumos.d.ts +2 -1
- package/dist/ckb/transactionLumos.d.ts.map +1 -1
- package/dist/client/client.js +1 -1
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +2 -3
- package/dist/signer/btc/verify.d.ts +14 -1
- package/dist/signer/btc/verify.d.ts.map +1 -1
- package/dist/signer/btc/verify.js +22 -1
- package/dist/signer/doge/index.d.ts +5 -0
- package/dist/signer/doge/index.d.ts.map +1 -0
- package/dist/signer/doge/index.js +4 -0
- package/dist/signer/doge/signerDoge.d.ts +52 -0
- package/dist/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist/signer/doge/signerDoge.js +82 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist/signer/doge/verify.d.ts +6 -0
- package/dist/signer/doge/verify.d.ts.map +1 -0
- package/dist/signer/doge/verify.js +17 -0
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +1 -0
- package/dist/signer/nostr/index.d.ts +1 -0
- package/dist/signer/nostr/index.d.ts.map +1 -1
- package/dist/signer/nostr/index.js +1 -0
- package/dist/signer/signer/index.d.ts +4 -2
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +5 -0
- package/dist.commonjs/address/address.advanced.js +23 -28
- package/dist.commonjs/address/advanced.js +1 -17
- package/dist.commonjs/address/index.js +11 -15
- package/dist.commonjs/advanced.js +2 -31
- package/dist.commonjs/advancedBarrel.js +5 -21
- package/dist.commonjs/barrel.js +12 -41
- package/dist.commonjs/bytes/advanced.js +1 -2
- package/dist.commonjs/bytes/index.js +7 -12
- package/dist.commonjs/ckb/advanced.js +3 -32
- package/dist.commonjs/ckb/index.js +3 -19
- package/dist.commonjs/ckb/molecule.advanced/generated.js +64 -131
- package/dist.commonjs/ckb/molecule.advanced/index.js +2 -19
- package/dist.commonjs/ckb/script.advanced.js +3 -6
- package/dist.commonjs/ckb/script.js +23 -53
- package/dist.commonjs/ckb/transaction.advanced.js +3 -6
- package/dist.commonjs/ckb/transaction.js +122 -163
- package/dist.commonjs/ckb/transactionLumos.d.ts +2 -1
- package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -1
- package/dist.commonjs/ckb/transactionLumos.js +1 -2
- package/dist.commonjs/client/advanced.js +6 -22
- package/dist.commonjs/client/cache/advanced.js +1 -17
- package/dist.commonjs/client/cache/cache.js +3 -7
- package/dist.commonjs/client/cache/index.js +2 -18
- package/dist.commonjs/client/cache/memory.advanced.js +21 -28
- package/dist.commonjs/client/cache/memory.js +19 -23
- package/dist.commonjs/client/client.js +22 -26
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicMainnet.js +8 -15
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicTestnet.js +8 -15
- package/dist.commonjs/client/clientTypes.advanced.js +3 -6
- package/dist.commonjs/client/clientTypes.js +29 -43
- package/dist.commonjs/client/index.js +6 -22
- package/dist.commonjs/client/jsonRpc/advanced.js +2 -18
- package/dist.commonjs/client/jsonRpc/index.js +37 -41
- package/dist.commonjs/client/jsonRpc/transformers.js +57 -61
- package/dist.commonjs/client/jsonRpc/types.js +1 -2
- package/dist.commonjs/client/transports/advanced.js +8 -25
- package/dist.commonjs/client/transports/http.js +1 -5
- package/dist.commonjs/client/transports/transport.js +1 -2
- package/dist.commonjs/client/transports/webSocket.js +3 -10
- package/dist.commonjs/fixedPoint/index.js +4 -9
- package/dist.commonjs/hasher/advanced.js +1 -4
- package/dist.commonjs/hasher/hasher.js +1 -2
- package/dist.commonjs/hasher/hasherCkb.js +14 -20
- package/dist.commonjs/hasher/hasherKeecak256.js +7 -11
- package/dist.commonjs/hasher/index.js +3 -19
- package/dist.commonjs/hex/index.js +3 -6
- package/dist.commonjs/index.js +2 -31
- package/dist.commonjs/keystore/index.js +21 -25
- package/dist.commonjs/molecule/codec.js +48 -63
- package/dist.commonjs/molecule/index.js +2 -18
- package/dist.commonjs/molecule/predefined.js +77 -103
- package/dist.commonjs/num/index.js +17 -29
- package/dist.commonjs/signer/btc/index.js +3 -19
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +20 -25
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +4 -8
- package/dist.commonjs/signer/btc/verify.d.ts +14 -1
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/verify.js +29 -11
- package/dist.commonjs/signer/ckb/index.js +5 -21
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +16 -20
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +20 -24
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +8 -12
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +12 -16
- package/dist.commonjs/signer/ckb/verifyJoyId.js +5 -8
- package/dist.commonjs/signer/doge/index.d.ts +5 -0
- package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/index.js +4 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDoge.js +82 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist.commonjs/signer/doge/verify.d.ts +6 -0
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/verify.js +17 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +2 -6
- package/dist.commonjs/signer/dummy/dummy.js +3 -7
- package/dist.commonjs/signer/dummy/index.js +3 -19
- package/dist.commonjs/signer/dummy/openLink.js +2 -6
- package/dist.commonjs/signer/evm/index.js +3 -19
- package/dist.commonjs/signer/evm/signerEvm.js +31 -35
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +4 -8
- package/dist.commonjs/signer/evm/verify.js +4 -7
- package/dist.commonjs/signer/index.d.ts +1 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/index.js +7 -22
- package/dist.commonjs/signer/nostr/index.d.ts +1 -0
- package/dist.commonjs/signer/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/signer/nostr/index.js +2 -17
- package/dist.commonjs/signer/nostr/signerNostr.js +21 -25
- package/dist.commonjs/signer/nostr/verify.js +12 -16
- package/dist.commonjs/signer/signer/index.d.ts +4 -2
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +22 -23
- package/dist.commonjs/utils/index.js +6 -12
- package/package.json +3 -1
- package/src/ckb/transactionLumos.ts +2 -1
- package/src/client/client.ts +1 -1
- package/src/signer/btc/signerBtc.ts +2 -3
- package/src/signer/btc/verify.ts +31 -2
- package/src/signer/doge/index.ts +4 -0
- package/src/signer/doge/signerDoge.ts +116 -0
- package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
- package/src/signer/doge/signerDogePrivateKey.ts +97 -0
- package/src/signer/doge/verify.ts +38 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/nostr/index.ts +1 -0
- package/src/signer/signer/index.ts +9 -0
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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");
|
|
1
|
+
import { Cell, OutPoint, } from "../../ckb/index.js";
|
|
2
|
+
import { hexFrom } from "../../hex/index.js";
|
|
3
|
+
import { numFrom, numToHex } from "../../num/index.js";
|
|
4
|
+
import { apply } from "../../utils/index.js";
|
|
5
|
+
import { Client } from "../client.js";
|
|
6
|
+
import { ErrorClientBase, ErrorClientDuplicatedTransaction, ErrorClientRBFRejected, ErrorClientResolveUnknown, ErrorClientVerification, } from "../clientTypes.js";
|
|
7
|
+
import { transportFromUri, } from "../transports/advanced.js";
|
|
8
|
+
import { JsonRpcTransformers, } from "./advanced.js";
|
|
12
9
|
/**
|
|
13
10
|
* Applies a transformation function to a value if the transformer is provided.
|
|
14
11
|
*
|
|
@@ -31,11 +28,11 @@ function transform(value, transformer) {
|
|
|
31
28
|
const ERROR_PARSERS = [
|
|
32
29
|
[
|
|
33
30
|
"Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)",
|
|
34
|
-
(error, match) => new
|
|
31
|
+
(error, match) => new ErrorClientResolveUnknown(error, OutPoint.fromBytes(match[1])),
|
|
35
32
|
],
|
|
36
33
|
[
|
|
37
34
|
"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
|
|
35
|
+
(error, match) => new ErrorClientVerification(error, match[3] === "Lock"
|
|
39
36
|
? "lock"
|
|
40
37
|
: match[1] === "Inputs"
|
|
41
38
|
? "inputType"
|
|
@@ -43,18 +40,18 @@ const ERROR_PARSERS = [
|
|
|
43
40
|
],
|
|
44
41
|
[
|
|
45
42
|
"Duplicated\\(Byte32\\((0x.*)\\)\\)",
|
|
46
|
-
(error, match) => new
|
|
43
|
+
(error, match) => new ErrorClientDuplicatedTransaction(error, match[1]),
|
|
47
44
|
],
|
|
48
45
|
[
|
|
49
46
|
'RBFRejected\\("Tx\'s current fee is ([0-9]*), expect it to >= ([0-9]*) to replace old txs"\\)',
|
|
50
|
-
(error, match) => new
|
|
47
|
+
(error, match) => new ErrorClientRBFRejected(error, match[1], match[2]),
|
|
51
48
|
],
|
|
52
49
|
];
|
|
53
50
|
/**
|
|
54
51
|
* An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
|
|
55
52
|
* Provides methods for sending transactions and building JSON-RPC payloads.
|
|
56
53
|
*/
|
|
57
|
-
class ClientJsonRpc extends
|
|
54
|
+
export class ClientJsonRpc extends Client {
|
|
58
55
|
/**
|
|
59
56
|
* Creates an instance of ClientJsonRpc.
|
|
60
57
|
*
|
|
@@ -70,23 +67,23 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
70
67
|
*
|
|
71
68
|
* @returns Fee rate statistics
|
|
72
69
|
*/
|
|
73
|
-
this.getFeeRateStatistics = this.buildSender("get_fee_rate_statistics", [(n) =>
|
|
74
|
-
mean:
|
|
75
|
-
median:
|
|
70
|
+
this.getFeeRateStatistics = this.buildSender("get_fee_rate_statistics", [(n) => apply(numFrom, n)], ({ mean, median }) => ({
|
|
71
|
+
mean: numFrom(mean),
|
|
72
|
+
median: numFrom(median),
|
|
76
73
|
}));
|
|
77
74
|
/**
|
|
78
75
|
* Get tip block number
|
|
79
76
|
*
|
|
80
77
|
* @returns Tip block number
|
|
81
78
|
*/
|
|
82
|
-
this.getTip = this.buildSender("get_tip_block_number", [],
|
|
79
|
+
this.getTip = this.buildSender("get_tip_block_number", [], numFrom);
|
|
83
80
|
/**
|
|
84
81
|
* Get tip block header
|
|
85
82
|
*
|
|
86
83
|
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
87
84
|
* @returns BlockHeader
|
|
88
85
|
*/
|
|
89
|
-
this.getTipHeader = this.buildSender("get_tip_header", [], (b) =>
|
|
86
|
+
this.getTipHeader = this.buildSender("get_tip_header", [], (b) => apply(JsonRpcTransformers.blockHeaderTo, b));
|
|
90
87
|
/**
|
|
91
88
|
* Get block by block number
|
|
92
89
|
*
|
|
@@ -95,7 +92,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
95
92
|
* @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
|
|
96
93
|
* @returns Block
|
|
97
94
|
*/
|
|
98
|
-
this.getBlockByNumber = this.buildSender("get_block_by_number", [(v) =>
|
|
95
|
+
this.getBlockByNumber = this.buildSender("get_block_by_number", [(v) => numToHex(numFrom(v))], (b) => apply(JsonRpcTransformers.blockTo, b));
|
|
99
96
|
/**
|
|
100
97
|
* Get block by block hash
|
|
101
98
|
*
|
|
@@ -104,7 +101,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
104
101
|
* @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
|
|
105
102
|
* @returns Block
|
|
106
103
|
*/
|
|
107
|
-
this.getBlockByHash = this.buildSender("get_block", [
|
|
104
|
+
this.getBlockByHash = this.buildSender("get_block", [hexFrom], (b) => apply(JsonRpcTransformers.blockTo, b));
|
|
108
105
|
/**
|
|
109
106
|
* Get header by block number
|
|
110
107
|
*
|
|
@@ -112,7 +109,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
112
109
|
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
113
110
|
* @returns BlockHeader
|
|
114
111
|
*/
|
|
115
|
-
this.getHeaderByNumber = this.buildSender("get_header_by_number", [(v) =>
|
|
112
|
+
this.getHeaderByNumber = this.buildSender("get_header_by_number", [(v) => numToHex(numFrom(v))], (b) => apply(JsonRpcTransformers.blockHeaderTo, b));
|
|
116
113
|
/**
|
|
117
114
|
* Get header by block hash
|
|
118
115
|
*
|
|
@@ -120,14 +117,14 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
120
117
|
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
121
118
|
* @returns BlockHeader
|
|
122
119
|
*/
|
|
123
|
-
this.getHeaderByHash = this.buildSender("get_header", [
|
|
120
|
+
this.getHeaderByHash = this.buildSender("get_header", [hexFrom], (b) => apply(JsonRpcTransformers.blockHeaderTo, b));
|
|
124
121
|
/**
|
|
125
122
|
* Estimate cycles of a transaction.
|
|
126
123
|
*
|
|
127
124
|
* @param transaction - The transaction to estimate.
|
|
128
125
|
* @returns Consumed cycles
|
|
129
126
|
*/
|
|
130
|
-
this.estimateCycles = this.buildSender("estimate_cycles", [
|
|
127
|
+
this.estimateCycles = this.buildSender("estimate_cycles", [JsonRpcTransformers.transactionFrom], ({ cycles }) => numFrom(cycles));
|
|
131
128
|
/**
|
|
132
129
|
* Test a transaction.
|
|
133
130
|
*
|
|
@@ -135,7 +132,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
135
132
|
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
136
133
|
* @returns Consumed cycles
|
|
137
134
|
*/
|
|
138
|
-
this.sendTransactionDry = this.buildSender("test_tx_pool_accept", [
|
|
135
|
+
this.sendTransactionDry = this.buildSender("test_tx_pool_accept", [JsonRpcTransformers.transactionFrom], ({ cycles }) => numFrom(cycles));
|
|
139
136
|
/**
|
|
140
137
|
* Send a transaction to node.
|
|
141
138
|
*
|
|
@@ -143,14 +140,14 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
143
140
|
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
144
141
|
* @returns Transaction hash.
|
|
145
142
|
*/
|
|
146
|
-
this.sendTransactionNoCache = this.buildSender("send_transaction", [
|
|
143
|
+
this.sendTransactionNoCache = this.buildSender("send_transaction", [JsonRpcTransformers.transactionFrom], hexFrom);
|
|
147
144
|
/**
|
|
148
145
|
* Get a transaction from node.
|
|
149
146
|
*
|
|
150
147
|
* @param txHash - The hash of the transaction.
|
|
151
148
|
* @returns The transaction with status.
|
|
152
149
|
*/
|
|
153
|
-
this.getTransactionNoCache = this.buildSender("get_transaction", [
|
|
150
|
+
this.getTransactionNoCache = this.buildSender("get_transaction", [hexFrom], JsonRpcTransformers.transactionResponseTo);
|
|
154
151
|
/**
|
|
155
152
|
* find cells from node.
|
|
156
153
|
*
|
|
@@ -161,10 +158,10 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
161
158
|
* @returns The found cells.
|
|
162
159
|
*/
|
|
163
160
|
this.findCellsPagedNoCache = this.buildSender("get_cells", [
|
|
164
|
-
|
|
161
|
+
JsonRpcTransformers.indexerSearchKeyFrom,
|
|
165
162
|
(order) => order ?? "asc",
|
|
166
|
-
(limit) =>
|
|
167
|
-
],
|
|
163
|
+
(limit) => numToHex(limit ?? 10),
|
|
164
|
+
], JsonRpcTransformers.findCellsResponseTo);
|
|
168
165
|
/**
|
|
169
166
|
* find transactions from node.
|
|
170
167
|
*
|
|
@@ -175,18 +172,18 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
175
172
|
* @returns The found transactions.
|
|
176
173
|
*/
|
|
177
174
|
this.findTransactionsPaged = this.buildSender("get_transactions", [
|
|
178
|
-
|
|
175
|
+
JsonRpcTransformers.indexerSearchKeyTransactionFrom,
|
|
179
176
|
(order) => order ?? "asc",
|
|
180
|
-
(limit) =>
|
|
181
|
-
],
|
|
177
|
+
(limit) => numToHex(limit ?? 10),
|
|
178
|
+
], JsonRpcTransformers.findTransactionsResponseTo);
|
|
182
179
|
/**
|
|
183
180
|
* get cells capacity from node.
|
|
184
181
|
*
|
|
185
182
|
* @param key - The search key of cells.
|
|
186
183
|
* @returns The sum of cells capacity.
|
|
187
184
|
*/
|
|
188
|
-
this.getCellsCapacity = this.buildSender("get_cells_capacity", [
|
|
189
|
-
this.transport =
|
|
185
|
+
this.getCellsCapacity = this.buildSender("get_cells_capacity", [JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => numFrom(capacity));
|
|
186
|
+
this.transport = transportFromUri(url_, config);
|
|
190
187
|
}
|
|
191
188
|
/**
|
|
192
189
|
* Returns the URL of the JSON-RPC server.
|
|
@@ -205,8 +202,8 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
205
202
|
* @returns The cell
|
|
206
203
|
*/
|
|
207
204
|
getCellLiveNoCache(outPoint, withData, includeTxPool) {
|
|
208
|
-
return this.buildSender("get_live_cell", [
|
|
209
|
-
cellOutput:
|
|
205
|
+
return this.buildSender("get_live_cell", [JsonRpcTransformers.outPointFrom], ({ cell, }) => apply(({ output, data, }) => Cell.from({
|
|
206
|
+
cellOutput: JsonRpcTransformers.cellOutputTo(output),
|
|
210
207
|
outputData: data?.content ?? "0x",
|
|
211
208
|
outPoint,
|
|
212
209
|
}), cell))(outPoint, withData ?? true, includeTxPool);
|
|
@@ -245,7 +242,7 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
245
242
|
throw builder(err, match);
|
|
246
243
|
}
|
|
247
244
|
}
|
|
248
|
-
throw new
|
|
245
|
+
throw new ErrorClientBase(err);
|
|
249
246
|
}
|
|
250
247
|
};
|
|
251
248
|
}
|
|
@@ -283,4 +280,3 @@ class ClientJsonRpc extends client_js_1.Client {
|
|
|
283
280
|
};
|
|
284
281
|
}
|
|
285
282
|
}
|
|
286
|
-
exports.ClientJsonRpc = ClientJsonRpc;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const index_js_5 = require("../../utils/index.js");
|
|
9
|
-
const clientTypes_js_1 = require("../clientTypes.js");
|
|
10
|
-
class JsonRpcTransformers {
|
|
1
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
2
|
+
import { Cell, CellDep, CellInput, CellOutput, OutPoint, Script, Transaction, depTypeFrom, epochFromHex, hashTypeFrom, } from "../../ckb/index.js";
|
|
3
|
+
import { hexFrom } from "../../hex/index.js";
|
|
4
|
+
import { numFrom, numLeFromBytes, numToHex } from "../../num/index.js";
|
|
5
|
+
import { apply } from "../../utils/index.js";
|
|
6
|
+
import { ClientIndexerSearchKey, ClientIndexerSearchKeyTransaction, } from "../clientTypes.js";
|
|
7
|
+
export class JsonRpcTransformers {
|
|
11
8
|
static hashTypeFrom(hashType) {
|
|
12
|
-
return
|
|
9
|
+
return hashTypeFrom(hashType);
|
|
13
10
|
}
|
|
14
11
|
static hashTypeTo(hashType) {
|
|
15
12
|
return hashType;
|
|
16
13
|
}
|
|
17
14
|
static depTypeFrom(depType) {
|
|
18
|
-
switch (
|
|
15
|
+
switch (depTypeFrom(depType)) {
|
|
19
16
|
case "code":
|
|
20
17
|
return "code";
|
|
21
18
|
case "depGroup":
|
|
@@ -31,7 +28,7 @@ class JsonRpcTransformers {
|
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
static scriptFrom(scriptLike) {
|
|
34
|
-
const script =
|
|
31
|
+
const script = Script.from(scriptLike);
|
|
35
32
|
return {
|
|
36
33
|
code_hash: script.codeHash,
|
|
37
34
|
hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
|
|
@@ -39,50 +36,50 @@ class JsonRpcTransformers {
|
|
|
39
36
|
};
|
|
40
37
|
}
|
|
41
38
|
static scriptTo(script) {
|
|
42
|
-
return
|
|
39
|
+
return Script.from({
|
|
43
40
|
codeHash: script.code_hash,
|
|
44
41
|
hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
|
|
45
42
|
args: script.args,
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
45
|
static outPointFrom(outPointLike) {
|
|
49
|
-
const outPoint =
|
|
46
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
50
47
|
return {
|
|
51
|
-
index:
|
|
48
|
+
index: numToHex(outPoint.index),
|
|
52
49
|
tx_hash: outPoint.txHash,
|
|
53
50
|
};
|
|
54
51
|
}
|
|
55
52
|
static outPointTo(outPoint) {
|
|
56
|
-
return
|
|
53
|
+
return OutPoint.from({
|
|
57
54
|
index: outPoint.index,
|
|
58
55
|
txHash: outPoint.tx_hash,
|
|
59
56
|
});
|
|
60
57
|
}
|
|
61
58
|
static cellInputFrom(cellInputLike) {
|
|
62
|
-
const cellInput =
|
|
59
|
+
const cellInput = CellInput.from(cellInputLike);
|
|
63
60
|
return {
|
|
64
61
|
previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
|
|
65
|
-
since:
|
|
62
|
+
since: numToHex(cellInput.since),
|
|
66
63
|
};
|
|
67
64
|
}
|
|
68
65
|
static cellInputTo(cellInput) {
|
|
69
|
-
return
|
|
66
|
+
return CellInput.from({
|
|
70
67
|
previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
|
|
71
68
|
since: cellInput.since,
|
|
72
69
|
});
|
|
73
70
|
}
|
|
74
71
|
static cellOutputFrom(cellOutput) {
|
|
75
72
|
return {
|
|
76
|
-
capacity:
|
|
73
|
+
capacity: numToHex(cellOutput.capacity),
|
|
77
74
|
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
78
|
-
type:
|
|
75
|
+
type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
79
76
|
};
|
|
80
77
|
}
|
|
81
78
|
static cellOutputTo(cellOutput) {
|
|
82
|
-
return
|
|
79
|
+
return CellOutput.from({
|
|
83
80
|
capacity: cellOutput.capacity,
|
|
84
81
|
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
85
|
-
type:
|
|
82
|
+
type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
86
83
|
});
|
|
87
84
|
}
|
|
88
85
|
static cellDepFrom(cellDep) {
|
|
@@ -92,15 +89,15 @@ class JsonRpcTransformers {
|
|
|
92
89
|
};
|
|
93
90
|
}
|
|
94
91
|
static cellDepTo(cellDep) {
|
|
95
|
-
return
|
|
92
|
+
return CellDep.from({
|
|
96
93
|
outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
|
|
97
94
|
depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
97
|
static transactionFrom(txLike) {
|
|
101
|
-
const tx =
|
|
98
|
+
const tx = Transaction.from(txLike);
|
|
102
99
|
return {
|
|
103
|
-
version:
|
|
100
|
+
version: numToHex(tx.version),
|
|
104
101
|
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
105
102
|
header_deps: tx.headerDeps,
|
|
106
103
|
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
@@ -110,7 +107,7 @@ class JsonRpcTransformers {
|
|
|
110
107
|
};
|
|
111
108
|
}
|
|
112
109
|
static transactionTo(tx) {
|
|
113
|
-
return
|
|
110
|
+
return Transaction.from({
|
|
114
111
|
version: tx.version,
|
|
115
112
|
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
|
|
116
113
|
headerDeps: tx.header_deps,
|
|
@@ -127,33 +124,33 @@ class JsonRpcTransformers {
|
|
|
127
124
|
return {
|
|
128
125
|
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
129
126
|
status,
|
|
130
|
-
cycles:
|
|
131
|
-
blockHash:
|
|
132
|
-
blockNumber:
|
|
133
|
-
txIndex:
|
|
127
|
+
cycles: apply(numFrom, cycles),
|
|
128
|
+
blockHash: apply(hexFrom, block_hash),
|
|
129
|
+
blockNumber: apply(numFrom, block_number),
|
|
130
|
+
txIndex: apply(numFrom, tx_index),
|
|
134
131
|
reason,
|
|
135
132
|
};
|
|
136
133
|
}
|
|
137
134
|
static blockHeaderTo(header) {
|
|
138
|
-
const dao =
|
|
135
|
+
const dao = bytesFrom(header.dao);
|
|
139
136
|
return {
|
|
140
|
-
compactTarget:
|
|
137
|
+
compactTarget: numFrom(header.compact_target),
|
|
141
138
|
dao: {
|
|
142
|
-
c:
|
|
143
|
-
ar:
|
|
144
|
-
s:
|
|
145
|
-
u:
|
|
139
|
+
c: numLeFromBytes(dao.slice(0, 8)),
|
|
140
|
+
ar: numLeFromBytes(dao.slice(8, 16)),
|
|
141
|
+
s: numLeFromBytes(dao.slice(16, 24)),
|
|
142
|
+
u: numLeFromBytes(dao.slice(24, 32)),
|
|
146
143
|
},
|
|
147
|
-
epoch:
|
|
144
|
+
epoch: epochFromHex(header.epoch),
|
|
148
145
|
extraHash: header.extra_hash,
|
|
149
146
|
hash: header.hash,
|
|
150
|
-
nonce:
|
|
151
|
-
number:
|
|
147
|
+
nonce: numFrom(header.nonce),
|
|
148
|
+
number: numFrom(header.number),
|
|
152
149
|
parentHash: header.parent_hash,
|
|
153
150
|
proposalsHash: header.proposals_hash,
|
|
154
|
-
timestamp:
|
|
151
|
+
timestamp: numFrom(header.timestamp),
|
|
155
152
|
transactionsRoot: header.transactions_root,
|
|
156
|
-
version:
|
|
153
|
+
version: numFrom(header.version),
|
|
157
154
|
};
|
|
158
155
|
}
|
|
159
156
|
static blockUncleTo(block) {
|
|
@@ -171,33 +168,33 @@ class JsonRpcTransformers {
|
|
|
171
168
|
};
|
|
172
169
|
}
|
|
173
170
|
static rangeFrom([a, b]) {
|
|
174
|
-
return [
|
|
171
|
+
return [numToHex(a), numToHex(b)];
|
|
175
172
|
}
|
|
176
173
|
static indexerSearchKeyFilterFrom(filter) {
|
|
177
174
|
return {
|
|
178
|
-
script:
|
|
179
|
-
script_len_range:
|
|
175
|
+
script: apply(JsonRpcTransformers.scriptFrom, filter.script),
|
|
176
|
+
script_len_range: apply(JsonRpcTransformers.rangeFrom, filter.scriptLenRange),
|
|
180
177
|
output_data: filter.outputData,
|
|
181
178
|
output_data_filter_mode: filter.outputDataSearchMode,
|
|
182
|
-
output_data_len_range:
|
|
183
|
-
output_capacity_range:
|
|
184
|
-
block_range:
|
|
179
|
+
output_data_len_range: apply(JsonRpcTransformers.rangeFrom, filter.outputDataLenRange),
|
|
180
|
+
output_capacity_range: apply(JsonRpcTransformers.rangeFrom, filter.outputCapacityRange),
|
|
181
|
+
block_range: apply(JsonRpcTransformers.rangeFrom, filter.blockRange),
|
|
185
182
|
};
|
|
186
183
|
}
|
|
187
184
|
static indexerSearchKeyFrom(keyLike) {
|
|
188
|
-
const key =
|
|
185
|
+
const key = ClientIndexerSearchKey.from(keyLike);
|
|
189
186
|
return {
|
|
190
187
|
script: JsonRpcTransformers.scriptFrom(key.script),
|
|
191
188
|
script_type: key.scriptType,
|
|
192
189
|
script_search_mode: key.scriptSearchMode,
|
|
193
|
-
filter:
|
|
190
|
+
filter: apply(JsonRpcTransformers.indexerSearchKeyFilterFrom, key.filter),
|
|
194
191
|
with_data: key.withData,
|
|
195
192
|
};
|
|
196
193
|
}
|
|
197
194
|
static findCellsResponseTo({ last_cursor, objects, }) {
|
|
198
195
|
return {
|
|
199
196
|
lastCursor: last_cursor,
|
|
200
|
-
cells: objects.map((cell) =>
|
|
197
|
+
cells: objects.map((cell) => Cell.from({
|
|
201
198
|
outPoint: JsonRpcTransformers.outPointTo(cell.out_point),
|
|
202
199
|
cellOutput: JsonRpcTransformers.cellOutputTo(cell.output),
|
|
203
200
|
outputData: cell.output_data ?? "0x",
|
|
@@ -205,12 +202,12 @@ class JsonRpcTransformers {
|
|
|
205
202
|
};
|
|
206
203
|
}
|
|
207
204
|
static indexerSearchKeyTransactionFrom(keyLike) {
|
|
208
|
-
const key =
|
|
205
|
+
const key = ClientIndexerSearchKeyTransaction.from(keyLike);
|
|
209
206
|
return {
|
|
210
207
|
script: JsonRpcTransformers.scriptFrom(key.script),
|
|
211
208
|
script_type: key.scriptType,
|
|
212
209
|
script_search_mode: key.scriptSearchMode,
|
|
213
|
-
filter:
|
|
210
|
+
filter: apply(JsonRpcTransformers.indexerSearchKeyFilterFrom, key.filter),
|
|
214
211
|
group_by_transaction: key.groupByTransaction,
|
|
215
212
|
};
|
|
216
213
|
}
|
|
@@ -226,9 +223,9 @@ class JsonRpcTransformers {
|
|
|
226
223
|
lastCursor: last_cursor,
|
|
227
224
|
transactions: objects.map((tx) => ({
|
|
228
225
|
txHash: tx.tx_hash,
|
|
229
|
-
blockNumber:
|
|
230
|
-
txIndex:
|
|
231
|
-
cellIndex:
|
|
226
|
+
blockNumber: numFrom(tx.block_number),
|
|
227
|
+
txIndex: numFrom(tx.tx_index),
|
|
228
|
+
cellIndex: numFrom(tx.io_index),
|
|
232
229
|
isInput: tx.io_type === "input",
|
|
233
230
|
})),
|
|
234
231
|
};
|
|
@@ -237,14 +234,13 @@ class JsonRpcTransformers {
|
|
|
237
234
|
lastCursor: last_cursor,
|
|
238
235
|
transactions: objects.map((tx) => ({
|
|
239
236
|
txHash: tx.tx_hash,
|
|
240
|
-
blockNumber:
|
|
241
|
-
txIndex:
|
|
237
|
+
blockNumber: numFrom(tx.block_number),
|
|
238
|
+
txIndex: numFrom(tx.tx_index),
|
|
242
239
|
cells: tx.cells.map(([type, i]) => ({
|
|
243
240
|
isInput: type === "input",
|
|
244
|
-
cellIndex:
|
|
241
|
+
cellIndex: numFrom(i),
|
|
245
242
|
})),
|
|
246
243
|
})),
|
|
247
244
|
};
|
|
248
245
|
}
|
|
249
246
|
}
|
|
250
|
-
exports.JsonRpcTransformers = JsonRpcTransformers;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 = transportFromUri;
|
|
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) {
|
|
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 function transportFromUri(uri, config) {
|
|
24
7
|
if (uri.startsWith("wss://")) {
|
|
25
|
-
return new
|
|
8
|
+
return new TransportWebSocket(uri, config?.timeout);
|
|
26
9
|
}
|
|
27
|
-
return new
|
|
10
|
+
return new TransportHttp(uri, config?.timeout);
|
|
28
11
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransportHttp = void 0;
|
|
4
|
-
class TransportHttp {
|
|
1
|
+
export class TransportHttp {
|
|
5
2
|
constructor(url, timeout = 30000) {
|
|
6
3
|
this.url = url;
|
|
7
4
|
this.timeout = timeout;
|
|
@@ -23,4 +20,3 @@ class TransportHttp {
|
|
|
23
20
|
return raw;
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
exports.TransportHttp = TransportHttp;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TransportWebSocket = void 0;
|
|
7
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
-
class TransportWebSocket {
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
export class TransportWebSocket {
|
|
9
3
|
constructor(url, timeout = 30000) {
|
|
10
4
|
this.url = url;
|
|
11
5
|
this.timeout = timeout;
|
|
@@ -19,7 +13,7 @@ class TransportWebSocket {
|
|
|
19
13
|
this.openSocket) {
|
|
20
14
|
return this.openSocket;
|
|
21
15
|
}
|
|
22
|
-
const socket = new
|
|
16
|
+
const socket = new WebSocket(this.url);
|
|
23
17
|
const onMessage = ({ data }) => {
|
|
24
18
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
25
19
|
const res = JSON.parse(data);
|
|
@@ -87,4 +81,3 @@ class TransportWebSocket {
|
|
|
87
81
|
});
|
|
88
82
|
}
|
|
89
83
|
}
|
|
90
|
-
exports.TransportWebSocket = TransportWebSocket;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Represents a fixed point value as a bigint.
|
|
4
3
|
* @public
|
|
5
4
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.One = exports.Zero = void 0;
|
|
8
|
-
exports.fixedPointToString = fixedPointToString;
|
|
9
|
-
exports.fixedPointFrom = fixedPointFrom;
|
|
10
5
|
/**
|
|
11
6
|
* Converts a FixedPointLike value to its string representation with fixed-point decimals.
|
|
12
7
|
* @public
|
|
@@ -22,7 +17,7 @@ exports.fixedPointFrom = fixedPointFrom;
|
|
|
22
17
|
* const strFromNumber = fixedPointToString(1.23456789, 8); // Outputs "1.23456789"
|
|
23
18
|
* ```
|
|
24
19
|
*/
|
|
25
|
-
function fixedPointToString(val, decimals = 8) {
|
|
20
|
+
export function fixedPointToString(val, decimals = 8) {
|
|
26
21
|
const str = fixedPointFrom(val).toString();
|
|
27
22
|
if (decimals === 0) {
|
|
28
23
|
return str;
|
|
@@ -49,7 +44,7 @@ function fixedPointToString(val, decimals = 8) {
|
|
|
49
44
|
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
50
45
|
* ```
|
|
51
46
|
*/
|
|
52
|
-
function fixedPointFrom(val, decimals = 8) {
|
|
47
|
+
export function fixedPointFrom(val, decimals = 8) {
|
|
53
48
|
if (typeof val === "bigint") {
|
|
54
49
|
return val;
|
|
55
50
|
}
|
|
@@ -64,10 +59,10 @@ function fixedPointFrom(val, decimals = 8) {
|
|
|
64
59
|
* Represents the fixed point value of zero as a bigint.
|
|
65
60
|
* @public
|
|
66
61
|
*/
|
|
67
|
-
|
|
62
|
+
export const Zero = 0n;
|
|
68
63
|
/**
|
|
69
64
|
* Represents the fixed point value of one as a FixedPoint (bigint).
|
|
70
65
|
* Equivalent to 1 in fixed-point representation with default decimals (8).
|
|
71
66
|
* @public
|
|
72
67
|
*/
|
|
73
|
-
|
|
68
|
+
export const One = fixedPointFrom("1");
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|