aboutsummaryrefslogtreecommitdiffstats
path: root/core/genesis.go
diff options
context:
space:
mode:
authorWei-Ning Huang <aitjcize@gmail.com>2018-11-09 14:16:06 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:53 +0800
commitc4e7e5e338e57995a9d709129d8d5c22863432c0 (patch)
treec104db3e197db2afbcb05aad009fdf3694c2e5d9 /core/genesis.go
parent07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8 (diff)
downloaddexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.tar
dexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.tar.gz
dexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.tar.bz2
dexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.tar.lz
dexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.tar.xz
dexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.tar.zst
dexon-c4e7e5e338e57995a9d709129d8d5c22863432c0.zip
core: genesis: make ToBlock() compatible with legacy ethereum code (#3)
Make ToBlock() compatible with legacy ethereum code so we can run tests normally.
Diffstat (limited to 'core/genesis.go')
-rw-r--r--core/genesis.go64
1 files changed, 36 insertions, 28 deletions
diff --git a/core/genesis.go b/core/genesis.go
index 38b8c360b..b444ea4fe 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -266,48 +266,56 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
totalStaked := big.NewInt(0)
for addr, account := range g.Alloc {
- if account.Staked == nil {
+ // For DEXON consensus genesis staking.
+ if g.Config != nil && g.Config.Dexcon != nil {
account.Staked = big.NewInt(0)
+ statedb.AddBalance(addr, new(big.Int).Sub(account.Balance, account.Staked))
+ totalStaked = new(big.Int).Add(totalStaked, account.Staked)
+ } else {
+ statedb.AddBalance(addr, account.Balance)
}
- statedb.AddBalance(addr, new(big.Int).Sub(account.Balance, account.Staked))
+
statedb.SetCode(addr, account.Code)
statedb.SetNonce(addr, account.Nonce)
for key, value := range account.Storage {
statedb.SetState(addr, key, value)
}
- totalStaked = new(big.Int).Add(totalStaked, account.Staked)
}
- // Move staked balance to governance contract.
- statedb.AddBalance(vm.GovernanceContractAddress, totalStaked)
-
- // Stake in governance state.
- keys := AllocKey{}
- for addr := range g.Alloc {
- keys = append(keys, addr)
- }
- sort.Sort(keys)
+ // For DEXON consensus genesis staking.
+ if g.Config != nil && g.Config.Dexcon != nil {
+ // Move staked balance to governance contract.
+ statedb.AddBalance(vm.GovernanceContractAddress, totalStaked)
- for _, addr := range keys {
- account := g.Alloc[addr]
- if account.Staked == nil {
- account.Staked = big.NewInt(0)
+ // Stake in governance state.
+ keys := AllocKey{}
+ for addr := range g.Alloc {
+ keys = append(keys, addr)
}
- if account.Staked.Cmp(big.NewInt(0)) > 0 {
- govStateHelper.Stake(addr, account.PublicKey, account.Staked,
- account.NodeInfo.Name, account.NodeInfo.Email,
- account.NodeInfo.Location, account.NodeInfo.Url)
+ sort.Sort(keys)
+
+ for _, addr := range keys {
+ account := g.Alloc[addr]
+ if account.Staked == nil {
+ account.Staked = big.NewInt(0)
+ }
+ if account.Staked.Cmp(big.NewInt(0)) > 0 {
+ govStateHelper.Stake(addr, account.PublicKey, account.Staked,
+ account.NodeInfo.Name, account.NodeInfo.Email,
+ account.NodeInfo.Location, account.NodeInfo.Url)
+ }
}
- }
- // Genesis CRS.
- crs := crypto.Keccak256([]byte(g.Config.Dexcon.GenesisCRSText))
- govStateHelper.PushCRS(common.BytesToHash(crs))
- // Owner.
- govStateHelper.SetOwner(g.Config.Dexcon.Owner)
+ // Genesis CRS.
+ crs := crypto.Keccak256([]byte(g.Config.Dexcon.GenesisCRSText))
+ govStateHelper.PushCRS(common.BytesToHash(crs))
- // Governance configuration.
- govStateHelper.UpdateConfiguration(g.Config.Dexcon)
+ // Owner.
+ govStateHelper.SetOwner(g.Config.Dexcon.Owner)
+
+ // Governance configuration.
+ govStateHelper.UpdateConfiguration(g.Config.Dexcon)
+ }
root := statedb.IntermediateRoot(false)
head := &types.Header{