Skip to content

Commit

Permalink
Minor cleanups.
Browse files Browse the repository at this point in the history
Nothing major here, the return type was inferred previously and now it is explicit and returning a promise from an async function is functionally equivalent to awaiting the promise and returning the result, just less clear what is an async call and what isn't.
  • Loading branch information
MicahZoltu committed May 17, 2018
1 parent 6d6262e commit cee6eb0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/block-reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ const rollback = async <TBlock extends Block>(blockHistory: BlockHistory<TBlock>
return blockHistory;
}

const backfill = async <TBlock extends Block>(getBlockByHash: GetBlockByHash<TBlock>, blockHistory: BlockHistory<TBlock>, newBlock: TBlock, onBlockAdded: (block: TBlock) => Promise<void>, onBlockRemoved: (block: TBlock) => Promise<void>, blockRetention: number) => {
const backfill = async <TBlock extends Block>(getBlockByHash: GetBlockByHash<TBlock>, blockHistory: BlockHistory<TBlock>, newBlock: TBlock, onBlockAdded: (block: TBlock) => Promise<void>, onBlockRemoved: (block: TBlock) => Promise<void>, blockRetention: number): Promise<BlockHistory<TBlock>> => {
if (newBlock.parentHash === "0x0000000000000000000000000000000000000000000000000000000000000000")
return rollback(blockHistory, onBlockRemoved);
return await rollback(blockHistory, onBlockRemoved);
const parentBlock = await getBlockByHash(newBlock.parentHash);
if (parentBlock === null) throw new Error("Failed to fetch parent block.");
if (parseInt(parentBlock.number, 16) + blockRetention < parseInt(blockHistory.last().number, 16))
return rollback(blockHistory, onBlockRemoved);
return await rollback(blockHistory, onBlockRemoved);
blockHistory = await reconcileBlockHistory(getBlockByHash, blockHistory, parentBlock, onBlockAdded, onBlockRemoved, blockRetention);
return await reconcileBlockHistory(getBlockByHash, blockHistory, newBlock, onBlockAdded, onBlockRemoved, blockRetention);
}
Expand Down

0 comments on commit cee6eb0

Please sign in to comment.