planetmint-go/x/dao/keeper/reissuance.go
Jürgen Eckel c02e00616f
ignite scaffold type reissuance proposer rawtx tx-id block-height:uint --module dao
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-10-05 17:08:22 +02:00

31 lines
1006 B
Go

package keeper
import (
"math/big"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func (k Keeper) StoreReissuance(ctx sdk.Context, reissuance types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
appendValue := k.cdc.MustMarshal(&reissuance)
store.Set(getReissuanceBytes(reissuance.BlockHeight), appendValue)
}
func (k Keeper) GetReissuance(ctx sdk.Context, height uint64) (val types.Challenge, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
reissuance := store.Get(getReissuanceBytes(height))
if reissuance == nil {
return val, false
}
k.cdc.MustUnmarshal(reissuance, &val)
return val, true
}
func getReissuanceBytes(height uint64) []byte {
// Adding 1 because 0 will be interpreted as nil, which is an invalid key
return big.NewInt(int64(height + 1)).Bytes()
}