refactor(x/bank/v2): migrate to handlers (#21659)

This commit is contained in:
Julien Robert 2024-09-12 14:23:41 +02:00 committed by GitHub
parent 766117c5ff
commit bf817f89aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 144 additions and 505 deletions

View File

@ -3,6 +3,6 @@ plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true
# - name: grpc-gateway ## TODO find a way to exclude v2
# out: ..
# opt: logtostderr=true,allow_colon_final_segments=true

View File

@ -2,22 +2,11 @@ syntax = "proto3";
package cosmos.bank.v2;
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/query/v1/query.proto";
import "amino/amino.proto";
import "cosmos/bank/v2/bank.proto";
option go_package = "cosmossdk.io/x/bank/v2/types";
// Query defines the gRPC querier service.
service Query {
// Params queries the parameters of x/bank module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cosmos/bank/v2/params";
}
}
// QueryParamsRequest defines the request type for querying x/bank/v2 parameters.
message QueryParamsRequest {}

View File

@ -9,15 +9,6 @@ import "amino/amino.proto";
option go_package = "cosmossdk.io/x/bank/v2/types";
// Msg defines the bank Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
// UpdateParams defines a governance operation for updating the x/bank/v2 module parameters.
// The authority is defined in the keeper.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {}
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

View File

@ -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,
// },
// },
// },
// }
}

View File

@ -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
}

View File

@ -1,47 +0,0 @@
package keeper
import (
"bytes"
"context"
"fmt"
"cosmossdk.io/x/bank/v2/types"
)
var _ types.MsgServer = msgServer{}
type msgServer struct {
*Keeper
}
// NewMsgServer creates a new bank/v2 message server.
func NewMsgServer(k *Keeper) types.MsgServer {
return msgServer{k}
}
// UpdateParams implements types.MsgServer.
func (m msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
authorityBytes, err := m.addressCodec.StringToBytes(msg.Authority)
if err != nil {
return nil, err
}
if !bytes.Equal(m.authority, authorityBytes) {
expectedAuthority, err := m.addressCodec.BytesToString(m.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 := m.params.Set(ctx, msg.Params); err != nil {
return nil, err
}
return &types.MsgUpdateParamsResponse{}, nil
}

View File

@ -1,33 +0,0 @@
package keeper
import (
"context"
"errors"
"cosmossdk.io/x/bank/v2/types"
)
var _ types.QueryServer = querier{}
type querier struct {
*Keeper
}
// NewMsgServer creates a new bank/v2 query server.
func NewQuerier(k *Keeper) types.QueryServer {
return querier{k}
}
// Params implements types.QueryServer.
func (q querier) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, errors.New("empty request")
}
params, err := q.params.Get(ctx)
if err != nil {
return nil, err
}
return &types.QueryParamsResponse{Params: params}, nil
}

View File

@ -3,9 +3,10 @@ package bankv2
import (
"context"
"encoding/json"
"errors"
"fmt"
"google.golang.org/grpc"
gogoproto "github.com/cosmos/gogoproto/proto"
appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/registry"
@ -22,6 +23,8 @@ var (
_ appmodulev2.AppModule = AppModule{}
_ appmodulev2.HasGenesis = AppModule{}
_ appmodulev2.HasRegisterInterfaces = AppModule{}
_ appmodulev2.HasQueryHandlers = AppModule{}
_ appmodulev2.HasMsgHandlers = AppModule{}
)
// AppModule implements an application module for the bank module.
@ -53,14 +56,6 @@ func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
types.RegisterInterfaces(registrar)
}
// RegisterServices registers module services.
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
types.RegisterMsgServer(registrar, keeper.NewMsgServer(am.keeper))
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
return nil
}
// DefaultGenesis returns default genesis state as raw bytes for the bank module.
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(types.DefaultGenesisState())
@ -95,3 +90,35 @@ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)
return am.cdc.MarshalJSON(gs)
}
// RegisterMsgHandlers registers the message handlers for the bank module.
func (am AppModule) RegisterMsgHandlers(router appmodulev2.MsgRouter) {
handlers := keeper.NewHandlers(am.keeper)
var errs error
if err := appmodulev2.RegisterHandler(
router, gogoproto.MessageName(&types.MsgUpdateParams{}), handlers.MsgUpdateParams,
); err != nil {
errs = errors.Join(errs, err)
}
if errs != nil {
panic(errs)
}
}
// RegisterQueryHandlers registers the query handlers for the bank module.
func (am AppModule) RegisterQueryHandlers(router appmodulev2.QueryRouter) {
handlers := keeper.NewHandlers(am.keeper)
var errs error
if err := appmodulev2.RegisterHandler(
router, gogoproto.MessageName(&types.QueryParamsRequest{}), handlers.QueryParams,
); err != nil {
errs = errors.Join(errs, err)
}
if errs != nil {
panic(errs)
}
}

View File

@ -3,14 +3,10 @@ package types
import (
"cosmossdk.io/core/registry"
"cosmossdk.io/core/transaction"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)
func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
registrar.RegisterImplementations((*transaction.Msg)(nil),
&MsgUpdateParams{},
)
msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc)
}

View File

@ -4,17 +4,10 @@
package types
import (
context "context"
fmt "fmt"
_ "github.com/cosmos/cosmos-sdk/types/query"
_ "github.com/cosmos/cosmos-sdk/types/tx/amino"
_ "github.com/cosmos/gogoproto/gogoproto"
grpc1 "github.com/cosmos/gogoproto/grpc"
proto "github.com/cosmos/gogoproto/proto"
_ "google.golang.org/genproto/googleapis/api/annotations"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
math "math"
math_bits "math/bits"
@ -122,109 +115,21 @@ func init() {
func init() { proto.RegisterFile("cosmos/bank/v2/query.proto", fileDescriptor_bf35183cd83cb842) }
var fileDescriptor_bf35183cd83cb842 = []byte{
// 294 bytes of a gzipped FileDescriptorProto
// 213 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4a, 0xce, 0x2f, 0xce,
0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0xcc, 0xcb, 0xd6, 0x2f, 0x33, 0xd2, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa,
0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0xc8, 0xe9, 0x81, 0xe4, 0xf4, 0xca, 0x8c,
0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0x95, 0x94, 0x4c, 0x7a,
0x7e, 0x7e, 0x7a, 0x4e, 0xaa, 0x7e, 0x62, 0x41, 0xa6, 0x7e, 0x62, 0x5e, 0x5e, 0x7e, 0x49, 0x62,
0x49, 0x66, 0x7e, 0x5e, 0x31, 0x54, 0x56, 0x1a, 0x6a, 0x3e, 0xd8, 0x5c, 0xfd, 0x32, 0x43, 0x64,
0x0b, 0xa4, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x54, 0x48, 0x12, 0xcd, 0x3d,
0x60, 0xbb, 0xc1, 0x52, 0x4a, 0x22, 0x5c, 0x42, 0x81, 0x20, 0xcd, 0x01, 0x89, 0x45, 0x89, 0xb9,
0xc5, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0x01, 0x5c, 0xc2, 0x28, 0xa2, 0xc5, 0x05,
0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x96, 0x5c, 0x6c, 0x05, 0x60, 0x11, 0x09, 0x46, 0x05, 0x46, 0x0d,
0x6e, 0x23, 0x31, 0x3d, 0x54, 0xcf, 0xe8, 0x41, 0xd4, 0x3b, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0,
0xe2, 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x06, 0xa3, 0x7a, 0x2e, 0x56, 0xb0, 0x89, 0x42, 0x65,
0x5c, 0x6c, 0x10, 0x55, 0x42, 0x4a, 0xe8, 0xba, 0x31, 0x1d, 0x22, 0xa5, 0x8c, 0x57, 0x0d, 0xc4,
0x59, 0x4a, 0xca, 0x1d, 0x20, 0xab, 0x9a, 0x2e, 0x3f, 0x99, 0xcc, 0x24, 0x21, 0x24, 0xa6, 0x8f,
0xe6, 0x59, 0x88, 0x03, 0x9c, 0xcc, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1,
0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21,
0x4a, 0x06, 0xa2, 0xa1, 0x38, 0x25, 0x5b, 0x2f, 0x33, 0x5f, 0xbf, 0x02, 0xae, 0xb1, 0xa4, 0xb2,
0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x4e, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x75, 0xc4,
0xad, 0xf4, 0xd4, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// QueryClient is the client API for Query service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type QueryClient interface {
// Params queries the parameters of x/bank module.
Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
}
type queryClient struct {
cc grpc1.ClientConn
}
func NewQueryClient(cc grpc1.ClientConn) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) {
out := new(QueryParamsResponse)
err := c.cc.Invoke(ctx, "/cosmos.bank.v2.Query/Params", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// QueryServer is the server API for Query service.
type QueryServer interface {
// Params queries the parameters of x/bank module.
Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
}
// UnimplementedQueryServer can be embedded to have forward compatible implementations.
type UnimplementedQueryServer struct {
}
func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Params not implemented")
}
func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
s.RegisterService(&_Query_serviceDesc, srv)
}
func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryParamsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).Params(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/cosmos.bank.v2.Query/Params",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest))
}
return interceptor(ctx, in, info, handler)
}
var Query_serviceDesc = _Query_serviceDesc
var _Query_serviceDesc = grpc.ServiceDesc{
ServiceName: "cosmos.bank.v2.Query",
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Params",
Handler: _Query_Params_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cosmos/bank/v2/query.proto",
0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0x95, 0x94, 0x60, 0x62,
0x6e, 0x66, 0x5e, 0xbe, 0x3e, 0x98, 0x84, 0x0a, 0x49, 0xa2, 0x19, 0x0a, 0x36, 0x00, 0x2c, 0xa5,
0x24, 0xc2, 0x25, 0x14, 0x08, 0xb2, 0x22, 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x38, 0x28, 0xb5, 0xb0,
0x34, 0xb5, 0xb8, 0x44, 0x29, 0x80, 0x4b, 0x18, 0x45, 0xb4, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55,
0xc8, 0x92, 0x8b, 0xad, 0x00, 0x2c, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa6, 0x87,
0xea, 0x22, 0x3d, 0x88, 0x7a, 0x27, 0xce, 0x13, 0xf7, 0xe4, 0x19, 0x56, 0x3c, 0xdf, 0xa0, 0xc5,
0x18, 0x04, 0xd5, 0xe0, 0x64, 0x76, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e,
0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51,
0x32, 0x10, 0x33, 0x8a, 0x53, 0xb2, 0xf5, 0x32, 0xf3, 0xf5, 0x2b, 0xe0, 0x8e, 0x2c, 0xa9, 0x2c,
0x48, 0x2d, 0x4e, 0x62, 0x03, 0x3b, 0xd3, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x47, 0xcc,
0x3c, 0x18, 0x01, 0x00, 0x00,
}
func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) {

View File

@ -1,153 +0,0 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: cosmos/bank/v2/query.proto
/*
Package types is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package types
import (
"context"
"io"
"net/http"
"github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
var _ = metadata.Join
func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := server.Params(ctx, &protoReq)
return msg, metadata, err
}
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
// UnaryRPC :call QueryServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterQueryHandler(ctx, mux, conn)
}
// RegisterQueryHandler registers the http handlers for service Query to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn))
}
// RegisterQueryHandlerClient registers the http handlers for service Query
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "QueryClient" to call the correct interceptors.
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "bank", "v2", "params"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Query_Params_0 = runtime.ForwardResponseMessage
)

View File

@ -4,17 +4,12 @@
package types
import (
context "context"
fmt "fmt"
_ "github.com/cosmos/cosmos-proto"
_ "github.com/cosmos/cosmos-sdk/types/msgservice"
_ "github.com/cosmos/cosmos-sdk/types/tx/amino"
_ "github.com/cosmos/gogoproto/gogoproto"
grpc1 "github.com/cosmos/gogoproto/grpc"
proto "github.com/cosmos/gogoproto/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
math "math"
math_bits "math/bits"
@ -132,7 +127,7 @@ func init() {
func init() { proto.RegisterFile("cosmos/bank/v2/tx.proto", fileDescriptor_14123aa47d73c00a) }
var fileDescriptor_14123aa47d73c00a = []byte{
// 332 bytes of a gzipped FileDescriptorProto
// 299 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4f, 0xce, 0x2f, 0xce,
0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0xcc, 0xcb, 0xd6, 0x2f, 0x33, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28,
0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0x48, 0xe8, 0x81, 0x24, 0xf4, 0xca, 0x8c, 0xa4, 0x44, 0xd2,
@ -147,98 +142,11 @@ var fileDescriptor_14123aa47d73c00a = []byte{
0x93, 0x7a, 0x10, 0xf3, 0x9d, 0x38, 0x4f, 0xdc, 0x93, 0x67, 0x58, 0xf1, 0x7c, 0x83, 0x16, 0x63,
0x10, 0x54, 0x83, 0x95, 0x79, 0xd3, 0xf3, 0x0d, 0x5a, 0x08, 0xa3, 0xba, 0x9e, 0x6f, 0xd0, 0x52,
0x81, 0x68, 0xd6, 0x2d, 0x4e, 0xc9, 0xd6, 0xaf, 0x80, 0x87, 0x00, 0x9a, 0x5b, 0x95, 0x24, 0xb9,
0xc4, 0xd1, 0x84, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x8d, 0x32, 0xb8, 0x98, 0x7d,
0x8b, 0xd3, 0x85, 0xa2, 0xb8, 0x78, 0x50, 0x7c, 0x27, 0x8f, 0xee, 0x2a, 0x34, 0xfd, 0x52, 0xea,
0x04, 0x14, 0xc0, 0x2c, 0x50, 0x62, 0x90, 0x62, 0x6d, 0x00, 0xf9, 0xc2, 0xc9, 0xec, 0xc4, 0x23,
0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2,
0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x64, 0x20, 0x46, 0x15, 0xa7, 0x64, 0xeb, 0x65,
0xe6, 0x23, 0x79, 0xa3, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x07, 0xc6, 0x80, 0x00,
0x00, 0x00, 0xff, 0xff, 0x48, 0xbd, 0x6a, 0x7d, 0x26, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// MsgClient is the client API for Msg service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type MsgClient interface {
// UpdateParams defines a governance operation for updating the x/bank/v2 module parameters.
// The authority is defined in the keeper.
UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error)
}
type msgClient struct {
cc grpc1.ClientConn
}
func NewMsgClient(cc grpc1.ClientConn) MsgClient {
return &msgClient{cc}
}
func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) {
out := new(MsgUpdateParamsResponse)
err := c.cc.Invoke(ctx, "/cosmos.bank.v2.Msg/UpdateParams", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// MsgServer is the server API for Msg service.
type MsgServer interface {
// UpdateParams defines a governance operation for updating the x/bank/v2 module parameters.
// The authority is defined in the keeper.
UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error)
}
// UnimplementedMsgServer can be embedded to have forward compatible implementations.
type UnimplementedMsgServer struct {
}
func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented")
}
func RegisterMsgServer(s grpc1.Server, srv MsgServer) {
s.RegisterService(&_Msg_serviceDesc, srv)
}
func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MsgUpdateParams)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MsgServer).UpdateParams(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/cosmos.bank.v2.Msg/UpdateParams",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams))
}
return interceptor(ctx, in, info, handler)
}
var Msg_serviceDesc = _Msg_serviceDesc
var _Msg_serviceDesc = grpc.ServiceDesc{
ServiceName: "cosmos.bank.v2.Msg",
HandlerType: (*MsgServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "UpdateParams",
Handler: _Msg_UpdateParams_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cosmos/bank/v2/tx.proto",
0xc4, 0xd1, 0x84, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x9d, 0xcc, 0x4e, 0x3c, 0x92,
0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c,
0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x06, 0x62, 0x74, 0x71, 0x4a, 0xb6, 0x5e, 0x66,
0x3e, 0x92, 0xe1, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x90, 0x31, 0x06, 0x04, 0x00,
0x00, 0xff, 0xff, 0xbd, 0xd0, 0xd5, 0x76, 0xbc, 0x01, 0x00, 0x00,
}
func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) {