@ckb-ccc/core 0.0.13-alpha.6 → 0.0.13-alpha.8
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 +22 -0
- package/dist/ckb/transaction.d.ts +91 -1
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +118 -24
- package/dist/client/cache/cache.d.ts +29 -9
- package/dist/client/cache/cache.d.ts.map +1 -1
- package/dist/client/cache/cache.js +43 -1
- package/dist/client/cache/memory.d.ts +10 -6
- package/dist/client/cache/memory.d.ts.map +1 -1
- package/dist/client/cache/memory.js +49 -39
- package/dist/client/client.d.ts +10 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +6 -5
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +15 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +15 -0
- package/dist/client/clientTypes.d.ts +47 -4
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +26 -1
- package/dist/client/jsonRpc/index.d.ts +39 -1
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +63 -2
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist/client/jsonRpc/transformers.js +11 -4
- package/dist/fixedPoint/index.d.ts +3 -3
- package/dist/fixedPoint/index.js +3 -3
- package/dist/signer/signer/index.d.ts +3 -1
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +14 -0
- package/dist.commonjs/ckb/transaction.d.ts +91 -1
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +121 -23
- package/dist.commonjs/client/cache/cache.d.ts +29 -9
- package/dist.commonjs/client/cache/cache.d.ts.map +1 -1
- package/dist.commonjs/client/cache/cache.js +45 -0
- package/dist.commonjs/client/cache/memory.d.ts +10 -6
- package/dist.commonjs/client/cache/memory.d.ts.map +1 -1
- package/dist.commonjs/client/cache/memory.js +49 -39
- package/dist.commonjs/client/client.d.ts +10 -4
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +6 -5
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +15 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +15 -0
- package/dist.commonjs/client/clientTypes.d.ts +47 -4
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +33 -5
- package/dist.commonjs/client/jsonRpc/index.d.ts +39 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +74 -13
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/transformers.js +55 -48
- package/dist.commonjs/fixedPoint/index.d.ts +3 -3
- package/dist.commonjs/fixedPoint/index.js +3 -3
- package/dist.commonjs/signer/signer/index.d.ts +3 -1
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +14 -0
- package/package.json +1 -1
- package/src/ckb/transaction.ts +170 -30
- package/src/client/cache/cache.ts +58 -13
- package/src/client/cache/memory.ts +60 -52
- package/src/client/client.ts +22 -5
- package/src/client/clientPublicMainnet.advanced.ts +17 -0
- package/src/client/clientPublicTestnet.advanced.ts +17 -0
- package/src/client/clientTypes.ts +76 -5
- package/src/client/jsonRpc/index.ts +105 -3
- package/src/client/jsonRpc/transformers.ts +11 -3
- package/src/fixedPoint/index.ts +3 -3
- package/src/signer/signer/index.ts +20 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonRpcTransformers = void 0;
|
|
4
|
-
const index_js_1 = require("../../
|
|
5
|
-
const index_js_2 = require("../../
|
|
6
|
-
const index_js_3 = require("../../
|
|
7
|
-
const index_js_4 = require("../../
|
|
4
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
5
|
+
const index_js_2 = require("../../ckb/index.js");
|
|
6
|
+
const index_js_3 = require("../../hex/index.js");
|
|
7
|
+
const index_js_4 = require("../../num/index.js");
|
|
8
|
+
const index_js_5 = require("../../utils/index.js");
|
|
8
9
|
const clientTypes_js_1 = require("../clientTypes.js");
|
|
9
10
|
class JsonRpcTransformers {
|
|
10
11
|
static hashTypeFrom(hashType) {
|
|
11
|
-
return (0,
|
|
12
|
+
return (0, index_js_2.hashTypeFrom)(hashType);
|
|
12
13
|
}
|
|
13
14
|
static hashTypeTo(hashType) {
|
|
14
15
|
return hashType;
|
|
15
16
|
}
|
|
16
17
|
static depTypeFrom(depType) {
|
|
17
|
-
switch ((0,
|
|
18
|
+
switch ((0, index_js_2.depTypeFrom)(depType)) {
|
|
18
19
|
case "code":
|
|
19
20
|
return "code";
|
|
20
21
|
case "depGroup":
|
|
@@ -30,7 +31,7 @@ class JsonRpcTransformers {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
static scriptFrom(scriptLike) {
|
|
33
|
-
const script =
|
|
34
|
+
const script = index_js_2.Script.from(scriptLike);
|
|
34
35
|
return {
|
|
35
36
|
code_hash: script.codeHash,
|
|
36
37
|
hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
|
|
@@ -38,50 +39,50 @@ class JsonRpcTransformers {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
static scriptTo(script) {
|
|
41
|
-
return
|
|
42
|
+
return index_js_2.Script.from({
|
|
42
43
|
codeHash: script.code_hash,
|
|
43
44
|
hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
|
|
44
45
|
args: script.args,
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
static outPointFrom(outPointLike) {
|
|
48
|
-
const outPoint =
|
|
49
|
+
const outPoint = index_js_2.OutPoint.from(outPointLike);
|
|
49
50
|
return {
|
|
50
|
-
index: (0,
|
|
51
|
+
index: (0, index_js_4.numToHex)(outPoint.index),
|
|
51
52
|
tx_hash: outPoint.txHash,
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
static outPointTo(outPoint) {
|
|
55
|
-
return
|
|
56
|
+
return index_js_2.OutPoint.from({
|
|
56
57
|
index: outPoint.index,
|
|
57
58
|
txHash: outPoint.tx_hash,
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
static cellInputFrom(cellInputLike) {
|
|
61
|
-
const cellInput =
|
|
62
|
+
const cellInput = index_js_2.CellInput.from(cellInputLike);
|
|
62
63
|
return {
|
|
63
64
|
previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
|
|
64
|
-
since: (0,
|
|
65
|
+
since: (0, index_js_4.numToHex)(cellInput.since),
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
static cellInputTo(cellInput) {
|
|
68
|
-
return
|
|
69
|
+
return index_js_2.CellInput.from({
|
|
69
70
|
previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
|
|
70
71
|
since: cellInput.since,
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
74
|
static cellOutputFrom(cellOutput) {
|
|
74
75
|
return {
|
|
75
|
-
capacity: (0,
|
|
76
|
+
capacity: (0, index_js_4.numToHex)(cellOutput.capacity),
|
|
76
77
|
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
77
|
-
type: (0,
|
|
78
|
+
type: (0, index_js_5.apply)(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
static cellOutputTo(cellOutput) {
|
|
81
|
-
return
|
|
82
|
+
return index_js_2.CellOutput.from({
|
|
82
83
|
capacity: cellOutput.capacity,
|
|
83
84
|
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
84
|
-
type: (0,
|
|
85
|
+
type: (0, index_js_5.apply)(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
static cellDepFrom(cellDep) {
|
|
@@ -91,15 +92,15 @@ class JsonRpcTransformers {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
static cellDepTo(cellDep) {
|
|
94
|
-
return
|
|
95
|
+
return index_js_2.CellDep.from({
|
|
95
96
|
outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
|
|
96
97
|
depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
static transactionFrom(txLike) {
|
|
100
|
-
const tx =
|
|
101
|
+
const tx = index_js_2.Transaction.from(txLike);
|
|
101
102
|
return {
|
|
102
|
-
version: (0,
|
|
103
|
+
version: (0, index_js_4.numToHex)(tx.version),
|
|
103
104
|
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
104
105
|
header_deps: tx.headerDeps,
|
|
105
106
|
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
@@ -109,7 +110,7 @@ class JsonRpcTransformers {
|
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
static transactionTo(tx) {
|
|
112
|
-
return
|
|
113
|
+
return index_js_2.Transaction.from({
|
|
113
114
|
version: tx.version,
|
|
114
115
|
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
|
|
115
116
|
headerDeps: tx.header_deps,
|
|
@@ -126,27 +127,33 @@ class JsonRpcTransformers {
|
|
|
126
127
|
return {
|
|
127
128
|
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
128
129
|
status,
|
|
129
|
-
cycles: (0,
|
|
130
|
-
blockHash: (0,
|
|
131
|
-
blockNumber: (0,
|
|
132
|
-
txIndex: (0,
|
|
130
|
+
cycles: (0, index_js_5.apply)(index_js_4.numFrom, cycles),
|
|
131
|
+
blockHash: (0, index_js_5.apply)(index_js_3.hexFrom, block_hash),
|
|
132
|
+
blockNumber: (0, index_js_5.apply)(index_js_4.numFrom, block_number),
|
|
133
|
+
txIndex: (0, index_js_5.apply)(index_js_4.numFrom, tx_index),
|
|
133
134
|
reason,
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
static blockHeaderTo(header) {
|
|
138
|
+
const dao = (0, index_js_1.bytesFrom)(header.dao);
|
|
137
139
|
return {
|
|
138
|
-
compactTarget: (0,
|
|
139
|
-
dao:
|
|
140
|
-
|
|
140
|
+
compactTarget: (0, index_js_4.numFrom)(header.compact_target),
|
|
141
|
+
dao: {
|
|
142
|
+
c: (0, index_js_4.numLeFromBytes)(dao.slice(0, 8)),
|
|
143
|
+
ar: (0, index_js_4.numLeFromBytes)(dao.slice(8, 16)),
|
|
144
|
+
s: (0, index_js_4.numLeFromBytes)(dao.slice(16, 24)),
|
|
145
|
+
u: (0, index_js_4.numLeFromBytes)(dao.slice(24, 32)),
|
|
146
|
+
},
|
|
147
|
+
epoch: (0, index_js_2.epochFromHex)(header.epoch),
|
|
141
148
|
extraHash: header.extra_hash,
|
|
142
149
|
hash: header.hash,
|
|
143
|
-
nonce: (0,
|
|
144
|
-
number: (0,
|
|
150
|
+
nonce: (0, index_js_4.numFrom)(header.nonce),
|
|
151
|
+
number: (0, index_js_4.numFrom)(header.number),
|
|
145
152
|
parentHash: header.parent_hash,
|
|
146
153
|
proposalsHash: header.proposals_hash,
|
|
147
|
-
timestamp: (0,
|
|
154
|
+
timestamp: (0, index_js_4.numFrom)(header.timestamp),
|
|
148
155
|
transactionsRoot: header.transactions_root,
|
|
149
|
-
version: (0,
|
|
156
|
+
version: (0, index_js_4.numFrom)(header.version),
|
|
150
157
|
};
|
|
151
158
|
}
|
|
152
159
|
static blockUncleTo(block) {
|
|
@@ -164,17 +171,17 @@ class JsonRpcTransformers {
|
|
|
164
171
|
};
|
|
165
172
|
}
|
|
166
173
|
static rangeFrom([a, b]) {
|
|
167
|
-
return [(0,
|
|
174
|
+
return [(0, index_js_4.numToHex)(a), (0, index_js_4.numToHex)(b)];
|
|
168
175
|
}
|
|
169
176
|
static indexerSearchKeyFilterFrom(filter) {
|
|
170
177
|
return {
|
|
171
|
-
script: (0,
|
|
172
|
-
script_len_range: (0,
|
|
178
|
+
script: (0, index_js_5.apply)(JsonRpcTransformers.scriptFrom, filter.script),
|
|
179
|
+
script_len_range: (0, index_js_5.apply)(JsonRpcTransformers.rangeFrom, filter.scriptLenRange),
|
|
173
180
|
output_data: filter.outputData,
|
|
174
181
|
output_data_filter_mode: filter.outputDataSearchMode,
|
|
175
|
-
output_data_len_range: (0,
|
|
176
|
-
output_capacity_range: (0,
|
|
177
|
-
block_range: (0,
|
|
182
|
+
output_data_len_range: (0, index_js_5.apply)(JsonRpcTransformers.rangeFrom, filter.outputDataLenRange),
|
|
183
|
+
output_capacity_range: (0, index_js_5.apply)(JsonRpcTransformers.rangeFrom, filter.outputCapacityRange),
|
|
184
|
+
block_range: (0, index_js_5.apply)(JsonRpcTransformers.rangeFrom, filter.blockRange),
|
|
178
185
|
};
|
|
179
186
|
}
|
|
180
187
|
static indexerSearchKeyFrom(keyLike) {
|
|
@@ -183,14 +190,14 @@ class JsonRpcTransformers {
|
|
|
183
190
|
script: JsonRpcTransformers.scriptFrom(key.script),
|
|
184
191
|
script_type: key.scriptType,
|
|
185
192
|
script_search_mode: key.scriptSearchMode,
|
|
186
|
-
filter: (0,
|
|
193
|
+
filter: (0, index_js_5.apply)(JsonRpcTransformers.indexerSearchKeyFilterFrom, key.filter),
|
|
187
194
|
with_data: key.withData,
|
|
188
195
|
};
|
|
189
196
|
}
|
|
190
197
|
static findCellsResponseTo({ last_cursor, objects, }) {
|
|
191
198
|
return {
|
|
192
199
|
lastCursor: last_cursor,
|
|
193
|
-
cells: objects.map((cell) =>
|
|
200
|
+
cells: objects.map((cell) => index_js_2.Cell.from({
|
|
194
201
|
outPoint: JsonRpcTransformers.outPointTo(cell.out_point),
|
|
195
202
|
cellOutput: JsonRpcTransformers.cellOutputTo(cell.output),
|
|
196
203
|
outputData: cell.output_data ?? "0x",
|
|
@@ -203,7 +210,7 @@ class JsonRpcTransformers {
|
|
|
203
210
|
script: JsonRpcTransformers.scriptFrom(key.script),
|
|
204
211
|
script_type: key.scriptType,
|
|
205
212
|
script_search_mode: key.scriptSearchMode,
|
|
206
|
-
filter: (0,
|
|
213
|
+
filter: (0, index_js_5.apply)(JsonRpcTransformers.indexerSearchKeyFilterFrom, key.filter),
|
|
207
214
|
group_by_transaction: key.groupByTransaction,
|
|
208
215
|
};
|
|
209
216
|
}
|
|
@@ -219,9 +226,9 @@ class JsonRpcTransformers {
|
|
|
219
226
|
lastCursor: last_cursor,
|
|
220
227
|
transactions: objects.map((tx) => ({
|
|
221
228
|
txHash: tx.tx_hash,
|
|
222
|
-
blockNumber: (0,
|
|
223
|
-
txIndex: (0,
|
|
224
|
-
cellIndex: (0,
|
|
229
|
+
blockNumber: (0, index_js_4.numFrom)(tx.block_number),
|
|
230
|
+
txIndex: (0, index_js_4.numFrom)(tx.tx_index),
|
|
231
|
+
cellIndex: (0, index_js_4.numFrom)(tx.io_index),
|
|
225
232
|
isInput: tx.io_type === "input",
|
|
226
233
|
})),
|
|
227
234
|
};
|
|
@@ -230,11 +237,11 @@ class JsonRpcTransformers {
|
|
|
230
237
|
lastCursor: last_cursor,
|
|
231
238
|
transactions: objects.map((tx) => ({
|
|
232
239
|
txHash: tx.tx_hash,
|
|
233
|
-
blockNumber: (0,
|
|
234
|
-
txIndex: (0,
|
|
240
|
+
blockNumber: (0, index_js_4.numFrom)(tx.block_number),
|
|
241
|
+
txIndex: (0, index_js_4.numFrom)(tx.tx_index),
|
|
235
242
|
cells: tx.cells.map(([type, i]) => ({
|
|
236
243
|
isInput: type === "input",
|
|
237
|
-
cellIndex: (0,
|
|
244
|
+
cellIndex: (0, index_js_4.numFrom)(i),
|
|
238
245
|
})),
|
|
239
246
|
})),
|
|
240
247
|
};
|
|
@@ -20,8 +20,8 @@ export type FixedPointLike = bigint | string | number;
|
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
22
22
|
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
23
|
-
* const strFromString = fixedPointToString("
|
|
24
|
-
* const strFromNumber = fixedPointToString(
|
|
23
|
+
* const strFromString = fixedPointToString("1.23456789", 8); // Outputs "1.23456789"
|
|
24
|
+
* const strFromNumber = fixedPointToString(1.23456789, 8); // Outputs "1.23456789"
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export declare function fixedPointToString(val: FixedPointLike, decimals?: number): string;
|
|
@@ -35,7 +35,7 @@ export declare function fixedPointToString(val: FixedPointLike, decimals?: numbe
|
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
|
-
* const fixedPoint = fixedPointFrom(
|
|
38
|
+
* const fixedPoint = fixedPointFrom(123456789n, 8); // Outputs 123456789n
|
|
39
39
|
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
40
40
|
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
41
41
|
* ```
|
|
@@ -16,8 +16,8 @@ exports.One = exports.Zero = exports.fixedPointFrom = exports.fixedPointToString
|
|
|
16
16
|
* @example
|
|
17
17
|
* ```typescript
|
|
18
18
|
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
19
|
-
* const strFromString = fixedPointToString("
|
|
20
|
-
* const strFromNumber = fixedPointToString(
|
|
19
|
+
* const strFromString = fixedPointToString("1.23456789", 8); // Outputs "1.23456789"
|
|
20
|
+
* const strFromNumber = fixedPointToString(1.23456789, 8); // Outputs "1.23456789"
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
function fixedPointToString(val, decimals = 8) {
|
|
@@ -43,7 +43,7 @@ exports.fixedPointToString = fixedPointToString;
|
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
45
|
* ```typescript
|
|
46
|
-
* const fixedPoint = fixedPointFrom(
|
|
46
|
+
* const fixedPoint = fixedPointFrom(123456789n, 8); // Outputs 123456789n
|
|
47
47
|
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
48
48
|
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
49
49
|
* ```
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Address } from "../../address/index.js";
|
|
2
|
+
import { ClientCollectableSearchKeyFilterLike } from "../../advancedBarrel.js";
|
|
2
3
|
import { BytesLike } from "../../bytes/index.js";
|
|
3
|
-
import { Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
|
+
import { Cell, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
5
|
import { Client } from "../../client/index.js";
|
|
5
6
|
import { Hex } from "../../hex/index.js";
|
|
6
7
|
import { Num } from "../../num/index.js";
|
|
@@ -128,6 +129,7 @@ export declare abstract class Signer {
|
|
|
128
129
|
* @returns A promise that resolves to an array of addresses as strings.
|
|
129
130
|
*/
|
|
130
131
|
getAddresses(): Promise<string[]>;
|
|
132
|
+
findCells(filter: ClientCollectableSearchKeyFilterLike, withData?: boolean | null): AsyncGenerator<Cell>;
|
|
131
133
|
/**
|
|
132
134
|
* Gets balance of all addresses
|
|
133
135
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":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AC;IAQlE;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAItD;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,OAAO,CAAC,OAAO,CAAC;IAmBnB;;;;;OAKG;IACG,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IAIxD;;;;;OAKG;IACG,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKhE;;;;;;OAMG;IACH,kBAAkB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAG9D;AAED;;;GAGG;AACH,qBAAa,UAAU;IAEZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAExB;AAED;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
|
@@ -129,6 +129,20 @@ class Signer {
|
|
|
129
129
|
async getAddresses() {
|
|
130
130
|
return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
|
|
131
131
|
}
|
|
132
|
+
async *findCells(filter, withData) {
|
|
133
|
+
const scripts = await this.getAddressObjs();
|
|
134
|
+
for (const { script } of scripts) {
|
|
135
|
+
for await (const cell of this.client.findCells({
|
|
136
|
+
script,
|
|
137
|
+
scriptType: "lock",
|
|
138
|
+
filter,
|
|
139
|
+
scriptSearchMode: "exact",
|
|
140
|
+
withData,
|
|
141
|
+
})) {
|
|
142
|
+
yield cell;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
132
146
|
/**
|
|
133
147
|
* Gets balance of all addresses
|
|
134
148
|
*
|
package/package.json
CHANGED
package/src/ckb/transaction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientCollectableSearchKeyFilterLike } from "../advancedBarrel.js";
|
|
2
|
-
import { Bytes, BytesLike, bytesFrom } from "../bytes/index.js";
|
|
2
|
+
import { Bytes, BytesLike, bytesConcat, bytesFrom } from "../bytes/index.js";
|
|
3
3
|
import { CellDepInfoLike, Client, KnownScript } from "../client/index.js";
|
|
4
4
|
import {
|
|
5
5
|
Zero,
|
|
@@ -11,8 +11,11 @@ import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
|
11
11
|
import {
|
|
12
12
|
Num,
|
|
13
13
|
NumLike,
|
|
14
|
+
numBeToBytes,
|
|
14
15
|
numFrom,
|
|
15
16
|
numFromBytes,
|
|
17
|
+
numLeFromBytes,
|
|
18
|
+
numLeToBytes,
|
|
16
19
|
numToBytes,
|
|
17
20
|
numToHex,
|
|
18
21
|
} from "../num/index.js";
|
|
@@ -416,12 +419,162 @@ export class Cell {
|
|
|
416
419
|
}
|
|
417
420
|
}
|
|
418
421
|
|
|
422
|
+
/**
|
|
423
|
+
* @public
|
|
424
|
+
*/
|
|
425
|
+
export type EpochLike = [NumLike, NumLike, NumLike];
|
|
426
|
+
/**
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
export type Epoch = [Num, Num, Num];
|
|
430
|
+
/**
|
|
431
|
+
* @public
|
|
432
|
+
*/
|
|
433
|
+
export function epochFrom(epochLike: EpochLike): Epoch {
|
|
434
|
+
return [numFrom(epochLike[0]), numFrom(epochLike[1]), numFrom(epochLike[2])];
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
export function epochFromHex(hex: HexLike): Epoch {
|
|
440
|
+
const bytes = bytesFrom(hexFrom(hex));
|
|
441
|
+
|
|
442
|
+
return [
|
|
443
|
+
numFrom(bytes.slice(4, 7)),
|
|
444
|
+
numFrom(bytes.slice(2, 4)),
|
|
445
|
+
numFrom(bytes.slice(0, 2)),
|
|
446
|
+
];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
451
|
+
export function epochToHex(epochLike: EpochLike): Hex {
|
|
452
|
+
const epoch = epochFrom(epochLike);
|
|
453
|
+
|
|
454
|
+
return hexFrom(
|
|
455
|
+
bytesConcat(
|
|
456
|
+
numBeToBytes(epoch[2], 2),
|
|
457
|
+
numBeToBytes(epoch[1], 2),
|
|
458
|
+
numBeToBytes(epoch[0], 3),
|
|
459
|
+
),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* @public
|
|
465
|
+
*/
|
|
466
|
+
export type SinceLike =
|
|
467
|
+
| {
|
|
468
|
+
relative: "absolute" | "relative";
|
|
469
|
+
metric: "blockNumber" | "epoch" | "timestamp";
|
|
470
|
+
value: NumLike;
|
|
471
|
+
}
|
|
472
|
+
| NumLike;
|
|
473
|
+
/**
|
|
474
|
+
* @public
|
|
475
|
+
*/
|
|
476
|
+
export class Since {
|
|
477
|
+
/**
|
|
478
|
+
* Creates an instance of Since.
|
|
479
|
+
*
|
|
480
|
+
* @param relative - Absolute or relative
|
|
481
|
+
* @param metric - The metric of since
|
|
482
|
+
* @param value - The value of since
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
constructor(
|
|
486
|
+
public relative: "absolute" | "relative",
|
|
487
|
+
public metric: "blockNumber" | "epoch" | "timestamp",
|
|
488
|
+
public value: Num,
|
|
489
|
+
) {}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Clone a Since.
|
|
493
|
+
*
|
|
494
|
+
* @returns A cloned Since instance.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* const since1 = since0.clone();
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
clone(): Since {
|
|
502
|
+
return new Since(this.relative, this.metric, this.value);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Creates a Since instance from a SinceLike object.
|
|
507
|
+
*
|
|
508
|
+
* @param since - A SinceLike object or an instance of Since.
|
|
509
|
+
* @returns A Since instance.
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* const since = Since.from("0x1234567812345678");
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
static from(since: SinceLike): Since {
|
|
517
|
+
if (since instanceof Since) {
|
|
518
|
+
return since;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (typeof since === "object" && "relative" in since) {
|
|
522
|
+
return new Since(since.relative, since.metric, numFrom(since.value));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return Since.fromNum(since);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Converts the Since instance to num.
|
|
530
|
+
*
|
|
531
|
+
* @returns A num
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const num = since.toNum();
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
toNum(): Num {
|
|
540
|
+
const flag =
|
|
541
|
+
((this.relative === "absolute" ? 0 : 1) << 7) |
|
|
542
|
+
({ blockNumber: 0, epoch: 1, timestamp: 2 }[this.metric] << 5);
|
|
543
|
+
|
|
544
|
+
return numFrom(bytesConcat([flag], numLeToBytes(this.value, 7)));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Creates a Since instance from a num-like value.
|
|
549
|
+
*
|
|
550
|
+
* @param numLike - The num-like value to convert.
|
|
551
|
+
* @returns A Since instance.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const since = Since.fromNum("0x0");
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
static fromNum(numLike: NumLike): Since {
|
|
560
|
+
const bytes = numBeToBytes(numLike, 8);
|
|
561
|
+
|
|
562
|
+
const relative = bytes[0] >> 7 === 0 ? "absolute" : "relative";
|
|
563
|
+
const metric = (["blockNumber", "epoch", "timestamp"] as Since["metric"][])[
|
|
564
|
+
(bytes[0] >> 5) & 3
|
|
565
|
+
];
|
|
566
|
+
const value = numLeFromBytes(bytes.slice(1, 8));
|
|
567
|
+
|
|
568
|
+
return new Since(relative, metric, value);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
419
572
|
/**
|
|
420
573
|
* @public
|
|
421
574
|
*/
|
|
422
575
|
export type CellInputLike = {
|
|
423
576
|
previousOutput: OutPointLike;
|
|
424
|
-
since?: NumLike | null;
|
|
577
|
+
since?: SinceLike | NumLike | null;
|
|
425
578
|
cellOutput?: CellOutputLike | null;
|
|
426
579
|
outputData?: HexLike | null;
|
|
427
580
|
};
|
|
@@ -485,7 +638,7 @@ export class CellInput {
|
|
|
485
638
|
|
|
486
639
|
return new CellInput(
|
|
487
640
|
OutPoint.from(cellInput.previousOutput),
|
|
488
|
-
|
|
641
|
+
Since.from(cellInput.since ?? 0).toNum(),
|
|
489
642
|
apply(CellOutput.from, cellInput.cellOutput),
|
|
490
643
|
apply(hexFrom, cellInput.outputData),
|
|
491
644
|
);
|
|
@@ -1536,46 +1689,33 @@ export class Transaction {
|
|
|
1536
1689
|
addedCount: number;
|
|
1537
1690
|
accumulated?: T;
|
|
1538
1691
|
}> {
|
|
1539
|
-
const scripts = (await from.getAddressObjs()).map(({ script }) => script);
|
|
1540
1692
|
const collectedCells = [];
|
|
1541
1693
|
|
|
1542
1694
|
let acc: T = init;
|
|
1543
1695
|
let fulfilled = false;
|
|
1544
|
-
for (const
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
})) {
|
|
1552
|
-
if (
|
|
1553
|
-
this.inputs.some(({ previousOutput }) =>
|
|
1554
|
-
previousOutput.eq(cell.outPoint),
|
|
1555
|
-
)
|
|
1556
|
-
) {
|
|
1557
|
-
continue;
|
|
1558
|
-
}
|
|
1559
|
-
const i = collectedCells.push(cell);
|
|
1560
|
-
const next = await Promise.resolve(
|
|
1561
|
-
accumulator(acc, cell, i - 1, collectedCells),
|
|
1562
|
-
);
|
|
1563
|
-
if (next === undefined) {
|
|
1564
|
-
fulfilled = true;
|
|
1565
|
-
break;
|
|
1566
|
-
}
|
|
1567
|
-
acc = next;
|
|
1696
|
+
for await (const cell of from.findCells(filter, true)) {
|
|
1697
|
+
if (
|
|
1698
|
+
this.inputs.some(({ previousOutput }) =>
|
|
1699
|
+
previousOutput.eq(cell.outPoint),
|
|
1700
|
+
)
|
|
1701
|
+
) {
|
|
1702
|
+
continue;
|
|
1568
1703
|
}
|
|
1569
|
-
|
|
1704
|
+
const i = collectedCells.push(cell);
|
|
1705
|
+
const next = await Promise.resolve(
|
|
1706
|
+
accumulator(acc, cell, i - 1, collectedCells),
|
|
1707
|
+
);
|
|
1708
|
+
if (next === undefined) {
|
|
1709
|
+
fulfilled = true;
|
|
1570
1710
|
break;
|
|
1571
1711
|
}
|
|
1712
|
+
acc = next;
|
|
1572
1713
|
}
|
|
1573
1714
|
|
|
1574
1715
|
this.inputs.push(
|
|
1575
1716
|
...collectedCells.map(({ outPoint, outputData, cellOutput }) =>
|
|
1576
1717
|
CellInput.from({
|
|
1577
1718
|
previousOutput: outPoint,
|
|
1578
|
-
since: 0,
|
|
1579
1719
|
outputData,
|
|
1580
1720
|
cellOutput,
|
|
1581
1721
|
}),
|