github.com/Finschia/finschia-sdk@v0.48.1/x/collection/keeper/keeper.go (about)

     1  package keeper
     2  
     3  import (
     4  	"github.com/Finschia/ostracon/libs/log"
     5  
     6  	"github.com/Finschia/finschia-sdk/codec"
     7  	sdk "github.com/Finschia/finschia-sdk/types"
     8  	"github.com/Finschia/finschia-sdk/x/collection"
     9  	"github.com/Finschia/finschia-sdk/x/token/class"
    10  )
    11  
    12  // Keeper defines the collection module Keeper
    13  type Keeper struct {
    14  	classKeeper collection.ClassKeeper
    15  
    16  	// The (unexposed) keys used to access the stores from the Context.
    17  	storeKey sdk.StoreKey
    18  
    19  	// The codec for binary encoding/decoding.
    20  	cdc codec.Codec
    21  }
    22  
    23  // NewKeeper returns a collection keeper
    24  func NewKeeper(
    25  	cdc codec.Codec,
    26  	key sdk.StoreKey,
    27  	ck collection.ClassKeeper,
    28  ) Keeper {
    29  	return Keeper{
    30  		classKeeper: ck,
    31  		storeKey:    key,
    32  		cdc:         cdc,
    33  	}
    34  }
    35  
    36  // Logger returns a module-specific logger.
    37  func (k Keeper) Logger(ctx sdk.Context) log.Logger {
    38  	return ctx.Logger().With("module", "x/"+collection.ModuleName)
    39  }
    40  
    41  func ValidateLegacyContract(k Keeper, ctx sdk.Context, contractID string) error {
    42  	if !k.classKeeper.HasID(ctx, contractID) {
    43  		return class.ErrContractNotExist.Wrap(contractID)
    44  	}
    45  
    46  	if _, err := k.GetContract(ctx, contractID); err != nil {
    47  		return err
    48  	}
    49  
    50  	return nil
    51  }