-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add legacy params for easier migration
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |