Skip to content

Commit

Permalink
fix(core): recordCells should not add usableCells
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanssen0 committed Aug 29, 2024
1 parent 9e6b9fd commit 6d62032
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
17 changes: 17 additions & 0 deletions .changeset/gold-bikes-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@ckb-ccc/core": patch
"@ckb-ccc/ccc": patch
"ckb-ccc": patch
"@ckb-ccc/connector": patch
"@ckb-ccc/connector-react": patch
"@ckb-ccc/eip6963": patch
"@ckb-ccc/joy-id": patch
"@ckb-ccc/lumos-patches": patch
"@ckb-ccc/nip07": patch
"@ckb-ccc/okx": patch
"@ckb-ccc/rei": patch
"@ckb-ccc/uni-sat": patch
"@ckb-ccc/utxo-global": patch
---

fix(core): recordCells should not add usableCells
34 changes: 17 additions & 17 deletions packages/core/src/client/cache/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { ClientCache } from "./cache.js";
import { filterCell } from "./memory.advanced.js";

export class ClientCacheMemory implements ClientCache {
private readonly cachedTransactions: Transaction[] = [];
private readonly unusableOutPoints: OutPoint[] = [];
private readonly usableCells: Cell[] = [];
private readonly knownTransactions: Transaction[] = [];
private readonly knownCells: Cell[] = [];

async markUsable(...cellLikes: (CellLike | CellLike[])[]): Promise<void> {
Expand Down Expand Up @@ -73,6 +73,18 @@ export class ClientCacheMemory implements ClientCache {
);
}

async *findCells(
keyLike: ClientCollectableSearchKeyLike,
): AsyncGenerator<Cell> {
for (const cell of this.usableCells) {
if (!filterCell(keyLike, cell)) {
continue;
}

yield cell;
}
}

async isUnusable(outPointLike: OutPointLike): Promise<boolean> {
const outPoint = OutPoint.from(outPointLike);
return this.unusableOutPoints.find((o) => o.eq(outPoint)) !== undefined;
Expand All @@ -81,30 +93,18 @@ export class ClientCacheMemory implements ClientCache {
async recordTransactions(
...transactions: (TransactionLike | TransactionLike[])[]
): Promise<void> {
this.cachedTransactions.push(...transactions.flat().map(Transaction.from));
this.knownTransactions.push(...transactions.flat().map(Transaction.from));
}
async getTransaction(txHashLike: HexLike): Promise<Transaction | undefined> {
const txHash = hexFrom(txHashLike);
return this.cachedTransactions.find((tx) => tx.hash() === txHash);
return this.knownTransactions.find((tx) => tx.hash() === txHash);
}

async recordCells(...cells: (CellLike | CellLike[])[]): Promise<void> {
this.usableCells.push(...cells.flat().map(Cell.from));
this.knownCells.push(...cells.flat().map(Cell.from));
}
async getCell(outPointLike: OutPointLike): Promise<Cell | undefined> {
const outPoint = OutPoint.from(outPointLike);
return this.usableCells.find((cell) => cell.outPoint.eq(outPoint));
}

async *findCells(
keyLike: ClientCollectableSearchKeyLike,
): AsyncGenerator<Cell> {
for (const cell of this.usableCells) {
if (!filterCell(keyLike, cell)) {
continue;
}

yield cell;
}
return this.knownCells.find((cell) => cell.outPoint.eq(outPoint));
}
}
2 changes: 1 addition & 1 deletion packages/demo/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
title,
msgs.map((msg, i) => (
<React.Fragment key={i}>
{i === 0 ? " " : ""}
{i === 0 ? "" : " "}
{msg}
</React.Fragment>
)),
Expand Down

0 comments on commit 6d62032

Please sign in to comment.