@ckb-ccc/core 0.1.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +6 -2
- 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 +35 -0
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +60 -4
- 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 +29 -78
- package/dist/ckb/transaction.d.ts +125 -264
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +146 -357
- 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 +2 -0
- package/dist/molecule/codec.d.ts.map +1 -1
- package/dist/molecule/codec.js +57 -44
- package/dist/molecule/entity.d.ts +119 -0
- package/dist/molecule/entity.d.ts.map +1 -0
- package/dist/molecule/entity.js +134 -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/num/index.d.ts.map +1 -1
- package/dist/num/index.js +2 -2
- package/dist/signer/btc/verify.js +1 -1
- package/dist/signer/doge/verify.d.ts.map +1 -1
- package/dist/signer/doge/verify.js +3 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
- package/dist.commonjs/address/address.advanced.js +6 -2
- 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 +35 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -1
- package/dist.commonjs/bytes/index.js +62 -4
- 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 +29 -102
- package/dist.commonjs/ckb/transaction.d.ts +125 -264
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +167 -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 +2 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -1
- package/dist.commonjs/molecule/codec.js +56 -43
- package/dist.commonjs/molecule/entity.d.ts +119 -0
- package/dist.commonjs/molecule/entity.d.ts.map +1 -0
- package/dist.commonjs/molecule/entity.js +139 -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/num/index.d.ts.map +1 -1
- package/dist.commonjs/num/index.js +2 -2
- package/dist.commonjs/signer/btc/verify.js +1 -1
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/doge/verify.js +3 -1
- 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/address/address.advanced.ts +6 -2
- package/src/barrel.ts +1 -1
- package/src/bytes/index.ts +70 -6
- package/src/ckb/advanced.ts +0 -1
- package/src/ckb/script.ts +20 -85
- package/src/ckb/transaction.ts +123 -416
- package/src/molecule/barrel.ts +3 -0
- package/src/molecule/codec.ts +82 -66
- package/src/molecule/entity.ts +183 -0
- package/src/molecule/index.ts +1 -2
- package/src/molecule/predefined.ts +20 -69
- package/src/num/index.ts +2 -5
- package/src/signer/btc/verify.ts +1 -1
- package/src/signer/doge/verify.ts +3 -1
- 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,23 @@ 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
|
|
148
|
-
}
|
|
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()));
|
|
124
|
+
return new OutPoint_1((0, index_js_4.hexFrom)(outPoint.txHash), (0, index_js_6.numFrom)(outPoint.index));
|
|
172
125
|
}
|
|
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.struct({
|
|
130
|
+
txHash: index_js_5.mol.Byte32,
|
|
131
|
+
index: index_js_5.mol.Uint32,
|
|
132
|
+
}))
|
|
133
|
+
], OutPoint);
|
|
207
134
|
/**
|
|
208
135
|
* @public
|
|
209
136
|
*/
|
|
210
|
-
class CellOutput {
|
|
137
|
+
let CellOutput = CellOutput_1 = class CellOutput extends index_js_5.mol.Entity.Base() {
|
|
211
138
|
/**
|
|
212
139
|
* Creates an instance of CellOutput.
|
|
213
140
|
*
|
|
@@ -216,6 +143,7 @@ class CellOutput {
|
|
|
216
143
|
* @param type - The optional type script of the cell.
|
|
217
144
|
*/
|
|
218
145
|
constructor(capacity, lock, type) {
|
|
146
|
+
super();
|
|
219
147
|
this.capacity = capacity;
|
|
220
148
|
this.lock = lock;
|
|
221
149
|
this.type = type;
|
|
@@ -223,19 +151,6 @@ class CellOutput {
|
|
|
223
151
|
get occupiedSize() {
|
|
224
152
|
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
225
153
|
}
|
|
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
154
|
/**
|
|
240
155
|
* Creates a CellOutput instance from a CellOutputLike object.
|
|
241
156
|
*
|
|
@@ -252,55 +167,21 @@ class CellOutput {
|
|
|
252
167
|
* ```
|
|
253
168
|
*/
|
|
254
169
|
static from(cellOutput) {
|
|
255
|
-
if (cellOutput instanceof
|
|
170
|
+
if (cellOutput instanceof CellOutput_1) {
|
|
256
171
|
return cellOutput;
|
|
257
172
|
}
|
|
258
|
-
return new
|
|
173
|
+
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));
|
|
259
174
|
}
|
|
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())));
|
|
301
|
-
}
|
|
302
|
-
}
|
|
175
|
+
};
|
|
303
176
|
exports.CellOutput = CellOutput;
|
|
177
|
+
exports.CellOutput = CellOutput = CellOutput_1 = __decorate([
|
|
178
|
+
index_js_5.mol.codec(index_js_5.mol.table({
|
|
179
|
+
capacity: index_js_5.mol.Uint64,
|
|
180
|
+
lock: script_js_1.Script,
|
|
181
|
+
type: script_js_1.ScriptOpt,
|
|
182
|
+
}))
|
|
183
|
+
], CellOutput);
|
|
184
|
+
exports.CellOutputVec = index_js_5.mol.vector(CellOutput);
|
|
304
185
|
/**
|
|
305
186
|
* @public
|
|
306
187
|
*/
|
|
@@ -348,17 +229,17 @@ exports.Cell = Cell;
|
|
|
348
229
|
* @public
|
|
349
230
|
*/
|
|
350
231
|
function epochFrom(epochLike) {
|
|
351
|
-
return [(0,
|
|
232
|
+
return [(0, index_js_6.numFrom)(epochLike[0]), (0, index_js_6.numFrom)(epochLike[1]), (0, index_js_6.numFrom)(epochLike[2])];
|
|
352
233
|
}
|
|
353
234
|
/**
|
|
354
235
|
* @public
|
|
355
236
|
*/
|
|
356
237
|
function epochFromHex(hex) {
|
|
357
|
-
const num = (0,
|
|
238
|
+
const num = (0, index_js_6.numFrom)((0, index_js_4.hexFrom)(hex));
|
|
358
239
|
return [
|
|
359
|
-
num & (0,
|
|
360
|
-
(num >> (0,
|
|
361
|
-
(num >> (0,
|
|
240
|
+
num & (0, index_js_6.numFrom)("0xffffff"),
|
|
241
|
+
(num >> (0, index_js_6.numFrom)(24)) & (0, index_js_6.numFrom)("0xffff"),
|
|
242
|
+
(num >> (0, index_js_6.numFrom)(40)) & (0, index_js_6.numFrom)("0xffff"),
|
|
362
243
|
];
|
|
363
244
|
}
|
|
364
245
|
/**
|
|
@@ -366,14 +247,14 @@ function epochFromHex(hex) {
|
|
|
366
247
|
*/
|
|
367
248
|
function epochToHex(epochLike) {
|
|
368
249
|
const epoch = epochFrom(epochLike);
|
|
369
|
-
return (0,
|
|
370
|
-
((0,
|
|
371
|
-
((0,
|
|
250
|
+
return (0, index_js_6.numToHex)((0, index_js_6.numFrom)(epoch[0]) +
|
|
251
|
+
((0, index_js_6.numFrom)(epoch[1]) << (0, index_js_6.numFrom)(24)) +
|
|
252
|
+
((0, index_js_6.numFrom)(epoch[2]) << (0, index_js_6.numFrom)(40)));
|
|
372
253
|
}
|
|
373
254
|
/**
|
|
374
255
|
* @public
|
|
375
256
|
*/
|
|
376
|
-
class Since {
|
|
257
|
+
let Since = Since_1 = class Since extends index_js_5.mol.Entity.Base() {
|
|
377
258
|
/**
|
|
378
259
|
* Creates an instance of Since.
|
|
379
260
|
*
|
|
@@ -382,6 +263,7 @@ class Since {
|
|
|
382
263
|
* @param value - The value of since
|
|
383
264
|
*/
|
|
384
265
|
constructor(relative, metric, value) {
|
|
266
|
+
super();
|
|
385
267
|
this.relative = relative;
|
|
386
268
|
this.metric = metric;
|
|
387
269
|
this.value = value;
|
|
@@ -397,7 +279,7 @@ class Since {
|
|
|
397
279
|
* ```
|
|
398
280
|
*/
|
|
399
281
|
clone() {
|
|
400
|
-
return new
|
|
282
|
+
return new Since_1(this.relative, this.metric, this.value);
|
|
401
283
|
}
|
|
402
284
|
/**
|
|
403
285
|
* Creates a Since instance from a SinceLike object.
|
|
@@ -411,13 +293,13 @@ class Since {
|
|
|
411
293
|
* ```
|
|
412
294
|
*/
|
|
413
295
|
static from(since) {
|
|
414
|
-
if (since instanceof
|
|
296
|
+
if (since instanceof Since_1) {
|
|
415
297
|
return since;
|
|
416
298
|
}
|
|
417
299
|
if (typeof since === "object" && "relative" in since) {
|
|
418
|
-
return new
|
|
300
|
+
return new Since_1(since.relative, since.metric, (0, index_js_6.numFrom)(since.value));
|
|
419
301
|
}
|
|
420
|
-
return
|
|
302
|
+
return Since_1.fromNum(since);
|
|
421
303
|
}
|
|
422
304
|
/**
|
|
423
305
|
* Converts the Since instance to num.
|
|
@@ -431,11 +313,11 @@ class Since {
|
|
|
431
313
|
*/
|
|
432
314
|
toNum() {
|
|
433
315
|
return (this.value |
|
|
434
|
-
(this.relative === "absolute" ? index_js_2.Zero : (0,
|
|
316
|
+
(this.relative === "absolute" ? index_js_2.Zero : (0, index_js_6.numFrom)("0x8000000000000000")) |
|
|
435
317
|
{
|
|
436
|
-
blockNumber: (0,
|
|
437
|
-
epoch: (0,
|
|
438
|
-
timestamp: (0,
|
|
318
|
+
blockNumber: (0, index_js_6.numFrom)("0x0000000000000000"),
|
|
319
|
+
epoch: (0, index_js_6.numFrom)("0x2000000000000000"),
|
|
320
|
+
timestamp: (0, index_js_6.numFrom)("0x4000000000000000"),
|
|
439
321
|
}[this.metric]);
|
|
440
322
|
}
|
|
441
323
|
/**
|
|
@@ -450,18 +332,21 @@ class Since {
|
|
|
450
332
|
* ```
|
|
451
333
|
*/
|
|
452
334
|
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
|
|
335
|
+
const num = (0, index_js_6.numFrom)(numLike);
|
|
336
|
+
const relative = num >> (0, index_js_6.numFrom)(63) === index_js_2.Zero ? "absolute" : "relative";
|
|
337
|
+
const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> (0, index_js_6.numFrom)(61)) & (0, index_js_6.numFrom)(3))];
|
|
338
|
+
const value = num & (0, index_js_6.numFrom)("0x00ffffffffffffff");
|
|
339
|
+
return new Since_1(relative, metric, value);
|
|
458
340
|
}
|
|
459
|
-
}
|
|
341
|
+
};
|
|
460
342
|
exports.Since = Since;
|
|
343
|
+
exports.Since = Since = Since_1 = __decorate([
|
|
344
|
+
index_js_5.mol.codec(index_js_5.mol.Uint64.mapIn((encodable) => Since.from(encodable).toNum()))
|
|
345
|
+
], Since);
|
|
461
346
|
/**
|
|
462
347
|
* @public
|
|
463
348
|
*/
|
|
464
|
-
class CellInput {
|
|
349
|
+
let CellInput = CellInput_1 = class CellInput extends index_js_5.mol.Entity.Base() {
|
|
465
350
|
/**
|
|
466
351
|
* Creates an instance of CellInput.
|
|
467
352
|
*
|
|
@@ -471,24 +356,12 @@ class CellInput {
|
|
|
471
356
|
* @param outputData - The optional output data associated with the cell input.
|
|
472
357
|
*/
|
|
473
358
|
constructor(previousOutput, since, cellOutput, outputData) {
|
|
359
|
+
super();
|
|
474
360
|
this.previousOutput = previousOutput;
|
|
475
361
|
this.since = since;
|
|
476
362
|
this.cellOutput = cellOutput;
|
|
477
363
|
this.outputData = outputData;
|
|
478
364
|
}
|
|
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
365
|
/**
|
|
493
366
|
* Creates a CellInput instance from a CellInputLike object.
|
|
494
367
|
*
|
|
@@ -504,10 +377,10 @@ class CellInput {
|
|
|
504
377
|
* ```
|
|
505
378
|
*/
|
|
506
379
|
static from(cellInput) {
|
|
507
|
-
if (cellInput instanceof
|
|
380
|
+
if (cellInput instanceof CellInput_1) {
|
|
508
381
|
return cellInput;
|
|
509
382
|
}
|
|
510
|
-
return new
|
|
383
|
+
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
384
|
}
|
|
512
385
|
/**
|
|
513
386
|
* Complete extra infos in the input. Like the output of the out point.
|
|
@@ -530,53 +403,24 @@ class CellInput {
|
|
|
530
403
|
this.cellOutput = cell.cellOutput;
|
|
531
404
|
this.outputData = cell.outputData;
|
|
532
405
|
}
|
|
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
|
-
}
|
|
406
|
+
};
|
|
575
407
|
exports.CellInput = CellInput;
|
|
408
|
+
exports.CellInput = CellInput = CellInput_1 = __decorate([
|
|
409
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
410
|
+
.struct({
|
|
411
|
+
since: Since,
|
|
412
|
+
previousOutput: OutPoint,
|
|
413
|
+
})
|
|
414
|
+
.mapIn((encodable) => ({
|
|
415
|
+
...encodable,
|
|
416
|
+
since: encodable.since ?? 0,
|
|
417
|
+
})))
|
|
418
|
+
], CellInput);
|
|
419
|
+
exports.CellInputVec = index_js_5.mol.vector(CellInput);
|
|
576
420
|
/**
|
|
577
421
|
* @public
|
|
578
422
|
*/
|
|
579
|
-
class CellDep {
|
|
423
|
+
let CellDep = CellDep_1 = class CellDep extends index_js_5.mol.Entity.Base() {
|
|
580
424
|
/**
|
|
581
425
|
* Creates an instance of CellDep.
|
|
582
426
|
*
|
|
@@ -584,6 +428,7 @@ class CellDep {
|
|
|
584
428
|
* @param depType - The dependency type.
|
|
585
429
|
*/
|
|
586
430
|
constructor(outPoint, depType) {
|
|
431
|
+
super();
|
|
587
432
|
this.outPoint = outPoint;
|
|
588
433
|
this.depType = depType;
|
|
589
434
|
}
|
|
@@ -598,7 +443,7 @@ class CellDep {
|
|
|
598
443
|
* ```
|
|
599
444
|
*/
|
|
600
445
|
clone() {
|
|
601
|
-
return new
|
|
446
|
+
return new CellDep_1(this.outPoint.clone(), this.depType);
|
|
602
447
|
}
|
|
603
448
|
/**
|
|
604
449
|
* Creates a CellDep instance from a CellDepLike object.
|
|
@@ -615,71 +460,24 @@ class CellDep {
|
|
|
615
460
|
* ```
|
|
616
461
|
*/
|
|
617
462
|
static from(cellDep) {
|
|
618
|
-
if (cellDep instanceof
|
|
463
|
+
if (cellDep instanceof CellDep_1) {
|
|
619
464
|
return cellDep;
|
|
620
465
|
}
|
|
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
|
-
};
|
|
466
|
+
return new CellDep_1(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
633
467
|
}
|
|
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);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
468
|
+
};
|
|
678
469
|
exports.CellDep = CellDep;
|
|
470
|
+
exports.CellDep = CellDep = CellDep_1 = __decorate([
|
|
471
|
+
index_js_5.mol.codec(index_js_5.mol.struct({
|
|
472
|
+
outPoint: OutPoint,
|
|
473
|
+
depType: exports.DepTypeCodec,
|
|
474
|
+
}))
|
|
475
|
+
], CellDep);
|
|
476
|
+
exports.CellDepVec = index_js_5.mol.vector(CellDep);
|
|
679
477
|
/**
|
|
680
478
|
* @public
|
|
681
479
|
*/
|
|
682
|
-
class WitnessArgs {
|
|
480
|
+
let WitnessArgs = WitnessArgs_1 = class WitnessArgs extends index_js_5.mol.Entity.Base() {
|
|
683
481
|
/**
|
|
684
482
|
* Creates an instance of WitnessArgs.
|
|
685
483
|
*
|
|
@@ -688,6 +486,7 @@ class WitnessArgs {
|
|
|
688
486
|
* @param outputType - The optional output type field of the witness.
|
|
689
487
|
*/
|
|
690
488
|
constructor(lock, inputType, outputType) {
|
|
489
|
+
super();
|
|
691
490
|
this.lock = lock;
|
|
692
491
|
this.inputType = inputType;
|
|
693
492
|
this.outputType = outputType;
|
|
@@ -708,55 +507,20 @@ class WitnessArgs {
|
|
|
708
507
|
* ```
|
|
709
508
|
*/
|
|
710
509
|
static from(witnessArgs) {
|
|
711
|
-
if (witnessArgs instanceof
|
|
510
|
+
if (witnessArgs instanceof WitnessArgs_1) {
|
|
712
511
|
return witnessArgs;
|
|
713
512
|
}
|
|
714
|
-
return new
|
|
513
|
+
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));
|
|
715
514
|
}
|
|
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()));
|
|
757
|
-
}
|
|
758
|
-
}
|
|
515
|
+
};
|
|
759
516
|
exports.WitnessArgs = WitnessArgs;
|
|
517
|
+
exports.WitnessArgs = WitnessArgs = WitnessArgs_1 = __decorate([
|
|
518
|
+
index_js_5.mol.codec(index_js_5.mol.table({
|
|
519
|
+
lock: index_js_5.mol.BytesOpt,
|
|
520
|
+
inputType: index_js_5.mol.BytesOpt,
|
|
521
|
+
outputType: index_js_5.mol.BytesOpt,
|
|
522
|
+
}))
|
|
523
|
+
], WitnessArgs);
|
|
760
524
|
/**
|
|
761
525
|
* @public
|
|
762
526
|
*/
|
|
@@ -765,12 +529,20 @@ function udtBalanceFrom(dataLike) {
|
|
|
765
529
|
if (data.length !== 16) {
|
|
766
530
|
throw new Error("Invalid UDT cell data");
|
|
767
531
|
}
|
|
768
|
-
return (0,
|
|
532
|
+
return (0, index_js_6.numFromBytes)(data);
|
|
769
533
|
}
|
|
534
|
+
exports.RawTransaction = index_js_5.mol.table({
|
|
535
|
+
version: index_js_5.mol.Uint32,
|
|
536
|
+
cellDeps: exports.CellDepVec,
|
|
537
|
+
headerDeps: index_js_5.mol.Byte32Vec,
|
|
538
|
+
inputs: exports.CellInputVec,
|
|
539
|
+
outputs: exports.CellOutputVec,
|
|
540
|
+
outputsData: index_js_5.mol.BytesVec,
|
|
541
|
+
});
|
|
770
542
|
/**
|
|
771
543
|
* @public
|
|
772
544
|
*/
|
|
773
|
-
class Transaction {
|
|
545
|
+
let Transaction = Transaction_1 = class Transaction extends index_js_5.mol.Entity.Base() {
|
|
774
546
|
/**
|
|
775
547
|
* Creates an instance of Transaction.
|
|
776
548
|
*
|
|
@@ -783,6 +555,7 @@ class Transaction {
|
|
|
783
555
|
* @param witnesses - The witnesses of the transaction.
|
|
784
556
|
*/
|
|
785
557
|
constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
|
|
558
|
+
super();
|
|
786
559
|
this.version = version;
|
|
787
560
|
this.cellDeps = cellDeps;
|
|
788
561
|
this.headerDeps = headerDeps;
|
|
@@ -802,7 +575,7 @@ class Transaction {
|
|
|
802
575
|
* ```
|
|
803
576
|
*/
|
|
804
577
|
static default() {
|
|
805
|
-
return new
|
|
578
|
+
return new Transaction_1(0n, [], [], [], [], [], []);
|
|
806
579
|
}
|
|
807
580
|
/**
|
|
808
581
|
* Copy every properties from another transaction.
|
|
@@ -813,7 +586,7 @@ class Transaction {
|
|
|
813
586
|
* ```
|
|
814
587
|
*/
|
|
815
588
|
copy(txLike) {
|
|
816
|
-
const tx =
|
|
589
|
+
const tx = Transaction_1.from(txLike);
|
|
817
590
|
this.version = tx.version;
|
|
818
591
|
this.cellDeps = tx.cellDeps;
|
|
819
592
|
this.headerDeps = tx.headerDeps;
|
|
@@ -822,19 +595,6 @@ class Transaction {
|
|
|
822
595
|
this.outputsData = tx.outputsData;
|
|
823
596
|
this.witnesses = tx.witnesses;
|
|
824
597
|
}
|
|
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
598
|
/**
|
|
839
599
|
* Creates a Transaction instance from a TransactionLike object.
|
|
840
600
|
*
|
|
@@ -855,7 +615,7 @@ class Transaction {
|
|
|
855
615
|
* ```
|
|
856
616
|
*/
|
|
857
617
|
static from(tx) {
|
|
858
|
-
if (tx instanceof
|
|
618
|
+
if (tx instanceof Transaction_1) {
|
|
859
619
|
return tx;
|
|
860
620
|
}
|
|
861
621
|
const outputs = tx.outputs?.map((output, i) => {
|
|
@@ -865,7 +625,7 @@ class Transaction {
|
|
|
865
625
|
});
|
|
866
626
|
if (o.capacity === index_js_2.Zero) {
|
|
867
627
|
o.capacity = (0, index_js_2.fixedPointFrom)(o.occupiedSize +
|
|
868
|
-
((0,
|
|
628
|
+
((0, index_js_7.apply)(index_js_1.bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
869
629
|
}
|
|
870
630
|
return o;
|
|
871
631
|
}) ?? [];
|
|
@@ -873,7 +633,7 @@ class Transaction {
|
|
|
873
633
|
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
874
634
|
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => (0, index_js_4.hexFrom)(d)));
|
|
875
635
|
}
|
|
876
|
-
return new
|
|
636
|
+
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
637
|
}
|
|
878
638
|
/**
|
|
879
639
|
* Creates a Transaction instance from a Lumos skeleton.
|
|
@@ -889,7 +649,7 @@ class Transaction {
|
|
|
889
649
|
* ```
|
|
890
650
|
*/
|
|
891
651
|
static fromLumosSkeleton(skeleton) {
|
|
892
|
-
return
|
|
652
|
+
return Transaction_1.from({
|
|
893
653
|
version: 0n,
|
|
894
654
|
cellDeps: skeleton.cellDeps.toArray(),
|
|
895
655
|
headerDeps: skeleton.headerDeps.toArray(),
|
|
@@ -912,7 +672,7 @@ class Transaction {
|
|
|
912
672
|
stringify() {
|
|
913
673
|
return JSON.stringify(this, (_, value) => {
|
|
914
674
|
if (typeof value === "bigint") {
|
|
915
|
-
return (0,
|
|
675
|
+
return (0, index_js_6.numToHex)(value);
|
|
916
676
|
}
|
|
917
677
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
918
678
|
return value;
|
|
@@ -929,50 +689,34 @@ class Transaction {
|
|
|
929
689
|
* ```
|
|
930
690
|
*/
|
|
931
691
|
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
|
-
}));
|
|
692
|
+
return exports.RawTransaction.encode(this);
|
|
940
693
|
}
|
|
941
694
|
/**
|
|
942
|
-
*
|
|
695
|
+
* Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
|
|
696
|
+
* To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
|
|
943
697
|
*
|
|
944
|
-
* @returns
|
|
698
|
+
* @returns The hash of the transaction.
|
|
945
699
|
*
|
|
946
700
|
* @example
|
|
947
701
|
* ```typescript
|
|
948
|
-
* const
|
|
702
|
+
* const txHash = transaction.hash();
|
|
949
703
|
* ```
|
|
950
704
|
*/
|
|
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
|
-
}));
|
|
705
|
+
hash() {
|
|
706
|
+
return (0, index_js_3.hashCkb)(this.rawToBytes());
|
|
963
707
|
}
|
|
964
708
|
/**
|
|
965
|
-
* Calculates the hash of the transaction.
|
|
709
|
+
* Calculates the hash of the transaction with witnesses.
|
|
966
710
|
*
|
|
967
|
-
* @returns The hash of the transaction.
|
|
711
|
+
* @returns The hash of the transaction with witnesses.
|
|
968
712
|
*
|
|
969
713
|
* @example
|
|
970
714
|
* ```typescript
|
|
971
|
-
* const
|
|
715
|
+
* const txFullHash = transaction.hashFull();
|
|
972
716
|
* ```
|
|
973
717
|
*/
|
|
974
|
-
|
|
975
|
-
return (0, index_js_3.hashCkb)(this.
|
|
718
|
+
hashFull() {
|
|
719
|
+
return (0, index_js_3.hashCkb)(this.toBytes());
|
|
976
720
|
}
|
|
977
721
|
/**
|
|
978
722
|
* Hashes a witness and updates the hasher.
|
|
@@ -987,7 +731,7 @@ class Transaction {
|
|
|
987
731
|
*/
|
|
988
732
|
static hashWitnessToHasher(witness, hasher) {
|
|
989
733
|
const raw = (0, index_js_1.bytesFrom)((0, index_js_4.hexFrom)(witness));
|
|
990
|
-
hasher.update((0,
|
|
734
|
+
hasher.update((0, index_js_6.numToBytes)(raw.length, 8));
|
|
991
735
|
hasher.update(raw);
|
|
992
736
|
}
|
|
993
737
|
/**
|
|
@@ -1028,7 +772,7 @@ class Transaction {
|
|
|
1028
772
|
if (position === -1) {
|
|
1029
773
|
return undefined;
|
|
1030
774
|
}
|
|
1031
|
-
|
|
775
|
+
Transaction_1.hashWitnessToHasher(this.witnesses[i], hasher);
|
|
1032
776
|
}
|
|
1033
777
|
if (position === -1) {
|
|
1034
778
|
return undefined;
|
|
@@ -1278,19 +1022,19 @@ class Transaction {
|
|
|
1278
1022
|
this.setWitnessArgsAt(position, witness);
|
|
1279
1023
|
}
|
|
1280
1024
|
async getInputsCapacity(client) {
|
|
1281
|
-
return (0,
|
|
1025
|
+
return (0, index_js_7.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1282
1026
|
await input.completeExtraInfos(client);
|
|
1283
1027
|
if (!input.cellOutput) {
|
|
1284
1028
|
throw new Error("Unable to complete input");
|
|
1285
1029
|
}
|
|
1286
1030
|
return acc + input.cellOutput.capacity;
|
|
1287
|
-
}, (0,
|
|
1031
|
+
}, (0, index_js_6.numFrom)(0));
|
|
1288
1032
|
}
|
|
1289
1033
|
getOutputsCapacity() {
|
|
1290
|
-
return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0,
|
|
1034
|
+
return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0, index_js_6.numFrom)(0));
|
|
1291
1035
|
}
|
|
1292
1036
|
async getInputsUdtBalance(client, type) {
|
|
1293
|
-
return (0,
|
|
1037
|
+
return (0, index_js_7.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1294
1038
|
await input.completeExtraInfos(client);
|
|
1295
1039
|
if (!input.cellOutput || !input.outputData) {
|
|
1296
1040
|
throw new Error("Unable to complete input");
|
|
@@ -1299,7 +1043,7 @@ class Transaction {
|
|
|
1299
1043
|
return;
|
|
1300
1044
|
}
|
|
1301
1045
|
return acc + udtBalanceFrom(input.outputData);
|
|
1302
|
-
}, (0,
|
|
1046
|
+
}, (0, index_js_6.numFrom)(0));
|
|
1303
1047
|
}
|
|
1304
1048
|
getOutputsUdtBalance(type) {
|
|
1305
1049
|
return this.outputs.reduce((acc, output, i) => {
|
|
@@ -1307,7 +1051,7 @@ class Transaction {
|
|
|
1307
1051
|
return acc;
|
|
1308
1052
|
}
|
|
1309
1053
|
return acc + udtBalanceFrom(this.outputsData[i]);
|
|
1310
|
-
}, (0,
|
|
1054
|
+
}, (0, index_js_6.numFrom)(0));
|
|
1311
1055
|
}
|
|
1312
1056
|
async completeInputs(from, filter, accumulator, init) {
|
|
1313
1057
|
const collectedCells = [];
|
|
@@ -1341,7 +1085,7 @@ class Transaction {
|
|
|
1341
1085
|
};
|
|
1342
1086
|
}
|
|
1343
1087
|
async completeInputsByCapacity(from, capacityTweak, filter) {
|
|
1344
|
-
const exceptedCapacity = this.getOutputsCapacity() + (0,
|
|
1088
|
+
const exceptedCapacity = this.getOutputsCapacity() + (0, index_js_6.numFrom)(capacityTweak ?? 0);
|
|
1345
1089
|
const inputsCapacity = await this.getInputsCapacity(from.client);
|
|
1346
1090
|
if (inputsCapacity >= exceptedCapacity) {
|
|
1347
1091
|
return 0;
|
|
@@ -1373,7 +1117,7 @@ class Transaction {
|
|
|
1373
1117
|
}
|
|
1374
1118
|
const { addedCount, accumulated } = await this.completeInputs(from, {
|
|
1375
1119
|
script: type,
|
|
1376
|
-
outputDataLenRange: [16, (0,
|
|
1120
|
+
outputDataLenRange: [16, (0, index_js_6.numFrom)("0xffffffff")],
|
|
1377
1121
|
}, (acc, { outputData }) => {
|
|
1378
1122
|
const balance = udtBalanceFrom(outputData);
|
|
1379
1123
|
const sum = acc + balance;
|
|
@@ -1386,7 +1130,7 @@ class Transaction {
|
|
|
1386
1130
|
}
|
|
1387
1131
|
estimateFee(feeRate) {
|
|
1388
1132
|
const txSize = this.toBytes().length + 4;
|
|
1389
|
-
return ((0,
|
|
1133
|
+
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
1134
|
}
|
|
1391
1135
|
async completeFee(from, change, expectedFeeRate, filter) {
|
|
1392
1136
|
const feeRate = expectedFeeRate ?? (await from.client.getFeeRate());
|
|
@@ -1418,7 +1162,7 @@ class Transaction {
|
|
|
1418
1162
|
this.copy(tx);
|
|
1419
1163
|
return [collected, false];
|
|
1420
1164
|
}
|
|
1421
|
-
const needed = (0,
|
|
1165
|
+
const needed = (0, index_js_6.numFrom)(await Promise.resolve(change(tx, extraCapacity - leastFee)));
|
|
1422
1166
|
// No enough extra capacity to create new cells for change
|
|
1423
1167
|
if (needed > index_js_2.Zero) {
|
|
1424
1168
|
leastExtraCapacity = needed;
|
|
@@ -1461,7 +1205,7 @@ class Transaction {
|
|
|
1461
1205
|
return this.completeFeeChangeToLock(from, script, feeRate, filter);
|
|
1462
1206
|
}
|
|
1463
1207
|
completeFeeChangeToOutput(from, index, feeRate, filter) {
|
|
1464
|
-
const change = Number((0,
|
|
1208
|
+
const change = Number((0, index_js_6.numFrom)(index));
|
|
1465
1209
|
if (!this.outputs[change]) {
|
|
1466
1210
|
throw new Error("Non-existed output to change");
|
|
1467
1211
|
}
|
|
@@ -1470,5 +1214,20 @@ class Transaction {
|
|
|
1470
1214
|
return 0;
|
|
1471
1215
|
}, feeRate, filter);
|
|
1472
1216
|
}
|
|
1473
|
-
}
|
|
1217
|
+
};
|
|
1474
1218
|
exports.Transaction = Transaction;
|
|
1219
|
+
exports.Transaction = Transaction = Transaction_1 = __decorate([
|
|
1220
|
+
index_js_5.mol.codec(index_js_5.mol
|
|
1221
|
+
.table({
|
|
1222
|
+
raw: exports.RawTransaction,
|
|
1223
|
+
witnesses: index_js_5.mol.BytesVec,
|
|
1224
|
+
})
|
|
1225
|
+
.mapIn((txLike) => {
|
|
1226
|
+
const tx = Transaction.from(txLike);
|
|
1227
|
+
return {
|
|
1228
|
+
raw: tx,
|
|
1229
|
+
witnesses: tx.witnesses,
|
|
1230
|
+
};
|
|
1231
|
+
})
|
|
1232
|
+
.mapOut((tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses })))
|
|
1233
|
+
], Transaction);
|