-
Notifications
You must be signed in to change notification settings - Fork 39
/
mock_blocks.go
41 lines (35 loc) · 1.08 KB
/
mock_blocks.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
package ethereummock
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
)
var MockGenesisBlock = NewBlock(nil, common.HexToAddress("0x0"), []*types.Transaction{}, 0)
func NewBlock(parent *types.Block, nodeID common.Address, txs []*types.Transaction, blockTime uint64) *types.Block {
var parentHash common.Hash
var height uint64
if parent != nil {
parentHash = parent.Hash()
height = parent.NumberU64() + 1
}
header := types.Header{
ParentHash: parentHash,
UncleHash: common.Hash{},
Coinbase: nodeID,
Root: common.Hash{},
TxHash: common.Hash{},
ReceiptHash: common.Hash{},
Bloom: types.Bloom{},
Difficulty: big.NewInt(0),
Number: big.NewInt(int64(height)),
GasLimit: 0,
GasUsed: 0,
Time: blockTime, // Set the block time here
Extra: nil,
MixDigest: common.Hash{},
Nonce: types.BlockNonce{},
BaseFee: nil,
}
return types.NewBlock(&header, &types.Body{Transactions: txs}, nil, trie.NewStackTrie(nil))
}