forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
53 lines (45 loc) · 1.42 KB
/
common.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
package gov
import (
"context"
"time"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/rs/zerolog/log"
"github.com/faddat/bdjuno/database"
"github.com/faddat/bdjuno/x/gov/types"
)
// UpdateProposal return a function for time.AfterFunc() to update the proposal status on a given time
func UpdateProposal(id uint64, govClient govtypes.QueryClient, db *database.BigDipperDb) func() {
return func() {
err := updateProposalStatuses(id, govClient, db)
if err != nil {
log.Error().Str("module", "gov").Err(err).Uint64("proposal_id", id).
Msg("error while updating proposal")
}
}
}
func updateProposalStatuses(id uint64, govClient govtypes.QueryClient, db *database.BigDipperDb) error {
// Get the proposal
res, err := govClient.Proposal(context.Background(), &govtypes.QueryProposalRequest{ProposalId: id})
if err != nil {
return err
}
proposal := res.Proposal
if proposal.Status == govtypes.StatusVotingPeriod {
update := UpdateProposal(proposal.ProposalId, govClient, db)
time.AfterFunc(time.Since(proposal.VotingEndTime), update)
}
// Update the proposal to update the status
return db.UpdateProposal(types.NewProposal(
proposal.GetTitle(),
proposal.GetContent().GetDescription(),
proposal.ProposalRoute(),
proposal.ProposalType(),
proposal.ProposalId,
proposal.Status,
proposal.SubmitTime,
proposal.DepositEndTime,
proposal.VotingStartTime,
proposal.VotingEndTime,
"",
))
}