Skip to content

Commit

Permalink
Import type
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner committed Jan 8, 2025
1 parent 394fef1 commit 871ed33
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/database/source/database-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject, injectable } from "@mainsail/container";
import { Contracts, Identifiers } from "@mainsail/contracts";
import { Utils } from "@mainsail/kernel";
import { Database, RootDatabase } from "lmdb";
import type { Database, RootDatabase } from "lmdb";

@injectable()
export class DatabaseService implements Contracts.Database.DatabaseService {
Expand Down Expand Up @@ -294,19 +294,22 @@ export class DatabaseService implements Contracts.Database.DatabaseService {
return;
}

const transactionIds: string[] | undefined = this.transactionIdStorage.get(height);
Utils.assert.defined<string[]>(transactionIds);
const blockHeader = await this.blockDeserializer.deserializeHeader(blockBuffer);

const transactions: Buffer[] = [];
for (const id of transactionIds) {
const transaction: Buffer | undefined = this.transactionStorage.get(id);
for (let index = 0; index < blockHeader.numberOfTransactions; index++) {
const key = `${height}-${index}`;
const transaction: Buffer | undefined = this.transactionStorage.get(key);
Utils.assert.defined<Buffer>(transaction);

const sizeBuff = Buffer.alloc(2);
sizeBuff.writeUInt16LE(transaction.length, 0);
transactions.push(sizeBuff, transaction);
}

const transactionIds: string[] | undefined = this.transactionIdStorage.get(height);
Utils.assert.defined<string[]>(transactionIds);

return Buffer.concat([blockBuffer, ...transactions]);
}

Expand Down

0 comments on commit 871ed33

Please sign in to comment.