Skip to content

Commit

Permalink
Fix channel id from params not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
p0p3yee committed Aug 23, 2023
1 parent 4353a24 commit ff9f5ff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
7 changes: 7 additions & 0 deletions x/pep/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(
k.TrustedAddresses(ctx),
k.TrustedCounterParties(ctx),
k.ChannelID(ctx),
)
}

Expand All @@ -30,3 +31,9 @@ func (k Keeper) TrustedCounterParties(ctx sdk.Context) (res []*types.TrustedCoun
k.paramstore.Get(ctx, types.KeyTrustedCounterParties, &res)
return
}

// ChannelID returns the ChannelID param
func (k Keeper) ChannelID(ctx sdk.Context) (res string) {
k.paramstore.Get(ctx, types.KeyChannelID, &res)
return
}
2 changes: 1 addition & 1 deletion x/pep/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
PortID = "pep"

// ChannelID is the default channel id that module will use to transmit IBC packets.
ChannelID = "channel-01"
ChannelID = "channel-0"
)

var (
Expand Down
33 changes: 31 additions & 2 deletions x/pep/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,40 @@ var (
DefaultTrustedCounterParties []*TrustedCounterParty
)

var (
KeyChannelID = []byte("ChannelID")
DefaultChannelID = ChannelID
)

// ParamKeyTable the param key table for launch module
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}

// NewParams creates a new Params instance
func NewParams(trAddrs []string, trustedParties []*TrustedCounterParty) Params {
func NewParams(
trAddrs []string,
trustedParties []*TrustedCounterParty,
channelID string,
) Params {
return Params{
TrustedAddresses: trAddrs,
TrustedCounterParties: trustedParties,
ChannelId: channelID,
}
}

// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return NewParams(DefaultTrustedAddresses, DefaultTrustedCounterParties)
return NewParams(DefaultTrustedAddresses, DefaultTrustedCounterParties, DefaultChannelID)
}

// ParamSetPairs get the params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyTrustedAddresses, &p.TrustedAddresses, validateTrustedAddresses),
paramtypes.NewParamSetPair(KeyTrustedCounterParties, &p.TrustedCounterParties, validateTrustedCounterParties),
paramtypes.NewParamSetPair(KeyChannelID, &p.ChannelId, validateChannelID),
}
}

Expand All @@ -54,6 +65,10 @@ func (p Params) Validate() error {
if err := validateTrustedCounterParties(p.TrustedCounterParties); err != nil {
return err
}

if err := validateChannelID(p.ChannelId); err != nil {
return err
}
return nil
}

Expand All @@ -63,6 +78,20 @@ func (p Params) String() string {
return string(out)
}

// validateChannelID validates the channelID param
func validateChannelID(v interface{}) error {
channelID, ok := v.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", v)
}

if len(channelID) < 1 {
return fmt.Errorf("invalid Channel ID")
}

return nil
}

// validateTrustedAddresses validates the TrustedAddresses param
func validateTrustedAddresses(v interface{}) error {
trustedList, ok := v.([]string)
Expand Down

0 comments on commit ff9f5ff

Please sign in to comment.