diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-19 18:47:24 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-13 18:11:44 +0800 |
commit | 061ed2c8187fe10e35e20e12945533f5c4fd6313 (patch) | |
tree | 1c2bfd21b668929af15105c74fb5327dcadda6f6 | |
parent | b4d5ec900749ccd421dd49dad0e679e771913b1b (diff) | |
download | go-tangerine-061ed2c8187fe10e35e20e12945533f5c4fd6313.tar.gz go-tangerine-061ed2c8187fe10e35e20e12945533f5c4fd6313.tar.zst go-tangerine-061ed2c8187fe10e35e20e12945533f5c4fd6313.zip |
core: vm: emit event when transfering owner (#277)
-rw-r--r-- | core/vm/oracle_contract_abi.go | 17 | ||||
-rw-r--r-- | core/vm/oracle_contracts.go | 17 | ||||
-rw-r--r-- | core/vm/oracle_contracts_test.go | 14 |
3 files changed, 48 insertions, 0 deletions
diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go index af0affece..f0845eb7b 100644 --- a/core/vm/oracle_contract_abi.go +++ b/core/vm/oracle_contract_abi.go @@ -659,6 +659,23 @@ const GovernanceABIJSON = ` "type": "address" }, { + "indexed": true, + "name": "NewOwnerAddress", + "type": "address" + } + ], + "name": "NodeOwnershipTransfered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "NodeAddress", + "type": "address" + }, + { "indexed": false, "name": "Amount", "type": "uint256" diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index e30d0382a..c138a6b4a 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -1054,6 +1054,16 @@ func (s *GovernanceState) emitCRSProposed(round *big.Int, crs common.Hash) { }) } +// event NodeOwnershipTransfered(address indexed NodeAddress, address indexed NewOwnerAddress); +func (s *GovernanceState) emitNodeOwnershipTransfered(nodeAddr, newNodeAddr common.Address) { + s.StateDB.AddLog(&types.Log{ + Address: GovernanceContractAddress, + Topics: []common.Hash{GovernanceABI.Events["NodeOwnershipTransfered"].Id(), + nodeAddr.Hash(), newNodeAddr.Hash()}, + Data: []byte{}, + }) +} + // event Staked(address indexed NodeAddress, uint256 Amount); func (s *GovernanceState) emitStaked(nodeAddr common.Address, amount *big.Int) { s.StateDB.AddLog(&types.Log{ @@ -2369,6 +2379,11 @@ func (g *GovernanceContract) transferNodeOwnership(newOwner common.Address) ([]b return nil, errExecutionReverted } + newOffset := g.state.NodesOffsetByAddress(newOwner) + if newOffset.Cmp(big.NewInt(0)) >= 0 { + return nil, errExecutionReverted + } + node := g.state.Node(offset) g.state.PutNodeOffsets(node, big.NewInt(0)) @@ -2376,6 +2391,8 @@ func (g *GovernanceContract) transferNodeOwnership(newOwner common.Address) ([]b g.state.PutNodeOffsets(node, offset) g.state.UpdateNode(offset, node) + g.state.emitNodeOwnershipTransfered(caller, newOwner) + return nil, nil } diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go index 69e13e1a1..4b25b39da 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -271,6 +271,20 @@ func (g *OracleContractsTestSuite) TestTransferNodeOwnership() { g.Require().Equal(uint64(0), g.s.NodesOffsetByNodeKeyAddress(nodeKeyAddr).Uint64()) g.Require().Equal(offset.Uint64(), g.s.NodesOffsetByAddress(newAddr).Uint64()) g.Require().Equal(offset.Uint64(), g.s.NodesOffsetByNodeKeyAddress(newNodeKeyAddr).Uint64()) + + // Call with owner. + privKey2, addr2 := g.newPrefundAccount() + pk2 := crypto.FromECDSAPub(&privKey2.PublicKey) + input, err = GovernanceABI.ABI.Pack("register", pk2, "Test2", "test1@dexon.org", "Taipei", "https://dexon.org") + g.Require().NoError(err) + _, err = g.call(GovernanceContractAddress, addr2, input, amount) + g.Require().NoError(err) + + // Transfer to duplicate owner address. + input, err = GovernanceABI.ABI.Pack("transferNodeOwnership", addr2) + g.Require().NoError(err) + _, err = g.call(GovernanceContractAddress, newAddr, input, amount) + g.Require().Error(err) } func (g *OracleContractsTestSuite) TestStakingMechanism() { |