Skip to content

Commit

Permalink
Merge pull request #129 from textury/bg/mine-endpoint
Browse files Browse the repository at this point in the history
🐛 fix: fix /mine/20 creating only block entry in database
  • Loading branch information
cedriking committed Jul 21, 2022
2 parents b230bce + 8a9aecf commit f1d548d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/routes/mine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ export async function mineRoute(ctx: Router.RouterContext) {
const inc = +(ctx.params?.qty || 1);

txs = await transactionDB.getUnminedTxs();
ctx.network.current = await blockDB.mine(ctx.network.blocks, ctx.network.current, txs);
ctx.network.height = ctx.network.height + inc;
ctx.network.blocks = ctx.network.blocks + inc;
for (let i = 1; i <= inc; i++) {
let $txs = [];
if (i === inc) {
$txs = txs; // add the transactions to the last block
}
ctx.network.current = await blockDB.mine(ctx.network.blocks, ctx.network.current, $txs);
ctx.network.height = ctx.network.height + 1;
ctx.network.blocks = ctx.network.blocks + 1;
}

await transactionDB.mineTxs(ctx.network.current);

Expand Down

0 comments on commit f1d548d

Please sign in to comment.