From 8d9bd50502921f464ca44017c2d1e7ca0cc40c5d Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Mon, 28 Jan 2019 13:43:05 +0800 Subject: core/vm: modify Withdrawn event and add NodeRemoved event (#179) * core/vm: add delegatorAddr to withdrawn event * core/vm: update gov abi * core/vm: add NodeRemoved event --- core/vm/oracle_contract_abi.go | 17 +++++++++++++++++ core/vm/oracle_contracts.go | 18 ++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/vm/oracle_contract_abi.go b/core/vm/oracle_contract_abi.go index 7722ecbce..f3e5aef06 100644 --- a/core/vm/oracle_contract_abi.go +++ b/core/vm/oracle_contract_abi.go @@ -666,6 +666,18 @@ const GovernanceABIJSON = ` "name": "Unstaked", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "NodeAddress", + "type": "address" + } + ], + "name": "NodeRemoved", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -718,6 +730,11 @@ const GovernanceABIJSON = ` "name": "NodeAddress", "type": "address" }, + { + "indexed": true, + "name": "DelegatorAddress", + "type": "address" + }, { "indexed": false, "name": "Amount", diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index 86dbb1db4..342f5f4b9 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -969,6 +969,15 @@ func (s *GovernanceStateHelper) emitUnstaked(nodeAddr common.Address) { }) } +// event NodeRemoved(address indexed NodeAddress); +func (s *GovernanceStateHelper) emitNodeRemoved(nodeAddr common.Address) { + s.StateDB.AddLog(&types.Log{ + Address: GovernanceContractAddress, + Topics: []common.Hash{GovernanceABI.Events["NodeRemoved"].Id(), nodeAddr.Hash()}, + Data: []byte{}, + }) +} + // event Delegated(address indexed NodeAddress, address indexed DelegatorAddress, uint256 Amount); func (s *GovernanceStateHelper) emitDelegated(nodeAddr, delegatorAddr common.Address, amount *big.Int) { s.StateDB.AddLog(&types.Log{ @@ -987,11 +996,11 @@ func (s *GovernanceStateHelper) emitUndelegated(nodeAddr, delegatorAddr common.A }) } -// event Withdrawn(address indexed NodeAddress, uint256 Amount); -func (s *GovernanceStateHelper) emitWithdrawn(nodeAddr common.Address, amount *big.Int) { +// event Withdrawn(address indexed NodeAddress, address indexed DelegatorAddress, uint256 Amount); +func (s *GovernanceStateHelper) emitWithdrawn(nodeAddr common.Address, delegatorAddr common.Address, amount *big.Int) { s.StateDB.AddLog(&types.Log{ Address: GovernanceContractAddress, - Topics: []common.Hash{GovernanceABI.Events["Withdrawn"].Id(), nodeAddr.Hash()}, + Topics: []common.Hash{GovernanceABI.Events["Withdrawn"].Id(), nodeAddr.Hash(), delegatorAddr.Hash()}, Data: common.BigToHash(amount).Bytes(), }) } @@ -1462,7 +1471,7 @@ func (g *GovernanceContract) withdraw(nodeAddr common.Address) ([]byte, error) { return nil, errExecutionReverted } - g.state.emitWithdrawn(nodeAddr, delegator.Value) + g.state.emitWithdrawn(nodeAddr, delegator.Owner, delegator.Value) // We are the last delegator to withdraw the fund, remove the node info. if g.state.LenDelegators(nodeAddr).Cmp(big.NewInt(0)) == 0 { @@ -1479,6 +1488,7 @@ func (g *GovernanceContract) withdraw(nodeAddr common.Address) ([]byte, error) { } g.state.DeleteNodesOffsetByAddress(nodeAddr) g.state.PopLastNode() + g.state.emitNodeRemoved(nodeAddr) } return g.useGas(100000) -- cgit v1.2.3