mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-28 00:42:30 +00:00

* added InitPoP message * added getChallenge query to inspect challenges * adjusted towards a unique block height identification unit: int64, not uint64 * added challenge param finished to identify challenges that weren't completed but will be part of re-issuance. Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
31 lines
959 B
Go
31 lines
959 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) StoreChallenge(ctx sdk.Context, challenge types.Challenge) {
|
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChallengeKey))
|
|
appendValue := k.cdc.MustMarshal(&challenge)
|
|
store.Set(getChallengeBytes(challenge.Height), appendValue)
|
|
}
|
|
|
|
func (k Keeper) LookupChallenge(ctx sdk.Context, height int64) (val types.Challenge, found bool) {
|
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ChallengeKey))
|
|
challenge := store.Get(getChallengeBytes(height))
|
|
if challenge == nil {
|
|
return val, false
|
|
}
|
|
k.cdc.MustUnmarshal(challenge, &val)
|
|
return val, true
|
|
}
|
|
|
|
func getChallengeBytes(height int64) []byte {
|
|
// Adding 1 because 0 will be interpreted as nil, which is an invalid key
|
|
return big.NewInt(height + 1).Bytes()
|
|
}
|