@ckb-ccc/core 0.1.2 → 1.0.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 +6 -0
- package/dist/barrel.d.ts +1 -1
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -1
- package/dist/bytes/index.d.ts +14 -0
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +29 -0
- package/dist/ckb/advanced.d.ts +0 -1
- package/dist/ckb/advanced.d.ts.map +1 -1
- package/dist/ckb/advanced.js +0 -1
- package/dist/ckb/script.d.ts +17 -58
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +31 -78
- package/dist/ckb/transaction.d.ts +114 -260
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +162 -358
- package/dist/molecule/barrel.d.ts +4 -0
- package/dist/molecule/barrel.d.ts.map +1 -0
- package/dist/molecule/barrel.js +3 -0
- package/dist/molecule/codec.d.ts.map +1 -1
- package/dist/molecule/codec.js +6 -3
- package/dist/molecule/entity.d.ts +98 -0
- package/dist/molecule/entity.d.ts.map +1 -0
- package/dist/molecule/entity.js +113 -0
- package/dist/molecule/index.d.ts +1 -2
- package/dist/molecule/index.d.ts.map +1 -1
- package/dist/molecule/index.js +1 -2
- package/dist/molecule/predefined.d.ts +13 -20
- package/dist/molecule/predefined.d.ts.map +1 -1
- package/dist/molecule/predefined.js +14 -54
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +1 -14
- package/dist.commonjs/bytes/index.d.ts +14 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -1
- package/dist.commonjs/bytes/index.js +30 -0
- package/dist.commonjs/ckb/advanced.d.ts +0 -1
- package/dist.commonjs/ckb/advanced.d.ts.map +1 -1
- package/dist.commonjs/ckb/advanced.js +0 -14
- package/dist.commonjs/ckb/script.d.ts +17 -58
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.js +31 -102
- package/dist.commonjs/ckb/transaction.d.ts +114 -260
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +182 -408
- package/dist.commonjs/molecule/barrel.d.ts +4 -0
- package/dist.commonjs/molecule/barrel.d.ts.map +1 -0
- package/dist.commonjs/{ckb/molecule.advanced/index.js → molecule/barrel.js} +3 -8
- package/dist.commonjs/molecule/codec.d.ts.map +1 -1
- package/dist.commonjs/molecule/codec.js +6 -3
- package/dist.commonjs/molecule/entity.d.ts +98 -0
- package/dist.commonjs/molecule/entity.d.ts.map +1 -0
- package/dist.commonjs/molecule/entity.js +118 -0
- package/dist.commonjs/molecule/index.d.ts +1 -2
- package/dist.commonjs/molecule/index.d.ts.map +1 -1
- package/dist.commonjs/molecule/index.js +13 -4
- package/dist.commonjs/molecule/predefined.d.ts +13 -20
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
- package/dist.commonjs/molecule/predefined.js +14 -77
- package/dist.commonjs/utils/index.d.ts +3 -0
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/barrel.ts +1 -1
- package/src/bytes/index.ts +34 -0
- package/src/ckb/advanced.ts +0 -1
- package/src/ckb/script.ts +22 -85
- package/src/ckb/transaction.ts +134 -412
- package/src/molecule/barrel.ts +3 -0
- package/src/molecule/codec.ts +9 -5
- package/src/molecule/entity.ts +163 -0
- package/src/molecule/index.ts +1 -2
- package/src/molecule/predefined.ts +20 -69
- package/src/utils/index.ts +5 -0
- package/dist/ckb/molecule.advanced/generated.d.ts +0 -355
- package/dist/ckb/molecule.advanced/generated.d.ts.map +0 -1
- package/dist/ckb/molecule.advanced/generated.js +0 -1468
- package/dist/ckb/molecule.advanced/index.d.ts +0 -6
- package/dist/ckb/molecule.advanced/index.d.ts.map +0 -1
- package/dist/ckb/molecule.advanced/index.js +0 -7
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +0 -355
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +0 -1
- package/dist.commonjs/ckb/molecule.advanced/generated.js +0 -1535
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +0 -6
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +0 -1
- package/src/ckb/molecule.advanced/blockchain.mol +0 -118
- package/src/ckb/molecule.advanced/generated.d.ts +0 -444
- package/src/ckb/molecule.advanced/generated.js +0 -1804
- package/src/ckb/molecule.advanced/index.ts +0 -11
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
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 __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;
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
24
7
|
};
|
|
8
|
+
var OutPoint_1, CellOutput_1, Since_1, CellInput_1, CellDep_1, WitnessArgs_1, Transaction_1;
|
|
25
9
|
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;
|
|
10
|
+
exports.Transaction = exports.RawTransaction = exports.WitnessArgs = exports.CellDepVec = exports.CellDep = exports.CellInputVec = exports.CellInput = exports.Since = exports.Cell = exports.CellOutputVec = exports.CellOutput = exports.OutPoint = exports.DepTypeCodec = void 0;
|
|
27
11
|
exports.depTypeFrom = depTypeFrom;
|
|
28
12
|
exports.depTypeToBytes = depTypeToBytes;
|
|
29
13
|
exports.depTypeFromBytes = depTypeFromBytes;
|
|
@@ -35,11 +19,16 @@ const index_js_1 = require("../bytes/index.js");
|
|
|
35
19
|
const index_js_2 = require("../fixedPoint/index.js");
|
|
36
20
|
const index_js_3 = require("../hasher/index.js");
|
|
37
21
|
const index_js_4 = require("../hex/index.js");
|
|
38
|
-
const index_js_5 = require("../
|
|
39
|
-
const index_js_6 = require("../
|
|
40
|
-
const
|
|
22
|
+
const index_js_5 = require("../molecule/index.js");
|
|
23
|
+
const index_js_6 = require("../num/index.js");
|
|
24
|
+
const index_js_7 = require("../utils/index.js");
|
|
41
25
|
const script_js_1 = require("./script.js");
|
|
42
26
|
const transaction_advanced_js_1 = require("./transaction.advanced.js");
|
|
27
|
+
exports.DepTypeCodec = index_js_5.mol.Codec.from({
|
|
28
|
+
byteLength: 1,
|
|
29
|
+
encode: depTypeToBytes,
|
|
30
|
+
decode: depTypeFromBytes,
|
|
31
|
+
});
|
|
43
32
|
/**
|
|
44
33
|
* Converts a DepTypeLike value to a DepType.
|
|
45
34
|
* @public
|
|
@@ -105,7 +94,7 @@ function depTypeFromBytes(bytes) {
|
|
|
105
94
|
/**
|
|
106
95
|
* @public
|
|
107
96
|
*/
|
|
108
|
-
class OutPoint {
|
|
97
|
+
let OutPoint = OutPoint_1 = class OutPoint extends index_js_5.mol.Entity.Base() {
|
|
109
98
|
/**
|
|
110
99
|
* Creates an instance of OutPoint.
|
|
111
100
|
*
|
|
@@ -113,22 +102,10 @@ class OutPoint {
|
|
|
113
102
|
* @param index - The index of the output in the transaction.
|
|
114
103
|
*/
|
|
115
104
|
constructor(txHash, index) {
|
|
105
|
+
super();
|
|
116
106
|
this.txHash = txHash;
|
|
117
107
|
this.index = index;
|
|
118
108
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Clone an OutPoint.
|
|
121
|
-
*
|
|
122
|
-
* @returns A cloned OutPoint instance.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```typescript
|
|
126
|
-
* const outPoint1 = outPoint0.clone();
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
clone() {
|
|
130
|
-
return new OutPoint(this.txHash, this.index);
|
|
131
|
-
}
|
|
132
109
|
/**
|
|
133
110
|
* Creates an OutPoint instance from an OutPointLike object.
|
|
134
111
|
*
|
|
@@ -141,73 +118,25 @@ class OutPoint {
|
|
|
141
118
|
* ```
|
|
142
119
|
*/
|
|
143
120
|
static from(outPoint) {
|
|
144
|
-
if (outPoint instanceof
|
|
121
|
+
if (outPoint instanceof OutPoint_1) {
|
|
145
122
|
return outPoint;
|
|
146
123
|
}
|
|
147
|
-
return new
|
|
124
|
+
return new OutPoint_1((0, index_js_4.hexFrom)(outPoint.txHash), (0, index_js_6.numFrom)(outPoint.index));
|
|
148
125
|
}
|
|
149
|
-
|
|
150
|
-
* Converts the OutPoint instance to molecule data format.
|
|
151
|
-
*
|
|
152
|
-
* @returns An object representing the outpoint in molecule data format.
|
|
153
|
-
*/
|
|
154
|
-
_toMolData() {
|
|
155
|
-
return {
|
|
156
|
-
txHash: (0, index_js_1.bytesFrom)(this.txHash),
|
|
157
|
-
index: (0, index_js_5.numToBytes)(this.index, 4),
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Converts the OutPoint instance to bytes.
|
|
162
|
-
*
|
|
163
|
-
* @returns A Uint8Array containing the outpoint bytes.
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```typescript
|
|
167
|
-
* const outPointBytes = outPoint.toBytes();
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
toBytes() {
|
|
171
|
-
return (0, index_js_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Creates an OutPoint instance from a byte-like value or molecule OutPoint.
|
|
175
|
-
*
|
|
176
|
-
* @param bytes - The byte-like value or molecule OutPoint to convert.
|
|
177
|
-
* @returns An OutPoint instance.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
static fromBytes(bytes) {
|
|
185
|
-
const view = bytes instanceof mol.OutPoint
|
|
186
|
-
? bytes
|
|
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()));
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Compares the current OutPoint instance with another OutPointLike object for equality.
|
|
192
|
-
*
|
|
193
|
-
* @param val - The OutPointLike object to compare with.
|
|
194
|
-
* @returns True if the out points are equal, otherwise false.
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* const isEqual = outPoint.eq(anotherOutPoint);
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
eq(val) {
|
|
202
|
-
const outPoint = OutPoint.from(val);
|
|
203
|
-
return this.txHash === outPoint.txHash && this.index === outPoint.index;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
126
|
+
};
|
|
206
127
|
exports.OutPoint = OutPoint;
|
|
128
|
+
exports.OutPoint = OutPoint = OutPoint_1 = __decorate([
|
|
129
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
130
|
+
.struct({
|
|
131
|
+
txHash: index_js_5.mol.Byte32,
|
|
132
|
+
index: index_js_5.mol.Uint32,
|
|
133
|
+
})
|
|
134
|
+
.map({ outMap: (decoded) => OutPoint.from(decoded) }))
|
|
135
|
+
], OutPoint);
|
|
207
136
|
/**
|
|
208
137
|
* @public
|
|
209
138
|
*/
|
|
210
|
-
class CellOutput {
|
|
139
|
+
let CellOutput = CellOutput_1 = class CellOutput extends index_js_5.mol.Entity.Base() {
|
|
211
140
|
/**
|
|
212
141
|
* Creates an instance of CellOutput.
|
|
213
142
|
*
|
|
@@ -216,6 +145,7 @@ class CellOutput {
|
|
|
216
145
|
* @param type - The optional type script of the cell.
|
|
217
146
|
*/
|
|
218
147
|
constructor(capacity, lock, type) {
|
|
148
|
+
super();
|
|
219
149
|
this.capacity = capacity;
|
|
220
150
|
this.lock = lock;
|
|
221
151
|
this.type = type;
|
|
@@ -223,19 +153,6 @@ class CellOutput {
|
|
|
223
153
|
get occupiedSize() {
|
|
224
154
|
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
225
155
|
}
|
|
226
|
-
/**
|
|
227
|
-
* Clone a CellOutput.
|
|
228
|
-
*
|
|
229
|
-
* @returns A cloned CellOutput instance.
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```typescript
|
|
233
|
-
* const cellOutput1 = cellOutput0.clone();
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
clone() {
|
|
237
|
-
return new CellOutput(this.capacity, this.lock.clone(), this.type?.clone());
|
|
238
|
-
}
|
|
239
156
|
/**
|
|
240
157
|
* Creates a CellOutput instance from a CellOutputLike object.
|
|
241
158
|
*
|
|
@@ -252,55 +169,23 @@ class CellOutput {
|
|
|
252
169
|
* ```
|
|
253
170
|
*/
|
|
254
171
|
static from(cellOutput) {
|
|
255
|
-
if (cellOutput instanceof
|
|
172
|
+
if (cellOutput instanceof CellOutput_1) {
|
|
256
173
|
return cellOutput;
|
|
257
174
|
}
|
|
258
|
-
return new
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Converts the CellOutput instance to molecule data format.
|
|
262
|
-
*
|
|
263
|
-
* @returns An object representing the cell output in molecule data format.
|
|
264
|
-
*/
|
|
265
|
-
_toMolData() {
|
|
266
|
-
return {
|
|
267
|
-
capacity: (0, index_js_5.numToBytes)(this.capacity, 8),
|
|
268
|
-
lock: this.lock._toMolData(),
|
|
269
|
-
type: this.type?._toMolData(),
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Converts the CellOutput instance to bytes.
|
|
274
|
-
*
|
|
275
|
-
* @returns A Uint8Array containing the cell output bytes.
|
|
276
|
-
*
|
|
277
|
-
* @example
|
|
278
|
-
* ```typescript
|
|
279
|
-
* const cellOutputBytes = cellOutput.toBytes();
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
toBytes() {
|
|
283
|
-
return (0, index_js_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Creates a CellOutput instance from a byte-like value or molecule CellOutput.
|
|
287
|
-
*
|
|
288
|
-
* @param bytes - The byte-like value or molecule CellOutput to convert.
|
|
289
|
-
* @returns A CellOutput instance.
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```typescript
|
|
293
|
-
* const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
static fromBytes(bytes) {
|
|
297
|
-
const view = bytes instanceof mol.CellOutput
|
|
298
|
-
? bytes
|
|
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())));
|
|
175
|
+
return new CellOutput_1((0, index_js_6.numFrom)(cellOutput.capacity), script_js_1.Script.from(cellOutput.lock), (0, index_js_7.apply)(script_js_1.Script.from, cellOutput.type));
|
|
301
176
|
}
|
|
302
|
-
}
|
|
177
|
+
};
|
|
303
178
|
exports.CellOutput = CellOutput;
|
|
179
|
+
exports.CellOutput = CellOutput = CellOutput_1 = __decorate([
|
|
180
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
181
|
+
.table({
|
|
182
|
+
capacity: index_js_5.mol.Uint64,
|
|
183
|
+
lock: script_js_1.Script,
|
|
184
|
+
type: script_js_1.ScriptOpt,
|
|
185
|
+
})
|
|
186
|
+
.map({ outMap: (decoded) => CellOutput.from(decoded) }))
|
|
187
|
+
], CellOutput);
|
|
188
|
+
exports.CellOutputVec = index_js_5.mol.vector(CellOutput);
|
|
304
189
|
/**
|
|
305
190
|
* @public
|
|
306
191
|
*/
|
|
@@ -348,17 +233,17 @@ exports.Cell = Cell;
|
|
|
348
233
|
* @public
|
|
349
234
|
*/
|
|
350
235
|
function epochFrom(epochLike) {
|
|
351
|
-
return [(0,
|
|
236
|
+
return [(0, index_js_6.numFrom)(epochLike[0]), (0, index_js_6.numFrom)(epochLike[1]), (0, index_js_6.numFrom)(epochLike[2])];
|
|
352
237
|
}
|
|
353
238
|
/**
|
|
354
239
|
* @public
|
|
355
240
|
*/
|
|
356
241
|
function epochFromHex(hex) {
|
|
357
|
-
const num = (0,
|
|
242
|
+
const num = (0, index_js_6.numFrom)((0, index_js_4.hexFrom)(hex));
|
|
358
243
|
return [
|
|
359
|
-
num & (0,
|
|
360
|
-
(num >> (0,
|
|
361
|
-
(num >> (0,
|
|
244
|
+
num & (0, index_js_6.numFrom)("0xffffff"),
|
|
245
|
+
(num >> (0, index_js_6.numFrom)(24)) & (0, index_js_6.numFrom)("0xffff"),
|
|
246
|
+
(num >> (0, index_js_6.numFrom)(40)) & (0, index_js_6.numFrom)("0xffff"),
|
|
362
247
|
];
|
|
363
248
|
}
|
|
364
249
|
/**
|
|
@@ -366,14 +251,14 @@ function epochFromHex(hex) {
|
|
|
366
251
|
*/
|
|
367
252
|
function epochToHex(epochLike) {
|
|
368
253
|
const epoch = epochFrom(epochLike);
|
|
369
|
-
return (0,
|
|
370
|
-
((0,
|
|
371
|
-
((0,
|
|
254
|
+
return (0, index_js_6.numToHex)((0, index_js_6.numFrom)(epoch[0]) +
|
|
255
|
+
((0, index_js_6.numFrom)(epoch[1]) << (0, index_js_6.numFrom)(24)) +
|
|
256
|
+
((0, index_js_6.numFrom)(epoch[2]) << (0, index_js_6.numFrom)(40)));
|
|
372
257
|
}
|
|
373
258
|
/**
|
|
374
259
|
* @public
|
|
375
260
|
*/
|
|
376
|
-
class Since {
|
|
261
|
+
let Since = Since_1 = class Since extends index_js_5.mol.Entity.Base() {
|
|
377
262
|
/**
|
|
378
263
|
* Creates an instance of Since.
|
|
379
264
|
*
|
|
@@ -382,6 +267,7 @@ class Since {
|
|
|
382
267
|
* @param value - The value of since
|
|
383
268
|
*/
|
|
384
269
|
constructor(relative, metric, value) {
|
|
270
|
+
super();
|
|
385
271
|
this.relative = relative;
|
|
386
272
|
this.metric = metric;
|
|
387
273
|
this.value = value;
|
|
@@ -397,7 +283,7 @@ class Since {
|
|
|
397
283
|
* ```
|
|
398
284
|
*/
|
|
399
285
|
clone() {
|
|
400
|
-
return new
|
|
286
|
+
return new Since_1(this.relative, this.metric, this.value);
|
|
401
287
|
}
|
|
402
288
|
/**
|
|
403
289
|
* Creates a Since instance from a SinceLike object.
|
|
@@ -411,13 +297,13 @@ class Since {
|
|
|
411
297
|
* ```
|
|
412
298
|
*/
|
|
413
299
|
static from(since) {
|
|
414
|
-
if (since instanceof
|
|
300
|
+
if (since instanceof Since_1) {
|
|
415
301
|
return since;
|
|
416
302
|
}
|
|
417
303
|
if (typeof since === "object" && "relative" in since) {
|
|
418
|
-
return new
|
|
304
|
+
return new Since_1(since.relative, since.metric, (0, index_js_6.numFrom)(since.value));
|
|
419
305
|
}
|
|
420
|
-
return
|
|
306
|
+
return Since_1.fromNum(since);
|
|
421
307
|
}
|
|
422
308
|
/**
|
|
423
309
|
* Converts the Since instance to num.
|
|
@@ -431,11 +317,11 @@ class Since {
|
|
|
431
317
|
*/
|
|
432
318
|
toNum() {
|
|
433
319
|
return (this.value |
|
|
434
|
-
(this.relative === "absolute" ? index_js_2.Zero : (0,
|
|
320
|
+
(this.relative === "absolute" ? index_js_2.Zero : (0, index_js_6.numFrom)("0x8000000000000000")) |
|
|
435
321
|
{
|
|
436
|
-
blockNumber: (0,
|
|
437
|
-
epoch: (0,
|
|
438
|
-
timestamp: (0,
|
|
322
|
+
blockNumber: (0, index_js_6.numFrom)("0x0000000000000000"),
|
|
323
|
+
epoch: (0, index_js_6.numFrom)("0x2000000000000000"),
|
|
324
|
+
timestamp: (0, index_js_6.numFrom)("0x4000000000000000"),
|
|
439
325
|
}[this.metric]);
|
|
440
326
|
}
|
|
441
327
|
/**
|
|
@@ -450,18 +336,24 @@ class Since {
|
|
|
450
336
|
* ```
|
|
451
337
|
*/
|
|
452
338
|
static fromNum(numLike) {
|
|
453
|
-
const num = (0,
|
|
454
|
-
const relative = num >> (0,
|
|
455
|
-
const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> (0,
|
|
456
|
-
const value = num & (0,
|
|
457
|
-
return new
|
|
339
|
+
const num = (0, index_js_6.numFrom)(numLike);
|
|
340
|
+
const relative = num >> (0, index_js_6.numFrom)(63) === index_js_2.Zero ? "absolute" : "relative";
|
|
341
|
+
const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> (0, index_js_6.numFrom)(61)) & (0, index_js_6.numFrom)(3))];
|
|
342
|
+
const value = num & (0, index_js_6.numFrom)("0x00ffffffffffffff");
|
|
343
|
+
return new Since_1(relative, metric, value);
|
|
458
344
|
}
|
|
459
|
-
}
|
|
345
|
+
};
|
|
460
346
|
exports.Since = Since;
|
|
347
|
+
exports.Since = Since = Since_1 = __decorate([
|
|
348
|
+
index_js_5.mol.codec(index_js_5.mol.Uint64.map({
|
|
349
|
+
inMap: (encodable) => Since.from(encodable).toNum(),
|
|
350
|
+
outMap: (decoded) => Since.from(decoded),
|
|
351
|
+
}))
|
|
352
|
+
], Since);
|
|
461
353
|
/**
|
|
462
354
|
* @public
|
|
463
355
|
*/
|
|
464
|
-
class CellInput {
|
|
356
|
+
let CellInput = CellInput_1 = class CellInput extends index_js_5.mol.Entity.Base() {
|
|
465
357
|
/**
|
|
466
358
|
* Creates an instance of CellInput.
|
|
467
359
|
*
|
|
@@ -471,24 +363,12 @@ class CellInput {
|
|
|
471
363
|
* @param outputData - The optional output data associated with the cell input.
|
|
472
364
|
*/
|
|
473
365
|
constructor(previousOutput, since, cellOutput, outputData) {
|
|
366
|
+
super();
|
|
474
367
|
this.previousOutput = previousOutput;
|
|
475
368
|
this.since = since;
|
|
476
369
|
this.cellOutput = cellOutput;
|
|
477
370
|
this.outputData = outputData;
|
|
478
371
|
}
|
|
479
|
-
/**
|
|
480
|
-
* Clone a CellInput.
|
|
481
|
-
*
|
|
482
|
-
* @returns A cloned CellInput instance.
|
|
483
|
-
*
|
|
484
|
-
* @example
|
|
485
|
-
* ```typescript
|
|
486
|
-
* const cellInput1 = cellInput0.clone();
|
|
487
|
-
* ```
|
|
488
|
-
*/
|
|
489
|
-
clone() {
|
|
490
|
-
return new CellInput(this.previousOutput.clone(), this.since, this.cellOutput?.clone(), this.outputData);
|
|
491
|
-
}
|
|
492
372
|
/**
|
|
493
373
|
* Creates a CellInput instance from a CellInputLike object.
|
|
494
374
|
*
|
|
@@ -504,10 +384,10 @@ class CellInput {
|
|
|
504
384
|
* ```
|
|
505
385
|
*/
|
|
506
386
|
static from(cellInput) {
|
|
507
|
-
if (cellInput instanceof
|
|
387
|
+
if (cellInput instanceof CellInput_1) {
|
|
508
388
|
return cellInput;
|
|
509
389
|
}
|
|
510
|
-
return new
|
|
390
|
+
return new CellInput_1(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), (0, index_js_7.apply)(CellOutput.from, cellInput.cellOutput), (0, index_js_7.apply)(index_js_4.hexFrom, cellInput.outputData));
|
|
511
391
|
}
|
|
512
392
|
/**
|
|
513
393
|
* Complete extra infos in the input. Like the output of the out point.
|
|
@@ -530,53 +410,24 @@ class CellInput {
|
|
|
530
410
|
this.cellOutput = cell.cellOutput;
|
|
531
411
|
this.outputData = cell.outputData;
|
|
532
412
|
}
|
|
533
|
-
|
|
534
|
-
* Converts the CellInput instance to molecule data format.
|
|
535
|
-
*
|
|
536
|
-
* @returns An object representing the cell input in molecule data format.
|
|
537
|
-
*/
|
|
538
|
-
_toMolData() {
|
|
539
|
-
return {
|
|
540
|
-
previousOutput: this.previousOutput._toMolData(),
|
|
541
|
-
since: (0, index_js_5.numToBytes)(this.since, 8),
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Converts the CellInput instance to bytes.
|
|
546
|
-
*
|
|
547
|
-
* @returns A Uint8Array containing the cell input bytes.
|
|
548
|
-
*
|
|
549
|
-
* @example
|
|
550
|
-
* ```typescript
|
|
551
|
-
* const cellInputBytes = cellInput.toBytes();
|
|
552
|
-
* ```
|
|
553
|
-
*/
|
|
554
|
-
toBytes() {
|
|
555
|
-
return (0, index_js_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Creates a CellInput instance from a byte-like value or molecule CellInput.
|
|
559
|
-
*
|
|
560
|
-
* @param bytes - The byte-like value or molecule CellInput to convert.
|
|
561
|
-
* @returns A CellInput instance.
|
|
562
|
-
*
|
|
563
|
-
* @example
|
|
564
|
-
* ```typescript
|
|
565
|
-
* const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
|
|
566
|
-
* ```
|
|
567
|
-
*/
|
|
568
|
-
static fromBytes(bytes) {
|
|
569
|
-
const view = bytes instanceof mol.CellInput
|
|
570
|
-
? bytes
|
|
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()));
|
|
573
|
-
}
|
|
574
|
-
}
|
|
413
|
+
};
|
|
575
414
|
exports.CellInput = CellInput;
|
|
415
|
+
exports.CellInput = CellInput = CellInput_1 = __decorate([
|
|
416
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
417
|
+
.struct({
|
|
418
|
+
since: Since,
|
|
419
|
+
previousOutput: OutPoint,
|
|
420
|
+
})
|
|
421
|
+
.map({
|
|
422
|
+
inMap: (encodable) => ({ ...encodable, since: encodable.since ?? 0 }),
|
|
423
|
+
outMap: (decoded) => CellInput.from(decoded),
|
|
424
|
+
}))
|
|
425
|
+
], CellInput);
|
|
426
|
+
exports.CellInputVec = index_js_5.mol.vector(CellInput);
|
|
576
427
|
/**
|
|
577
428
|
* @public
|
|
578
429
|
*/
|
|
579
|
-
class CellDep {
|
|
430
|
+
let CellDep = CellDep_1 = class CellDep extends index_js_5.mol.Entity.Base() {
|
|
580
431
|
/**
|
|
581
432
|
* Creates an instance of CellDep.
|
|
582
433
|
*
|
|
@@ -584,6 +435,7 @@ class CellDep {
|
|
|
584
435
|
* @param depType - The dependency type.
|
|
585
436
|
*/
|
|
586
437
|
constructor(outPoint, depType) {
|
|
438
|
+
super();
|
|
587
439
|
this.outPoint = outPoint;
|
|
588
440
|
this.depType = depType;
|
|
589
441
|
}
|
|
@@ -598,7 +450,7 @@ class CellDep {
|
|
|
598
450
|
* ```
|
|
599
451
|
*/
|
|
600
452
|
clone() {
|
|
601
|
-
return new
|
|
453
|
+
return new CellDep_1(this.outPoint.clone(), this.depType);
|
|
602
454
|
}
|
|
603
455
|
/**
|
|
604
456
|
* Creates a CellDep instance from a CellDepLike object.
|
|
@@ -615,71 +467,26 @@ class CellDep {
|
|
|
615
467
|
* ```
|
|
616
468
|
*/
|
|
617
469
|
static from(cellDep) {
|
|
618
|
-
if (cellDep instanceof
|
|
470
|
+
if (cellDep instanceof CellDep_1) {
|
|
619
471
|
return cellDep;
|
|
620
472
|
}
|
|
621
|
-
return new
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* Converts the CellDep instance to molecule data format.
|
|
625
|
-
*
|
|
626
|
-
* @returns An object representing the cell dependency in molecule data format.
|
|
627
|
-
*/
|
|
628
|
-
_toMolData() {
|
|
629
|
-
return {
|
|
630
|
-
outPoint: this.outPoint._toMolData(),
|
|
631
|
-
depType: depTypeToBytes(this.depType),
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Converts the CellDep instance to bytes.
|
|
636
|
-
*
|
|
637
|
-
* @returns A Uint8Array containing the cell dependency bytes.
|
|
638
|
-
*
|
|
639
|
-
* @example
|
|
640
|
-
* ```typescript
|
|
641
|
-
* const cellDepBytes = cellDep.toBytes();
|
|
642
|
-
* ```
|
|
643
|
-
*/
|
|
644
|
-
toBytes() {
|
|
645
|
-
return (0, index_js_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Creates a CellDep instance from a byte-like value or molecule CellDep.
|
|
649
|
-
*
|
|
650
|
-
* @param bytes - The byte-like value or molecule CellDep to convert.
|
|
651
|
-
* @returns A CellDep instance.
|
|
652
|
-
*
|
|
653
|
-
* @example
|
|
654
|
-
* ```typescript
|
|
655
|
-
* const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
|
|
656
|
-
* ```
|
|
657
|
-
*/
|
|
658
|
-
fromBytes(bytes) {
|
|
659
|
-
const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, index_js_1.bytesFrom)(bytes));
|
|
660
|
-
return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Compares the current CellDep instance with another CellDepLike object for equality.
|
|
664
|
-
*
|
|
665
|
-
* @param val - The CellDepLike object to compare with.
|
|
666
|
-
* @returns True if the cell deps are equal, otherwise false.
|
|
667
|
-
*
|
|
668
|
-
* @example
|
|
669
|
-
* ```typescript
|
|
670
|
-
* const isEqual = cellDep.eq(anotherCellDep);
|
|
671
|
-
* ```
|
|
672
|
-
*/
|
|
673
|
-
eq(val) {
|
|
674
|
-
const cellDep = CellDep.from(val);
|
|
675
|
-
return (this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType);
|
|
473
|
+
return new CellDep_1(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
676
474
|
}
|
|
677
|
-
}
|
|
475
|
+
};
|
|
678
476
|
exports.CellDep = CellDep;
|
|
477
|
+
exports.CellDep = CellDep = CellDep_1 = __decorate([
|
|
478
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
479
|
+
.struct({
|
|
480
|
+
outPoint: OutPoint,
|
|
481
|
+
depType: exports.DepTypeCodec,
|
|
482
|
+
})
|
|
483
|
+
.map({ outMap: (decoded) => CellDep.from(decoded) }))
|
|
484
|
+
], CellDep);
|
|
485
|
+
exports.CellDepVec = index_js_5.mol.vector(CellDep);
|
|
679
486
|
/**
|
|
680
487
|
* @public
|
|
681
488
|
*/
|
|
682
|
-
class WitnessArgs {
|
|
489
|
+
let WitnessArgs = WitnessArgs_1 = class WitnessArgs extends index_js_5.mol.Entity.Base() {
|
|
683
490
|
/**
|
|
684
491
|
* Creates an instance of WitnessArgs.
|
|
685
492
|
*
|
|
@@ -688,6 +495,7 @@ class WitnessArgs {
|
|
|
688
495
|
* @param outputType - The optional output type field of the witness.
|
|
689
496
|
*/
|
|
690
497
|
constructor(lock, inputType, outputType) {
|
|
498
|
+
super();
|
|
691
499
|
this.lock = lock;
|
|
692
500
|
this.inputType = inputType;
|
|
693
501
|
this.outputType = outputType;
|
|
@@ -708,55 +516,22 @@ class WitnessArgs {
|
|
|
708
516
|
* ```
|
|
709
517
|
*/
|
|
710
518
|
static from(witnessArgs) {
|
|
711
|
-
if (witnessArgs instanceof
|
|
519
|
+
if (witnessArgs instanceof WitnessArgs_1) {
|
|
712
520
|
return witnessArgs;
|
|
713
521
|
}
|
|
714
|
-
return new
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* Converts the WitnessArgs instance to molecule data format.
|
|
718
|
-
*
|
|
719
|
-
* @returns An object representing the witness arguments in molecule data format.
|
|
720
|
-
*/
|
|
721
|
-
_toMolData() {
|
|
722
|
-
return {
|
|
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),
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
/**
|
|
729
|
-
* Converts the WitnessArgs instance to bytes.
|
|
730
|
-
*
|
|
731
|
-
* @returns A Uint8Array containing the witness arguments bytes.
|
|
732
|
-
*
|
|
733
|
-
* @example
|
|
734
|
-
* ```typescript
|
|
735
|
-
* const witnessArgsBytes = witnessArgs.toBytes();
|
|
736
|
-
* ```
|
|
737
|
-
*/
|
|
738
|
-
toBytes() {
|
|
739
|
-
return (0, index_js_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
|
|
743
|
-
*
|
|
744
|
-
* @param bytes - The byte-like value or molecule WitnessArgs to convert.
|
|
745
|
-
* @returns A WitnessArgs instance.
|
|
746
|
-
*
|
|
747
|
-
* @example
|
|
748
|
-
* ```typescript
|
|
749
|
-
* const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
|
|
750
|
-
* ```
|
|
751
|
-
*/
|
|
752
|
-
static fromBytes(bytes) {
|
|
753
|
-
const view = bytes instanceof mol.WitnessArgs
|
|
754
|
-
? bytes
|
|
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()));
|
|
522
|
+
return new WitnessArgs_1((0, index_js_7.apply)(index_js_4.hexFrom, witnessArgs.lock), (0, index_js_7.apply)(index_js_4.hexFrom, witnessArgs.inputType), (0, index_js_7.apply)(index_js_4.hexFrom, witnessArgs.outputType));
|
|
757
523
|
}
|
|
758
|
-
}
|
|
524
|
+
};
|
|
759
525
|
exports.WitnessArgs = WitnessArgs;
|
|
526
|
+
exports.WitnessArgs = WitnessArgs = WitnessArgs_1 = __decorate([
|
|
527
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
528
|
+
.table({
|
|
529
|
+
lock: index_js_5.mol.BytesOpt,
|
|
530
|
+
inputType: index_js_5.mol.BytesOpt,
|
|
531
|
+
outputType: index_js_5.mol.BytesOpt,
|
|
532
|
+
})
|
|
533
|
+
.map({ outMap: (decoded) => WitnessArgs.from(decoded) }))
|
|
534
|
+
], WitnessArgs);
|
|
760
535
|
/**
|
|
761
536
|
* @public
|
|
762
537
|
*/
|
|
@@ -765,12 +540,22 @@ function udtBalanceFrom(dataLike) {
|
|
|
765
540
|
if (data.length !== 16) {
|
|
766
541
|
throw new Error("Invalid UDT cell data");
|
|
767
542
|
}
|
|
768
|
-
return (0,
|
|
543
|
+
return (0, index_js_6.numFromBytes)(data);
|
|
769
544
|
}
|
|
545
|
+
exports.RawTransaction = index_js_5.mol
|
|
546
|
+
.table({
|
|
547
|
+
version: index_js_5.mol.Uint32,
|
|
548
|
+
cellDeps: exports.CellDepVec,
|
|
549
|
+
headerDeps: index_js_5.mol.Byte32Vec,
|
|
550
|
+
inputs: exports.CellInputVec,
|
|
551
|
+
outputs: exports.CellOutputVec,
|
|
552
|
+
outputsData: index_js_5.mol.BytesVec,
|
|
553
|
+
})
|
|
554
|
+
.map({ outMap: (decoded) => Transaction.from(decoded) });
|
|
770
555
|
/**
|
|
771
556
|
* @public
|
|
772
557
|
*/
|
|
773
|
-
class Transaction {
|
|
558
|
+
let Transaction = Transaction_1 = class Transaction extends index_js_5.mol.Entity.Base() {
|
|
774
559
|
/**
|
|
775
560
|
* Creates an instance of Transaction.
|
|
776
561
|
*
|
|
@@ -783,6 +568,7 @@ class Transaction {
|
|
|
783
568
|
* @param witnesses - The witnesses of the transaction.
|
|
784
569
|
*/
|
|
785
570
|
constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
|
|
571
|
+
super();
|
|
786
572
|
this.version = version;
|
|
787
573
|
this.cellDeps = cellDeps;
|
|
788
574
|
this.headerDeps = headerDeps;
|
|
@@ -802,7 +588,7 @@ class Transaction {
|
|
|
802
588
|
* ```
|
|
803
589
|
*/
|
|
804
590
|
static default() {
|
|
805
|
-
return new
|
|
591
|
+
return new Transaction_1(0n, [], [], [], [], [], []);
|
|
806
592
|
}
|
|
807
593
|
/**
|
|
808
594
|
* Copy every properties from another transaction.
|
|
@@ -813,7 +599,7 @@ class Transaction {
|
|
|
813
599
|
* ```
|
|
814
600
|
*/
|
|
815
601
|
copy(txLike) {
|
|
816
|
-
const tx =
|
|
602
|
+
const tx = Transaction_1.from(txLike);
|
|
817
603
|
this.version = tx.version;
|
|
818
604
|
this.cellDeps = tx.cellDeps;
|
|
819
605
|
this.headerDeps = tx.headerDeps;
|
|
@@ -822,19 +608,6 @@ class Transaction {
|
|
|
822
608
|
this.outputsData = tx.outputsData;
|
|
823
609
|
this.witnesses = tx.witnesses;
|
|
824
610
|
}
|
|
825
|
-
/**
|
|
826
|
-
* Clone a Transaction.
|
|
827
|
-
*
|
|
828
|
-
* @returns A cloned instance
|
|
829
|
-
*
|
|
830
|
-
* @example
|
|
831
|
-
* ```typescript
|
|
832
|
-
* const tx1 = tx0.clone();
|
|
833
|
-
* ```
|
|
834
|
-
*/
|
|
835
|
-
clone() {
|
|
836
|
-
return new Transaction(0n, this.cellDeps.map((c) => c.clone()), [...this.headerDeps], this.inputs.map((i) => i.clone()), this.outputs.map((o) => o.clone()), [...this.outputsData], [...this.witnesses]);
|
|
837
|
-
}
|
|
838
611
|
/**
|
|
839
612
|
* Creates a Transaction instance from a TransactionLike object.
|
|
840
613
|
*
|
|
@@ -855,7 +628,7 @@ class Transaction {
|
|
|
855
628
|
* ```
|
|
856
629
|
*/
|
|
857
630
|
static from(tx) {
|
|
858
|
-
if (tx instanceof
|
|
631
|
+
if (tx instanceof Transaction_1) {
|
|
859
632
|
return tx;
|
|
860
633
|
}
|
|
861
634
|
const outputs = tx.outputs?.map((output, i) => {
|
|
@@ -865,7 +638,7 @@ class Transaction {
|
|
|
865
638
|
});
|
|
866
639
|
if (o.capacity === index_js_2.Zero) {
|
|
867
640
|
o.capacity = (0, index_js_2.fixedPointFrom)(o.occupiedSize +
|
|
868
|
-
((0,
|
|
641
|
+
((0, index_js_7.apply)(index_js_1.bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
869
642
|
}
|
|
870
643
|
return o;
|
|
871
644
|
}) ?? [];
|
|
@@ -873,7 +646,7 @@ class Transaction {
|
|
|
873
646
|
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
874
647
|
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => (0, index_js_4.hexFrom)(d)));
|
|
875
648
|
}
|
|
876
|
-
return new
|
|
649
|
+
return new Transaction_1((0, index_js_6.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) ?? []);
|
|
877
650
|
}
|
|
878
651
|
/**
|
|
879
652
|
* Creates a Transaction instance from a Lumos skeleton.
|
|
@@ -889,7 +662,7 @@ class Transaction {
|
|
|
889
662
|
* ```
|
|
890
663
|
*/
|
|
891
664
|
static fromLumosSkeleton(skeleton) {
|
|
892
|
-
return
|
|
665
|
+
return Transaction_1.from({
|
|
893
666
|
version: 0n,
|
|
894
667
|
cellDeps: skeleton.cellDeps.toArray(),
|
|
895
668
|
headerDeps: skeleton.headerDeps.toArray(),
|
|
@@ -912,7 +685,7 @@ class Transaction {
|
|
|
912
685
|
stringify() {
|
|
913
686
|
return JSON.stringify(this, (_, value) => {
|
|
914
687
|
if (typeof value === "bigint") {
|
|
915
|
-
return (0,
|
|
688
|
+
return (0, index_js_6.numToHex)(value);
|
|
916
689
|
}
|
|
917
690
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
918
691
|
return value;
|
|
@@ -929,50 +702,34 @@ class Transaction {
|
|
|
929
702
|
* ```
|
|
930
703
|
*/
|
|
931
704
|
rawToBytes() {
|
|
932
|
-
return
|
|
933
|
-
version: (0, index_js_5.numToBytes)(this.version, 4),
|
|
934
|
-
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
935
|
-
headerDeps: this.headerDeps.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
936
|
-
inputs: this.inputs.map((i) => i._toMolData()),
|
|
937
|
-
outputs: this.outputs.map((o) => o._toMolData()),
|
|
938
|
-
outputsData: this.outputsData.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
939
|
-
}));
|
|
705
|
+
return exports.RawTransaction.encode(this);
|
|
940
706
|
}
|
|
941
707
|
/**
|
|
942
|
-
*
|
|
708
|
+
* Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
|
|
709
|
+
* To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
|
|
943
710
|
*
|
|
944
|
-
* @returns
|
|
711
|
+
* @returns The hash of the transaction.
|
|
945
712
|
*
|
|
946
713
|
* @example
|
|
947
714
|
* ```typescript
|
|
948
|
-
* const
|
|
715
|
+
* const txHash = transaction.hash();
|
|
949
716
|
* ```
|
|
950
717
|
*/
|
|
951
|
-
|
|
952
|
-
return (0,
|
|
953
|
-
raw: {
|
|
954
|
-
version: (0, index_js_5.numToBytes)(this.version, 4),
|
|
955
|
-
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
956
|
-
headerDeps: this.headerDeps.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
957
|
-
inputs: this.inputs.map((i) => i._toMolData()),
|
|
958
|
-
outputs: this.outputs.map((o) => o._toMolData()),
|
|
959
|
-
outputsData: this.outputsData.map((header) => (0, index_js_1.bytesFrom)(header)),
|
|
960
|
-
},
|
|
961
|
-
witnesses: this.witnesses.map((witness) => (0, index_js_1.bytesFrom)(witness)),
|
|
962
|
-
}));
|
|
718
|
+
hash() {
|
|
719
|
+
return (0, index_js_3.hashCkb)(this.rawToBytes());
|
|
963
720
|
}
|
|
964
721
|
/**
|
|
965
|
-
* Calculates the hash of the transaction.
|
|
722
|
+
* Calculates the hash of the transaction with witnesses.
|
|
966
723
|
*
|
|
967
|
-
* @returns The hash of the transaction.
|
|
724
|
+
* @returns The hash of the transaction with witnesses.
|
|
968
725
|
*
|
|
969
726
|
* @example
|
|
970
727
|
* ```typescript
|
|
971
|
-
* const
|
|
728
|
+
* const txFullHash = transaction.hashFull();
|
|
972
729
|
* ```
|
|
973
730
|
*/
|
|
974
|
-
|
|
975
|
-
return (0, index_js_3.hashCkb)(this.
|
|
731
|
+
hashFull() {
|
|
732
|
+
return (0, index_js_3.hashCkb)(this.toBytes());
|
|
976
733
|
}
|
|
977
734
|
/**
|
|
978
735
|
* Hashes a witness and updates the hasher.
|
|
@@ -987,7 +744,7 @@ class Transaction {
|
|
|
987
744
|
*/
|
|
988
745
|
static hashWitnessToHasher(witness, hasher) {
|
|
989
746
|
const raw = (0, index_js_1.bytesFrom)((0, index_js_4.hexFrom)(witness));
|
|
990
|
-
hasher.update((0,
|
|
747
|
+
hasher.update((0, index_js_6.numToBytes)(raw.length, 8));
|
|
991
748
|
hasher.update(raw);
|
|
992
749
|
}
|
|
993
750
|
/**
|
|
@@ -1028,7 +785,7 @@ class Transaction {
|
|
|
1028
785
|
if (position === -1) {
|
|
1029
786
|
return undefined;
|
|
1030
787
|
}
|
|
1031
|
-
|
|
788
|
+
Transaction_1.hashWitnessToHasher(this.witnesses[i], hasher);
|
|
1032
789
|
}
|
|
1033
790
|
if (position === -1) {
|
|
1034
791
|
return undefined;
|
|
@@ -1278,19 +1035,19 @@ class Transaction {
|
|
|
1278
1035
|
this.setWitnessArgsAt(position, witness);
|
|
1279
1036
|
}
|
|
1280
1037
|
async getInputsCapacity(client) {
|
|
1281
|
-
return (0,
|
|
1038
|
+
return (0, index_js_7.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1282
1039
|
await input.completeExtraInfos(client);
|
|
1283
1040
|
if (!input.cellOutput) {
|
|
1284
1041
|
throw new Error("Unable to complete input");
|
|
1285
1042
|
}
|
|
1286
1043
|
return acc + input.cellOutput.capacity;
|
|
1287
|
-
}, (0,
|
|
1044
|
+
}, (0, index_js_6.numFrom)(0));
|
|
1288
1045
|
}
|
|
1289
1046
|
getOutputsCapacity() {
|
|
1290
|
-
return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0,
|
|
1047
|
+
return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0, index_js_6.numFrom)(0));
|
|
1291
1048
|
}
|
|
1292
1049
|
async getInputsUdtBalance(client, type) {
|
|
1293
|
-
return (0,
|
|
1050
|
+
return (0, index_js_7.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1294
1051
|
await input.completeExtraInfos(client);
|
|
1295
1052
|
if (!input.cellOutput || !input.outputData) {
|
|
1296
1053
|
throw new Error("Unable to complete input");
|
|
@@ -1299,7 +1056,7 @@ class Transaction {
|
|
|
1299
1056
|
return;
|
|
1300
1057
|
}
|
|
1301
1058
|
return acc + udtBalanceFrom(input.outputData);
|
|
1302
|
-
}, (0,
|
|
1059
|
+
}, (0, index_js_6.numFrom)(0));
|
|
1303
1060
|
}
|
|
1304
1061
|
getOutputsUdtBalance(type) {
|
|
1305
1062
|
return this.outputs.reduce((acc, output, i) => {
|
|
@@ -1307,7 +1064,7 @@ class Transaction {
|
|
|
1307
1064
|
return acc;
|
|
1308
1065
|
}
|
|
1309
1066
|
return acc + udtBalanceFrom(this.outputsData[i]);
|
|
1310
|
-
}, (0,
|
|
1067
|
+
}, (0, index_js_6.numFrom)(0));
|
|
1311
1068
|
}
|
|
1312
1069
|
async completeInputs(from, filter, accumulator, init) {
|
|
1313
1070
|
const collectedCells = [];
|
|
@@ -1341,7 +1098,7 @@ class Transaction {
|
|
|
1341
1098
|
};
|
|
1342
1099
|
}
|
|
1343
1100
|
async completeInputsByCapacity(from, capacityTweak, filter) {
|
|
1344
|
-
const exceptedCapacity = this.getOutputsCapacity() + (0,
|
|
1101
|
+
const exceptedCapacity = this.getOutputsCapacity() + (0, index_js_6.numFrom)(capacityTweak ?? 0);
|
|
1345
1102
|
const inputsCapacity = await this.getInputsCapacity(from.client);
|
|
1346
1103
|
if (inputsCapacity >= exceptedCapacity) {
|
|
1347
1104
|
return 0;
|
|
@@ -1373,7 +1130,7 @@ class Transaction {
|
|
|
1373
1130
|
}
|
|
1374
1131
|
const { addedCount, accumulated } = await this.completeInputs(from, {
|
|
1375
1132
|
script: type,
|
|
1376
|
-
outputDataLenRange: [16, (0,
|
|
1133
|
+
outputDataLenRange: [16, (0, index_js_6.numFrom)("0xffffffff")],
|
|
1377
1134
|
}, (acc, { outputData }) => {
|
|
1378
1135
|
const balance = udtBalanceFrom(outputData);
|
|
1379
1136
|
const sum = acc + balance;
|
|
@@ -1386,7 +1143,7 @@ class Transaction {
|
|
|
1386
1143
|
}
|
|
1387
1144
|
estimateFee(feeRate) {
|
|
1388
1145
|
const txSize = this.toBytes().length + 4;
|
|
1389
|
-
return ((0,
|
|
1146
|
+
return ((0, index_js_6.numFrom)(txSize) * (0, index_js_6.numFrom)(feeRate) + (0, index_js_6.numFrom)(1000)) / (0, index_js_6.numFrom)(1000);
|
|
1390
1147
|
}
|
|
1391
1148
|
async completeFee(from, change, expectedFeeRate, filter) {
|
|
1392
1149
|
const feeRate = expectedFeeRate ?? (await from.client.getFeeRate());
|
|
@@ -1418,7 +1175,7 @@ class Transaction {
|
|
|
1418
1175
|
this.copy(tx);
|
|
1419
1176
|
return [collected, false];
|
|
1420
1177
|
}
|
|
1421
|
-
const needed = (0,
|
|
1178
|
+
const needed = (0, index_js_6.numFrom)(await Promise.resolve(change(tx, extraCapacity - leastFee)));
|
|
1422
1179
|
// No enough extra capacity to create new cells for change
|
|
1423
1180
|
if (needed > index_js_2.Zero) {
|
|
1424
1181
|
leastExtraCapacity = needed;
|
|
@@ -1461,7 +1218,7 @@ class Transaction {
|
|
|
1461
1218
|
return this.completeFeeChangeToLock(from, script, feeRate, filter);
|
|
1462
1219
|
}
|
|
1463
1220
|
completeFeeChangeToOutput(from, index, feeRate, filter) {
|
|
1464
|
-
const change = Number((0,
|
|
1221
|
+
const change = Number((0, index_js_6.numFrom)(index));
|
|
1465
1222
|
if (!this.outputs[change]) {
|
|
1466
1223
|
throw new Error("Non-existed output to change");
|
|
1467
1224
|
}
|
|
@@ -1470,5 +1227,22 @@ class Transaction {
|
|
|
1470
1227
|
return 0;
|
|
1471
1228
|
}, feeRate, filter);
|
|
1472
1229
|
}
|
|
1473
|
-
}
|
|
1230
|
+
};
|
|
1474
1231
|
exports.Transaction = Transaction;
|
|
1232
|
+
exports.Transaction = Transaction = Transaction_1 = __decorate([
|
|
1233
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
1234
|
+
.table({
|
|
1235
|
+
raw: exports.RawTransaction,
|
|
1236
|
+
witnesses: index_js_5.mol.BytesVec,
|
|
1237
|
+
})
|
|
1238
|
+
.map({
|
|
1239
|
+
inMap: (txLike) => {
|
|
1240
|
+
const tx = Transaction.from(txLike);
|
|
1241
|
+
return {
|
|
1242
|
+
raw: tx,
|
|
1243
|
+
witnesses: tx.witnesses,
|
|
1244
|
+
};
|
|
1245
|
+
},
|
|
1246
|
+
outMap: (tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses }),
|
|
1247
|
+
}))
|
|
1248
|
+
], Transaction);
|