laconicd/x/registry/keeper/invariants.go

37 lines
1.1 KiB
Go
Raw Normal View History

package keeper
import (
2022-12-09 04:17:14 +00:00
"github.com/cerc-io/laconicd/x/registry/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
2022-12-09 04:17:14 +00:00
// RegisterInvariants registers all registry module invariants.
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {
ir.RegisterRoute(types.ModuleName, "record", RecordInvariants(k))
}
// RecordInvariants checks that every record:
// (1) has a corresponding naming record &
// (2) associated bond exists, if bondID is not null.
func RecordInvariants(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
2022-10-17 07:15:01 +00:00
// store := ctx.KVStore(k.storeKey)
// itr := sdk.KVStorePrefixIterator(store, PrefixCIDToRecordIndex)
// defer itr.Close()
// for ; itr.Valid(); itr.Next() {
// bz := store.Get(itr.Key())
// if bz != nil {
// var obj types.RecordObj
// k.cdc.MustUnmarshalBinaryBare(bz, &obj)
// record := obj.ToRecord()
// if record.BondID != "" && !k.bondKeeper.HasBond(ctx, record.BondID) {
// return sdk.FormatInvariant(types.ModuleName, "record-bond", fmt.Sprintf("Bond not found for record ID: '%s'.", record.ID)), true
// }
// }
// }
return "", false
}
}