@ckb-ccc/core 0.1.0 → 0.1.2
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 +12 -0
- package/dist.commonjs/address/address.advanced.js +28 -23
- package/dist.commonjs/address/advanced.js +17 -1
- package/dist.commonjs/address/index.js +15 -11
- package/dist.commonjs/advanced.js +31 -2
- package/dist.commonjs/advancedBarrel.js +21 -5
- package/dist.commonjs/barrel.js +41 -12
- package/dist.commonjs/bytes/advanced.js +2 -1
- package/dist.commonjs/bytes/index.js +12 -7
- package/dist.commonjs/ckb/advanced.js +32 -3
- package/dist.commonjs/ckb/index.js +19 -3
- package/dist.commonjs/ckb/molecule.advanced/generated.js +131 -64
- package/dist.commonjs/ckb/molecule.advanced/index.js +19 -2
- package/dist.commonjs/ckb/script.advanced.js +6 -3
- package/dist.commonjs/ckb/script.js +53 -23
- package/dist.commonjs/ckb/transaction.advanced.js +6 -3
- package/dist.commonjs/ckb/transaction.js +163 -122
- package/dist.commonjs/ckb/transactionLumos.js +2 -1
- package/dist.commonjs/client/advanced.js +22 -6
- package/dist.commonjs/client/cache/advanced.js +17 -1
- package/dist.commonjs/client/cache/cache.js +7 -3
- package/dist.commonjs/client/cache/index.js +18 -2
- package/dist.commonjs/client/cache/memory.advanced.js +28 -21
- package/dist.commonjs/client/cache/memory.js +23 -19
- package/dist.commonjs/client/client.js +25 -21
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +25 -22
- package/dist.commonjs/client/clientPublicMainnet.js +15 -8
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +25 -22
- package/dist.commonjs/client/clientPublicTestnet.js +15 -8
- package/dist.commonjs/client/clientTypes.advanced.js +6 -3
- package/dist.commonjs/client/clientTypes.js +43 -29
- package/dist.commonjs/client/index.js +22 -6
- package/dist.commonjs/client/jsonRpc/advanced.js +18 -2
- package/dist.commonjs/client/jsonRpc/index.js +41 -37
- package/dist.commonjs/client/jsonRpc/transformers.js +61 -57
- package/dist.commonjs/client/jsonRpc/types.js +2 -1
- package/dist.commonjs/client/transports/advanced.js +25 -8
- package/dist.commonjs/client/transports/http.js +5 -1
- package/dist.commonjs/client/transports/transport.js +2 -1
- package/dist.commonjs/client/transports/webSocket.js +10 -3
- package/dist.commonjs/fixedPoint/index.js +9 -4
- package/dist.commonjs/hasher/advanced.js +4 -1
- package/dist.commonjs/hasher/hasher.js +2 -1
- package/dist.commonjs/hasher/hasherCkb.js +20 -14
- package/dist.commonjs/hasher/hasherKeecak256.js +11 -7
- package/dist.commonjs/hasher/index.js +19 -3
- package/dist.commonjs/hex/index.js +6 -3
- package/dist.commonjs/index.js +31 -2
- package/dist.commonjs/keystore/index.js +25 -21
- package/dist.commonjs/molecule/codec.js +63 -48
- package/dist.commonjs/molecule/index.js +18 -2
- package/dist.commonjs/molecule/predefined.js +103 -77
- package/dist.commonjs/num/index.js +29 -17
- package/dist.commonjs/signer/btc/index.js +19 -3
- package/dist.commonjs/signer/btc/signerBtc.js +24 -20
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +8 -4
- package/dist.commonjs/signer/btc/verify.js +26 -17
- package/dist.commonjs/signer/ckb/index.js +21 -5
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +20 -16
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +24 -20
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +12 -8
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +16 -12
- package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -5
- package/dist.commonjs/signer/doge/index.js +20 -4
- package/dist.commonjs/signer/doge/signerDoge.js +26 -19
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +6 -2
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +17 -13
- package/dist.commonjs/signer/doge/verify.js +15 -12
- package/dist.commonjs/signer/dummy/alwaysError.js +6 -2
- package/dist.commonjs/signer/dummy/dummy.js +7 -3
- package/dist.commonjs/signer/dummy/index.js +19 -3
- package/dist.commonjs/signer/dummy/openLink.js +6 -2
- package/dist.commonjs/signer/evm/index.js +19 -3
- package/dist.commonjs/signer/evm/signerEvm.js +35 -31
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +8 -4
- package/dist.commonjs/signer/evm/verify.js +7 -4
- package/dist.commonjs/signer/index.js +23 -7
- package/dist.commonjs/signer/nostr/index.js +18 -2
- package/dist.commonjs/signer/nostr/signerNostr.js +25 -21
- package/dist.commonjs/signer/nostr/verify.js +16 -12
- package/dist.commonjs/signer/signer/index.js +25 -19
- package/dist.commonjs/utils/index.js +12 -6
- package/package.json +6 -2
|
@@ -1,12 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Transaction = exports.WitnessArgs = exports.CellDep = exports.CellInput = exports.Since = exports.Cell = exports.CellOutput = exports.OutPoint = void 0;
|
|
27
|
+
exports.depTypeFrom = depTypeFrom;
|
|
28
|
+
exports.depTypeToBytes = depTypeToBytes;
|
|
29
|
+
exports.depTypeFromBytes = depTypeFromBytes;
|
|
30
|
+
exports.epochFrom = epochFrom;
|
|
31
|
+
exports.epochFromHex = epochFromHex;
|
|
32
|
+
exports.epochToHex = epochToHex;
|
|
33
|
+
exports.udtBalanceFrom = udtBalanceFrom;
|
|
34
|
+
const index_js_1 = require("../bytes/index.js");
|
|
35
|
+
const index_js_2 = require("../fixedPoint/index.js");
|
|
36
|
+
const index_js_3 = require("../hasher/index.js");
|
|
37
|
+
const index_js_4 = require("../hex/index.js");
|
|
38
|
+
const index_js_5 = require("../num/index.js");
|
|
39
|
+
const index_js_6 = require("../utils/index.js");
|
|
40
|
+
const mol = __importStar(require("./molecule.advanced/index.js"));
|
|
41
|
+
const script_js_1 = require("./script.js");
|
|
42
|
+
const transaction_advanced_js_1 = require("./transaction.advanced.js");
|
|
10
43
|
/**
|
|
11
44
|
* Converts a DepTypeLike value to a DepType.
|
|
12
45
|
* @public
|
|
@@ -22,13 +55,13 @@ import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
|
|
|
22
55
|
* const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
|
|
23
56
|
* ```
|
|
24
57
|
*/
|
|
25
|
-
|
|
58
|
+
function depTypeFrom(val) {
|
|
26
59
|
const depType = (() => {
|
|
27
60
|
if (typeof val === "number") {
|
|
28
|
-
return NUM_TO_DEP_TYPE[val];
|
|
61
|
+
return transaction_advanced_js_1.NUM_TO_DEP_TYPE[val];
|
|
29
62
|
}
|
|
30
63
|
if (typeof val === "bigint") {
|
|
31
|
-
return NUM_TO_DEP_TYPE[Number(val)];
|
|
64
|
+
return transaction_advanced_js_1.NUM_TO_DEP_TYPE[Number(val)];
|
|
32
65
|
}
|
|
33
66
|
return val;
|
|
34
67
|
})();
|
|
@@ -49,8 +82,8 @@ export function depTypeFrom(val) {
|
|
|
49
82
|
* const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
|
|
50
83
|
* ```
|
|
51
84
|
*/
|
|
52
|
-
|
|
53
|
-
return bytesFrom([DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
|
|
85
|
+
function depTypeToBytes(depType) {
|
|
86
|
+
return (0, index_js_1.bytesFrom)([transaction_advanced_js_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
|
|
54
87
|
}
|
|
55
88
|
/**
|
|
56
89
|
* Converts a byte-like value to a DepType.
|
|
@@ -66,13 +99,13 @@ export function depTypeToBytes(depType) {
|
|
|
66
99
|
* const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
|
|
67
100
|
* ```
|
|
68
101
|
*/
|
|
69
|
-
|
|
70
|
-
return NUM_TO_DEP_TYPE[bytesFrom(bytes)[0]];
|
|
102
|
+
function depTypeFromBytes(bytes) {
|
|
103
|
+
return transaction_advanced_js_1.NUM_TO_DEP_TYPE[(0, index_js_1.bytesFrom)(bytes)[0]];
|
|
71
104
|
}
|
|
72
105
|
/**
|
|
73
106
|
* @public
|
|
74
107
|
*/
|
|
75
|
-
|
|
108
|
+
class OutPoint {
|
|
76
109
|
/**
|
|
77
110
|
* Creates an instance of OutPoint.
|
|
78
111
|
*
|
|
@@ -111,7 +144,7 @@ export class OutPoint {
|
|
|
111
144
|
if (outPoint instanceof OutPoint) {
|
|
112
145
|
return outPoint;
|
|
113
146
|
}
|
|
114
|
-
return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
|
|
147
|
+
return new OutPoint((0, index_js_4.hexFrom)(outPoint.txHash), (0, index_js_5.numFrom)(outPoint.index));
|
|
115
148
|
}
|
|
116
149
|
/**
|
|
117
150
|
* Converts the OutPoint instance to molecule data format.
|
|
@@ -120,8 +153,8 @@ export class OutPoint {
|
|
|
120
153
|
*/
|
|
121
154
|
_toMolData() {
|
|
122
155
|
return {
|
|
123
|
-
txHash: bytesFrom(this.txHash),
|
|
124
|
-
index: numToBytes(this.index, 4),
|
|
156
|
+
txHash: (0, index_js_1.bytesFrom)(this.txHash),
|
|
157
|
+
index: (0, index_js_5.numToBytes)(this.index, 4),
|
|
125
158
|
};
|
|
126
159
|
}
|
|
127
160
|
/**
|
|
@@ -135,7 +168,7 @@ export class OutPoint {
|
|
|
135
168
|
* ```
|
|
136
169
|
*/
|
|
137
170
|
toBytes() {
|
|
138
|
-
return bytesFrom(mol.SerializeOutPoint(this._toMolData()));
|
|
171
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
|
|
139
172
|
}
|
|
140
173
|
/**
|
|
141
174
|
* Creates an OutPoint instance from a byte-like value or molecule OutPoint.
|
|
@@ -151,8 +184,8 @@ export class OutPoint {
|
|
|
151
184
|
static fromBytes(bytes) {
|
|
152
185
|
const view = bytes instanceof mol.OutPoint
|
|
153
186
|
? bytes
|
|
154
|
-
: new mol.OutPoint(bytesFrom(bytes));
|
|
155
|
-
return new OutPoint(hexFrom(view.getTxHash().raw()), numFromBytes(view.getIndex().raw()));
|
|
187
|
+
: new mol.OutPoint((0, index_js_1.bytesFrom)(bytes));
|
|
188
|
+
return new OutPoint((0, index_js_4.hexFrom)(view.getTxHash().raw()), (0, index_js_5.numFromBytes)(view.getIndex().raw()));
|
|
156
189
|
}
|
|
157
190
|
/**
|
|
158
191
|
* Compares the current OutPoint instance with another OutPointLike object for equality.
|
|
@@ -170,10 +203,11 @@ export class OutPoint {
|
|
|
170
203
|
return this.txHash === outPoint.txHash && this.index === outPoint.index;
|
|
171
204
|
}
|
|
172
205
|
}
|
|
206
|
+
exports.OutPoint = OutPoint;
|
|
173
207
|
/**
|
|
174
208
|
* @public
|
|
175
209
|
*/
|
|
176
|
-
|
|
210
|
+
class CellOutput {
|
|
177
211
|
/**
|
|
178
212
|
* Creates an instance of CellOutput.
|
|
179
213
|
*
|
|
@@ -221,7 +255,7 @@ export class CellOutput {
|
|
|
221
255
|
if (cellOutput instanceof CellOutput) {
|
|
222
256
|
return cellOutput;
|
|
223
257
|
}
|
|
224
|
-
return new CellOutput(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
|
|
258
|
+
return new CellOutput((0, index_js_5.numFrom)(cellOutput.capacity), script_js_1.Script.from(cellOutput.lock), (0, index_js_6.apply)(script_js_1.Script.from, cellOutput.type));
|
|
225
259
|
}
|
|
226
260
|
/**
|
|
227
261
|
* Converts the CellOutput instance to molecule data format.
|
|
@@ -230,7 +264,7 @@ export class CellOutput {
|
|
|
230
264
|
*/
|
|
231
265
|
_toMolData() {
|
|
232
266
|
return {
|
|
233
|
-
capacity: numToBytes(this.capacity, 8),
|
|
267
|
+
capacity: (0, index_js_5.numToBytes)(this.capacity, 8),
|
|
234
268
|
lock: this.lock._toMolData(),
|
|
235
269
|
type: this.type?._toMolData(),
|
|
236
270
|
};
|
|
@@ -246,7 +280,7 @@ export class CellOutput {
|
|
|
246
280
|
* ```
|
|
247
281
|
*/
|
|
248
282
|
toBytes() {
|
|
249
|
-
return bytesFrom(mol.SerializeCellOutput(this._toMolData()));
|
|
283
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
|
|
250
284
|
}
|
|
251
285
|
/**
|
|
252
286
|
* Creates a CellOutput instance from a byte-like value or molecule CellOutput.
|
|
@@ -262,14 +296,15 @@ export class CellOutput {
|
|
|
262
296
|
static fromBytes(bytes) {
|
|
263
297
|
const view = bytes instanceof mol.CellOutput
|
|
264
298
|
? bytes
|
|
265
|
-
: new mol.CellOutput(bytesFrom(bytes));
|
|
266
|
-
return new CellOutput(numFromBytes(view.getCapacity().raw()), Script.fromBytes(view.getLock()), apply(Script.fromBytes, mol.molOptional(view.getType())));
|
|
299
|
+
: new mol.CellOutput((0, index_js_1.bytesFrom)(bytes));
|
|
300
|
+
return new CellOutput((0, index_js_5.numFromBytes)(view.getCapacity().raw()), script_js_1.Script.fromBytes(view.getLock()), (0, index_js_6.apply)(script_js_1.Script.fromBytes, mol.molOptional(view.getType())));
|
|
267
301
|
}
|
|
268
302
|
}
|
|
303
|
+
exports.CellOutput = CellOutput;
|
|
269
304
|
/**
|
|
270
305
|
* @public
|
|
271
306
|
*/
|
|
272
|
-
|
|
307
|
+
class Cell {
|
|
273
308
|
/**
|
|
274
309
|
* Creates an instance of Cell.
|
|
275
310
|
*
|
|
@@ -292,7 +327,7 @@ export class Cell {
|
|
|
292
327
|
if (cell instanceof Cell) {
|
|
293
328
|
return cell;
|
|
294
329
|
}
|
|
295
|
-
return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
|
|
330
|
+
return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), (0, index_js_4.hexFrom)(cell.outputData));
|
|
296
331
|
}
|
|
297
332
|
/**
|
|
298
333
|
* Clone a Cell
|
|
@@ -308,36 +343,37 @@ export class Cell {
|
|
|
308
343
|
return new Cell(this.outPoint.clone(), this.cellOutput.clone(), this.outputData);
|
|
309
344
|
}
|
|
310
345
|
}
|
|
346
|
+
exports.Cell = Cell;
|
|
311
347
|
/**
|
|
312
348
|
* @public
|
|
313
349
|
*/
|
|
314
|
-
|
|
315
|
-
return [numFrom(epochLike[0]), numFrom(epochLike[1]), numFrom(epochLike[2])];
|
|
350
|
+
function epochFrom(epochLike) {
|
|
351
|
+
return [(0, index_js_5.numFrom)(epochLike[0]), (0, index_js_5.numFrom)(epochLike[1]), (0, index_js_5.numFrom)(epochLike[2])];
|
|
316
352
|
}
|
|
317
353
|
/**
|
|
318
354
|
* @public
|
|
319
355
|
*/
|
|
320
|
-
|
|
321
|
-
const num = numFrom(hexFrom(hex));
|
|
356
|
+
function epochFromHex(hex) {
|
|
357
|
+
const num = (0, index_js_5.numFrom)((0, index_js_4.hexFrom)(hex));
|
|
322
358
|
return [
|
|
323
|
-
num & numFrom("0xffffff"),
|
|
324
|
-
(num >> numFrom(24)) & numFrom("0xffff"),
|
|
325
|
-
(num >> numFrom(40)) & numFrom("0xffff"),
|
|
359
|
+
num & (0, index_js_5.numFrom)("0xffffff"),
|
|
360
|
+
(num >> (0, index_js_5.numFrom)(24)) & (0, index_js_5.numFrom)("0xffff"),
|
|
361
|
+
(num >> (0, index_js_5.numFrom)(40)) & (0, index_js_5.numFrom)("0xffff"),
|
|
326
362
|
];
|
|
327
363
|
}
|
|
328
364
|
/**
|
|
329
365
|
* @public
|
|
330
366
|
*/
|
|
331
|
-
|
|
367
|
+
function epochToHex(epochLike) {
|
|
332
368
|
const epoch = epochFrom(epochLike);
|
|
333
|
-
return numToHex(numFrom(epoch[0]) +
|
|
334
|
-
(numFrom(epoch[1]) << numFrom(24)) +
|
|
335
|
-
(numFrom(epoch[2]) << numFrom(40)));
|
|
369
|
+
return (0, index_js_5.numToHex)((0, index_js_5.numFrom)(epoch[0]) +
|
|
370
|
+
((0, index_js_5.numFrom)(epoch[1]) << (0, index_js_5.numFrom)(24)) +
|
|
371
|
+
((0, index_js_5.numFrom)(epoch[2]) << (0, index_js_5.numFrom)(40)));
|
|
336
372
|
}
|
|
337
373
|
/**
|
|
338
374
|
* @public
|
|
339
375
|
*/
|
|
340
|
-
|
|
376
|
+
class Since {
|
|
341
377
|
/**
|
|
342
378
|
* Creates an instance of Since.
|
|
343
379
|
*
|
|
@@ -379,7 +415,7 @@ export class Since {
|
|
|
379
415
|
return since;
|
|
380
416
|
}
|
|
381
417
|
if (typeof since === "object" && "relative" in since) {
|
|
382
|
-
return new Since(since.relative, since.metric, numFrom(since.value));
|
|
418
|
+
return new Since(since.relative, since.metric, (0, index_js_5.numFrom)(since.value));
|
|
383
419
|
}
|
|
384
420
|
return Since.fromNum(since);
|
|
385
421
|
}
|
|
@@ -395,11 +431,11 @@ export class Since {
|
|
|
395
431
|
*/
|
|
396
432
|
toNum() {
|
|
397
433
|
return (this.value |
|
|
398
|
-
(this.relative === "absolute" ? Zero : numFrom("0x8000000000000000")) |
|
|
434
|
+
(this.relative === "absolute" ? index_js_2.Zero : (0, index_js_5.numFrom)("0x8000000000000000")) |
|
|
399
435
|
{
|
|
400
|
-
blockNumber: numFrom("0x0000000000000000"),
|
|
401
|
-
epoch: numFrom("0x2000000000000000"),
|
|
402
|
-
timestamp: numFrom("0x4000000000000000"),
|
|
436
|
+
blockNumber: (0, index_js_5.numFrom)("0x0000000000000000"),
|
|
437
|
+
epoch: (0, index_js_5.numFrom)("0x2000000000000000"),
|
|
438
|
+
timestamp: (0, index_js_5.numFrom)("0x4000000000000000"),
|
|
403
439
|
}[this.metric]);
|
|
404
440
|
}
|
|
405
441
|
/**
|
|
@@ -414,17 +450,18 @@ export class Since {
|
|
|
414
450
|
* ```
|
|
415
451
|
*/
|
|
416
452
|
static fromNum(numLike) {
|
|
417
|
-
const num = numFrom(numLike);
|
|
418
|
-
const relative = num >> numFrom(63) === Zero ? "absolute" : "relative";
|
|
419
|
-
const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> numFrom(61)) & numFrom(3))];
|
|
420
|
-
const value = num & numFrom("0x00ffffffffffffff");
|
|
453
|
+
const num = (0, index_js_5.numFrom)(numLike);
|
|
454
|
+
const relative = num >> (0, index_js_5.numFrom)(63) === index_js_2.Zero ? "absolute" : "relative";
|
|
455
|
+
const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> (0, index_js_5.numFrom)(61)) & (0, index_js_5.numFrom)(3))];
|
|
456
|
+
const value = num & (0, index_js_5.numFrom)("0x00ffffffffffffff");
|
|
421
457
|
return new Since(relative, metric, value);
|
|
422
458
|
}
|
|
423
459
|
}
|
|
460
|
+
exports.Since = Since;
|
|
424
461
|
/**
|
|
425
462
|
* @public
|
|
426
463
|
*/
|
|
427
|
-
|
|
464
|
+
class CellInput {
|
|
428
465
|
/**
|
|
429
466
|
* Creates an instance of CellInput.
|
|
430
467
|
*
|
|
@@ -470,7 +507,7 @@ export class CellInput {
|
|
|
470
507
|
if (cellInput instanceof CellInput) {
|
|
471
508
|
return cellInput;
|
|
472
509
|
}
|
|
473
|
-
return new CellInput(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), apply(CellOutput.from, cellInput.cellOutput), apply(hexFrom, cellInput.outputData));
|
|
510
|
+
return new CellInput(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), (0, index_js_6.apply)(CellOutput.from, cellInput.cellOutput), (0, index_js_6.apply)(index_js_4.hexFrom, cellInput.outputData));
|
|
474
511
|
}
|
|
475
512
|
/**
|
|
476
513
|
* Complete extra infos in the input. Like the output of the out point.
|
|
@@ -501,7 +538,7 @@ export class CellInput {
|
|
|
501
538
|
_toMolData() {
|
|
502
539
|
return {
|
|
503
540
|
previousOutput: this.previousOutput._toMolData(),
|
|
504
|
-
since: numToBytes(this.since, 8),
|
|
541
|
+
since: (0, index_js_5.numToBytes)(this.since, 8),
|
|
505
542
|
};
|
|
506
543
|
}
|
|
507
544
|
/**
|
|
@@ -515,7 +552,7 @@ export class CellInput {
|
|
|
515
552
|
* ```
|
|
516
553
|
*/
|
|
517
554
|
toBytes() {
|
|
518
|
-
return bytesFrom(mol.SerializeCellInput(this._toMolData()));
|
|
555
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
|
|
519
556
|
}
|
|
520
557
|
/**
|
|
521
558
|
* Creates a CellInput instance from a byte-like value or molecule CellInput.
|
|
@@ -531,14 +568,15 @@ export class CellInput {
|
|
|
531
568
|
static fromBytes(bytes) {
|
|
532
569
|
const view = bytes instanceof mol.CellInput
|
|
533
570
|
? bytes
|
|
534
|
-
: new mol.CellInput(bytesFrom(bytes));
|
|
535
|
-
return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), numFromBytes(view.getSince().raw()));
|
|
571
|
+
: new mol.CellInput((0, index_js_1.bytesFrom)(bytes));
|
|
572
|
+
return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, index_js_5.numFromBytes)(view.getSince().raw()));
|
|
536
573
|
}
|
|
537
574
|
}
|
|
575
|
+
exports.CellInput = CellInput;
|
|
538
576
|
/**
|
|
539
577
|
* @public
|
|
540
578
|
*/
|
|
541
|
-
|
|
579
|
+
class CellDep {
|
|
542
580
|
/**
|
|
543
581
|
* Creates an instance of CellDep.
|
|
544
582
|
*
|
|
@@ -604,7 +642,7 @@ export class CellDep {
|
|
|
604
642
|
* ```
|
|
605
643
|
*/
|
|
606
644
|
toBytes() {
|
|
607
|
-
return bytesFrom(mol.SerializeCellDep(this._toMolData()));
|
|
645
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
|
|
608
646
|
}
|
|
609
647
|
/**
|
|
610
648
|
* Creates a CellDep instance from a byte-like value or molecule CellDep.
|
|
@@ -618,7 +656,7 @@ export class CellDep {
|
|
|
618
656
|
* ```
|
|
619
657
|
*/
|
|
620
658
|
fromBytes(bytes) {
|
|
621
|
-
const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep(bytesFrom(bytes));
|
|
659
|
+
const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, index_js_1.bytesFrom)(bytes));
|
|
622
660
|
return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
|
|
623
661
|
}
|
|
624
662
|
/**
|
|
@@ -637,10 +675,11 @@ export class CellDep {
|
|
|
637
675
|
return (this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType);
|
|
638
676
|
}
|
|
639
677
|
}
|
|
678
|
+
exports.CellDep = CellDep;
|
|
640
679
|
/**
|
|
641
680
|
* @public
|
|
642
681
|
*/
|
|
643
|
-
|
|
682
|
+
class WitnessArgs {
|
|
644
683
|
/**
|
|
645
684
|
* Creates an instance of WitnessArgs.
|
|
646
685
|
*
|
|
@@ -672,7 +711,7 @@ export class WitnessArgs {
|
|
|
672
711
|
if (witnessArgs instanceof WitnessArgs) {
|
|
673
712
|
return witnessArgs;
|
|
674
713
|
}
|
|
675
|
-
return new WitnessArgs(apply(hexFrom, witnessArgs.lock), apply(hexFrom, witnessArgs.inputType), apply(hexFrom, witnessArgs.outputType));
|
|
714
|
+
return new WitnessArgs((0, index_js_6.apply)(index_js_4.hexFrom, witnessArgs.lock), (0, index_js_6.apply)(index_js_4.hexFrom, witnessArgs.inputType), (0, index_js_6.apply)(index_js_4.hexFrom, witnessArgs.outputType));
|
|
676
715
|
}
|
|
677
716
|
/**
|
|
678
717
|
* Converts the WitnessArgs instance to molecule data format.
|
|
@@ -681,9 +720,9 @@ export class WitnessArgs {
|
|
|
681
720
|
*/
|
|
682
721
|
_toMolData() {
|
|
683
722
|
return {
|
|
684
|
-
lock: apply(bytesFrom, this.lock),
|
|
685
|
-
inputType: apply(bytesFrom, this.inputType),
|
|
686
|
-
outputType: apply(bytesFrom, this.outputType),
|
|
723
|
+
lock: (0, index_js_6.apply)(index_js_1.bytesFrom, this.lock),
|
|
724
|
+
inputType: (0, index_js_6.apply)(index_js_1.bytesFrom, this.inputType),
|
|
725
|
+
outputType: (0, index_js_6.apply)(index_js_1.bytesFrom, this.outputType),
|
|
687
726
|
};
|
|
688
727
|
}
|
|
689
728
|
/**
|
|
@@ -697,7 +736,7 @@ export class WitnessArgs {
|
|
|
697
736
|
* ```
|
|
698
737
|
*/
|
|
699
738
|
toBytes() {
|
|
700
|
-
return bytesFrom(mol.SerializeWitnessArgs(this._toMolData()));
|
|
739
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
|
|
701
740
|
}
|
|
702
741
|
/**
|
|
703
742
|
* Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
|
|
@@ -713,24 +752,25 @@ export class WitnessArgs {
|
|
|
713
752
|
static fromBytes(bytes) {
|
|
714
753
|
const view = bytes instanceof mol.WitnessArgs
|
|
715
754
|
? bytes
|
|
716
|
-
: new mol.WitnessArgs(bytesFrom(bytes));
|
|
717
|
-
return new WitnessArgs(apply(hexFrom, mol.molOptional(view.getLock())?.raw()), apply(hexFrom, mol.molOptional(view.getInputType())?.raw()), apply(hexFrom, mol.molOptional(view.getOutputType())?.raw()));
|
|
755
|
+
: new mol.WitnessArgs((0, index_js_1.bytesFrom)(bytes));
|
|
756
|
+
return new WitnessArgs((0, index_js_6.apply)(index_js_4.hexFrom, mol.molOptional(view.getLock())?.raw()), (0, index_js_6.apply)(index_js_4.hexFrom, mol.molOptional(view.getInputType())?.raw()), (0, index_js_6.apply)(index_js_4.hexFrom, mol.molOptional(view.getOutputType())?.raw()));
|
|
718
757
|
}
|
|
719
758
|
}
|
|
759
|
+
exports.WitnessArgs = WitnessArgs;
|
|
720
760
|
/**
|
|
721
761
|
* @public
|
|
722
762
|
*/
|
|
723
|
-
|
|
724
|
-
const data = bytesFrom(dataLike).slice(0, 16);
|
|
763
|
+
function udtBalanceFrom(dataLike) {
|
|
764
|
+
const data = (0, index_js_1.bytesFrom)(dataLike).slice(0, 16);
|
|
725
765
|
if (data.length !== 16) {
|
|
726
766
|
throw new Error("Invalid UDT cell data");
|
|
727
767
|
}
|
|
728
|
-
return numFromBytes(data);
|
|
768
|
+
return (0, index_js_5.numFromBytes)(data);
|
|
729
769
|
}
|
|
730
770
|
/**
|
|
731
771
|
* @public
|
|
732
772
|
*/
|
|
733
|
-
|
|
773
|
+
class Transaction {
|
|
734
774
|
/**
|
|
735
775
|
* Creates an instance of Transaction.
|
|
736
776
|
*
|
|
@@ -823,17 +863,17 @@ export class Transaction {
|
|
|
823
863
|
...output,
|
|
824
864
|
capacity: output.capacity ?? 0,
|
|
825
865
|
});
|
|
826
|
-
if (o.capacity === Zero) {
|
|
827
|
-
o.capacity = fixedPointFrom(o.occupiedSize +
|
|
828
|
-
(apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
866
|
+
if (o.capacity === index_js_2.Zero) {
|
|
867
|
+
o.capacity = (0, index_js_2.fixedPointFrom)(o.occupiedSize +
|
|
868
|
+
((0, index_js_6.apply)(index_js_1.bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
829
869
|
}
|
|
830
870
|
return o;
|
|
831
871
|
}) ?? [];
|
|
832
|
-
const outputsData = outputs.map((_, i) => hexFrom(tx.outputsData?.[i] ?? "0x"));
|
|
872
|
+
const outputsData = outputs.map((_, i) => (0, index_js_4.hexFrom)(tx.outputsData?.[i] ?? "0x"));
|
|
833
873
|
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
834
|
-
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)));
|
|
874
|
+
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => (0, index_js_4.hexFrom)(d)));
|
|
835
875
|
}
|
|
836
|
-
return new Transaction(numFrom(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(hexFrom) ?? []);
|
|
876
|
+
return new Transaction((0, index_js_5.numFrom)(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(index_js_4.hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(index_js_4.hexFrom) ?? []);
|
|
837
877
|
}
|
|
838
878
|
/**
|
|
839
879
|
* Creates a Transaction instance from a Lumos skeleton.
|
|
@@ -872,7 +912,7 @@ export class Transaction {
|
|
|
872
912
|
stringify() {
|
|
873
913
|
return JSON.stringify(this, (_, value) => {
|
|
874
914
|
if (typeof value === "bigint") {
|
|
875
|
-
return numToHex(value);
|
|
915
|
+
return (0, index_js_5.numToHex)(value);
|
|
876
916
|
}
|
|
877
917
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
878
918
|
return value;
|
|
@@ -889,13 +929,13 @@ export class Transaction {
|
|
|
889
929
|
* ```
|
|
890
930
|
*/
|
|
891
931
|
rawToBytes() {
|
|
892
|
-
return bytesFrom(mol.SerializeRawTransaction({
|
|
893
|
-
version: numToBytes(this.version, 4),
|
|
932
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeRawTransaction({
|
|
933
|
+
version: (0, index_js_5.numToBytes)(this.version, 4),
|
|
894
934
|
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
895
|
-
headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
|
|
935
|
+
headerDeps: this.headerDeps.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
896
936
|
inputs: this.inputs.map((i) => i._toMolData()),
|
|
897
937
|
outputs: this.outputs.map((o) => o._toMolData()),
|
|
898
|
-
outputsData: this.outputsData.map((header) => bytesFrom(header)),
|
|
938
|
+
outputsData: this.outputsData.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
899
939
|
}));
|
|
900
940
|
}
|
|
901
941
|
/**
|
|
@@ -909,16 +949,16 @@ export class Transaction {
|
|
|
909
949
|
* ```
|
|
910
950
|
*/
|
|
911
951
|
toBytes() {
|
|
912
|
-
return bytesFrom(mol.SerializeTransaction({
|
|
952
|
+
return (0, index_js_1.bytesFrom)(mol.SerializeTransaction({
|
|
913
953
|
raw: {
|
|
914
|
-
version: numToBytes(this.version, 4),
|
|
954
|
+
version: (0, index_js_5.numToBytes)(this.version, 4),
|
|
915
955
|
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
916
|
-
headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
|
|
956
|
+
headerDeps: this.headerDeps.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
917
957
|
inputs: this.inputs.map((i) => i._toMolData()),
|
|
918
958
|
outputs: this.outputs.map((o) => o._toMolData()),
|
|
919
|
-
outputsData: this.outputsData.map((header) => bytesFrom(header)),
|
|
959
|
+
outputsData: this.outputsData.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
920
960
|
},
|
|
921
|
-
witnesses: this.witnesses.map((witness) => bytesFrom(witness)),
|
|
961
|
+
witnesses: this.witnesses.map((witness) => (0, index_js_1.bytesFrom)(witness)),
|
|
922
962
|
}));
|
|
923
963
|
}
|
|
924
964
|
/**
|
|
@@ -932,7 +972,7 @@ export class Transaction {
|
|
|
932
972
|
* ```
|
|
933
973
|
*/
|
|
934
974
|
hash() {
|
|
935
|
-
return hashCkb(this.rawToBytes());
|
|
975
|
+
return (0, index_js_3.hashCkb)(this.rawToBytes());
|
|
936
976
|
}
|
|
937
977
|
/**
|
|
938
978
|
* Hashes a witness and updates the hasher.
|
|
@@ -946,8 +986,8 @@ export class Transaction {
|
|
|
946
986
|
* ```
|
|
947
987
|
*/
|
|
948
988
|
static hashWitnessToHasher(witness, hasher) {
|
|
949
|
-
const raw = bytesFrom(hexFrom(witness));
|
|
950
|
-
hasher.update(numToBytes(raw.length, 8));
|
|
989
|
+
const raw = (0, index_js_1.bytesFrom)((0, index_js_4.hexFrom)(witness));
|
|
990
|
+
hasher.update((0, index_js_5.numToBytes)(raw.length, 8));
|
|
951
991
|
hasher.update(raw);
|
|
952
992
|
}
|
|
953
993
|
/**
|
|
@@ -967,8 +1007,8 @@ export class Transaction {
|
|
|
967
1007
|
* }
|
|
968
1008
|
* ```
|
|
969
1009
|
*/
|
|
970
|
-
async getSignHashInfo(scriptLike, client, hasher = new HasherCkb()) {
|
|
971
|
-
const script = Script.from(scriptLike);
|
|
1010
|
+
async getSignHashInfo(scriptLike, client, hasher = new index_js_3.HasherCkb()) {
|
|
1011
|
+
const script = script_js_1.Script.from(scriptLike);
|
|
972
1012
|
let position = -1;
|
|
973
1013
|
hasher.update(this.hash());
|
|
974
1014
|
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
@@ -1011,7 +1051,7 @@ export class Transaction {
|
|
|
1011
1051
|
* ```
|
|
1012
1052
|
*/
|
|
1013
1053
|
async findInputIndexByLockId(scriptIdLike, client) {
|
|
1014
|
-
const script = Script.from({ ...scriptIdLike, args: "0x" });
|
|
1054
|
+
const script = script_js_1.Script.from({ ...scriptIdLike, args: "0x" });
|
|
1015
1055
|
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
1016
1056
|
const input = this.inputs[i];
|
|
1017
1057
|
await input.completeExtraInfos(client);
|
|
@@ -1037,7 +1077,7 @@ export class Transaction {
|
|
|
1037
1077
|
* ```
|
|
1038
1078
|
*/
|
|
1039
1079
|
async findInputIndexByLock(scriptLike, client) {
|
|
1040
|
-
const script = Script.from(scriptLike);
|
|
1080
|
+
const script = script_js_1.Script.from(scriptLike);
|
|
1041
1081
|
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
1042
1082
|
const input = this.inputs[i];
|
|
1043
1083
|
await input.completeExtraInfos(client);
|
|
@@ -1062,7 +1102,7 @@ export class Transaction {
|
|
|
1062
1102
|
* ```
|
|
1063
1103
|
*/
|
|
1064
1104
|
async findLastInputIndexByLock(scriptLike, client) {
|
|
1065
|
-
const script = Script.from(scriptLike);
|
|
1105
|
+
const script = script_js_1.Script.from(scriptLike);
|
|
1066
1106
|
for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
|
|
1067
1107
|
const input = this.inputs[i];
|
|
1068
1108
|
await input.completeExtraInfos(client);
|
|
@@ -1157,7 +1197,7 @@ export class Transaction {
|
|
|
1157
1197
|
if (this.outputsData.length < index) {
|
|
1158
1198
|
this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
|
|
1159
1199
|
}
|
|
1160
|
-
this.outputsData[index] = hexFrom(witness);
|
|
1200
|
+
this.outputsData[index] = (0, index_js_4.hexFrom)(witness);
|
|
1161
1201
|
}
|
|
1162
1202
|
/**
|
|
1163
1203
|
* Add output
|
|
@@ -1175,8 +1215,8 @@ export class Transaction {
|
|
|
1175
1215
|
...outputLike,
|
|
1176
1216
|
capacity: outputLike.capacity ?? 0,
|
|
1177
1217
|
});
|
|
1178
|
-
if (output.capacity === Zero) {
|
|
1179
|
-
output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData).length);
|
|
1218
|
+
if (output.capacity === index_js_2.Zero) {
|
|
1219
|
+
output.capacity = (0, index_js_2.fixedPointFrom)(output.occupiedSize + (0, index_js_1.bytesFrom)(outputData).length);
|
|
1180
1220
|
}
|
|
1181
1221
|
const i = this.outputs.push(output) - 1;
|
|
1182
1222
|
this.setOutputDataAt(i, outputData);
|
|
@@ -1213,7 +1253,7 @@ export class Transaction {
|
|
|
1213
1253
|
if (this.witnesses.length < index) {
|
|
1214
1254
|
this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
|
|
1215
1255
|
}
|
|
1216
|
-
this.witnesses[index] = hexFrom(witness.toBytes());
|
|
1256
|
+
this.witnesses[index] = (0, index_js_4.hexFrom)(witness.toBytes());
|
|
1217
1257
|
}
|
|
1218
1258
|
/**
|
|
1219
1259
|
* Prepare dummy witness for sighash all method
|
|
@@ -1234,23 +1274,23 @@ export class Transaction {
|
|
|
1234
1274
|
return;
|
|
1235
1275
|
}
|
|
1236
1276
|
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
1237
|
-
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
1277
|
+
witness.lock = (0, index_js_4.hexFrom)(Array.from(new Array(lockLen), () => 0));
|
|
1238
1278
|
this.setWitnessArgsAt(position, witness);
|
|
1239
1279
|
}
|
|
1240
1280
|
async getInputsCapacity(client) {
|
|
1241
|
-
return reduceAsync(this.inputs, async (acc, input) => {
|
|
1281
|
+
return (0, index_js_6.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1242
1282
|
await input.completeExtraInfos(client);
|
|
1243
1283
|
if (!input.cellOutput) {
|
|
1244
1284
|
throw new Error("Unable to complete input");
|
|
1245
1285
|
}
|
|
1246
1286
|
return acc + input.cellOutput.capacity;
|
|
1247
|
-
}, numFrom(0));
|
|
1287
|
+
}, (0, index_js_5.numFrom)(0));
|
|
1248
1288
|
}
|
|
1249
1289
|
getOutputsCapacity() {
|
|
1250
|
-
return this.outputs.reduce((acc, { capacity }) => acc + capacity, numFrom(0));
|
|
1290
|
+
return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0, index_js_5.numFrom)(0));
|
|
1251
1291
|
}
|
|
1252
1292
|
async getInputsUdtBalance(client, type) {
|
|
1253
|
-
return reduceAsync(this.inputs, async (acc, input) => {
|
|
1293
|
+
return (0, index_js_6.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1254
1294
|
await input.completeExtraInfos(client);
|
|
1255
1295
|
if (!input.cellOutput || !input.outputData) {
|
|
1256
1296
|
throw new Error("Unable to complete input");
|
|
@@ -1259,7 +1299,7 @@ export class Transaction {
|
|
|
1259
1299
|
return;
|
|
1260
1300
|
}
|
|
1261
1301
|
return acc + udtBalanceFrom(input.outputData);
|
|
1262
|
-
}, numFrom(0));
|
|
1302
|
+
}, (0, index_js_5.numFrom)(0));
|
|
1263
1303
|
}
|
|
1264
1304
|
getOutputsUdtBalance(type) {
|
|
1265
1305
|
return this.outputs.reduce((acc, output, i) => {
|
|
@@ -1267,7 +1307,7 @@ export class Transaction {
|
|
|
1267
1307
|
return acc;
|
|
1268
1308
|
}
|
|
1269
1309
|
return acc + udtBalanceFrom(this.outputsData[i]);
|
|
1270
|
-
}, numFrom(0));
|
|
1310
|
+
}, (0, index_js_5.numFrom)(0));
|
|
1271
1311
|
}
|
|
1272
1312
|
async completeInputs(from, filter, accumulator, init) {
|
|
1273
1313
|
const collectedCells = [];
|
|
@@ -1301,7 +1341,7 @@ export class Transaction {
|
|
|
1301
1341
|
};
|
|
1302
1342
|
}
|
|
1303
1343
|
async completeInputsByCapacity(from, capacityTweak, filter) {
|
|
1304
|
-
const exceptedCapacity = this.getOutputsCapacity() + numFrom(capacityTweak ?? 0);
|
|
1344
|
+
const exceptedCapacity = this.getOutputsCapacity() + (0, index_js_5.numFrom)(capacityTweak ?? 0);
|
|
1305
1345
|
const inputsCapacity = await this.getInputsCapacity(from.client);
|
|
1306
1346
|
if (inputsCapacity >= exceptedCapacity) {
|
|
1307
1347
|
return 0;
|
|
@@ -1316,13 +1356,13 @@ export class Transaction {
|
|
|
1316
1356
|
if (accumulated === undefined) {
|
|
1317
1357
|
return addedCount;
|
|
1318
1358
|
}
|
|
1319
|
-
throw new Error(`Insufficient CKB, need ${fixedPointToString(exceptedCapacity - accumulated)} extra CKB`);
|
|
1359
|
+
throw new Error(`Insufficient CKB, need ${(0, index_js_2.fixedPointToString)(exceptedCapacity - accumulated)} extra CKB`);
|
|
1320
1360
|
}
|
|
1321
1361
|
async completeInputsAll(from, filter) {
|
|
1322
1362
|
const { addedCount } = await this.completeInputs(from, filter ?? {
|
|
1323
1363
|
scriptLenRange: [0, 1],
|
|
1324
1364
|
outputDataLenRange: [0, 1],
|
|
1325
|
-
}, (acc, { cellOutput: { capacity } }) => acc + capacity, Zero);
|
|
1365
|
+
}, (acc, { cellOutput: { capacity } }) => acc + capacity, index_js_2.Zero);
|
|
1326
1366
|
return addedCount;
|
|
1327
1367
|
}
|
|
1328
1368
|
async completeInputsByUdt(from, type) {
|
|
@@ -1333,7 +1373,7 @@ export class Transaction {
|
|
|
1333
1373
|
}
|
|
1334
1374
|
const { addedCount, accumulated } = await this.completeInputs(from, {
|
|
1335
1375
|
script: type,
|
|
1336
|
-
outputDataLenRange: [16, numFrom("0xffffffff")],
|
|
1376
|
+
outputDataLenRange: [16, (0, index_js_5.numFrom)("0xffffffff")],
|
|
1337
1377
|
}, (acc, { outputData }) => {
|
|
1338
1378
|
const balance = udtBalanceFrom(outputData);
|
|
1339
1379
|
const sum = acc + balance;
|
|
@@ -1346,14 +1386,14 @@ export class Transaction {
|
|
|
1346
1386
|
}
|
|
1347
1387
|
estimateFee(feeRate) {
|
|
1348
1388
|
const txSize = this.toBytes().length + 4;
|
|
1349
|
-
return (numFrom(txSize) * numFrom(feeRate) + numFrom(1000)) / numFrom(1000);
|
|
1389
|
+
return ((0, index_js_5.numFrom)(txSize) * (0, index_js_5.numFrom)(feeRate) + (0, index_js_5.numFrom)(1000)) / (0, index_js_5.numFrom)(1000);
|
|
1350
1390
|
}
|
|
1351
1391
|
async completeFee(from, change, expectedFeeRate, filter) {
|
|
1352
1392
|
const feeRate = expectedFeeRate ?? (await from.client.getFeeRate());
|
|
1353
1393
|
// Complete all inputs extra infos for cache
|
|
1354
1394
|
await this.getInputsCapacity(from.client);
|
|
1355
|
-
let leastFee = Zero;
|
|
1356
|
-
let leastExtraCapacity = Zero;
|
|
1395
|
+
let leastFee = index_js_2.Zero;
|
|
1396
|
+
let leastExtraCapacity = index_js_2.Zero;
|
|
1357
1397
|
while (true) {
|
|
1358
1398
|
const tx = this.clone();
|
|
1359
1399
|
const collected = await (async () => {
|
|
@@ -1361,14 +1401,14 @@ export class Transaction {
|
|
|
1361
1401
|
return await tx.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
|
|
1362
1402
|
}
|
|
1363
1403
|
catch (err) {
|
|
1364
|
-
if (leastExtraCapacity !== Zero) {
|
|
1404
|
+
if (leastExtraCapacity !== index_js_2.Zero) {
|
|
1365
1405
|
throw new Error("Not enough capacity for the change cell");
|
|
1366
1406
|
}
|
|
1367
1407
|
throw err;
|
|
1368
1408
|
}
|
|
1369
1409
|
})();
|
|
1370
1410
|
await from.prepareTransaction(tx);
|
|
1371
|
-
if (leastFee === Zero) {
|
|
1411
|
+
if (leastFee === index_js_2.Zero) {
|
|
1372
1412
|
// The initial fee is calculated based on prepared transaction
|
|
1373
1413
|
leastFee = tx.estimateFee(feeRate);
|
|
1374
1414
|
}
|
|
@@ -1378,9 +1418,9 @@ export class Transaction {
|
|
|
1378
1418
|
this.copy(tx);
|
|
1379
1419
|
return [collected, false];
|
|
1380
1420
|
}
|
|
1381
|
-
const needed = numFrom(await Promise.resolve(change(tx, extraCapacity - leastFee)));
|
|
1421
|
+
const needed = (0, index_js_5.numFrom)(await Promise.resolve(change(tx, extraCapacity - leastFee)));
|
|
1382
1422
|
// No enough extra capacity to create new cells for change
|
|
1383
|
-
if (needed > Zero) {
|
|
1423
|
+
if (needed > index_js_2.Zero) {
|
|
1384
1424
|
leastExtraCapacity = needed;
|
|
1385
1425
|
continue;
|
|
1386
1426
|
}
|
|
@@ -1404,10 +1444,10 @@ export class Transaction {
|
|
|
1404
1444
|
}
|
|
1405
1445
|
}
|
|
1406
1446
|
completeFeeChangeToLock(from, change, feeRate, filter) {
|
|
1407
|
-
const script = Script.from(change);
|
|
1447
|
+
const script = script_js_1.Script.from(change);
|
|
1408
1448
|
return this.completeFee(from, (tx, capacity) => {
|
|
1409
1449
|
const changeCell = CellOutput.from({ capacity: 0, lock: script });
|
|
1410
|
-
const occupiedCapacity = fixedPointFrom(changeCell.occupiedSize);
|
|
1450
|
+
const occupiedCapacity = (0, index_js_2.fixedPointFrom)(changeCell.occupiedSize);
|
|
1411
1451
|
if (capacity < occupiedCapacity) {
|
|
1412
1452
|
return occupiedCapacity;
|
|
1413
1453
|
}
|
|
@@ -1421,7 +1461,7 @@ export class Transaction {
|
|
|
1421
1461
|
return this.completeFeeChangeToLock(from, script, feeRate, filter);
|
|
1422
1462
|
}
|
|
1423
1463
|
completeFeeChangeToOutput(from, index, feeRate, filter) {
|
|
1424
|
-
const change = Number(numFrom(index));
|
|
1464
|
+
const change = Number((0, index_js_5.numFrom)(index));
|
|
1425
1465
|
if (!this.outputs[change]) {
|
|
1426
1466
|
throw new Error("Non-existed output to change");
|
|
1427
1467
|
}
|
|
@@ -1431,3 +1471,4 @@ export class Transaction {
|
|
|
1431
1471
|
}, feeRate, filter);
|
|
1432
1472
|
}
|
|
1433
1473
|
}
|
|
1474
|
+
exports.Transaction = Transaction;
|