Skip to content

Commit

Permalink
feat: add openingBlock method to Blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
tammo committed Feb 6, 2020
1 parent aae54b4 commit 815562e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Block, fromBlockObject } from './Block';
import { Block, fromBlockObject, BlockType } from './Block';
import { SigPublicKey, NTRUPublicKey } from './Keys';
import { StorageId } from './Storage';

Expand All @@ -22,6 +22,14 @@ export class Blockchain {
const prevs = this.blocks.map(block => block.prev).filter(prev => !!prev);
return this.blocks.find(block => prevs.indexOf(block.signature) === -1);
}

openingBlock(): Block | undefined {
if (!Array.isArray(this.blocks)) {
return;
}

return this.blocks.filter(block => block.type === BlockType.OPENING && !block.prev).pop();
}
}

export function fromBlockchainObject(obj: any) {
Expand Down

0 comments on commit 815562e

Please sign in to comment.