@ckb-ccc/core 0.0.13-alpha.5 → 0.0.13-alpha.7
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 +18 -0
- package/dist/ckb/transaction.d.ts +91 -1
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +118 -23
- package/dist/client/client.d.ts +10 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +6 -5
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +15 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +15 -0
- package/dist/client/clientTypes.d.ts +23 -3
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.d.ts +39 -1
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +39 -1
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist/client/jsonRpc/transformers.js +11 -4
- package/dist/signer/signer/index.d.ts +6 -3
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +20 -5
- package/dist.commonjs/ckb/transaction.d.ts +91 -1
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +121 -22
- package/dist.commonjs/client/client.d.ts +10 -4
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +6 -5
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +15 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +15 -0
- package/dist.commonjs/client/clientTypes.d.ts +23 -3
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts +39 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +39 -1
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/transformers.js +55 -48
- package/dist.commonjs/signer/signer/index.d.ts +6 -3
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +20 -5
- package/package.json +1 -1
- package/src/ckb/transaction.ts +170 -29
- package/src/client/client.ts +22 -5
- package/src/client/clientPublicMainnet.advanced.ts +17 -0
- package/src/client/clientPublicTestnet.advanced.ts +17 -0
- package/src/client/clientTypes.ts +23 -3
- package/src/client/jsonRpc/index.ts +61 -1
- package/src/client/jsonRpc/transformers.ts +11 -3
- package/src/signer/signer/index.ts +24 -3
package/src/ckb/transaction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientCollectableSearchKeyFilterLike } from "../advancedBarrel.js";
|
|
2
|
-
import { Bytes, BytesLike, bytesFrom } from "../bytes/index.js";
|
|
2
|
+
import { Bytes, BytesLike, bytesConcat, bytesFrom } from "../bytes/index.js";
|
|
3
3
|
import { CellDepInfoLike, Client, KnownScript } from "../client/index.js";
|
|
4
4
|
import {
|
|
5
5
|
Zero,
|
|
@@ -11,8 +11,11 @@ import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
|
11
11
|
import {
|
|
12
12
|
Num,
|
|
13
13
|
NumLike,
|
|
14
|
+
numBeToBytes,
|
|
14
15
|
numFrom,
|
|
15
16
|
numFromBytes,
|
|
17
|
+
numLeFromBytes,
|
|
18
|
+
numLeToBytes,
|
|
16
19
|
numToBytes,
|
|
17
20
|
numToHex,
|
|
18
21
|
} from "../num/index.js";
|
|
@@ -416,12 +419,162 @@ export class Cell {
|
|
|
416
419
|
}
|
|
417
420
|
}
|
|
418
421
|
|
|
422
|
+
/**
|
|
423
|
+
* @public
|
|
424
|
+
*/
|
|
425
|
+
export type EpochLike = [NumLike, NumLike, NumLike];
|
|
426
|
+
/**
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
export type Epoch = [Num, Num, Num];
|
|
430
|
+
/**
|
|
431
|
+
* @public
|
|
432
|
+
*/
|
|
433
|
+
export function epochFrom(epochLike: EpochLike): Epoch {
|
|
434
|
+
return [numFrom(epochLike[0]), numFrom(epochLike[1]), numFrom(epochLike[2])];
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
export function epochFromHex(hex: HexLike): Epoch {
|
|
440
|
+
const bytes = bytesFrom(hexFrom(hex));
|
|
441
|
+
|
|
442
|
+
return [
|
|
443
|
+
numFrom(bytes.slice(4, 7)),
|
|
444
|
+
numFrom(bytes.slice(2, 4)),
|
|
445
|
+
numFrom(bytes.slice(0, 2)),
|
|
446
|
+
];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
451
|
+
export function epochToHex(epochLike: EpochLike): Hex {
|
|
452
|
+
const epoch = epochFrom(epochLike);
|
|
453
|
+
|
|
454
|
+
return hexFrom(
|
|
455
|
+
bytesConcat(
|
|
456
|
+
numBeToBytes(epoch[2], 2),
|
|
457
|
+
numBeToBytes(epoch[1], 2),
|
|
458
|
+
numBeToBytes(epoch[0], 3),
|
|
459
|
+
),
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* @public
|
|
465
|
+
*/
|
|
466
|
+
export type SinceLike =
|
|
467
|
+
| {
|
|
468
|
+
relative: "absolute" | "relative";
|
|
469
|
+
metric: "blockNumber" | "epoch" | "timestamp";
|
|
470
|
+
value: NumLike;
|
|
471
|
+
}
|
|
472
|
+
| NumLike;
|
|
473
|
+
/**
|
|
474
|
+
* @public
|
|
475
|
+
*/
|
|
476
|
+
export class Since {
|
|
477
|
+
/**
|
|
478
|
+
* Creates an instance of Since.
|
|
479
|
+
*
|
|
480
|
+
* @param relative - Absolute or relative
|
|
481
|
+
* @param metric - The metric of since
|
|
482
|
+
* @param value - The value of since
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
constructor(
|
|
486
|
+
public relative: "absolute" | "relative",
|
|
487
|
+
public metric: "blockNumber" | "epoch" | "timestamp",
|
|
488
|
+
public value: Num,
|
|
489
|
+
) {}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Clone a Since.
|
|
493
|
+
*
|
|
494
|
+
* @returns A cloned Since instance.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* const since1 = since0.clone();
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
clone(): Since {
|
|
502
|
+
return new Since(this.relative, this.metric, this.value);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Creates a Since instance from a SinceLike object.
|
|
507
|
+
*
|
|
508
|
+
* @param since - A SinceLike object or an instance of Since.
|
|
509
|
+
* @returns A Since instance.
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* const since = Since.from("0x1234567812345678");
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
static from(since: SinceLike): Since {
|
|
517
|
+
if (since instanceof Since) {
|
|
518
|
+
return since;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (typeof since === "object" && "relative" in since) {
|
|
522
|
+
return new Since(since.relative, since.metric, numFrom(since.value));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return Since.fromNum(since);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Converts the Since instance to num.
|
|
530
|
+
*
|
|
531
|
+
* @returns A num
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const num = since.toNum();
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
toNum(): Num {
|
|
540
|
+
const flag =
|
|
541
|
+
((this.relative === "absolute" ? 0 : 1) << 7) |
|
|
542
|
+
({ blockNumber: 0, epoch: 1, timestamp: 2 }[this.metric] << 5);
|
|
543
|
+
|
|
544
|
+
return numFrom(bytesConcat([flag], numLeToBytes(this.value, 7)));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Creates a Since instance from a num-like value.
|
|
549
|
+
*
|
|
550
|
+
* @param numLike - The num-like value to convert.
|
|
551
|
+
* @returns A Since instance.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const since = Since.fromNum("0x0");
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
static fromNum(numLike: NumLike): Since {
|
|
560
|
+
const bytes = numBeToBytes(numLike, 8);
|
|
561
|
+
|
|
562
|
+
const relative = bytes[0] >> 7 === 0 ? "absolute" : "relative";
|
|
563
|
+
const metric = (["blockNumber", "epoch", "timestamp"] as Since["metric"][])[
|
|
564
|
+
(bytes[0] >> 5) & 3
|
|
565
|
+
];
|
|
566
|
+
const value = numLeFromBytes(bytes.slice(1, 8));
|
|
567
|
+
|
|
568
|
+
return new Since(relative, metric, value);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
419
572
|
/**
|
|
420
573
|
* @public
|
|
421
574
|
*/
|
|
422
575
|
export type CellInputLike = {
|
|
423
576
|
previousOutput: OutPointLike;
|
|
424
|
-
since?: NumLike | null;
|
|
577
|
+
since?: SinceLike | NumLike | null;
|
|
425
578
|
cellOutput?: CellOutputLike | null;
|
|
426
579
|
outputData?: HexLike | null;
|
|
427
580
|
};
|
|
@@ -485,7 +638,7 @@ export class CellInput {
|
|
|
485
638
|
|
|
486
639
|
return new CellInput(
|
|
487
640
|
OutPoint.from(cellInput.previousOutput),
|
|
488
|
-
|
|
641
|
+
Since.from(cellInput.since ?? 0).toNum(),
|
|
489
642
|
apply(CellOutput.from, cellInput.cellOutput),
|
|
490
643
|
apply(hexFrom, cellInput.outputData),
|
|
491
644
|
);
|
|
@@ -1536,45 +1689,33 @@ export class Transaction {
|
|
|
1536
1689
|
addedCount: number;
|
|
1537
1690
|
accumulated?: T;
|
|
1538
1691
|
}> {
|
|
1539
|
-
const scripts = (await from.getAddressObjs()).map(({ script }) => script);
|
|
1540
1692
|
const collectedCells = [];
|
|
1541
1693
|
|
|
1542
1694
|
let acc: T = init;
|
|
1543
1695
|
let fulfilled = false;
|
|
1544
|
-
for (const
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
})) {
|
|
1552
|
-
if (
|
|
1553
|
-
this.inputs.some(({ previousOutput }) =>
|
|
1554
|
-
previousOutput.eq(cell.outPoint),
|
|
1555
|
-
)
|
|
1556
|
-
) {
|
|
1557
|
-
continue;
|
|
1558
|
-
}
|
|
1559
|
-
const i = collectedCells.push(cell);
|
|
1560
|
-
const next = await Promise.resolve(
|
|
1561
|
-
accumulator(acc, cell, i - 1, collectedCells),
|
|
1562
|
-
);
|
|
1563
|
-
if (next === undefined) {
|
|
1564
|
-
fulfilled = true;
|
|
1565
|
-
break;
|
|
1566
|
-
}
|
|
1696
|
+
for await (const cell of from.findCells(filter, true)) {
|
|
1697
|
+
if (
|
|
1698
|
+
this.inputs.some(({ previousOutput }) =>
|
|
1699
|
+
previousOutput.eq(cell.outPoint),
|
|
1700
|
+
)
|
|
1701
|
+
) {
|
|
1702
|
+
continue;
|
|
1567
1703
|
}
|
|
1568
|
-
|
|
1704
|
+
const i = collectedCells.push(cell);
|
|
1705
|
+
const next = await Promise.resolve(
|
|
1706
|
+
accumulator(acc, cell, i - 1, collectedCells),
|
|
1707
|
+
);
|
|
1708
|
+
if (next === undefined) {
|
|
1709
|
+
fulfilled = true;
|
|
1569
1710
|
break;
|
|
1570
1711
|
}
|
|
1712
|
+
acc = next;
|
|
1571
1713
|
}
|
|
1572
1714
|
|
|
1573
1715
|
this.inputs.push(
|
|
1574
1716
|
...collectedCells.map(({ outPoint, outputData, cellOutput }) =>
|
|
1575
1717
|
CellInput.from({
|
|
1576
1718
|
previousOutput: outPoint,
|
|
1577
|
-
since: 0,
|
|
1578
1719
|
outputData,
|
|
1579
1720
|
cellOutput,
|
|
1580
1721
|
}),
|
package/src/client/client.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { ClientCacheMemory } from "./cache/memory.js";
|
|
|
18
18
|
import { ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
|
|
19
19
|
import {
|
|
20
20
|
ClientBlock,
|
|
21
|
+
ClientBlockHeader,
|
|
21
22
|
ClientFindCellsResponse,
|
|
22
23
|
ClientFindTransactionsGroupedResponse,
|
|
23
24
|
ClientFindTransactionsResponse,
|
|
@@ -45,6 +46,7 @@ export enum KnownScript {
|
|
|
45
46
|
UniqueType = "UniqueType",
|
|
46
47
|
SingleUseLock = "SingleUseLock",
|
|
47
48
|
OutputTypeProxyLock = "OutputTypeProxyLock",
|
|
49
|
+
NervosDao = "NervosDao",
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
@@ -92,6 +94,7 @@ export abstract class Client {
|
|
|
92
94
|
>;
|
|
93
95
|
|
|
94
96
|
abstract getTip(): Promise<Num>;
|
|
97
|
+
abstract getTipHeader(verbosity?: number | null): Promise<ClientBlockHeader>;
|
|
95
98
|
abstract getBlockByNumber(
|
|
96
99
|
blockNumber: NumLike,
|
|
97
100
|
verbosity?: number | null,
|
|
@@ -102,6 +105,20 @@ export abstract class Client {
|
|
|
102
105
|
verbosity?: number | null,
|
|
103
106
|
withCycles?: boolean | null,
|
|
104
107
|
): Promise<ClientBlock | undefined>;
|
|
108
|
+
abstract getHeaderByNumber(
|
|
109
|
+
blockNumber: NumLike,
|
|
110
|
+
verbosity?: number | null,
|
|
111
|
+
): Promise<ClientBlockHeader | undefined>;
|
|
112
|
+
abstract getHeaderByHash(
|
|
113
|
+
blockHash: HexLike,
|
|
114
|
+
verbosity?: number | null,
|
|
115
|
+
): Promise<ClientBlockHeader | undefined>;
|
|
116
|
+
|
|
117
|
+
abstract estimateCycles(transaction: TransactionLike): Promise<Num>;
|
|
118
|
+
abstract sendTransactionDry(
|
|
119
|
+
transaction: TransactionLike,
|
|
120
|
+
validator?: OutputsValidator,
|
|
121
|
+
): Promise<Num>;
|
|
105
122
|
|
|
106
123
|
abstract sendTransactionNoCache(
|
|
107
124
|
transaction: TransactionLike,
|
|
@@ -155,7 +172,7 @@ export abstract class Client {
|
|
|
155
172
|
return res;
|
|
156
173
|
}
|
|
157
174
|
|
|
158
|
-
async *
|
|
175
|
+
async *findCellsOnChin(
|
|
159
176
|
key: ClientIndexerSearchKeyLike,
|
|
160
177
|
order?: "asc" | "desc",
|
|
161
178
|
limit = 10,
|
|
@@ -185,7 +202,7 @@ export abstract class Client {
|
|
|
185
202
|
* @param keyLike - The search key.
|
|
186
203
|
* @returns A async generator for yielding cells.
|
|
187
204
|
*/
|
|
188
|
-
async *
|
|
205
|
+
async *findCells(
|
|
189
206
|
keyLike: ClientCollectableSearchKeyLike,
|
|
190
207
|
order?: "asc" | "desc",
|
|
191
208
|
limit = 10,
|
|
@@ -198,7 +215,7 @@ export abstract class Client {
|
|
|
198
215
|
yield cell;
|
|
199
216
|
}
|
|
200
217
|
|
|
201
|
-
for await (const cell of this.
|
|
218
|
+
for await (const cell of this.findCellsOnChin(key, order, limit)) {
|
|
202
219
|
if (
|
|
203
220
|
(await this.cache.isUnusable(cell.outPoint)) ||
|
|
204
221
|
foundedOutPoints.some((founded) => founded.eq(cell.outPoint))
|
|
@@ -217,7 +234,7 @@ export abstract class Client {
|
|
|
217
234
|
order?: "asc" | "desc",
|
|
218
235
|
limit = 10,
|
|
219
236
|
): AsyncGenerator<Cell> {
|
|
220
|
-
return this.
|
|
237
|
+
return this.findCells(
|
|
221
238
|
{
|
|
222
239
|
script: lock,
|
|
223
240
|
scriptType: "lock",
|
|
@@ -238,7 +255,7 @@ export abstract class Client {
|
|
|
238
255
|
order?: "asc" | "desc",
|
|
239
256
|
limit = 10,
|
|
240
257
|
): AsyncGenerator<Cell> {
|
|
241
|
-
return this.
|
|
258
|
+
return this.findCells(
|
|
242
259
|
{
|
|
243
260
|
script: type,
|
|
244
261
|
scriptType: "type",
|
|
@@ -254,4 +254,21 @@ export const MAINNET_SCRIPTS: Record<
|
|
|
254
254
|
},
|
|
255
255
|
],
|
|
256
256
|
},
|
|
257
|
+
[KnownScript.NervosDao]: {
|
|
258
|
+
codeHash:
|
|
259
|
+
"0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
|
|
260
|
+
hashType: "type",
|
|
261
|
+
cellDeps: [
|
|
262
|
+
{
|
|
263
|
+
cellDep: {
|
|
264
|
+
outPoint: {
|
|
265
|
+
txHash:
|
|
266
|
+
"0xe2fb199810d49a4d8beec56718ba2593b665db9d52299a0f9e6e75416d73ff5c",
|
|
267
|
+
index: 2,
|
|
268
|
+
},
|
|
269
|
+
depType: "code",
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
},
|
|
257
274
|
});
|
|
@@ -265,4 +265,21 @@ export const TESTNET_SCRIPTS: Record<
|
|
|
265
265
|
},
|
|
266
266
|
],
|
|
267
267
|
},
|
|
268
|
+
[KnownScript.NervosDao]: {
|
|
269
|
+
codeHash:
|
|
270
|
+
"0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
|
|
271
|
+
hashType: "type",
|
|
272
|
+
cellDeps: [
|
|
273
|
+
{
|
|
274
|
+
cellDep: {
|
|
275
|
+
outPoint: {
|
|
276
|
+
txHash:
|
|
277
|
+
"0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f",
|
|
278
|
+
index: 2,
|
|
279
|
+
},
|
|
280
|
+
depType: "code",
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
},
|
|
268
285
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cell, Script, Transaction } from "../ckb/index.js";
|
|
1
|
+
import { Cell, Epoch, Script, Transaction } from "../ckb/index.js";
|
|
2
2
|
import { Hex, hexFrom } from "../hex/index.js";
|
|
3
3
|
import { Num, NumLike } from "../num/index.js";
|
|
4
4
|
import { apply } from "../utils/index.js";
|
|
@@ -181,8 +181,28 @@ export type ClientFindTransactionsGroupedResponse = {
|
|
|
181
181
|
*/
|
|
182
182
|
export type ClientBlockHeader = {
|
|
183
183
|
compactTarget: Num;
|
|
184
|
-
dao:
|
|
185
|
-
|
|
184
|
+
dao: {
|
|
185
|
+
/**
|
|
186
|
+
* C_i: the total issuance up to and including block i.
|
|
187
|
+
*/
|
|
188
|
+
c: Num;
|
|
189
|
+
/**
|
|
190
|
+
* AR_i: the current accumulated rate at block i.
|
|
191
|
+
* AR_j / AR_i reflects the CKByte amount if one deposit 1 CKB to Nervos DAO at block i, and withdraw at block j.
|
|
192
|
+
*/
|
|
193
|
+
ar: Num;
|
|
194
|
+
/**
|
|
195
|
+
* S_i: the total unissued secondary issuance up to and including block i,
|
|
196
|
+
* including unclaimed Nervos DAO compensation and treasury funds.
|
|
197
|
+
*/
|
|
198
|
+
s: Num;
|
|
199
|
+
/**
|
|
200
|
+
* U_i: the total occupied capacities currently in the blockchain up to and including block i.
|
|
201
|
+
* Occupied capacity is the sum of capacities used to store all cells.
|
|
202
|
+
*/
|
|
203
|
+
u: Num;
|
|
204
|
+
};
|
|
205
|
+
epoch: Epoch;
|
|
186
206
|
extraHash: Hex;
|
|
187
207
|
hash: Hex;
|
|
188
208
|
nonce: Num;
|
|
@@ -88,7 +88,17 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
88
88
|
) as () => Promise<Num>;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* Get
|
|
91
|
+
* Get tip block header
|
|
92
|
+
*
|
|
93
|
+
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
94
|
+
* @returns BlockHeader
|
|
95
|
+
*/
|
|
96
|
+
getTipHeader = this.buildSender("get_tip_header", [], (b) =>
|
|
97
|
+
apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
98
|
+
) as Client["getTipHeader"];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get block by block number
|
|
92
102
|
*
|
|
93
103
|
* @param blockNumber - The block number.
|
|
94
104
|
* @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
|
|
@@ -113,6 +123,56 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
113
123
|
apply(JsonRpcTransformers.blockTo, b),
|
|
114
124
|
) as Client["getBlockByHash"];
|
|
115
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Get header by block number
|
|
128
|
+
*
|
|
129
|
+
* @param blockNumber - The block number.
|
|
130
|
+
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
131
|
+
* @returns BlockHeader
|
|
132
|
+
*/
|
|
133
|
+
getHeaderByNumber = this.buildSender(
|
|
134
|
+
"get_header_by_number",
|
|
135
|
+
[(v: NumLike) => numToHex(numFrom(v))],
|
|
136
|
+
(b) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
137
|
+
) as Client["getHeaderByNumber"];
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get header by block hash
|
|
141
|
+
*
|
|
142
|
+
* @param blockHash - The block hash.
|
|
143
|
+
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
144
|
+
* @returns BlockHeader
|
|
145
|
+
*/
|
|
146
|
+
getHeaderByHash = this.buildSender("get_header", [hexFrom], (b) =>
|
|
147
|
+
apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
148
|
+
) as Client["getHeaderByHash"];
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Estimate cycles of a transaction.
|
|
152
|
+
*
|
|
153
|
+
* @param transaction - The transaction to estimate.
|
|
154
|
+
* @returns Consumed cycles
|
|
155
|
+
*/
|
|
156
|
+
estimateCycles = this.buildSender(
|
|
157
|
+
"estimate_cycles",
|
|
158
|
+
[JsonRpcTransformers.transactionFrom],
|
|
159
|
+
({ cycles }: { cycles: NumLike }) => numFrom(cycles),
|
|
160
|
+
) as Client["estimateCycles"];
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Test a transaction.
|
|
164
|
+
*
|
|
165
|
+
* @param transaction - The transaction to test.
|
|
166
|
+
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
167
|
+
* @returns Consumed cycles
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
sendTransactionDry = this.buildSender(
|
|
171
|
+
"test_tx_pool_accept",
|
|
172
|
+
[JsonRpcTransformers.transactionFrom],
|
|
173
|
+
({ cycles }: { cycles: NumLike }) => numFrom(cycles),
|
|
174
|
+
) as Client["sendTransactionDry"];
|
|
175
|
+
|
|
116
176
|
/**
|
|
117
177
|
* Send a transaction to node.
|
|
118
178
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
1
2
|
import {
|
|
2
3
|
Cell,
|
|
3
4
|
CellDep,
|
|
@@ -17,10 +18,11 @@ import {
|
|
|
17
18
|
Transaction,
|
|
18
19
|
TransactionLike,
|
|
19
20
|
depTypeFrom,
|
|
21
|
+
epochFromHex,
|
|
20
22
|
hashTypeFrom,
|
|
21
23
|
} from "../../ckb/index.js";
|
|
22
24
|
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
23
|
-
import { NumLike, numFrom, numToHex } from "../../num/index.js";
|
|
25
|
+
import { NumLike, numFrom, numLeFromBytes, numToHex } from "../../num/index.js";
|
|
24
26
|
import { apply } from "../../utils/index.js";
|
|
25
27
|
import {
|
|
26
28
|
ClientBlock,
|
|
@@ -201,10 +203,16 @@ export class JsonRpcTransformers {
|
|
|
201
203
|
};
|
|
202
204
|
}
|
|
203
205
|
static blockHeaderTo(header: JsonRpcBlockHeader): ClientBlockHeader {
|
|
206
|
+
const dao = bytesFrom(header.dao);
|
|
204
207
|
return {
|
|
205
208
|
compactTarget: numFrom(header.compact_target),
|
|
206
|
-
dao:
|
|
207
|
-
|
|
209
|
+
dao: {
|
|
210
|
+
c: numLeFromBytes(dao.slice(0, 8)),
|
|
211
|
+
ar: numLeFromBytes(dao.slice(8, 16)),
|
|
212
|
+
s: numLeFromBytes(dao.slice(16, 24)),
|
|
213
|
+
u: numLeFromBytes(dao.slice(24, 32)),
|
|
214
|
+
},
|
|
215
|
+
epoch: epochFromHex(header.epoch),
|
|
208
216
|
extraHash: header.extra_hash,
|
|
209
217
|
hash: header.hash,
|
|
210
218
|
nonce: numFrom(header.nonce),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Address } from "../../address/index.js";
|
|
2
|
+
import { ClientCollectableSearchKeyFilterLike } from "../../advancedBarrel.js";
|
|
2
3
|
import { BytesLike } from "../../bytes/index.js";
|
|
3
|
-
import { Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
|
+
import { Cell, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
4
5
|
import { Client } from "../../client/index.js";
|
|
5
6
|
import { Hex } from "../../hex/index.js";
|
|
6
7
|
import { Num } from "../../num/index.js";
|
|
@@ -46,7 +47,8 @@ export type NetworkPreference = {
|
|
|
46
47
|
* BTC: // They made a mess...
|
|
47
48
|
* btc
|
|
48
49
|
* btcTestnet
|
|
49
|
-
*
|
|
50
|
+
* btcTestnet4 // UTXO Global
|
|
51
|
+
* btcSignet // OKX & UTXO Global
|
|
50
52
|
* fractalBtc // UniSat
|
|
51
53
|
*/
|
|
52
54
|
network: string;
|
|
@@ -82,9 +84,10 @@ export abstract class Signer {
|
|
|
82
84
|
// undefined otherwise
|
|
83
85
|
matchNetworkPreference(
|
|
84
86
|
preferences: NetworkPreference[],
|
|
85
|
-
currentNetwork: string,
|
|
87
|
+
currentNetwork: string | undefined,
|
|
86
88
|
): NetworkPreference | undefined {
|
|
87
89
|
if (
|
|
90
|
+
currentNetwork !== undefined &&
|
|
88
91
|
preferences.some(({ signerType, addressPrefix, network }) => {
|
|
89
92
|
signerType === this.type &&
|
|
90
93
|
addressPrefix === this.client.addressPrefix &&
|
|
@@ -223,6 +226,24 @@ export abstract class Signer {
|
|
|
223
226
|
);
|
|
224
227
|
}
|
|
225
228
|
|
|
229
|
+
async *findCells(
|
|
230
|
+
filter: ClientCollectableSearchKeyFilterLike,
|
|
231
|
+
withData?: boolean | null,
|
|
232
|
+
): AsyncGenerator<Cell> {
|
|
233
|
+
const scripts = await this.getAddressObjs();
|
|
234
|
+
for (const { script } of scripts) {
|
|
235
|
+
for await (const cell of this.client.findCells({
|
|
236
|
+
script,
|
|
237
|
+
scriptType: "lock",
|
|
238
|
+
filter,
|
|
239
|
+
scriptSearchMode: "exact",
|
|
240
|
+
withData,
|
|
241
|
+
})) {
|
|
242
|
+
yield cell;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
226
247
|
/**
|
|
227
248
|
* Gets balance of all addresses
|
|
228
249
|
*
|