-
Notifications
You must be signed in to change notification settings - Fork 832
/
gov_hooks.go
90 lines (71 loc) · 2.88 KB
/
gov_hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package keeper
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/tharsis/evmos/x/intrarelayer/types"
)
var _ govtypes.GovHooks = &Keeper{}
// AfterProposalSubmission performs a no-op
func (k Keeper) AfterProposalSubmission(ctx sdk.Context, proposalID uint64) {}
// AfterProposalDeposit hook overrides the voting period for the
// RegisterTokenPairProposal to the value defined on the intrarelayer module
// parameters.
func (k Keeper) AfterProposalDeposit(ctx sdk.Context, proposalID uint64, _ sdk.AccAddress) {
// fetch the original voting period from gov params
votingPeriod := k.govKeeper.GetVotingParams(ctx).VotingPeriod
// get the new voting period
newVotingPeriod := k.GetVotingPeriod(ctx, types.ProposalTypeRegisterCoin)
// perform a no-op if voting periods are equal
if newVotingPeriod == votingPeriod {
return
}
// get proposal
proposal, found := k.govKeeper.GetProposal(ctx, proposalID)
if !found {
return
}
// check if the proposal is on voting period
if proposal.Status != govtypes.StatusVotingPeriod {
return
}
content := proposal.GetContent()
// check if proposal content and type matches the given type
if content.ProposalType() != types.ProposalTypeRegisterCoin && content.ProposalType() != types.ProposalTypeRegisterERC20 {
return
}
switch content.(type) {
case *types.RegisterCoinProposal, *types.RegisterERC20Proposal:
// valid proposal types
default:
return
}
originalEndTime := proposal.VotingEndTime
proposal.VotingEndTime = proposal.VotingStartTime.Add(newVotingPeriod)
// remove old proposal from the queue with old voting end time
k.govKeeper.RemoveFromActiveProposalQueue(ctx, proposalID, originalEndTime)
// reinsert the proposal to the queue with the updated voting end time
k.govKeeper.InsertActiveProposalQueue(ctx, proposalID, proposal.VotingEndTime)
// update the proposal
k.govKeeper.SetProposal(ctx, proposal)
k.govKeeper.Logger(ctx).Info("proposal voting end time updated", "id", proposalID, "endtime", proposal.VotingEndTime.String())
}
// AfterProposalVote performs a no-op
func (k Keeper) AfterProposalVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress) {}
// AfterProposalFailedMinDeposit performs a no-op
func (k Keeper) AfterProposalFailedMinDeposit(ctx sdk.Context, proposalID uint64) {}
// AfterProposalVotingPeriodEnded performs a no-op
func (k Keeper) AfterProposalVotingPeriodEnded(ctx sdk.Context, proposalID uint64) {}
// GetVotingPeriod implements the ProposalHook interface
func (k Keeper) GetVotingPeriod(ctx sdk.Context, proposalType string) time.Duration {
params := k.GetParams(ctx)
switch proposalType {
case types.ProposalTypeRegisterCoin:
return params.TokenPairVotingPeriod
case types.ProposalTypeRegisterERC20:
return params.TokenPairVotingPeriod
default:
vp := k.govKeeper.GetVotingParams(ctx)
return vp.VotingPeriod
}
}