aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-12 18:57:49 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:21 +0800
commitad52a199d1a4e267d7b523736ca598b2b2ca8660 (patch)
treee12ea088c6aad60f87fff58627d3373a7023d1a3
parent68f5e492c01d9496463e0507f99e6303877e7328 (diff)
downloadgo-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.tar
go-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.tar.gz
go-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.tar.bz2
go-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.tar.lz
go-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.tar.xz
go-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.tar.zst
go-tangerine-ad52a199d1a4e267d7b523736ca598b2b2ca8660.zip
core: vm: emit events for more governance actions (#142)
-rw-r--r--core/vm/governance.go145
1 files changed, 145 insertions, 0 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go
index 1df82f84c..dc17134ce 100644
--- a/core/vm/governance.go
+++ b/core/vm/governance.go
@@ -677,6 +677,84 @@ const GovernanceABIJSON = `
"type": "event"
},
{
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "NodeAddress",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "Amount",
+ "type": "uint256"
+ }
+ ],
+ "name": "Withdrawn",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "NodeAddress",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "Type",
+ "type": "uint256"
+ },
+ {
+ "indexed": false,
+ "name": "Arg1",
+ "type": "bytes"
+ },
+ {
+ "indexed": false,
+ "name": "Arg2",
+ "type": "bytes"
+ }
+ ],
+ "name": "ForkReported",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "NodeAddress",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "Amount",
+ "type": "uint256"
+ }
+ ],
+ "name": "Fined",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "NodeAddress",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "Amount",
+ "type": "uint256"
+ }
+ ],
+ "name": "FinePaid",
+ "type": "event"
+ },
+ {
"constant": false,
"inputs": [
{
@@ -2370,6 +2448,65 @@ 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) {
+ s.StateDB.AddLog(&types.Log{
+ Address: GovernanceContractAddress,
+ Topics: []common.Hash{events["Withdrawn"].Id(), nodeAddr.Hash()},
+ Data: common.BigToHash(amount).Bytes(),
+ })
+}
+
+// event ForkReported(address indexed NodeAddress, address indexed Type, bytes Arg1, bytes Arg2);
+func (s *GovernanceStateHelper) emitForkReported(nodeAddr common.Address, reportType *big.Int, arg1, arg2 []byte) {
+
+ t, err := abi.NewType("bytes", nil)
+ if err != nil {
+ panic(err)
+ }
+
+ arg := abi.Arguments{
+ abi.Argument{
+ Name: "Arg1",
+ Type: t,
+ Indexed: false,
+ },
+ abi.Argument{
+ Name: "Arg2",
+ Type: t,
+ Indexed: false,
+ },
+ }
+
+ data, err := arg.Pack(arg1, arg2)
+ if err != nil {
+ panic(err)
+ }
+ s.StateDB.AddLog(&types.Log{
+ Address: GovernanceContractAddress,
+ Topics: []common.Hash{events["ForkReported"].Id(), nodeAddr.Hash()},
+ Data: data,
+ })
+}
+
+// event Fined(address indexed NodeAddress, uint256 Amount);
+func (s *GovernanceStateHelper) emitFined(nodeAddr common.Address, amount *big.Int) {
+ s.StateDB.AddLog(&types.Log{
+ Address: GovernanceContractAddress,
+ Topics: []common.Hash{events["Fined"].Id(), nodeAddr.Hash()},
+ Data: common.BigToHash(amount).Bytes(),
+ })
+}
+
+// event FinePaid(address indexed NodeAddress, uint256 Amount);
+func (s *GovernanceStateHelper) emitFinePaid(nodeAddr common.Address, amount *big.Int) {
+ s.StateDB.AddLog(&types.Log{
+ Address: GovernanceContractAddress,
+ Topics: []common.Hash{events["FinePaid"].Id(), nodeAddr.Hash()},
+ Data: common.BigToHash(amount).Bytes(),
+ })
+}
+
// GovernanceContract represents the governance contract of DEXCON.
type GovernanceContract struct {
evm *EVM
@@ -2784,6 +2921,8 @@ func (g *GovernanceContract) withdraw(nodeAddr common.Address) ([]byte, error) {
return nil, errExecutionReverted
}
+ g.state.emitWithdrawn(nodeAddr, 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 {
length := g.state.LenNodes()
@@ -2859,6 +2998,8 @@ func (g *GovernanceContract) payFine(nodeAddr common.Address) ([]byte, error) {
// TODO: paid fine should be added to award pool.
+ g.state.emitFinePaid(nodeAddr, g.contract.Value())
+
return g.useGas(100000)
}
@@ -2944,6 +3085,8 @@ func (g *GovernanceContract) fine(nodeAddr common.Address, amount *big.Int, payl
node.Fined = new(big.Int).Add(node.Fined, amount)
g.state.UpdateNode(nodeOffset, node)
+ g.state.emitFined(nodeAddr, amount)
+
return nil
}
@@ -2987,6 +3130,8 @@ func (g *GovernanceContract) report(reportType *big.Int, arg1, arg2 []byte) ([]b
offset := g.state.NodesOffsetByID(Bytes32(reportedNodeID.Hash))
node := g.state.Node(offset)
+ g.state.emitForkReported(node.Owner, reportType, arg1, arg2)
+
fineValue := g.state.FineValue(reportType)
if err := g.fine(node.Owner, fineValue, arg1, arg2); err != nil {
return nil, errExecutionReverted