@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
package/src/ckb/transaction.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../fixedPoint/index.js";
|
|
9
9
|
import { Hasher, HasherCkb, hashCkb } from "../hasher/index.js";
|
|
10
10
|
import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
11
|
+
import { mol } from "../molecule/index.js";
|
|
11
12
|
import {
|
|
12
13
|
Num,
|
|
13
14
|
NumLike,
|
|
@@ -18,11 +19,16 @@ import {
|
|
|
18
19
|
} from "../num/index.js";
|
|
19
20
|
import { Signer } from "../signer/index.js";
|
|
20
21
|
import { apply, reduceAsync } from "../utils/index.js";
|
|
21
|
-
import
|
|
22
|
-
import { Script, ScriptLike } from "./script.js";
|
|
22
|
+
import { Script, ScriptLike, ScriptOpt } from "./script.js";
|
|
23
23
|
import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
|
|
24
24
|
import { LumosTransactionSkeletonType } from "./transactionLumos.js";
|
|
25
25
|
|
|
26
|
+
export const DepTypeCodec: mol.Codec<DepTypeLike, DepType> = mol.Codec.from({
|
|
27
|
+
byteLength: 1,
|
|
28
|
+
encode: depTypeToBytes,
|
|
29
|
+
decode: depTypeFromBytes,
|
|
30
|
+
});
|
|
31
|
+
|
|
26
32
|
/**
|
|
27
33
|
* @public
|
|
28
34
|
*/
|
|
@@ -112,7 +118,15 @@ export type OutPointLike = {
|
|
|
112
118
|
/**
|
|
113
119
|
* @public
|
|
114
120
|
*/
|
|
115
|
-
|
|
121
|
+
@mol.codec(
|
|
122
|
+
mol
|
|
123
|
+
.struct({
|
|
124
|
+
txHash: mol.Byte32,
|
|
125
|
+
index: mol.Uint32,
|
|
126
|
+
})
|
|
127
|
+
.map({ outMap: (decoded) => OutPoint.from(decoded) }),
|
|
128
|
+
)
|
|
129
|
+
export class OutPoint extends mol.Entity.Base<OutPointLike, OutPoint>() {
|
|
116
130
|
/**
|
|
117
131
|
* Creates an instance of OutPoint.
|
|
118
132
|
*
|
|
@@ -123,20 +137,8 @@ export class OutPoint {
|
|
|
123
137
|
constructor(
|
|
124
138
|
public txHash: Hex,
|
|
125
139
|
public index: Num,
|
|
126
|
-
) {
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Clone an OutPoint.
|
|
130
|
-
*
|
|
131
|
-
* @returns A cloned OutPoint instance.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* const outPoint1 = outPoint0.clone();
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
clone(): OutPoint {
|
|
139
|
-
return new OutPoint(this.txHash, this.index);
|
|
140
|
+
) {
|
|
141
|
+
super();
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
@@ -156,74 +158,6 @@ export class OutPoint {
|
|
|
156
158
|
}
|
|
157
159
|
return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
|
|
158
160
|
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Converts the OutPoint instance to molecule data format.
|
|
162
|
-
*
|
|
163
|
-
* @returns An object representing the outpoint in molecule data format.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
_toMolData() {
|
|
167
|
-
return {
|
|
168
|
-
txHash: bytesFrom(this.txHash),
|
|
169
|
-
index: numToBytes(this.index, 4),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Converts the OutPoint instance to bytes.
|
|
175
|
-
*
|
|
176
|
-
* @returns A Uint8Array containing the outpoint bytes.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```typescript
|
|
180
|
-
* const outPointBytes = outPoint.toBytes();
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
toBytes(): Bytes {
|
|
185
|
-
return bytesFrom(mol.SerializeOutPoint(this._toMolData()));
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Creates an OutPoint instance from a byte-like value or molecule OutPoint.
|
|
190
|
-
*
|
|
191
|
-
* @param bytes - The byte-like value or molecule OutPoint to convert.
|
|
192
|
-
* @returns An OutPoint instance.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```typescript
|
|
196
|
-
* const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
static fromBytes(bytes: BytesLike | mol.OutPoint): OutPoint {
|
|
201
|
-
const view =
|
|
202
|
-
bytes instanceof mol.OutPoint
|
|
203
|
-
? bytes
|
|
204
|
-
: new mol.OutPoint(bytesFrom(bytes));
|
|
205
|
-
|
|
206
|
-
return new OutPoint(
|
|
207
|
-
hexFrom(view.getTxHash().raw()),
|
|
208
|
-
numFromBytes(view.getIndex().raw()),
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Compares the current OutPoint instance with another OutPointLike object for equality.
|
|
214
|
-
*
|
|
215
|
-
* @param val - The OutPointLike object to compare with.
|
|
216
|
-
* @returns True if the out points are equal, otherwise false.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* ```typescript
|
|
220
|
-
* const isEqual = outPoint.eq(anotherOutPoint);
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
eq(val: OutPointLike): boolean {
|
|
224
|
-
const outPoint = OutPoint.from(val);
|
|
225
|
-
return this.txHash === outPoint.txHash && this.index === outPoint.index;
|
|
226
|
-
}
|
|
227
161
|
}
|
|
228
162
|
|
|
229
163
|
/**
|
|
@@ -237,7 +171,16 @@ export type CellOutputLike = {
|
|
|
237
171
|
/**
|
|
238
172
|
* @public
|
|
239
173
|
*/
|
|
240
|
-
|
|
174
|
+
@mol.codec(
|
|
175
|
+
mol
|
|
176
|
+
.table({
|
|
177
|
+
capacity: mol.Uint64,
|
|
178
|
+
lock: Script,
|
|
179
|
+
type: ScriptOpt,
|
|
180
|
+
})
|
|
181
|
+
.map({ outMap: (decoded) => CellOutput.from(decoded) }),
|
|
182
|
+
)
|
|
183
|
+
export class CellOutput extends mol.Entity.Base<CellOutputLike, CellOutput>() {
|
|
241
184
|
/**
|
|
242
185
|
* Creates an instance of CellOutput.
|
|
243
186
|
*
|
|
@@ -250,26 +193,14 @@ export class CellOutput {
|
|
|
250
193
|
public capacity: Num,
|
|
251
194
|
public lock: Script,
|
|
252
195
|
public type?: Script,
|
|
253
|
-
) {
|
|
196
|
+
) {
|
|
197
|
+
super();
|
|
198
|
+
}
|
|
254
199
|
|
|
255
200
|
get occupiedSize(): number {
|
|
256
201
|
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
257
202
|
}
|
|
258
203
|
|
|
259
|
-
/**
|
|
260
|
-
* Clone a CellOutput.
|
|
261
|
-
*
|
|
262
|
-
* @returns A cloned CellOutput instance.
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* ```typescript
|
|
266
|
-
* const cellOutput1 = cellOutput0.clone();
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
clone(): CellOutput {
|
|
270
|
-
return new CellOutput(this.capacity, this.lock.clone(), this.type?.clone());
|
|
271
|
-
}
|
|
272
|
-
|
|
273
204
|
/**
|
|
274
205
|
* Creates a CellOutput instance from a CellOutputLike object.
|
|
275
206
|
*
|
|
@@ -296,61 +227,8 @@ export class CellOutput {
|
|
|
296
227
|
apply(Script.from, cellOutput.type),
|
|
297
228
|
);
|
|
298
229
|
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Converts the CellOutput instance to molecule data format.
|
|
302
|
-
*
|
|
303
|
-
* @returns An object representing the cell output in molecule data format.
|
|
304
|
-
*/
|
|
305
|
-
|
|
306
|
-
_toMolData() {
|
|
307
|
-
return {
|
|
308
|
-
capacity: numToBytes(this.capacity, 8),
|
|
309
|
-
lock: this.lock._toMolData(),
|
|
310
|
-
type: this.type?._toMolData(),
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Converts the CellOutput instance to bytes.
|
|
316
|
-
*
|
|
317
|
-
* @returns A Uint8Array containing the cell output bytes.
|
|
318
|
-
*
|
|
319
|
-
* @example
|
|
320
|
-
* ```typescript
|
|
321
|
-
* const cellOutputBytes = cellOutput.toBytes();
|
|
322
|
-
* ```
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
toBytes(): Bytes {
|
|
326
|
-
return bytesFrom(mol.SerializeCellOutput(this._toMolData()));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Creates a CellOutput instance from a byte-like value or molecule CellOutput.
|
|
331
|
-
*
|
|
332
|
-
* @param bytes - The byte-like value or molecule CellOutput to convert.
|
|
333
|
-
* @returns A CellOutput instance.
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* ```typescript
|
|
337
|
-
* const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
|
|
338
|
-
* ```
|
|
339
|
-
*/
|
|
340
|
-
|
|
341
|
-
static fromBytes(bytes: BytesLike | mol.CellOutput): CellOutput {
|
|
342
|
-
const view =
|
|
343
|
-
bytes instanceof mol.CellOutput
|
|
344
|
-
? bytes
|
|
345
|
-
: new mol.CellOutput(bytesFrom(bytes));
|
|
346
|
-
|
|
347
|
-
return new CellOutput(
|
|
348
|
-
numFromBytes(view.getCapacity().raw()),
|
|
349
|
-
Script.fromBytes(view.getLock()),
|
|
350
|
-
apply(Script.fromBytes, mol.molOptional(view.getType())),
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
230
|
}
|
|
231
|
+
export const CellOutputVec = mol.vector(CellOutput);
|
|
354
232
|
|
|
355
233
|
/**
|
|
356
234
|
* @public
|
|
@@ -468,7 +346,13 @@ export type SinceLike =
|
|
|
468
346
|
/**
|
|
469
347
|
* @public
|
|
470
348
|
*/
|
|
471
|
-
|
|
349
|
+
@mol.codec(
|
|
350
|
+
mol.Uint64.map<SinceLike, Since>({
|
|
351
|
+
inMap: (encodable) => Since.from(encodable).toNum(),
|
|
352
|
+
outMap: (decoded) => Since.from(decoded),
|
|
353
|
+
}),
|
|
354
|
+
)
|
|
355
|
+
export class Since extends mol.Entity.Base<SinceLike, Since>() {
|
|
472
356
|
/**
|
|
473
357
|
* Creates an instance of Since.
|
|
474
358
|
*
|
|
@@ -481,7 +365,9 @@ export class Since {
|
|
|
481
365
|
public relative: "absolute" | "relative",
|
|
482
366
|
public metric: "blockNumber" | "epoch" | "timestamp",
|
|
483
367
|
public value: Num,
|
|
484
|
-
) {
|
|
368
|
+
) {
|
|
369
|
+
super();
|
|
370
|
+
}
|
|
485
371
|
|
|
486
372
|
/**
|
|
487
373
|
* Clone a Since.
|
|
@@ -580,7 +466,18 @@ export type CellInputLike = {
|
|
|
580
466
|
/**
|
|
581
467
|
* @public
|
|
582
468
|
*/
|
|
583
|
-
|
|
469
|
+
@mol.codec(
|
|
470
|
+
mol
|
|
471
|
+
.struct({
|
|
472
|
+
since: Since,
|
|
473
|
+
previousOutput: OutPoint,
|
|
474
|
+
})
|
|
475
|
+
.map<CellInputLike, CellInput>({
|
|
476
|
+
inMap: (encodable) => ({ ...encodable, since: encodable.since ?? 0 }),
|
|
477
|
+
outMap: (decoded) => CellInput.from(decoded),
|
|
478
|
+
}),
|
|
479
|
+
)
|
|
480
|
+
export class CellInput extends mol.Entity.Base<CellInputLike, CellInput>() {
|
|
584
481
|
/**
|
|
585
482
|
* Creates an instance of CellInput.
|
|
586
483
|
*
|
|
@@ -595,25 +492,8 @@ export class CellInput {
|
|
|
595
492
|
public since: Num,
|
|
596
493
|
public cellOutput?: CellOutput,
|
|
597
494
|
public outputData?: Hex,
|
|
598
|
-
) {
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Clone a CellInput.
|
|
602
|
-
*
|
|
603
|
-
* @returns A cloned CellInput instance.
|
|
604
|
-
*
|
|
605
|
-
* @example
|
|
606
|
-
* ```typescript
|
|
607
|
-
* const cellInput1 = cellInput0.clone();
|
|
608
|
-
* ```
|
|
609
|
-
*/
|
|
610
|
-
clone(): CellInput {
|
|
611
|
-
return new CellInput(
|
|
612
|
-
this.previousOutput.clone(),
|
|
613
|
-
this.since,
|
|
614
|
-
this.cellOutput?.clone(),
|
|
615
|
-
this.outputData,
|
|
616
|
-
);
|
|
495
|
+
) {
|
|
496
|
+
super();
|
|
617
497
|
}
|
|
618
498
|
|
|
619
499
|
/**
|
|
@@ -666,59 +546,8 @@ export class CellInput {
|
|
|
666
546
|
this.cellOutput = cell.cellOutput;
|
|
667
547
|
this.outputData = cell.outputData;
|
|
668
548
|
}
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Converts the CellInput instance to molecule data format.
|
|
672
|
-
*
|
|
673
|
-
* @returns An object representing the cell input in molecule data format.
|
|
674
|
-
*/
|
|
675
|
-
|
|
676
|
-
_toMolData() {
|
|
677
|
-
return {
|
|
678
|
-
previousOutput: this.previousOutput._toMolData(),
|
|
679
|
-
since: numToBytes(this.since, 8),
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Converts the CellInput instance to bytes.
|
|
685
|
-
*
|
|
686
|
-
* @returns A Uint8Array containing the cell input bytes.
|
|
687
|
-
*
|
|
688
|
-
* @example
|
|
689
|
-
* ```typescript
|
|
690
|
-
* const cellInputBytes = cellInput.toBytes();
|
|
691
|
-
* ```
|
|
692
|
-
*/
|
|
693
|
-
|
|
694
|
-
toBytes(): Bytes {
|
|
695
|
-
return bytesFrom(mol.SerializeCellInput(this._toMolData()));
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
* Creates a CellInput instance from a byte-like value or molecule CellInput.
|
|
700
|
-
*
|
|
701
|
-
* @param bytes - The byte-like value or molecule CellInput to convert.
|
|
702
|
-
* @returns A CellInput instance.
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* ```typescript
|
|
706
|
-
* const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
|
|
707
|
-
* ```
|
|
708
|
-
*/
|
|
709
|
-
|
|
710
|
-
static fromBytes(bytes: BytesLike | mol.CellInput): CellInput {
|
|
711
|
-
const view =
|
|
712
|
-
bytes instanceof mol.CellInput
|
|
713
|
-
? bytes
|
|
714
|
-
: new mol.CellInput(bytesFrom(bytes));
|
|
715
|
-
|
|
716
|
-
return new CellInput(
|
|
717
|
-
OutPoint.fromBytes(view.getPreviousOutput()),
|
|
718
|
-
numFromBytes(view.getSince().raw()),
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
549
|
}
|
|
550
|
+
export const CellInputVec = mol.vector(CellInput);
|
|
722
551
|
|
|
723
552
|
/**
|
|
724
553
|
* @public
|
|
@@ -730,7 +559,15 @@ export type CellDepLike = {
|
|
|
730
559
|
/**
|
|
731
560
|
* @public
|
|
732
561
|
*/
|
|
733
|
-
|
|
562
|
+
@mol.codec(
|
|
563
|
+
mol
|
|
564
|
+
.struct({
|
|
565
|
+
outPoint: OutPoint,
|
|
566
|
+
depType: DepTypeCodec,
|
|
567
|
+
})
|
|
568
|
+
.map({ outMap: (decoded) => CellDep.from(decoded) }),
|
|
569
|
+
)
|
|
570
|
+
export class CellDep extends mol.Entity.Base<CellDepLike, CellDep>() {
|
|
734
571
|
/**
|
|
735
572
|
* Creates an instance of CellDep.
|
|
736
573
|
*
|
|
@@ -741,7 +578,9 @@ export class CellDep {
|
|
|
741
578
|
constructor(
|
|
742
579
|
public outPoint: OutPoint,
|
|
743
580
|
public depType: DepType,
|
|
744
|
-
) {
|
|
581
|
+
) {
|
|
582
|
+
super();
|
|
583
|
+
}
|
|
745
584
|
|
|
746
585
|
/**
|
|
747
586
|
* Clone a CellDep.
|
|
@@ -783,75 +622,8 @@ export class CellDep {
|
|
|
783
622
|
depTypeFrom(cellDep.depType),
|
|
784
623
|
);
|
|
785
624
|
}
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* Converts the CellDep instance to molecule data format.
|
|
789
|
-
*
|
|
790
|
-
* @returns An object representing the cell dependency in molecule data format.
|
|
791
|
-
*/
|
|
792
|
-
|
|
793
|
-
_toMolData() {
|
|
794
|
-
return {
|
|
795
|
-
outPoint: this.outPoint._toMolData(),
|
|
796
|
-
depType: depTypeToBytes(this.depType),
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* Converts the CellDep instance to bytes.
|
|
802
|
-
*
|
|
803
|
-
* @returns A Uint8Array containing the cell dependency bytes.
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* ```typescript
|
|
807
|
-
* const cellDepBytes = cellDep.toBytes();
|
|
808
|
-
* ```
|
|
809
|
-
*/
|
|
810
|
-
|
|
811
|
-
toBytes(): Bytes {
|
|
812
|
-
return bytesFrom(mol.SerializeCellDep(this._toMolData()));
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* Creates a CellDep instance from a byte-like value or molecule CellDep.
|
|
817
|
-
*
|
|
818
|
-
* @param bytes - The byte-like value or molecule CellDep to convert.
|
|
819
|
-
* @returns A CellDep instance.
|
|
820
|
-
*
|
|
821
|
-
* @example
|
|
822
|
-
* ```typescript
|
|
823
|
-
* const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
|
|
824
|
-
* ```
|
|
825
|
-
*/
|
|
826
|
-
|
|
827
|
-
fromBytes(bytes: BytesLike | mol.CellDep): CellDep {
|
|
828
|
-
const view =
|
|
829
|
-
bytes instanceof mol.CellDep ? bytes : new mol.CellDep(bytesFrom(bytes));
|
|
830
|
-
|
|
831
|
-
return new CellDep(
|
|
832
|
-
OutPoint.fromBytes(view.getOutPoint()),
|
|
833
|
-
depTypeFromBytes([view.getDepType()]),
|
|
834
|
-
);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* Compares the current CellDep instance with another CellDepLike object for equality.
|
|
839
|
-
*
|
|
840
|
-
* @param val - The CellDepLike object to compare with.
|
|
841
|
-
* @returns True if the cell deps are equal, otherwise false.
|
|
842
|
-
*
|
|
843
|
-
* @example
|
|
844
|
-
* ```typescript
|
|
845
|
-
* const isEqual = cellDep.eq(anotherCellDep);
|
|
846
|
-
* ```
|
|
847
|
-
*/
|
|
848
|
-
eq(val: CellDepLike): boolean {
|
|
849
|
-
const cellDep = CellDep.from(val);
|
|
850
|
-
return (
|
|
851
|
-
this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType
|
|
852
|
-
);
|
|
853
|
-
}
|
|
854
625
|
}
|
|
626
|
+
export const CellDepVec = mol.vector(CellDep);
|
|
855
627
|
|
|
856
628
|
/**
|
|
857
629
|
* @public
|
|
@@ -864,7 +636,19 @@ export type WitnessArgsLike = {
|
|
|
864
636
|
/**
|
|
865
637
|
* @public
|
|
866
638
|
*/
|
|
867
|
-
|
|
639
|
+
@mol.codec(
|
|
640
|
+
mol
|
|
641
|
+
.table({
|
|
642
|
+
lock: mol.BytesOpt,
|
|
643
|
+
inputType: mol.BytesOpt,
|
|
644
|
+
outputType: mol.BytesOpt,
|
|
645
|
+
})
|
|
646
|
+
.map({ outMap: (decoded) => WitnessArgs.from(decoded) }),
|
|
647
|
+
)
|
|
648
|
+
export class WitnessArgs extends mol.Entity.Base<
|
|
649
|
+
WitnessArgsLike,
|
|
650
|
+
WitnessArgs
|
|
651
|
+
>() {
|
|
868
652
|
/**
|
|
869
653
|
* Creates an instance of WitnessArgs.
|
|
870
654
|
*
|
|
@@ -877,7 +661,9 @@ export class WitnessArgs {
|
|
|
877
661
|
public lock?: Hex,
|
|
878
662
|
public inputType?: Hex,
|
|
879
663
|
public outputType?: Hex,
|
|
880
|
-
) {
|
|
664
|
+
) {
|
|
665
|
+
super();
|
|
666
|
+
}
|
|
881
667
|
|
|
882
668
|
/**
|
|
883
669
|
* Creates a WitnessArgs instance from a WitnessArgsLike object.
|
|
@@ -906,60 +692,6 @@ export class WitnessArgs {
|
|
|
906
692
|
apply(hexFrom, witnessArgs.outputType),
|
|
907
693
|
);
|
|
908
694
|
}
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* Converts the WitnessArgs instance to molecule data format.
|
|
912
|
-
*
|
|
913
|
-
* @returns An object representing the witness arguments in molecule data format.
|
|
914
|
-
*/
|
|
915
|
-
|
|
916
|
-
_toMolData() {
|
|
917
|
-
return {
|
|
918
|
-
lock: apply(bytesFrom, this.lock),
|
|
919
|
-
inputType: apply(bytesFrom, this.inputType),
|
|
920
|
-
outputType: apply(bytesFrom, this.outputType),
|
|
921
|
-
};
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
/**
|
|
925
|
-
* Converts the WitnessArgs instance to bytes.
|
|
926
|
-
*
|
|
927
|
-
* @returns A Uint8Array containing the witness arguments bytes.
|
|
928
|
-
*
|
|
929
|
-
* @example
|
|
930
|
-
* ```typescript
|
|
931
|
-
* const witnessArgsBytes = witnessArgs.toBytes();
|
|
932
|
-
* ```
|
|
933
|
-
*/
|
|
934
|
-
|
|
935
|
-
toBytes(): Bytes {
|
|
936
|
-
return bytesFrom(mol.SerializeWitnessArgs(this._toMolData()));
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
/**
|
|
940
|
-
* Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
|
|
941
|
-
*
|
|
942
|
-
* @param bytes - The byte-like value or molecule WitnessArgs to convert.
|
|
943
|
-
* @returns A WitnessArgs instance.
|
|
944
|
-
*
|
|
945
|
-
* @example
|
|
946
|
-
* ```typescript
|
|
947
|
-
* const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
|
|
948
|
-
* ```
|
|
949
|
-
*/
|
|
950
|
-
|
|
951
|
-
static fromBytes(bytes: BytesLike | mol.WitnessArgs): WitnessArgs {
|
|
952
|
-
const view =
|
|
953
|
-
bytes instanceof mol.WitnessArgs
|
|
954
|
-
? bytes
|
|
955
|
-
: new mol.WitnessArgs(bytesFrom(bytes));
|
|
956
|
-
|
|
957
|
-
return new WitnessArgs(
|
|
958
|
-
apply(hexFrom, mol.molOptional(view.getLock())?.raw()),
|
|
959
|
-
apply(hexFrom, mol.molOptional(view.getInputType())?.raw()),
|
|
960
|
-
apply(hexFrom, mol.molOptional(view.getOutputType())?.raw()),
|
|
961
|
-
);
|
|
962
|
-
}
|
|
963
695
|
}
|
|
964
696
|
|
|
965
697
|
/**
|
|
@@ -974,6 +706,17 @@ export function udtBalanceFrom(dataLike: BytesLike): Num {
|
|
|
974
706
|
return numFromBytes(data);
|
|
975
707
|
}
|
|
976
708
|
|
|
709
|
+
export const RawTransaction = mol
|
|
710
|
+
.table({
|
|
711
|
+
version: mol.Uint32,
|
|
712
|
+
cellDeps: CellDepVec,
|
|
713
|
+
headerDeps: mol.Byte32Vec,
|
|
714
|
+
inputs: CellInputVec,
|
|
715
|
+
outputs: CellOutputVec,
|
|
716
|
+
outputsData: mol.BytesVec,
|
|
717
|
+
})
|
|
718
|
+
.map({ outMap: (decoded) => Transaction.from(decoded) });
|
|
719
|
+
|
|
977
720
|
/**
|
|
978
721
|
* @public
|
|
979
722
|
*/
|
|
@@ -992,7 +735,27 @@ export type TransactionLike = {
|
|
|
992
735
|
/**
|
|
993
736
|
* @public
|
|
994
737
|
*/
|
|
995
|
-
|
|
738
|
+
@mol.codec(
|
|
739
|
+
mol
|
|
740
|
+
.table({
|
|
741
|
+
raw: RawTransaction,
|
|
742
|
+
witnesses: mol.BytesVec,
|
|
743
|
+
})
|
|
744
|
+
.map<TransactionLike, Transaction>({
|
|
745
|
+
inMap: (txLike) => {
|
|
746
|
+
const tx = Transaction.from(txLike);
|
|
747
|
+
return {
|
|
748
|
+
raw: tx,
|
|
749
|
+
witnesses: tx.witnesses,
|
|
750
|
+
};
|
|
751
|
+
},
|
|
752
|
+
outMap: (tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses }),
|
|
753
|
+
}),
|
|
754
|
+
)
|
|
755
|
+
export class Transaction extends mol.Entity.Base<
|
|
756
|
+
TransactionLike,
|
|
757
|
+
Transaction
|
|
758
|
+
>() {
|
|
996
759
|
/**
|
|
997
760
|
* Creates an instance of Transaction.
|
|
998
761
|
*
|
|
@@ -1013,7 +776,9 @@ export class Transaction {
|
|
|
1013
776
|
public outputs: CellOutput[],
|
|
1014
777
|
public outputsData: Hex[],
|
|
1015
778
|
public witnesses: Hex[],
|
|
1016
|
-
) {
|
|
779
|
+
) {
|
|
780
|
+
super();
|
|
781
|
+
}
|
|
1017
782
|
|
|
1018
783
|
/**
|
|
1019
784
|
* Creates a default Transaction instance with empty fields.
|
|
@@ -1048,28 +813,6 @@ export class Transaction {
|
|
|
1048
813
|
this.witnesses = tx.witnesses;
|
|
1049
814
|
}
|
|
1050
815
|
|
|
1051
|
-
/**
|
|
1052
|
-
* Clone a Transaction.
|
|
1053
|
-
*
|
|
1054
|
-
* @returns A cloned instance
|
|
1055
|
-
*
|
|
1056
|
-
* @example
|
|
1057
|
-
* ```typescript
|
|
1058
|
-
* const tx1 = tx0.clone();
|
|
1059
|
-
* ```
|
|
1060
|
-
*/
|
|
1061
|
-
clone(): Transaction {
|
|
1062
|
-
return new Transaction(
|
|
1063
|
-
0n,
|
|
1064
|
-
this.cellDeps.map((c) => c.clone()),
|
|
1065
|
-
[...this.headerDeps],
|
|
1066
|
-
this.inputs.map((i) => i.clone()),
|
|
1067
|
-
this.outputs.map((o) => o.clone()),
|
|
1068
|
-
[...this.outputsData],
|
|
1069
|
-
[...this.witnesses],
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
816
|
/**
|
|
1074
817
|
* Creates a Transaction instance from a TransactionLike object.
|
|
1075
818
|
*
|
|
@@ -1188,57 +931,36 @@ export class Transaction {
|
|
|
1188
931
|
* ```
|
|
1189
932
|
*/
|
|
1190
933
|
rawToBytes(): Bytes {
|
|
1191
|
-
return
|
|
1192
|
-
mol.SerializeRawTransaction({
|
|
1193
|
-
version: numToBytes(this.version, 4),
|
|
1194
|
-
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
1195
|
-
headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
|
|
1196
|
-
inputs: this.inputs.map((i) => i._toMolData()),
|
|
1197
|
-
outputs: this.outputs.map((o) => o._toMolData()),
|
|
1198
|
-
outputsData: this.outputsData.map((header) => bytesFrom(header)),
|
|
1199
|
-
}),
|
|
1200
|
-
);
|
|
934
|
+
return RawTransaction.encode(this);
|
|
1201
935
|
}
|
|
1202
936
|
|
|
1203
937
|
/**
|
|
1204
|
-
*
|
|
938
|
+
* Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
|
|
939
|
+
* To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
|
|
1205
940
|
*
|
|
1206
|
-
* @returns
|
|
941
|
+
* @returns The hash of the transaction.
|
|
1207
942
|
*
|
|
1208
943
|
* @example
|
|
1209
944
|
* ```typescript
|
|
1210
|
-
* const
|
|
945
|
+
* const txHash = transaction.hash();
|
|
1211
946
|
* ```
|
|
1212
947
|
*/
|
|
1213
|
-
|
|
1214
|
-
return
|
|
1215
|
-
mol.SerializeTransaction({
|
|
1216
|
-
raw: {
|
|
1217
|
-
version: numToBytes(this.version, 4),
|
|
1218
|
-
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
1219
|
-
headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
|
|
1220
|
-
inputs: this.inputs.map((i) => i._toMolData()),
|
|
1221
|
-
outputs: this.outputs.map((o) => o._toMolData()),
|
|
1222
|
-
outputsData: this.outputsData.map((header) => bytesFrom(header)),
|
|
1223
|
-
},
|
|
1224
|
-
witnesses: this.witnesses.map((witness) => bytesFrom(witness)),
|
|
1225
|
-
}),
|
|
1226
|
-
);
|
|
948
|
+
hash(): Hex {
|
|
949
|
+
return hashCkb(this.rawToBytes());
|
|
1227
950
|
}
|
|
1228
951
|
|
|
1229
952
|
/**
|
|
1230
|
-
* Calculates the hash of the transaction.
|
|
953
|
+
* Calculates the hash of the transaction with witnesses.
|
|
1231
954
|
*
|
|
1232
|
-
* @returns The hash of the transaction.
|
|
955
|
+
* @returns The hash of the transaction with witnesses.
|
|
1233
956
|
*
|
|
1234
957
|
* @example
|
|
1235
958
|
* ```typescript
|
|
1236
|
-
* const
|
|
959
|
+
* const txFullHash = transaction.hashFull();
|
|
1237
960
|
* ```
|
|
1238
961
|
*/
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
return hashCkb(this.rawToBytes());
|
|
962
|
+
hashFull(): Hex {
|
|
963
|
+
return hashCkb(this.toBytes());
|
|
1242
964
|
}
|
|
1243
965
|
|
|
1244
966
|
/**
|