forked from ethereum-optimism/minigeth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_blockchain.go
78 lines (65 loc) · 2.18 KB
/
fake_blockchain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package core
import (
"log"
"math/big"
"github.com/lightlink-network/minigeth/common"
"github.com/lightlink-network/minigeth/consensus"
"github.com/lightlink-network/minigeth/consensus/ethash"
"github.com/lightlink-network/minigeth/core/types"
"github.com/lightlink-network/minigeth/oracle"
"github.com/lightlink-network/minigeth/params"
"github.com/lightlink-network/minigeth/rlp"
)
type BlockChain struct {
// TODO: write stub BlockChain
chainConfig *params.ChainConfig // Chain & network configuration
engine consensus.Engine
lastBlock *types.Header
}
func NewBlockChain(parent *types.Header) *BlockChain {
return &BlockChain{
chainConfig: params.MainnetChainConfig,
engine: ðash.Ethash{},
lastBlock: parent,
}
}
// Config retrieves the chain's fork configuration.
func (bc *BlockChain) Config() *params.ChainConfig { return bc.chainConfig }
// Engine retrieves the blockchain's consensus engine.
func (bc *BlockChain) Engine() consensus.Engine { return bc.engine }
// GetHeader retrieves a block header from the database by hash and number,
// caching it if found.
func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.Header {
if hash == bc.lastBlock.Hash() {
return bc.lastBlock
}
oracle.PrefetchBlock(big.NewInt(int64(number)), true, nil)
var ret types.Header
err := rlp.DecodeBytes(oracle.Preimage(hash), &ret)
if err != nil {
log.Fatal(err)
}
return &ret
}
func (bc *BlockChain) CurrentHeader() *types.Header {
log.Fatal("CurrentHeader")
// this right?
return bc.lastBlock
}
// GetHeaderByHash retrieves a block header from the database by hash, caching it if
// found.
func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *types.Header {
log.Fatal("GetHeaderByHash", hash)
return nil
}
// GetHeaderByNumber retrieves a block header from the database by number,
// caching it (associated with its hash) if found.
func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header {
log.Fatal("GetHeaderByNumber", number)
return nil
}
// GetTd retrieves the total difficulty from the database by hash and number.
func (bc *BlockChain) GetTd(hash common.Hash, number uint64) *big.Int {
log.Fatal("GetTd", hash, number)
return nil
}