-
Notifications
You must be signed in to change notification settings - Fork 6
/
mission_vote_hooks.go
50 lines (40 loc) · 1.61 KB
/
mission_vote_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
package keeper
import (
"github.com/chain4energy/c4e-chain/x/cfeclaim/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
type MissionVoteHooks struct {
k Keeper
}
// NewMissionVoteHooks returns a GovHooks that triggers mission completion on voting for a proposal
func (k Keeper) NewMissionVoteHooks() MissionVoteHooks {
return MissionVoteHooks{k}
}
var _ govtypes.GovHooks = MissionVoteHooks{}
// AfterProposalVote completes mission when a vote is cast
func (h MissionVoteHooks) AfterProposalVote(ctx sdk.Context, _ uint64, voterAddr sdk.AccAddress) {
if _, found := h.k.GetUserEntry(ctx, voterAddr.String()); found {
missions := h.k.GetAllMission(ctx)
for _, mission := range missions {
if mission.MissionType == types.MissionVote {
if err := h.k.CompleteMissionFromHook(ctx, mission.CampaignId, mission.Id, voterAddr.String()); err != nil {
h.k.Logger(ctx).Debug("mission vote hook unsuccessful", "info", err)
}
}
}
}
}
// Below are the other hooks used by GovHooks interface, they are not used by this module
// AfterProposalSubmission implements GovHooks
func (h MissionVoteHooks) AfterProposalSubmission(_ sdk.Context, _ uint64) {
}
// AfterProposalDeposit implements GovHooks
func (h MissionVoteHooks) AfterProposalDeposit(_ sdk.Context, _ uint64, _ sdk.AccAddress) {
}
// AfterProposalFailedMinDeposit implements GovHooks
func (h MissionVoteHooks) AfterProposalFailedMinDeposit(_ sdk.Context, _ uint64) {
}
// AfterProposalVotingPeriodEnded implements GovHooks
func (h MissionVoteHooks) AfterProposalVotingPeriodEnded(_ sdk.Context, _ uint64) {
}