github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/params/keeper.go (about)

     1  package params
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/params/subspace"
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/params/types"
    10  
    11  	"github.com/fibonacci-chain/fbc/libs/tendermint/libs/log"
    12  )
    13  
    14  // Keeper of the global paramstore
    15  type Keeper struct {
    16  	cdc    *codec.Codec
    17  	key    sdk.StoreKey
    18  	tkey   sdk.StoreKey
    19  	spaces map[string]*Subspace
    20  }
    21  
    22  // NewKeeper constructs a params keeper
    23  func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey) Keeper {
    24  	return Keeper{
    25  		cdc:    cdc,
    26  		key:    key,
    27  		tkey:   tkey,
    28  		spaces: make(map[string]*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", fmt.Sprintf("x/%s", types.ModuleName))
    35  }
    36  
    37  // Allocate subspace used for keepers
    38  func (k Keeper) Subspace(s string) 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 := subspace.NewSubspace(k.cdc, 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) (Subspace, bool) {
    56  	space, ok := k.spaces[s]
    57  	if !ok {
    58  		return Subspace{}, false
    59  	}
    60  	return *space, ok
    61  }