@ckb-ccc/core 1.9.0 → 1.10.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 +25 -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/script.d.ts +12 -0
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +17 -0
- package/dist/ckb/transaction.d.ts +147 -14
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +165 -28
- package/dist/ckb/transactionErrors.d.ts +15 -0
- package/dist/ckb/transactionErrors.d.ts.map +1 -0
- package/dist/ckb/transactionErrors.js +21 -0
- package/dist/client/cache/cache.d.ts +7 -0
- package/dist/client/cache/cache.d.ts.map +1 -1
- package/dist/client/cache/cache.js +11 -0
- package/dist/client/cache/memory.advanced.d.ts +36 -3
- package/dist/client/cache/memory.advanced.d.ts.map +1 -1
- package/dist/client/cache/memory.advanced.js +53 -25
- package/dist/client/cache/memory.d.ts +10 -1
- package/dist/client/cache/memory.d.ts.map +1 -1
- package/dist/client/cache/memory.js +13 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +6 -9
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +60 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts +23 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +145 -1
- package/dist/client/clientTypes.advanced.d.ts +0 -1
- package/dist/client/clientTypes.advanced.d.ts.map +1 -1
- package/dist/client/clientTypes.advanced.js +0 -1
- package/dist/client/knownScript.d.ts +3 -1
- package/dist/client/knownScript.d.ts.map +1 -1
- package/dist/client/knownScript.js +4 -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/script.d.ts +12 -0
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.js +17 -0
- package/dist.commonjs/ckb/transaction.d.ts +147 -14
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +164 -27
- package/dist.commonjs/ckb/transactionErrors.d.ts +15 -0
- package/dist.commonjs/ckb/transactionErrors.d.ts.map +1 -0
- package/dist.commonjs/ckb/transactionErrors.js +26 -0
- package/dist.commonjs/client/cache/cache.d.ts +7 -0
- package/dist.commonjs/client/cache/cache.d.ts.map +1 -1
- package/dist.commonjs/client/cache/cache.js +11 -0
- package/dist.commonjs/client/cache/memory.advanced.d.ts +36 -3
- package/dist.commonjs/client/cache/memory.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/cache/memory.advanced.js +54 -26
- package/dist.commonjs/client/cache/memory.d.ts +10 -1
- package/dist.commonjs/client/cache/memory.d.ts.map +1 -1
- package/dist.commonjs/client/cache/memory.js +12 -1
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +5 -8
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +60 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +23 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +146 -2
- package/dist.commonjs/client/clientTypes.advanced.d.ts +0 -1
- package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.advanced.js +1 -2
- package/dist.commonjs/client/knownScript.d.ts +3 -1
- package/dist.commonjs/client/knownScript.d.ts.map +1 -1
- package/dist.commonjs/client/knownScript.js +4 -0
- package/package.json +1 -1
- package/src/ckb/index.ts +1 -0
- package/src/ckb/script.ts +20 -0
- package/src/ckb/transaction.ts +210 -33
- package/src/ckb/transactionErrors.ts +36 -0
- package/src/client/cache/cache.ts +14 -1
- package/src/client/cache/memory.advanced.ts +57 -30
- package/src/client/cache/memory.ts +18 -1
- package/src/client/client.ts +5 -10
- package/src/client/clientPublicMainnet.advanced.ts +68 -0
- package/src/client/clientPublicTestnet.advanced.ts +164 -1
- package/src/client/clientTypes.advanced.ts +0 -1
- package/src/client/knownScript.ts +5 -0
|
@@ -28,6 +28,7 @@ const index_js_7 = require("../num/index.js");
|
|
|
28
28
|
const index_js_8 = require("../utils/index.js");
|
|
29
29
|
const script_js_1 = require("./script.js");
|
|
30
30
|
const transaction_advanced_js_1 = require("./transaction.advanced.js");
|
|
31
|
+
const transactionErrors_js_1 = require("./transactionErrors.js");
|
|
31
32
|
exports.DepTypeCodec = index_js_6.mol.Codec.from({
|
|
32
33
|
byteLength: 1,
|
|
33
34
|
encode: depTypeToBytes,
|
|
@@ -127,6 +128,34 @@ let OutPoint = OutPoint_1 = class OutPoint extends index_js_6.mol.Entity.Base()
|
|
|
127
128
|
}
|
|
128
129
|
return new OutPoint_1((0, index_js_5.hexFrom)(outPoint.txHash), (0, index_js_7.numFrom)(outPoint.index));
|
|
129
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Clone a OutPoint.
|
|
133
|
+
*
|
|
134
|
+
* @returns A cloned OutPoint instance.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const outPoint1 = outPoint0.clone();
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
clone() {
|
|
142
|
+
return new OutPoint_1(this.txHash, this.index);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if the OutPoint is equal to another OutPoint.
|
|
146
|
+
* @public
|
|
147
|
+
* @param other - The other OutPoint to compare with
|
|
148
|
+
* @returns True if the OutPoints are equal, false otherwise
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const isEqual = outPoint0.eq(outPoint1);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
eq(other) {
|
|
156
|
+
other = OutPoint_1.from(other);
|
|
157
|
+
return this.txHash === other.txHash && this.index === other.index;
|
|
158
|
+
}
|
|
130
159
|
};
|
|
131
160
|
exports.OutPoint = OutPoint;
|
|
132
161
|
exports.OutPoint = OutPoint = OutPoint_1 = __decorate([
|
|
@@ -176,6 +205,19 @@ let CellOutput = CellOutput_1 = class CellOutput extends index_js_6.mol.Entity.B
|
|
|
176
205
|
}
|
|
177
206
|
return new CellOutput_1((0, index_js_7.numFrom)(cellOutput.capacity), script_js_1.Script.from(cellOutput.lock), (0, index_js_8.apply)(script_js_1.Script.from, cellOutput.type));
|
|
178
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Clone a CellOutput.
|
|
210
|
+
*
|
|
211
|
+
* @returns A cloned CellOutput instance.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const cellOutput1 = cellOutput0.clone();
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
clone() {
|
|
219
|
+
return new CellOutput_1(this.capacity, this.lock.clone(), this.type?.clone());
|
|
220
|
+
}
|
|
179
221
|
};
|
|
180
222
|
exports.CellOutput = CellOutput;
|
|
181
223
|
exports.CellOutput = CellOutput = CellOutput_1 = __decorate([
|
|
@@ -506,11 +548,18 @@ let CellInput = CellInput_1 = class CellInput extends index_js_6.mol.Entity.Base
|
|
|
506
548
|
async getExtraCapacity(client) {
|
|
507
549
|
return (await this.getCell(client)).getDaoProfit(client);
|
|
508
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Clone a CellInput.
|
|
553
|
+
*
|
|
554
|
+
* @returns A cloned CellInput instance.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```typescript
|
|
558
|
+
* const cellInput1 = cellInput0.clone();
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
509
561
|
clone() {
|
|
510
|
-
|
|
511
|
-
cloned.cellOutput = this.cellOutput;
|
|
512
|
-
cloned.outputData = this.outputData;
|
|
513
|
-
return cloned;
|
|
562
|
+
return new CellInput_1(this.previousOutput.clone(), this.since, this.cellOutput?.clone(), this.outputData);
|
|
514
563
|
}
|
|
515
564
|
};
|
|
516
565
|
exports.CellInput = CellInput;
|
|
@@ -538,19 +587,6 @@ let CellDep = CellDep_1 = class CellDep extends index_js_6.mol.Entity.Base() {
|
|
|
538
587
|
this.outPoint = outPoint;
|
|
539
588
|
this.depType = depType;
|
|
540
589
|
}
|
|
541
|
-
/**
|
|
542
|
-
* Clone a CellDep.
|
|
543
|
-
*
|
|
544
|
-
* @returns A cloned CellDep instance.
|
|
545
|
-
*
|
|
546
|
-
* @example
|
|
547
|
-
* ```typescript
|
|
548
|
-
* const cellDep1 = cellDep0.clone();
|
|
549
|
-
* ```
|
|
550
|
-
*/
|
|
551
|
-
clone() {
|
|
552
|
-
return new CellDep_1(this.outPoint.clone(), this.depType);
|
|
553
|
-
}
|
|
554
590
|
/**
|
|
555
591
|
* Creates a CellDep instance from a CellDepLike object.
|
|
556
592
|
*
|
|
@@ -571,6 +607,19 @@ let CellDep = CellDep_1 = class CellDep extends index_js_6.mol.Entity.Base() {
|
|
|
571
607
|
}
|
|
572
608
|
return new CellDep_1(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
573
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Clone a CellDep.
|
|
612
|
+
*
|
|
613
|
+
* @returns A cloned CellDep instance.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* const cellDep1 = cellDep0.clone();
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
clone() {
|
|
621
|
+
return new CellDep_1(this.outPoint.clone(), this.depType);
|
|
622
|
+
}
|
|
574
623
|
};
|
|
575
624
|
exports.CellDep = CellDep;
|
|
576
625
|
exports.CellDep = CellDep = CellDep_1 = __decorate([
|
|
@@ -700,6 +749,46 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
700
749
|
this.outputsData = tx.outputsData;
|
|
701
750
|
this.witnesses = tx.witnesses;
|
|
702
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* Creates a deep copy of the transaction.
|
|
754
|
+
* This method creates a new Transaction instance with all nested objects cloned,
|
|
755
|
+
* ensuring that modifications to the cloned transaction do not affect the original.
|
|
756
|
+
*
|
|
757
|
+
* @returns A new Transaction instance that is a deep copy of the current transaction.
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* ```typescript
|
|
761
|
+
* const originalTx = Transaction.from({
|
|
762
|
+
* version: 0,
|
|
763
|
+
* inputs: [{ previousOutput: { txHash: "0x...", index: 0 } }],
|
|
764
|
+
* outputs: [{ capacity: 1000n, lock: lockScript }],
|
|
765
|
+
* outputsData: ["0x"],
|
|
766
|
+
* witnesses: ["0x"]
|
|
767
|
+
* });
|
|
768
|
+
*
|
|
769
|
+
* const clonedTx = originalTx.clone();
|
|
770
|
+
*
|
|
771
|
+
* // Modifications to clonedTx won't affect originalTx
|
|
772
|
+
* clonedTx.addOutput({ capacity: 2000n, lock: anotherLockScript });
|
|
773
|
+
* console.log(originalTx.outputs.length); // Still 1
|
|
774
|
+
* console.log(clonedTx.outputs.length); // Now 2
|
|
775
|
+
* ```
|
|
776
|
+
*
|
|
777
|
+
* @remarks
|
|
778
|
+
* The clone operation performs deep copying for:
|
|
779
|
+
* - Cell dependencies (cellDeps) - each CellDep is cloned
|
|
780
|
+
* - Inputs - each CellInput is cloned
|
|
781
|
+
* - Outputs - each CellOutput is cloned
|
|
782
|
+
*
|
|
783
|
+
* The following are shallow copied (references to immutable data):
|
|
784
|
+
* - Header dependencies (headerDeps) - Hex strings are immutable
|
|
785
|
+
* - Output data (outputsData) - Hex strings are immutable
|
|
786
|
+
* - Witnesses - Hex strings are immutable
|
|
787
|
+
* - Version - bigint is immutable
|
|
788
|
+
*/
|
|
789
|
+
clone() {
|
|
790
|
+
return new Transaction_1(this.version, this.cellDeps.map((c) => c.clone()), this.headerDeps.map((h) => h), this.inputs.map((i) => i.clone()), this.outputs.map((o) => o.clone()), this.outputsData.map((o) => o), this.witnesses.map((w) => w));
|
|
791
|
+
}
|
|
703
792
|
/**
|
|
704
793
|
* Creates a Transaction instance from a TransactionLike object.
|
|
705
794
|
*
|
|
@@ -1253,7 +1342,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1253
1342
|
if (accumulated === undefined) {
|
|
1254
1343
|
return addedCount;
|
|
1255
1344
|
}
|
|
1256
|
-
throw new
|
|
1345
|
+
throw new transactionErrors_js_1.ErrorTransactionInsufficientCapacity(expectedCapacity - accumulated);
|
|
1257
1346
|
}
|
|
1258
1347
|
async completeInputsAll(from, filter) {
|
|
1259
1348
|
const { addedCount } = await this.completeInputs(from, filter ?? {
|
|
@@ -1303,7 +1392,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1303
1392
|
if (accumulated === undefined || accumulated >= expectedBalance) {
|
|
1304
1393
|
return addedCount;
|
|
1305
1394
|
}
|
|
1306
|
-
throw new
|
|
1395
|
+
throw new transactionErrors_js_1.ErrorTransactionInsufficientCoin(expectedBalance - accumulated, type);
|
|
1307
1396
|
}
|
|
1308
1397
|
async completeInputsAddOne(from, filter) {
|
|
1309
1398
|
const { addedCount, accumulated } = await this.completeInputs(from, filter ?? {
|
|
@@ -1333,6 +1422,44 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1333
1422
|
// + 999 then / 1000 to ceil the calculated fee
|
|
1334
1423
|
return ((0, index_js_7.numFrom)(txSize) * (0, index_js_7.numFrom)(feeRate) + (0, index_js_7.numFrom)(999)) / (0, index_js_7.numFrom)(1000);
|
|
1335
1424
|
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Completes the transaction fee by adding inputs and handling change outputs.
|
|
1427
|
+
* This method automatically calculates the required fee based on the transaction size and fee rate,
|
|
1428
|
+
* adds necessary inputs to cover the fee, and handles change outputs through the provided change function.
|
|
1429
|
+
*
|
|
1430
|
+
* @param from - The signer to complete inputs from and prepare the transaction.
|
|
1431
|
+
* @param change - A function that handles change capacity. It receives the transaction and excess capacity,
|
|
1432
|
+
* and should return the additional capacity needed (0 if change is handled successfully,
|
|
1433
|
+
* positive number if more capacity is needed for change cell creation).
|
|
1434
|
+
* @param expectedFeeRate - The expected fee rate in shannons per 1000 bytes. If not provided,
|
|
1435
|
+
* it will be fetched from the client.
|
|
1436
|
+
* @param filter - Optional filter for selecting cells when adding inputs.
|
|
1437
|
+
* @param options - Optional configuration object.
|
|
1438
|
+
* @param options.feeRateBlockRange - Block range for fee rate calculation when expectedFeeRate is not provided.
|
|
1439
|
+
* @param options.maxFeeRate - Maximum allowed fee rate.
|
|
1440
|
+
* @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
|
|
1441
|
+
* @returns A promise that resolves to a tuple containing:
|
|
1442
|
+
* - The number of inputs added during the process
|
|
1443
|
+
* - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
|
|
1444
|
+
*
|
|
1445
|
+
* @throws {ErrorTransactionInsufficientCapacity} When there's not enough capacity to cover the fee.
|
|
1446
|
+
* @throws {Error} When the change function doesn't properly handle the available capacity.
|
|
1447
|
+
*
|
|
1448
|
+
* @example
|
|
1449
|
+
* ```typescript
|
|
1450
|
+
* const [addedInputs, hasChange] = await tx.completeFee(
|
|
1451
|
+
* signer,
|
|
1452
|
+
* (tx, capacity) => {
|
|
1453
|
+
* if (capacity >= 61_00000000n) { // Minimum for a change cell
|
|
1454
|
+
* tx.addOutput({ capacity, lock: changeScript });
|
|
1455
|
+
* return 0;
|
|
1456
|
+
* }
|
|
1457
|
+
* return 61_00000000n; // Need more capacity for change cell
|
|
1458
|
+
* },
|
|
1459
|
+
* 1000n // 1000 shannons per 1000 bytes
|
|
1460
|
+
* );
|
|
1461
|
+
* ```
|
|
1462
|
+
*/
|
|
1336
1463
|
async completeFee(from, change, expectedFeeRate, filter, options) {
|
|
1337
1464
|
const feeRate = expectedFeeRate ??
|
|
1338
1465
|
(await from.client.getFeeRate(options?.feeRateBlockRange, options));
|
|
@@ -1343,12 +1470,22 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1343
1470
|
while (true) {
|
|
1344
1471
|
const tx = this.clone();
|
|
1345
1472
|
const collected = await (async () => {
|
|
1473
|
+
if (!(options?.shouldAddInputs ?? true)) {
|
|
1474
|
+
const fee = (await tx.getFee(from.client)) - leastFee - leastExtraCapacity;
|
|
1475
|
+
if (fee < index_js_3.Zero) {
|
|
1476
|
+
throw new transactionErrors_js_1.ErrorTransactionInsufficientCapacity(-fee);
|
|
1477
|
+
}
|
|
1478
|
+
return 0;
|
|
1479
|
+
}
|
|
1346
1480
|
try {
|
|
1347
1481
|
return await tx.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
|
|
1348
1482
|
}
|
|
1349
1483
|
catch (err) {
|
|
1350
|
-
if (
|
|
1351
|
-
|
|
1484
|
+
if (err instanceof transactionErrors_js_1.ErrorTransactionInsufficientCapacity &&
|
|
1485
|
+
leastExtraCapacity !== index_js_3.Zero) {
|
|
1486
|
+
throw new transactionErrors_js_1.ErrorTransactionInsufficientCapacity(err.amount, {
|
|
1487
|
+
isForChange: true,
|
|
1488
|
+
});
|
|
1352
1489
|
}
|
|
1353
1490
|
throw err;
|
|
1354
1491
|
}
|
|
@@ -1388,7 +1525,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1388
1525
|
leastFee = changedFee;
|
|
1389
1526
|
}
|
|
1390
1527
|
}
|
|
1391
|
-
completeFeeChangeToLock(from, change, feeRate, filter) {
|
|
1528
|
+
completeFeeChangeToLock(from, change, feeRate, filter, options) {
|
|
1392
1529
|
const script = script_js_1.Script.from(change);
|
|
1393
1530
|
return this.completeFee(from, (tx, capacity) => {
|
|
1394
1531
|
const changeCell = CellOutput.from({ capacity: 0, lock: script });
|
|
@@ -1399,13 +1536,13 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1399
1536
|
changeCell.capacity = capacity;
|
|
1400
1537
|
tx.addOutput(changeCell);
|
|
1401
1538
|
return 0;
|
|
1402
|
-
}, feeRate, filter);
|
|
1539
|
+
}, feeRate, filter, options);
|
|
1403
1540
|
}
|
|
1404
|
-
async completeFeeBy(from, feeRate, filter) {
|
|
1541
|
+
async completeFeeBy(from, feeRate, filter, options) {
|
|
1405
1542
|
const { script } = await from.getRecommendedAddressObj();
|
|
1406
|
-
return this.completeFeeChangeToLock(from, script, feeRate, filter);
|
|
1543
|
+
return this.completeFeeChangeToLock(from, script, feeRate, filter, options);
|
|
1407
1544
|
}
|
|
1408
|
-
completeFeeChangeToOutput(from, index, feeRate, filter) {
|
|
1545
|
+
completeFeeChangeToOutput(from, index, feeRate, filter, options) {
|
|
1409
1546
|
const change = Number((0, index_js_7.numFrom)(index));
|
|
1410
1547
|
if (!this.outputs[change]) {
|
|
1411
1548
|
throw new Error("Non-existed output to change");
|
|
@@ -1413,7 +1550,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
|
|
|
1413
1550
|
return this.completeFee(from, (tx, capacity) => {
|
|
1414
1551
|
tx.outputs[change].capacity += capacity;
|
|
1415
1552
|
return 0;
|
|
1416
|
-
}, feeRate, filter);
|
|
1553
|
+
}, feeRate, filter, options);
|
|
1417
1554
|
}
|
|
1418
1555
|
};
|
|
1419
1556
|
exports.Transaction = Transaction;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Num, NumLike } from "../num/index.js";
|
|
2
|
+
import { Script, ScriptLike } from "./script.js";
|
|
3
|
+
export declare class ErrorTransactionInsufficientCapacity extends Error {
|
|
4
|
+
readonly amount: Num;
|
|
5
|
+
readonly isForChange: boolean;
|
|
6
|
+
constructor(amountLike: NumLike, reason?: {
|
|
7
|
+
isForChange?: boolean;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export declare class ErrorTransactionInsufficientCoin extends Error {
|
|
11
|
+
readonly amount: Num;
|
|
12
|
+
readonly type: Script;
|
|
13
|
+
constructor(amountLike: NumLike, typeLike: ScriptLike);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=transactionErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionErrors.d.ts","sourceRoot":"","sources":["../../src/ckb/transactionErrors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAW,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjD,qBAAa,oCAAqC,SAAQ,KAAK;IAC7D,SAAgB,MAAM,EAAE,GAAG,CAAC;IAC5B,SAAgB,WAAW,EAAE,OAAO,CAAC;gBAGnC,UAAU,EAAE,OAAO,EACnB,MAAM,CAAC,EAAE;QACP,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB;CAUJ;AAED,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,SAAgB,MAAM,EAAE,GAAG,CAAC;IAC5B,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU;CAOtD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorTransactionInsufficientCoin = exports.ErrorTransactionInsufficientCapacity = void 0;
|
|
4
|
+
const index_js_1 = require("../fixedPoint/index.js");
|
|
5
|
+
const index_js_2 = require("../num/index.js");
|
|
6
|
+
const script_js_1 = require("./script.js");
|
|
7
|
+
class ErrorTransactionInsufficientCapacity extends Error {
|
|
8
|
+
constructor(amountLike, reason) {
|
|
9
|
+
const amount = (0, index_js_2.numFrom)(amountLike);
|
|
10
|
+
const isForChange = reason?.isForChange ?? false;
|
|
11
|
+
super(`Insufficient CKB, need ${(0, index_js_1.fixedPointToString)(amount)} extra CKB${isForChange ? " for the change cell" : ""}`);
|
|
12
|
+
this.amount = amount;
|
|
13
|
+
this.isForChange = isForChange;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ErrorTransactionInsufficientCapacity = ErrorTransactionInsufficientCapacity;
|
|
17
|
+
class ErrorTransactionInsufficientCoin extends Error {
|
|
18
|
+
constructor(amountLike, typeLike) {
|
|
19
|
+
const amount = (0, index_js_2.numFrom)(amountLike);
|
|
20
|
+
const type = script_js_1.Script.from(typeLike);
|
|
21
|
+
super(`Insufficient coin, need ${amount} extra coin`);
|
|
22
|
+
this.amount = amount;
|
|
23
|
+
this.type = type;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ErrorTransactionInsufficientCoin = ErrorTransactionInsufficientCoin;
|
|
@@ -87,5 +87,12 @@ export declare abstract class ClientCache {
|
|
|
87
87
|
* @param _number
|
|
88
88
|
*/
|
|
89
89
|
getBlockByNumber(_number: NumLike): Promise<ClientBlock | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a block header is considered confirmed.
|
|
92
|
+
* The default implementation compares the header's timestamp against the current time
|
|
93
|
+
* and a configured confirmation time. Override this method for custom confirmation logic.
|
|
94
|
+
* @param header
|
|
95
|
+
*/
|
|
96
|
+
hasHeaderConfirmed(header: ClientBlockHeader): boolean;
|
|
90
97
|
}
|
|
91
98
|
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/client/cache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,oBA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O,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAI1E;;;;;OAKG;IACH,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAKvD"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientCache = void 0;
|
|
4
4
|
const index_js_1 = require("../../ckb/index.js");
|
|
5
|
+
const index_js_2 = require("../../num/index.js");
|
|
6
|
+
const memory_advanced_js_1 = require("./memory.advanced.js");
|
|
5
7
|
/**
|
|
6
8
|
* @public
|
|
7
9
|
* The ClientCache class is mainly designed for chained transactions.
|
|
@@ -128,5 +130,14 @@ class ClientCache {
|
|
|
128
130
|
async getBlockByNumber(_number) {
|
|
129
131
|
return;
|
|
130
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Checks if a block header is considered confirmed.
|
|
135
|
+
* The default implementation compares the header's timestamp against the current time
|
|
136
|
+
* and a configured confirmation time. Override this method for custom confirmation logic.
|
|
137
|
+
* @param header
|
|
138
|
+
*/
|
|
139
|
+
hasHeaderConfirmed(header) {
|
|
140
|
+
return ((0, index_js_2.numFrom)(Date.now()) - header.timestamp >= memory_advanced_js_1.DEFAULT_CONFIRMED_BLOCK_TIME);
|
|
141
|
+
}
|
|
131
142
|
}
|
|
132
143
|
exports.ClientCache = ClientCache;
|
|
@@ -2,6 +2,7 @@ import { Cell, CellLike, ScriptLike } from "../../ckb/index.js";
|
|
|
2
2
|
import { HexLike } from "../../hex/index.js";
|
|
3
3
|
import { NumLike } from "../../num/index.js";
|
|
4
4
|
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
5
|
+
export declare const DEFAULT_CONFIRMED_BLOCK_TIME: bigint;
|
|
5
6
|
export type CellRecord = [
|
|
6
7
|
false,
|
|
7
8
|
Pick<Cell, "outPoint"> & Partial<Pick<Cell, "cellOutput" | "outputData">>
|
|
@@ -11,12 +12,44 @@ export declare function filterScript(valueLike: ScriptLike | undefined, filterLi
|
|
|
11
12
|
export declare function filterNumByRange(lengthLike: NumLike, range: [NumLike, NumLike] | undefined): boolean;
|
|
12
13
|
export declare function filterScriptByLenRange(valueLike?: ScriptLike, scriptLenRange?: [NumLike, NumLike]): boolean;
|
|
13
14
|
export declare function filterCell(searchKeyLike: ClientCollectableSearchKeyLike, cellLike: CellLike): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* A Least Recently Used (LRU) cache implemented using a Map.
|
|
17
|
+
*
|
|
18
|
+
* This class extends the built-in Map to provide an LRU cache with a fixed capacity.
|
|
19
|
+
* When the cache is full, the least recently used entry is automatically evicted.
|
|
20
|
+
*
|
|
21
|
+
* @template K The type of the keys in the cache.
|
|
22
|
+
* @template V The type of the values in the cache.
|
|
23
|
+
*/
|
|
14
24
|
export declare class MapLru<K, V> extends Map<K, V> {
|
|
15
25
|
private readonly capacity;
|
|
16
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a new MapLru instance.
|
|
28
|
+
*
|
|
29
|
+
* @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
|
|
30
|
+
* @throws {Error} If the capacity is not a positive integer.
|
|
31
|
+
*/
|
|
17
32
|
constructor(capacity: number);
|
|
18
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves a value from the cache.
|
|
35
|
+
*
|
|
36
|
+
* If the key is present in the cache, the value is moved to the most-recently-used position.
|
|
37
|
+
*
|
|
38
|
+
* @param key The key of the value to retrieve.
|
|
39
|
+
* @returns The value associated with the key, or undefined if the key is not present.
|
|
40
|
+
*/
|
|
41
|
+
get(key: K): V | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Inserts a new value into the cache, or updates an existing value.
|
|
44
|
+
*
|
|
45
|
+
* If the key is already present in the cache, it is first deleted so that the re-insertion
|
|
46
|
+
* moves it to the most-recently-used position.
|
|
47
|
+
* If the cache is over capacity after the insertion, the least recently used entry is evicted.
|
|
48
|
+
*
|
|
49
|
+
* @param key The key of the value to insert or update.
|
|
50
|
+
* @param value The value to associate with the key.
|
|
51
|
+
* @returns This MapLru instance.
|
|
52
|
+
*/
|
|
19
53
|
set(key: K, value: V): this;
|
|
20
|
-
delete(key: K): boolean;
|
|
21
54
|
}
|
|
22
55
|
//# sourceMappingURL=memory.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAU,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,8BAA8B,EAE/B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"memory.advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAU,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,8BAA8B,EAE/B,MAAM,4BAA4B,CAAC;AAGpC,eAAO,MAAM,4BAA4B,QAA0B,CAAC;AAGpE,MAAM,MAAM,UAAU,GAClB;IACE,KAAK;IACL,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC;CAC1E,GACD,CAAC,IAAI,EAAE,IAAI,CAAC,GACZ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAEtB,wBAAgB,UAAU,CACxB,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,OAAO,GAAG,SAAS,EAC/B,UAAU,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GACzC,OAAO,CAgBT;AAED,wBAAgB,YAAY,CAC1B,SAAS,EAAE,UAAU,GAAG,SAAS,EACjC,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,GACzC,OAAO,CAkBT;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,OAAO,EACnB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,GACpC,OAAO,CAQT;AAED,wBAAgB,sBAAsB,CACpC,SAAS,CAAC,EAAE,UAAU,EACtB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAClC,OAAO,CAYT;AAED,wBAAgB,UAAU,CACxB,aAAa,EAAE,8BAA8B,EAC7C,QAAQ,EAAE,QAAQ,GACjB,OAAO,CA4CT;AAED;;;;;;;;GAQG;AACH,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAO7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IANrC;;;;;OAKG;gBAC0B,QAAQ,EAAE,MAAM;IAO7C;;;;;;;OAOG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAenC;;;;;;;;;;OAUG;IACM,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;CAarC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MapLru = void 0;
|
|
3
|
+
exports.MapLru = exports.DEFAULT_CONFIRMED_BLOCK_TIME = void 0;
|
|
4
4
|
exports.filterData = filterData;
|
|
5
5
|
exports.filterScript = filterScript;
|
|
6
6
|
exports.filterNumByRange = filterNumByRange;
|
|
@@ -12,6 +12,7 @@ const index_js_3 = require("../../hex/index.js");
|
|
|
12
12
|
const index_js_4 = require("../../num/index.js");
|
|
13
13
|
const clientTypes_advanced_js_1 = require("../clientTypes.advanced.js");
|
|
14
14
|
const clientTypes_js_1 = require("../clientTypes.js");
|
|
15
|
+
exports.DEFAULT_CONFIRMED_BLOCK_TIME = (0, index_js_4.numFrom)(1000 * 10 * 50); // 50 blocks * 10s
|
|
15
16
|
function filterData(dataLike, filterLike, filterMode) {
|
|
16
17
|
if (!filterLike) {
|
|
17
18
|
return true;
|
|
@@ -86,42 +87,69 @@ function filterCell(searchKeyLike, cellLike) {
|
|
|
86
87
|
}
|
|
87
88
|
return true;
|
|
88
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* A Least Recently Used (LRU) cache implemented using a Map.
|
|
92
|
+
*
|
|
93
|
+
* This class extends the built-in Map to provide an LRU cache with a fixed capacity.
|
|
94
|
+
* When the cache is full, the least recently used entry is automatically evicted.
|
|
95
|
+
*
|
|
96
|
+
* @template K The type of the keys in the cache.
|
|
97
|
+
* @template V The type of the values in the cache.
|
|
98
|
+
*/
|
|
89
99
|
class MapLru extends Map {
|
|
100
|
+
/**
|
|
101
|
+
* Constructs a new MapLru instance.
|
|
102
|
+
*
|
|
103
|
+
* @param capacity The maximum number of entries the cache can hold. Must be a positive integer.
|
|
104
|
+
* @throws {Error} If the capacity is not a positive integer.
|
|
105
|
+
*/
|
|
90
106
|
constructor(capacity) {
|
|
91
107
|
super();
|
|
92
108
|
this.capacity = capacity;
|
|
93
|
-
|
|
109
|
+
if (!Number.isInteger(capacity) || capacity < 1) {
|
|
110
|
+
throw new Error("Capacity must be a positive integer");
|
|
111
|
+
}
|
|
94
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves a value from the cache.
|
|
115
|
+
*
|
|
116
|
+
* If the key is present in the cache, the value is moved to the most-recently-used position.
|
|
117
|
+
*
|
|
118
|
+
* @param key The key of the value to retrieve.
|
|
119
|
+
* @returns The value associated with the key, or undefined if the key is not present.
|
|
120
|
+
*/
|
|
95
121
|
get(key) {
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const index = this.lru.indexOf(key);
|
|
101
|
-
if (index !== -1) {
|
|
102
|
-
this.lru.splice(index, 1);
|
|
103
|
-
}
|
|
104
|
-
this.lru.push(key);
|
|
105
|
-
if (this.lru.length > this.capacity) {
|
|
106
|
-
this.delete(this.lru[0]);
|
|
107
|
-
this.lru.shift();
|
|
122
|
+
// Check if the key exists. If not, return undefined.
|
|
123
|
+
if (!super.has(key)) {
|
|
124
|
+
return undefined;
|
|
108
125
|
}
|
|
109
|
-
|
|
126
|
+
const value = super.get(key);
|
|
127
|
+
// Move to most-recently-used position
|
|
128
|
+
super.delete(key);
|
|
129
|
+
super.set(key, value);
|
|
130
|
+
return value;
|
|
110
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Inserts a new value into the cache, or updates an existing value.
|
|
134
|
+
*
|
|
135
|
+
* If the key is already present in the cache, it is first deleted so that the re-insertion
|
|
136
|
+
* moves it to the most-recently-used position.
|
|
137
|
+
* If the cache is over capacity after the insertion, the least recently used entry is evicted.
|
|
138
|
+
*
|
|
139
|
+
* @param key The key of the value to insert or update.
|
|
140
|
+
* @param value The value to associate with the key.
|
|
141
|
+
* @returns This MapLru instance.
|
|
142
|
+
*/
|
|
111
143
|
set(key, value) {
|
|
112
|
-
|
|
144
|
+
// Delete and re-insert to move key to the end (most-recently-used)
|
|
145
|
+
super.delete(key);
|
|
113
146
|
super.set(key, value);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
const index = this.lru.indexOf(key);
|
|
121
|
-
if (index !== -1) {
|
|
122
|
-
this.lru.splice(index, 1);
|
|
147
|
+
// Evict oldest if over capacity
|
|
148
|
+
if (super.size > this.capacity) {
|
|
149
|
+
const oldestKey = super.keys().next().value;
|
|
150
|
+
super.delete(oldestKey);
|
|
123
151
|
}
|
|
124
|
-
return
|
|
152
|
+
return this;
|
|
125
153
|
}
|
|
126
154
|
}
|
|
127
155
|
exports.MapLru = MapLru;
|
|
@@ -8,6 +8,7 @@ export declare class ClientCacheMemory extends ClientCache {
|
|
|
8
8
|
private readonly maxCells;
|
|
9
9
|
private readonly maxTxs;
|
|
10
10
|
private readonly maxBlocks;
|
|
11
|
+
private readonly confirmedBlockTime;
|
|
11
12
|
/**
|
|
12
13
|
* OutPoint => [isLive, Cell | OutPoint]
|
|
13
14
|
*/
|
|
@@ -24,7 +25,14 @@ export declare class ClientCacheMemory extends ClientCache {
|
|
|
24
25
|
* Block Hash => Block Header / Full Block
|
|
25
26
|
*/
|
|
26
27
|
private readonly knownBlocks;
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
|
|
30
|
+
* @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
|
|
31
|
+
* @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
|
|
32
|
+
* @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
|
|
33
|
+
* Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
|
|
34
|
+
*/
|
|
35
|
+
constructor(maxCells?: number, maxTxs?: number, maxBlocks?: number, confirmedBlockTime?: bigint);
|
|
28
36
|
markUsableNoCache(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
29
37
|
markUnusable(...outPointLikes: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
30
38
|
clear(): Promise<void>;
|
|
@@ -40,5 +48,6 @@ export declare class ClientCacheMemory extends ClientCache {
|
|
|
40
48
|
recordBlocks(...blocks: (ClientBlockLike | ClientBlockLike[])[]): Promise<void>;
|
|
41
49
|
getBlockByHash(hashLike: HexLike): Promise<ClientBlock | undefined>;
|
|
42
50
|
getBlockByNumber(numberLike: NumLike): Promise<ClientBlock | undefined>;
|
|
51
|
+
hasHeaderConfirmed(header: ClientBlockHeader): boolean;
|
|
43
52
|
}
|
|
44
53
|
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAY,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAW,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAgB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAY,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAW,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAgB,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EACzB,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQzC,qBAAa,iBAAkB,SAAQ,WAAW;IAgC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;I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AE,CAAC,EAAE,GAC9D,OAAO,CAAC,IAAI,CAAC;IAaV,eAAe,CACnB,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAQnC,iBAAiB,CACrB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAUnC,YAAY,CAChB,GAAG,MAAM,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACjD,OAAO,CAAC,IAAI,CAAC;IAQV,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAWnE,gBAAgB,CACpB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAUnC,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAGvD"}
|
|
@@ -8,11 +8,19 @@ const clientTypes_js_1 = require("../clientTypes.js");
|
|
|
8
8
|
const cache_js_1 = require("./cache.js");
|
|
9
9
|
const memory_advanced_js_1 = require("./memory.advanced.js");
|
|
10
10
|
class ClientCacheMemory extends cache_js_1.ClientCache {
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @param maxCells - Maximum number of cells to store in the cache. Defaults to 512.
|
|
13
|
+
* @param maxTxs - Maximum number of transactions to store in the cache. Defaults to 256.
|
|
14
|
+
* @param maxBlocks - Maximum number of blocks to store in the cache. Defaults to 128.
|
|
15
|
+
* @param confirmedBlockTime - Time in milliseconds after which a block is considered confirmed.
|
|
16
|
+
* Defaults to DEFAULT_CONFIRMED_BLOCK_TIME (50 blocks * 10s).
|
|
17
|
+
*/
|
|
18
|
+
constructor(maxCells = 512, maxTxs = 256, maxBlocks = 128, confirmedBlockTime = memory_advanced_js_1.DEFAULT_CONFIRMED_BLOCK_TIME) {
|
|
12
19
|
super();
|
|
13
20
|
this.maxCells = maxCells;
|
|
14
21
|
this.maxTxs = maxTxs;
|
|
15
22
|
this.maxBlocks = maxBlocks;
|
|
23
|
+
this.confirmedBlockTime = confirmedBlockTime;
|
|
16
24
|
this.cells = new memory_advanced_js_1.MapLru(this.maxCells);
|
|
17
25
|
this.knownTransactions = new memory_advanced_js_1.MapLru(this.maxTxs);
|
|
18
26
|
this.knownBlockHashes = new memory_advanced_js_1.MapLru(this.maxBlocks);
|
|
@@ -137,5 +145,8 @@ class ClientCacheMemory extends cache_js_1.ClientCache {
|
|
|
137
145
|
}
|
|
138
146
|
return this.getBlockByHash(hash);
|
|
139
147
|
}
|
|
148
|
+
hasHeaderConfirmed(header) {
|
|
149
|
+
return (0, index_js_3.numFrom)(Date.now()) - header.timestamp >= this.confirmedBlockTime;
|
|
150
|
+
}
|
|
140
151
|
}
|
|
141
152
|
exports.ClientCacheMemory = ClientCacheMemory;
|