diff options
Diffstat (limited to 'dex/governance.go')
-rw-r--r-- | dex/governance.go | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/dex/governance.go b/dex/governance.go index 199bcdc87..ec029f2f1 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -259,6 +259,64 @@ func (d *DexconGovernance) AddDKGFinalize(round uint64, final *dkgTypes.Finalize } } +// ReportForkVote reports a node for forking votes. +func (d *DexconGovernance) ReportForkVote(vote1, vote2 *coreTypes.Vote) { + method := vm.GovernanceContractName2Method["report"] + + vote1Bytes, err := rlp.EncodeToBytes(vote1) + if err != nil { + log.Error("failed to RLP encode vote1 to bytes", "err", err) + return + } + + vote2Bytes, err := rlp.EncodeToBytes(vote2) + if err != nil { + log.Error("failed to RLP encode vote2 to bytes", "err", err) + return + } + + res, err := method.Inputs.Pack(big.NewInt(vm.ReportTypeForkVote), vote1Bytes, vote2Bytes) + if err != nil { + log.Error("failed to pack report input", "err", err) + return + } + + data := append(method.Id(), res...) + err = d.sendGovTx(context.Background(), data) + if err != nil { + log.Error("failed to send report fork vote tx", "err", err) + } +} + +// ReportForkBlock reports a node for forking blocks. +func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) { + method := vm.GovernanceContractName2Method["report"] + + block1Bytes, err := rlp.EncodeToBytes(block1) + if err != nil { + log.Error("failed to RLP encode block1 to bytes", "err", err) + return + } + + block2Bytes, err := rlp.EncodeToBytes(block2) + if err != nil { + log.Error("failed to RLP encode block2 to bytes", "err", err) + return + } + + res, err := method.Inputs.Pack(big.NewInt(vm.ReportTypeForkBlock), block1Bytes, block2Bytes) + if err != nil { + log.Error("failed to pack report input", "err", err) + return + } + + data := append(method.Id(), res...) + err = d.sendGovTx(context.Background(), data) + if err != nil { + log.Error("failed to send report fork block tx", "err", err) + } +} + func (d *DexconGovernance) GetNumChains(round uint64) uint32 { return d.Configuration(round).NumChains } @@ -292,11 +350,3 @@ func (d *DexconGovernance) DKGSet(round uint64) (map[string]struct{}, error) { } return r, nil } - -func (d *DexconGovernance) ReportForkVote(vote1, vote2 *coreTypes.Vote) { - // TODO: finish this. -} - -func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) { - // TODO: finish this. -} |