-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(x/bank/v2): migrate to handlers (#21659)
- Loading branch information
1 parent
766117c
commit bf817f8
Showing
12 changed files
with
144 additions
and
505 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
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
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
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 |
---|---|---|
@@ -1,40 +1,36 @@ | ||
package bankv2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" | ||
"cosmossdk.io/x/bank/v2/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/version" | ||
) | ||
|
||
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. | ||
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { | ||
return &autocliv1.ModuleOptions{ | ||
Query: &autocliv1.ServiceCommandDescriptor{ | ||
Service: types.Query_serviceDesc.ServiceName, | ||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{ | ||
{ | ||
RpcMethod: "Params", | ||
Use: "params", | ||
Short: "Query current bank/v2 parameters", | ||
}, | ||
}, | ||
}, | ||
Tx: &autocliv1.ServiceCommandDescriptor{ | ||
Service: types.Msg_serviceDesc.ServiceName, | ||
EnhanceCustomCommand: true, | ||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{ | ||
{ | ||
RpcMethod: "UpdateParams", | ||
Use: "update-params-proposal <params>", | ||
Short: "Submit a proposal to update bank module params. Note: the entire params must be provided.", | ||
Example: fmt.Sprintf(`%s tx bank update-params-proposal '{ }'`, version.AppName), | ||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}}, | ||
GovProposal: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
return nil // Disable AutoCLI until https://github.com/cosmos/cosmos-sdk/issues/21682 is resolved. | ||
// return &autocliv1.ModuleOptions{ | ||
// Query: &autocliv1.ServiceCommandDescriptor{ | ||
// Service: "cosmos.bank.v2.Query", | ||
// RpcCommandOptions: []*autocliv1.RpcCommandOptions{ | ||
// { | ||
// RpcMethod: "Params", | ||
// Use: "params", | ||
// Short: "Query current bank/v2 parameters", | ||
// }, | ||
// }, | ||
// }, | ||
// Tx: &autocliv1.ServiceCommandDescriptor{ | ||
// Service: "cosmos.bank.v2.Msg", | ||
// EnhanceCustomCommand: true, | ||
// RpcCommandOptions: []*autocliv1.RpcCommandOptions{ | ||
// { | ||
// RpcMethod: "UpdateParams", | ||
// Use: "update-params-proposal <params>", | ||
// Short: "Submit a proposal to update bank module params. Note: the entire params must be provided.", | ||
// Example: fmt.Sprintf(`%s tx bank update-params-proposal '{ }'`, version.AppName), | ||
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}}, | ||
// GovProposal: true, | ||
// }, | ||
// }, | ||
// }, | ||
// } | ||
} |
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,60 @@ | ||
package keeper | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"cosmossdk.io/x/bank/v2/types" | ||
) | ||
|
||
type handlers struct { | ||
*Keeper | ||
} | ||
|
||
// NewHandlers creates a new bank/v2 handlers | ||
func NewHandlers(k *Keeper) handlers { | ||
return handlers{k} | ||
} | ||
|
||
// UpdateParams updates the parameters of the bank/v2 module. | ||
func (h handlers) MsgUpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { | ||
authorityBytes, err := h.addressCodec.StringToBytes(msg.Authority) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !bytes.Equal(h.authority, authorityBytes) { | ||
expectedAuthority, err := h.addressCodec.BytesToString(h.authority) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, fmt.Errorf("invalid authority; expected %s, got %s", expectedAuthority, msg.Authority) | ||
} | ||
|
||
if err := msg.Params.Validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := h.params.Set(ctx, msg.Params); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgUpdateParamsResponse{}, nil | ||
} | ||
|
||
// QueryParams queries the parameters of the bank/v2 module. | ||
func (h handlers) QueryParams(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { | ||
if req == nil { | ||
return nil, errors.New("empty request") | ||
} | ||
|
||
params, err := h.params.Get(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.QueryParamsResponse{Params: params}, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.