2017-10-23 15:56:29 +00:00
|
|
|
package fakes
|
|
|
|
|
2017-11-06 18:53:43 +00:00
|
|
|
import "github.com/8thlight/vulcanizedb/pkg/core"
|
2017-10-23 15:56:29 +00:00
|
|
|
|
|
|
|
type Blockchain struct {
|
2017-11-27 15:39:53 +00:00
|
|
|
blocks map[int64]core.Block
|
|
|
|
contractAttributes map[string]map[string]string
|
|
|
|
blocksChannel chan core.Block
|
|
|
|
WasToldToStop bool
|
|
|
|
}
|
|
|
|
|
2017-11-27 22:18:42 +00:00
|
|
|
func (blockchain *Blockchain) GetContractAttributes(contractHash string) ([]core.ContractAttribute, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2017-11-27 15:39:53 +00:00
|
|
|
func (blockchain *Blockchain) GetContractStateAttribute(contractHash string, attributeName string) (*string, error) {
|
|
|
|
result := new(string)
|
|
|
|
*result = blockchain.contractAttributes[contractHash][attributeName]
|
|
|
|
return result, nil
|
2017-10-23 15:56:29 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 20:36:12 +00:00
|
|
|
func NewBlockchain() *Blockchain {
|
2017-11-27 15:39:53 +00:00
|
|
|
return &Blockchain{
|
|
|
|
blocks: make(map[int64]core.Block),
|
|
|
|
contractAttributes: make(map[string]map[string]string),
|
|
|
|
}
|
2017-11-06 20:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
|
2017-11-02 11:41:24 +00:00
|
|
|
func (blockchain *Blockchain) SubscribeToBlocks(outputBlocks chan core.Block) {
|
2017-11-06 20:36:12 +00:00
|
|
|
blockchain.blocksChannel = outputBlocks
|
2017-10-23 15:56:29 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 20:36:12 +00:00
|
|
|
func (blockchain *Blockchain) AddBlock(block core.Block) {
|
|
|
|
blockchain.blocks[block.Number] = block
|
|
|
|
blockchain.blocksChannel <- block
|
2017-10-23 15:56:29 +00:00
|
|
|
}
|
2017-10-23 18:58:33 +00:00
|
|
|
|
2017-11-02 11:41:24 +00:00
|
|
|
func (*Blockchain) StartListening() {}
|
2017-11-03 13:54:32 +00:00
|
|
|
|
|
|
|
func (blockchain *Blockchain) StopListening() {
|
|
|
|
blockchain.WasToldToStop = true
|
|
|
|
}
|
2017-11-27 15:39:53 +00:00
|
|
|
|
|
|
|
func (blockchain *Blockchain) SetContractStateAttribute(contractHash string, attributeName string, attributeValue string) {
|
|
|
|
contractStateAttributes := blockchain.contractAttributes[contractHash]
|
|
|
|
if contractStateAttributes == nil {
|
|
|
|
blockchain.contractAttributes[contractHash] = make(map[string]string)
|
|
|
|
}
|
|
|
|
blockchain.contractAttributes[contractHash][attributeName] = attributeValue
|
|
|
|
}
|