@ckb-ccc/core 0.0.13-alpha.7 → 0.0.13-alpha.8
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 +12 -0
- package/dist/client/cache/cache.d.ts +29 -9
- package/dist/client/cache/cache.d.ts.map +1 -1
- package/dist/client/cache/cache.js +43 -1
- package/dist/client/cache/memory.d.ts +10 -6
- package/dist/client/cache/memory.d.ts.map +1 -1
- package/dist/client/cache/memory.js +49 -39
- package/dist/client/clientTypes.d.ts +25 -2
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +26 -1
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +24 -1
- package/dist/fixedPoint/index.d.ts +3 -3
- package/dist/fixedPoint/index.js +3 -3
- package/dist.commonjs/client/cache/cache.d.ts +29 -9
- package/dist.commonjs/client/cache/cache.d.ts.map +1 -1
- package/dist.commonjs/client/cache/cache.js +45 -0
- package/dist.commonjs/client/cache/memory.d.ts +10 -6
- package/dist.commonjs/client/cache/memory.d.ts.map +1 -1
- package/dist.commonjs/client/cache/memory.js +49 -39
- package/dist.commonjs/client/clientTypes.d.ts +25 -2
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +33 -5
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +40 -17
- package/dist.commonjs/fixedPoint/index.d.ts +3 -3
- package/dist.commonjs/fixedPoint/index.js +3 -3
- package/package.json +1 -1
- package/src/client/cache/cache.ts +58 -13
- package/src/client/cache/memory.ts +60 -52
- package/src/client/clientTypes.ts +54 -3
- package/src/client/jsonRpc/index.ts +44 -2
- package/src/fixedPoint/index.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ckb-ccc/core
|
|
2
2
|
|
|
3
|
+
## 0.0.13-alpha.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8629449`](https://github.com/ckb-ecofund/ccc/commit/86294490e76fc2a1cee20f827883e02fceca6e8b) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(core): ClientCache.clear
|
|
8
|
+
|
|
9
|
+
replaced ClientCache.revertTransactions
|
|
10
|
+
|
|
11
|
+
- [`52156f9`](https://github.com/ckb-ecofund/ccc/commit/52156f9df9cae9e0b71b77b49cda0e4d73e76142) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(core): ClientCache.revertTransaction
|
|
12
|
+
|
|
13
|
+
- [`63606db`](https://github.com/ckb-ecofund/ccc/commit/63606db908f95bfc857430083932144d1ef4deef) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(coree): typed errors
|
|
14
|
+
|
|
3
15
|
## 0.0.13-alpha.7
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
2
|
import { HexLike } from "../../hex/index.js";
|
|
3
3
|
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
|
-
export
|
|
5
|
-
markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
6
|
-
markUnusable(...outPointLike: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
4
|
+
export declare abstract class ClientCache {
|
|
5
|
+
abstract markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
6
|
+
abstract markUnusable(...outPointLike: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
7
7
|
markTransactions(...transactionLike: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
abstract clear(): Promise<void>;
|
|
9
|
+
abstract findCells(filter: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
10
|
+
/**
|
|
11
|
+
* Get a known cell by out point
|
|
12
|
+
* @param _outPoint
|
|
13
|
+
*/
|
|
14
|
+
abstract getCell(_outPoint: OutPointLike): Promise<Cell | undefined>;
|
|
15
|
+
abstract isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Record known transactions
|
|
18
|
+
* Implement this method to enable transactions query caching
|
|
19
|
+
* @param _transactions
|
|
20
|
+
*/
|
|
21
|
+
recordTransactions(..._transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a known transaction by hash
|
|
24
|
+
* Implement this method to enable transactions query caching
|
|
25
|
+
* @param _txHash
|
|
26
|
+
*/
|
|
27
|
+
getTransaction(_txHash: HexLike): Promise<Transaction | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Record known cells
|
|
30
|
+
* Implement this method to enable cells query caching
|
|
31
|
+
* @param _cells
|
|
32
|
+
*/
|
|
33
|
+
recordCells(..._cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
14
34
|
}
|
|
15
35
|
//# 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,oBAAoB,CAAC;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5E,
|
|
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,oBA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} from "../../ckb/index.js";
|
|
2
|
+
export class ClientCache {
|
|
3
|
+
async markTransactions(...transactionLike) {
|
|
4
|
+
await Promise.all([
|
|
5
|
+
this.recordTransactions(...transactionLike),
|
|
6
|
+
...transactionLike.flat().map((transactionLike) => {
|
|
7
|
+
const tx = Transaction.from(transactionLike);
|
|
8
|
+
const txHash = tx.hash();
|
|
9
|
+
return Promise.all([
|
|
10
|
+
...tx.inputs.map((i) => this.markUnusable(i.previousOutput)),
|
|
11
|
+
...tx.outputs.map((o, i) => this.markUsable({
|
|
12
|
+
cellOutput: o,
|
|
13
|
+
outputData: tx.outputsData[i],
|
|
14
|
+
outPoint: {
|
|
15
|
+
txHash,
|
|
16
|
+
index: i,
|
|
17
|
+
},
|
|
18
|
+
})),
|
|
19
|
+
]);
|
|
20
|
+
}),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Record known transactions
|
|
25
|
+
* Implement this method to enable transactions query caching
|
|
26
|
+
* @param _transactions
|
|
27
|
+
*/
|
|
28
|
+
async recordTransactions(..._transactions) { }
|
|
29
|
+
/**
|
|
30
|
+
* Get a known transaction by hash
|
|
31
|
+
* Implement this method to enable transactions query caching
|
|
32
|
+
* @param _txHash
|
|
33
|
+
*/
|
|
34
|
+
async getTransaction(_txHash) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Record known cells
|
|
39
|
+
* Implement this method to enable cells query caching
|
|
40
|
+
* @param _cells
|
|
41
|
+
*/
|
|
42
|
+
async recordCells(..._cells) { }
|
|
43
|
+
}
|
|
@@ -2,19 +2,23 @@ import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../.
|
|
|
2
2
|
import { HexLike } from "../../hex/index.js";
|
|
3
3
|
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
4
|
import { ClientCache } from "./cache.js";
|
|
5
|
-
export declare class ClientCacheMemory
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare class ClientCacheMemory extends ClientCache {
|
|
6
|
+
/**
|
|
7
|
+
* OutPoint => [isLive, Cell | OutPoint]
|
|
8
|
+
*/
|
|
9
|
+
private readonly cells;
|
|
10
|
+
/**
|
|
11
|
+
* TX Hash => Transaction
|
|
12
|
+
*/
|
|
8
13
|
private readonly knownTransactions;
|
|
9
|
-
private readonly knownCells;
|
|
10
14
|
markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
11
15
|
markUnusable(...outPointLikes: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
12
|
-
|
|
16
|
+
clear(): Promise<void>;
|
|
13
17
|
findCells(keyLike: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
18
|
+
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
14
19
|
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
15
20
|
recordTransactions(...transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
16
21
|
getTransaction(txHashLike: HexLike): Promise<Transaction | undefined>;
|
|
17
22
|
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
18
|
-
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
19
23
|
}
|
|
20
24
|
//# 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,EACL,IAAI,EACJ,QAAQ,EAER,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,qBAAa,iBAAkB,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","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@@ -1,73 +1,83 @@
|
|
|
1
1
|
import { Cell, OutPoint, Transaction, } from "../../ckb/index.js";
|
|
2
2
|
import { hexFrom } from "../../hex/index.js";
|
|
3
|
+
import { ClientCache } from "./cache.js";
|
|
3
4
|
import { filterCell } from "./memory.advanced.js";
|
|
4
|
-
export class ClientCacheMemory {
|
|
5
|
+
export class ClientCacheMemory extends ClientCache {
|
|
5
6
|
constructor() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
super(...arguments);
|
|
8
|
+
/**
|
|
9
|
+
* OutPoint => [isLive, Cell | OutPoint]
|
|
10
|
+
*/
|
|
11
|
+
this.cells = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* TX Hash => Transaction
|
|
14
|
+
*/
|
|
15
|
+
this.knownTransactions = new Map();
|
|
10
16
|
}
|
|
11
17
|
async markUsable(...cellLikes) {
|
|
12
18
|
cellLikes.flat().forEach((cellLike) => {
|
|
13
19
|
const cell = Cell.from(cellLike).clone();
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
17
|
-
if (index !== -1) {
|
|
18
|
-
this.unusableOutPoints.splice(index, 1);
|
|
19
|
-
}
|
|
20
|
+
const outPointStr = hexFrom(cell.outPoint.toBytes());
|
|
21
|
+
this.cells.set(outPointStr, [true, cell]);
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
async markUnusable(...outPointLikes) {
|
|
23
25
|
outPointLikes.flat().forEach((outPointLike) => {
|
|
24
26
|
const outPoint = OutPoint.from(outPointLike);
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
27
|
+
const outPointStr = hexFrom(outPoint.toBytes());
|
|
28
|
+
const existed = this.cells.get(outPointStr);
|
|
29
|
+
if (existed) {
|
|
30
|
+
existed[0] = false;
|
|
31
|
+
return;
|
|
29
32
|
}
|
|
33
|
+
this.cells.set(outPointStr, [false, { outPoint }]);
|
|
30
34
|
});
|
|
31
35
|
}
|
|
32
|
-
async
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await Promise.all(tx.inputs.map((i) => this.markUnusable(i.previousOutput)));
|
|
37
|
-
await Promise.all(tx.outputs.map((o, i) => this.markUsable({
|
|
38
|
-
cellOutput: o,
|
|
39
|
-
outputData: tx.outputsData[i],
|
|
40
|
-
outPoint: {
|
|
41
|
-
txHash,
|
|
42
|
-
index: i,
|
|
43
|
-
},
|
|
44
|
-
})));
|
|
45
|
-
}));
|
|
36
|
+
async clear() {
|
|
37
|
+
for (const val of this.cells.values()) {
|
|
38
|
+
val[0] = undefined;
|
|
39
|
+
}
|
|
46
40
|
}
|
|
47
41
|
async *findCells(keyLike) {
|
|
48
|
-
for (const cell of this.
|
|
42
|
+
for (const [isLive, cell] of this.cells.values()) {
|
|
43
|
+
if (!isLive) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
49
46
|
if (!filterCell(keyLike, cell)) {
|
|
50
47
|
continue;
|
|
51
48
|
}
|
|
52
|
-
yield cell;
|
|
49
|
+
yield cell.clone();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async getCell(outPointLike) {
|
|
53
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
54
|
+
const cell = this.cells.get(hexFrom(outPoint.toBytes()))?.[1];
|
|
55
|
+
if (cell && cell.cellOutput && cell.outputData) {
|
|
56
|
+
return Cell.from(cell.clone());
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
async isUnusable(outPointLike) {
|
|
56
60
|
const outPoint = OutPoint.from(outPointLike);
|
|
57
|
-
return this.
|
|
61
|
+
return !(this.cells.get(hexFrom(outPoint.toBytes()))?.[0] ?? true);
|
|
58
62
|
}
|
|
59
63
|
async recordTransactions(...transactions) {
|
|
60
|
-
|
|
64
|
+
transactions.flat().map((txLike) => {
|
|
65
|
+
const tx = Transaction.from(txLike);
|
|
66
|
+
this.knownTransactions.set(tx.hash(), tx);
|
|
67
|
+
});
|
|
61
68
|
}
|
|
62
69
|
async getTransaction(txHashLike) {
|
|
63
70
|
const txHash = hexFrom(txHashLike);
|
|
64
|
-
return this.knownTransactions.
|
|
71
|
+
return this.knownTransactions.get(txHash)?.clone();
|
|
65
72
|
}
|
|
66
73
|
async recordCells(...cells) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
cells.flat().map((cellLike) => {
|
|
75
|
+
const cell = Cell.from(cellLike);
|
|
76
|
+
const outPointStr = hexFrom(cell.outPoint.toBytes());
|
|
77
|
+
if (this.cells.get(outPointStr)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.cells.set(outPointStr, [undefined, cell]);
|
|
81
|
+
});
|
|
72
82
|
}
|
|
73
83
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Cell, Epoch, Script, Transaction } from "../ckb/index.js";
|
|
2
|
-
import { Hex } from "../hex/index.js";
|
|
1
|
+
import { Cell, Epoch, OutPoint, OutPointLike, Script, Transaction } from "../ckb/index.js";
|
|
2
|
+
import { Hex, HexLike } from "../hex/index.js";
|
|
3
3
|
import { Num, NumLike } from "../num/index.js";
|
|
4
4
|
import { ClientCollectableSearchKeyFilterLike, ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
|
|
5
5
|
/**
|
|
@@ -167,4 +167,27 @@ export type ClientBlock = {
|
|
|
167
167
|
transactions: Transaction[];
|
|
168
168
|
uncles: ClientBlockUncle[];
|
|
169
169
|
};
|
|
170
|
+
export interface ErrorClientBaseLike {
|
|
171
|
+
message: string;
|
|
172
|
+
code: number;
|
|
173
|
+
data: string;
|
|
174
|
+
}
|
|
175
|
+
export declare class ErrorClientBase extends Error {
|
|
176
|
+
readonly message: string;
|
|
177
|
+
readonly code: number;
|
|
178
|
+
readonly data: string;
|
|
179
|
+
constructor(origin: ErrorClientBaseLike);
|
|
180
|
+
}
|
|
181
|
+
export declare class ErrorClientResolveUnknown extends ErrorClientBase {
|
|
182
|
+
readonly outPoint: OutPoint;
|
|
183
|
+
constructor(origin: ErrorClientBaseLike, outPointLike: OutPointLike);
|
|
184
|
+
}
|
|
185
|
+
export declare class ErrorClientVerification extends ErrorClientBase {
|
|
186
|
+
readonly source: "lock" | "inputType" | "outputType";
|
|
187
|
+
readonly errorCode: number;
|
|
188
|
+
readonly scriptHashType: "data" | "type";
|
|
189
|
+
readonly sourceIndex: Num;
|
|
190
|
+
readonly scriptCodeHash: Hex;
|
|
191
|
+
constructor(origin: ErrorClientBaseLike, source: "lock" | "inputType" | "outputType", sourceIndex: NumLike, errorCode: number, scriptHashType: "data" | "type", scriptCodeHash: HexLike);
|
|
192
|
+
}
|
|
170
193
|
//# sourceMappingURL=clientTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientTypes.d.ts","sourceRoot":"","sources":["../../src/client/clientTypes.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"clientTypes.d.ts","sourceRoot":"","sources":["../../src/client/clientTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AAExD,OAAO,EACL,oCAAoC,EACpC,8BAA8B,EAE/B,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,yBAAyB,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,SAAS,GACT,UAAU,GACV,WAAW,GACX,SAAS,GACT,UAAU,CAAC;AACf;;GAEG;AACH,MAAM,MAAM,y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AAW,EAAE,OAAO,EACJ,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GAAG,MAAM,EAC/C,cAAc,EAAE,OAAO;CAM1B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Script } from "../ckb/index.js";
|
|
1
|
+
import { OutPoint, Script, } from "../ckb/index.js";
|
|
2
2
|
import { hexFrom } from "../hex/index.js";
|
|
3
|
+
import { numFrom } from "../num/index.js";
|
|
3
4
|
import { apply } from "../utils/index.js";
|
|
4
5
|
import { clientSearchKeyRangeFrom, } from "./clientTypes.advanced.js";
|
|
5
6
|
/**
|
|
@@ -49,3 +50,27 @@ export class ClientIndexerSearchKeyTransaction {
|
|
|
49
50
|
return new ClientIndexerSearchKeyTransaction(Script.from(keyLike.script), keyLike.scriptType, keyLike.scriptSearchMode, apply(ClientIndexerSearchKeyFilter.from, keyLike.filter), keyLike.groupByTransaction ?? undefined);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
53
|
+
export class ErrorClientBase extends Error {
|
|
54
|
+
constructor(origin) {
|
|
55
|
+
super(origin.message);
|
|
56
|
+
this.message = origin.message;
|
|
57
|
+
this.code = origin.code;
|
|
58
|
+
this.data = origin.data;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export class ErrorClientResolveUnknown extends ErrorClientBase {
|
|
62
|
+
constructor(origin, outPointLike) {
|
|
63
|
+
super(origin);
|
|
64
|
+
this.outPoint = OutPoint.from(outPointLike);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export class ErrorClientVerification extends ErrorClientBase {
|
|
68
|
+
constructor(origin, source, sourceIndex, errorCode, scriptHashType, scriptCodeHash) {
|
|
69
|
+
super(origin);
|
|
70
|
+
this.source = source;
|
|
71
|
+
this.errorCode = errorCode;
|
|
72
|
+
this.scriptHashType = scriptHashType;
|
|
73
|
+
this.sourceIndex = numFrom(sourceIndex);
|
|
74
|
+
this.scriptCodeHash = hexFrom(scriptCodeHash);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EAKzB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EAGf,MAAM,2BAA2B,CAAC;AA2BnC;;;GAGG;AAEH,8BAAsB,aAAc,SAAQ,MAAM;IAW9C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAVvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IAEtC;;;;;OAKG;gBAGgB,IAAI,EAAE,MAAM,EAC7B,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,WAAW,CAAA;KAAE;IAOpD;;;;OAIG;IAEH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;OAIG;IAEH,MAAM,QAIK,QAAQ,GAAG,CAAC,CAAC;IAExB;;;;;OAKG;IACH,YAAY,oGAEgB;IAE5B;;;;;;;OAOG;IACH,gBAAgB,yKAIgB;IAEhC;;;;;;;OAOG;IACH,cAAc,mMAEgB;IAE9B;;;;;;OAMG;IACH,iBAAiB,sIAIgB;IAEjC;;;;;;OAMG;IACH,eAAe,gKAEgB;IAE/B;;;;;OAKG;IACH,cAAc,oDAIgB;IAE9B;;;;;;OAMG;IAEH,kBAAkB,8FAIgB;IAElC;;;;;;OAMG;IAEH,sBAAsB,gBAKP,eAAe,cAChB,gBAAgB,GAAG,SAAS,KACrC,QAAQ,GAAG,CAAC,CAAC;IAElB;;;;;OAKG;IAEH,qBAAqB,WAIP,OAAO,KAAK,QAAQ,yBAAyB,GAAG,SAAS,CAAC,CAAC;IAEzE;;;;;;;;OAQG;IAEH,qBAAqB,QASd,0BAA0B,UACvB,KAAK,GAAG,MAAM,UACd,OAAO,UACP,MAAM,KACX,QAAQ,uBAAuB,CAAC,CAAC;IAEtC;;;;;;;;OAQG;IAEH,qBAAqB;;;;;;;;MAQgB;IAErC;;;;;OAKG;IAEH,gBAAgB,QAIL,0BAA0B,KAAK,QAAQ,GAAG,CAAC,CAAC;IAEvD;;;;;;;OAOG;IAEH,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC,EAAE,EACrD,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,GACnC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC;IAyD1C;;;;;;;OAOG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAerD;;;;;;OAMG;IAEH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,cAAc;CAQpE"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { OutPoint } from "../../ckb/index.js";
|
|
1
2
|
import { hexFrom } from "../../hex/index.js";
|
|
2
3
|
import { numFrom, numToHex } from "../../num/index.js";
|
|
3
4
|
import { apply } from "../../utils/index.js";
|
|
4
5
|
import { Client } from "../client.js";
|
|
6
|
+
import { ErrorClientBase, ErrorClientResolveUnknown, ErrorClientVerification, } from "../clientTypes.js";
|
|
5
7
|
import { transportFromUri, } from "../transports/advanced.js";
|
|
6
8
|
import { JsonRpcTransformers } from "./advanced.js";
|
|
7
9
|
/**
|
|
@@ -172,7 +174,28 @@ export class ClientJsonRpc extends Client {
|
|
|
172
174
|
const payload = ClientJsonRpc.buildPayload(rpcMethod, await Promise.all(req
|
|
173
175
|
.concat(Array.from(new Array(Math.max(inTransformers.length - req.length, 0))))
|
|
174
176
|
.map((v, i) => transform(v, inTransformers[i]))));
|
|
175
|
-
|
|
177
|
+
try {
|
|
178
|
+
return transform(await this.send(payload), outTransformer);
|
|
179
|
+
}
|
|
180
|
+
catch (errAny) {
|
|
181
|
+
if (typeof errAny !== "object" || errAny === null) {
|
|
182
|
+
throw errAny;
|
|
183
|
+
}
|
|
184
|
+
const err = errAny;
|
|
185
|
+
const unknownOutPointMatch = err.data.match(new RegExp("Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)"))?.[1];
|
|
186
|
+
if (unknownOutPointMatch) {
|
|
187
|
+
throw new ErrorClientResolveUnknown(err, OutPoint.fromBytes(unknownOutPointMatch));
|
|
188
|
+
}
|
|
189
|
+
const verificationFailedMatch = err.data.match(new RegExp("Verification\\(Error { kind: Script, inner: TransactionScriptError { source: (Inputs|Outputs)\\[([0-9]*)\\].(Lock|Type), cause: ValidationFailure: see error code (-?[0-9])* on page https://nervosnetwork\\.github\\.io/ckb-script-error-codes/by-(type|data)-hash/(.*)\\.html"));
|
|
190
|
+
if (verificationFailedMatch) {
|
|
191
|
+
throw new ErrorClientVerification(err, verificationFailedMatch[3] === "Lock"
|
|
192
|
+
? "lock"
|
|
193
|
+
: verificationFailedMatch[1] === "Inputs"
|
|
194
|
+
? "inputType"
|
|
195
|
+
: "outputType", verificationFailedMatch[2], Number(verificationFailedMatch[4]), verificationFailedMatch[5] === "data" ? "data" : "type", verificationFailedMatch[6]);
|
|
196
|
+
}
|
|
197
|
+
throw new ErrorClientBase(err);
|
|
198
|
+
}
|
|
176
199
|
};
|
|
177
200
|
}
|
|
178
201
|
/**
|
|
@@ -20,8 +20,8 @@ export type FixedPointLike = bigint | string | number;
|
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
22
22
|
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
23
|
-
* const strFromString = fixedPointToString("
|
|
24
|
-
* const strFromNumber = fixedPointToString(
|
|
23
|
+
* const strFromString = fixedPointToString("1.23456789", 8); // Outputs "1.23456789"
|
|
24
|
+
* const strFromNumber = fixedPointToString(1.23456789, 8); // Outputs "1.23456789"
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export declare function fixedPointToString(val: FixedPointLike, decimals?: number): string;
|
|
@@ -35,7 +35,7 @@ export declare function fixedPointToString(val: FixedPointLike, decimals?: numbe
|
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* ```typescript
|
|
38
|
-
* const fixedPoint = fixedPointFrom(
|
|
38
|
+
* const fixedPoint = fixedPointFrom(123456789n, 8); // Outputs 123456789n
|
|
39
39
|
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
40
40
|
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
41
41
|
* ```
|
package/dist/fixedPoint/index.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
15
15
|
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
16
|
-
* const strFromString = fixedPointToString("
|
|
17
|
-
* const strFromNumber = fixedPointToString(
|
|
16
|
+
* const strFromString = fixedPointToString("1.23456789", 8); // Outputs "1.23456789"
|
|
17
|
+
* const strFromNumber = fixedPointToString(1.23456789, 8); // Outputs "1.23456789"
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export function fixedPointToString(val, decimals = 8) {
|
|
@@ -39,7 +39,7 @@ export function fixedPointToString(val, decimals = 8) {
|
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ```typescript
|
|
42
|
-
* const fixedPoint = fixedPointFrom(
|
|
42
|
+
* const fixedPoint = fixedPointFrom(123456789n, 8); // Outputs 123456789n
|
|
43
43
|
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
44
44
|
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
45
45
|
* ```
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
2
|
import { HexLike } from "../../hex/index.js";
|
|
3
3
|
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
|
-
export
|
|
5
|
-
markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
6
|
-
markUnusable(...outPointLike: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
4
|
+
export declare abstract class ClientCache {
|
|
5
|
+
abstract markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
6
|
+
abstract markUnusable(...outPointLike: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
7
7
|
markTransactions(...transactionLike: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
abstract clear(): Promise<void>;
|
|
9
|
+
abstract findCells(filter: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
10
|
+
/**
|
|
11
|
+
* Get a known cell by out point
|
|
12
|
+
* @param _outPoint
|
|
13
|
+
*/
|
|
14
|
+
abstract getCell(_outPoint: OutPointLike): Promise<Cell | undefined>;
|
|
15
|
+
abstract isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Record known transactions
|
|
18
|
+
* Implement this method to enable transactions query caching
|
|
19
|
+
* @param _transactions
|
|
20
|
+
*/
|
|
21
|
+
recordTransactions(..._transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a known transaction by hash
|
|
24
|
+
* Implement this method to enable transactions query caching
|
|
25
|
+
* @param _txHash
|
|
26
|
+
*/
|
|
27
|
+
getTransaction(_txHash: HexLike): Promise<Transaction | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Record known cells
|
|
30
|
+
* Implement this method to enable cells query caching
|
|
31
|
+
* @param _cells
|
|
32
|
+
*/
|
|
33
|
+
recordCells(..._cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
14
34
|
}
|
|
15
35
|
//# 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,oBAAoB,CAAC;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5E,
|
|
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,oBAAoB,CAAC;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5E,8BAAsB,WAAW;IAC/B,QAAQ,CAAC,UAAU,CAAC,GAAG,SAAS,EAAE,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3E,QAAQ,CAAC,YAAY,CACnB,GAAG,YAAY,EAAE,CAAC,YAAY,GAAG,YAAY,EAAE,CAAC,EAAE,GACjD,OAAO,CAAC,IAAI,CAAC;IACV,gBAAgB,CACpB,GAAG,eAAe,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GAC1D,OAAO,CAAC,IAAI,CAAC;IAuBhB,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAChB,MAAM,EAAE,8BAA8B,GACrC,cAAc,CAAC,IAAI,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IACpE,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAEjE;;;;OAIG;IACG,kBAAkB,CACtB,GAAG,aAAa,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACxD,OAAO,CAAC,IAAI,CAAC;IAChB;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAIxE;;;;OAIG;IACG,WAAW,CAAC,GAAG,MAAM,EAAE,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CACvE"}
|
|
@@ -1,2 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientCache = void 0;
|
|
4
|
+
const index_js_1 = require("../../ckb/index.js");
|
|
5
|
+
class ClientCache {
|
|
6
|
+
async markTransactions(...transactionLike) {
|
|
7
|
+
await Promise.all([
|
|
8
|
+
this.recordTransactions(...transactionLike),
|
|
9
|
+
...transactionLike.flat().map((transactionLike) => {
|
|
10
|
+
const tx = index_js_1.Transaction.from(transactionLike);
|
|
11
|
+
const txHash = tx.hash();
|
|
12
|
+
return Promise.all([
|
|
13
|
+
...tx.inputs.map((i) => this.markUnusable(i.previousOutput)),
|
|
14
|
+
...tx.outputs.map((o, i) => this.markUsable({
|
|
15
|
+
cellOutput: o,
|
|
16
|
+
outputData: tx.outputsData[i],
|
|
17
|
+
outPoint: {
|
|
18
|
+
txHash,
|
|
19
|
+
index: i,
|
|
20
|
+
},
|
|
21
|
+
})),
|
|
22
|
+
]);
|
|
23
|
+
}),
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Record known transactions
|
|
28
|
+
* Implement this method to enable transactions query caching
|
|
29
|
+
* @param _transactions
|
|
30
|
+
*/
|
|
31
|
+
async recordTransactions(..._transactions) { }
|
|
32
|
+
/**
|
|
33
|
+
* Get a known transaction by hash
|
|
34
|
+
* Implement this method to enable transactions query caching
|
|
35
|
+
* @param _txHash
|
|
36
|
+
*/
|
|
37
|
+
async getTransaction(_txHash) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Record known cells
|
|
42
|
+
* Implement this method to enable cells query caching
|
|
43
|
+
* @param _cells
|
|
44
|
+
*/
|
|
45
|
+
async recordCells(..._cells) { }
|
|
46
|
+
}
|
|
47
|
+
exports.ClientCache = ClientCache;
|
|
@@ -2,19 +2,23 @@ import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../.
|
|
|
2
2
|
import { HexLike } from "../../hex/index.js";
|
|
3
3
|
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
4
|
import { ClientCache } from "./cache.js";
|
|
5
|
-
export declare class ClientCacheMemory
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare class ClientCacheMemory extends ClientCache {
|
|
6
|
+
/**
|
|
7
|
+
* OutPoint => [isLive, Cell | OutPoint]
|
|
8
|
+
*/
|
|
9
|
+
private readonly cells;
|
|
10
|
+
/**
|
|
11
|
+
* TX Hash => Transaction
|
|
12
|
+
*/
|
|
8
13
|
private readonly knownTransactions;
|
|
9
|
-
private readonly knownCells;
|
|
10
14
|
markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void>;
|
|
11
15
|
markUnusable(...outPointLikes: (OutPointLike | OutPointLike[])[]): Promise<void>;
|
|
12
|
-
|
|
16
|
+
clear(): Promise<void>;
|
|
13
17
|
findCells(keyLike: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
18
|
+
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
14
19
|
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
15
20
|
recordTransactions(...transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
16
21
|
getTransaction(txHashLike: HexLike): Promise<Transaction | undefined>;
|
|
17
22
|
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
18
|
-
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
19
23
|
}
|
|
20
24
|
//# 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,EACL,IAAI,EACJ,QAAQ,EAER,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAW,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,qBAAa,iBAAkB,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EAER,YAAY,EACZ,WAAW,EACX,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B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