Skip to content

Commit

Permalink
refactor: add legacy params for easier migration
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed May 3, 2024
1 parent 34385f2 commit dfb231a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions x/authority/types/params_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package types

import (
"fmt"

"cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

var _ paramstypes.ParamSet = &Params{}

// Params is the legacy ParamAuthority interface.
// https://github.com/strangelove-ventures/paramauthority/blob/v1.1.0/x/params/types/proposal/genesis.pb.go#L71-L74
type Params struct {
Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty" yaml:"authority"`
}

// Deprecated: ParamKeyTable returns the legacy ParamAuthority key table.
// https://github.com/strangelove-ventures/paramauthority/blob/v1.1.0/x/params/types/proposal/params.go#L11-L14
func ParamKeyTable() paramstypes.KeyTable {
return paramstypes.NewKeyTable().RegisterParamSet(&Params{})
}

// ParamSetPairs implements the ParamSet interface.
// https://github.com/strangelove-ventures/paramauthority/blob/v1.1.0/x/params/types/proposal/params.go#L33-L38
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(AuthorityKey, p.Authority, validateAuthority),
}
}

// https://github.com/strangelove-ventures/paramauthority/blob/v1.1.0/x/params/types/proposal/params.go#L40-L51
func validateAuthority(i interface{}) error {
a, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if _, err := sdk.AccAddressFromBech32(a); err != nil {
return errors.Wrap(err, "authority")
}

return nil
}

0 comments on commit dfb231a

Please sign in to comment.