aboutsummaryrefslogtreecommitdiffstats
path: root/core/genesis.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@cobinhood.com>2018-10-11 15:01:10 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:23:38 +0800
commit5bda6cec66d7b03b23963f3d44514ac1e98da2c4 (patch)
tree26f8fae53c9b27c41f19ada583c1d3989e05926a /core/genesis.go
parent6ec5fe5c618125f4d00e3f4cd8a5dc2bbddf1dc4 (diff)
downloadgo-tangerine-5bda6cec66d7b03b23963f3d44514ac1e98da2c4.tar.gz
go-tangerine-5bda6cec66d7b03b23963f3d44514ac1e98da2c4.tar.zst
go-tangerine-5bda6cec66d7b03b23963f3d44514ac1e98da2c4.zip
core: add stake and public key to genesis account info
Diffstat (limited to 'core/genesis.go')
-rw-r--r--core/genesis.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/core/genesis.go b/core/genesis.go
index f795ac241..6982312d2 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -31,6 +31,8 @@ import (
"github.com/dexon-foundation/dexon/core/rawdb"
"github.com/dexon-foundation/dexon/core/state"
"github.com/dexon-foundation/dexon/core/types"
+ "github.com/dexon-foundation/dexon/core/vm"
+ "github.com/dexon-foundation/dexon/crypto"
"github.com/dexon-foundation/dexon/ethdb"
"github.com/dexon-foundation/dexon/log"
"github.com/dexon-foundation/dexon/params"
@@ -83,6 +85,8 @@ type GenesisAccount struct {
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *big.Int `json:"balance" gencodec:"required"`
Nonce uint64 `json:"nonce,omitempty"`
+ Staked *big.Int `json:"staked"`
+ PublicKey []byte `json:"publicKey"`
PrivateKey []byte `json:"secretKey,omitempty"` // for tests
}
@@ -101,8 +105,10 @@ type genesisSpecMarshaling struct {
type genesisAccountMarshaling struct {
Code hexutil.Bytes
Balance *math.HexOrDecimal256
+ Staked *math.HexOrDecimal256
Nonce math.HexOrDecimal64
Storage map[storageJSON]storageJSON
+ PublicKey hexutil.Bytes
PrivateKey hexutil.Bytes
}
@@ -231,13 +237,29 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
db = ethdb.NewMemDatabase()
}
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
+ govStateHelper := vm.GovernanceStateHelper{
+ Address: vm.GovernanceContractAddress,
+ StateDB: statedb,
+ }
for addr, account := range g.Alloc {
- 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)
}
+
+ // Stake in governance state.
+ if account.Staked.Cmp(big.NewInt(0)) > 0 {
+ pk, err := crypto.DecompressPubkey(account.PublicKey)
+ if err != nil {
+ panic(err)
+ }
+ if crypto.PubkeyToAddress(*pk) != addr {
+ panic(fmt.Errorf("public key does not belones to %s", addr))
+ }
+ govStateHelper.Stake(addr, account.PublicKey, account.Staked)
+ }
}
root := statedb.IntermediateRoot(false)
head := &types.Header{
@@ -373,7 +395,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
- faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
+ faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
},
}
}