From a986c29558b804cc4f3d43e251f4cbdb85881c80 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 13:39:41 +0100 Subject: [PATCH 01/20] Add empty TxByHash --- baseapp/grpcrouter.go | 8 +- client/grpc/simulate/simulate.pb.go | 679 ----------- client/grpc/simulate/simulate.pb.gw.go | 166 --- client/tx/tx.go | 15 +- client/tx/tx_test.go | 4 +- .../base/simulate/v1beta1/simulate.proto | 33 - proto/cosmos/tx/v1beta1/service.proto | 49 + .../simulate.go => types/tx/service.go | 22 +- types/tx/service.pb.go | 1079 +++++++++++++++++ types/tx/service.pb.gw.go | 246 ++++ .../tx/service_test.go | 21 +- x/simulation/operation.go | 2 +- 12 files changed, 1412 insertions(+), 912 deletions(-) delete mode 100644 client/grpc/simulate/simulate.pb.go delete mode 100644 client/grpc/simulate/simulate.pb.gw.go delete mode 100644 proto/cosmos/base/simulate/v1beta1/simulate.proto create mode 100644 proto/cosmos/tx/v1beta1/service.proto rename client/grpc/simulate/simulate.go => types/tx/service.go (60%) create mode 100644 types/tx/service.pb.go create mode 100644 types/tx/service.pb.gw.go rename client/grpc/simulate/simulate_test.go => types/tx/service_test.go (86%) diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go index a32da6758120..4c0c7e97e572 100644 --- a/baseapp/grpcrouter.go +++ b/baseapp/grpcrouter.go @@ -10,9 +10,9 @@ import ( "google.golang.org/grpc/encoding/proto" "github.com/cosmos/cosmos-sdk/client/grpc/reflection" - "github.com/cosmos/cosmos-sdk/client/grpc/simulate" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" ) var protoCodec = encoding.GetCodec(proto.Name) @@ -113,11 +113,11 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In // RegisterSimulateService registers the simulate service on the gRPC router. func (qrt *GRPCQueryRouter) RegisterSimulateService( - simulateFn simulate.BaseAppSimulateFn, + simulateFn tx.BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry, ) { - simulate.RegisterSimulateServiceServer( + tx.RegisterServiceServer( qrt, - simulate.NewSimulateServer(simulateFn, interfaceRegistry), + tx.NewTxServer(simulateFn, interfaceRegistry), ) } diff --git a/client/grpc/simulate/simulate.pb.go b/client/grpc/simulate/simulate.pb.go deleted file mode 100644 index 8fe707913e00..000000000000 --- a/client/grpc/simulate/simulate.pb.go +++ /dev/null @@ -1,679 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: cosmos/base/simulate/v1beta1/simulate.proto - -package simulate - -import ( - context "context" - fmt "fmt" - types "github.com/cosmos/cosmos-sdk/types" - tx "github.com/cosmos/cosmos-sdk/types/tx" - grpc1 "github.com/gogo/protobuf/grpc" - proto "github.com/gogo/protobuf/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" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// SimulateRequest is the request type for the SimulateServiceService.Simulate -// RPC method. -type SimulateRequest struct { - // tx is the transaction to simulate. - Tx *tx.Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` -} - -func (m *SimulateRequest) Reset() { *m = SimulateRequest{} } -func (m *SimulateRequest) String() string { return proto.CompactTextString(m) } -func (*SimulateRequest) ProtoMessage() {} -func (*SimulateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_503c836d80bb2d47, []int{0} -} -func (m *SimulateRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SimulateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SimulateRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SimulateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_SimulateRequest.Merge(m, src) -} -func (m *SimulateRequest) XXX_Size() int { - return m.Size() -} -func (m *SimulateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_SimulateRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_SimulateRequest proto.InternalMessageInfo - -func (m *SimulateRequest) GetTx() *tx.Tx { - if m != nil { - return m.Tx - } - return nil -} - -// SimulateResponse is the response type for the -// SimulateServiceService.SimulateRPC method. -type SimulateResponse struct { - // gas_info is the information about gas used in the simulation. - GasInfo *types.GasInfo `protobuf:"bytes,1,opt,name=gas_info,json=gasInfo,proto3" json:"gas_info,omitempty"` - // result is the result of the simulation. - Result *types.Result `protobuf:"bytes,2,opt,name=result,proto3" json:"result,omitempty"` -} - -func (m *SimulateResponse) Reset() { *m = SimulateResponse{} } -func (m *SimulateResponse) String() string { return proto.CompactTextString(m) } -func (*SimulateResponse) ProtoMessage() {} -func (*SimulateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_503c836d80bb2d47, []int{1} -} -func (m *SimulateResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SimulateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SimulateResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SimulateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_SimulateResponse.Merge(m, src) -} -func (m *SimulateResponse) XXX_Size() int { - return m.Size() -} -func (m *SimulateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_SimulateResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_SimulateResponse proto.InternalMessageInfo - -func (m *SimulateResponse) GetGasInfo() *types.GasInfo { - if m != nil { - return m.GasInfo - } - return nil -} - -func (m *SimulateResponse) GetResult() *types.Result { - if m != nil { - return m.Result - } - return nil -} - -func init() { - proto.RegisterType((*SimulateRequest)(nil), "cosmos.base.simulate.v1beta1.SimulateRequest") - proto.RegisterType((*SimulateResponse)(nil), "cosmos.base.simulate.v1beta1.SimulateResponse") -} - -func init() { - proto.RegisterFile("cosmos/base/simulate/v1beta1/simulate.proto", fileDescriptor_503c836d80bb2d47) -} - -var fileDescriptor_503c836d80bb2d47 = []byte{ - // 351 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xbf, 0x4b, 0xf3, 0x40, - 0x18, 0xc7, 0x7b, 0x19, 0xfa, 0x96, 0x7b, 0x87, 0xf7, 0x25, 0x20, 0x94, 0x50, 0x42, 0x8d, 0x28, - 0x05, 0xe9, 0x1d, 0xad, 0x4b, 0x07, 0x27, 0x17, 0x11, 0xb7, 0xd4, 0xc9, 0x45, 0x2e, 0xf1, 0x1a, - 0x0f, 0xd3, 0xbb, 0x98, 0x7b, 0x52, 0x32, 0x3b, 0x3a, 0x09, 0x4e, 0xfe, 0x11, 0xfe, 0x1f, 0x8e, - 0x05, 0x17, 0x47, 0x69, 0xfd, 0x43, 0xa4, 0xc9, 0x25, 0x2d, 0x82, 0xd2, 0x29, 0xb9, 0xe7, 0xf9, - 0x7c, 0xbf, 0xcf, 0x2f, 0x7c, 0x18, 0x2a, 0x3d, 0x55, 0x9a, 0x06, 0x4c, 0x73, 0xaa, 0xc5, 0x34, - 0x8b, 0x19, 0x70, 0x3a, 0x1b, 0x04, 0x1c, 0xd8, 0xa0, 0x0e, 0x90, 0x24, 0x55, 0xa0, 0xec, 0x4e, - 0x09, 0x93, 0x15, 0x4c, 0xea, 0x9c, 0x81, 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6, 0x4b, 0xb7, 0xf1, - 0xbe, 0x74, 0x1b, 0x97, 0x83, 0x48, 0xc0, 0x4d, 0x16, 0x90, 0x50, 0x4d, 0x2b, 0xaf, 0xf2, 0xd3, - 0xd7, 0xd7, 0xb7, 0x34, 0x8c, 0x05, 0x97, 0x40, 0xa3, 0x34, 0x09, 0x6b, 0xb3, 0xa0, 0x59, 0x9c, - 0xf2, 0xe8, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x7d, 0x16, 0xed, 0x90, 0x76, 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 - -// SimulateServiceClient is the client API for SimulateService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type SimulateServiceClient interface { - // Simulate simulates executing a transaction for estimating gas usage. - Simulate(ctx context.Context, in *SimulateRequest, opts ...grpc.CallOption) (*SimulateResponse, error) -} - -type simulateServiceClient struct { - cc grpc1.ClientConn -} - -func NewSimulateServiceClient(cc grpc1.ClientConn) SimulateServiceClient { - return &simulateServiceClient{cc} -} - -func (c *simulateServiceClient) Simulate(ctx context.Context, in *SimulateRequest, opts ...grpc.CallOption) (*SimulateResponse, error) { - out := new(SimulateResponse) - err := c.cc.Invoke(ctx, "/cosmos.base.simulate.v1beta1.SimulateService/Simulate", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// SimulateServiceServer is the server API for SimulateService service. -type SimulateServiceServer interface { - // Simulate simulates executing a transaction for estimating gas usage. - Simulate(context.Context, *SimulateRequest) (*SimulateResponse, error) -} - -// UnimplementedSimulateServiceServer can be embedded to have forward compatible implementations. -type UnimplementedSimulateServiceServer struct { -} - -func (*UnimplementedSimulateServiceServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Simulate not implemented") -} - -func RegisterSimulateServiceServer(s grpc1.Server, srv SimulateServiceServer) { - s.RegisterService(&_SimulateService_serviceDesc, srv) -} - -func _SimulateService_Simulate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SimulateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(SimulateServiceServer).Simulate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.base.simulate.v1beta1.SimulateService/Simulate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(SimulateServiceServer).Simulate(ctx, req.(*SimulateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _SimulateService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "cosmos.base.simulate.v1beta1.SimulateService", - HandlerType: (*SimulateServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Simulate", - Handler: _SimulateService_Simulate_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "cosmos/base/simulate/v1beta1/simulate.proto", -} - -func (m *SimulateRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SimulateRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SimulateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Tx != nil { - { - size, err := m.Tx.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintSimulate(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *SimulateResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SimulateResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SimulateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Result != nil { - { - size, err := m.Result.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintSimulate(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.GasInfo != nil { - { - size, err := m.GasInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintSimulate(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintSimulate(dAtA []byte, offset int, v uint64) int { - offset -= sovSimulate(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *SimulateRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Tx != nil { - l = m.Tx.Size() - n += 1 + l + sovSimulate(uint64(l)) - } - return n -} - -func (m *SimulateResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.GasInfo != nil { - l = m.GasInfo.Size() - n += 1 + l + sovSimulate(uint64(l)) - } - if m.Result != nil { - l = m.Result.Size() - n += 1 + l + sovSimulate(uint64(l)) - } - return n -} - -func sovSimulate(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozSimulate(x uint64) (n int) { - return sovSimulate(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *SimulateRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSimulate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SimulateRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SimulateRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Tx", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSimulate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSimulate - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSimulate - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Tx == nil { - m.Tx = &tx.Tx{} - } - if err := m.Tx.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSimulate(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSimulate - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSimulate - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SimulateResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSimulate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SimulateResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SimulateResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field GasInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSimulate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSimulate - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSimulate - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.GasInfo == nil { - m.GasInfo = &types.GasInfo{} - } - if err := m.GasInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSimulate - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSimulate - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSimulate - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Result == nil { - m.Result = &types.Result{} - } - if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSimulate(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSimulate - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSimulate - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipSimulate(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSimulate - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSimulate - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSimulate - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthSimulate - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupSimulate - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthSimulate - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthSimulate = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSimulate = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupSimulate = fmt.Errorf("proto: unexpected end of group") -) diff --git a/client/grpc/simulate/simulate.pb.gw.go b/client/grpc/simulate/simulate.pb.gw.go deleted file mode 100644 index 78cb85437c22..000000000000 --- a/client/grpc/simulate/simulate.pb.gw.go +++ /dev/null @@ -1,166 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: cosmos/base/simulate/v1beta1/simulate.proto - -/* -Package simulate is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package simulate - -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/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 ( - filter_SimulateService_Simulate_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_SimulateService_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, client SimulateServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq SimulateRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_SimulateService_Simulate_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Simulate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_SimulateService_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, server SimulateServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq SimulateRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_SimulateService_Simulate_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Simulate(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterSimulateServiceHandlerServer registers the http handlers for service SimulateService to "mux". -// UnaryRPC :call SimulateServiceServer 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 (such as grpc.SendHeader, etc) to stop working. Consider using RegisterSimulateServiceHandlerFromEndpoint instead. -func RegisterSimulateServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server SimulateServiceServer) error { - - mux.Handle("POST", pattern_SimulateService_Simulate_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.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_SimulateService_Simulate_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SimulateService_Simulate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterSimulateServiceHandlerFromEndpoint is same as RegisterSimulateServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterSimulateServiceHandlerFromEndpoint(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 RegisterSimulateServiceHandler(ctx, mux, conn) -} - -// RegisterSimulateServiceHandler registers the http handlers for service SimulateService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterSimulateServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterSimulateServiceHandlerClient(ctx, mux, NewSimulateServiceClient(conn)) -} - -// RegisterSimulateServiceHandlerClient registers the http handlers for service SimulateService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SimulateServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SimulateServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "SimulateServiceClient" to call the correct interceptors. -func RegisterSimulateServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client SimulateServiceClient) error { - - mux.Handle("POST", pattern_SimulateService_Simulate_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_SimulateService_Simulate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_SimulateService_Simulate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_SimulateService_Simulate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 2}, []string{"cosmos", "base", "simulate", "v1beta1"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_SimulateService_Simulate_0 = runtime.ForwardResponseMessage -) diff --git a/client/tx/tx.go b/client/tx/tx.go index 43f2235b1b9b..e55a28ed0b5c 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - sim "github.com/cosmos/cosmos-sdk/client/grpc/simulate" "github.com/cosmos/cosmos-sdk/client/input" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -279,7 +278,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { return nil, fmt.Errorf("cannot simulate amino tx") } - simReq := sim.SimulateRequest{Tx: protoTx} + simReq := tx.SimulateRequest{Tx: protoTx} return simReq.Marshal() } @@ -288,21 +287,21 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { // simulation response obtained by the query and the adjusted gas amount. func CalculateGas( queryFunc func(string, []byte) ([]byte, int64, error), txf Factory, msgs ...sdk.Msg, -) (sim.SimulateResponse, uint64, error) { +) (tx.SimulateResponse, uint64, error) { txBytes, err := BuildSimTx(txf, msgs...) if err != nil { - return sim.SimulateResponse{}, 0, err + return tx.SimulateResponse{}, 0, err } - bz, _, err := queryFunc("/cosmos.base.simulate.v1beta1.SimulateService/Simulate", txBytes) + bz, _, err := queryFunc("/cosmos.base.tx.v1beta1.SimulateService/Simulate", txBytes) if err != nil { - return sim.SimulateResponse{}, 0, err + return tx.SimulateResponse{}, 0, err } - var simRes sim.SimulateResponse + var simRes tx.SimulateResponse if err := simRes.Unmarshal(bz); err != nil { - return sim.SimulateResponse{}, 0, err + return tx.SimulateResponse{}, 0, err } return simRes, uint64(txf.GasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index da4db5fc8bff..3325e738d553 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -7,12 +7,12 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/grpc/simulate" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/signing" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -28,7 +28,7 @@ func TestCalculateGas(t *testing.T) { if wantErr { return nil, 0, errors.New("query failed") } - simRes := &simulate.SimulateResponse{ + simRes := &txtypes.SimulateResponse{ GasInfo: &sdk.GasInfo{GasUsed: gasUsed, GasWanted: gasUsed}, Result: &sdk.Result{Data: []byte("tx data"), Log: "log"}, } diff --git a/proto/cosmos/base/simulate/v1beta1/simulate.proto b/proto/cosmos/base/simulate/v1beta1/simulate.proto deleted file mode 100644 index e7e678d99cdb..000000000000 --- a/proto/cosmos/base/simulate/v1beta1/simulate.proto +++ /dev/null @@ -1,33 +0,0 @@ -syntax = "proto3"; -package cosmos.base.simulate.v1beta1; - -import "google/api/annotations.proto"; -import "cosmos/base/abci/v1beta1/abci.proto"; -import "cosmos/tx/v1beta1/tx.proto"; - -option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/simulate"; - -// SimulateService defines a gRPC service for simulating transactions. -// It may also support querying and broadcasting in the future. -service SimulateService { - // Simulate simulates executing a transaction for estimating gas usage. - rpc Simulate(SimulateRequest) returns (SimulateResponse) { - option (google.api.http).post = "/cosmos/base/simulate/v1beta1/simulate"; - } -} - -// SimulateRequest is the request type for the SimulateServiceService.Simulate -// RPC method. -message SimulateRequest { - // tx is the transaction to simulate. - cosmos.tx.v1beta1.Tx tx = 1; -} - -// SimulateResponse is the response type for the -// SimulateServiceService.SimulateRPC method. -message SimulateResponse { - // gas_info is the information about gas used in the simulation. - cosmos.base.abci.v1beta1.GasInfo gas_info = 1; - // result is the result of the simulation. - cosmos.base.abci.v1beta1.Result result = 2; -} diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto new file mode 100644 index 000000000000..341d083fc4e1 --- /dev/null +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; +package cosmos.tx.v1beta1; + +import "google/api/annotations.proto"; +import "cosmos/base/abci/v1beta1/abci.proto"; +import "cosmos/tx/v1beta1/tx.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/types/tx"; + +// Service defines a gRPC service for simulating transactions. +service Service { + // Simulate simulates executing a transaction for estimating gas usage. + rpc Simulate(SimulateRequest) returns (SimulateResponse) { + option (google.api.http).post = "/cosmos/tx/v1beta1/simulate"; + } + // Simulate simulates executing a transaction for estimating gas usage. + rpc TxByHash(TxByHashRequest) returns (TxByHashResponse) { + option (google.api.http).get = "/cosmos/tx/v1beta1/txByHash"; + } +} + +// SimulateRequest is the request type for the Service.Simulate +// RPC method. +message SimulateRequest { + // tx is the transaction to simulate. + cosmos.tx.v1beta1.Tx tx = 1; +} + +// SimulateResponse is the response type for the +// Service.SimulateRPC method. +message SimulateResponse { + // gas_info is the information about gas used in the simulation. + cosmos.base.abci.v1beta1.GasInfo gas_info = 1; + // result is the result of the simulation. + cosmos.base.abci.v1beta1.Result result = 2; +} + +// TxByHash is the request type for the Service.TxByHash +// RPC method. +message TxByHashRequest { + // hash is the tx hash to query. + bytes hash = 1; +} + +// TxByHashResponse is the response type for the Service.TxByHash method. +message TxByHashResponse { + // tx is the queried transaction. + cosmos.tx.v1beta1.Tx tx = 1; +} diff --git a/client/grpc/simulate/simulate.go b/types/tx/service.go similarity index 60% rename from client/grpc/simulate/simulate.go rename to types/tx/service.go index 9eed3e30a167..8de537fd19ea 100644 --- a/client/grpc/simulate/simulate.go +++ b/types/tx/service.go @@ -1,4 +1,4 @@ -package simulate +package tx import ( "context" @@ -13,23 +13,23 @@ import ( // BaseAppSimulateFn is the signature of the Baseapp#Simulate function. type BaseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) -type simulateServer struct { +type txServer struct { simulate BaseAppSimulateFn interfaceRegistry codectypes.InterfaceRegistry } -// NewSimulateServer creates a new SimulateServer. -func NewSimulateServer(simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) SimulateServiceServer { - return simulateServer{ +// NewTxServer creates a new TxService server. +func NewTxServer(simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer { + return txServer{ simulate: simulate, interfaceRegistry: interfaceRegistry, } } -var _ SimulateServiceServer = simulateServer{} +var _ ServiceServer = txServer{} -// Simulate implements the SimulateService.Simulate RPC method. -func (s simulateServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) { +// Simulate implements the ServiceServer.Simulate RPC method. +func (s txServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) { if req.Tx == nil { return nil, status.Error(codes.InvalidArgument, "invalid empty tx") } @@ -53,3 +53,9 @@ func (s simulateServer) Simulate(ctx context.Context, req *SimulateRequest) (*Si Result: result, }, nil } + +// TxByHash implements the ServiceServer.TxByHash RPC method. +func (s txServer) TxByHash(ctx context.Context, req *TxByHashRequest) (*TxByHashResponse, error) { + // TODO + return nil, nil +} diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go new file mode 100644 index 000000000000..95fc3bb1d37a --- /dev/null +++ b/types/tx/service.pb.go @@ -0,0 +1,1079 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/tx/v1beta1/service.proto + +package tx + +import ( + context "context" + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/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" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// SimulateRequest is the request type for the Service.Simulate +// RPC method. +type SimulateRequest struct { + // tx is the transaction to tx. + Tx *Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` +} + +func (m *SimulateRequest) Reset() { *m = SimulateRequest{} } +func (m *SimulateRequest) String() string { return proto.CompactTextString(m) } +func (*SimulateRequest) ProtoMessage() {} +func (*SimulateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_e0b00a618705eca7, []int{0} +} +func (m *SimulateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SimulateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SimulateRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SimulateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SimulateRequest.Merge(m, src) +} +func (m *SimulateRequest) XXX_Size() int { + return m.Size() +} +func (m *SimulateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SimulateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SimulateRequest proto.InternalMessageInfo + +func (m *SimulateRequest) GetTx() *Tx { + if m != nil { + return m.Tx + } + return nil +} + +// SimulateResponse is the response type for the +// Service.SimulateRPC method. +type SimulateResponse struct { + // gas_info is the information about gas used in the simulation. + GasInfo *types.GasInfo `protobuf:"bytes,1,opt,name=gas_info,json=gasInfo,proto3" json:"gas_info,omitempty"` + // result is the result of the simulation. + Result *types.Result `protobuf:"bytes,2,opt,name=result,proto3" json:"result,omitempty"` +} + +func (m *SimulateResponse) Reset() { *m = SimulateResponse{} } +func (m *SimulateResponse) String() string { return proto.CompactTextString(m) } +func (*SimulateResponse) ProtoMessage() {} +func (*SimulateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e0b00a618705eca7, []int{1} +} +func (m *SimulateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SimulateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SimulateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SimulateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SimulateResponse.Merge(m, src) +} +func (m *SimulateResponse) XXX_Size() int { + return m.Size() +} +func (m *SimulateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SimulateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SimulateResponse proto.InternalMessageInfo + +func (m *SimulateResponse) GetGasInfo() *types.GasInfo { + if m != nil { + return m.GasInfo + } + return nil +} + +func (m *SimulateResponse) GetResult() *types.Result { + if m != nil { + return m.Result + } + return nil +} + +// TxByHash is the request type for the Service.TxByHash +// RPC method. +type TxByHashRequest struct { + // hash is the tx hash to query. + Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (m *TxByHashRequest) Reset() { *m = TxByHashRequest{} } +func (m *TxByHashRequest) String() string { return proto.CompactTextString(m) } +func (*TxByHashRequest) ProtoMessage() {} +func (*TxByHashRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_e0b00a618705eca7, []int{2} +} +func (m *TxByHashRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxByHashRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TxByHashRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxByHashRequest.Merge(m, src) +} +func (m *TxByHashRequest) XXX_Size() int { + return m.Size() +} +func (m *TxByHashRequest) XXX_DiscardUnknown() { + xxx_messageInfo_TxByHashRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_TxByHashRequest proto.InternalMessageInfo + +func (m *TxByHashRequest) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +// TxByHashResponse is the response type for the Service.TxByHash method. +type TxByHashResponse struct { + // tx is the queried transaction. + Tx *Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` +} + +func (m *TxByHashResponse) Reset() { *m = TxByHashResponse{} } +func (m *TxByHashResponse) String() string { return proto.CompactTextString(m) } +func (*TxByHashResponse) ProtoMessage() {} +func (*TxByHashResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e0b00a618705eca7, []int{3} +} +func (m *TxByHashResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxByHashResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TxByHashResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxByHashResponse.Merge(m, src) +} +func (m *TxByHashResponse) XXX_Size() int { + return m.Size() +} +func (m *TxByHashResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TxByHashResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_TxByHashResponse proto.InternalMessageInfo + +func (m *TxByHashResponse) GetTx() *Tx { + if m != nil { + return m.Tx + } + return nil +} + +func init() { + proto.RegisterType((*SimulateRequest)(nil), "cosmos.tx.v1beta1.SimulateRequest") + proto.RegisterType((*SimulateResponse)(nil), "cosmos.tx.v1beta1.SimulateResponse") + proto.RegisterType((*TxByHashRequest)(nil), "cosmos.tx.v1beta1.TxByHashRequest") + proto.RegisterType((*TxByHashResponse)(nil), "cosmos.tx.v1beta1.TxByHashResponse") +} + +func init() { proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescriptor_e0b00a618705eca7) } + +var fileDescriptor_e0b00a618705eca7 = []byte{ + // 393 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x4b, 0xe3, 0x40, + 0x14, 0xc7, 0x9b, 0xb0, 0xb4, 0x65, 0x76, 0xa1, 0xdd, 0x81, 0x85, 0x92, 0xdd, 0xcd, 0x76, 0x53, + 0x0a, 0x5e, 0xcc, 0xd0, 0x7a, 0xa9, 0x20, 0x08, 0xbd, 0xa8, 0xd7, 0xb4, 0x27, 0x2f, 0x32, 0x89, + 0xd3, 0x24, 0xd8, 0x66, 0x62, 0xe7, 0xa5, 0x4c, 0xaf, 0x1e, 0x3d, 0x09, 0xfe, 0x53, 0x1e, 0x0b, + 0x5e, 0x3c, 0x4a, 0xeb, 0xbf, 0x21, 0x48, 0x93, 0x8c, 0x85, 0x36, 0x8a, 0xa7, 0x4c, 0xc8, 0xe7, + 0xfb, 0xe3, 0xbd, 0x0c, 0xfa, 0xe7, 0x71, 0x31, 0xe1, 0x82, 0x80, 0x24, 0xb3, 0x8e, 0xcb, 0x80, + 0x76, 0x88, 0x60, 0xd3, 0x59, 0xe8, 0x31, 0x3b, 0x9e, 0x72, 0xe0, 0xf8, 0x67, 0x06, 0xd8, 0x20, + 0xed, 0x1c, 0x30, 0xfe, 0xf8, 0x9c, 0xfb, 0x63, 0x46, 0x68, 0x1c, 0x12, 0x1a, 0x45, 0x1c, 0x28, + 0x84, 0x3c, 0x12, 0x99, 0xc0, 0x68, 0xe5, 0x8e, 0x2e, 0x15, 0x8c, 0x50, 0xd7, 0x0b, 0xdf, 0x8d, + 0xd7, 0x2f, 0x39, 0x64, 0xec, 0xc6, 0x82, 0xcc, 0xbe, 0x59, 0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+ 0x16, 0x4b, 0x53, 0x7b, 0x5e, 0x9a, 0xda, 0xdd, 0xca, 0x2c, 0x2d, 0x56, 0x66, 0xe9, 0x69, 0x65, + 0x96, 0xce, 0xdb, 0x7e, 0x08, 0x41, 0xe2, 0xda, 0x1e, 0x9f, 0x28, 0x83, 0xec, 0xb1, 0x2f, 0x2e, + 0xaf, 0x08, 0xcc, 0x63, 0xb6, 0x76, 0x74, 0xcb, 0xe9, 0x85, 0x3b, 0x78, 0x0b, 0x00, 0x00, 0xff, + 0xff, 0x84, 0x84, 0xcd, 0xc1, 0x05, 0x03, 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 + +// ServiceClient is the client API for Service service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ServiceClient interface { + // Simulate simulates executing a transaction for estimating gas usage. + Simulate(ctx context.Context, in *SimulateRequest, opts ...grpc.CallOption) (*SimulateResponse, error) + // Simulate simulates executing a transaction for estimating gas usage. + TxByHash(ctx context.Context, in *TxByHashRequest, opts ...grpc.CallOption) (*TxByHashResponse, error) +} + +type serviceClient struct { + cc grpc1.ClientConn +} + +func NewServiceClient(cc grpc1.ClientConn) ServiceClient { + return &serviceClient{cc} +} + +func (c *serviceClient) Simulate(ctx context.Context, in *SimulateRequest, opts ...grpc.CallOption) (*SimulateResponse, error) { + out := new(SimulateResponse) + err := c.cc.Invoke(ctx, "/cosmos.tx.v1beta1.Service/Simulate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serviceClient) TxByHash(ctx context.Context, in *TxByHashRequest, opts ...grpc.CallOption) (*TxByHashResponse, error) { + out := new(TxByHashResponse) + err := c.cc.Invoke(ctx, "/cosmos.tx.v1beta1.Service/TxByHash", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServiceServer is the server API for Service service. +type ServiceServer interface { + // Simulate simulates executing a transaction for estimating gas usage. + Simulate(context.Context, *SimulateRequest) (*SimulateResponse, error) + // Simulate simulates executing a transaction for estimating gas usage. + TxByHash(context.Context, *TxByHashRequest) (*TxByHashResponse, error) +} + +// UnimplementedServiceServer can be embedded to have forward compatible implementations. +type UnimplementedServiceServer struct { +} + +func (*UnimplementedServiceServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Simulate not implemented") +} +func (*UnimplementedServiceServer) TxByHash(ctx context.Context, req *TxByHashRequest) (*TxByHashResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TxByHash not implemented") +} + +func RegisterServiceServer(s grpc1.Server, srv ServiceServer) { + s.RegisterService(&_Service_serviceDesc, srv) +} + +func _Service_Simulate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SimulateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).Simulate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.tx.v1beta1.Service/Simulate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).Simulate(ctx, req.(*SimulateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Service_TxByHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TxByHashRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).TxByHash(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.tx.v1beta1.Service/TxByHash", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).TxByHash(ctx, req.(*TxByHashRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Service_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.tx.v1beta1.Service", + HandlerType: (*ServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Simulate", + Handler: _Service_Simulate_Handler, + }, + { + MethodName: "TxByHash", + Handler: _Service_TxByHash_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/tx/v1beta1/service.proto", +} + +func (m *SimulateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SimulateRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SimulateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Tx != nil { + { + size, err := m.Tx.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SimulateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SimulateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SimulateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != nil { + { + size, err := m.Result.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.GasInfo != nil { + { + size, err := m.GasInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *TxByHashRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TxByHashRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TxByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintService(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *TxByHashResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TxByHashResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TxByHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Tx != nil { + { + size, err := m.Tx.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintService(dAtA []byte, offset int, v uint64) int { + offset -= sovService(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SimulateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Tx != nil { + l = m.Tx.Size() + n += 1 + l + sovService(uint64(l)) + } + return n +} + +func (m *SimulateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.GasInfo != nil { + l = m.GasInfo.Size() + n += 1 + l + sovService(uint64(l)) + } + if m.Result != nil { + l = m.Result.Size() + n += 1 + l + sovService(uint64(l)) + } + return n +} + +func (m *TxByHashRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovService(uint64(l)) + } + return n +} + +func (m *TxByHashResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Tx != nil { + l = m.Tx.Size() + n += 1 + l + sovService(uint64(l)) + } + return n +} + +func sovService(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozService(x uint64) (n int) { + return sovService(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *SimulateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SimulateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SimulateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tx", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Tx == nil { + m.Tx = &Tx{} + } + if err := m.Tx.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipService(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SimulateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SimulateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SimulateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GasInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.GasInfo == nil { + m.GasInfo = &types.GasInfo{} + } + if err := m.GasInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Result == nil { + m.Result = &types.Result{} + } + if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipService(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TxByHashRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TxByHashRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TxByHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipService(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TxByHashResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TxByHashResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TxByHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tx", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Tx == nil { + m.Tx = &Tx{} + } + if err := m.Tx.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipService(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipService(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowService + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowService + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowService + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthService + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupService + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthService + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthService = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowService = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupService = fmt.Errorf("proto: unexpected end of group") +) diff --git a/types/tx/service.pb.gw.go b/types/tx/service.pb.gw.go new file mode 100644 index 000000000000..f2e8a058e1ac --- /dev/null +++ b/types/tx/service.pb.gw.go @@ -0,0 +1,246 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: cosmos/tx/v1beta1/service.proto + +/* +Package tx is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package tx + +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/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 ( + filter_Service_Simulate_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SimulateRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_Simulate_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Simulate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Service_Simulate_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq SimulateRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_Simulate_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Simulate(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Service_TxByHash_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Service_TxByHash_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq TxByHashRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_TxByHash_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.TxByHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Service_TxByHash_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq TxByHashRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_TxByHash_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.TxByHash(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterServiceHandlerServer registers the http handlers for service Service to "mux". +// UnaryRPC :call ServiceServer 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 (such as grpc.SendHeader, etc) to stop working. Consider using RegisterServiceHandlerFromEndpoint instead. +func RegisterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ServiceServer) error { + + mux.Handle("POST", pattern_Service_Simulate_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.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Service_Simulate_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_Simulate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Service_TxByHash_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.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Service_TxByHash_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_TxByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterServiceHandlerFromEndpoint is same as RegisterServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterServiceHandlerFromEndpoint(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 RegisterServiceHandler(ctx, mux, conn) +} + +// RegisterServiceHandler registers the http handlers for service Service to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterServiceHandlerClient(ctx, mux, NewServiceClient(conn)) +} + +// RegisterServiceHandlerClient registers the http handlers for service Service +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "ServiceClient" to call the correct interceptors. +func RegisterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ServiceClient) error { + + mux.Handle("POST", pattern_Service_Simulate_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_Service_Simulate_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_Simulate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Service_TxByHash_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_Service_TxByHash_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Service_TxByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Service_Simulate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "simulate"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Service_TxByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "txByHash"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Service_Simulate_0 = runtime.ForwardResponseMessage + + forward_Service_TxByHash_0 = runtime.ForwardResponseMessage +) diff --git a/client/grpc/simulate/simulate_test.go b/types/tx/service_test.go similarity index 86% rename from client/grpc/simulate/simulate_test.go rename to types/tx/service_test.go index 11b58168a923..1b2d74b6c155 100644 --- a/client/grpc/simulate/simulate_test.go +++ b/types/tx/service_test.go @@ -1,4 +1,4 @@ -package simulate_test +package tx_test import ( "context" @@ -9,13 +9,12 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/grpc/simulate" - "github.com/cosmos/cosmos-sdk/client/tx" + clienttx "github.com/cosmos/cosmos-sdk/client/tx" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - txtypes "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -27,7 +26,7 @@ type IntegrationTestSuite struct { app *simapp.SimApp clientCtx client.Context - queryClient simulate.SimulateServiceClient + queryClient tx.ServiceClient sdkCtx sdk.Context } @@ -43,11 +42,11 @@ func (s *IntegrationTestSuite) SetupSuite() { clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig) // Create new simulation server. - srv := simulate.NewSimulateServer(app.BaseApp.Simulate, encodingConfig.InterfaceRegistry) + srv := tx.NewTxServer(app.BaseApp.Simulate, encodingConfig.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry()) - simulate.RegisterSimulateServiceServer(queryHelper, srv) - queryClient := simulate.NewSimulateServiceClient(queryHelper) + tx.RegisterServiceServer(queryHelper, srv) + queryClient := tx.NewServiceClient(queryHelper) s.app = app s.clientCtx = clientCtx @@ -91,7 +90,7 @@ func (s IntegrationTestSuite) TestSimulateService() { } txBuilder.SetSignatures(sigV2) // 2nd round: actually sign - sigV2, err = tx.SignWithPrivKey( + sigV2, err = clienttx.SignWithPrivKey( s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), authsigning.SignerData{ChainID: s.sdkCtx.ChainID(), AccountNumber: accNum, Sequence: accSeq}, txBuilder, priv1, s.clientCtx.TxConfig, accSeq, @@ -101,11 +100,11 @@ func (s IntegrationTestSuite) TestSimulateService() { any, ok := txBuilder.(codectypes.IntoAny) s.Require().True(ok) cached := any.AsAny().GetCachedValue() - txTx, ok := cached.(*txtypes.Tx) + txTx, ok := cached.(*tx.Tx) s.Require().True(ok) res, err := s.queryClient.Simulate( context.Background(), - &simulate.SimulateRequest{Tx: txTx}, + &tx.SimulateRequest{Tx: txTx}, ) s.Require().NoError(err) diff --git a/x/simulation/operation.go b/x/simulation/operation.go index 914daafc8b91..f46d6c0eb86c 100644 --- a/x/simulation/operation.go +++ b/x/simulation/operation.go @@ -132,7 +132,7 @@ func NewWeightedOperation(weight int, op simulation.Operation) WeightedOperation } } -// WeightedOperations is the group of all weighted operations to simulate. +// WeightedOperations is the group of all weighted operations to tx. type WeightedOperations []simulation.WeightedOperation func (ops WeightedOperations) totalWeight() int { From f23fbb4157176ed12c52c287a1a5ed9b8eab3638 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 13:42:11 +0100 Subject: [PATCH 02/20] Fix search & replace --- client/tx/tx.go | 2 +- x/simulation/operation.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index e55a28ed0b5c..892bbba40ee6 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -293,7 +293,7 @@ func CalculateGas( return tx.SimulateResponse{}, 0, err } - bz, _, err := queryFunc("/cosmos.base.tx.v1beta1.SimulateService/Simulate", txBytes) + bz, _, err := queryFunc("/cosmos.tx.v1beta1.Service/Simulate", txBytes) if err != nil { return tx.SimulateResponse{}, 0, err } diff --git a/x/simulation/operation.go b/x/simulation/operation.go index f46d6c0eb86c..914daafc8b91 100644 --- a/x/simulation/operation.go +++ b/x/simulation/operation.go @@ -132,7 +132,7 @@ func NewWeightedOperation(weight int, op simulation.Operation) WeightedOperation } } -// WeightedOperations is the group of all weighted operations to tx. +// WeightedOperations is the group of all weighted operations to simulate. type WeightedOperations []simulation.WeightedOperation func (ops WeightedOperations) totalWeight() int { From 7eba495409a7c103d6f32df0e25305321f7841e7 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 15:15:54 +0100 Subject: [PATCH 03/20] Renname to GetTx --- baseapp/grpcrouter.go | 8 +- proto/cosmos/tx/v1beta1/service.proto | 12 +- simapp/app.go | 2 +- types/tx/service.go | 19 ++- types/tx/service.pb.go | 178 +++++++++++++------------- types/tx/service.pb.gw.go | 34 ++--- types/tx/service_test.go | 2 +- 7 files changed, 134 insertions(+), 121 deletions(-) diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go index 4c0c7e97e572..3492567e4902 100644 --- a/baseapp/grpcrouter.go +++ b/baseapp/grpcrouter.go @@ -5,6 +5,7 @@ import ( gogogrpc "github.com/gogo/protobuf/grpc" abci "github.com/tendermint/tendermint/abci/types" + rpcclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc" "google.golang.org/grpc/encoding" "google.golang.org/grpc/encoding/proto" @@ -111,13 +112,14 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In ) } -// RegisterSimulateService registers the simulate service on the gRPC router. -func (qrt *GRPCQueryRouter) RegisterSimulateService( +// RegisterTxService registers the tx service on the gRPC router. +func (qrt *GRPCQueryRouter) RegisterTxService( + rpcClient rpcclient.Client, simulateFn tx.BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry, ) { tx.RegisterServiceServer( qrt, - tx.NewTxServer(simulateFn, interfaceRegistry), + tx.NewTxServer(rpcClient, simulateFn, interfaceRegistry), ) } diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 341d083fc4e1..4d4d3ad6681f 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -14,8 +14,8 @@ service Service { option (google.api.http).post = "/cosmos/tx/v1beta1/simulate"; } // Simulate simulates executing a transaction for estimating gas usage. - rpc TxByHash(TxByHashRequest) returns (TxByHashResponse) { - option (google.api.http).get = "/cosmos/tx/v1beta1/txByHash"; + rpc GetTx(GetTxRequest) returns (GetTxResponse) { + option (google.api.http).get = "/cosmos/tx/v1beta1/getTx"; } } @@ -35,15 +35,15 @@ message SimulateResponse { cosmos.base.abci.v1beta1.Result result = 2; } -// TxByHash is the request type for the Service.TxByHash +// GetTx is the request type for the Service.GetTx // RPC method. -message TxByHashRequest { +message GetTxRequest { // hash is the tx hash to query. bytes hash = 1; } -// TxByHashResponse is the response type for the Service.TxByHash method. -message TxByHashResponse { +// GetTxResponse is the response type for the Service.GetTx method. +message GetTxResponse { // tx is the queried transaction. cosmos.tx.v1beta1.Tx tx = 1; } diff --git a/simapp/app.go b/simapp/app.go index 41683dff82c3..e1ab98830c39 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -204,7 +204,7 @@ func NewSimApp( bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) - bApp.GRPCQueryRouter().RegisterSimulateService(bApp.Simulate, interfaceRegistry) + bApp.GRPCQueryRouter().RegisterTxService(bApp.Simulate, interfaceRegistry) keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, diff --git a/types/tx/service.go b/types/tx/service.go index 8de537fd19ea..31bf31cb6bda 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -2,7 +2,9 @@ package tx import ( "context" + fmt "fmt" + rpcclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -14,13 +16,15 @@ import ( type BaseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) type txServer struct { + rpcClient rpcclient.Client simulate BaseAppSimulateFn interfaceRegistry codectypes.InterfaceRegistry } // NewTxServer creates a new TxService server. -func NewTxServer(simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer { +func NewTxServer(rpcClient rpcclient.Client, simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer { return txServer{ + rpcClient: rpcClient, simulate: simulate, interfaceRegistry: interfaceRegistry, } @@ -54,8 +58,15 @@ func (s txServer) Simulate(ctx context.Context, req *SimulateRequest) (*Simulate }, nil } -// TxByHash implements the ServiceServer.TxByHash RPC method. -func (s txServer) TxByHash(ctx context.Context, req *TxByHashRequest) (*TxByHashResponse, error) { - // TODO +// GetTx implements the ServiceServer.GetTx RPC method. +func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, error) { + // TODO We should also check the proof flag in gRPC header. + // https://github.com/cosmos/cosmos-sdk/issues/7036. + result, err := s.rpcClient.Tx(ctx, req.Hash, false) + if err != nil { + return nil, err + } + + fmt.Println(result) return nil, nil } diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go index 95fc3bb1d37a..ea845ae09e1e 100644 --- a/types/tx/service.pb.go +++ b/types/tx/service.pb.go @@ -32,7 +32,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // SimulateRequest is the request type for the Service.Simulate // RPC method. type SimulateRequest struct { - // tx is the transaction to tx. + // tx is the transaction to simulate. Tx *Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` } @@ -132,25 +132,25 @@ func (m *SimulateResponse) GetResult() *types.Result { return nil } -// TxByHash is the request type for the Service.TxByHash +// GetTx is the request type for the Service.GetTx // RPC method. -type TxByHashRequest struct { +type GetTxRequest struct { // hash is the tx hash to query. Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` } -func (m *TxByHashRequest) Reset() { *m = TxByHashRequest{} } -func (m *TxByHashRequest) String() string { return proto.CompactTextString(m) } -func (*TxByHashRequest) ProtoMessage() {} -func (*TxByHashRequest) Descriptor() ([]byte, []int) { +func (m *GetTxRequest) Reset() { *m = GetTxRequest{} } +func (m *GetTxRequest) String() string { return proto.CompactTextString(m) } +func (*GetTxRequest) ProtoMessage() {} +func (*GetTxRequest) Descriptor() ([]byte, []int) { return fileDescriptor_e0b00a618705eca7, []int{2} } -func (m *TxByHashRequest) XXX_Unmarshal(b []byte) error { +func (m *GetTxRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *TxByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *GetTxRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_TxByHashRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_GetTxRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -160,43 +160,43 @@ func (m *TxByHashRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, err return b[:n], nil } } -func (m *TxByHashRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_TxByHashRequest.Merge(m, src) +func (m *GetTxRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetTxRequest.Merge(m, src) } -func (m *TxByHashRequest) XXX_Size() int { +func (m *GetTxRequest) XXX_Size() int { return m.Size() } -func (m *TxByHashRequest) XXX_DiscardUnknown() { - xxx_messageInfo_TxByHashRequest.DiscardUnknown(m) +func (m *GetTxRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetTxRequest.DiscardUnknown(m) } -var xxx_messageInfo_TxByHashRequest proto.InternalMessageInfo +var xxx_messageInfo_GetTxRequest proto.InternalMessageInfo -func (m *TxByHashRequest) GetHash() []byte { +func (m *GetTxRequest) GetHash() []byte { if m != nil { return m.Hash } return nil } -// TxByHashResponse is the response type for the Service.TxByHash method. -type TxByHashResponse struct { +// GetTxResponse is the response type for the Service.GetTx method. +type GetTxResponse struct { // tx is the queried transaction. Tx *Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` } -func (m *TxByHashResponse) Reset() { *m = TxByHashResponse{} } -func (m *TxByHashResponse) String() string { return proto.CompactTextString(m) } -func (*TxByHashResponse) ProtoMessage() {} -func (*TxByHashResponse) Descriptor() ([]byte, []int) { +func (m *GetTxResponse) Reset() { *m = GetTxResponse{} } +func (m *GetTxResponse) String() string { return proto.CompactTextString(m) } +func (*GetTxResponse) ProtoMessage() {} +func (*GetTxResponse) Descriptor() ([]byte, []int) { return fileDescriptor_e0b00a618705eca7, []int{3} } -func (m *TxByHashResponse) XXX_Unmarshal(b []byte) error { +func (m *GetTxResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *TxByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *GetTxResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_TxByHashResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_GetTxResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -206,19 +206,19 @@ func (m *TxByHashResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } -func (m *TxByHashResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_TxByHashResponse.Merge(m, src) +func (m *GetTxResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetTxResponse.Merge(m, src) } -func (m *TxByHashResponse) XXX_Size() int { +func (m *GetTxResponse) XXX_Size() int { return m.Size() } -func (m *TxByHashResponse) XXX_DiscardUnknown() { - xxx_messageInfo_TxByHashResponse.DiscardUnknown(m) +func (m *GetTxResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetTxResponse.DiscardUnknown(m) } -var xxx_messageInfo_TxByHashResponse proto.InternalMessageInfo +var xxx_messageInfo_GetTxResponse proto.InternalMessageInfo -func (m *TxByHashResponse) GetTx() *Tx { +func (m *GetTxResponse) GetTx() *Tx { if m != nil { return m.Tx } @@ -228,39 +228,39 @@ func (m *TxByHashResponse) GetTx() *Tx { func init() { proto.RegisterType((*SimulateRequest)(nil), "cosmos.tx.v1beta1.SimulateRequest") proto.RegisterType((*SimulateResponse)(nil), "cosmos.tx.v1beta1.SimulateResponse") - proto.RegisterType((*TxByHashRequest)(nil), "cosmos.tx.v1beta1.TxByHashRequest") - proto.RegisterType((*TxByHashResponse)(nil), "cosmos.tx.v1beta1.TxByHashResponse") + proto.RegisterType((*GetTxRequest)(nil), "cosmos.tx.v1beta1.GetTxRequest") + proto.RegisterType((*GetTxResponse)(nil), "cosmos.tx.v1beta1.GetTxResponse") } func init() { proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescriptor_e0b00a618705eca7) } var fileDescriptor_e0b00a618705eca7 = []byte{ - // 393 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x4b, 0xe3, 0x40, - 0x14, 0xc7, 0x9b, 0xb0, 0xb4, 0x65, 0x76, 0xa1, 0xdd, 0x81, 0x85, 0x92, 0xdd, 0xcd, 0x76, 0x53, - 0x0a, 0x5e, 0xcc, 0xd0, 0x7a, 0xa9, 0x20, 0x08, 0xbd, 0xa8, 0xd7, 0xb4, 0x27, 0x2f, 0x32, 0x89, - 0xd3, 0x24, 0xd8, 0x66, 0x62, 0xe7, 0xa5, 0x4c, 0xaf, 0x1e, 0x3d, 0x09, 0xfe, 0x53, 0x1e, 0x0b, - 0x5e, 0x3c, 0x4a, 0xeb, 0xbf, 0x21, 0x48, 0x93, 0x8c, 0x85, 0x36, 0x8a, 0xa7, 0x4c, 0xc8, 0xe7, - 0xfb, 0xe3, 0xbd, 0x0c, 0xfa, 0xe7, 0x71, 0x31, 0xe1, 0x82, 0x80, 0x24, 0xb3, 0x8e, 0xcb, 0x80, - 0x76, 0x88, 0x60, 0xd3, 0x59, 0xe8, 0x31, 0x3b, 0x9e, 0x72, 0xe0, 0xf8, 0x67, 0x06, 0xd8, 0x20, - 0xed, 0x1c, 0x30, 0xfe, 0xf8, 0x9c, 0xfb, 0x63, 0x46, 0x68, 0x1c, 0x12, 0x1a, 0x45, 0x1c, 0x28, - 0x84, 0x3c, 0x12, 0x99, 0xc0, 0x68, 0xe5, 0x8e, 0x2e, 0x15, 0x8c, 0x50, 0xd7, 0x0b, 0xdf, 0x8d, - 0xd7, 0x2f, 0x39, 0x64, 0xec, 0xc6, 0x82, 0xcc, 0xbe, 0x59, 0x3d, 0x54, 0x1b, 0x84, 0x93, 0x64, - 0x4c, 0x81, 0x39, 0xec, 0x3a, 0x61, 0x02, 0x70, 0x1b, 0xe9, 0x20, 0x1b, 0x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, 0xdb, 0x7e, 0x08, 0x41, 0xe2, 0xda, 0x1e, 0x9f, 0x28, 0x83, 0xec, 0xb1, 0x2f, 0x2e, - 0xaf, 0x08, 0xcc, 0x63, 0xb6, 0x76, 0x74, 0xcb, 0xe9, 0x85, 0x3b, 0x78, 0x0b, 0x00, 0x00, 0xff, - 0xff, 0x84, 0x84, 0xcd, 0xc1, 0x05, 0x03, 0x00, 0x00, + // 398 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6a, 0xdb, 0x30, + 0x1c, 0xc7, 0x63, 0xb3, 0x25, 0x41, 0xcb, 0xd8, 0x26, 0x18, 0x04, 0x6f, 0x73, 0x3c, 0x85, 0xc0, + 0x2e, 0xb3, 0x48, 0x06, 0x23, 0x87, 0xc1, 0xa0, 0x97, 0xd0, 0xab, 0x93, 0x53, 0x2f, 0x45, 0x76, + 0x15, 0xc7, 0xd4, 0xb1, 0xdc, 0x48, 0x0e, 0xea, 0xb5, 0xc7, 0x9e, 0x0a, 0x7d, 0xa9, 0x1e, 0x03, + 0xbd, 0xf4, 0x58, 0x92, 0xbe, 0x40, 0xdf, 0xa0, 0x58, 0x96, 0xdb, 0xd2, 0x38, 0xa5, 0x27, 0xcb, + 0xf8, 0xf3, 0xfd, 0xf3, 0xb3, 0x7e, 0xa0, 0x13, 0x30, 0x3e, 0x67, 0x1c, 0x0b, 0x89, 0x97, 0x7d, + 0x9f, 0x0a, 0xd2, 0xc7, 0x9c, 0x2e, 0x96, 0x51, 0x40, 0xdd, 0x74, 0xc1, 0x04, 0x83, 0x5f, 0x0a, + 0xc0, 0x15, 0xd2, 0xd5, 0x80, 0xf5, 0x3d, 0x64, 0x2c, 0x8c, 0x29, 0x26, 0x69, 0x84, 0x49, 0x92, + 0x30, 0x41, 0x44, 0xc4, 0x12, 0x5e, 0x08, 0xac, 0xae, 0x76, 0xf4, 0x09, 0xa7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, 0x1b, 0xd0, 0x81, 0x8e, 0x0a, 0xb4, 0x60, 0xbb, 0x22, 0x30, 0xcc, 0xc9, 0xbd, + 0xff, 0x57, 0x6b, 0xdb, 0x58, 0xad, 0x6d, 0xe3, 0x76, 0x6d, 0x1b, 0x17, 0x1b, 0xbb, 0xb6, 0xda, + 0xd8, 0xb5, 0x9b, 0x8d, 0x5d, 0x3b, 0xe8, 0x85, 0x91, 0x98, 0x65, 0xbe, 0x1b, 0xb0, 0x79, 0xa9, + 0x2e, 0x1e, 0xbf, 0xf9, 0xd1, 0x31, 0x16, 0xa7, 0x29, 0xcd, 0xed, 0xfc, 0xba, 0x5a, 0xaf, 0x3f, + 0x0f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xfd, 0xe9, 0xb9, 0xf3, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -278,7 +278,7 @@ type ServiceClient interface { // Simulate simulates executing a transaction for estimating gas usage. Simulate(ctx context.Context, in *SimulateRequest, opts ...grpc.CallOption) (*SimulateResponse, error) // Simulate simulates executing a transaction for estimating gas usage. - TxByHash(ctx context.Context, in *TxByHashRequest, opts ...grpc.CallOption) (*TxByHashResponse, error) + GetTx(ctx context.Context, in *GetTxRequest, opts ...grpc.CallOption) (*GetTxResponse, error) } type serviceClient struct { @@ -298,9 +298,9 @@ func (c *serviceClient) Simulate(ctx context.Context, in *SimulateRequest, opts return out, nil } -func (c *serviceClient) TxByHash(ctx context.Context, in *TxByHashRequest, opts ...grpc.CallOption) (*TxByHashResponse, error) { - out := new(TxByHashResponse) - err := c.cc.Invoke(ctx, "/cosmos.tx.v1beta1.Service/TxByHash", in, out, opts...) +func (c *serviceClient) GetTx(ctx context.Context, in *GetTxRequest, opts ...grpc.CallOption) (*GetTxResponse, error) { + out := new(GetTxResponse) + err := c.cc.Invoke(ctx, "/cosmos.tx.v1beta1.Service/GetTx", in, out, opts...) if err != nil { return nil, err } @@ -312,7 +312,7 @@ type ServiceServer interface { // Simulate simulates executing a transaction for estimating gas usage. Simulate(context.Context, *SimulateRequest) (*SimulateResponse, error) // Simulate simulates executing a transaction for estimating gas usage. - TxByHash(context.Context, *TxByHashRequest) (*TxByHashResponse, error) + GetTx(context.Context, *GetTxRequest) (*GetTxResponse, error) } // UnimplementedServiceServer can be embedded to have forward compatible implementations. @@ -322,8 +322,8 @@ type UnimplementedServiceServer struct { func (*UnimplementedServiceServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Simulate not implemented") } -func (*UnimplementedServiceServer) TxByHash(ctx context.Context, req *TxByHashRequest) (*TxByHashResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method TxByHash not implemented") +func (*UnimplementedServiceServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetTx not implemented") } func RegisterServiceServer(s grpc1.Server, srv ServiceServer) { @@ -348,20 +348,20 @@ func _Service_Simulate_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _Service_TxByHash_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TxByHashRequest) +func _Service_GetTx_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetTxRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(ServiceServer).TxByHash(ctx, in) + return srv.(ServiceServer).GetTx(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cosmos.tx.v1beta1.Service/TxByHash", + FullMethod: "/cosmos.tx.v1beta1.Service/GetTx", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ServiceServer).TxByHash(ctx, req.(*TxByHashRequest)) + return srv.(ServiceServer).GetTx(ctx, req.(*GetTxRequest)) } return interceptor(ctx, in, info, handler) } @@ -375,8 +375,8 @@ var _Service_serviceDesc = grpc.ServiceDesc{ Handler: _Service_Simulate_Handler, }, { - MethodName: "TxByHash", - Handler: _Service_TxByHash_Handler, + MethodName: "GetTx", + Handler: _Service_GetTx_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -465,7 +465,7 @@ func (m *SimulateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *TxByHashRequest) Marshal() (dAtA []byte, err error) { +func (m *GetTxRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -475,12 +475,12 @@ func (m *TxByHashRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *TxByHashRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *GetTxRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *TxByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *GetTxRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -495,7 +495,7 @@ func (m *TxByHashRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *TxByHashResponse) Marshal() (dAtA []byte, err error) { +func (m *GetTxResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -505,12 +505,12 @@ func (m *TxByHashResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *TxByHashResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *GetTxResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *TxByHashResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *GetTxResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -571,7 +571,7 @@ func (m *SimulateResponse) Size() (n int) { return n } -func (m *TxByHashRequest) Size() (n int) { +func (m *GetTxRequest) Size() (n int) { if m == nil { return 0 } @@ -584,7 +584,7 @@ func (m *TxByHashRequest) Size() (n int) { return n } -func (m *TxByHashResponse) Size() (n int) { +func (m *GetTxResponse) Size() (n int) { if m == nil { return 0 } @@ -817,7 +817,7 @@ func (m *SimulateResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *TxByHashRequest) Unmarshal(dAtA []byte) error { +func (m *GetTxRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -840,10 +840,10 @@ func (m *TxByHashRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: TxByHashRequest: wiretype end group for non-group") + return fmt.Errorf("proto: GetTxRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: TxByHashRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GetTxRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -904,7 +904,7 @@ func (m *TxByHashRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *TxByHashResponse) Unmarshal(dAtA []byte) error { +func (m *GetTxResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -927,10 +927,10 @@ func (m *TxByHashResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: TxByHashResponse: wiretype end group for non-group") + return fmt.Errorf("proto: GetTxResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: TxByHashResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GetTxResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/types/tx/service.pb.gw.go b/types/tx/service.pb.gw.go index f2e8a058e1ac..1b33225157f0 100644 --- a/types/tx/service.pb.gw.go +++ b/types/tx/service.pb.gw.go @@ -68,37 +68,37 @@ func local_request_Service_Simulate_0(ctx context.Context, marshaler runtime.Mar } var ( - filter_Service_TxByHash_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_Service_GetTx_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_Service_TxByHash_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TxByHashRequest +func request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetTxRequest var metadata runtime.ServerMetadata if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_TxByHash_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_GetTx_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.TxByHash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetTx(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Service_TxByHash_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TxByHashRequest +func local_request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetTxRequest var metadata runtime.ServerMetadata if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_TxByHash_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_GetTx_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.TxByHash(ctx, &protoReq) + msg, err := server.GetTx(ctx, &protoReq) return msg, metadata, err } @@ -129,7 +129,7 @@ func RegisterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, se }) - mux.Handle("GET", pattern_Service_TxByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Service_GetTx_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) @@ -138,14 +138,14 @@ func RegisterServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, se runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Service_TxByHash_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Service_GetTx_0(rctx, inboundMarshaler, server, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Service_TxByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Service_GetTx_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -210,7 +210,7 @@ func RegisterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl }) - mux.Handle("GET", pattern_Service_TxByHash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Service_GetTx_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) @@ -219,14 +219,14 @@ func RegisterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Service_TxByHash_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Service_GetTx_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Service_TxByHash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Service_GetTx_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -236,11 +236,11 @@ func RegisterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl var ( pattern_Service_Simulate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "simulate"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Service_TxByHash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "txByHash"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Service_GetTx_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "getTx"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( forward_Service_Simulate_0 = runtime.ForwardResponseMessage - forward_Service_TxByHash_0 = runtime.ForwardResponseMessage + forward_Service_GetTx_0 = runtime.ForwardResponseMessage ) diff --git a/types/tx/service_test.go b/types/tx/service_test.go index 1b2d74b6c155..e3c80f2e66d7 100644 --- a/types/tx/service_test.go +++ b/types/tx/service_test.go @@ -42,7 +42,7 @@ func (s *IntegrationTestSuite) SetupSuite() { clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig) // Create new simulation server. - srv := tx.NewTxServer(app.BaseApp.Simulate, encodingConfig.InterfaceRegistry) + srv := tx.NewTxServer(clientCtx.Client, app.BaseApp.Simulate, encodingConfig.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry()) tx.RegisterServiceServer(queryHelper, srv) From 78e219aad82bc609d0721d0b4a3ca004b3ce91a7 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 17:11:55 +0100 Subject: [PATCH 04/20] Make getTx grpc work --- baseapp/grpcrouter.go | 6 +- proto/cosmos/tx/v1beta1/service.proto | 2 +- server/start.go | 4 + server/types/app.go | 5 + simapp/app.go | 14 ++- testutil/network/util.go | 4 + types/tx/service.go | 52 ++++++-- types/tx/service_test.go | 170 +++++++++++++++----------- 8 files changed, 170 insertions(+), 87 deletions(-) diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go index 3492567e4902..42c16e8f9930 100644 --- a/baseapp/grpcrouter.go +++ b/baseapp/grpcrouter.go @@ -5,11 +5,11 @@ import ( gogogrpc "github.com/gogo/protobuf/grpc" abci "github.com/tendermint/tendermint/abci/types" - rpcclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc" "google.golang.org/grpc/encoding" "google.golang.org/grpc/encoding/proto" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/reflection" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -114,12 +114,12 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In // RegisterTxService registers the tx service on the gRPC router. func (qrt *GRPCQueryRouter) RegisterTxService( - rpcClient rpcclient.Client, + clientCtx client.Context, simulateFn tx.BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry, ) { tx.RegisterServiceServer( qrt, - tx.NewTxServer(rpcClient, simulateFn, interfaceRegistry), + tx.NewTxServer(clientCtx, simulateFn, interfaceRegistry), ) } diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 4d4d3ad6681f..96b02538e618 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -15,7 +15,7 @@ service Service { } // Simulate simulates executing a transaction for estimating gas usage. rpc GetTx(GetTxRequest) returns (GetTxResponse) { - option (google.api.http).get = "/cosmos/tx/v1beta1/getTx"; + option (google.api.http).get = "/cosmos/tx/v1beta1/getTx/{hash}"; } } diff --git a/server/start.go b/server/start.go index ca39a7606e64..58ed9d954d38 100644 --- a/server/start.go +++ b/server/start.go @@ -264,6 +264,10 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App var grpcSrv *grpc.Server if config.GRPC.Enable { + // Add the tx service in the gRPC router. + app.RegisterTxService(clientCtx) + + // Create a new server, and attach it to the app's gRPC router. grpcSrv, err = servergrpc.StartGRPCServer(app, config.GRPC.Address) if err != nil { return err diff --git a/server/types/app.go b/server/types/app.go index 9dfc565ee345..f036f6ff093c 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -10,6 +10,7 @@ import ( tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" ) @@ -37,6 +38,10 @@ type ( // RegisterGRPCServer registers gRPC services directly with the gRPC // server. RegisterGRPCServer(grpc.Server) + + // RegisterTxService registers the gRPC Query service for tx (such as tx + // simulation, fetching txs by hash...). + RegisterTxService(clientCtx client.Context) } // AppCreator is a function that allows us to lazily initialize an diff --git a/simapp/app.go b/simapp/app.go index e1ab98830c39..c13e6678d8d4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -134,7 +135,10 @@ var ( } ) -var _ App = (*SimApp)(nil) +var ( + _ App = (*SimApp)(nil) + _ servertypes.Application = (*SimApp)(nil) +) // SimApp extends an ABCI application, but with most of its parameters exported. // They are exported for convenience in creating helper functions, as object @@ -204,7 +208,6 @@ func NewSimApp( bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) - bApp.GRPCQueryRouter().RegisterTxService(bApp.Simulate, interfaceRegistry) keys := sdk.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, @@ -547,7 +550,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) - ModuleBasics.RegisterGRPCRoutes(apiSvr.ClientCtx, apiSvr.GRPCRouter) + ModuleBasics.RegisterGRPCRoutes(clientCtx, apiSvr.GRPCRouter) // register swagger API from root so that other applications can override easily if apiConfig.Swagger { @@ -555,6 +558,11 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon } } +// RegisterTxService implements the Application.RegisterTxService method. +func (app *SimApp) RegisterTxService(clientCtx client.Context) { + app.BaseApp.GRPCQueryRouter().RegisterTxService(clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) +} + // RegisterSwaggerAPI registers swagger route with API Server func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) { statikFS, err := fs.New() diff --git a/testutil/network/util.go b/testutil/network/util.go index 28a43ea7d599..148d47f356c1 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -84,6 +84,10 @@ func startInProcess(cfg Config, val *Validator) error { } if val.AppConfig.GRPC.Enable { + // Add the tx service in the gRPC router. + app.RegisterTxService(val.ClientCtx) + + // Create a new server, and attach it to the app's gRPC router. grpcSrv, err := servergrpc.StartGRPCServer(app, val.AppConfig.GRPC.Address) if err != nil { return err diff --git a/types/tx/service.go b/types/tx/service.go index 31bf31cb6bda..fd8a9e6576f7 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -2,29 +2,29 @@ package tx import ( "context" - fmt "fmt" - rpcclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // BaseAppSimulateFn is the signature of the Baseapp#Simulate function. type BaseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) type txServer struct { - rpcClient rpcclient.Client + clientCtx client.Context simulate BaseAppSimulateFn interfaceRegistry codectypes.InterfaceRegistry } // NewTxServer creates a new TxService server. -func NewTxServer(rpcClient rpcclient.Client, simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer { +func NewTxServer(clientCtx client.Context, simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer { return txServer{ - rpcClient: rpcClient, + clientCtx: clientCtx, simulate: simulate, interfaceRegistry: interfaceRegistry, } @@ -62,11 +62,47 @@ func (s txServer) Simulate(ctx context.Context, req *SimulateRequest) (*Simulate func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, error) { // TODO We should also check the proof flag in gRPC header. // https://github.com/cosmos/cosmos-sdk/issues/7036. - result, err := s.rpcClient.Tx(ctx, req.Hash, false) + result, err := s.clientCtx.Client.Tx(ctx, req.Hash, false) if err != nil { return nil, err } - fmt.Println(result) - return nil, nil + sdkTx, err := s.clientCtx.TxConfig.TxDecoder()(result.Tx) + if err != nil { + return nil, err + } + + txBuilder, ok := sdkTx.(client.TxBuilder) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (client.TxBuilder)(nil), sdkTx) + } + // Convert the txBuilder to a tx.Tx. + protoTx, err := TxBuilderToProtoTx(txBuilder) + if err != nil { + return nil, err + } + + return &GetTxResponse{ + Tx: protoTx, + }, nil +} + +// TxBuilderToProtoTx convert a txBuilder into a proto tx.Tx. +func TxBuilderToProtoTx(txBuilder client.TxBuilder) (*Tx, error) { + intoAnyTx, ok := txBuilder.(codectypes.IntoAny) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) + } + + any := intoAnyTx.AsAny().GetCachedValue() + if any == nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "any's cached value is empty") + } + + protoTx, ok := any.(*Tx) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) + } + + return protoTx, nil } diff --git a/types/tx/service_test.go b/types/tx/service_test.go index e3c80f2e66d7..4f9f8203d2b0 100644 --- a/types/tx/service_test.go +++ b/types/tx/service_test.go @@ -2,109 +2,93 @@ package tx_test import ( "context" + "encoding/hex" + fmt "fmt" "testing" "github.com/stretchr/testify/suite" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" clienttx "github.com/cosmos/cosmos-sdk/client/tx" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) type IntegrationTestSuite struct { suite.Suite - app *simapp.SimApp - clientCtx client.Context + cfg network.Config + network *network.Network + queryClient tx.ServiceClient - sdkCtx sdk.Context } func (s *IntegrationTestSuite) SetupSuite() { - app := simapp.Setup(true) - sdkCtx := app.BaseApp.NewContext(true, tmproto.Header{}) + s.T().Log("setting up integration test suite") - app.AccountKeeper.SetParams(sdkCtx, authtypes.DefaultParams()) - app.BankKeeper.SetParams(sdkCtx, banktypes.DefaultParams()) + cfg := network.DefaultConfig() + cfg.NumValidators = 1 - // Set up TxConfig. - encodingConfig := simapp.MakeTestEncodingConfig() - clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig) + s.cfg = cfg + s.network = network.New(s.T(), cfg) - // Create new simulation server. - srv := tx.NewTxServer(clientCtx.Client, app.BaseApp.Simulate, encodingConfig.InterfaceRegistry) + s.Require().NotNil(s.network) - queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry()) - tx.RegisterServiceServer(queryHelper, srv) - queryClient := tx.NewServiceClient(queryHelper) + _, err := s.network.WaitForHeight(1) + s.Require().NoError(err) - s.app = app - s.clientCtx = clientCtx - s.queryClient = queryClient - s.sdkCtx = sdkCtx + s.queryClient = tx.NewServiceClient(s.network.Validators[0].ClientCtx) } -func (s IntegrationTestSuite) TestSimulateService() { - // Create an account with some funds. - priv1, _, addr1 := testdata.KeyTestPubAddr() - acc1 := s.app.AccountKeeper.NewAccountWithAddress(s.sdkCtx, addr1) - err := acc1.SetAccountNumber(0) - s.Require().NoError(err) - s.app.AccountKeeper.SetAccount(s.sdkCtx, acc1) - s.app.BankKeeper.SetBalances(s.sdkCtx, addr1, sdk.Coins{ - sdk.NewInt64Coin("atom", 10000000), - }) - - // Create a test x/bank MsgSend. - coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10)) - _, _, addr2 := testdata.KeyTestPubAddr() - msg := banktypes.NewMsgSend(addr1, addr2, coins) - feeAmount := testdata.NewTestFeeAmount() - gasLimit := testdata.NewTestGasLimit() - memo := "foo" - accSeq, accNum := uint64(0), uint64(0) +func (s *IntegrationTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite") + s.network.Cleanup() +} + +func (s IntegrationTestSuite) TestSimulate() { + val := s.network.Validators[0] - // Create a txBuilder. - txBuilder := s.clientCtx.TxConfig.NewTxBuilder() - txBuilder.SetMsgs(msg) - txBuilder.SetMemo(memo) + // prepare txBuilder with msg + txBuilder := val.ClientCtx.TxConfig.NewTxBuilder() + feeAmount := sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)} + gasLimit := testdata.NewTestGasLimit() + s.Require().NoError( + txBuilder.SetMsgs(&banktypes.MsgSend{ + FromAddress: val.Address.String(), + ToAddress: val.Address.String(), + Amount: sdk.Coins{sdk.NewInt64Coin(s.cfg.BondDenom, 10)}, + }), + ) txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) - // 1st round: set empty signature - sigV2 := signing.SignatureV2{ - PubKey: priv1.PubKey(), - Data: &signing.SingleSignatureData{ - SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), - Signature: nil, - }, - } - txBuilder.SetSignatures(sigV2) - // 2nd round: actually sign - sigV2, err = clienttx.SignWithPrivKey( - s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), - authsigning.SignerData{ChainID: s.sdkCtx.ChainID(), AccountNumber: accNum, Sequence: accSeq}, - txBuilder, priv1, s.clientCtx.TxConfig, accSeq, - ) - txBuilder.SetSignatures(sigV2) + txBuilder.SetMemo("foobar") + + // setup txFactory + txFactory := clienttx.Factory{}. + WithChainID(val.ClientCtx.ChainID). + WithKeybase(val.ClientCtx.Keyring). + WithTxConfig(val.ClientCtx.TxConfig). + WithSignMode(signing.SignMode_SIGN_MODE_DIRECT) + + // Sign Tx. + err := authclient.SignTx(txFactory, val.ClientCtx, val.Moniker, txBuilder, false) + s.Require().NoError(err) + + // Convert the txBuilder to a tx.Tx. + protoTx, err := tx.TxBuilderToProtoTx(txBuilder) + s.Require().NoError(err) - any, ok := txBuilder.(codectypes.IntoAny) - s.Require().True(ok) - cached := any.AsAny().GetCachedValue() - txTx, ok := cached.(*tx.Tx) - s.Require().True(ok) + // Run the simulate gRPC query. res, err := s.queryClient.Simulate( context.Background(), - &tx.SimulateRequest{Tx: txTx}, + &tx.SimulateRequest{Tx: protoTx}, ) s.Require().NoError(err) @@ -113,6 +97,48 @@ func (s IntegrationTestSuite) TestSimulateService() { s.Require().True(res.GetGasInfo().GetGasUsed() > 0) // Gas used sometimes change, just check it's not empty. } -func TestSimulateTestSuite(t *testing.T) { +func (s IntegrationTestSuite) TestGetTx() { + val := s.network.Validators[0] + + // Create a new MsgSend tx from val to itself. + out, err := bankcli.MsgSendExec( + val.ClientCtx, + val.Address, + val.Address, + sdk.NewCoins( + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)), + ), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--gas=%d", flags.DefaultGasLimit), + fmt.Sprintf("--%s=foobar", flags.FlagMemo), + ) + s.Require().NoError(err) + var txRes sdk.TxResponse + s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &txRes)) + s.Require().Equal(uint32(0), txRes.Code) + + s.Require().NoError(s.network.WaitForNextBlock()) + + // Query the tx via gRPC. + hash, err := hex.DecodeString(txRes.TxHash) + s.Require().NoError(err) + grpcRes, err := s.queryClient.GetTx( + context.Background(), + &tx.GetTxRequest{Hash: hash}, + ) + s.Require().NoError(err) + s.Require().Equal("foobar", grpcRes.Tx.Body.Memo) + + // Query the tx via grpc-gateway. + restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/getTx/%s", val.APIAddress, val.Address.String())) + s.Require().NoError(err) + + fmt.Println(string(restRes)) + s.Require().True(false) +} + +func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } From 2e1c6e819f21c7fa3443d3bf487e757cb5c2933b Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 17:18:36 +0100 Subject: [PATCH 05/20] Hash as string --- proto/cosmos/tx/v1beta1/service.proto | 4 +- types/tx/service.go | 9 +++- types/tx/service.pb.go | 75 +++++++++++++-------------- types/tx/service.pb.gw.go | 44 +++++++++++----- types/tx/service_test.go | 7 +-- 5 files changed, 80 insertions(+), 59 deletions(-) diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 96b02538e618..8e7ef199ffe1 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -38,8 +38,8 @@ message SimulateResponse { // GetTx is the request type for the Service.GetTx // RPC method. message GetTxRequest { - // hash is the tx hash to query. - bytes hash = 1; + // hash is the tx hash to query, encoded as a hex string. + string hash = 1; } // GetTxResponse is the response type for the Service.GetTx method. diff --git a/types/tx/service.go b/types/tx/service.go index fd8a9e6576f7..f4dcc6c1740c 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -2,6 +2,7 @@ package tx import ( "context" + "encoding/hex" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -60,9 +61,15 @@ func (s txServer) Simulate(ctx context.Context, req *SimulateRequest) (*Simulate // GetTx implements the ServiceServer.GetTx RPC method. func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, error) { + // We get hash as a hex string in the request, convert it to bytes. + hash, err := hex.DecodeString(req.Hash) + if err != nil { + return nil, err + } + // TODO We should also check the proof flag in gRPC header. // https://github.com/cosmos/cosmos-sdk/issues/7036. - result, err := s.clientCtx.Client.Tx(ctx, req.Hash, false) + result, err := s.clientCtx.Client.Tx(ctx, hash, false) if err != nil { return nil, err } diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go index ea845ae09e1e..d58485c6583b 100644 --- a/types/tx/service.pb.go +++ b/types/tx/service.pb.go @@ -135,8 +135,8 @@ func (m *SimulateResponse) GetResult() *types.Result { // GetTx is the request type for the Service.GetTx // RPC method. type GetTxRequest struct { - // hash is the tx hash to query. - Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + // hash is the tx hash to query, encoded as a hex string. + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` } func (m *GetTxRequest) Reset() { *m = GetTxRequest{} } @@ -172,11 +172,11 @@ func (m *GetTxRequest) XXX_DiscardUnknown() { var xxx_messageInfo_GetTxRequest proto.InternalMessageInfo -func (m *GetTxRequest) GetHash() []byte { +func (m *GetTxRequest) GetHash() string { if m != nil { return m.Hash } - return nil + return "" } // GetTxResponse is the response type for the Service.GetTx method. @@ -235,32 +235,33 @@ func init() { func init() { proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescriptor_e0b00a618705eca7) } var fileDescriptor_e0b00a618705eca7 = []byte{ - // 398 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6a, 0xdb, 0x30, - 0x1c, 0xc7, 0x63, 0xb3, 0x25, 0x41, 0xcb, 0xd8, 0x26, 0x18, 0x04, 0x6f, 0x73, 0x3c, 0x85, 0xc0, - 0x2e, 0xb3, 0x48, 0x06, 0x23, 0x87, 0xc1, 0xa0, 0x97, 0xd0, 0xab, 0x93, 0x53, 0x2f, 0x45, 0x76, - 0x15, 0xc7, 0xd4, 0xb1, 0xdc, 0x48, 0x0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95, 0xd6, 0xd9, - 0xad, 0xf5, 0x14, 0xe7, 0x69, 0x1e, 0x21, 0xd0, 0x1a, 0x51, 0x31, 0x91, 0xe5, 0x0c, 0x10, 0xbc, - 0x9b, 0x11, 0x3e, 0x53, 0x1d, 0x5a, 0x9e, 0x3a, 0xa3, 0xbf, 0xe0, 0xa3, 0x66, 0x74, 0xd9, 0xb7, - 0x0d, 0x3a, 0xb8, 0x37, 0x40, 0x63, 0x5c, 0x5c, 0x13, 0x94, 0xa0, 0x59, 0xce, 0x0c, 0x51, 0x85, - 0xe4, 0xc5, 0xbf, 0xb4, 0xba, 0xaf, 0x32, 0x45, 0x0f, 0xd4, 0x3d, 0xbb, 0xbe, 0xbb, 0x34, 0x7f, - 0xa0, 0x6f, 0xb8, 0x62, 0x3f, 0xca, 0xb4, 0x18, 0xbc, 0x57, 0xed, 0x61, 0xa7, 0xc2, 0xf2, 0xf9, - 0xec, 0x96, 0xb3, 0x1b, 0xd0, 0x81, 0x8e, 0x0a, 0xb4, 0x60, 0xbb, 0x22, 0x30, 0xcc, 0xc9, 0xbd, - 0xff, 0x57, 0x6b, 0xdb, 0x58, 0xad, 0x6d, 0xe3, 0x76, 0x6d, 0x1b, 0x17, 0x1b, 0xbb, 0xb6, 0xda, - 0xd8, 0xb5, 0x9b, 0x8d, 0x5d, 0x3b, 0xe8, 0x85, 0x91, 0x98, 0x65, 0xbe, 0x1b, 0xb0, 0x79, 0xa9, - 0x2e, 0x1e, 0xbf, 0xf9, 0xd1, 0x31, 0x16, 0xa7, 0x29, 0xcd, 0xed, 0xfc, 0xba, 0x5a, 0xaf, 0x3f, - 0x0f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x1d, 0xfd, 0xe9, 0xb9, 0xf3, 0x02, 0x00, 0x00, + // 405 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3d, 0x6b, 0xdb, 0x40, + 0x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xe3, 0x98, + 0xa6, 0xae, 0x5e, 0x59, 0x6d, 0xd9, 0xbf, 0x87, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xa7, 0x66, + 0x2d, 0xfa, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -850,7 +851,7 @@ func (m *GetTxRequest) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowService @@ -860,25 +861,23 @@ func (m *GetTxRequest) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthService } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthService } if postIndex > l { return io.ErrUnexpectedEOF } - m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) - if m.Hash == nil { - m.Hash = []byte{} - } + m.Hash = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/types/tx/service.pb.gw.go b/types/tx/service.pb.gw.go index 1b33225157f0..f02e3ab05a00 100644 --- a/types/tx/service.pb.gw.go +++ b/types/tx/service.pb.gw.go @@ -67,19 +67,26 @@ func local_request_Service_Simulate_0(ctx context.Context, marshaler runtime.Mar } -var ( - filter_Service_GetTx_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - func request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq GetTxRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_GetTx_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) } msg, err := client.GetTx(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) @@ -91,11 +98,22 @@ func local_request_Service_GetTx_0(ctx context.Context, marshaler runtime.Marsha var protoReq GetTxRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["hash"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Service_GetTx_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + protoReq.Hash, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err) } msg, err := server.GetTx(ctx, &protoReq) @@ -236,7 +254,7 @@ func RegisterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl var ( pattern_Service_Simulate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "simulate"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Service_GetTx_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "getTx"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Service_GetTx_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "tx", "v1beta1", "getTx", "hash"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/types/tx/service_test.go b/types/tx/service_test.go index 4f9f8203d2b0..920514e9b5ff 100644 --- a/types/tx/service_test.go +++ b/types/tx/service_test.go @@ -2,7 +2,6 @@ package tx_test import ( "context" - "encoding/hex" fmt "fmt" "testing" @@ -122,17 +121,15 @@ func (s IntegrationTestSuite) TestGetTx() { s.Require().NoError(s.network.WaitForNextBlock()) // Query the tx via gRPC. - hash, err := hex.DecodeString(txRes.TxHash) - s.Require().NoError(err) grpcRes, err := s.queryClient.GetTx( context.Background(), - &tx.GetTxRequest{Hash: hash}, + &tx.GetTxRequest{Hash: txRes.TxHash}, ) s.Require().NoError(err) s.Require().Equal("foobar", grpcRes.Tx.Body.Memo) // Query the tx via grpc-gateway. - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/getTx/%s", val.APIAddress, val.Address.String())) + restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/getTx/%s", val.APIAddress, txRes.TxHash)) s.Require().NoError(err) fmt.Println(string(restRes)) From f86d98dc2231df0fab722cb987734d0a7701b2d4 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 17:34:15 +0100 Subject: [PATCH 06/20] Add todo comment --- client/tx/tx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/tx/tx.go b/client/tx/tx.go index 892bbba40ee6..7c5f338d187b 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -293,6 +293,7 @@ func CalculateGas( return tx.SimulateResponse{}, 0, err } + // TODO This should use the generated queryClient. bz, _, err := queryFunc("/cosmos.tx.v1beta1.Service/Simulate", txBytes) if err != nil { return tx.SimulateResponse{}, 0, err From f7f2daf69f26ef7e1c219e14250f49a248e2d813 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 17:49:40 +0100 Subject: [PATCH 07/20] /tx --- proto/cosmos/tx/v1beta1/service.proto | 2 +- types/tx/service.pb.go | 50 +++++++++++++-------------- types/tx/service.pb.gw.go | 2 +- types/tx/service_test.go | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 8e7ef199ffe1..5ce021252e14 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -15,7 +15,7 @@ service Service { } // Simulate simulates executing a transaction for estimating gas usage. rpc GetTx(GetTxRequest) returns (GetTxResponse) { - option (google.api.http).get = "/cosmos/tx/v1beta1/getTx/{hash}"; + option (google.api.http).get = "/cosmos/tx/v1beta1/tx/{hash}"; } } diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go index d58485c6583b..9d8007ceb292 100644 --- a/types/tx/service.pb.go +++ b/types/tx/service.pb.go @@ -235,33 +235,33 @@ func init() { func init() { proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescriptor_e0b00a618705eca7) } var fileDescriptor_e0b00a618705eca7 = []byte{ - // 405 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3d, 0x6b, 0xdb, 0x40, - 0x18, 0xc7, 0x2d, 0xd1, 0xda, 0xee, 0xb5, 0xa5, 0xed, 0x41, 0xc1, 0xa8, 0xad, 0x6c, 0x9f, 0x31, - 0xed, 0x52, 0x1d, 0x76, 0xa1, 0x78, 0x08, 0x04, 0xb2, 0x98, 0xac, 0xb2, 0xa7, 0x2c, 0xe1, 0xa4, + // 404 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x31, 0x6b, 0xdb, 0x40, + 0x1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, 0xbd, 0x01, 0x2a, 0x83, 0xec, 0x37, 0x41, 0x09, 0xaa, 0x79, 0x67, + 0x88, 0x0a, 0x2c, 0x2f, 0xee, 0xd2, 0x6a, 0xbd, 0xaa, 0xc9, 0x72, 0xa0, 0xd6, 0xd9, 0xf5, 0xdd, + 0xa5, 0xf9, 0x13, 0xfd, 0xc0, 0x05, 0xfb, 0x91, 0x4f, 0x8b, 0xc1, 0x7b, 0x95, 0x1e, 0x36, 0x0a, + 0x90, 0xcf, 0xbb, 0x5b, 0xcd, 0xcd, 0x02, 0x3d, 0xf0, 0xb7, 0x1a, 0x68, 0xc3, 0x3a, 0x2e, 0xda, + 0x0c, 0x7c, 0x92, 0x5e, 0xd7, 0xe9, 0xce, 0xf6, 0xd5, 0xd2, 0x36, 0x16, 0x4b, 0xdb, 0xb8, 0x5d, 0xda, 0xc6, 0xc5, 0xca, 0x2e, 0x2d, 0x56, 0x76, 0xe9, 0x66, 0x65, 0x97, 0xf6, 0xda, 0x41, 0x28, - 0xc6, 0x89, 0xe7, 0xf8, 0x6c, 0x9a, 0x9b, 0x64, 0x8f, 0xbf, 0xfc, 0xe0, 0x10, 0x8b, 0xe3, 0x98, - 0xa6, 0xae, 0x5e, 0x59, 0x6d, 0xd9, 0xbf, 0x87, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xa7, 0x66, - 0x2d, 0xfa, 0x02, 0x00, 0x00, + 0xc6, 0x89, 0xe7, 0xf8, 0x6c, 0x9a, 0x13, 0xb2, 0xc7, 0x5f, 0x7e, 0x70, 0x88, 0xc5, 0x71, 0x4c, + 0x53, 0xa4, 0x57, 0x56, 0x2b, 0xf6, 0xef, 0x21, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x4c, 0x40, 0xff, + 0xf7, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/types/tx/service.pb.gw.go b/types/tx/service.pb.gw.go index f02e3ab05a00..270036363ad5 100644 --- a/types/tx/service.pb.gw.go +++ b/types/tx/service.pb.gw.go @@ -254,7 +254,7 @@ func RegisterServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl var ( pattern_Service_Simulate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "tx", "v1beta1", "simulate"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Service_GetTx_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cosmos", "tx", "v1beta1", "getTx", "hash"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Service_GetTx_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3}, []string{"cosmos", "tx", "v1beta1", "hash"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( diff --git a/types/tx/service_test.go b/types/tx/service_test.go index 920514e9b5ff..1d5133864130 100644 --- a/types/tx/service_test.go +++ b/types/tx/service_test.go @@ -129,7 +129,7 @@ func (s IntegrationTestSuite) TestGetTx() { s.Require().Equal("foobar", grpcRes.Tx.Body.Memo) // Query the tx via grpc-gateway. - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/getTx/%s", val.APIAddress, txRes.TxHash)) + restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/tx/%s", val.APIAddress, txRes.TxHash)) s.Require().NoError(err) fmt.Println(string(restRes)) From 03cd9bf9896abda6e93bec67b02fda6e84f2152d Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 18:29:36 +0100 Subject: [PATCH 08/20] Make tests pass --- simapp/app.go | 6 ++++++ testutil/network/util.go | 10 +++++++--- types/tx/service.go | 2 +- types/tx/service_test.go | 8 ++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index c13e6678d8d4..384d974404bf 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -1,6 +1,7 @@ package simapp import ( + "context" "io" "net/http" "os" @@ -27,6 +28,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -547,8 +549,12 @@ func (app *SimApp) SimulationManager() *module.SimulationManager { func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { clientCtx := apiSvr.ClientCtx rpc.RegisterRoutes(clientCtx, apiSvr.Router) + // Register legacy tx routes. authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) + // Register new tx routes from grpc-gateway. + tx.RegisterServiceHandlerClient(context.Background(), apiSvr.GRPCRouter, tx.NewServiceClient(clientCtx)) + // Register legacy and grpc-gateway routes for all modules. ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) ModuleBasics.RegisterGRPCRoutes(clientCtx, apiSvr.GRPCRouter) diff --git a/testutil/network/util.go b/testutil/network/util.go index 148d47f356c1..45e7dfbc8251 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -59,10 +59,16 @@ func startInProcess(cfg Config, val *Validator) error { val.RPCClient = local.New(tmNode) } - if val.APIAddress != "" { + // We'll need a RPC client if the validator exposes a gRPC or REST endpoint. + if val.APIAddress != "" || val.AppConfig.GRPC.Enable { val.ClientCtx = val.ClientCtx. WithClient(val.RPCClient) + // Add the tx service in the gRPC router. + app.RegisterTxService(val.ClientCtx) + } + + if val.APIAddress != "" { apiSrv := api.New(val.ClientCtx, logger.With("module", "api-server")) app.RegisterAPIRoutes(apiSrv, val.AppConfig.API) @@ -84,8 +90,6 @@ func startInProcess(cfg Config, val *Validator) error { } if val.AppConfig.GRPC.Enable { - // Add the tx service in the gRPC router. - app.RegisterTxService(val.ClientCtx) // Create a new server, and attach it to the app's gRPC router. grpcSrv, err := servergrpc.StartGRPCServer(app, val.AppConfig.GRPC.Address) diff --git a/types/tx/service.go b/types/tx/service.go index f4dcc6c1740c..dc1dbdfbe08c 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -95,7 +95,7 @@ func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, } // TxBuilderToProtoTx convert a txBuilder into a proto tx.Tx. -func TxBuilderToProtoTx(txBuilder client.TxBuilder) (*Tx, error) { +func TxBuilderToProtoTx(txBuilder client.TxBuilder) (*Tx, error) { // nolint intoAnyTx, ok := txBuilder.(codectypes.IntoAny) if !ok { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) diff --git a/types/tx/service_test.go b/types/tx/service_test.go index 1d5133864130..583846c8964b 100644 --- a/types/tx/service_test.go +++ b/types/tx/service_test.go @@ -2,7 +2,7 @@ package tx_test import ( "context" - fmt "fmt" + "fmt" "testing" "github.com/stretchr/testify/suite" @@ -131,9 +131,9 @@ func (s IntegrationTestSuite) TestGetTx() { // Query the tx via grpc-gateway. restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/tx/%s", val.APIAddress, txRes.TxHash)) s.Require().NoError(err) - - fmt.Println(string(restRes)) - s.Require().True(false) + var getTxRes tx.GetTxResponse + s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(restRes, &getTxRes)) + s.Require().Equal("foobar", getTxRes.Tx.Body.Memo) } func TestIntegrationTestSuite(t *testing.T) { From 50ebca83ceb99060da0c8d1bcb79572534fd673a Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 18:36:04 +0100 Subject: [PATCH 09/20] Put into function --- simapp/app.go | 3 +-- types/tx/service.go | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 384d974404bf..95eb0e0d7e36 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -1,7 +1,6 @@ package simapp import ( - "context" "io" "net/http" "os" @@ -552,7 +551,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon // Register legacy tx routes. authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) // Register new tx routes from grpc-gateway. - tx.RegisterServiceHandlerClient(context.Background(), apiSvr.GRPCRouter, tx.NewServiceClient(clientCtx)) + tx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter) // Register legacy and grpc-gateway routes for all modules. ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) diff --git a/types/tx/service.go b/types/tx/service.go index dc1dbdfbe08c..04d53c0075dc 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" + "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -113,3 +114,9 @@ func TxBuilderToProtoTx(txBuilder client.TxBuilder) (*Tx, error) { // nolint return protoTx, nil } + +// RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the +// given Mux. +func RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientCtx)) +} From cc21f9e3ac2e96639e6fa3fcdba5d8f6df233b14 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 18:39:40 +0100 Subject: [PATCH 10/20] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c4e7d1f830c..5c86b655518d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * `Validator.ConsensusPubkey` type changed from `string` to `codectypes.Any`. * `MsgCreateValidator.Pubkey` type changed from `string` to `codectypes.Any`. * Deprecating and renaming `MakeEncodingConfig` to `MakeTestEncodingConfig` (both in `simapp` and `simapp/params` packages). +* (tx) [\#7688](https://github.com/cosmos/cosmos-sdk/pull/7688) The gRPC simulate service method has been moved from `cosmos.base.v1beta1.simulate` to `cosmos.tx.v1beta1`, as a method in the Tx service. ### Features From a488465145b487bbe33e3fb50ee1e7871ff8b353 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 18:52:32 +0100 Subject: [PATCH 11/20] Fix lint --- types/tx/service.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/tx/service.go b/types/tx/service.go index 04d53c0075dc..5c4ba991dded 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" + gogogrpc "github.com/gogo/protobuf/grpc" "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -117,6 +118,6 @@ func TxBuilderToProtoTx(txBuilder client.TxBuilder) (*Tx, error) { // nolint // RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the // given Mux. -func RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientCtx)) +func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { + RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn)) } From d40abfdfcf8bcbac20ac52279ef6b416a8f16a1e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 18:57:31 +0100 Subject: [PATCH 12/20] RegisterTxService in server --- server/start.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/start.go b/server/start.go index 58ed9d954d38..b01ae8e9dd74 100644 --- a/server/start.go +++ b/server/start.go @@ -231,6 +231,9 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App return err } + // Add the tx service to the gRPC router. + app.RegisterTxService(clientCtx) + var apiSrv *api.Server config := config.GetConfig(ctx.Viper) @@ -264,9 +267,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App var grpcSrv *grpc.Server if config.GRPC.Enable { - // Add the tx service in the gRPC router. - app.RegisterTxService(clientCtx) - // Create a new server, and attach it to the app's gRPC router. grpcSrv, err = servergrpc.StartGRPCServer(app, config.GRPC.Address) if err != nil { From ac272292e210e13172da39fbf5ffc1b9874cec40 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 27 Oct 2020 18:59:00 +0100 Subject: [PATCH 13/20] Remove comment --- server/start.go | 1 - testutil/network/util.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/server/start.go b/server/start.go index b01ae8e9dd74..6e014de75080 100644 --- a/server/start.go +++ b/server/start.go @@ -267,7 +267,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App var grpcSrv *grpc.Server if config.GRPC.Enable { - // Create a new server, and attach it to the app's gRPC router. grpcSrv, err = servergrpc.StartGRPCServer(app, config.GRPC.Address) if err != nil { return err diff --git a/testutil/network/util.go b/testutil/network/util.go index 45e7dfbc8251..d85dafd0a15a 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -90,8 +90,6 @@ func startInProcess(cfg Config, val *Validator) error { } if val.AppConfig.GRPC.Enable { - - // Create a new server, and attach it to the app's gRPC router. grpcSrv, err := servergrpc.StartGRPCServer(app, val.AppConfig.GRPC.Address) if err != nil { return err From de92530ee1c59ad1db5d3fa33964cb9efc233963 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 28 Oct 2020 17:05:48 +0100 Subject: [PATCH 14/20] Update proto/cosmos/tx/v1beta1/service.proto Co-authored-by: Cory --- proto/cosmos/tx/v1beta1/service.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index 5ce021252e14..a629f76fe1b9 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -7,7 +7,7 @@ import "cosmos/tx/v1beta1/tx.proto"; option go_package = "github.com/cosmos/cosmos-sdk/types/tx"; -// Service defines a gRPC service for simulating transactions. +// Service defines a gRPC service for interacting with transactions. service Service { // Simulate simulates executing a transaction for estimating gas usage. rpc Simulate(SimulateRequest) returns (SimulateResponse) { From b2083df919d044e26655efe73f799047ecd913b3 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 29 Oct 2020 11:32:17 +0100 Subject: [PATCH 15/20] Create new protoCdc --- types/tx/service.go | 41 ++++++++-------------------------------- types/tx/service_test.go | 25 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/types/tx/service.go b/types/tx/service.go index 5c4ba991dded..d934ab463301 100644 --- a/types/tx/service.go +++ b/types/tx/service.go @@ -3,6 +3,7 @@ package tx import ( "context" "encoding/hex" + fmt "fmt" gogogrpc "github.com/gogo/protobuf/grpc" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -10,9 +11,9 @@ import ( "google.golang.org/grpc/status" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) // BaseAppSimulateFn is the signature of the Baseapp#Simulate function. @@ -76,46 +77,20 @@ func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, return nil, err } - sdkTx, err := s.clientCtx.TxConfig.TxDecoder()(result.Tx) - if err != nil { - return nil, err - } - - txBuilder, ok := sdkTx.(client.TxBuilder) - if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (client.TxBuilder)(nil), sdkTx) - } - // Convert the txBuilder to a tx.Tx. - protoTx, err := TxBuilderToProtoTx(txBuilder) + // Create a proto codec, we need it to unmarshal the tx bytes. + cdc := codec.NewProtoCodec(s.clientCtx.InterfaceRegistry) + var protoTx Tx + err = cdc.UnmarshalBinaryBare(result.Tx, &protoTx) if err != nil { return nil, err } + fmt.Println(protoTx) return &GetTxResponse{ - Tx: protoTx, + Tx: &protoTx, }, nil } -// TxBuilderToProtoTx convert a txBuilder into a proto tx.Tx. -func TxBuilderToProtoTx(txBuilder client.TxBuilder) (*Tx, error) { // nolint - intoAnyTx, ok := txBuilder.(codectypes.IntoAny) - if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) - } - - any := intoAnyTx.AsAny().GetCachedValue() - if any == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "any's cached value is empty") - } - - protoTx, ok := any.(*Tx) - if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) - } - - return protoTx, nil -} - // RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the // given Mux. func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { diff --git a/types/tx/service_test.go b/types/tx/service_test.go index 583846c8964b..ec51cf0e2bb9 100644 --- a/types/tx/service_test.go +++ b/types/tx/service_test.go @@ -7,11 +7,14 @@ import ( "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clienttx "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -81,7 +84,7 @@ func (s IntegrationTestSuite) TestSimulate() { s.Require().NoError(err) // Convert the txBuilder to a tx.Tx. - protoTx, err := tx.TxBuilderToProtoTx(txBuilder) + protoTx, err := txBuilderToProtoTx(txBuilder) s.Require().NoError(err) // Run the simulate gRPC query. @@ -139,3 +142,23 @@ func (s IntegrationTestSuite) TestGetTx() { func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } + +// txBuilderToProtoTx converts a txBuilder into a proto tx.Tx. +func txBuilderToProtoTx(txBuilder client.TxBuilder) (*tx.Tx, error) { // nolint + intoAnyTx, ok := txBuilder.(codectypes.IntoAny) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) + } + + any := intoAnyTx.AsAny().GetCachedValue() + if any == nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "any's cached value is empty") + } + + protoTx, ok := any.(*tx.Tx) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", (codectypes.IntoAny)(nil), intoAnyTx) + } + + return protoTx, nil +} From 142a3a390d3b216478e5a7676535c6781769f641 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 29 Oct 2020 11:40:47 +0100 Subject: [PATCH 16/20] Move tx service to x/auth --- baseapp/grpcrouter.go | 14 ---------- simapp/app.go | 6 ++--- {types => x/auth}/tx/service.go | 39 ++++++++++++++++++---------- {types => x/auth}/tx/service_test.go | 0 4 files changed, 29 insertions(+), 30 deletions(-) rename {types => x/auth}/tx/service.go (62%) rename {types => x/auth}/tx/service_test.go (100%) diff --git a/baseapp/grpcrouter.go b/baseapp/grpcrouter.go index 42c16e8f9930..666ff2343a6b 100644 --- a/baseapp/grpcrouter.go +++ b/baseapp/grpcrouter.go @@ -9,11 +9,9 @@ import ( "google.golang.org/grpc/encoding" "google.golang.org/grpc/encoding/proto" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/reflection" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx" ) var protoCodec = encoding.GetCodec(proto.Name) @@ -111,15 +109,3 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In reflection.NewReflectionServiceServer(interfaceRegistry), ) } - -// RegisterTxService registers the tx service on the gRPC router. -func (qrt *GRPCQueryRouter) RegisterTxService( - clientCtx client.Context, - simulateFn tx.BaseAppSimulateFn, - interfaceRegistry codectypes.InterfaceRegistry, -) { - tx.RegisterServiceServer( - qrt, - tx.NewTxServer(clientCtx, simulateFn, interfaceRegistry), - ) -} diff --git a/simapp/app.go b/simapp/app.go index 95eb0e0d7e36..1d584ff0f7c5 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -27,13 +27,13 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" "github.com/cosmos/cosmos-sdk/x/bank" @@ -551,7 +551,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon // Register legacy tx routes. authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) // Register new tx routes from grpc-gateway. - tx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter) + authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter) // Register legacy and grpc-gateway routes for all modules. ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) @@ -565,7 +565,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon // RegisterTxService implements the Application.RegisterTxService method. func (app *SimApp) RegisterTxService(clientCtx client.Context) { - app.BaseApp.GRPCQueryRouter().RegisterTxService(clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) + authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } // RegisterSwaggerAPI registers swagger route with API Server diff --git a/types/tx/service.go b/x/auth/tx/service.go similarity index 62% rename from types/tx/service.go rename to x/auth/tx/service.go index d934ab463301..aaac7368e67b 100644 --- a/types/tx/service.go +++ b/x/auth/tx/service.go @@ -3,30 +3,31 @@ package tx import ( "context" "encoding/hex" - fmt "fmt" gogogrpc "github.com/gogo/protobuf/grpc" "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) -// BaseAppSimulateFn is the signature of the Baseapp#Simulate function. -type BaseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) +// baseAppSimulateFn is the signature of the Baseapp#Simulate function. +type baseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) type txServer struct { clientCtx client.Context - simulate BaseAppSimulateFn + simulate baseAppSimulateFn interfaceRegistry codectypes.InterfaceRegistry } // NewTxServer creates a new TxService server. -func NewTxServer(clientCtx client.Context, simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) ServiceServer { +func NewTxServer(clientCtx client.Context, simulate baseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) txtypes.ServiceServer { return txServer{ clientCtx: clientCtx, simulate: simulate, @@ -34,10 +35,10 @@ func NewTxServer(clientCtx client.Context, simulate BaseAppSimulateFn, interface } } -var _ ServiceServer = txServer{} +var _ txtypes.ServiceServer = txServer{} // Simulate implements the ServiceServer.Simulate RPC method. -func (s txServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) { +func (s txServer) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (*txtypes.SimulateResponse, error) { if req.Tx == nil { return nil, status.Error(codes.InvalidArgument, "invalid empty tx") } @@ -56,14 +57,14 @@ func (s txServer) Simulate(ctx context.Context, req *SimulateRequest) (*Simulate return nil, err } - return &SimulateResponse{ + return &txtypes.SimulateResponse{ GasInfo: &gasInfo, Result: result, }, nil } // GetTx implements the ServiceServer.GetTx RPC method. -func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, error) { +func (s txServer) GetTx(ctx context.Context, req *txtypes.GetTxRequest) (*txtypes.GetTxResponse, error) { // We get hash as a hex string in the request, convert it to bytes. hash, err := hex.DecodeString(req.Hash) if err != nil { @@ -79,20 +80,32 @@ func (s txServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, // Create a proto codec, we need it to unmarshal the tx bytes. cdc := codec.NewProtoCodec(s.clientCtx.InterfaceRegistry) - var protoTx Tx + var protoTx txtypes.Tx err = cdc.UnmarshalBinaryBare(result.Tx, &protoTx) if err != nil { return nil, err } - fmt.Println(protoTx) - return &GetTxResponse{ + return &txtypes.GetTxResponse{ Tx: &protoTx, }, nil } +// RegisterTxService registers the tx service on the gRPC router. +func RegisterTxService( + qrt *baseapp.GRPCQueryRouter, + clientCtx client.Context, + simulateFn baseAppSimulateFn, + interfaceRegistry codectypes.InterfaceRegistry, +) { + txtypes.RegisterServiceServer( + qrt, + NewTxServer(clientCtx, simulateFn, interfaceRegistry), + ) +} + // RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the // given Mux. func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { - RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn)) + txtypes.RegisterServiceHandlerClient(context.Background(), mux, txtypes.NewServiceClient(clientConn)) } diff --git a/types/tx/service_test.go b/x/auth/tx/service_test.go similarity index 100% rename from types/tx/service_test.go rename to x/auth/tx/service_test.go From 01e4a986410457bf0d210b2868a82513c11cbfd8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 29 Oct 2020 11:45:01 +0100 Subject: [PATCH 17/20] Small tweaks --- CHANGELOG.md | 1 + proto/cosmos/tx/v1beta1/service.proto | 2 +- types/tx/service.pb.go | 4 ++-- x/auth/tx/service.go | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c86b655518d..997cf958bd75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (codec) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) `InterfaceRegistry` now inherits `jsonpb.AnyResolver`, and has a `RegisterCustomTypeURL` method to support ADR 031 packing of `Any`s. `AnyResolver` is now a required parameter to `RejectUnknownFields`. * (baseapp) [\#7519](https://github.com/cosmos/cosmos-sdk/pull/7519) Add `ServiceMsgRouter` to BaseApp to handle routing of protobuf service `Msg`s. The two new types defined in ADR 031, `sdk.ServiceMsg` and `sdk.MsgRequest` are introduced with this router. +* (tx) [\#7688](https://github.com/cosmos/cosmos-sdk/pull/7688) Add a new Tx gRPC service with methods `Simulate` and `GetTx` (by hash). ### Bug Fixes diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index a629f76fe1b9..eb7784001cc8 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -13,7 +13,7 @@ service Service { rpc Simulate(SimulateRequest) returns (SimulateResponse) { option (google.api.http).post = "/cosmos/tx/v1beta1/simulate"; } - // Simulate simulates executing a transaction for estimating gas usage. + // GetTx fetches a tx by hash. rpc GetTx(GetTxRequest) returns (GetTxResponse) { option (google.api.http).get = "/cosmos/tx/v1beta1/tx/{hash}"; } diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go index 9d8007ceb292..ae691fd6273a 100644 --- a/types/tx/service.pb.go +++ b/types/tx/service.pb.go @@ -278,7 +278,7 @@ const _ = grpc.SupportPackageIsVersion4 type ServiceClient interface { // Simulate simulates executing a transaction for estimating gas usage. Simulate(ctx context.Context, in *SimulateRequest, opts ...grpc.CallOption) (*SimulateResponse, error) - // Simulate simulates executing a transaction for estimating gas usage. + // GetTx fetches a tx by hash. GetTx(ctx context.Context, in *GetTxRequest, opts ...grpc.CallOption) (*GetTxResponse, error) } @@ -312,7 +312,7 @@ func (c *serviceClient) GetTx(ctx context.Context, in *GetTxRequest, opts ...grp type ServiceServer interface { // Simulate simulates executing a transaction for estimating gas usage. Simulate(context.Context, *SimulateRequest) (*SimulateResponse, error) - // Simulate simulates executing a transaction for estimating gas usage. + // GetTx fetches a tx by hash. GetTx(context.Context, *GetTxRequest) (*GetTxResponse, error) } diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index aaac7368e67b..4c8d1c7d1777 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -20,13 +20,14 @@ import ( // baseAppSimulateFn is the signature of the Baseapp#Simulate function. type baseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) +// txServer is the server for the protobuf Tx service. type txServer struct { clientCtx client.Context simulate baseAppSimulateFn interfaceRegistry codectypes.InterfaceRegistry } -// NewTxServer creates a new TxService server. +// NewTxServer creates a new Tx service server. func NewTxServer(clientCtx client.Context, simulate baseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) txtypes.ServiceServer { return txServer{ clientCtx: clientCtx, From 4f92090a0fbaad635f77a5416a1d43b3543224fc Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 29 Oct 2020 11:57:50 +0100 Subject: [PATCH 18/20] Link gh issue --- client/tx/tx.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index 7c5f338d187b..fb0e71280501 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -293,7 +293,8 @@ func CalculateGas( return tx.SimulateResponse{}, 0, err } - // TODO This should use the generated queryClient. + // TODO This should use the generated tx service Client. + // https://github.com/cosmos/cosmos-sdk/issues/7726 bz, _, err := queryFunc("/cosmos.tx.v1beta1.Service/Simulate", txBytes) if err != nil { return tx.SimulateResponse{}, 0, err From 5b216d0a6e8207a2b2c7e3a74508da84efdb5cd9 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 29 Oct 2020 12:05:40 +0100 Subject: [PATCH 19/20] Fix lint --- x/auth/tx/service.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 4c8d1c7d1777..9bca0b509c4f 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -94,7 +93,7 @@ func (s txServer) GetTx(ctx context.Context, req *txtypes.GetTxRequest) (*txtype // RegisterTxService registers the tx service on the gRPC router. func RegisterTxService( - qrt *baseapp.GRPCQueryRouter, + qrt gogogrpc.Server, clientCtx client.Context, simulateFn baseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry, From 2c6f627376f18731a71fe8117c329f16288d7f09 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 29 Oct 2020 20:03:53 +0100 Subject: [PATCH 20/20] Update x/auth/tx/service.go Co-authored-by: Aleksandr Bezobchuk --- x/auth/tx/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 9bca0b509c4f..d430dc2b0a38 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -81,8 +81,8 @@ func (s txServer) GetTx(ctx context.Context, req *txtypes.GetTxRequest) (*txtype // Create a proto codec, we need it to unmarshal the tx bytes. cdc := codec.NewProtoCodec(s.clientCtx.InterfaceRegistry) var protoTx txtypes.Tx - err = cdc.UnmarshalBinaryBare(result.Tx, &protoTx) - if err != nil { + + if err := cdc.UnmarshalBinaryBare(result.Tx, &protoTx); err != nil { return nil, err }