diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-19 16:31:44 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:50 +0800 |
commit | b52b1b2106f075260674660638aa60fe5ec81f87 (patch) | |
tree | 84f1d5d95d143fe0f20daed8aa42ac85b4a6363e /core | |
parent | 7febfae8bba63f6b7e1326b22437dee38989c400 (diff) | |
download | dexon-b52b1b2106f075260674660638aa60fe5ec81f87.tar dexon-b52b1b2106f075260674660638aa60fe5ec81f87.tar.gz dexon-b52b1b2106f075260674660638aa60fe5ec81f87.tar.bz2 dexon-b52b1b2106f075260674660638aa60fe5ec81f87.tar.lz dexon-b52b1b2106f075260674660638aa60fe5ec81f87.tar.xz dexon-b52b1b2106f075260674660638aa60fe5ec81f87.tar.zst dexon-b52b1b2106f075260674660638aa60fe5ec81f87.zip |
core: vm: add blockReward to governance
Diffstat (limited to 'core')
-rw-r--r-- | core/genesis.go | 8 | ||||
-rw-r--r-- | core/vm/governance.go | 35 |
2 files changed, 39 insertions, 4 deletions
diff --git a/core/genesis.go b/core/genesis.go index c9f4e2499..4d3edb3e8 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -276,16 +276,16 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { govStateHelper.Stake(addr, account.PublicKey, account.Staked) } } + // Genesis CRS. + crs := crypto.Keccak256([]byte(g.Config.Dexcon.GenesisCRSText)) + govStateHelper.PushCRS(common.BytesToHash(crs)) + // Owner. govStateHelper.SetOwner(g.Config.Dexcon.Owner) // Governance configuration. govStateHelper.UpdateConfiguration(g.Config.Dexcon) - // Genesis CRS. - crs := crypto.Keccak256([]byte(g.Config.Dexcon.GenesisCRSText)) - govStateHelper.PushCRS(common.BytesToHash(crs)) - root := statedb.IntermediateRoot(false) head := &types.Header{ Number: new(big.Int).SetUint64(g.Number), diff --git a/core/vm/governance.go b/core/vm/governance.go index 2e07ba3eb..b2bb531f2 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -42,6 +42,20 @@ const abiJSON = ` [ { "constant": true, + "inputs": [], + "name": "blockReward", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, "inputs": [ { "name": "", @@ -407,6 +421,10 @@ const abiJSON = ` "constant": false, "inputs": [ { + "name": "BlockReward", + "type": "uint256" + }, + { "name": "NumChains", "type": "uint256" }, @@ -679,6 +697,12 @@ func RunGovernanceContract(evm *EVM, input []byte, contract *Contract) ( // Solidity auto generated methods. // -------------------------------- + case "blockReward": + res, err := method.Outputs.Pack(g.state.BlockReward()) + if err != nil { + return nil, errExecutionReverted + } + return res, nil case "crs": round := new(big.Int) if err := method.Inputs.Unpack(&round, arguments); err != nil { @@ -856,6 +880,7 @@ const ( dkgFinailizedLoc dkgFinalizedsCountLoc ownerLoc + blockRewardLoc numChainsLoc lambdaBALoc lambdaDKGLoc @@ -1183,6 +1208,14 @@ func (s *GovernanceStateHelper) SetOwner(newOwner common.Address) { s.setState(common.BigToHash(big.NewInt(ownerLoc)), newOwner.Hash()) } +// uint256 public blockReward; +func (s *GovernanceStateHelper) BlockReward() *big.Int { + return s.getStateBigInt(big.NewInt(blockRewardLoc)) +} +func (s *GovernanceStateHelper) SetBlockReward(reward *big.Int) { + s.setStateBigInt(big.NewInt(blockRewardLoc), reward) +} + // uint256 public numChains; func (s *GovernanceStateHelper) NumChains() *big.Int { return s.getStateBigInt(big.NewInt(numChainsLoc)) @@ -1247,6 +1280,7 @@ func (s *GovernanceStateHelper) Stake(addr common.Address, publicKey []byte, sta // Configuration returns the current configuration. func (s *GovernanceStateHelper) Configuration() *params.DexconConfig { return ¶ms.DexconConfig{ + BlockReward: s.getStateBigInt(big.NewInt(blockRewardLoc)), NumChains: uint32(s.getStateBigInt(big.NewInt(numChainsLoc)).Uint64()), LambdaBA: s.getStateBigInt(big.NewInt(lambdaBALoc)).Uint64(), LambdaDKG: s.getStateBigInt(big.NewInt(lambdaDKGLoc)).Uint64(), @@ -1262,6 +1296,7 @@ func (s *GovernanceStateHelper) Configuration() *params.DexconConfig { // UpdateConfiguration updates system configuration. func (s *GovernanceStateHelper) UpdateConfiguration(cfg *params.DexconConfig) { + s.setStateBigInt(big.NewInt(blockRewardLoc), cfg.BlockReward) s.setStateBigInt(big.NewInt(numChainsLoc), big.NewInt(int64(cfg.NumChains))) s.setStateBigInt(big.NewInt(lambdaBALoc), big.NewInt(int64(cfg.LambdaBA))) s.setStateBigInt(big.NewInt(lambdaDKGLoc), big.NewInt(int64(cfg.LambdaDKG))) |