Add ability to populate missing blocks
* The command populates up to the highest known block number
* The anticipated use case is that the listener will be running
in parallel to the populateBlocks command
* This will mean that the listener is responsible for picking up
new blocks, and the populateBlocks command is reposible for
historical blocks
* Reformat SQL statements
This commit is contained in:
+25
-5
@@ -3,16 +3,36 @@ package fakes
|
||||
import "github.com/8thlight/vulcanizedb/pkg/core"
|
||||
|
||||
type Blockchain struct {
|
||||
outputBlocks chan core.Block
|
||||
blocks map[int64]core.Block
|
||||
blocksChannel chan core.Block
|
||||
WasToldToStop bool
|
||||
}
|
||||
|
||||
func (blockchain *Blockchain) SubscribeToBlocks(outputBlocks chan core.Block) {
|
||||
blockchain.outputBlocks = outputBlocks
|
||||
func NewBlockchain() *Blockchain {
|
||||
return &Blockchain{blocks: make(map[int64]core.Block)}
|
||||
}
|
||||
|
||||
func (blockchain Blockchain) AddBlock(block core.Block) {
|
||||
blockchain.outputBlocks <- block
|
||||
func NewBlockchainWithBlocks(blocks []core.Block) *Blockchain {
|
||||
blockNumberToBlocks := make(map[int64]core.Block)
|
||||
for _, block := range blocks {
|
||||
blockNumberToBlocks[block.Number] = block
|
||||
}
|
||||
return &Blockchain{
|
||||
blocks: blockNumberToBlocks,
|
||||
}
|
||||
}
|
||||
|
||||
func (blockchain *Blockchain) GetBlockByNumber(blockNumber int64) core.Block {
|
||||
return blockchain.blocks[blockNumber]
|
||||
}
|
||||
|
||||
func (blockchain *Blockchain) SubscribeToBlocks(outputBlocks chan core.Block) {
|
||||
blockchain.blocksChannel = outputBlocks
|
||||
}
|
||||
|
||||
func (blockchain *Blockchain) AddBlock(block core.Block) {
|
||||
blockchain.blocks[block.Number] = block
|
||||
blockchain.blocksChannel <- block
|
||||
}
|
||||
|
||||
func (*Blockchain) StartListening() {}
|
||||
|
||||
Reference in New Issue
Block a user