aboutsummaryrefslogtreecommitdiffstats
path: root/core/genesis.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-06-19 07:57:16 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 00:51:47 +0800
commitceaf1c080b4047c26d433e778d4d3142f4e29d24 (patch)
tree5f1f5b8cfad997ac3be2070e7a6a0c9876d8d5d9 /core/genesis.go
parent1d42888d3047dabfb352c94a2051e7af14d2a509 (diff)
downloadgo-tangerine-ceaf1c080b4047c26d433e778d4d3142f4e29d24.tar.gz
go-tangerine-ceaf1c080b4047c26d433e778d4d3142f4e29d24.tar.zst
go-tangerine-ceaf1c080b4047c26d433e778d4d3142f4e29d24.zip
core: add GenerateChain, GenesisBlockForTesting
Diffstat (limited to 'core/genesis.go')
-rw-r--r--core/genesis.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/genesis.go b/core/genesis.go
index de2eee9db..df13466ec 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -3,6 +3,7 @@ package core
import (
"encoding/json"
"fmt"
+ "math/big"
"os"
"github.com/ethereum/go-ethereum/common"
@@ -56,3 +57,20 @@ var GenesisAccounts = []byte(`{
"e6716f9544a56c530d868e4bfbacb172315bdead": {"balance": "1606938044258990275541962092341162602522202993782792835301376"},
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4": {"balance": "1606938044258990275541962092341162602522202993782792835301376"}
}`)
+
+// GenesisBlockForTesting creates a block in which addr has the given wei balance.
+// The state trie of the block is written to db.
+func GenesisBlockForTesting(db common.Database, addr common.Address, balance *big.Int) *types.Block {
+ statedb := state.New(common.Hash{}, db)
+ obj := statedb.GetOrNewStateObject(addr)
+ obj.SetBalance(balance)
+ statedb.Update()
+ statedb.Sync()
+ block := types.NewBlock(&types.Header{
+ Difficulty: params.GenesisDifficulty,
+ GasLimit: params.GenesisGasLimit,
+ Root: statedb.Root(),
+ }, nil, nil, nil)
+ block.Td = params.GenesisDifficulty
+ return block
+}