@ckb-ccc/core 0.0.13-alpha.1 → 0.0.13-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/client/advanced.d.ts +1 -1
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +1 -1
- package/dist/client/cache/advanced.d.ts +2 -0
- package/dist/client/cache/advanced.d.ts.map +1 -0
- package/dist/client/cache/advanced.js +1 -0
- package/dist/client/cache/cache.d.ts +14 -0
- package/dist/client/cache/cache.d.ts.map +1 -0
- package/dist/client/cache/cache.js +1 -0
- package/dist/client/cache/index.d.ts +3 -0
- package/dist/client/cache/index.d.ts.map +1 -0
- package/dist/client/cache/index.js +2 -0
- package/dist/client/{client.advanced.d.ts → cache/memory.advanced.d.ts} +5 -5
- package/dist/client/cache/memory.advanced.d.ts.map +1 -0
- package/dist/client/{client.advanced.js → cache/memory.advanced.js} +6 -6
- package/dist/client/cache/memory.d.ts +19 -0
- package/dist/client/cache/memory.d.ts.map +1 -0
- package/dist/client/cache/memory.js +54 -0
- package/dist/client/client.d.ts +4 -7
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +14 -37
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.d.ts.map +1 -1
- package/dist.commonjs/client/advanced.js +1 -1
- package/dist.commonjs/client/cache/advanced.d.ts +2 -0
- package/dist.commonjs/client/cache/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/cache/advanced.js +17 -0
- package/dist.commonjs/client/cache/cache.d.ts +14 -0
- package/dist.commonjs/client/cache/cache.d.ts.map +1 -0
- package/dist.commonjs/client/cache/cache.js +2 -0
- package/dist.commonjs/client/cache/index.d.ts +3 -0
- package/dist.commonjs/client/cache/index.d.ts.map +1 -0
- package/dist.commonjs/client/cache/index.js +18 -0
- package/dist.commonjs/client/{client.advanced.d.ts → cache/memory.advanced.d.ts} +5 -5
- package/dist.commonjs/client/cache/memory.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/{client.advanced.js → cache/memory.advanced.js} +6 -6
- package/dist.commonjs/client/cache/memory.d.ts +19 -0
- package/dist.commonjs/client/cache/memory.d.ts.map +1 -0
- package/dist.commonjs/client/cache/memory.js +58 -0
- package/dist.commonjs/client/client.d.ts +4 -7
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +14 -37
- package/dist.commonjs/client/index.d.ts +1 -0
- package/dist.commonjs/client/index.d.ts.map +1 -1
- package/dist.commonjs/client/index.js +1 -0
- package/package.json +1 -1
- package/src/client/advanced.ts +1 -1
- package/src/client/cache/advanced.ts +1 -0
- package/src/client/cache/cache.ts +25 -0
- package/src/client/cache/index.ts +2 -0
- package/src/client/{client.advanced.ts → cache/memory.advanced.ts} +6 -6
- package/src/client/cache/memory.ts +75 -0
- package/src/client/client.ts +14 -42
- package/src/client/index.ts +1 -0
- package/dist/client/client.advanced.d.ts.map +0 -1
- package/dist.commonjs/client/client.advanced.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ckb-ccc/core
|
|
2
2
|
|
|
3
|
+
## 0.0.13-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`96dbb61`](https://github.com/ckb-ecofund/ccc/commit/96dbb6107d2071b9383350ddd578557746227054) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(core): custom client cache
|
|
8
|
+
|
|
3
9
|
## 0.0.13-alpha.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC"}
|
package/dist/client/advanced.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./memory.advanced.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../../hex/index.js";
|
|
3
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
|
+
export interface ClientCache {
|
|
5
|
+
markUsable(cellLike: CellLike): Promise<void>;
|
|
6
|
+
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
7
|
+
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
8
|
+
recordTransactions(...transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
9
|
+
getTransaction(txHash: HexLike): Promise<Transaction | undefined>;
|
|
10
|
+
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
11
|
+
getCell(outPoint: OutPointLike): Promise<Cell | undefined>;
|
|
12
|
+
findCells(filter: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +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,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzD,kBAAkB,CAChB,GAAG,YAAY,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACvD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAElE,WAAW,CAAC,GAAG,KAAK,EAAE,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAC3D,SAAS,CAAC,MAAM,EAAE,8BAA8B,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;CACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CellLike, ScriptLike } from "
|
|
2
|
-
import { HexLike } from "
|
|
3
|
-
import { NumLike } from "
|
|
4
|
-
import { ClientCollectableSearchKeyLike } from "
|
|
1
|
+
import { CellLike, ScriptLike } from "../../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../../hex/index.js";
|
|
3
|
+
import { NumLike } from "../../num/index.js";
|
|
4
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
5
5
|
export declare function filterData(dataLike: HexLike, filterLike: HexLike | undefined, filterMode: "exact" | "prefix" | "partial"): boolean;
|
|
6
6
|
export declare function filterScript(valueLike: ScriptLike | undefined, filterLike: ScriptLike | undefined, filterMode: "prefix" | "exact" | "partial"): boolean;
|
|
7
7
|
export declare function filterNumByRange(lengthLike: NumLike, range: [NumLike, NumLike] | undefined): boolean;
|
|
8
8
|
export declare function filterScriptByLenRange(valueLike?: ScriptLike, scriptLenRange?: [NumLike, NumLike]): boolean;
|
|
9
9
|
export declare function filterCell(searchKeyLike: ClientCollectableSearchKeyLike, cellLike: CellLike): boolean;
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=memory.advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,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,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"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { bytesFrom } from "
|
|
2
|
-
import { Cell, Script } from "
|
|
3
|
-
import { hexFrom } from "
|
|
4
|
-
import { numFrom } from "
|
|
5
|
-
import { clientSearchKeyRangeFrom, } from "
|
|
6
|
-
import { ClientIndexerSearchKey } from "
|
|
1
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
2
|
+
import { Cell, Script } from "../../ckb/index.js";
|
|
3
|
+
import { hexFrom } from "../../hex/index.js";
|
|
4
|
+
import { numFrom } from "../../num/index.js";
|
|
5
|
+
import { clientSearchKeyRangeFrom, } from "../clientTypes.advanced.js";
|
|
6
|
+
import { ClientIndexerSearchKey } from "../clientTypes.js";
|
|
7
7
|
export function filterData(dataLike, filterLike, filterMode) {
|
|
8
8
|
if (!filterLike) {
|
|
9
9
|
return true;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../../hex/index.js";
|
|
3
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
|
+
import { ClientCache } from "./cache.js";
|
|
5
|
+
export declare class ClientCacheMemory implements ClientCache {
|
|
6
|
+
private readonly cachedTransactions;
|
|
7
|
+
private readonly unusableOutPoints;
|
|
8
|
+
private readonly usableCells;
|
|
9
|
+
private readonly knownCells;
|
|
10
|
+
markUsable(cellLike: CellLike): Promise<void>;
|
|
11
|
+
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
12
|
+
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
13
|
+
recordTransactions(...transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
14
|
+
getTransaction(txHashLike: HexLike): Promise<Transaction | undefined>;
|
|
15
|
+
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
16
|
+
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
17
|
+
findCells(keyLike: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +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,YAAW,WAAW;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAkB;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IAEnC,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7C,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD,kBAAkB,CACtB,GAAG,YAAY,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACvD,OAAO,CAAC,IAAI,CAAC;IAGV,cAAc,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAKrE,WAAW,CAAC,GAAG,KAAK,EAAE,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAG/D,OAAO,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAK7D,SAAS,CACd,OAAO,EAAE,8BAA8B,GACtC,cAAc,CAAC,IAAI,CAAC;CASxB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Cell, OutPoint, Transaction, } from "../../ckb/index.js";
|
|
2
|
+
import { hexFrom } from "../../hex/index.js";
|
|
3
|
+
import { filterCell } from "./memory.advanced.js";
|
|
4
|
+
export class ClientCacheMemory {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.cachedTransactions = [];
|
|
7
|
+
this.unusableOutPoints = [];
|
|
8
|
+
this.usableCells = [];
|
|
9
|
+
this.knownCells = [];
|
|
10
|
+
}
|
|
11
|
+
async markUsable(cellLike) {
|
|
12
|
+
const cell = Cell.from(cellLike).clone();
|
|
13
|
+
this.usableCells.push(cell);
|
|
14
|
+
this.knownCells.push(cell);
|
|
15
|
+
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
16
|
+
if (index !== -1) {
|
|
17
|
+
this.unusableOutPoints.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async markUnusable(outPointLike) {
|
|
21
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
22
|
+
this.unusableOutPoints.push(outPoint.clone());
|
|
23
|
+
const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
|
|
24
|
+
if (index !== -1) {
|
|
25
|
+
this.usableCells.splice(index, 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async isUnusable(outPointLike) {
|
|
29
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
30
|
+
return this.unusableOutPoints.find((o) => o.eq(outPoint)) !== undefined;
|
|
31
|
+
}
|
|
32
|
+
async recordTransactions(...transactions) {
|
|
33
|
+
this.cachedTransactions.push(...transactions.flat().map(Transaction.from));
|
|
34
|
+
}
|
|
35
|
+
async getTransaction(txHashLike) {
|
|
36
|
+
const txHash = hexFrom(txHashLike);
|
|
37
|
+
return this.cachedTransactions.find((tx) => tx.hash() === txHash);
|
|
38
|
+
}
|
|
39
|
+
async recordCells(...cells) {
|
|
40
|
+
this.usableCells.push(...cells.flat().map(Cell.from));
|
|
41
|
+
}
|
|
42
|
+
async getCell(outPointLike) {
|
|
43
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
44
|
+
return this.usableCells.find((cell) => cell.outPoint.eq(outPoint));
|
|
45
|
+
}
|
|
46
|
+
async *findCells(keyLike) {
|
|
47
|
+
for (const cell of this.usableCells) {
|
|
48
|
+
if (!filterCell(keyLike, cell)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
yield cell;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/client/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Cell, CellDep, CellDepLike,
|
|
1
|
+
import { Cell, CellDep, CellDepLike, OutPointLike, Script, ScriptLike, TransactionLike } from "../ckb/index.js";
|
|
2
2
|
import { Hex, HexLike } from "../hex/index.js";
|
|
3
3
|
import { Num, NumLike } from "../num/index.js";
|
|
4
|
+
import { ClientCache } from "./cache/index.js";
|
|
4
5
|
import { ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
|
|
5
6
|
import { ClientBlock, ClientFindCellsResponse, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse, ClientIndexerSearchKeyLike, ClientIndexerSearchKeyTransactionLike, ClientTransactionResponse, OutputsValidator } from "./clientTypes.js";
|
|
6
7
|
/**
|
|
@@ -41,10 +42,8 @@ export declare class CellDepInfo {
|
|
|
41
42
|
* @public
|
|
42
43
|
*/
|
|
43
44
|
export declare abstract class Client {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
private readonly usableCells;
|
|
47
|
-
private readonly knownCells;
|
|
45
|
+
cache: ClientCache;
|
|
46
|
+
constructor(cache?: ClientCache);
|
|
48
47
|
abstract get url(): string;
|
|
49
48
|
abstract get addressPrefix(): string;
|
|
50
49
|
abstract getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType"> & {
|
|
@@ -53,8 +52,6 @@ export declare abstract class Client {
|
|
|
53
52
|
abstract getTip(): Promise<Num>;
|
|
54
53
|
abstract getBlockByNumber(blockNumber: NumLike, verbosity?: number | null, withCycles?: boolean | null): Promise<ClientBlock | undefined>;
|
|
55
54
|
abstract getBlockByHash(blockHash: HexLike, verbosity?: number | null, withCycles?: boolean | null): Promise<ClientBlock | undefined>;
|
|
56
|
-
markUsable(cellLike: CellLike): Promise<void>;
|
|
57
|
-
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
58
55
|
abstract sendTransactionNoCache(transaction: TransactionLike, validator?: OutputsValidator): Promise<Hex>;
|
|
59
56
|
abstract getTransactionNoCache(txHash: HexLike): Promise<ClientTransactionResponse | undefined>;
|
|
60
57
|
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,WAAW,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,WAAW,EAEX,YAAY,EACZ,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,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,EACtB,KAAK,CAAC,EAAE,MAAM,GACb,cAAc,CACb,8BAA8B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GACjD,qCAAqC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAC3D;IAsBD,QAAQ,CAAC,gBAAgB,CAAC,GAAG,EAAE,0BAA0B,GAAG,OAAO,CAAC,GAAG,CAAC;IAElE,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC;IAYhD,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAQ7C,eAAe,CACnB,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC;IAwBT,cAAc,CAClB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC;CAwBlD"}
|
package/dist/client/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Zero } from "../fixedPoint/index.js";
|
|
|
3
3
|
import { hexFrom } from "../hex/index.js";
|
|
4
4
|
import { numFrom } from "../num/index.js";
|
|
5
5
|
import { apply, reduceAsync } from "../utils/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ClientCacheMemory } from "./cache/memory.js";
|
|
7
7
|
import { ClientIndexerSearchKey, } from "./clientTypes.js";
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
@@ -40,34 +40,14 @@ export class CellDepInfo {
|
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
42
|
export class Client {
|
|
43
|
-
constructor() {
|
|
44
|
-
this.
|
|
45
|
-
this.unusableOutPoints = [];
|
|
46
|
-
this.usableCells = [];
|
|
47
|
-
this.knownCells = [];
|
|
48
|
-
}
|
|
49
|
-
async markUsable(cellLike) {
|
|
50
|
-
const cell = Cell.from(cellLike).clone();
|
|
51
|
-
this.usableCells.push(cell);
|
|
52
|
-
this.knownCells.push(cell);
|
|
53
|
-
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
54
|
-
if (index !== -1) {
|
|
55
|
-
this.unusableOutPoints.splice(index, 1);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async markUnusable(outPointLike) {
|
|
59
|
-
const outPoint = OutPoint.from(outPointLike);
|
|
60
|
-
this.unusableOutPoints.push(outPoint.clone());
|
|
61
|
-
const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
|
|
62
|
-
if (index !== -1) {
|
|
63
|
-
this.usableCells.splice(index, 1);
|
|
64
|
-
}
|
|
43
|
+
constructor(cache = new ClientCacheMemory()) {
|
|
44
|
+
this.cache = cache;
|
|
65
45
|
}
|
|
66
46
|
async getCell(outPointLike) {
|
|
67
47
|
const outPoint = OutPoint.from(outPointLike);
|
|
68
|
-
const cached = this.
|
|
48
|
+
const cached = await this.cache.getCell(outPoint);
|
|
69
49
|
if (cached) {
|
|
70
|
-
return cached
|
|
50
|
+
return cached;
|
|
71
51
|
}
|
|
72
52
|
const transaction = await this.getTransactionNoCache(outPoint.txHash);
|
|
73
53
|
if (!transaction) {
|
|
@@ -82,12 +62,12 @@ export class Client {
|
|
|
82
62
|
cellOutput: transaction.transaction.outputs[index],
|
|
83
63
|
outputData: transaction.transaction.outputsData[index] ?? "0x",
|
|
84
64
|
});
|
|
85
|
-
this.
|
|
86
|
-
return cell
|
|
65
|
+
await this.cache.recordCells(cell);
|
|
66
|
+
return cell;
|
|
87
67
|
}
|
|
88
68
|
async findCellsPaged(key, order, limit, after) {
|
|
89
69
|
const res = await this.findCellsPagedNoCache(key, order, limit, after);
|
|
90
|
-
this.
|
|
70
|
+
await this.cache.recordCells(res.cells);
|
|
91
71
|
return res;
|
|
92
72
|
}
|
|
93
73
|
async *findCells(key, order, limit = 10) {
|
|
@@ -112,15 +92,12 @@ export class Client {
|
|
|
112
92
|
async *findCellsByCollectableSearchKey(keyLike, order, limit = 10) {
|
|
113
93
|
const key = ClientIndexerSearchKey.from(keyLike);
|
|
114
94
|
const foundedOutPoints = [];
|
|
115
|
-
for (const cell of this.
|
|
116
|
-
if (!filterCell(key, cell)) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
95
|
+
for await (const cell of this.cache.findCells(key)) {
|
|
119
96
|
foundedOutPoints.push(cell.outPoint);
|
|
120
97
|
yield cell;
|
|
121
98
|
}
|
|
122
99
|
for await (const cell of this.findCells(key, order, limit)) {
|
|
123
|
-
if (this.
|
|
100
|
+
if ((await this.cache.isUnusable(cell.outPoint)) ||
|
|
124
101
|
foundedOutPoints.some((founded) => founded.eq(cell.outPoint))) {
|
|
125
102
|
continue;
|
|
126
103
|
}
|
|
@@ -216,9 +193,9 @@ export class Client {
|
|
|
216
193
|
async sendTransaction(transaction, validator) {
|
|
217
194
|
const tx = Transaction.from(transaction);
|
|
218
195
|
const txHash = await this.sendTransactionNoCache(tx, validator);
|
|
219
|
-
this.
|
|
220
|
-
await Promise.all(tx.inputs.map((i) => this.markUnusable(i.previousOutput)));
|
|
221
|
-
await Promise.all(tx.outputs.map((o, i) => this.markUsable({
|
|
196
|
+
await this.cache.recordTransactions(tx);
|
|
197
|
+
await Promise.all(tx.inputs.map((i) => this.cache.markUnusable(i.previousOutput)));
|
|
198
|
+
await Promise.all(tx.outputs.map((o, i) => this.cache.markUsable({
|
|
222
199
|
cellOutput: o,
|
|
223
200
|
outputData: tx.outputsData[i],
|
|
224
201
|
outPoint: {
|
|
@@ -234,7 +211,7 @@ export class Client {
|
|
|
234
211
|
if (res?.transaction) {
|
|
235
212
|
return res;
|
|
236
213
|
}
|
|
237
|
-
const tx = this.
|
|
214
|
+
const tx = await this.cache.getTransaction(txHash);
|
|
238
215
|
if (!tx) {
|
|
239
216
|
return;
|
|
240
217
|
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC"}
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./cache/advanced.js"), exports);
|
|
18
18
|
__exportStar(require("./clientPublicMainnet.advanced.js"), exports);
|
|
19
19
|
__exportStar(require("./clientPublicTestnet.advanced.js"), exports);
|
|
20
20
|
__exportStar(require("./clientTypes.advanced.js"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./memory.advanced.js"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../../hex/index.js";
|
|
3
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
|
+
export interface ClientCache {
|
|
5
|
+
markUsable(cellLike: CellLike): Promise<void>;
|
|
6
|
+
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
7
|
+
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
8
|
+
recordTransactions(...transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
9
|
+
getTransaction(txHash: HexLike): Promise<Transaction | undefined>;
|
|
10
|
+
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
11
|
+
getCell(outPoint: OutPointLike): Promise<Cell | undefined>;
|
|
12
|
+
findCells(filter: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +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,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzD,kBAAkB,CAChB,GAAG,YAAY,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACvD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAElE,WAAW,CAAC,GAAG,KAAK,EAAE,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAC3D,SAAS,CAAC,MAAM,EAAE,8BAA8B,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;CACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cache.js"), exports);
|
|
18
|
+
__exportStar(require("./memory.js"), exports);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CellLike, ScriptLike } from "
|
|
2
|
-
import { HexLike } from "
|
|
3
|
-
import { NumLike } from "
|
|
4
|
-
import { ClientCollectableSearchKeyLike } from "
|
|
1
|
+
import { CellLike, ScriptLike } from "../../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../../hex/index.js";
|
|
3
|
+
import { NumLike } from "../../num/index.js";
|
|
4
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
5
5
|
export declare function filterData(dataLike: HexLike, filterLike: HexLike | undefined, filterMode: "exact" | "prefix" | "partial"): boolean;
|
|
6
6
|
export declare function filterScript(valueLike: ScriptLike | undefined, filterLike: ScriptLike | undefined, filterMode: "prefix" | "exact" | "partial"): boolean;
|
|
7
7
|
export declare function filterNumByRange(lengthLike: NumLike, range: [NumLike, NumLike] | undefined): boolean;
|
|
8
8
|
export declare function filterScriptByLenRange(valueLike?: ScriptLike, scriptLenRange?: [NumLike, NumLike]): boolean;
|
|
9
9
|
export declare function filterCell(searchKeyLike: ClientCollectableSearchKeyLike, cellLike: CellLike): boolean;
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=memory.advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.advanced.d.ts","sourceRoot":"","sources":["../../../src/client/cache/memory.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,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,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"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.filterCell = exports.filterScriptByLenRange = exports.filterNumByRange = exports.filterScript = exports.filterData = void 0;
|
|
4
|
-
const index_js_1 = require("
|
|
5
|
-
const index_js_2 = require("
|
|
6
|
-
const index_js_3 = require("
|
|
7
|
-
const index_js_4 = require("
|
|
8
|
-
const clientTypes_advanced_js_1 = require("
|
|
9
|
-
const clientTypes_js_1 = require("
|
|
4
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
5
|
+
const index_js_2 = require("../../ckb/index.js");
|
|
6
|
+
const index_js_3 = require("../../hex/index.js");
|
|
7
|
+
const index_js_4 = require("../../num/index.js");
|
|
8
|
+
const clientTypes_advanced_js_1 = require("../clientTypes.advanced.js");
|
|
9
|
+
const clientTypes_js_1 = require("../clientTypes.js");
|
|
10
10
|
function filterData(dataLike, filterLike, filterMode) {
|
|
11
11
|
if (!filterLike) {
|
|
12
12
|
return true;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Cell, CellLike, OutPointLike, Transaction, TransactionLike } from "../../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../../hex/index.js";
|
|
3
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
4
|
+
import { ClientCache } from "./cache.js";
|
|
5
|
+
export declare class ClientCacheMemory implements ClientCache {
|
|
6
|
+
private readonly cachedTransactions;
|
|
7
|
+
private readonly unusableOutPoints;
|
|
8
|
+
private readonly usableCells;
|
|
9
|
+
private readonly knownCells;
|
|
10
|
+
markUsable(cellLike: CellLike): Promise<void>;
|
|
11
|
+
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
12
|
+
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
13
|
+
recordTransactions(...transactions: (TransactionLike | TransactionLike[])[]): Promise<void>;
|
|
14
|
+
getTransaction(txHashLike: HexLike): Promise<Transaction | undefined>;
|
|
15
|
+
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
16
|
+
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
17
|
+
findCells(keyLike: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +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,YAAW,WAAW;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAkB;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IAEnC,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7C,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxD,kBAAkB,CACtB,GAAG,YAAY,EAAE,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,EAAE,GACvD,OAAO,CAAC,IAAI,CAAC;IAGV,cAAc,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAKrE,WAAW,CAAC,GAAG,KAAK,EAAE,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAG/D,OAAO,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAK7D,SAAS,CACd,OAAO,EAAE,8BAA8B,GACtC,cAAc,CAAC,IAAI,CAAC;CASxB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientCacheMemory = void 0;
|
|
4
|
+
const index_js_1 = require("../../ckb/index.js");
|
|
5
|
+
const index_js_2 = require("../../hex/index.js");
|
|
6
|
+
const memory_advanced_js_1 = require("./memory.advanced.js");
|
|
7
|
+
class ClientCacheMemory {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.cachedTransactions = [];
|
|
10
|
+
this.unusableOutPoints = [];
|
|
11
|
+
this.usableCells = [];
|
|
12
|
+
this.knownCells = [];
|
|
13
|
+
}
|
|
14
|
+
async markUsable(cellLike) {
|
|
15
|
+
const cell = index_js_1.Cell.from(cellLike).clone();
|
|
16
|
+
this.usableCells.push(cell);
|
|
17
|
+
this.knownCells.push(cell);
|
|
18
|
+
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
19
|
+
if (index !== -1) {
|
|
20
|
+
this.unusableOutPoints.splice(index, 1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async markUnusable(outPointLike) {
|
|
24
|
+
const outPoint = index_js_1.OutPoint.from(outPointLike);
|
|
25
|
+
this.unusableOutPoints.push(outPoint.clone());
|
|
26
|
+
const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
|
|
27
|
+
if (index !== -1) {
|
|
28
|
+
this.usableCells.splice(index, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async isUnusable(outPointLike) {
|
|
32
|
+
const outPoint = index_js_1.OutPoint.from(outPointLike);
|
|
33
|
+
return this.unusableOutPoints.find((o) => o.eq(outPoint)) !== undefined;
|
|
34
|
+
}
|
|
35
|
+
async recordTransactions(...transactions) {
|
|
36
|
+
this.cachedTransactions.push(...transactions.flat().map(index_js_1.Transaction.from));
|
|
37
|
+
}
|
|
38
|
+
async getTransaction(txHashLike) {
|
|
39
|
+
const txHash = (0, index_js_2.hexFrom)(txHashLike);
|
|
40
|
+
return this.cachedTransactions.find((tx) => tx.hash() === txHash);
|
|
41
|
+
}
|
|
42
|
+
async recordCells(...cells) {
|
|
43
|
+
this.usableCells.push(...cells.flat().map(index_js_1.Cell.from));
|
|
44
|
+
}
|
|
45
|
+
async getCell(outPointLike) {
|
|
46
|
+
const outPoint = index_js_1.OutPoint.from(outPointLike);
|
|
47
|
+
return this.usableCells.find((cell) => cell.outPoint.eq(outPoint));
|
|
48
|
+
}
|
|
49
|
+
async *findCells(keyLike) {
|
|
50
|
+
for (const cell of this.usableCells) {
|
|
51
|
+
if (!(0, memory_advanced_js_1.filterCell)(keyLike, cell)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
yield cell;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ClientCacheMemory = ClientCacheMemory;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Cell, CellDep, CellDepLike,
|
|
1
|
+
import { Cell, CellDep, CellDepLike, OutPointLike, Script, ScriptLike, TransactionLike } from "../ckb/index.js";
|
|
2
2
|
import { Hex, HexLike } from "../hex/index.js";
|
|
3
3
|
import { Num, NumLike } from "../num/index.js";
|
|
4
|
+
import { ClientCache } from "./cache/index.js";
|
|
4
5
|
import { ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
|
|
5
6
|
import { ClientBlock, ClientFindCellsResponse, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse, ClientIndexerSearchKeyLike, ClientIndexerSearchKeyTransactionLike, ClientTransactionResponse, OutputsValidator } from "./clientTypes.js";
|
|
6
7
|
/**
|
|
@@ -41,10 +42,8 @@ export declare class CellDepInfo {
|
|
|
41
42
|
* @public
|
|
42
43
|
*/
|
|
43
44
|
export declare abstract class Client {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
private readonly usableCells;
|
|
47
|
-
private readonly knownCells;
|
|
45
|
+
cache: ClientCache;
|
|
46
|
+
constructor(cache?: ClientCache);
|
|
48
47
|
abstract get url(): string;
|
|
49
48
|
abstract get addressPrefix(): string;
|
|
50
49
|
abstract getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType"> & {
|
|
@@ -53,8 +52,6 @@ export declare abstract class Client {
|
|
|
53
52
|
abstract getTip(): Promise<Num>;
|
|
54
53
|
abstract getBlockByNumber(blockNumber: NumLike, verbosity?: number | null, withCycles?: boolean | null): Promise<ClientBlock | undefined>;
|
|
55
54
|
abstract getBlockByHash(blockHash: HexLike, verbosity?: number | null, withCycles?: boolean | null): Promise<ClientBlock | undefined>;
|
|
56
|
-
markUsable(cellLike: CellLike): Promise<void>;
|
|
57
|
-
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
58
55
|
abstract sendTransactionNoCache(transaction: TransactionLike, validator?: OutputsValidator): Promise<Hex>;
|
|
59
56
|
abstract getTransactionNoCache(txHash: HexLike): Promise<ClientTransactionResponse | undefined>;
|
|
60
57
|
getCell(outPointLike: OutPointLike): Promise<Cell | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,WAAW,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,WAAW,EAEX,YAAY,E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EACnC,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,EACtB,KAAK,CAAC,EAAE,MAAM,GACb,cAAc,CACb,8BAA8B,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GACjD,qCAAqC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAC3D;IAsBD,QAAQ,CAAC,gBAAgB,CAAC,GAAG,EAAE,0BAA0B,GAAG,OAAO,CAAC,GAAG,CAAC;IAElE,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC;IAYhD,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAQ7C,eAAe,CACnB,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC;IAwBT,cAAc,CAClB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC;CAwBlD"}
|
|
@@ -6,7 +6,7 @@ const index_js_2 = require("../fixedPoint/index.js");
|
|
|
6
6
|
const index_js_3 = require("../hex/index.js");
|
|
7
7
|
const index_js_4 = require("../num/index.js");
|
|
8
8
|
const index_js_5 = require("../utils/index.js");
|
|
9
|
-
const
|
|
9
|
+
const memory_js_1 = require("./cache/memory.js");
|
|
10
10
|
const clientTypes_js_1 = require("./clientTypes.js");
|
|
11
11
|
/**
|
|
12
12
|
* @public
|
|
@@ -44,34 +44,14 @@ exports.CellDepInfo = CellDepInfo;
|
|
|
44
44
|
* @public
|
|
45
45
|
*/
|
|
46
46
|
class Client {
|
|
47
|
-
constructor() {
|
|
48
|
-
this.
|
|
49
|
-
this.unusableOutPoints = [];
|
|
50
|
-
this.usableCells = [];
|
|
51
|
-
this.knownCells = [];
|
|
52
|
-
}
|
|
53
|
-
async markUsable(cellLike) {
|
|
54
|
-
const cell = index_js_1.Cell.from(cellLike).clone();
|
|
55
|
-
this.usableCells.push(cell);
|
|
56
|
-
this.knownCells.push(cell);
|
|
57
|
-
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
58
|
-
if (index !== -1) {
|
|
59
|
-
this.unusableOutPoints.splice(index, 1);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async markUnusable(outPointLike) {
|
|
63
|
-
const outPoint = index_js_1.OutPoint.from(outPointLike);
|
|
64
|
-
this.unusableOutPoints.push(outPoint.clone());
|
|
65
|
-
const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
|
|
66
|
-
if (index !== -1) {
|
|
67
|
-
this.usableCells.splice(index, 1);
|
|
68
|
-
}
|
|
47
|
+
constructor(cache = new memory_js_1.ClientCacheMemory()) {
|
|
48
|
+
this.cache = cache;
|
|
69
49
|
}
|
|
70
50
|
async getCell(outPointLike) {
|
|
71
51
|
const outPoint = index_js_1.OutPoint.from(outPointLike);
|
|
72
|
-
const cached = this.
|
|
52
|
+
const cached = await this.cache.getCell(outPoint);
|
|
73
53
|
if (cached) {
|
|
74
|
-
return cached
|
|
54
|
+
return cached;
|
|
75
55
|
}
|
|
76
56
|
const transaction = await this.getTransactionNoCache(outPoint.txHash);
|
|
77
57
|
if (!transaction) {
|
|
@@ -86,12 +66,12 @@ class Client {
|
|
|
86
66
|
cellOutput: transaction.transaction.outputs[index],
|
|
87
67
|
outputData: transaction.transaction.outputsData[index] ?? "0x",
|
|
88
68
|
});
|
|
89
|
-
this.
|
|
90
|
-
return cell
|
|
69
|
+
await this.cache.recordCells(cell);
|
|
70
|
+
return cell;
|
|
91
71
|
}
|
|
92
72
|
async findCellsPaged(key, order, limit, after) {
|
|
93
73
|
const res = await this.findCellsPagedNoCache(key, order, limit, after);
|
|
94
|
-
this.
|
|
74
|
+
await this.cache.recordCells(res.cells);
|
|
95
75
|
return res;
|
|
96
76
|
}
|
|
97
77
|
async *findCells(key, order, limit = 10) {
|
|
@@ -116,15 +96,12 @@ class Client {
|
|
|
116
96
|
async *findCellsByCollectableSearchKey(keyLike, order, limit = 10) {
|
|
117
97
|
const key = clientTypes_js_1.ClientIndexerSearchKey.from(keyLike);
|
|
118
98
|
const foundedOutPoints = [];
|
|
119
|
-
for (const cell of this.
|
|
120
|
-
if (!(0, client_advanced_js_1.filterCell)(key, cell)) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
99
|
+
for await (const cell of this.cache.findCells(key)) {
|
|
123
100
|
foundedOutPoints.push(cell.outPoint);
|
|
124
101
|
yield cell;
|
|
125
102
|
}
|
|
126
103
|
for await (const cell of this.findCells(key, order, limit)) {
|
|
127
|
-
if (this.
|
|
104
|
+
if ((await this.cache.isUnusable(cell.outPoint)) ||
|
|
128
105
|
foundedOutPoints.some((founded) => founded.eq(cell.outPoint))) {
|
|
129
106
|
continue;
|
|
130
107
|
}
|
|
@@ -220,9 +197,9 @@ class Client {
|
|
|
220
197
|
async sendTransaction(transaction, validator) {
|
|
221
198
|
const tx = index_js_1.Transaction.from(transaction);
|
|
222
199
|
const txHash = await this.sendTransactionNoCache(tx, validator);
|
|
223
|
-
this.
|
|
224
|
-
await Promise.all(tx.inputs.map((i) => this.markUnusable(i.previousOutput)));
|
|
225
|
-
await Promise.all(tx.outputs.map((o, i) => this.markUsable({
|
|
200
|
+
await this.cache.recordTransactions(tx);
|
|
201
|
+
await Promise.all(tx.inputs.map((i) => this.cache.markUnusable(i.previousOutput)));
|
|
202
|
+
await Promise.all(tx.outputs.map((o, i) => this.cache.markUsable({
|
|
226
203
|
cellOutput: o,
|
|
227
204
|
outputData: tx.outputsData[i],
|
|
228
205
|
outPoint: {
|
|
@@ -238,7 +215,7 @@ class Client {
|
|
|
238
215
|
if (res?.transaction) {
|
|
239
216
|
return res;
|
|
240
217
|
}
|
|
241
|
-
const tx = this.
|
|
218
|
+
const tx = await this.cache.getTransaction(txHash);
|
|
242
219
|
if (!tx) {
|
|
243
220
|
return;
|
|
244
221
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cache/index.js"), exports);
|
|
17
18
|
__exportStar(require("./client.js"), exports);
|
|
18
19
|
__exportStar(require("./clientPublicMainnet.js"), exports);
|
|
19
20
|
__exportStar(require("./clientPublicTestnet.js"), exports);
|
package/package.json
CHANGED
package/src/client/advanced.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./memory.advanced.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cell,
|
|
3
|
+
CellLike,
|
|
4
|
+
OutPointLike,
|
|
5
|
+
Transaction,
|
|
6
|
+
TransactionLike,
|
|
7
|
+
} from "../../ckb/index.js";
|
|
8
|
+
import { HexLike } from "../../hex/index.js";
|
|
9
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
10
|
+
|
|
11
|
+
export interface ClientCache {
|
|
12
|
+
markUsable(cellLike: CellLike): Promise<void>;
|
|
13
|
+
markUnusable(outPointLike: OutPointLike): Promise<void>;
|
|
14
|
+
|
|
15
|
+
isUnusable(outPointLike: OutPointLike): Promise<boolean>;
|
|
16
|
+
|
|
17
|
+
recordTransactions(
|
|
18
|
+
...transactions: (TransactionLike | TransactionLike[])[]
|
|
19
|
+
): Promise<void>;
|
|
20
|
+
getTransaction(txHash: HexLike): Promise<Transaction | undefined>;
|
|
21
|
+
|
|
22
|
+
recordCells(...cells: (CellLike | CellLike[])[]): Promise<void>;
|
|
23
|
+
getCell(outPoint: OutPointLike): Promise<Cell | undefined>;
|
|
24
|
+
findCells(filter: ClientCollectableSearchKeyLike): AsyncGenerator<Cell>;
|
|
25
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { bytesFrom } from "
|
|
2
|
-
import { Cell, CellLike, Script, ScriptLike } from "
|
|
3
|
-
import { HexLike, hexFrom } from "
|
|
4
|
-
import { NumLike, numFrom } from "
|
|
1
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
2
|
+
import { Cell, CellLike, Script, ScriptLike } from "../../ckb/index.js";
|
|
3
|
+
import { HexLike, hexFrom } from "../../hex/index.js";
|
|
4
|
+
import { NumLike, numFrom } from "../../num/index.js";
|
|
5
5
|
import {
|
|
6
6
|
ClientCollectableSearchKeyLike,
|
|
7
7
|
clientSearchKeyRangeFrom,
|
|
8
|
-
} from "
|
|
9
|
-
import { ClientIndexerSearchKey } from "
|
|
8
|
+
} from "../clientTypes.advanced.js";
|
|
9
|
+
import { ClientIndexerSearchKey } from "../clientTypes.js";
|
|
10
10
|
|
|
11
11
|
export function filterData(
|
|
12
12
|
dataLike: HexLike,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cell,
|
|
3
|
+
CellLike,
|
|
4
|
+
OutPoint,
|
|
5
|
+
OutPointLike,
|
|
6
|
+
Transaction,
|
|
7
|
+
TransactionLike,
|
|
8
|
+
} from "../../ckb/index.js";
|
|
9
|
+
import { HexLike, hexFrom } from "../../hex/index.js";
|
|
10
|
+
import { ClientCollectableSearchKeyLike } from "../clientTypes.advanced.js";
|
|
11
|
+
import { ClientCache } from "./cache.js";
|
|
12
|
+
import { filterCell } from "./memory.advanced.js";
|
|
13
|
+
|
|
14
|
+
export class ClientCacheMemory implements ClientCache {
|
|
15
|
+
private readonly cachedTransactions: Transaction[] = [];
|
|
16
|
+
private readonly unusableOutPoints: OutPoint[] = [];
|
|
17
|
+
private readonly usableCells: Cell[] = [];
|
|
18
|
+
private readonly knownCells: Cell[] = [];
|
|
19
|
+
|
|
20
|
+
async markUsable(cellLike: CellLike): Promise<void> {
|
|
21
|
+
const cell = Cell.from(cellLike).clone();
|
|
22
|
+
this.usableCells.push(cell);
|
|
23
|
+
this.knownCells.push(cell);
|
|
24
|
+
|
|
25
|
+
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
26
|
+
if (index !== -1) {
|
|
27
|
+
this.unusableOutPoints.splice(index, 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async markUnusable(outPointLike: OutPointLike): Promise<void> {
|
|
32
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
33
|
+
this.unusableOutPoints.push(outPoint.clone());
|
|
34
|
+
|
|
35
|
+
const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
|
|
36
|
+
if (index !== -1) {
|
|
37
|
+
this.usableCells.splice(index, 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async isUnusable(outPointLike: OutPointLike): Promise<boolean> {
|
|
42
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
43
|
+
return this.unusableOutPoints.find((o) => o.eq(outPoint)) !== undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async recordTransactions(
|
|
47
|
+
...transactions: (TransactionLike | TransactionLike[])[]
|
|
48
|
+
): Promise<void> {
|
|
49
|
+
this.cachedTransactions.push(...transactions.flat().map(Transaction.from));
|
|
50
|
+
}
|
|
51
|
+
async getTransaction(txHashLike: HexLike): Promise<Transaction | undefined> {
|
|
52
|
+
const txHash = hexFrom(txHashLike);
|
|
53
|
+
return this.cachedTransactions.find((tx) => tx.hash() === txHash);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async recordCells(...cells: (CellLike | CellLike[])[]): Promise<void> {
|
|
57
|
+
this.usableCells.push(...cells.flat().map(Cell.from));
|
|
58
|
+
}
|
|
59
|
+
async getCell(outPointLike: OutPointLike): Promise<Cell | undefined> {
|
|
60
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
61
|
+
return this.usableCells.find((cell) => cell.outPoint.eq(outPoint));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async *findCells(
|
|
65
|
+
keyLike: ClientCollectableSearchKeyLike,
|
|
66
|
+
): AsyncGenerator<Cell> {
|
|
67
|
+
for (const cell of this.usableCells) {
|
|
68
|
+
if (!filterCell(keyLike, cell)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
yield cell;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/client/client.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
Cell,
|
|
3
3
|
CellDep,
|
|
4
4
|
CellDepLike,
|
|
5
|
-
CellLike,
|
|
6
5
|
OutPoint,
|
|
7
6
|
OutPointLike,
|
|
8
7
|
Script,
|
|
@@ -14,7 +13,8 @@ import { Zero } from "../fixedPoint/index.js";
|
|
|
14
13
|
import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
15
14
|
import { Num, NumLike, numFrom } from "../num/index.js";
|
|
16
15
|
import { apply, reduceAsync } from "../utils/index.js";
|
|
17
|
-
import {
|
|
16
|
+
import { ClientCache } from "./cache/index.js";
|
|
17
|
+
import { ClientCacheMemory } from "./cache/memory.js";
|
|
18
18
|
import { ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
|
|
19
19
|
import {
|
|
20
20
|
ClientBlock,
|
|
@@ -76,10 +76,7 @@ export class CellDepInfo {
|
|
|
76
76
|
* @public
|
|
77
77
|
*/
|
|
78
78
|
export abstract class Client {
|
|
79
|
-
|
|
80
|
-
private readonly unusableOutPoints: OutPoint[] = [];
|
|
81
|
-
private readonly usableCells: Cell[] = [];
|
|
82
|
-
private readonly knownCells: Cell[] = [];
|
|
79
|
+
constructor(public cache: ClientCache = new ClientCacheMemory()) {}
|
|
83
80
|
|
|
84
81
|
abstract get url(): string;
|
|
85
82
|
abstract get addressPrefix(): string;
|
|
@@ -102,27 +99,6 @@ export abstract class Client {
|
|
|
102
99
|
withCycles?: boolean | null,
|
|
103
100
|
): Promise<ClientBlock | undefined>;
|
|
104
101
|
|
|
105
|
-
async markUsable(cellLike: CellLike): Promise<void> {
|
|
106
|
-
const cell = Cell.from(cellLike).clone();
|
|
107
|
-
this.usableCells.push(cell);
|
|
108
|
-
this.knownCells.push(cell);
|
|
109
|
-
|
|
110
|
-
const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
|
|
111
|
-
if (index !== -1) {
|
|
112
|
-
this.unusableOutPoints.splice(index, 1);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async markUnusable(outPointLike: OutPointLike): Promise<void> {
|
|
117
|
-
const outPoint = OutPoint.from(outPointLike);
|
|
118
|
-
this.unusableOutPoints.push(outPoint.clone());
|
|
119
|
-
|
|
120
|
-
const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
|
|
121
|
-
if (index !== -1) {
|
|
122
|
-
this.usableCells.splice(index, 1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
102
|
abstract sendTransactionNoCache(
|
|
127
103
|
transaction: TransactionLike,
|
|
128
104
|
validator?: OutputsValidator,
|
|
@@ -133,10 +109,10 @@ export abstract class Client {
|
|
|
133
109
|
|
|
134
110
|
async getCell(outPointLike: OutPointLike): Promise<Cell | undefined> {
|
|
135
111
|
const outPoint = OutPoint.from(outPointLike);
|
|
136
|
-
const cached = this.
|
|
112
|
+
const cached = await this.cache.getCell(outPoint);
|
|
137
113
|
|
|
138
114
|
if (cached) {
|
|
139
|
-
return cached
|
|
115
|
+
return cached;
|
|
140
116
|
}
|
|
141
117
|
|
|
142
118
|
const transaction = await this.getTransactionNoCache(outPoint.txHash);
|
|
@@ -154,8 +130,8 @@ export abstract class Client {
|
|
|
154
130
|
cellOutput: transaction.transaction.outputs[index],
|
|
155
131
|
outputData: transaction.transaction.outputsData[index] ?? "0x",
|
|
156
132
|
});
|
|
157
|
-
this.
|
|
158
|
-
return cell
|
|
133
|
+
await this.cache.recordCells(cell);
|
|
134
|
+
return cell;
|
|
159
135
|
}
|
|
160
136
|
|
|
161
137
|
abstract findCellsPagedNoCache(
|
|
@@ -171,7 +147,7 @@ export abstract class Client {
|
|
|
171
147
|
after?: string,
|
|
172
148
|
): Promise<ClientFindCellsResponse> {
|
|
173
149
|
const res = await this.findCellsPagedNoCache(key, order, limit, after);
|
|
174
|
-
this.
|
|
150
|
+
await this.cache.recordCells(res.cells);
|
|
175
151
|
return res;
|
|
176
152
|
}
|
|
177
153
|
|
|
@@ -213,18 +189,14 @@ export abstract class Client {
|
|
|
213
189
|
const key = ClientIndexerSearchKey.from(keyLike);
|
|
214
190
|
const foundedOutPoints = [];
|
|
215
191
|
|
|
216
|
-
for (const cell of this.
|
|
217
|
-
if (!filterCell(key, cell)) {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
|
|
192
|
+
for await (const cell of this.cache.findCells(key)) {
|
|
221
193
|
foundedOutPoints.push(cell.outPoint);
|
|
222
194
|
yield cell;
|
|
223
195
|
}
|
|
224
196
|
|
|
225
197
|
for await (const cell of this.findCells(key, order, limit)) {
|
|
226
198
|
if (
|
|
227
|
-
this.
|
|
199
|
+
(await this.cache.isUnusable(cell.outPoint)) ||
|
|
228
200
|
foundedOutPoints.some((founded) => founded.eq(cell.outPoint))
|
|
229
201
|
) {
|
|
230
202
|
continue;
|
|
@@ -506,13 +478,13 @@ export abstract class Client {
|
|
|
506
478
|
|
|
507
479
|
const txHash = await this.sendTransactionNoCache(tx, validator);
|
|
508
480
|
|
|
509
|
-
this.
|
|
481
|
+
await this.cache.recordTransactions(tx);
|
|
510
482
|
await Promise.all(
|
|
511
|
-
tx.inputs.map((i) => this.markUnusable(i.previousOutput)),
|
|
483
|
+
tx.inputs.map((i) => this.cache.markUnusable(i.previousOutput)),
|
|
512
484
|
);
|
|
513
485
|
await Promise.all(
|
|
514
486
|
tx.outputs.map((o, i) =>
|
|
515
|
-
this.markUsable({
|
|
487
|
+
this.cache.markUsable({
|
|
516
488
|
cellOutput: o,
|
|
517
489
|
outputData: tx.outputsData[i],
|
|
518
490
|
outPoint: {
|
|
@@ -534,7 +506,7 @@ export abstract class Client {
|
|
|
534
506
|
return res;
|
|
535
507
|
}
|
|
536
508
|
|
|
537
|
-
const tx = this.
|
|
509
|
+
const tx = await this.cache.getTransaction(txHash);
|
|
538
510
|
if (!tx) {
|
|
539
511
|
return;
|
|
540
512
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.advanced.d.ts","sourceRoot":"","sources":["../../src/client/client.advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,QAAQ,EAAU,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACL,8BAA8B,EAE/B,MAAM,2BAA2B,CAAC;AAGnC,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,EA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