github.com/Finschia/finschia-sdk@v0.48.1/x/params/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/params/types"
     9  	"github.com/Finschia/finschia-sdk/x/params/types/proposal"
    10  )
    11  
    12  // Keeper of the global paramstore
    13  type Keeper struct {
    14  	cdc         codec.BinaryCodec
    15  	legacyAmino *codec.LegacyAmino
    16  	key         sdk.StoreKey
    17  	tkey        sdk.StoreKey
    18  	spaces      map[string]*types.Subspace
    19  }
    20  
    21  // NewKeeper constructs a params keeper
    22  func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) Keeper {
    23  	return Keeper{
    24  		cdc:         cdc,
    25  		legacyAmino: legacyAmino,
    26  		key:         key,
    27  		tkey:        tkey,
    28  		spaces:      make(map[string]*types.Subspace),
    29  	}
    30  }
    31  
    32  // Logger returns a module-specific logger.
    33  func (k Keeper) Logger(ctx sdk.Context) log.Logger {
    34  	return ctx.Logger().With("module", "x/"+proposal.ModuleName)
    35  }
    36  
    37  // Allocate subspace used for keepers
    38  func (k Keeper) Subspace(s string) types.Subspace {
    39  	_, ok := k.spaces[s]
    40  	if ok {
    41  		panic("subspace already occupied")
    42  	}
    43  
    44  	if s == "" {
    45  		panic("cannot use empty string for subspace")
    46  	}
    47  
    48  	space := types.NewSubspace(k.cdc, k.legacyAmino, k.key, k.tkey, s)
    49  	k.spaces[s] = &space
    50  
    51  	return space
    52  }
    53  
    54  // Get existing substore from keeper
    55  func (k Keeper) GetSubspace(s string) (types.Subspace, bool) {
    56  	space, ok := k.spaces[s]
    57  	if !ok {
    58  		return types.Subspace{}, false
    59  	}
    60  	return *space, ok
    61  }