2019-02-08 18:33:06 -08:00
|
|
|
package gov
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/tags"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Called every block, process inflation, update validator set
|
2019-04-05 13:20:58 -07:00
|
|
|
func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags {
|
2019-04-15 20:58:06 -07:00
|
|
|
logger := keeper.Logger(ctx)
|
2019-02-08 18:33:06 -08:00
|
|
|
resTags := sdk.NewTags()
|
|
|
|
|
|
|
|
inactiveIterator := keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
|
|
|
defer inactiveIterator.Close()
|
|
|
|
for ; inactiveIterator.Valid(); inactiveIterator.Next() {
|
|
|
|
var proposalID uint64
|
|
|
|
|
|
|
|
keeper.cdc.MustUnmarshalBinaryLengthPrefixed(inactiveIterator.Value(), &proposalID)
|
2019-03-15 09:47:47 -07:00
|
|
|
inactiveProposal, ok := keeper.GetProposal(ctx, proposalID)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Sprintf("proposal %d does not exist", proposalID))
|
|
|
|
}
|
2019-02-08 18:33:06 -08:00
|
|
|
|
|
|
|
keeper.DeleteProposal(ctx, proposalID)
|
|
|
|
keeper.DeleteDeposits(ctx, proposalID) // delete any associated deposits (burned)
|
|
|
|
|
|
|
|
resTags = resTags.AppendTag(tags.ProposalID, fmt.Sprintf("%d", proposalID))
|
|
|
|
resTags = resTags.AppendTag(tags.ProposalResult, tags.ActionProposalDropped)
|
|
|
|
|
|
|
|
logger.Info(
|
|
|
|
fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %s (had only %s); deleted",
|
2019-03-15 09:47:47 -07:00
|
|
|
inactiveProposal.ProposalID,
|
2019-02-08 18:33:06 -08:00
|
|
|
inactiveProposal.GetTitle(),
|
|
|
|
keeper.GetDepositParams(ctx).MinDeposit,
|
2019-03-15 09:47:47 -07:00
|
|
|
inactiveProposal.TotalDeposit,
|
2019-02-08 18:33:06 -08:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetch active proposals whose voting periods have ended (are passed the block time)
|
|
|
|
activeIterator := keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
|
|
|
defer activeIterator.Close()
|
|
|
|
for ; activeIterator.Valid(); activeIterator.Next() {
|
|
|
|
var proposalID uint64
|
|
|
|
|
|
|
|
keeper.cdc.MustUnmarshalBinaryLengthPrefixed(activeIterator.Value(), &proposalID)
|
2019-03-15 09:47:47 -07:00
|
|
|
activeProposal, ok := keeper.GetProposal(ctx, proposalID)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Sprintf("proposal %d does not exist", proposalID))
|
|
|
|
}
|
2019-02-08 18:33:06 -08:00
|
|
|
passes, tallyResults := tally(ctx, keeper, activeProposal)
|
|
|
|
|
|
|
|
var tagValue string
|
|
|
|
if passes {
|
2019-03-15 09:47:47 -07:00
|
|
|
keeper.RefundDeposits(ctx, activeProposal.ProposalID)
|
|
|
|
activeProposal.Status = StatusPassed
|
2019-02-08 18:33:06 -08:00
|
|
|
tagValue = tags.ActionProposalPassed
|
|
|
|
} else {
|
2019-03-15 09:47:47 -07:00
|
|
|
keeper.DeleteDeposits(ctx, activeProposal.ProposalID)
|
|
|
|
activeProposal.Status = StatusRejected
|
2019-02-08 18:33:06 -08:00
|
|
|
tagValue = tags.ActionProposalRejected
|
|
|
|
}
|
|
|
|
|
2019-03-15 09:47:47 -07:00
|
|
|
activeProposal.FinalTallyResult = tallyResults
|
2019-02-08 18:33:06 -08:00
|
|
|
keeper.SetProposal(ctx, activeProposal)
|
2019-03-15 09:47:47 -07:00
|
|
|
keeper.RemoveFromActiveProposalQueue(ctx, activeProposal.VotingEndTime, activeProposal.ProposalID)
|
2019-02-08 18:33:06 -08:00
|
|
|
|
|
|
|
logger.Info(
|
|
|
|
fmt.Sprintf(
|
|
|
|
"proposal %d (%s) tallied; passed: %v",
|
2019-03-15 09:47:47 -07:00
|
|
|
activeProposal.ProposalID, activeProposal.GetTitle(), passes,
|
2019-02-08 18:33:06 -08:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
resTags = resTags.AppendTag(tags.ProposalID, fmt.Sprintf("%d", proposalID))
|
|
|
|
resTags = resTags.AppendTag(tags.ProposalResult, tagValue)
|
|
|
|
}
|
|
|
|
|
2019-04-05 13:20:58 -07:00
|
|
|
return resTags
|
2019-02-08 18:33:06 -08:00
|
|
|
}
|