2017-10-23 15:56:29 +00:00
|
|
|
package fakes
|
|
|
|
|
2017-11-28 16:45:21 +00:00
|
|
|
import (
|
2017-12-04 18:54:33 +00:00
|
|
|
"math/big"
|
|
|
|
|
2018-01-06 20:31:53 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
2017-11-28 16:45:21 +00:00
|
|
|
)
|
2017-10-23 15:56:29 +00:00
|
|
|
|
|
|
|
type Blockchain struct {
|
2018-02-13 16:31:57 +00:00
|
|
|
logs map[string][]core.Log
|
|
|
|
blocks map[int64]core.Block
|
|
|
|
contractAttributes map[string]map[string]string
|
|
|
|
blocksChannel chan core.Block
|
|
|
|
WasToldToStop bool
|
|
|
|
node core.Node
|
|
|
|
ContractReturnValue []byte
|
2018-03-27 21:06:12 +00:00
|
|
|
err error
|
2018-02-13 16:31:57 +00:00
|
|
|
}
|
|
|
|
|
2018-03-12 19:09:20 +00:00
|
|
|
func (blockchain *Blockchain) FetchContractData(abiJSON string, address string, method string, methodArg interface{}, result interface{}, blockNumber int64) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2018-02-13 16:31:57 +00:00
|
|
|
func (blockchain *Blockchain) CallContract(contractHash string, input []byte, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
return blockchain.ContractReturnValue, nil
|
2017-12-07 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 20:06:22 +00:00
|
|
|
func (blockchain *Blockchain) LastBlock() *big.Int {
|
|
|
|
var max int64
|
|
|
|
for blockNumber := range blockchain.blocks {
|
|
|
|
if blockNumber > max {
|
|
|
|
max = blockNumber
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return big.NewInt(max)
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:42:35 +00:00
|
|
|
func (blockchain *Blockchain) GetLogs(contract core.Contract, startingBlock *big.Int, endingBlock *big.Int) ([]core.Log, error) {
|
2017-12-11 21:08:00 +00:00
|
|
|
return blockchain.logs[contract.Hash], nil
|
|
|
|
}
|
|
|
|
|
2017-12-07 19:32:16 +00:00
|
|
|
func (blockchain *Blockchain) Node() core.Node {
|
|
|
|
return blockchain.node
|
2017-11-27 15:39:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
func NewBlockchain(err error) *Blockchain {
|
2017-11-27 15:39:53 +00:00
|
|
|
return &Blockchain{
|
|
|
|
blocks: make(map[int64]core.Block),
|
2017-12-11 21:08:00 +00:00
|
|
|
logs: make(map[string][]core.Log),
|
2017-11-27 15:39:53 +00:00
|
|
|
contractAttributes: make(map[string]map[string]string),
|
2018-02-13 16:31:57 +00:00
|
|
|
node: core.Node{GenesisBlock: "GENESIS", NetworkID: 1, ID: "x123", ClientName: "Geth"},
|
2018-03-27 21:06:12 +00:00
|
|
|
err: err,
|
2017-11-27 15:39:53 +00:00
|
|
|
}
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
func (blockchain *Blockchain) GetBlockByNumber(blockNumber int64) (core.Block, error) {
|
|
|
|
if blockchain.err != nil {
|
|
|
|
return core.Block{}, blockchain.err
|
|
|
|
}
|
|
|
|
return blockchain.blocks[blockNumber], nil
|
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
|
|
|
}
|