diff --git a/client/base_client.go b/client/base_client.go index 1c4ef74..437f06d 100644 --- a/client/base_client.go +++ b/client/base_client.go @@ -17,6 +17,7 @@ import ( "github.com/tendermint/tendermint/libs/log" rpcclient "github.com/tendermint/tendermint/rpc/client" + clientTx "github.com/irisnet/core-sdk-go/client/tx" "github.com/irisnet/core-sdk-go/common" commoncache "github.com/irisnet/core-sdk-go/common/cache" commoncodec "github.com/irisnet/core-sdk-go/common/codec" @@ -170,6 +171,18 @@ func (base *baseClient) BuildAndSend(msg []sdktypes.Msg, baseTx sdktypes.BaseTx) if e != nil { return e } + + // TODO 下面判断和返回的逻辑应该放到 broadcastTx 中,broadcastTx 传入的 ctx 是 Factory + // 判断是模拟交易返回计算的 gas 费,不在链上执行 + if ctx.SimulateAndExecute() { + res = sdktypes.ResultTx{ + GasWanted: int64(ctx.Gas()), + GasUsed: 0, + Data: txByte, + } + return nil + } + if res, e = base.broadcastTx(txByte, ctx.Mode()); e != nil { address = ctx.Address() return e @@ -338,8 +351,8 @@ func (base baseClient) QueryStore(key sdktypes.HexBytes, storeName string, heigh return resp, nil } -func (base *baseClient) prepare(baseTx sdktypes.BaseTx) (*sdktypes.Factory, error) { - factory := sdktypes.NewFactory(). +func (base *baseClient) prepare(baseTx sdktypes.BaseTx) (*clientTx.Factory, error) { + factory := clientTx.NewFactory(). WithChainID(base.cfg.ChainID). WithKeyManager(base.AccountQuery.Km). WithMode(base.cfg.Mode). @@ -411,8 +424,8 @@ func (base *baseClient) prepare(baseTx sdktypes.BaseTx) (*sdktypes.Factory, erro return factory, nil } -func (base *baseClient) prepareWithAccount(addr string, accountNumber, sequence uint64, baseTx sdktypes.BaseTx) (*sdktypes.Factory, error) { - factory := sdktypes.NewFactory(). +func (base *baseClient) prepareWithAccount(addr string, accountNumber, sequence uint64, baseTx sdktypes.BaseTx) (*clientTx.Factory, error) { + factory := clientTx.NewFactory(). WithChainID(base.cfg.ChainID). WithKeyManager(base.AccountQuery.Km). WithMode(base.cfg.Mode). diff --git a/client/tx.go b/client/tx.go index 86a2f15..4c94556 100644 --- a/client/tx.go +++ b/client/tx.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" "errors" + clientTx "github.com/irisnet/core-sdk-go/client/tx" "strings" "time" @@ -100,7 +101,7 @@ func (base baseClient) EstimateTxGas(txBytes []byte) (uint64, error) { return adjusted, nil } -func (base *baseClient) buildTx(msgs []sdk.Msg, baseTx sdk.BaseTx) ([]byte, *sdk.Factory, sdk.Error) { +func (base *baseClient) buildTx(msgs []sdk.Msg, baseTx sdk.BaseTx) ([]byte, *clientTx.Factory, sdk.Error) { builder, err := base.prepare(baseTx) if err != nil { return nil, builder, sdk.Wrap(err) @@ -113,7 +114,7 @@ func (base *baseClient) buildTx(msgs []sdk.Msg, baseTx sdk.BaseTx) ([]byte, *sdk return txByte, builder, nil } -func (base *baseClient) buildTxWithAccount(addr string, accountNumber, sequence uint64, msgs []sdk.Msg, baseTx sdk.BaseTx) ([]byte, *sdk.Factory, sdk.Error) { +func (base *baseClient) buildTxWithAccount(addr string, accountNumber, sequence uint64, msgs []sdk.Msg, baseTx sdk.BaseTx) ([]byte, *clientTx.Factory, sdk.Error) { builder, err := base.prepareWithAccount(addr, accountNumber, sequence, baseTx) if err != nil { return nil, builder, sdk.Wrap(err) diff --git a/types/factory.go b/client/tx/factory.go similarity index 64% rename from types/factory.go rename to client/tx/factory.go index 9f281de..a0e279c 100644 --- a/types/factory.go +++ b/client/tx/factory.go @@ -1,8 +1,12 @@ -package types +package tx import ( "errors" "fmt" + codecTypes "github.com/irisnet/core-sdk-go/common/codec/types" + "github.com/irisnet/core-sdk-go/common/crypto/keys/sm2" + "github.com/irisnet/core-sdk-go/types" + "github.com/irisnet/core-sdk-go/types/tx" "github.com/irisnet/core-sdk-go/types/tx/signing" ) @@ -21,15 +25,15 @@ type ( gas uint64 gasAdjustment float64 simulateAndExecute bool - fees Coins - feeGranter AccAddress - feePayer AccAddress - gasPrices DecCoins - mode BroadcastMode + fees types.Coins + feeGranter types.AccAddress + feePayer types.AccAddress + gasPrices types.DecCoins + mode types.BroadcastMode signMode signing.SignMode - signModeHandler SignModeHandler - keyManager KeyManager - txConfig TxConfig + signModeHandler types.SignModeHandler + keyManager types.KeyManager + txConfig types.TxConfig queryFunc QueryWithData } @@ -52,7 +56,7 @@ func (f *Factory) Gas() uint64 { return f.gas } func (f Factory) GasAdjustment() float64 { return f.gasAdjustment } // Fees returns the fee of the transaction. -func (f *Factory) Fees() Coins { return f.fees } +func (f *Factory) Fees() types.Coins { return f.fees } // Sequence returns the sequence of the account. func (f *Factory) Sequence() uint64 { return f.sequence } @@ -64,10 +68,10 @@ func (f *Factory) Memo() string { return f.memo } func (f *Factory) AccountNumber() uint64 { return f.accountNumber } // KeyManager returns keyManager. -func (f *Factory) KeyManager() KeyManager { return f.keyManager } +func (f *Factory) KeyManager() types.KeyManager { return f.keyManager } // Mode returns mode. -func (f *Factory) Mode() BroadcastMode { return f.mode } +func (f *Factory) Mode() types.BroadcastMode { return f.mode } // SimulateAndExecute returns the option to simulateAndExecute and then execute the transaction // using the gas from the simulation results @@ -98,19 +102,19 @@ func (f *Factory) WithGasAdjustment(gasAdjustment float64) *Factory { } // WithFee returns a pointer of the context with an updated Fee. -func (f *Factory) WithFee(fee Coins) *Factory { +func (f *Factory) WithFee(fee types.Coins) *Factory { f.fees = fee return f } // WithFeeGranter returns a pointer of the context with an updated FeeGranter. -func (f *Factory) WithFeeGranter(feeGranter AccAddress) *Factory { +func (f *Factory) WithFeeGranter(feeGranter types.AccAddress) *Factory { f.feeGranter = feeGranter return f } // WithFeePayer returns a pointer of the context with an updated FeePayer. -func (f *Factory) WithFeePayer(feePayer AccAddress) *Factory { +func (f *Factory) WithFeePayer(feePayer types.AccAddress) *Factory { f.feePayer = feePayer return f } @@ -133,14 +137,14 @@ func (f *Factory) WithAccountNumber(accnum uint64) *Factory { return f } -// WithKeyManager returns a pointer of the context with a KeyManager. -func (f *Factory) WithKeyManager(keyManager KeyManager) *Factory { +// WithKeyManager returns a pointer of the context with a types.KeyManager. +func (f *Factory) WithKeyManager(keyManager types.KeyManager) *Factory { f.keyManager = keyManager return f } // WithMode returns a pointer of the context with a Mode. -func (f *Factory) WithMode(mode BroadcastMode) *Factory { +func (f *Factory) WithMode(mode types.BroadcastMode) *Factory { f.mode = mode return f } @@ -163,14 +167,14 @@ func (f *Factory) WithAddress(address string) *Factory { return f } -// WithTxConfig returns a pointer of the context with an TxConfig -func (f *Factory) WithTxConfig(txConfig TxConfig) *Factory { +// WithTxConfig returns a pointer of the context with an types.TxConfig +func (f *Factory) WithTxConfig(txConfig types.TxConfig) *Factory { f.txConfig = txConfig return f } // WithSignModeHandler returns a pointer of the context with an signModeHandler. -func (f *Factory) WithSignModeHandler(signModeHandler SignModeHandler) *Factory { +func (f *Factory) WithSignModeHandler(signModeHandler types.SignModeHandler) *Factory { f.signModeHandler = signModeHandler return f } @@ -187,7 +191,22 @@ func (f *Factory) WithTimeout(height uint64) *Factory { return f } -func (f *Factory) BuildAndSign(name string, msgs []Msg, json bool) ([]byte, error) { +func (f *Factory) BuildAndSign(name string, msgs []Msg, json bool) ([]byte, error) { if f.SimulateAndExecute() { + _, adjusted, err := f.CalculateGas(msgs...) + if err != nil { + return nil, err + } + f.WithGas(adjusted) + + // TODO 设置计算出的费用。下面这个就不用了,因为在 broadcastTx 直接就返回了,不会执行和扣费 + //fee, _ := types.ParseDecCoins(fmt.Sprintf("%dugas", adjusted)) + //fees, err := toMinCoin(fee...) + //if err != nil { + // return nil, err + //} + //f.WithFee(fees) + } + tx, err := f.BuildUnsignedTx(msgs) if err != nil { return nil, err @@ -213,7 +232,7 @@ func (f *Factory) BuildAndSign(name string, msgs []Msg, json bool) ([]byte, erro return txBytes, nil } -func (f *Factory) BuildUnsignedTx(msgs []Msg) (TxBuilder, error) { +func (f *Factory) BuildUnsignedTx(msgs []types.Msg) (types.TxBuilder, error) { if f.chainID == "" { return nil, fmt.Errorf("chain ID required but not specified") } @@ -225,15 +244,15 @@ func (f *Factory) BuildUnsignedTx(msgs []Msg) (TxBuilder, error) { return nil, errors.New("cannot provide both fees and gas prices") } - glDec := NewDec(int64(f.gas)) + glDec := types.NewDec(int64(f.gas)) // Derive the fees based on the provided gas prices, where // fee = ceil(gasPrice * gasLimit). - fees = make(Coins, len(f.gasPrices)) + fees = make(types.Coins, len(f.gasPrices)) for i, gp := range f.gasPrices { fee := gp.Amount.Mul(glDec) - fees[i] = NewCoin(gp.Denom, fee.Ceil().RoundInt()) + fees[i] = types.NewCoin(gp.Denom, fee.Ceil().RoundInt()) } } @@ -254,15 +273,75 @@ func (f *Factory) BuildUnsignedTx(msgs []Msg) (TxBuilder, error) { return tx, nil } +// BuildSimTx creates an unsigned tx with an empty single signature and returns +// the encoded transaction or an error if the unsigned transaction cannot be +// built. +func (f *Factory) BuildSimTx(msgs ...types.Msg) ([]byte, error) { + txb, err := f.BuildUnsignedTx(msgs) + if err != nil { + return nil, err + } + + // Create an empty signature literal as the ante handler will populate with a + // sentinel pubkey. + sig := signing.SignatureV2{ + PubKey: &sm2.PubKey{}, + Data: &signing.SingleSignatureData{ + SignMode: f.signMode, + }, + Sequence: f.Sequence(), + } + + if err := txb.SetSignatures(sig); err != nil { + return nil, err + } + + any, ok := txb.(codecTypes.IntoAny) + if !ok { + return nil, fmt.Errorf("cannot simulateAndExecute tx that cannot be wrapped into any") + } + cached := any.AsAny().GetCachedValue() + protoTx, ok := cached.(*tx.Tx) + if !ok { + return nil, fmt.Errorf("cannot simulateAndExecute amino tx") + } + + simReq := tx.SimulateRequest{Tx: protoTx} + + return simReq.Marshal() +} + +// CalculateGas simulates the execution of a transaction and returns the +// simulation response obtained by the query and the adjusted gas amount. +func (f *Factory) CalculateGas(msgs ...types.Msg) (tx.SimulateResponse, uint64, error) { + txBytes, err := f.BuildSimTx(msgs...) + if err != nil { + return tx.SimulateResponse{}, 0, err + } + + bz, _, err := f.queryFunc("/cosmos.tx.v1beta1.Service/Simulate", txBytes) + if err != nil { + return tx.SimulateResponse{}, 0, err + } + + var simRes tx.SimulateResponse + + if err := simRes.Unmarshal(bz); err != nil { + return tx.SimulateResponse{}, 0, err + } + + return simRes, uint64(f.GasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil +} + // Sign signs a transaction given a name, passphrase, and a single message to // signed. An error is returned if signing fails. -func (f *Factory) Sign(name string, txBuilder TxBuilder) error { +func (f *Factory) Sign(name string, txBuilder types.TxBuilder) error { signMode := f.signMode if signMode == signing.SignMode_SIGN_MODE_UNSPECIFIED { // use the SignModeHandler's default mode if unspecified signMode = f.txConfig.SignModeHandler().DefaultMode() } - signerData := SignerData{ + signerData := types.SignerData{ ChainID: f.chainID, AccountNumber: f.accountNumber, Sequence: f.sequence, @@ -320,3 +399,14 @@ func (f *Factory) Sign(name string, txBuilder TxBuilder) error { // And here the tx is populated with the signature return txBuilder.SetSignatures(sig) } + +func toMinCoin(coins ...types.DecCoin) (types.Coins, types.Error) { + for i := range coins { + if coins[i].Denom == "iris" { + coins[i].Denom = "uiris" + coins[i].Amount = coins[i].Amount.MulInt(types.NewIntWithDecimal(1, 6)) + } + } + ucoins, _ := types.DecCoins(coins).TruncateDecimal() + return ucoins, nil +} diff --git a/proto/cosmos/base/simulate/v1beta1/simlate.proto b/proto/cosmos/base/simulate/v1beta1/simlate.proto new file mode 100644 index 0000000..05b407a --- /dev/null +++ b/proto/cosmos/base/simulate/v1beta1/simlate.proto @@ -0,0 +1,33 @@ +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/bianjieai/core-sdk-go/types"; + +// 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; +} \ No newline at end of file diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go new file mode 100644 index 0000000..8c6fd3b --- /dev/null +++ b/types/tx/service.pb.go @@ -0,0 +1,671 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: service.proto + +package tx + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + types "github.com/irisnet/core-sdk-go/types" + _ "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 `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_a0b84a42fa06f626, []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 +// 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_a0b84a42fa06f626, []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("service.proto", fileDescriptor_a0b84a42fa06f626) } + +var fileDescriptor_a0b84a42fa06f626 = []byte{ + // 355 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x4b, 0xc3, 0x40, + 0x14, 0xc7, 0x7b, 0x19, 0x6a, 0x89, 0x88, 0x12, 0x10, 0x4a, 0x28, 0xa1, 0x46, 0x94, 0x3a, 0xf4, + 0x8e, 0xd6, 0xa5, 0x83, 0x93, 0x0e, 0xe2, 0x9a, 0x3a, 0xb9, 0xc8, 0x25, 0x5e, 0xe3, 0x69, 0x9b, + 0x17, 0x73, 0x2f, 0x25, 0xae, 0x8e, 0x4e, 0x82, 0x93, 0x1f, 0xc2, 0xef, 0xe1, 0x58, 0x70, 0x71, + 0x94, 0xd6, 0x0f, 0x22, 0x4d, 0x2e, 0x6d, 0x11, 0x14, 0xb7, 0xe4, 0xbd, 0xff, 0xef, 0xdd, 0x7b, + 0xff, 0xbf, 0xb9, 0xa1, 0x44, 0x32, 0x96, 0x81, 0xa0, 0x71, 0x02, 0x08, 0x56, 0x23, 0x00, 0x35, + 0x02, 0x45, 0x7d, 0xae, 0x04, 0x55, 0x72, 0x94, 0x0e, 0x39, 0x0a, 0x3a, 0xee, 0xf8, 0x02, 0x79, + 0xc7, 0x6e, 0x84, 0x00, 0xe1, 0x50, 0x30, 0x1e, 0x4b, 0xc6, 0xa3, 0x08, 0x90, 0xa3, 0x84, 0x48, + 0x15, 0xac, 0xbd, 0x5b, 0xb0, 0x6c, 0xce, 0x32, 0xee, 0x07, 0x92, 0x69, 0x2e, 0xff, 0xd1, 0x22, + 0x5b, 0x8b, 0x30, 0x5b, 0x74, 0x31, 0x2b, 0x7a, 0x6e, 0xcf, 0xdc, 0xec, 0xeb, 0x27, 0x3d, 0x71, + 0x97, 0x0a, 0x85, 0xd6, 0x9e, 0x69, 0x60, 0x56, 0x27, 0x4d, 0xd2, 0x5a, 0xef, 0x6e, 0x53, 0xbd, + 0x1c, 0x66, 0xe5, 0x46, 0xf4, 0x3c, 0xf3, 0x0c, 0xcc, 0xdc, 0x47, 0x62, 0x6e, 0x2d, 0x51, 0x15, + 0x43, 0xa4, 0x84, 0x75, 0x64, 0xd6, 0x42, 0xae, 0x2e, 0x65, 0x34, 0x00, 0x3d, 0x61, 0x87, 0xae, + 0x9e, 0x97, 0x6f, 0x55, 0x0e, 0x3a, 0xe5, 0xea, 0x2c, 0x1a, 0x80, 0xb7, 0x16, 0x16, 0x1f, 0x56, + 0xcf, 0xac, 0x26, 0x42, 0xa5, 0x43, 0xac, 0x1b, 0x39, 0xdb, 0xfc, 0x9d, 0xf5, 0x72, 0x9d, 0xa7, + 0xf5, 0xdd, 0x57, 0xb2, 0xbc, 0xa3, 0x5f, 0xb8, 0x6b, 0xbd, 0x10, 0xb3, 0x56, 0xd6, 0xac, 0x36, + 0xfd, 0xcb, 0x65, 0xfa, 0xc3, 0x03, 0x9b, 0xfe, 0x57, 0x5e, 0xdc, 0xed, 0xd2, 0x87, 0xf7, 0xaf, + 0x67, 0xa3, 0xe5, 0xee, 0xb3, 0xd5, 0x40, 0x4a, 0x6e, 0x61, 0x7b, 0x59, 0x38, 0x3e, 0x79, 0x9b, + 0x3a, 0x64, 0x32, 0x75, 0xc8, 0xe7, 0xd4, 0x21, 0x4f, 0x33, 0xa7, 0x32, 0x99, 0x39, 0x95, 0x8f, + 0x99, 0x53, 0xb9, 0x38, 0x08, 0x25, 0x5e, 0xa7, 0x3e, 0x0d, 0x60, 0xc4, 0x7c, 0xc9, 0xa3, 0x1b, + 0x29, 0xb8, 0x64, 0x01, 0x24, 0xa2, 0xad, 0xae, 0x6e, 0xdb, 0x21, 0x30, 0xbc, 0x8f, 0xc5, 0x3c, + 0x4c, 0xbf, 0x9a, 0x47, 0x78, 0xf8, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xb6, 0x5f, 0x4b, 0x4f, 0x50, + 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: "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 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 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) || (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) || (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") +)