ipld-eth-server/pkg/fakes/blockchain.go

43 lines
1.0 KiB
Go
Raw Normal View History

package fakes
2017-11-06 18:53:43 +00:00
import "github.com/8thlight/vulcanizedb/pkg/core"
type Blockchain struct {
blocks map[int64]core.Block
blocksChannel chan core.Block
WasToldToStop bool
}
func NewBlockchain() *Blockchain {
return &Blockchain{blocks: make(map[int64]core.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
}
2017-10-23 18:58:33 +00:00
func (*Blockchain) StartListening() {}
func (blockchain *Blockchain) StopListening() {
blockchain.WasToldToStop = true
}