Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentine1898 committed Mar 12, 2024
1 parent 352e749 commit 0c83895
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
19 changes: 4 additions & 15 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,17 @@ export class IndexedDb implements IndexedDbInterface {
}

async *iterateTransactions() {
yield* new ReadableStream({
start: async cont => {
let cursor = await this.db.transaction('TRANSACTIONS').store.openCursor();
while (cursor) {
cont.enqueue(TransactionInfo.fromJson(cursor.value));
cursor = await cursor.continue();
}
cont.close();
},
});
yield* new ReadableStream(
new IdbCursorSource(this.db.transaction('TRANSACTIONS').store.openCursor(), TransactionInfo),
);
}

async saveTransaction(
id: TransactionId,
height: bigint,
transaction: Transaction,
): Promise<void> {
const tx = new TransactionInfo({
id,
height,
transaction,
});
const tx = new TransactionInfo({ id, height, transaction });
await this.u.update({
table: 'TRANSACTIONS',
value: tx.toJson() as Jsonified<TransactionInfo>,
Expand Down
6 changes: 3 additions & 3 deletions packages/storage/src/indexed-db/indexed-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('IndexedDb', () => {
await db.saveTransaction(transactionId, 1000n, transaction);
const txs: TransactionInfo[] = [];
for await (const tx of db.iterateTransactions()) {
txs.push(tx as TransactionInfo);
txs.push(tx);
}
expect(txs.length).toBe(1);

Expand Down Expand Up @@ -181,7 +181,7 @@ describe('IndexedDb', () => {

const txsAfterClean: TransactionInfo[] = [];
for await (const tx of db.iterateTransactions()) {
txsAfterClean.push(tx as TransactionInfo);
txsAfterClean.push(tx);
}
expect(txsAfterClean.length).toBe(0);
expect(await db.getFullSyncHeight()).toBeUndefined();
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('IndexedDb', () => {
await db.saveTransaction(transactionId, 1000n, transaction);
const savedTransactions: TransactionInfo[] = [];
for await (const tx of db.iterateTransactions()) {
savedTransactions.push(tx as TransactionInfo);
savedTransactions.push(tx);
}
expect(savedTransactions.length === 1).toBeTruthy();
expect(transaction.equals(savedTransactions[0]?.transaction)).toBeTruthy();
Expand Down

0 comments on commit 0c83895

Please sign in to comment.