github.com/KiraCore/sekai@v0.3.43/x/gov/keeper/proposal_duration.go (about) 1 package keeper 2 3 import ( 4 "fmt" 5 6 "github.com/KiraCore/sekai/x/gov/types" 7 "github.com/cosmos/cosmos-sdk/store/prefix" 8 sdk "github.com/cosmos/cosmos-sdk/types" 9 ) 10 11 func (k Keeper) SetProposalDuration(ctx sdk.Context, proposalType string, duration uint64) error { 12 // duration should be longer than minimum proposal duration 13 properties := k.GetNetworkProperties(ctx) 14 if duration < properties.MinimumProposalEndTime { 15 return fmt.Errorf("duration should be longer than minimum proposal duration") 16 } 17 18 store := ctx.KVStore(k.storeKey) 19 prefixStore := prefix.NewStore(store, types.KeyPrefixProposalDuration) 20 prefixStore.Set([]byte(proposalType), sdk.Uint64ToBigEndian(duration)) 21 return nil 22 } 23 24 func (k Keeper) GetProposalDuration(ctx sdk.Context, proposalType string) uint64 { 25 store := ctx.KVStore(k.storeKey) 26 prefixStore := prefix.NewStore(store, types.KeyPrefixProposalDuration) 27 bz := prefixStore.Get([]byte(proposalType)) 28 if bz == nil { 29 return 0 30 } 31 return sdk.BigEndianToUint64(bz) 32 } 33 34 func (k Keeper) GetAllProposalDurations(ctx sdk.Context) map[string]uint64 { 35 proposalDurations := make(map[string]uint64) 36 store := ctx.KVStore(k.storeKey) 37 prefixStore := prefix.NewStore(store, types.KeyPrefixProposalDuration) 38 iterator := prefixStore.Iterator(nil, nil) 39 defer iterator.Close() 40 for ; iterator.Valid(); iterator.Next() { 41 proposalDurations[string(iterator.Key())] = sdk.BigEndianToUint64(iterator.Value()) 42 } 43 return proposalDurations 44 }