diff --git a/middleware/packet-forward-middleware/router/keeper/params.go b/middleware/packet-forward-middleware/router/keeper/params.go index a73bcdd0..f7c3bdce 100644 --- a/middleware/packet-forward-middleware/router/keeper/params.go +++ b/middleware/packet-forward-middleware/router/keeper/params.go @@ -6,19 +6,19 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// GetSendEnabled retrieves the send enabled boolean from the paramstore +// GetFeePercentage retrieves the fee percentage for forwarded packets from the store. func (k Keeper) GetFeePercentage(ctx sdk.Context) sdk.Dec { var res sdk.Dec k.paramSpace.Get(ctx, types.KeyFeePercentage, &res) return res } -// GetParams returns the total set of ibc-transfer parameters. +// GetParams returns the total set of pfm parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { return types.NewParams(k.GetFeePercentage(ctx)) } -// SetParams sets the total set of ibc-transfer parameters. +// SetParams sets the total set of pfm parameters. func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } diff --git a/middleware/packet-forward-middleware/router/module.go b/middleware/packet-forward-middleware/router/module.go index 7c42f9db..561d02f1 100644 --- a/middleware/packet-forward-middleware/router/module.go +++ b/middleware/packet-forward-middleware/router/module.go @@ -102,6 +102,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the ibc-router module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + err := am.ValidateGenesis(cdc, nil, data) + if err != nil { + panic(err) + } + var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, genesisState) diff --git a/middleware/packet-forward-middleware/router/types/genesis.go b/middleware/packet-forward-middleware/router/types/genesis.go index 10efe103..a6f39848 100644 --- a/middleware/packet-forward-middleware/router/types/genesis.go +++ b/middleware/packet-forward-middleware/router/types/genesis.go @@ -1,6 +1,6 @@ package types -// NewGenesisState creates a 29-fee GenesisState instance. +// NewGenesisState creates a pfm GenesisState instance. func NewGenesisState(params Params, inFlightPackets map[string]InFlightPacket) *GenesisState { return &GenesisState{ Params: params, @@ -8,7 +8,7 @@ func NewGenesisState(params Params, inFlightPackets map[string]InFlightPacket) * } } -// DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. +// DefaultGenesisState returns a GenesisState with a default fee percentage of 0. func DefaultGenesisState() *GenesisState { return &GenesisState{ Params: DefaultParams(), @@ -16,8 +16,7 @@ func DefaultGenesisState() *GenesisState { } } -// Validate performs basic genesis state validation returning an error upon any -// failure. +// Validate performs basic genesis state validation returning an error upon any failure. func (gs GenesisState) Validate() error { return gs.Params.Validate() } diff --git a/middleware/packet-forward-middleware/router/types/params.go b/middleware/packet-forward-middleware/router/types/params.go index 8884cfed..bc79dfbe 100644 --- a/middleware/packet-forward-middleware/router/types/params.go +++ b/middleware/packet-forward-middleware/router/types/params.go @@ -1,47 +1,50 @@ package types import ( - fmt "fmt" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) var ( + // DefaultFeePercentage is the default value used to extract a fee from all forwarded packets. DefaultFeePercentage = sdk.NewDec(0) + // KeyFeePercentage is store's key for FeePercentage Params KeyFeePercentage = []byte("FeePercentage") ) -// ParamKeyTable type declaration for parameters +// ParamKeyTable type declaration for parameters. func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -// NewParams creates a new parameter configuration for the ibc transfer module +// NewParams creates a new parameter configuration for the pfm module. func NewParams(feePercentage sdk.Dec) Params { return Params{ FeePercentage: feePercentage, } } -// DefaultParams is the default parameter configuration for the ibc-transfer module +// DefaultParams is the default parameter configuration for the pfm module. func DefaultParams() Params { return NewParams(DefaultFeePercentage) } -// Validate all ibc-transfer module parameters +// Validate the pfm module parameters. func (p Params) Validate() error { return validateFeePercentage(p.FeePercentage) } -// ParamSetPairs implements params.ParamSet +// ParamSetPairs implements params.ParamSet. func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyFeePercentage, p.FeePercentage, validateFeePercentage), } } +// validateFeePercentage asserts that the fee percentage param is a valid sdk.Dec type. func validateFeePercentage(i interface{}) error { v, ok := i.(sdk.Dec) if !ok {