Skip to content

Commit

Permalink
Set key
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner committed Jan 8, 2025
1 parent 3d72407 commit 6417d40
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/database/source/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ export class DatabaseService implements Contracts.Database.DatabaseService {
return this.#transactionCache.get(id);
}

const transactionBytes: Buffer | undefined = this.transactionStorage.get(id);

if (!transactionBytes) {
const key: string | undefined = this.transactionIdStorage.get(id);
if (!key) {
return undefined;
}

const transactionBytes: Buffer | undefined = this.transactionStorage.get(id);
Utils.assert.defined<Buffer>(transactionBytes);

return await this.transactionFactory.fromBytes(transactionBytes);
}

Expand Down Expand Up @@ -236,8 +238,12 @@ export class DatabaseService implements Contracts.Database.DatabaseService {
height,
commit.block.transactions.map((tx) => tx.id),
);

for (const tx of commit.block.transactions) {
void this.transactionStorage.put(tx.id, tx.serialized);
Utils.assert.defined<number>(tx.data.sequence);
const key = `${height}-${tx.data.sequence}`;
void this.transactionIdStorage.put(tx.id, key);
void this.transactionStorage.put(key, tx.serialized);
}
void this.blockIdStorage.put(commit.block.data.id, height);
}
Expand Down

0 comments on commit 6417d40

Please sign in to comment.