aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/vm/oracle_contract_abi.go17
-rw-r--r--core/vm/oracle_contracts.go17
-rw-r--r--core/vm/oracle_contracts_test.go14
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 62261a36b..f21700d86 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -1058,6 +1058,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{
@@ -2373,6 +2383,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))
@@ -2380,6 +2395,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() {