@ckb-ccc/core 1.10.0 → 1.11.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 +43 -4
- package/dist/ckb/hash.d.ts +18 -0
- package/dist/ckb/hash.d.ts.map +1 -0
- package/dist/ckb/hash.js +19 -0
- package/dist/ckb/index.d.ts +1 -0
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +1 -0
- package/dist/ckb/transaction.d.ts +179 -11
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +197 -59
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +63 -62
- package/dist/client/clientPublicTestnet.advanced.d.ts +0 -23
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +63 -146
- package/dist/client/knownScript.d.ts +1 -3
- package/dist/client/knownScript.d.ts.map +1 -1
- package/dist/client/knownScript.js +0 -4
- package/dist/hasher/hasherCkb.d.ts +0 -16
- package/dist/hasher/hasherCkb.d.ts.map +1 -1
- package/dist/hasher/hasherCkb.js +0 -18
- package/dist/molecule/codec.d.ts +30 -10
- package/dist/molecule/codec.d.ts.map +1 -1
- package/dist/molecule/codec.js +46 -13
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +18 -6
- package/dist/signer/signer/index.d.ts +11 -1
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +23 -0
- package/dist.commonjs/ckb/hash.d.ts +18 -0
- package/dist.commonjs/ckb/hash.d.ts.map +1 -0
- package/dist.commonjs/ckb/hash.js +22 -0
- package/dist.commonjs/ckb/index.d.ts +1 -0
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +1 -0
- package/dist.commonjs/ckb/transaction.d.ts +179 -11
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +197 -59
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +63 -62
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +0 -23
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +64 -147
- package/dist.commonjs/client/knownScript.d.ts +1 -3
- package/dist.commonjs/client/knownScript.d.ts.map +1 -1
- package/dist.commonjs/client/knownScript.js +0 -4
- package/dist.commonjs/hasher/hasherCkb.d.ts +0 -16
- package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -1
- package/dist.commonjs/hasher/hasherCkb.js +2 -21
- package/dist.commonjs/molecule/codec.d.ts +30 -10
- package/dist.commonjs/molecule/codec.d.ts.map +1 -1
- package/dist.commonjs/molecule/codec.js +46 -13
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +18 -6
- package/dist.commonjs/signer/signer/index.d.ts +11 -1
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +23 -0
- package/package.json +1 -1
- package/prettier.config.mjs +1 -1
- package/src/ckb/hash.ts +28 -0
- package/src/ckb/index.ts +1 -0
- package/src/ckb/transaction.ts +231 -52
- package/src/client/clientPublicMainnet.advanced.ts +72 -70
- package/src/client/clientPublicTestnet.advanced.ts +72 -165
- package/src/client/knownScript.ts +0 -5
- package/src/hasher/hasherCkb.ts +0 -26
- package/src/molecule/codec.ts +50 -13
- package/src/signer/ckb/signerCkbScriptReadonly.ts +24 -8
- package/src/signer/signer/index.ts +34 -0
package/dist/ckb/transaction.js
CHANGED
|
@@ -172,26 +172,15 @@ let CellOutput = CellOutput_1 = class CellOutput extends mol.Entity.Base() {
|
|
|
172
172
|
get occupiedSize() {
|
|
173
173
|
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
174
174
|
}
|
|
175
|
-
|
|
176
|
-
* Creates a CellOutput instance from a CellOutputLike object.
|
|
177
|
-
*
|
|
178
|
-
* @param cellOutput - A CellOutputLike object or an instance of CellOutput.
|
|
179
|
-
* @returns A CellOutput instance.
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```typescript
|
|
183
|
-
* const cellOutput = CellOutput.from({
|
|
184
|
-
* capacity: 1000n,
|
|
185
|
-
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
|
|
186
|
-
* type: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
187
|
-
* });
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
static from(cellOutput) {
|
|
175
|
+
static from(cellOutput, outputData) {
|
|
191
176
|
if (cellOutput instanceof CellOutput_1) {
|
|
192
177
|
return cellOutput;
|
|
193
178
|
}
|
|
194
|
-
|
|
179
|
+
const output = new CellOutput_1(numFrom(cellOutput.capacity ?? 0), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
|
|
180
|
+
if (output.capacity === Zero) {
|
|
181
|
+
output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData ?? "0x").length);
|
|
182
|
+
}
|
|
183
|
+
return output;
|
|
195
184
|
}
|
|
196
185
|
/**
|
|
197
186
|
* Clone a CellOutput.
|
|
@@ -234,15 +223,43 @@ export class Cell {
|
|
|
234
223
|
}
|
|
235
224
|
/**
|
|
236
225
|
* Creates a Cell instance from a CellLike object.
|
|
226
|
+
* This method accepts either `outPoint` or `previousOutput` to specify the cell's location,
|
|
227
|
+
* and supports automatic capacity calculation for the cell output.
|
|
237
228
|
*
|
|
238
|
-
* @param cell - A CellLike object or an instance of Cell.
|
|
229
|
+
* @param cell - A CellLike object or an instance of Cell. The object can use either:
|
|
230
|
+
* - `outPoint`: For referencing a cell output
|
|
231
|
+
* - `previousOutput`: For referencing a cell input (alternative name for outPoint)
|
|
232
|
+
* The cellOutput can omit capacity for automatic calculation.
|
|
239
233
|
* @returns A Cell instance.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* // Using outPoint with explicit capacity
|
|
238
|
+
* const cell1 = Cell.from({
|
|
239
|
+
* outPoint: { txHash: "0x...", index: 0 },
|
|
240
|
+
* cellOutput: {
|
|
241
|
+
* capacity: 1000n,
|
|
242
|
+
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
243
|
+
* },
|
|
244
|
+
* outputData: "0x"
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* // Using previousOutput with automatic capacity calculation
|
|
248
|
+
* const cell2 = Cell.from({
|
|
249
|
+
* previousOutput: { txHash: "0x...", index: 0 },
|
|
250
|
+
* cellOutput: {
|
|
251
|
+
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
252
|
+
* // capacity will be calculated automatically
|
|
253
|
+
* },
|
|
254
|
+
* outputData: "0x1234"
|
|
255
|
+
* });
|
|
256
|
+
* ```
|
|
240
257
|
*/
|
|
241
258
|
static from(cell) {
|
|
242
259
|
if (cell instanceof Cell) {
|
|
243
260
|
return cell;
|
|
244
261
|
}
|
|
245
|
-
return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
|
|
262
|
+
return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput, cell.outputData), hexFrom(cell.outputData));
|
|
246
263
|
}
|
|
247
264
|
get capacityFree() {
|
|
248
265
|
const occupiedSize = fixedPointFrom(this.cellOutput.occupiedSize + bytesFrom(this.outputData).length);
|
|
@@ -720,6 +737,9 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
720
737
|
}
|
|
721
738
|
/**
|
|
722
739
|
* Copy every properties from another transaction.
|
|
740
|
+
* This method replaces all properties of the current transaction with those from the provided transaction.
|
|
741
|
+
*
|
|
742
|
+
* @param txLike - The transaction-like object to copy properties from.
|
|
723
743
|
*
|
|
724
744
|
* @example
|
|
725
745
|
* ```typescript
|
|
@@ -799,17 +819,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
799
819
|
if (tx instanceof Transaction_1) {
|
|
800
820
|
return tx;
|
|
801
821
|
}
|
|
802
|
-
const outputs = tx.outputs?.map((output, i) =>
|
|
803
|
-
const o = CellOutput.from({
|
|
804
|
-
...output,
|
|
805
|
-
capacity: output.capacity ?? 0,
|
|
806
|
-
});
|
|
807
|
-
if (o.capacity === Zero) {
|
|
808
|
-
o.capacity = fixedPointFrom(o.occupiedSize +
|
|
809
|
-
(apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
810
|
-
}
|
|
811
|
-
return o;
|
|
812
|
-
}) ?? [];
|
|
822
|
+
const outputs = tx.outputs?.map((output, i) => CellOutput.from(output, tx.outputsData?.[i] ?? [])) ?? [];
|
|
813
823
|
const outputsData = outputs.map((_, i) => hexFrom(tx.outputsData?.[i] ?? "0x"));
|
|
814
824
|
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
815
825
|
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)));
|
|
@@ -992,7 +1002,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
992
1002
|
*
|
|
993
1003
|
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
994
1004
|
* @param client - The client for complete extra infos in the transaction.
|
|
995
|
-
* @returns A promise that resolves to the
|
|
1005
|
+
* @returns A promise that resolves to the found index, or undefined if no matching input is found.
|
|
996
1006
|
*
|
|
997
1007
|
* @example
|
|
998
1008
|
* ```typescript
|
|
@@ -1013,7 +1023,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1013
1023
|
*
|
|
1014
1024
|
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1015
1025
|
* @param client - The client for complete extra infos in the transaction.
|
|
1016
|
-
* @returns A promise that resolves to the
|
|
1026
|
+
* @returns A promise that resolves to the found index, or undefined if no matching input is found.
|
|
1017
1027
|
*
|
|
1018
1028
|
* @example
|
|
1019
1029
|
* ```typescript
|
|
@@ -1101,18 +1111,18 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1101
1111
|
* Set output data at index.
|
|
1102
1112
|
*
|
|
1103
1113
|
* @param index - The index of the output data.
|
|
1104
|
-
* @param
|
|
1114
|
+
* @param data - The data to set.
|
|
1105
1115
|
*
|
|
1106
1116
|
* @example
|
|
1107
1117
|
* ```typescript
|
|
1108
|
-
*
|
|
1118
|
+
* tx.setOutputDataAt(0, "0x00");
|
|
1109
1119
|
* ```
|
|
1110
1120
|
*/
|
|
1111
|
-
setOutputDataAt(index,
|
|
1121
|
+
setOutputDataAt(index, data) {
|
|
1112
1122
|
if (this.outputsData.length < index) {
|
|
1113
1123
|
this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
|
|
1114
1124
|
}
|
|
1115
|
-
this.outputsData[index] = hexFrom(
|
|
1125
|
+
this.outputsData[index] = hexFrom(data);
|
|
1116
1126
|
}
|
|
1117
1127
|
/**
|
|
1118
1128
|
* get input
|
|
@@ -1175,14 +1185,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1175
1185
|
* ```
|
|
1176
1186
|
*/
|
|
1177
1187
|
addOutput(outputLike, outputData = "0x") {
|
|
1178
|
-
const
|
|
1179
|
-
...outputLike,
|
|
1180
|
-
capacity: outputLike.capacity ?? 0,
|
|
1181
|
-
});
|
|
1182
|
-
if (output.capacity === Zero) {
|
|
1183
|
-
output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData).length);
|
|
1184
|
-
}
|
|
1185
|
-
const len = this.outputs.push(output);
|
|
1188
|
+
const len = this.outputs.push(CellOutput.from(outputLike, outputData));
|
|
1186
1189
|
this.setOutputDataAt(len - 1, outputData);
|
|
1187
1190
|
return len;
|
|
1188
1191
|
}
|
|
@@ -1454,18 +1457,20 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1454
1457
|
await this.getInputsCapacity(from.client);
|
|
1455
1458
|
let leastFee = Zero;
|
|
1456
1459
|
let leastExtraCapacity = Zero;
|
|
1460
|
+
let collected = 0;
|
|
1461
|
+
// ===
|
|
1462
|
+
// Usually, for the worst situation, three iterations are needed
|
|
1463
|
+
// 1. First attempt to complete the transaction.
|
|
1464
|
+
// 2. Not enough capacity for the change cell.
|
|
1465
|
+
// 3. Fee increased by the change cell.
|
|
1466
|
+
// ===
|
|
1457
1467
|
while (true) {
|
|
1458
|
-
|
|
1459
|
-
const collected = await (async () => {
|
|
1468
|
+
collected += await (async () => {
|
|
1460
1469
|
if (!(options?.shouldAddInputs ?? true)) {
|
|
1461
|
-
const fee = (await tx.getFee(from.client)) - leastFee - leastExtraCapacity;
|
|
1462
|
-
if (fee < Zero) {
|
|
1463
|
-
throw new ErrorTransactionInsufficientCapacity(-fee);
|
|
1464
|
-
}
|
|
1465
1470
|
return 0;
|
|
1466
1471
|
}
|
|
1467
1472
|
try {
|
|
1468
|
-
return await
|
|
1473
|
+
return await this.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
|
|
1469
1474
|
}
|
|
1470
1475
|
catch (err) {
|
|
1471
1476
|
if (err instanceof ErrorTransactionInsufficientCapacity &&
|
|
@@ -1477,20 +1482,28 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1477
1482
|
throw err;
|
|
1478
1483
|
}
|
|
1479
1484
|
})();
|
|
1480
|
-
await from.
|
|
1485
|
+
const fee = await this.getFee(from.client);
|
|
1486
|
+
if (fee < leastFee + leastExtraCapacity) {
|
|
1487
|
+
// Not enough capacity are collected, it should only happens when shouldAddInputs is false
|
|
1488
|
+
throw new ErrorTransactionInsufficientCapacity(leastFee + leastExtraCapacity - fee, { isForChange: leastExtraCapacity !== Zero });
|
|
1489
|
+
}
|
|
1490
|
+
await from.prepareTransaction(this);
|
|
1481
1491
|
if (leastFee === Zero) {
|
|
1482
1492
|
// The initial fee is calculated based on prepared transaction
|
|
1483
|
-
|
|
1493
|
+
// This should only happens during the first iteration
|
|
1494
|
+
leastFee = this.estimateFee(feeRate);
|
|
1484
1495
|
}
|
|
1485
|
-
const fee = await tx.getFee(from.client);
|
|
1486
1496
|
// The extra capacity paid the fee without a change
|
|
1497
|
+
// leastExtraCapacity should be 0 here, otherwise we should failed in the previous check
|
|
1498
|
+
// So this only happens in the first iteration
|
|
1487
1499
|
if (fee === leastFee) {
|
|
1488
|
-
this.copy(tx);
|
|
1489
1500
|
return [collected, false];
|
|
1490
1501
|
}
|
|
1502
|
+
// Invoke the change function on a transaction multiple times may cause problems, so we clone it
|
|
1503
|
+
const tx = this.clone();
|
|
1491
1504
|
const needed = numFrom(await Promise.resolve(change(tx, fee - leastFee)));
|
|
1492
|
-
// No enough extra capacity to create new cells for change
|
|
1493
1505
|
if (needed > Zero) {
|
|
1506
|
+
// No enough extra capacity to create new cells for change, collect inputs again
|
|
1494
1507
|
leastExtraCapacity = needed;
|
|
1495
1508
|
continue;
|
|
1496
1509
|
}
|
|
@@ -1512,6 +1525,38 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1512
1525
|
leastFee = changedFee;
|
|
1513
1526
|
}
|
|
1514
1527
|
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Completes the transaction fee by adding inputs and creating a change output with the specified lock script.
|
|
1530
|
+
* This is a convenience method that automatically creates a change cell with the provided lock script
|
|
1531
|
+
* when there's excess capacity after paying the transaction fee.
|
|
1532
|
+
*
|
|
1533
|
+
* @param from - The signer to complete inputs from and prepare the transaction.
|
|
1534
|
+
* @param change - The lock script for the change output cell.
|
|
1535
|
+
* @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
|
|
1536
|
+
* @param filter - Optional filter for selecting cells when adding inputs.
|
|
1537
|
+
* @param options - Optional configuration object.
|
|
1538
|
+
* @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
|
|
1539
|
+
* @param options.maxFeeRate - Maximum allowed fee rate.
|
|
1540
|
+
* @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
|
|
1541
|
+
* @returns A promise that resolves to a tuple containing:
|
|
1542
|
+
* - The number of inputs added during the process
|
|
1543
|
+
* - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
|
|
1544
|
+
*
|
|
1545
|
+
* @example
|
|
1546
|
+
* ```typescript
|
|
1547
|
+
* const changeScript = Script.from({
|
|
1548
|
+
* codeHash: "0x...",
|
|
1549
|
+
* hashType: "type",
|
|
1550
|
+
* args: "0x..."
|
|
1551
|
+
* });
|
|
1552
|
+
*
|
|
1553
|
+
* const [addedInputs, hasChange] = await tx.completeFeeChangeToLock(
|
|
1554
|
+
* signer,
|
|
1555
|
+
* changeScript,
|
|
1556
|
+
* 1000n // 1000 shannons per 1000 bytes
|
|
1557
|
+
* );
|
|
1558
|
+
* ```
|
|
1559
|
+
*/
|
|
1515
1560
|
completeFeeChangeToLock(from, change, feeRate, filter, options) {
|
|
1516
1561
|
const script = Script.from(change);
|
|
1517
1562
|
return this.completeFee(from, (tx, capacity) => {
|
|
@@ -1525,10 +1570,66 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
|
1525
1570
|
return 0;
|
|
1526
1571
|
}, feeRate, filter, options);
|
|
1527
1572
|
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Completes the transaction fee using the signer's recommended address for change.
|
|
1575
|
+
* This is a convenience method that automatically uses the signer's recommended
|
|
1576
|
+
* address as the change destination, making it easier to complete transactions
|
|
1577
|
+
* without manually specifying a change address.
|
|
1578
|
+
*
|
|
1579
|
+
* @param from - The signer to complete inputs from and prepare the transaction.
|
|
1580
|
+
* @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
|
|
1581
|
+
* @param filter - Optional filter for selecting cells when adding inputs.
|
|
1582
|
+
* @param options - Optional configuration object.
|
|
1583
|
+
* @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
|
|
1584
|
+
* @param options.maxFeeRate - Maximum allowed fee rate.
|
|
1585
|
+
* @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
|
|
1586
|
+
* @returns A promise that resolves to a tuple containing:
|
|
1587
|
+
* - The number of inputs added during the process
|
|
1588
|
+
* - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
|
|
1589
|
+
*
|
|
1590
|
+
* @example
|
|
1591
|
+
* ```typescript
|
|
1592
|
+
* const [addedInputs, hasChange] = await tx.completeFeeBy(
|
|
1593
|
+
* signer,
|
|
1594
|
+
* 1000n // 1000 shannons per 1000 bytes
|
|
1595
|
+
* );
|
|
1596
|
+
*
|
|
1597
|
+
* // Change will automatically go to signer's recommended address
|
|
1598
|
+
* ```
|
|
1599
|
+
*/
|
|
1528
1600
|
async completeFeeBy(from, feeRate, filter, options) {
|
|
1529
1601
|
const { script } = await from.getRecommendedAddressObj();
|
|
1530
1602
|
return this.completeFeeChangeToLock(from, script, feeRate, filter, options);
|
|
1531
1603
|
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Completes the transaction fee by adding excess capacity to an existing output.
|
|
1606
|
+
* Instead of creating a new change output, this method adds any excess capacity
|
|
1607
|
+
* to the specified existing output in the transaction.
|
|
1608
|
+
*
|
|
1609
|
+
* @param from - The signer to complete inputs from and prepare the transaction.
|
|
1610
|
+
* @param index - The index of the existing output to add excess capacity to.
|
|
1611
|
+
* @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
|
|
1612
|
+
* @param filter - Optional filter for selecting cells when adding inputs.
|
|
1613
|
+
* @param options - Optional configuration object.
|
|
1614
|
+
* @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
|
|
1615
|
+
* @param options.maxFeeRate - Maximum allowed fee rate.
|
|
1616
|
+
* @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
|
|
1617
|
+
* @returns A promise that resolves to a tuple containing:
|
|
1618
|
+
* - The number of inputs added during the process
|
|
1619
|
+
* - A boolean indicating whether change was applied (true) or fee was paid without change (false)
|
|
1620
|
+
*
|
|
1621
|
+
* @throws {Error} When the specified output index doesn't exist.
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* ```typescript
|
|
1625
|
+
* // Add excess capacity to the first output (index 0)
|
|
1626
|
+
* const [addedInputs, hasChange] = await tx.completeFeeChangeToOutput(
|
|
1627
|
+
* signer,
|
|
1628
|
+
* 0, // Output index
|
|
1629
|
+
* 1000n // 1000 shannons per 1000 bytes
|
|
1630
|
+
* );
|
|
1631
|
+
* ```
|
|
1632
|
+
*/
|
|
1532
1633
|
completeFeeChangeToOutput(from, index, feeRate, filter, options) {
|
|
1533
1634
|
const change = Number(numFrom(index));
|
|
1534
1635
|
if (!this.outputs[change]) {
|
|
@@ -1557,7 +1658,26 @@ Transaction = Transaction_1 = __decorate([
|
|
|
1557
1658
|
], Transaction);
|
|
1558
1659
|
export { Transaction };
|
|
1559
1660
|
/**
|
|
1560
|
-
* Calculate Nervos DAO profit between two blocks
|
|
1661
|
+
* Calculate Nervos DAO profit between two blocks.
|
|
1662
|
+
* This function computes the profit earned from a Nervos DAO deposit
|
|
1663
|
+
* based on the capacity and the time period between deposit and withdrawal.
|
|
1664
|
+
*
|
|
1665
|
+
* @param profitableCapacity - The capacity that earns profit (total capacity minus occupied capacity).
|
|
1666
|
+
* @param depositHeaderLike - The block header when the DAO deposit was made.
|
|
1667
|
+
* @param withdrawHeaderLike - The block header when the DAO withdrawal is made.
|
|
1668
|
+
* @returns The profit amount in CKB (capacity units).
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```typescript
|
|
1672
|
+
* const profit = calcDaoProfit(
|
|
1673
|
+
* ccc.fixedPointFrom(100), // 100 CKB profitable capacity
|
|
1674
|
+
* depositHeader,
|
|
1675
|
+
* withdrawHeader
|
|
1676
|
+
* );
|
|
1677
|
+
* console.log(`Profit: ${profit} shannons`);
|
|
1678
|
+
* ```
|
|
1679
|
+
*
|
|
1680
|
+
* @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
|
|
1561
1681
|
*/
|
|
1562
1682
|
export function calcDaoProfit(profitableCapacity, depositHeaderLike, withdrawHeaderLike) {
|
|
1563
1683
|
const depositHeader = ClientBlockHeader.from(depositHeaderLike);
|
|
@@ -1567,8 +1687,26 @@ export function calcDaoProfit(profitableCapacity, depositHeaderLike, withdrawHea
|
|
|
1567
1687
|
profitableSize);
|
|
1568
1688
|
}
|
|
1569
1689
|
/**
|
|
1570
|
-
* Calculate claimable epoch for Nervos DAO withdrawal
|
|
1571
|
-
*
|
|
1690
|
+
* Calculate claimable epoch for Nervos DAO withdrawal.
|
|
1691
|
+
* This function determines the earliest epoch when a Nervos DAO withdrawal
|
|
1692
|
+
* can be claimed based on the deposit and withdrawal epochs.
|
|
1693
|
+
*
|
|
1694
|
+
* @param depositHeader - The block header when the DAO deposit was made.
|
|
1695
|
+
* @param withdrawHeader - The block header when the DAO withdrawal was initiated.
|
|
1696
|
+
* @returns The epoch when the withdrawal can be claimed, represented as [number, index, length].
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* ```typescript
|
|
1700
|
+
* const claimEpoch = calcDaoClaimEpoch(depositHeader, withdrawHeader);
|
|
1701
|
+
* console.log(`Can claim at epoch: ${claimEpoch[0]}, index: ${claimEpoch[1]}, length: ${claimEpoch[2]}`);
|
|
1702
|
+
* ```
|
|
1703
|
+
*
|
|
1704
|
+
* @remarks
|
|
1705
|
+
* The Nervos DAO has a minimum lock period of 180 epochs (~30 days).
|
|
1706
|
+
* This function calculates the exact epoch when the withdrawal becomes claimable
|
|
1707
|
+
* based on the deposit epoch and withdrawal epoch timing.
|
|
1708
|
+
*
|
|
1709
|
+
* @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
|
|
1572
1710
|
*/
|
|
1573
1711
|
export function calcDaoClaimEpoch(depositHeader, withdrawHeader) {
|
|
1574
1712
|
const depositEpoch = ClientBlockHeader.from(depositHeader).epoch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAwcxE,CAAC"}
|
|
@@ -102,10 +102,71 @@ export const MAINNET_SCRIPTS = Object.freeze({
|
|
|
102
102
|
{
|
|
103
103
|
cellDep: {
|
|
104
104
|
outPoint: {
|
|
105
|
-
txHash: "
|
|
105
|
+
txHash: "0xbdc3153fcb7c256d007be758c0b50c8da60b5ac0e44ae9e11d3dcc5b73d2b347",
|
|
106
106
|
index: 0,
|
|
107
107
|
},
|
|
108
|
-
depType: "
|
|
108
|
+
depType: "code",
|
|
109
|
+
},
|
|
110
|
+
type: {
|
|
111
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
112
|
+
hashType: "type",
|
|
113
|
+
args: "0xd00c84f0ec8fd441c38bc3f87a371f547190f2fcff88e642bc5bf54b9e318323",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
cellDep: {
|
|
118
|
+
outPoint: {
|
|
119
|
+
txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
|
|
120
|
+
index: 1,
|
|
121
|
+
},
|
|
122
|
+
depType: "code",
|
|
123
|
+
},
|
|
124
|
+
type: {
|
|
125
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
126
|
+
hashType: "type",
|
|
127
|
+
args: "0xaede124e8eca8ea4a0029d5f0999299a3f9a4090c6fd6f83d88c41707cc8aa75",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
cellDep: {
|
|
132
|
+
outPoint: {
|
|
133
|
+
txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
|
|
134
|
+
index: 2,
|
|
135
|
+
},
|
|
136
|
+
depType: "code",
|
|
137
|
+
},
|
|
138
|
+
type: {
|
|
139
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
140
|
+
hashType: "type",
|
|
141
|
+
args: "0x2409a9568c2ae67e73e12b1f0193c9a44c782ec1c73627b3c92ad2d0fb6128ed",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
cellDep: {
|
|
146
|
+
outPoint: {
|
|
147
|
+
txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
|
|
148
|
+
index: 3,
|
|
149
|
+
},
|
|
150
|
+
depType: "code",
|
|
151
|
+
},
|
|
152
|
+
type: {
|
|
153
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
154
|
+
hashType: "type",
|
|
155
|
+
args: "0xaf96ed62f5997c4a4814058545bc958124bada97fcd42955756e3c078da64523",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
cellDep: {
|
|
160
|
+
outPoint: {
|
|
161
|
+
txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
|
|
162
|
+
index: 4,
|
|
163
|
+
},
|
|
164
|
+
depType: "code",
|
|
165
|
+
},
|
|
166
|
+
type: {
|
|
167
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
168
|
+
hashType: "type",
|
|
169
|
+
args: "0xfa9f0c3599dc23b9489a11dfedb11489c7ad342982848495856966ed23a6bc7d",
|
|
109
170
|
},
|
|
110
171
|
},
|
|
111
172
|
],
|
|
@@ -338,64 +399,4 @@ export const MAINNET_SCRIPTS = Object.freeze({
|
|
|
338
399
|
},
|
|
339
400
|
],
|
|
340
401
|
},
|
|
341
|
-
[KnownScript.RgbppLock]: {
|
|
342
|
-
codeHash: "0xbc6c568a1a0d0a09f6844dc9d74ddb4343c32143ff25f727c59edf4fb72d6936",
|
|
343
|
-
hashType: "type",
|
|
344
|
-
cellDeps: [
|
|
345
|
-
{
|
|
346
|
-
cellDep: {
|
|
347
|
-
outPoint: {
|
|
348
|
-
txHash: "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
|
|
349
|
-
index: 0,
|
|
350
|
-
},
|
|
351
|
-
depType: "code",
|
|
352
|
-
},
|
|
353
|
-
type: {
|
|
354
|
-
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
355
|
-
hashType: "type",
|
|
356
|
-
args: "0x68ad3d9e0bb9ea841a5d1fcd600137bd3f45401e759e353121f26cd0d981452f",
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
// Rgbpp lock config cell dep
|
|
360
|
-
{
|
|
361
|
-
cellDep: {
|
|
362
|
-
outPoint: {
|
|
363
|
-
txHash: "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
|
|
364
|
-
index: 1,
|
|
365
|
-
},
|
|
366
|
-
depType: "code",
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
],
|
|
370
|
-
},
|
|
371
|
-
[KnownScript.BtcTimeLock]: {
|
|
372
|
-
codeHash: "0x70d64497a075bd651e98ac030455ea200637ee325a12ad08aff03f1a117e5a62",
|
|
373
|
-
hashType: "type",
|
|
374
|
-
cellDeps: [
|
|
375
|
-
{
|
|
376
|
-
cellDep: {
|
|
377
|
-
outPoint: {
|
|
378
|
-
txHash: "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
|
|
379
|
-
index: 0,
|
|
380
|
-
},
|
|
381
|
-
depType: "code",
|
|
382
|
-
},
|
|
383
|
-
type: {
|
|
384
|
-
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
385
|
-
hashType: "type",
|
|
386
|
-
args: "0x44b8253ae18e913a2845b0d548eaf6b3ba1099ed26835888932a754194028a8a",
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
// btc time lock config cell dep
|
|
390
|
-
{
|
|
391
|
-
cellDep: {
|
|
392
|
-
outPoint: {
|
|
393
|
-
txHash: "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
|
|
394
|
-
index: 1,
|
|
395
|
-
},
|
|
396
|
-
depType: "code",
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
],
|
|
400
|
-
},
|
|
401
402
|
});
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
import { ScriptInfoLike } from "./clientTypes.js";
|
|
2
2
|
import { KnownScript } from "./knownScript.js";
|
|
3
3
|
export declare const TESTNET_SCRIPTS: Record<KnownScript, ScriptInfoLike>;
|
|
4
|
-
/**
|
|
5
|
-
* Bitcoin Signet specific script overrides for testnet
|
|
6
|
-
*
|
|
7
|
-
* Contains script configurations that differ when using Bitcoin Signet
|
|
8
|
-
* instead of Bitcoin Testnet3. Only RgbppLock and BtcTimeLock are affected.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { ClientPublicTestnet } from "@ckb-ccc/core";
|
|
13
|
-
* import { TESTNET_SCRIPTS, TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES } from "@ckb-ccc/core/advanced";
|
|
14
|
-
*
|
|
15
|
-
* // Use Bitcoin Testnet3 scripts (default)
|
|
16
|
-
* const testnet3Client = new ClientPublicTestnet();
|
|
17
|
-
*
|
|
18
|
-
* // Use Bitcoin Signet scripts by merging overrides
|
|
19
|
-
* const signetClient = new ClientPublicTestnet({
|
|
20
|
-
* scripts: {
|
|
21
|
-
* ...TESTNET_SCRIPTS,
|
|
22
|
-
* ...TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES
|
|
23
|
-
* }
|
|
24
|
-
* });
|
|
25
|
-
*/
|
|
26
|
-
export declare const TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES: Partial<Record<KnownScript, ScriptInfoLike>>;
|
|
27
4
|
//# sourceMappingURL=clientPublicTestnet.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientPublicTestnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"clientPublicTestnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAod5D,CAAC"}
|