diff --git a/.changeset/gold-bikes-joke.md b/.changeset/gold-bikes-joke.md new file mode 100644 index 00000000..6f3887f6 --- /dev/null +++ b/.changeset/gold-bikes-joke.md @@ -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 diff --git a/packages/core/src/client/cache/memory.ts b/packages/core/src/client/cache/memory.ts index a78a3d71..ee593040 100644 --- a/packages/core/src/client/cache/memory.ts +++ b/packages/core/src/client/cache/memory.ts @@ -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 { @@ -73,6 +73,18 @@ export class ClientCacheMemory implements ClientCache { ); } + async *findCells( + keyLike: ClientCollectableSearchKeyLike, + ): AsyncGenerator { + for (const cell of this.usableCells) { + if (!filterCell(keyLike, cell)) { + continue; + } + + yield cell; + } + } + async isUnusable(outPointLike: OutPointLike): Promise { const outPoint = OutPoint.from(outPointLike); return this.unusableOutPoints.find((o) => o.eq(outPoint)) !== undefined; @@ -81,30 +93,18 @@ export class ClientCacheMemory implements ClientCache { async recordTransactions( ...transactions: (TransactionLike | TransactionLike[])[] ): Promise { - this.cachedTransactions.push(...transactions.flat().map(Transaction.from)); + this.knownTransactions.push(...transactions.flat().map(Transaction.from)); } async getTransaction(txHashLike: HexLike): Promise { 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 { - this.usableCells.push(...cells.flat().map(Cell.from)); + this.knownCells.push(...cells.flat().map(Cell.from)); } async getCell(outPointLike: OutPointLike): Promise { const outPoint = OutPoint.from(outPointLike); - return this.usableCells.find((cell) => cell.outPoint.eq(outPoint)); - } - - async *findCells( - keyLike: ClientCollectableSearchKeyLike, - ): AsyncGenerator { - for (const cell of this.usableCells) { - if (!filterCell(keyLike, cell)) { - continue; - } - - yield cell; - } + return this.knownCells.find((cell) => cell.outPoint.eq(outPoint)); } } diff --git a/packages/demo/src/context.tsx b/packages/demo/src/context.tsx index 16d367fe..415d8a0c 100644 --- a/packages/demo/src/context.tsx +++ b/packages/demo/src/context.tsx @@ -104,7 +104,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) { title, msgs.map((msg, i) => ( - {i === 0 ? " " : ""} + {i === 0 ? "" : " "} {msg} )),