-
Notifications
You must be signed in to change notification settings - Fork 48
/
abci.go
35 lines (29 loc) · 1022 Bytes
/
abci.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
package posts
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/x/posts/keeper"
"github.com/desmos-labs/desmos/x/posts/types"
)
// EndBlocker called upon each block end to close expired polls
// TODO look how to iterate only over open poll
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
store := ctx.KVStore(k.StoreKey)
iterator := sdk.KVStorePrefixIterator(store, types.PostStorePrefix)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var post types.Post
k.Cdc.MustUnmarshalBinaryBare(iterator.Value(), &post)
if ctx.BlockTime().After(post.PollData.EndDate) || ctx.BlockTime().Equal(post.PollData.EndDate) {
post.PollData.Open = false
post.LastEdited = ctx.BlockTime()
k.SavePost(ctx, post)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeClosePoll,
sdk.NewAttribute(types.AttributeKeyPostID, post.PostID.String()),
sdk.NewAttribute(types.AttributeKeyPostOwner, post.Creator.String()),
),
)
}
}
}