Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit 3c1445f

Browse files
authored
Merge pull request #124 from ethereumjs/blockchain-interface
Define a Blockchain interface
2 parents 35fefe6 + a5a7f8e commit 3c1445f

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/index.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,52 @@ const Stoplight = require('flow-stoplight')
2020
const level = require('level-mem')
2121
const semaphore = require('semaphore')
2222

23+
export type Block = any
24+
25+
export interface BlockchainInterface {
26+
/**
27+
* Adds a block to the blockchain.
28+
*
29+
* @param block - The block to be added to the blockchain.
30+
* @param cb - The callback. It is given two parameters `err` and the saved `block`
31+
* @param isGenesis - True if block is the genesis block.
32+
*/
33+
putBlock(block: Block, cb: any, isGenesis?: boolean): void
34+
35+
/**
36+
* Deletes a block from the blockchain. All child blocks in the chain are deleted and any
37+
* encountered heads are set to the parent block.
38+
*
39+
* @param blockHash - The hash of the block to be deleted
40+
* @param cb - A callback.
41+
*/
42+
delBlock(blockHash: Buffer, cb: any): void
43+
44+
/**
45+
* Returns a block by its hash or number.
46+
*/
47+
getBlock(blockTag: Buffer | number | BN, cb: (err: Error | null, block?: Block) => void): void
48+
49+
/**
50+
* Iterates through blocks starting at the specified iterator head and calls the onBlock function
51+
* on each block.
52+
*
53+
* @param name - Name of the state root head
54+
* @param onBlock - Function called on each block with params (block, reorg, cb)
55+
* @param cb - A callback function
56+
*/
57+
iterator(name: string, onBlock: any, cb: any): void
58+
59+
/**
60+
* This method is only here for backwards compatibility. It can be removed once
61+
* [this PR](https://github.com/ethereumjs/ethereumjs-block/pull/72/files) gets merged, released,
62+
* and ethereumjs-block is updated here.
63+
*
64+
* The method should just call `cb` with `null` as first argument.
65+
*/
66+
getDetails(_: string, cb: any): void
67+
}
68+
2369
/**
2470
* This are the options that the Blockchain constructor can receive.
2571
*/
@@ -56,7 +102,7 @@ export interface BlockchainOptions {
56102
/**
57103
* This class stores and interacts with blocks.
58104
*/
59-
export default class Blockchain {
105+
export default class Blockchain implements BlockchainInterface {
60106
/**
61107
* @hidden
62108
*/

0 commit comments

Comments
 (0)