From 6a1a3450df442bc10c82f38e007519ef463023d9 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 13:29:50 -0400 Subject: [PATCH 01/54] Add Tx, SignDoc from #6111 to types/types.proto, refactor Tx -> TxI and Fee -> FeeI --- baseapp/baseapp.go | 2 +- baseapp/baseapp_test.go | 16 +- baseapp/helpers.go | 6 +- client/tx/tx.go | 6 +- server/mock/tx.go | 6 +- std/tx.go | 6 +- tests/mocks/types_handler.go | 2 +- types/codec.go | 2 +- types/config_test.go | 4 +- types/handler.go | 8 +- types/handler_test.go | 2 +- types/result.go | 4 +- types/result_test.go | 8 +- types/tx_msg.go | 10 +- types/types.pb.go | 4254 +++++++++++++++++++++++++++----- types/types.proto | 112 + x/auth/ante/ante_test.go | 28 +- x/auth/ante/basic.go | 8 +- x/auth/ante/fee.go | 6 +- x/auth/ante/setup.go | 4 +- x/auth/ante/setup_test.go | 4 +- x/auth/ante/sigverify.go | 12 +- x/auth/client/query.go | 2 +- x/auth/client/tx_test.go | 2 +- x/auth/types/stdtx.go | 8 +- x/auth/types/test_utils.go | 6 +- x/genutil/client/rest/query.go | 2 +- x/ibc/ante/ante.go | 2 +- x/ibc/ante/ante_test.go | 2 +- 29 files changed, 3767 insertions(+), 767 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index e9d0d2baa087..976ac1f525ee 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -467,7 +467,7 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context // Note, gas execution info is always returned. A reference to a Result is // returned if the tx does not run out of gas and if all the messages are valid // and execute successfully. An error is returned otherwise. -func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, err error) { +func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.TxI) (gInfo sdk.GasInfo, result *sdk.Result, err error) { // NOTE: GasWanted should be returned by the AnteHandler. GasUsed is // determined by the GasMeter. We need access to the context to get the gas // meter so we initialize upfront. diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 79d6cb5f5ab5..75c76b29df95 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -648,7 +648,7 @@ func (msg msgCounter2) ValidateBasic() error { // amino decode func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { - return func(txBytes []byte) (sdk.Tx, error) { + return func(txBytes []byte) (sdk.TxI, error) { var tx txTest if len(txBytes) == 0 { return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty") @@ -664,7 +664,7 @@ func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { } func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler { - return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + return func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithEventManager(sdk.NewEventManager()) store := newCtx.KVStore(capKey) txTest := tx.(txTest) @@ -942,7 +942,7 @@ func TestSimulateTx(t *testing.T) { gasConsumed := uint64(5) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasConsumed)) return }) @@ -1008,7 +1008,7 @@ func TestSimulateTx(t *testing.T) { func TestRunInvalidTransaction(t *testing.T) { anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { return }) } @@ -1111,7 +1111,7 @@ func TestRunInvalidTransaction(t *testing.T) { func TestTxGasLimits(t *testing.T) { gasGranted := uint64(10) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) // AnteHandlers must have their own defer/recover in order for the BaseApp @@ -1199,7 +1199,7 @@ func TestTxGasLimits(t *testing.T) { func TestMaxBlockGasLimits(t *testing.T) { gasGranted := uint64(10) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) defer func() { @@ -1368,7 +1368,7 @@ func TestBaseAppAnteHandler(t *testing.T) { func TestGasConsumptionBadTx(t *testing.T) { gasWanted := uint64(5) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasWanted)) defer func() { @@ -1439,7 +1439,7 @@ func TestGasConsumptionBadTx(t *testing.T) { func TestQuery(t *testing.T) { key, value := []byte("hello"), []byte("goodbye") anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { store := ctx.KVStore(capKey1) store.Set(key, value) return diff --git a/baseapp/helpers.go b/baseapp/helpers.go index 085d6b4ed642..b8ca928406cf 100644 --- a/baseapp/helpers.go +++ b/baseapp/helpers.go @@ -10,15 +10,15 @@ import ( var isAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString -func (app *BaseApp) Check(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) Check(tx sdk.TxI) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeCheck, nil, tx) } -func (app *BaseApp) Simulate(txBytes []byte, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) Simulate(txBytes []byte, tx sdk.TxI) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeSimulate, txBytes, tx) } -func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) Deliver(tx sdk.TxI) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeDeliver, nil, tx) } diff --git a/client/tx/tx.go b/client/tx/tx.go index 7ae89d0aff53..f87a135586f3 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -32,7 +32,7 @@ type ( } ClientFee interface { - sdk.Fee + sdk.FeeI SetGas(uint64) SetAmount(sdk.Coins) } @@ -48,13 +48,13 @@ type ( // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. ClientTx interface { - sdk.Tx + sdk.TxI codec.ProtoMarshaler SetMsgs(...sdk.Msg) error GetSignatures() []sdk.Signature SetSignatures(...ClientSignature) error - GetFee() sdk.Fee + GetFee() sdk.FeeI SetFee(ClientFee) error GetMemo() string SetMemo(string) diff --git a/server/mock/tx.go b/server/mock/tx.go index 27441051ce8a..beec27133a01 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -16,7 +16,7 @@ type kvstoreTx struct { bytes []byte } -var _ sdk.Tx = kvstoreTx{} +var _ sdk.TxI = kvstoreTx{} func NewTx(key, value string) kvstoreTx { bytes := fmt.Sprintf("%s=%s", key, value) @@ -58,8 +58,8 @@ func (tx kvstoreTx) GetSigners() []sdk.AccAddress { // takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has // all the signatures and can be used to authenticate. -func decodeTx(txBytes []byte) (sdk.Tx, error) { - var tx sdk.Tx +func decodeTx(txBytes []byte) (sdk.TxI, error) { + var tx sdk.TxI split := bytes.Split(txBytes, []byte("=")) if len(split) == 1 { diff --git a/std/tx.go b/std/tx.go index 8b922f637938..a6f709eb56cf 100644 --- a/std/tx.go +++ b/std/tx.go @@ -1,7 +1,7 @@ package std import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto" clientx "github.com/cosmos/cosmos-sdk/client/tx" @@ -11,7 +11,7 @@ import ( ) var ( - _ sdk.Tx = (*Transaction)(nil) + _ sdk.TxI = (*Transaction)(nil) _ clientx.ClientTx = (*Transaction)(nil) _ clientx.Generator = TxGenerator{} _ clientx.ClientFee = &StdFee{} @@ -147,7 +147,7 @@ func (tx *Transaction) SetSignatures(sdkSigs ...clientx.ClientSignature) error { } // GetFee returns the transaction's fee. -func (tx Transaction) GetFee() sdk.Fee { +func (tx Transaction) GetFee() sdk.FeeI { return tx.Fee } diff --git a/tests/mocks/types_handler.go b/tests/mocks/types_handler.go index da80614ae884..4025236a5c91 100644 --- a/tests/mocks/types_handler.go +++ b/tests/mocks/types_handler.go @@ -34,7 +34,7 @@ func (m *MockAnteDecorator) EXPECT() *MockAnteDecoratorMockRecorder { } // AnteHandle mocks base method -func (m *MockAnteDecorator) AnteHandle(ctx types.Context, tx types.Tx, simulate bool, next types.AnteHandler) (types.Context, error) { +func (m *MockAnteDecorator) AnteHandle(ctx types.Context, tx types.TxI, simulate bool, next types.AnteHandler) (types.Context, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AnteHandle", ctx, tx, simulate, next) ret0, _ := ret[0].(types.Context) diff --git a/types/codec.go b/types/codec.go index c00d95b2ee84..65e9b6e084ad 100644 --- a/types/codec.go +++ b/types/codec.go @@ -11,7 +11,7 @@ import ( // Register the sdk message type func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*Msg)(nil), nil) - cdc.RegisterInterface((*Tx)(nil), nil) + cdc.RegisterInterface((*TxI)(nil), nil) } // Register the sdk message type diff --git a/types/config_test.go b/types/config_test.go index df208e32f361..512ed107c99c 100644 --- a/types/config_test.go +++ b/types/config_test.go @@ -24,9 +24,9 @@ func TestConfig_SetTxEncoder(t *testing.T) { mockErr := errors.New("test") config := sdk.NewConfig() require.Nil(t, config.GetTxEncoder()) - encFunc := sdk.TxEncoder(func(tx sdk.Tx) ([]byte, error) { return nil, nil }) + encFunc := sdk.TxEncoder(func(tx sdk.TxI) ([]byte, error) { return nil, nil }) config.SetTxEncoder(encFunc) - _, err := config.GetTxEncoder()(sdk.Tx(nil)) + _, err := config.GetTxEncoder()(sdk.TxI(nil)) require.Error(t, mockErr, err) config.Seal() diff --git a/types/handler.go b/types/handler.go index 03d1f02d5806..62e6072fb34e 100644 --- a/types/handler.go +++ b/types/handler.go @@ -5,11 +5,11 @@ type Handler func(ctx Context, msg Msg) (*Result, error) // AnteHandler authenticates transactions, before their internal messages are handled. // If newCtx.IsZero(), ctx is used instead. -type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, err error) +type AnteHandler func(ctx Context, tx TxI, simulate bool) (newCtx Context, err error) // AnteDecorator wraps the next AnteHandler to perform custom pre- and post-processing. type AnteDecorator interface { - AnteHandle(ctx Context, tx Tx, simulate bool, next AnteHandler) (newCtx Context, err error) + AnteHandle(ctx Context, tx TxI, simulate bool, next AnteHandler) (newCtx Context, err error) } // ChainDecorator chains AnteDecorators together with each AnteDecorator @@ -36,7 +36,7 @@ func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler { chain = append(chain, Terminator{}) } - return func(ctx Context, tx Tx, simulate bool) (Context, error) { + return func(ctx Context, tx TxI, simulate bool) (Context, error) { return chain[0].AnteHandle(ctx, tx, simulate, ChainAnteDecorators(chain[1:]...)) } } @@ -61,6 +61,6 @@ func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler { type Terminator struct{} // Simply return provided Context and nil error -func (t Terminator) AnteHandle(ctx Context, _ Tx, _ bool, _ AnteHandler) (Context, error) { +func (t Terminator) AnteHandle(ctx Context, _ TxI, _ bool, _ AnteHandler) (Context, error) { return ctx, nil } diff --git a/types/handler_test.go b/types/handler_test.go index 670da2fccb55..0470954009b1 100644 --- a/types/handler_test.go +++ b/types/handler_test.go @@ -15,7 +15,7 @@ func TestChainAnteDecorators(t *testing.T) { // test panic require.Nil(t, sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...)) - ctx, tx := sdk.Context{}, sdk.Tx(nil) + ctx, tx := sdk.Context{}, sdk.TxI(nil) mockCtrl := gomock.NewController(t) mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl) mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1) diff --git a/types/result.go b/types/result.go index 41fad03b0cff..f7cc38d00443 100644 --- a/types/result.go +++ b/types/result.go @@ -79,12 +79,12 @@ type TxResponse struct { Info string `json:"info,omitempty"` GasWanted int64 `json:"gas_wanted,omitempty"` GasUsed int64 `json:"gas_used,omitempty"` - Tx Tx `json:"tx,omitempty"` + Tx TxI `json:"tx,omitempty"` Timestamp string `json:"timestamp,omitempty"` } // NewResponseResultTx returns a TxResponse given a ResultTx from tendermint -func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) TxResponse { +func NewResponseResultTx(res *ctypes.ResultTx, tx TxI, timestamp string) TxResponse { if res == nil { return TxResponse{} } diff --git a/types/result_test.go b/types/result_test.go index 70f7d98fbbdb..06af4e12db6b 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -91,12 +91,12 @@ func TestResponseResultTx(t *testing.T) { Info: "info", GasWanted: 100, GasUsed: 90, - Tx: sdk.Tx(nil), + Tx: sdk.TxI(nil), Timestamp: "timestamp", } - require.Equal(t, want, sdk.NewResponseResultTx(resultTx, sdk.Tx(nil), "timestamp")) - require.Equal(t, sdk.TxResponse{}, sdk.NewResponseResultTx(nil, sdk.Tx(nil), "timestamp")) + require.Equal(t, want, sdk.NewResponseResultTx(resultTx, sdk.TxI(nil), "timestamp")) + require.Equal(t, sdk.TxResponse{}, sdk.NewResponseResultTx(nil, sdk.TxI(nil), "timestamp")) require.Equal(t, `Response: Height: 10 TxHash: 74657374 @@ -108,7 +108,7 @@ func TestResponseResultTx(t *testing.T) { GasWanted: 100 GasUsed: 90 Codespace: codespace - Timestamp: timestamp`, sdk.NewResponseResultTx(resultTx, sdk.Tx(nil), "timestamp").String()) + Timestamp: timestamp`, sdk.NewResponseResultTx(resultTx, sdk.TxI(nil), "timestamp").String()) require.True(t, sdk.TxResponse{}.Empty()) require.False(t, want.Empty()) diff --git a/types/tx_msg.go b/types/tx_msg.go index 9123cd9be94a..7eac35522c48 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -31,9 +31,9 @@ type ( GetSigners() []AccAddress } - // Fee defines an interface for an application application-defined concrete + // FeeI defines an interface for an application application-defined concrete // transaction type to be able to set and return the transaction fee. - Fee interface { + FeeI interface { GetGas() uint64 GetAmount() Coins } @@ -46,7 +46,7 @@ type ( } // Tx defines the interface a transaction must fulfill. - Tx interface { + TxI interface { // Gets the all the transaction's messages. GetMsgs() []Msg @@ -57,10 +57,10 @@ type ( ) // TxDecoder unmarshals transaction bytes -type TxDecoder func(txBytes []byte) (Tx, error) +type TxDecoder func(txBytes []byte) (TxI, error) // TxEncoder marshals transaction to bytes -type TxEncoder func(tx Tx) ([]byte, error) +type TxEncoder func(tx TxI) ([]byte, error) //__________________________________________________________ diff --git a/types/types.pb.go b/types/types.pb.go index 6b4d9813ab5f..01184a4d631b 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + types1 "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/tendermint/tendermint/abci/types" @@ -26,6 +27,37 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type SignMode int32 + +const ( + SignMode_SIGN_MODE_UNSPECIFIED SignMode = 0 + SignMode_SIGN_MODE_DIRECT SignMode = 1 + SignMode_SIGN_MODE_TEXTUAL SignMode = 2 + SignMode_SIGN_MODE_LEGACY_AMINO_JSON SignMode = 127 +) + +var SignMode_name = map[int32]string{ + 0: "SIGN_MODE_UNSPECIFIED", + 1: "SIGN_MODE_DIRECT", + 2: "SIGN_MODE_TEXTUAL", + 127: "SIGN_MODE_LEGACY_AMINO_JSON", +} + +var SignMode_value = map[string]int32{ + "SIGN_MODE_UNSPECIFIED": 0, + "SIGN_MODE_DIRECT": 1, + "SIGN_MODE_TEXTUAL": 2, + "SIGN_MODE_LEGACY_AMINO_JSON": 127, +} + +func (x SignMode) String() string { + return proto.EnumName(SignMode_name, int32(x)) +} + +func (SignMode) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{0} +} + // Coin defines a token with a denomination and an amount. // // NOTE: The amount field is an Int which implements the custom method @@ -384,574 +416,3343 @@ func (m *SimulationResponse) GetResult() *Result { return nil } -func init() { - proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin") - proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin") - proto.RegisterType((*IntProto)(nil), "cosmos_sdk.v1.IntProto") - proto.RegisterType((*DecProto)(nil), "cosmos_sdk.v1.DecProto") - proto.RegisterType((*ValAddresses)(nil), "cosmos_sdk.v1.ValAddresses") - proto.RegisterType((*GasInfo)(nil), "cosmos_sdk.v1.GasInfo") - proto.RegisterType((*Result)(nil), "cosmos_sdk.v1.Result") - proto.RegisterType((*SimulationResponse)(nil), "cosmos_sdk.v1.SimulationResponse") +type Tx struct { + Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` + AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` + Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` } -func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } - -var fileDescriptor_2c0f90c600ad7e2e = []byte{ - // 534 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4f, 0x6f, 0xd3, 0x4e, - 0x10, 0xb5, 0x7f, 0xf6, 0x2f, 0x7f, 0x36, 0xe1, 0x4f, 0x17, 0x8a, 0xa2, 0x0a, 0xec, 0xc8, 0x48, - 0x28, 0x48, 0xd4, 0x16, 0x29, 0xa7, 0x70, 0xc2, 0x04, 0x55, 0xe1, 0x84, 0x16, 0x01, 0x12, 0x97, - 0x68, 0xe3, 0xdd, 0xba, 0x56, 0xe3, 0xdd, 0xc8, 0xbb, 0x29, 0xca, 0x2d, 0x47, 0x8e, 0x7c, 0x84, - 0x7e, 0x9c, 0x1e, 0x73, 0xac, 0x10, 0xb2, 0x20, 0xb9, 0x70, 0xee, 0x91, 0x13, 0xda, 0xb5, 0xc1, - 0x6a, 0x7a, 0xe3, 0x92, 0xcc, 0xce, 0xbc, 0x79, 0x33, 0xf3, 0xfc, 0xc0, 0x8e, 0x5c, 0xcc, 0xa8, - 0x08, 0xf4, 0xaf, 0x3f, 0xcb, 0xb8, 0xe4, 0xf0, 0x46, 0xc4, 0x45, 0xca, 0xc5, 0x58, 0x90, 0x13, - 0xff, 0xf4, 0xe9, 0xde, 0x23, 0x79, 0x9c, 0x64, 0x64, 0x3c, 0xc3, 0x99, 0x5c, 0x04, 0x1a, 0x11, - 0xc4, 0x3c, 0xe6, 0x55, 0x54, 0xb4, 0xed, 0x1d, 0x5c, 0xc7, 0x49, 0xca, 0x08, 0xcd, 0xd2, 0x84, - 0xc9, 0x00, 0x4f, 0xa2, 0x24, 0xb8, 0x36, 0xcb, 0x3b, 0x04, 0xf6, 0x4b, 0x9e, 0x30, 0x78, 0x17, - 0xfc, 0x4f, 0x28, 0xe3, 0x69, 0xc7, 0xec, 0x9a, 0xbd, 0x26, 0x2a, 0x1e, 0xf0, 0x21, 0xa8, 0xe1, - 0x94, 0xcf, 0x99, 0xec, 0xfc, 0xa7, 0xd2, 0x61, 0xeb, 0x3c, 0x77, 0x8d, 0xaf, 0xb9, 0x6b, 0x8d, - 0x98, 0x44, 0x65, 0x69, 0x60, 0xff, 0x3c, 0x73, 0x4d, 0xef, 0x35, 0xa8, 0x0f, 0x69, 0xf4, 0x2f, - 0x5c, 0x43, 0x1a, 0x6d, 0x71, 0x3d, 0x06, 0x8d, 0x11, 0x93, 0x6f, 0xb4, 0x18, 0x0f, 0x80, 0x95, - 0x30, 0x59, 0x50, 0x5d, 0x9d, 0xaf, 0xf2, 0x0a, 0x3a, 0xa4, 0xd1, 0x5f, 0x28, 0xa1, 0xd1, 0x36, - 0x54, 0xd1, 0xab, 0xbc, 0x17, 0x82, 0xf6, 0x7b, 0x3c, 0x7d, 0x41, 0x48, 0x46, 0x85, 0xa0, 0x02, - 0x3e, 0x01, 0x4d, 0xfc, 0xe7, 0xd1, 0x31, 0xbb, 0x56, 0xaf, 0x1d, 0xde, 0xfc, 0x95, 0xbb, 0xa0, - 0x02, 0xa1, 0x0a, 0x30, 0xb0, 0x97, 0xdf, 0xba, 0xa6, 0xc7, 0x41, 0xfd, 0x10, 0x8b, 0x11, 0x3b, - 0xe2, 0xf0, 0x19, 0x00, 0x31, 0x16, 0xe3, 0x4f, 0x98, 0x49, 0x4a, 0xf4, 0x50, 0x3b, 0xdc, 0xbd, - 0xcc, 0xdd, 0x9d, 0x05, 0x4e, 0xa7, 0x03, 0xaf, 0xaa, 0x79, 0xa8, 0x19, 0x63, 0xf1, 0x41, 0xc7, - 0xd0, 0x07, 0x0d, 0x55, 0x99, 0x0b, 0x4a, 0xb4, 0x0e, 0x76, 0x78, 0xe7, 0x32, 0x77, 0x6f, 0x55, - 0x3d, 0xaa, 0xe2, 0xa1, 0x7a, 0x8c, 0xc5, 0x3b, 0x15, 0xcd, 0x40, 0x0d, 0x51, 0x31, 0x9f, 0x4a, - 0x08, 0x81, 0x4d, 0xb0, 0xc4, 0x7a, 0x52, 0x1b, 0xe9, 0x18, 0xde, 0x06, 0xd6, 0x94, 0xc7, 0x85, - 0xa0, 0x48, 0x85, 0x70, 0x00, 0x6a, 0xf4, 0x94, 0x32, 0x29, 0x3a, 0x56, 0xd7, 0xea, 0xb5, 0xfa, - 0xf7, 0xfd, 0xca, 0x03, 0xbe, 0xf2, 0x80, 0x5f, 0x7c, 0xfd, 0x57, 0x0a, 0x14, 0xda, 0x4a, 0x24, - 0x54, 0x76, 0x0c, 0xec, 0xcf, 0x67, 0xae, 0xe1, 0x2d, 0x4d, 0x00, 0xdf, 0x26, 0xe9, 0x7c, 0x8a, - 0x65, 0xc2, 0x19, 0xa2, 0x62, 0xc6, 0x99, 0xa0, 0xf0, 0x79, 0xb1, 0x78, 0xc2, 0x8e, 0xb8, 0x5e, - 0xa1, 0xd5, 0xbf, 0xe7, 0x5f, 0xf1, 0xa9, 0x5f, 0x0a, 0x13, 0x36, 0x14, 0xe9, 0x2a, 0x77, 0x4d, - 0x7d, 0x85, 0xd6, 0x6a, 0x1f, 0xd4, 0x32, 0x7d, 0x85, 0x5e, 0xb5, 0xd5, 0xdf, 0xdd, 0x6a, 0x2d, - 0x4e, 0x44, 0x25, 0x28, 0x1c, 0x5e, 0xfc, 0x70, 0x8c, 0xe5, 0xda, 0x31, 0xce, 0xd7, 0x8e, 0xb9, - 0x5a, 0x3b, 0xe6, 0xf7, 0xb5, 0x63, 0x7e, 0xd9, 0x38, 0xc6, 0x6a, 0xe3, 0x18, 0x17, 0x1b, 0xc7, - 0xf8, 0xe8, 0xc5, 0x89, 0x3c, 0x9e, 0x4f, 0xfc, 0x88, 0xa7, 0x41, 0x41, 0x55, 0xfe, 0xed, 0x0b, - 0x72, 0x52, 0x18, 0x7c, 0x52, 0xd3, 0x0e, 0x3f, 0xf8, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x0e, 0xe8, - 0xc3, 0x0c, 0x62, 0x03, 0x00, 0x00, +func (m *Tx) Reset() { *m = Tx{} } +func (*Tx) ProtoMessage() {} +func (*Tx) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{8} } - -func (this *Coin) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Coin) - if !ok { - that2, ok := that.(Coin) - if ok { - that1 = &that2 - } else { - return false +func (m *Tx) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Tx) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Tx.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err } + return b[:n], nil } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Denom != that1.Denom { - return false - } - if !this.Amount.Equal(that1.Amount) { - return false - } - return true } -func (this *DecCoin) Equal(that interface{}) bool { - if that == nil { - return this == nil - } +func (m *Tx) XXX_Merge(src proto.Message) { + xxx_messageInfo_Tx.Merge(m, src) +} +func (m *Tx) XXX_Size() int { + return m.Size() +} +func (m *Tx) XXX_DiscardUnknown() { + xxx_messageInfo_Tx.DiscardUnknown(m) +} - that1, ok := that.(*DecCoin) - if !ok { - that2, ok := that.(DecCoin) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Denom != that1.Denom { - return false +var xxx_messageInfo_Tx proto.InternalMessageInfo + +func (m *Tx) GetBody() *TxBody { + if m != nil { + return m.Body } - if !this.Amount.Equal(that1.Amount) { - return false + return nil +} + +func (m *Tx) GetAuthInfo() *AuthInfo { + if m != nil { + return m.AuthInfo } - return true + return nil } -func (m *Coin) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err + +func (m *Tx) GetSignatures() [][]byte { + if m != nil { + return m.Signatures } - return dAtA[:n], nil + return nil } -func (m *Coin) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +type SignDoc struct { + Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` + AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` + ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + AccountNumber uint64 `protobuf:"varint,4,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` + // account_sequence starts at 1 rather than 0 to avoid the case where + // the default 0 value must be omitted in protobuf serialization + AccountSequence uint64 `protobuf:"varint,5,opt,name=account_sequence,json=accountSequence,proto3" json:"account_sequence,omitempty"` } -func (m *Coin) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Amount.Size() - i -= size - if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { - return 0, err +func (m *SignDoc) Reset() { *m = SignDoc{} } +func (*SignDoc) ProtoMessage() {} +func (*SignDoc) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{9} +} +func (m *SignDoc) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignDoc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignDoc.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err } - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) - i-- - dAtA[i] = 0xa + return b[:n], nil } - return len(dAtA) - i, nil +} +func (m *SignDoc) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignDoc.Merge(m, src) +} +func (m *SignDoc) XXX_Size() int { + return m.Size() +} +func (m *SignDoc) XXX_DiscardUnknown() { + xxx_messageInfo_SignDoc.DiscardUnknown(m) } -func (m *DecCoin) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +var xxx_messageInfo_SignDoc proto.InternalMessageInfo + +func (m *SignDoc) GetBody() *TxBody { + if m != nil { + return m.Body } - return dAtA[:n], nil + return nil } -func (m *DecCoin) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +func (m *SignDoc) GetAuthInfo() *AuthInfo { + if m != nil { + return m.AuthInfo + } + return nil } -func (m *DecCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Amount.Size() - i -= size - if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTypes(dAtA, i, uint64(size)) +func (m *SignDoc) GetChainId() string { + if m != nil { + return m.ChainId } - i-- - dAtA[i] = 0x12 - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) - i-- - dAtA[i] = 0xa + return "" +} + +func (m *SignDoc) GetAccountNumber() uint64 { + if m != nil { + return m.AccountNumber } - return len(dAtA) - i, nil + return 0 } -func (m *IntProto) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (m *SignDoc) GetAccountSequence() uint64 { + if m != nil { + return m.AccountSequence } - return dAtA[:n], nil + return 0 } -func (m *IntProto) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +type TxBody struct { + Messages []*types1.Any `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` + Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"` + TimeoutHeight int64 `protobuf:"varint,3,opt,name=timeout_height,json=timeoutHeight,proto3" json:"timeout_height,omitempty"` + ExtensionOptions []*types1.Any `protobuf:"bytes,1023,rep,name=extension_options,json=extensionOptions,proto3" json:"extension_options,omitempty"` } -func (m *IntProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Int.Size() - i -= size - if _, err := m.Int.MarshalTo(dAtA[i:]); err != nil { - return 0, err +func (m *TxBody) Reset() { *m = TxBody{} } +func (*TxBody) ProtoMessage() {} +func (*TxBody) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{10} +} +func (m *TxBody) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxBody) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxBody.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err } - i = encodeVarintTypes(dAtA, i, uint64(size)) + return b[:n], nil } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil +} +func (m *TxBody) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxBody.Merge(m, src) +} +func (m *TxBody) XXX_Size() int { + return m.Size() +} +func (m *TxBody) XXX_DiscardUnknown() { + xxx_messageInfo_TxBody.DiscardUnknown(m) } -func (m *DecProto) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +var xxx_messageInfo_TxBody proto.InternalMessageInfo + +func (m *TxBody) GetMessages() []*types1.Any { + if m != nil { + return m.Messages } - return dAtA[:n], nil + return nil } -func (m *DecProto) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +func (m *TxBody) GetMemo() string { + if m != nil { + return m.Memo + } + return "" } -func (m *DecProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Dec.Size() - i -= size - if _, err := m.Dec.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTypes(dAtA, i, uint64(size)) +func (m *TxBody) GetTimeoutHeight() int64 { + if m != nil { + return m.TimeoutHeight } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil + return 0 } -func (m *ValAddresses) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (m *TxBody) GetExtensionOptions() []*types1.Any { + if m != nil { + return m.ExtensionOptions } - return dAtA[:n], nil + return nil } -func (m *ValAddresses) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +type AuthInfo struct { + SignerInfos []*SignerInfo `protobuf:"bytes,1,rep,name=signer_infos,json=signerInfos,proto3" json:"signer_infos,omitempty"` + // The first signer is the primary signer and the one which pays the fee + Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` } -func (m *ValAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Addresses) > 0 { - for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Addresses[iNdEx]) - copy(dAtA[i:], m.Addresses[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Addresses[iNdEx]))) - i-- - dAtA[i] = 0xa +func (m *AuthInfo) Reset() { *m = AuthInfo{} } +func (*AuthInfo) ProtoMessage() {} +func (*AuthInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{11} +} +func (m *AuthInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AuthInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AuthInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err } + return b[:n], nil } - return len(dAtA) - i, nil } - -func (m *GasInfo) 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 *AuthInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_AuthInfo.Merge(m, src) } - -func (m *GasInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +func (m *AuthInfo) XXX_Size() int { + return m.Size() +} +func (m *AuthInfo) XXX_DiscardUnknown() { + xxx_messageInfo_AuthInfo.DiscardUnknown(m) } -func (m *GasInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.GasUsed != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.GasUsed)) - i-- - dAtA[i] = 0x10 - } - if m.GasWanted != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.GasWanted)) - i-- - dAtA[i] = 0x8 +var xxx_messageInfo_AuthInfo proto.InternalMessageInfo + +func (m *AuthInfo) GetSignerInfos() []*SignerInfo { + if m != nil { + return m.SignerInfos } - return len(dAtA) - i, nil + return nil } -func (m *Result) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (m *AuthInfo) GetFee() *Fee { + if m != nil { + return m.Fee } - return dAtA[:n], nil + return nil } -func (m *Result) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +type SignerInfo struct { + // PublicKey key is optional for accounts that already exist in state + PublicKey *types1.Any `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + // ModeInfo describes the signing mode of the signer and is a nested + // structure to support nested multisig pubkey's + ModeInfo *ModeInfo `protobuf:"bytes,2,opt,name=mode_info,json=modeInfo,proto3" json:"mode_info,omitempty"` } -func (m *Result) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Events) > 0 { - for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Events[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a +func (m *SignerInfo) Reset() { *m = SignerInfo{} } +func (*SignerInfo) ProtoMessage() {} +func (*SignerInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{12} +} +func (m *SignerInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignerInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignerInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err } + return b[:n], nil } - if len(m.Log) > 0 { - i -= len(m.Log) - copy(dAtA[i:], m.Log) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Log))) - i-- - dAtA[i] = 0x12 - } - if len(m.Data) > 0 { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0xa +} +func (m *SignerInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignerInfo.Merge(m, src) +} +func (m *SignerInfo) XXX_Size() int { + return m.Size() +} +func (m *SignerInfo) XXX_DiscardUnknown() { + xxx_messageInfo_SignerInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_SignerInfo proto.InternalMessageInfo + +func (m *SignerInfo) GetPublicKey() *types1.Any { + if m != nil { + return m.PublicKey } - return len(dAtA) - i, nil + return nil } -func (m *SimulationResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (m *SignerInfo) GetModeInfo() *ModeInfo { + if m != nil { + return m.ModeInfo } - return dAtA[:n], nil + return nil } -func (m *SimulationResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +type ModeInfo struct { + // Types that are valid to be assigned to Sum: + // *ModeInfo_Single_ + // *ModeInfo_Multi_ + Sum isModeInfo_Sum `protobuf_oneof:"sum"` } -func (m *SimulationResponse) 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 = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - { - size, err := m.GasInfo.MarshalToSizedBuffer(dAtA[:i]) +func (m *ModeInfo) Reset() { *m = ModeInfo{} } +func (*ModeInfo) ProtoMessage() {} +func (*ModeInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{13} +} +func (m *ModeInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModeInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) if err != nil { - return 0, err + return nil, err } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) + return b[:n], nil } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil +} +func (m *ModeInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModeInfo.Merge(m, src) +} +func (m *ModeInfo) XXX_Size() int { + return m.Size() +} +func (m *ModeInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ModeInfo.DiscardUnknown(m) } -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base +var xxx_messageInfo_ModeInfo proto.InternalMessageInfo + +type isModeInfo_Sum interface { + isModeInfo_Sum() + MarshalTo([]byte) (int, error) + Size() int } -func (m *Coin) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = m.Amount.Size() - n += 1 + l + sovTypes(uint64(l)) - return n + +type ModeInfo_Single_ struct { + Single *ModeInfo_Single `protobuf:"bytes,1,opt,name=single,proto3,oneof" json:"single,omitempty"` +} +type ModeInfo_Multi_ struct { + Multi *ModeInfo_Multi `protobuf:"bytes,2,opt,name=multi,proto3,oneof" json:"multi,omitempty"` } -func (m *DecCoin) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) +func (*ModeInfo_Single_) isModeInfo_Sum() {} +func (*ModeInfo_Multi_) isModeInfo_Sum() {} + +func (m *ModeInfo) GetSum() isModeInfo_Sum { + if m != nil { + return m.Sum } - l = m.Amount.Size() - n += 1 + l + sovTypes(uint64(l)) - return n + return nil } -func (m *IntProto) Size() (n int) { - if m == nil { - return 0 +func (m *ModeInfo) GetSingle() *ModeInfo_Single { + if x, ok := m.GetSum().(*ModeInfo_Single_); ok { + return x.Single } - var l int - _ = l - l = m.Int.Size() - n += 1 + l + sovTypes(uint64(l)) - return n + return nil } -func (m *DecProto) Size() (n int) { - if m == nil { - return 0 +func (m *ModeInfo) GetMulti() *ModeInfo_Multi { + if x, ok := m.GetSum().(*ModeInfo_Multi_); ok { + return x.Multi } - var l int - _ = l - l = m.Dec.Size() - n += 1 + l + sovTypes(uint64(l)) - return n + return nil } -func (m *ValAddresses) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Addresses) > 0 { - for _, b := range m.Addresses { - l = len(b) - n += 1 + l + sovTypes(uint64(l)) - } +// XXX_OneofWrappers is for the internal use of the proto package. +func (*ModeInfo) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*ModeInfo_Single_)(nil), + (*ModeInfo_Multi_)(nil), } - return n } -func (m *GasInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.GasWanted != 0 { - n += 1 + sovTypes(uint64(m.GasWanted)) +// Single is the mode info for a single signer. It is structured as a message +// to allow for additional fields such as locale for SIGN_MODE_TEXTUAL in the future +type ModeInfo_Single struct { + Mode SignMode `protobuf:"varint,1,opt,name=mode,proto3,enum=cosmos_sdk.v1.SignMode" json:"mode,omitempty"` +} + +func (m *ModeInfo_Single) Reset() { *m = ModeInfo_Single{} } +func (*ModeInfo_Single) ProtoMessage() {} +func (*ModeInfo_Single) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{13, 0} +} +func (m *ModeInfo_Single) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModeInfo_Single) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModeInfo_Single.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil } - if m.GasUsed != 0 { - n += 1 + sovTypes(uint64(m.GasUsed)) +} +func (m *ModeInfo_Single) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModeInfo_Single.Merge(m, src) +} +func (m *ModeInfo_Single) XXX_Size() int { + return m.Size() +} +func (m *ModeInfo_Single) XXX_DiscardUnknown() { + xxx_messageInfo_ModeInfo_Single.DiscardUnknown(m) +} + +var xxx_messageInfo_ModeInfo_Single proto.InternalMessageInfo + +func (m *ModeInfo_Single) GetMode() SignMode { + if m != nil { + return m.Mode } - return n + return SignMode_SIGN_MODE_UNSPECIFIED } -func (m *Result) Size() (n int) { - if m == nil { - return 0 +// Multi is the mode info for a multisig public key +type ModeInfo_Multi struct { + // bitarray specifies which keys within the multisig are signing + Bitarray *CompactBitArray `protobuf:"bytes,1,opt,name=bitarray,proto3" json:"bitarray,omitempty"` + // mode_infos is the corresponding modes of the signers of the multisig + // which could include nested multisig public keys + ModeInfos []*ModeInfo `protobuf:"bytes,2,rep,name=mode_infos,json=modeInfos,proto3" json:"mode_infos,omitempty"` +} + +func (m *ModeInfo_Multi) Reset() { *m = ModeInfo_Multi{} } +func (*ModeInfo_Multi) ProtoMessage() {} +func (*ModeInfo_Multi) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{13, 1} +} +func (m *ModeInfo_Multi) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModeInfo_Multi) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModeInfo_Multi.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 *ModeInfo_Multi) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModeInfo_Multi.Merge(m, src) +} +func (m *ModeInfo_Multi) XXX_Size() int { + return m.Size() +} +func (m *ModeInfo_Multi) XXX_DiscardUnknown() { + xxx_messageInfo_ModeInfo_Multi.DiscardUnknown(m) +} + +var xxx_messageInfo_ModeInfo_Multi proto.InternalMessageInfo + +func (m *ModeInfo_Multi) GetBitarray() *CompactBitArray { + if m != nil { + return m.Bitarray + } + return nil +} + +func (m *ModeInfo_Multi) GetModeInfos() []*ModeInfo { + if m != nil { + return m.ModeInfos + } + return nil +} + +// Fee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +type Fee struct { + Amount Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=Coins" json:"amount"` + GasLimit uint64 `protobuf:"varint,2,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"` +} + +func (m *Fee) Reset() { *m = Fee{} } +func (*Fee) ProtoMessage() {} +func (*Fee) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{14} +} +func (m *Fee) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Fee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Fee.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 *Fee) XXX_Merge(src proto.Message) { + xxx_messageInfo_Fee.Merge(m, src) +} +func (m *Fee) XXX_Size() int { + return m.Size() +} +func (m *Fee) XXX_DiscardUnknown() { + xxx_messageInfo_Fee.DiscardUnknown(m) +} + +var xxx_messageInfo_Fee proto.InternalMessageInfo + +// CompactBitArray is an implementation of a space efficient bit array. +// This is used to ensure that the encoded data takes up a minimal amount of +// space after proto encoding. +// This is not thread safe, and is not intended for concurrent usage. +type CompactBitArray struct { + ExtraBitsStored uint32 `protobuf:"varint,1,opt,name=extra_bits_stored,json=extraBitsStored,proto3" json:"extra_bits_stored,omitempty"` + Elems []byte `protobuf:"bytes,2,opt,name=elems,proto3" json:"elems,omitempty"` +} + +func (m *CompactBitArray) Reset() { *m = CompactBitArray{} } +func (*CompactBitArray) ProtoMessage() {} +func (*CompactBitArray) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{15} +} +func (m *CompactBitArray) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CompactBitArray) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CompactBitArray.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 *CompactBitArray) XXX_Merge(src proto.Message) { + xxx_messageInfo_CompactBitArray.Merge(m, src) +} +func (m *CompactBitArray) XXX_Size() int { + return m.Size() +} +func (m *CompactBitArray) XXX_DiscardUnknown() { + xxx_messageInfo_CompactBitArray.DiscardUnknown(m) +} + +var xxx_messageInfo_CompactBitArray proto.InternalMessageInfo + +func (m *CompactBitArray) GetExtraBitsStored() uint32 { + if m != nil { + return m.ExtraBitsStored + } + return 0 +} + +func (m *CompactBitArray) GetElems() []byte { + if m != nil { + return m.Elems + } + return nil +} + +func init() { + proto.RegisterEnum("cosmos_sdk.v1.SignMode", SignMode_name, SignMode_value) + proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin") + proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin") + proto.RegisterType((*IntProto)(nil), "cosmos_sdk.v1.IntProto") + proto.RegisterType((*DecProto)(nil), "cosmos_sdk.v1.DecProto") + proto.RegisterType((*ValAddresses)(nil), "cosmos_sdk.v1.ValAddresses") + proto.RegisterType((*GasInfo)(nil), "cosmos_sdk.v1.GasInfo") + proto.RegisterType((*Result)(nil), "cosmos_sdk.v1.Result") + proto.RegisterType((*SimulationResponse)(nil), "cosmos_sdk.v1.SimulationResponse") + proto.RegisterType((*Tx)(nil), "cosmos_sdk.v1.Tx") + proto.RegisterType((*SignDoc)(nil), "cosmos_sdk.v1.SignDoc") + proto.RegisterType((*TxBody)(nil), "cosmos_sdk.v1.TxBody") + proto.RegisterType((*AuthInfo)(nil), "cosmos_sdk.v1.AuthInfo") + proto.RegisterType((*SignerInfo)(nil), "cosmos_sdk.v1.SignerInfo") + proto.RegisterType((*ModeInfo)(nil), "cosmos_sdk.v1.ModeInfo") + proto.RegisterType((*ModeInfo_Single)(nil), "cosmos_sdk.v1.ModeInfo.Single") + proto.RegisterType((*ModeInfo_Multi)(nil), "cosmos_sdk.v1.ModeInfo.Multi") + proto.RegisterType((*Fee)(nil), "cosmos_sdk.v1.Fee") + proto.RegisterType((*CompactBitArray)(nil), "cosmos_sdk.v1.CompactBitArray") +} + +func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } + +var fileDescriptor_2c0f90c600ad7e2e = []byte{ + // 1181 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4d, 0x73, 0x1b, 0x45, + 0x13, 0xd6, 0x5a, 0xb2, 0x2c, 0xb7, 0xe5, 0x58, 0x9e, 0xc4, 0xef, 0x2b, 0x3b, 0x44, 0x72, 0x89, + 0x8f, 0x4a, 0x02, 0x59, 0x81, 0x13, 0x28, 0x4a, 0xe1, 0xa2, 0xb5, 0x14, 0x47, 0x21, 0xb6, 0x53, + 0x23, 0x07, 0x08, 0x97, 0xad, 0xd5, 0xee, 0x78, 0x35, 0x15, 0xed, 0x8e, 0xd8, 0x99, 0x0d, 0xd1, + 0x81, 0x22, 0xdc, 0xa8, 0xe2, 0xc2, 0x4f, 0xc8, 0x99, 0x3f, 0xc1, 0x35, 0xdc, 0x72, 0x4c, 0x51, + 0x60, 0xc0, 0xbe, 0x70, 0xce, 0x91, 0x0b, 0xd4, 0x7c, 0xc8, 0x22, 0x32, 0xce, 0x81, 0x2a, 0x2e, + 0xab, 0x9e, 0xee, 0x67, 0xfa, 0xe3, 0x99, 0x9e, 0x1e, 0xc1, 0xb2, 0x18, 0x0d, 0x09, 0xaf, 0xab, + 0xaf, 0x3d, 0x4c, 0x98, 0x60, 0x68, 0xd1, 0x67, 0x3c, 0x62, 0xdc, 0xe5, 0xc1, 0x7d, 0xfb, 0xc1, + 0x3b, 0x6b, 0x6f, 0x88, 0x3e, 0x4d, 0x02, 0x77, 0xe8, 0x25, 0x62, 0x54, 0x57, 0x88, 0x7a, 0xc8, + 0x42, 0x36, 0x91, 0xf4, 0xb6, 0xb5, 0xab, 0x27, 0x71, 0x82, 0xc4, 0x01, 0x49, 0x22, 0x1a, 0x8b, + 0xba, 0xd7, 0xf3, 0x69, 0xfd, 0x44, 0xac, 0xb5, 0xd5, 0x90, 0xb1, 0x70, 0x40, 0x34, 0xbe, 0x97, + 0xee, 0xd7, 0xbd, 0x78, 0xa4, 0x4d, 0xb5, 0x2d, 0xc8, 0x6d, 0x32, 0x1a, 0xa3, 0x73, 0x30, 0x1b, + 0x90, 0x98, 0x45, 0x65, 0x6b, 0xdd, 0xba, 0x38, 0x8f, 0xf5, 0x02, 0xbd, 0x0a, 0x79, 0x2f, 0x62, + 0x69, 0x2c, 0xca, 0x33, 0x52, 0xed, 0x2c, 0x3c, 0x39, 0xa8, 0x66, 0x7e, 0x3c, 0xa8, 0x66, 0x3b, + 0xb1, 0xc0, 0xc6, 0xd4, 0xc8, 0xfd, 0xfe, 0xb8, 0x6a, 0xd5, 0x6e, 0xc1, 0x5c, 0x8b, 0xf8, 0xff, + 0xc6, 0x57, 0x8b, 0xf8, 0x53, 0xbe, 0x2e, 0x41, 0xa1, 0x13, 0x8b, 0x3b, 0x8a, 0xa7, 0x0b, 0x90, + 0xa5, 0xb1, 0xd0, 0xae, 0x5e, 0x8c, 0x2f, 0xf5, 0x12, 0xda, 0x22, 0xfe, 0x31, 0x34, 0x20, 0xfe, + 0x34, 0x54, 0xba, 0x97, 0xfa, 0x9a, 0x03, 0xc5, 0x8f, 0xbc, 0x41, 0x33, 0x08, 0x12, 0xc2, 0x39, + 0xe1, 0xe8, 0x2d, 0x98, 0xf7, 0xc6, 0x8b, 0xb2, 0xb5, 0x9e, 0xbd, 0x58, 0x74, 0xce, 0xfc, 0x71, + 0x50, 0x85, 0x09, 0x08, 0x4f, 0x00, 0x8d, 0xdc, 0xa3, 0x9f, 0xd6, 0xad, 0x1a, 0x83, 0xb9, 0x2d, + 0x8f, 0x77, 0xe2, 0x7d, 0x86, 0xae, 0x01, 0x84, 0x1e, 0x77, 0x3f, 0xf7, 0x62, 0x41, 0x02, 0x15, + 0x34, 0xe7, 0xac, 0x3c, 0x3f, 0xa8, 0x2e, 0x8f, 0xbc, 0x68, 0xd0, 0xa8, 0x4d, 0x6c, 0x35, 0x3c, + 0x1f, 0x7a, 0xfc, 0x63, 0x25, 0x23, 0x1b, 0x0a, 0xd2, 0x92, 0x72, 0x12, 0x28, 0x1e, 0x72, 0xce, + 0xd9, 0xe7, 0x07, 0xd5, 0xa5, 0xc9, 0x1e, 0x69, 0xa9, 0xe1, 0xb9, 0xd0, 0xe3, 0x77, 0xa5, 0x34, + 0x84, 0x3c, 0x26, 0x3c, 0x1d, 0x08, 0x84, 0x20, 0x17, 0x78, 0xc2, 0x53, 0x91, 0x8a, 0x58, 0xc9, + 0xa8, 0x04, 0xd9, 0x01, 0x0b, 0x35, 0xa1, 0x58, 0x8a, 0xa8, 0x01, 0x79, 0xf2, 0x80, 0xc4, 0x82, + 0x97, 0xb3, 0xeb, 0xd9, 0x8b, 0x0b, 0x1b, 0xaf, 0xd8, 0x93, 0xf6, 0xb0, 0x65, 0x7b, 0xd8, 0xba, + 0x31, 0xda, 0x12, 0xe4, 0xe4, 0x24, 0x49, 0xd8, 0xec, 0x68, 0xe4, 0xbe, 0x7e, 0x5c, 0xcd, 0xd4, + 0x1e, 0x59, 0x80, 0xba, 0x34, 0x4a, 0x07, 0x9e, 0xa0, 0x2c, 0xc6, 0x84, 0x0f, 0x59, 0xcc, 0x09, + 0xba, 0xae, 0x13, 0xa7, 0xf1, 0x3e, 0x53, 0x29, 0x2c, 0x6c, 0xfc, 0xcf, 0x7e, 0xa1, 0x85, 0x6d, + 0x43, 0x8c, 0x53, 0x90, 0x4e, 0x9f, 0x1e, 0x54, 0x2d, 0x55, 0x85, 0xe2, 0xea, 0x0a, 0xe4, 0x13, + 0x55, 0x85, 0x4a, 0x75, 0x61, 0x63, 0x65, 0x6a, 0xab, 0x2e, 0x11, 0x1b, 0x50, 0xed, 0x1b, 0x0b, + 0x66, 0xf6, 0x1e, 0xa2, 0x4b, 0x90, 0xeb, 0xb1, 0x60, 0x64, 0xc2, 0x4d, 0xef, 0xd9, 0x7b, 0xe8, + 0xb0, 0x60, 0x84, 0x15, 0x04, 0x5d, 0x83, 0x79, 0x2f, 0x15, 0x7d, 0x9d, 0x9e, 0x8e, 0xf1, 0xff, + 0x29, 0x7c, 0x33, 0x15, 0x7d, 0x99, 0x0c, 0x2e, 0x78, 0x46, 0x42, 0x15, 0x00, 0x4e, 0xc3, 0xd8, + 0x13, 0x69, 0x42, 0x34, 0x61, 0x45, 0xfc, 0x37, 0x8d, 0x39, 0xf3, 0x9f, 0x2d, 0x98, 0xeb, 0xd2, + 0x30, 0x6e, 0x31, 0xff, 0xbf, 0x4f, 0x69, 0x15, 0x0a, 0x7e, 0xdf, 0xa3, 0xb1, 0x4b, 0x83, 0x72, + 0x56, 0x1d, 0xeb, 0x9c, 0x5a, 0x77, 0x02, 0xf4, 0x3a, 0x9c, 0xf1, 0x7c, 0x5f, 0x5e, 0x13, 0x37, + 0x4e, 0xa3, 0x1e, 0x49, 0xca, 0x39, 0xd9, 0x40, 0x78, 0xd1, 0x68, 0x77, 0x94, 0x12, 0x5d, 0x82, + 0xd2, 0x18, 0xc6, 0xc9, 0x67, 0x29, 0x89, 0x7d, 0x52, 0x9e, 0x55, 0xc0, 0x25, 0xa3, 0xef, 0x1a, + 0xb5, 0xa9, 0xef, 0x7b, 0x0b, 0xf2, 0x3a, 0x73, 0xf4, 0x36, 0x14, 0x22, 0xc2, 0xb9, 0x17, 0x9a, + 0x1b, 0xb1, 0xb0, 0x71, 0xce, 0xd6, 0xb3, 0xc3, 0x1e, 0xcf, 0x0e, 0xbb, 0x19, 0x8f, 0xf0, 0x31, + 0x4a, 0x76, 0x65, 0x44, 0x22, 0x66, 0x5a, 0x50, 0xc9, 0x32, 0x51, 0x41, 0x23, 0xc2, 0x52, 0xe1, + 0xf6, 0x09, 0x0d, 0xfb, 0x42, 0x55, 0x92, 0xc5, 0x8b, 0x46, 0x7b, 0x53, 0x29, 0x91, 0x03, 0xcb, + 0xe4, 0xa1, 0x20, 0x31, 0xa7, 0x2c, 0x76, 0xd9, 0x50, 0x76, 0x1b, 0x2f, 0xff, 0x39, 0xf7, 0x92, + 0xb0, 0xa5, 0x63, 0xfc, 0xae, 0x86, 0x9b, 0x0a, 0x04, 0x14, 0xc6, 0x54, 0xa2, 0x0f, 0xa0, 0x28, + 0x4f, 0x90, 0x24, 0x8a, 0xf8, 0x71, 0x19, 0xab, 0x53, 0xcc, 0x77, 0x15, 0x44, 0x71, 0xbf, 0xc0, + 0x8f, 0x65, 0x8e, 0x5e, 0x83, 0xec, 0x3e, 0x21, 0xe6, 0xb8, 0xd0, 0xd4, 0xa6, 0x1b, 0x84, 0x60, + 0x69, 0x36, 0x51, 0xbf, 0x00, 0x98, 0xb8, 0x41, 0x57, 0x01, 0x86, 0x69, 0x6f, 0x40, 0x7d, 0xf7, + 0x3e, 0x19, 0xf7, 0xc7, 0x3f, 0x57, 0x31, 0xaf, 0x71, 0x1f, 0x12, 0xd5, 0x23, 0x11, 0x0b, 0xc8, + 0xcb, 0x7a, 0x64, 0x9b, 0x05, 0x44, 0xf7, 0x48, 0x64, 0x24, 0x13, 0xfe, 0x87, 0x19, 0x28, 0x8c, + 0x8d, 0xe8, 0x7d, 0xc8, 0x73, 0x1a, 0x87, 0x03, 0x62, 0x22, 0x57, 0x4e, 0xf1, 0x62, 0x77, 0x15, + 0xea, 0x66, 0x06, 0x1b, 0x3c, 0x7a, 0x17, 0x66, 0xa3, 0x74, 0x20, 0xa8, 0x09, 0x7f, 0xe1, 0xb4, + 0x8d, 0xdb, 0x12, 0x74, 0x33, 0x83, 0x35, 0x7a, 0xed, 0x3a, 0xe4, 0xb5, 0x2b, 0xf4, 0x26, 0xe4, + 0x64, 0x66, 0x2a, 0xf0, 0x99, 0x13, 0xe9, 0x4b, 0x86, 0xa4, 0x0f, 0xac, 0x40, 0x3a, 0xf5, 0xb5, + 0xaf, 0x2c, 0x98, 0x55, 0xfe, 0x50, 0x03, 0x0a, 0x3d, 0x2a, 0xbc, 0x24, 0xf1, 0x46, 0xa7, 0x64, + 0xbe, 0xc9, 0xa2, 0xa1, 0xe7, 0x0b, 0x87, 0x8a, 0xa6, 0x44, 0xe1, 0x63, 0x3c, 0x7a, 0x0f, 0xe0, + 0x98, 0x3c, 0x5e, 0x9e, 0x51, 0xe7, 0x7c, 0x2a, 0x7b, 0xf3, 0x63, 0xf6, 0x4c, 0xcf, 0xe8, 0xaf, + 0x33, 0x0b, 0x59, 0x9e, 0x46, 0xb5, 0x01, 0x64, 0x6f, 0x10, 0x22, 0x87, 0xa7, 0x79, 0xa2, 0x74, + 0xd7, 0x9c, 0x3d, 0x91, 0x0b, 0x8d, 0x9d, 0x45, 0x39, 0xde, 0xbe, 0xfb, 0xa5, 0x3a, 0x2b, 0x57, + 0x7c, 0xfc, 0x72, 0xa1, 0xf3, 0x20, 0xa7, 0xbc, 0x3b, 0xa0, 0x11, 0xd5, 0x53, 0x2e, 0x87, 0xe5, + 0xc0, 0xbc, 0x2d, 0xd7, 0x8d, 0xa2, 0x9c, 0xac, 0xf2, 0x69, 0x53, 0x27, 0x77, 0x0f, 0x96, 0xa6, + 0xaa, 0x42, 0x97, 0xd5, 0x5d, 0x48, 0x3c, 0xb7, 0x47, 0x05, 0x77, 0xb9, 0x60, 0x89, 0x79, 0x53, + 0x16, 0xf1, 0x92, 0x32, 0x38, 0x54, 0xf0, 0xae, 0x52, 0xcb, 0xe7, 0x95, 0x0c, 0x48, 0xc4, 0x55, + 0x94, 0x22, 0xd6, 0x0b, 0x5d, 0xcf, 0x65, 0x0e, 0x85, 0x31, 0xe3, 0x68, 0x15, 0x56, 0xba, 0x9d, + 0xad, 0x1d, 0x77, 0x7b, 0xb7, 0xd5, 0x76, 0xef, 0xee, 0x74, 0xef, 0xb4, 0x37, 0x3b, 0x37, 0x3a, + 0xed, 0x56, 0x29, 0x83, 0xce, 0x41, 0x69, 0x62, 0x6a, 0x75, 0x70, 0x7b, 0x73, 0xaf, 0x64, 0xa1, + 0x15, 0x58, 0x9e, 0x68, 0xf7, 0xda, 0x9f, 0xec, 0xdd, 0x6d, 0xde, 0x2e, 0xcd, 0xa0, 0x2a, 0x9c, + 0x9f, 0xa8, 0x6f, 0xb7, 0xb7, 0x9a, 0x9b, 0xf7, 0xdc, 0xe6, 0x76, 0x67, 0x67, 0xd7, 0xbd, 0xd5, + 0xdd, 0xdd, 0x29, 0x7d, 0xe9, 0xb4, 0x9e, 0xfd, 0x56, 0xc9, 0x3c, 0x3a, 0xac, 0x64, 0x9e, 0x1c, + 0x56, 0xac, 0xa7, 0x87, 0x15, 0xeb, 0xd7, 0xc3, 0x8a, 0xf5, 0xed, 0x51, 0x25, 0xf3, 0xf4, 0xa8, + 0x92, 0x79, 0x76, 0x54, 0xc9, 0x7c, 0x5a, 0x0b, 0xa9, 0xe8, 0xa7, 0x3d, 0xdb, 0x67, 0x51, 0x5d, + 0x53, 0x6a, 0x7e, 0xae, 0xf0, 0xe0, 0xbe, 0xfe, 0xab, 0xd2, 0xcb, 0xab, 0x4b, 0x72, 0xf5, 0xaf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xb6, 0xa8, 0x9a, 0x6e, 0x2c, 0x09, 0x00, 0x00, +} + +func (this *Coin) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Coin) + if !ok { + that2, ok := that.(Coin) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Denom != that1.Denom { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true +} +func (this *DecCoin) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DecCoin) + if !ok { + that2, ok := that.(DecCoin) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Denom != that1.Denom { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true +} +func (this *Fee) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Fee) + if !ok { + that2, ok := that.(Fee) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Amount) != len(that1.Amount) { + return false + } + for i := range this.Amount { + if !this.Amount[i].Equal(&that1.Amount[i]) { + return false + } + } + if this.GasLimit != that1.GasLimit { + return false + } + return true +} +func (m *Coin) 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 *Coin) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Coin) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - l = len(m.Data) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) } - l = len(m.Log) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) + i-- + dAtA[i] = 0x12 + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa } - if len(m.Events) > 0 { - for _, e := range m.Events { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) + return len(dAtA) - i, nil +} + +func (m *DecCoin) 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 *DecCoin) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DecCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *IntProto) 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 *IntProto) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IntProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Int.Size() + i -= size + if _, err := m.Int.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *DecProto) 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 *DecProto) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DecProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Dec.Size() + i -= size + if _, err := m.Dec.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ValAddresses) 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 *ValAddresses) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *GasInfo) 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 *GasInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GasInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.GasUsed != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.GasUsed)) + i-- + dAtA[i] = 0x10 + } + if m.GasWanted != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.GasWanted)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Result) 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 *Result) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Result) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Events) > 0 { + for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Events[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Log) > 0 { + i -= len(m.Log) + copy(dAtA[i:], m.Log) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Log))) + i-- + dAtA[i] = 0x12 + } + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SimulationResponse) 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 *SimulationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SimulationResponse) 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 = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + { + size, err := m.GasInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Tx) 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 *Tx) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Tx) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signatures) > 0 { + for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Signatures[iNdEx]) + copy(dAtA[i:], m.Signatures[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Signatures[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if m.AuthInfo != nil { + { + size, err := m.AuthInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Body != nil { + { + size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SignDoc) 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 *SignDoc) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignDoc) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AccountSequence != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.AccountSequence)) + i-- + dAtA[i] = 0x28 + } + if m.AccountNumber != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.AccountNumber)) + i-- + dAtA[i] = 0x20 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x1a + } + if m.AuthInfo != nil { + { + size, err := m.AuthInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Body != nil { + { + size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *TxBody) 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 *TxBody) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TxBody) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ExtensionOptions) > 0 { + for iNdEx := len(m.ExtensionOptions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ExtensionOptions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3f + i-- + dAtA[i] = 0xfa + } + } + if m.TimeoutHeight != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.TimeoutHeight)) + i-- + dAtA[i] = 0x18 + } + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x12 + } + if len(m.Messages) > 0 { + for iNdEx := len(m.Messages) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Messages[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *AuthInfo) 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 *AuthInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AuthInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Fee != nil { + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.SignerInfos) > 0 { + for iNdEx := len(m.SignerInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SignerInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *SignerInfo) 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 *SignerInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignerInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ModeInfo != nil { + { + size, err := m.ModeInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.PublicKey != nil { + { + size, err := m.PublicKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ModeInfo) 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 *ModeInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModeInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *ModeInfo_Single_) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModeInfo_Single_) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Single != nil { + { + size, err := m.Single.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *ModeInfo_Multi_) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModeInfo_Multi_) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Multi != nil { + { + size, err := m.Multi.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *ModeInfo_Single) 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 *ModeInfo_Single) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModeInfo_Single) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Mode != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Mode)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ModeInfo_Multi) 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 *ModeInfo_Multi) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModeInfo_Multi) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ModeInfos) > 0 { + for iNdEx := len(m.ModeInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ModeInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Bitarray != nil { + { + size, err := m.Bitarray.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Fee) 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 *Fee) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.GasLimit != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.GasLimit)) + i-- + dAtA[i] = 0x10 + } + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *CompactBitArray) 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 *CompactBitArray) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CompactBitArray) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Elems) > 0 { + i -= len(m.Elems) + copy(dAtA[i:], m.Elems) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Elems))) + i-- + dAtA[i] = 0x12 + } + if m.ExtraBitsStored != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.ExtraBitsStored)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Coin) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *DecCoin) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *IntProto) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Int.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *DecProto) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Dec.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *ValAddresses) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Addresses) > 0 { + for _, b := range m.Addresses { + l = len(b) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *GasInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.GasWanted != 0 { + n += 1 + sovTypes(uint64(m.GasWanted)) + } + if m.GasUsed != 0 { + n += 1 + sovTypes(uint64(m.GasUsed)) + } + return n +} + +func (m *Result) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Log) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Events) > 0 { + for _, e := range m.Events { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *SimulationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.GasInfo.Size() + n += 1 + l + sovTypes(uint64(l)) + if m.Result != nil { + l = m.Result.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Tx) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Body != nil { + l = m.Body.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.AuthInfo != nil { + l = m.AuthInfo.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Signatures) > 0 { + for _, b := range m.Signatures { + l = len(b) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *SignDoc) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Body != nil { + l = m.Body.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.AuthInfo != nil { + l = m.AuthInfo.Size() + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.AccountNumber != 0 { + n += 1 + sovTypes(uint64(m.AccountNumber)) + } + if m.AccountSequence != 0 { + n += 1 + sovTypes(uint64(m.AccountSequence)) + } + return n +} + +func (m *TxBody) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Messages) > 0 { + for _, e := range m.Messages { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.TimeoutHeight != 0 { + n += 1 + sovTypes(uint64(m.TimeoutHeight)) + } + if len(m.ExtensionOptions) > 0 { + for _, e := range m.ExtensionOptions { + l = e.Size() + n += 2 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *AuthInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.SignerInfos) > 0 { + for _, e := range m.SignerInfos { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if m.Fee != nil { + l = m.Fee.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *SignerInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PublicKey != nil { + l = m.PublicKey.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if m.ModeInfo != nil { + l = m.ModeInfo.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ModeInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *ModeInfo_Single_) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Single != nil { + l = m.Single.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *ModeInfo_Multi_) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Multi != nil { + l = m.Multi.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *ModeInfo_Single) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Mode != 0 { + n += 1 + sovTypes(uint64(m.Mode)) + } + return n +} + +func (m *ModeInfo_Multi) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Bitarray != nil { + l = m.Bitarray.Size() + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.ModeInfos) > 0 { + for _, e := range m.ModeInfos { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Fee) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if m.GasLimit != 0 { + n += 1 + sovTypes(uint64(m.GasLimit)) + } + return n +} + +func (m *CompactBitArray) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ExtraBitsStored != 0 { + n += 1 + sovTypes(uint64(m.ExtraBitsStored)) + } + l = len(m.Elems) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ValAddresses) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ValAddresses{`, + `Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`, + `}`, + }, "") + return s +} +func (this *Tx) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Tx{`, + `Body:` + strings.Replace(this.Body.String(), "TxBody", "TxBody", 1) + `,`, + `AuthInfo:` + strings.Replace(this.AuthInfo.String(), "AuthInfo", "AuthInfo", 1) + `,`, + `Signatures:` + fmt.Sprintf("%v", this.Signatures) + `,`, + `}`, + }, "") + return s +} +func (this *SignDoc) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&SignDoc{`, + `Body:` + strings.Replace(this.Body.String(), "TxBody", "TxBody", 1) + `,`, + `AuthInfo:` + strings.Replace(this.AuthInfo.String(), "AuthInfo", "AuthInfo", 1) + `,`, + `ChainId:` + fmt.Sprintf("%v", this.ChainId) + `,`, + `AccountNumber:` + fmt.Sprintf("%v", this.AccountNumber) + `,`, + `AccountSequence:` + fmt.Sprintf("%v", this.AccountSequence) + `,`, + `}`, + }, "") + return s +} +func (this *TxBody) String() string { + if this == nil { + return "nil" + } + repeatedStringForMessages := "[]*Any{" + for _, f := range this.Messages { + repeatedStringForMessages += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," + } + repeatedStringForMessages += "}" + repeatedStringForExtensionOptions := "[]*Any{" + for _, f := range this.ExtensionOptions { + repeatedStringForExtensionOptions += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," + } + repeatedStringForExtensionOptions += "}" + s := strings.Join([]string{`&TxBody{`, + `Messages:` + repeatedStringForMessages + `,`, + `Memo:` + fmt.Sprintf("%v", this.Memo) + `,`, + `TimeoutHeight:` + fmt.Sprintf("%v", this.TimeoutHeight) + `,`, + `ExtensionOptions:` + repeatedStringForExtensionOptions + `,`, + `}`, + }, "") + return s +} +func (this *AuthInfo) String() string { + if this == nil { + return "nil" + } + repeatedStringForSignerInfos := "[]*SignerInfo{" + for _, f := range this.SignerInfos { + repeatedStringForSignerInfos += strings.Replace(f.String(), "SignerInfo", "SignerInfo", 1) + "," + } + repeatedStringForSignerInfos += "}" + s := strings.Join([]string{`&AuthInfo{`, + `SignerInfos:` + repeatedStringForSignerInfos + `,`, + `Fee:` + strings.Replace(this.Fee.String(), "Fee", "Fee", 1) + `,`, + `}`, + }, "") + return s +} +func (this *SignerInfo) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&SignerInfo{`, + `PublicKey:` + strings.Replace(fmt.Sprintf("%v", this.PublicKey), "Any", "types1.Any", 1) + `,`, + `ModeInfo:` + strings.Replace(this.ModeInfo.String(), "ModeInfo", "ModeInfo", 1) + `,`, + `}`, + }, "") + return s +} +func (this *ModeInfo) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ModeInfo{`, + `Sum:` + fmt.Sprintf("%v", this.Sum) + `,`, + `}`, + }, "") + return s +} +func (this *ModeInfo_Single_) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ModeInfo_Single_{`, + `Single:` + strings.Replace(fmt.Sprintf("%v", this.Single), "ModeInfo_Single", "ModeInfo_Single", 1) + `,`, + `}`, + }, "") + return s +} +func (this *ModeInfo_Multi_) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ModeInfo_Multi_{`, + `Multi:` + strings.Replace(fmt.Sprintf("%v", this.Multi), "ModeInfo_Multi", "ModeInfo_Multi", 1) + `,`, + `}`, + }, "") + return s +} +func (this *ModeInfo_Single) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ModeInfo_Single{`, + `Mode:` + fmt.Sprintf("%v", this.Mode) + `,`, + `}`, + }, "") + return s +} +func (this *ModeInfo_Multi) String() string { + if this == nil { + return "nil" + } + repeatedStringForModeInfos := "[]*ModeInfo{" + for _, f := range this.ModeInfos { + repeatedStringForModeInfos += strings.Replace(f.String(), "ModeInfo", "ModeInfo", 1) + "," + } + repeatedStringForModeInfos += "}" + s := strings.Join([]string{`&ModeInfo_Multi{`, + `Bitarray:` + strings.Replace(this.Bitarray.String(), "CompactBitArray", "CompactBitArray", 1) + `,`, + `ModeInfos:` + repeatedStringForModeInfos + `,`, + `}`, + }, "") + return s +} +func (this *Fee) String() string { + if this == nil { + return "nil" + } + repeatedStringForAmount := "[]Coin{" + for _, f := range this.Amount { + repeatedStringForAmount += fmt.Sprintf("%v", f) + "," + } + repeatedStringForAmount += "}" + s := strings.Join([]string{`&Fee{`, + `Amount:` + repeatedStringForAmount + `,`, + `GasLimit:` + fmt.Sprintf("%v", this.GasLimit) + `,`, + `}`, + }, "") + return s +} +func (this *CompactBitArray) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&CompactBitArray{`, + `ExtraBitsStored:` + fmt.Sprintf("%v", this.ExtraBitsStored) + `,`, + `Elems:` + fmt.Sprintf("%v", this.Elems) + `,`, + `}`, + }, "") + return s +} +func valueToStringTypes(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Coin) 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 ErrIntOverflowTypes + } + 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: Coin: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Coin: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DecCoin) 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 ErrIntOverflowTypes + } + 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: DecCoin: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DecCoin: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntProto) 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 ErrIntOverflowTypes + } + 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: IntProto: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DecProto) 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 ErrIntOverflowTypes + } + 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: DecProto: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValAddresses) 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 ErrIntOverflowTypes + } + 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: ValAddresses: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx)) + copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GasInfo) 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 ErrIntOverflowTypes + } + 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: GasInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GasInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) + } + m.GasWanted = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasWanted |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) + } + m.GasUsed = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasUsed |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Result) 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 ErrIntOverflowTypes + } + 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: Result: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Result: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Log = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Events = append(m.Events, types.Event{}) + if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SimulationResponse) 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 ErrIntOverflowTypes + } + 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: SimulationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SimulationResponse: 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 ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + 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 ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Result == nil { + m.Result = &Result{} + } + if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Tx) 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 ErrIntOverflowTypes + } + 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: Tx: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Tx: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Body == nil { + m.Body = &TxBody{} + } + if err := m.Body.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.AuthInfo == nil { + m.AuthInfo = &AuthInfo{} + } + if err := m.AuthInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) + copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignDoc) 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 ErrIntOverflowTypes + } + 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: SignDoc: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignDoc: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Body == nil { + m.Body = &TxBody{} + } + if err := m.Body.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.AuthInfo == nil { + m.AuthInfo = &AuthInfo{} + } + if err := m.AuthInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) + } + m.AccountNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountNumber |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountSequence", wireType) + } + m.AccountSequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountSequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy } } - return n -} - -func (m *SimulationResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.GasInfo.Size() - n += 1 + l + sovTypes(uint64(l)) - if m.Result != nil { - l = m.Result.Size() - n += 1 + l + sovTypes(uint64(l)) - } - return n -} -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *ValAddresses) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ValAddresses{`, - `Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`, - `}`, - }, "") - return s -} -func valueToStringTypes(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" + if iNdEx > l { + return io.ErrUnexpectedEOF } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) + return nil } -func (m *Coin) Unmarshal(dAtA []byte) error { +func (m *TxBody) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -974,17 +3775,17 @@ func (m *Coin) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Coin: wiretype end group for non-group") + return fmt.Errorf("proto: TxBody: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Coin: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: TxBody: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Messages", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -994,27 +3795,29 @@ func (m *Coin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + m.Messages = append(m.Messages, &types1.Any{}) + if err := m.Messages[len(m.Messages)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1042,7 +3845,58 @@ func (m *Coin) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Memo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutHeight", wireType) + } + m.TimeoutHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 1023: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExtensionOptions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExtensionOptions = append(m.ExtensionOptions, &types1.Any{}) + if err := m.ExtensionOptions[len(m.ExtensionOptions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1070,7 +3924,7 @@ func (m *Coin) Unmarshal(dAtA []byte) error { } return nil } -func (m *DecCoin) Unmarshal(dAtA []byte) error { +func (m *AuthInfo) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1093,17 +3947,17 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: DecCoin: wiretype end group for non-group") + return fmt.Errorf("proto: AuthInfo: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: DecCoin: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: AuthInfo: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SignerInfos", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1113,29 +3967,31 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + m.SignerInfos = append(m.SignerInfos, &SignerInfo{}) + if err := m.SignerInfos[len(m.SignerInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1145,23 +4001,150 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Fee == nil { + m.Fee = &Fee{} + } + if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignerInfo) 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 ErrIntOverflowTypes + } + 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: SignerInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignerInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PublicKey == nil { + m.PublicKey = &types1.Any{} + } + if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModeInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.ModeInfo == nil { + m.ModeInfo = &ModeInfo{} + } + if err := m.ModeInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1189,7 +4172,7 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { } return nil } -func (m *IntProto) Unmarshal(dAtA []byte) error { +func (m *ModeInfo) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1212,17 +4195,17 @@ func (m *IntProto) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: IntProto: wiretype end group for non-group") + return fmt.Errorf("proto: ModeInfo: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ModeInfo: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Single", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1232,84 +4215,32 @@ func (m *IntProto) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + v := &ModeInfo_Single{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } + m.Sum = &ModeInfo_Single_{v} iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DecProto) 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 ErrIntOverflowTypes - } - 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: DecProto: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Multi", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1319,25 +4250,26 @@ func (m *DecProto) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + v := &ModeInfo_Multi{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } + m.Sum = &ModeInfo_Multi_{v} iNdEx = postIndex default: iNdEx = preIndex @@ -1363,7 +4295,7 @@ func (m *DecProto) Unmarshal(dAtA []byte) error { } return nil } -func (m *ValAddresses) Unmarshal(dAtA []byte) error { +func (m *ModeInfo_Single) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1386,17 +4318,17 @@ func (m *ValAddresses) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ValAddresses: wiretype end group for non-group") + return fmt.Errorf("proto: Single: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Single: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Mode", wireType) } - var byteLen int + m.Mode = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1406,24 +4338,11 @@ func (m *ValAddresses) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + m.Mode |= SignMode(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx)) - copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -1448,7 +4367,7 @@ func (m *ValAddresses) Unmarshal(dAtA []byte) error { } return nil } -func (m *GasInfo) Unmarshal(dAtA []byte) error { +func (m *ModeInfo_Multi) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1471,17 +4390,17 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: GasInfo: wiretype end group for non-group") + return fmt.Errorf("proto: Multi: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: GasInfo: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Multi: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bitarray", wireType) } - m.GasWanted = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1491,16 +4410,33 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.GasWanted |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Bitarray == nil { + m.Bitarray = &CompactBitArray{} + } + if err := m.Bitarray.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModeInfos", wireType) } - m.GasUsed = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1510,11 +4446,26 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.GasUsed |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ModeInfos = append(m.ModeInfos, &ModeInfo{}) + if err := m.ModeInfos[len(m.ModeInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -1539,7 +4490,7 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { } return nil } -func (m *Result) Unmarshal(dAtA []byte) error { +func (m *Fee) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1562,17 +4513,17 @@ func (m *Result) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Result: wiretype end group for non-group") + return fmt.Errorf("proto: Fee: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Result: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Fee: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - var byteLen int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1582,63 +4533,31 @@ func (m *Result) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + byteLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} + m.Amount = append(m.Amount, Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Log = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasLimit", wireType) } - var msglen int + m.GasLimit = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1648,26 +4567,11 @@ func (m *Result) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.GasLimit |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Events = append(m.Events, types.Event{}) - if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -1692,7 +4596,7 @@ func (m *Result) Unmarshal(dAtA []byte) error { } return nil } -func (m *SimulationResponse) Unmarshal(dAtA []byte) error { +func (m *CompactBitArray) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1715,17 +4619,17 @@ func (m *SimulationResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: SimulationResponse: wiretype end group for non-group") + return fmt.Errorf("proto: CompactBitArray: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: SimulationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: CompactBitArray: 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) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExtraBitsStored", wireType) } - var msglen int + m.ExtraBitsStored = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1735,30 +4639,16 @@ func (m *SimulationResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.ExtraBitsStored |= uint32(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - 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) + return fmt.Errorf("proto: wrong wireType = %d for field Elems", wireType) } - var msglen int + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1768,26 +4658,24 @@ func (m *SimulationResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + if byteLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Result == nil { - m.Result = &Result{} - } - if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + m.Elems = append(m.Elems[:0], dAtA[iNdEx:postIndex]...) + if m.Elems == nil { + m.Elems = []byte{} } iNdEx = postIndex default: diff --git a/types/types.proto b/types/types.proto index c26219caa789..79fa5d1b53d4 100644 --- a/types/types.proto +++ b/types/types.proto @@ -3,6 +3,7 @@ package cosmos_sdk.v1; import "third_party/proto/gogoproto/gogo.proto"; import "third_party/proto/tendermint/abci/types/types.proto"; +import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/types"; option (gogoproto.goproto_stringer_all) = false; @@ -78,3 +79,114 @@ message SimulationResponse { GasInfo gas_info = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; Result result = 2; } + +message Tx { + option (gogoproto.stringer) = true; + + TxBody body = 1; + AuthInfo auth_info = 2; + repeated bytes signatures = 3; +} + +message SignDoc { + option (gogoproto.stringer) = true; + + TxBody body = 1; + AuthInfo auth_info = 2; + string chain_id = 3; + uint64 account_number = 4; + // account_sequence starts at 1 rather than 0 to avoid the case where + // the default 0 value must be omitted in protobuf serialization + uint64 account_sequence = 5; +} + +message TxBody { + option (gogoproto.stringer) = true; + + repeated google.protobuf.Any messages = 1; + string memo = 2; + int64 timeout_height = 3; + repeated google.protobuf.Any extension_options = 1023; +} + +message AuthInfo { + option (gogoproto.stringer) = true; + + repeated SignerInfo signer_infos = 1; + // The first signer is the primary signer and the one which pays the fee + Fee fee = 2; +} + +message SignerInfo { + option (gogoproto.stringer) = true; + + // PublicKey key is optional for accounts that already exist in state + google.protobuf.Any public_key = 1; + // ModeInfo describes the signing mode of the signer and is a nested + // structure to support nested multisig pubkey's + ModeInfo mode_info = 2; +} + +message ModeInfo { + option (gogoproto.stringer) = true; + + oneof sum { + Single single = 1; + Multi multi = 2; + } + + // Single is the mode info for a single signer. It is structured as a message + // to allow for additional fields such as locale for SIGN_MODE_TEXTUAL in the future + message Single { + option (gogoproto.stringer) = true; + + SignMode mode = 1; + } + + // Multi is the mode info for a multisig public key + message Multi { + option (gogoproto.stringer) = true; + + // bitarray specifies which keys within the multisig are signing + CompactBitArray bitarray = 1; + // mode_infos is the corresponding modes of the signers of the multisig + // which could include nested multisig public keys + repeated ModeInfo mode_infos = 2; + } +} + +enum SignMode { + SIGN_MODE_UNSPECIFIED = 0; + + SIGN_MODE_DIRECT = 1; + + SIGN_MODE_TEXTUAL = 2; + + SIGN_MODE_LEGACY_AMINO_JSON = 127; +} + +// Fee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +message Fee { + option (gogoproto.goproto_getters) = false; + option (gogoproto.equal) = true; + option (gogoproto.stringer) = true; + + repeated Coin amount = 1 + [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "Coins"]; + uint64 gas_limit = 2; +} + +// CompactBitArray is an implementation of a space efficient bit array. +// This is used to ensure that the encoded data takes up a minimal amount of +// space after proto encoding. +// This is not thread safe, and is not intended for concurrent usage. +message CompactBitArray { +// option (gogoproto.sizer) = false; +// option (gogoproto.goproto_stringer) = false; + option (gogoproto.stringer) = true; + + uint32 extra_bits_stored = 1; + bytes elems = 2; +} diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 9278caff2b0d..6157298eaaa5 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -21,13 +21,13 @@ import ( ) // run the tx through the anteHandler and ensure its valid -func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool) { +func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.TxI, simulate bool) { _, err := anteHandler(ctx, tx, simulate) require.Nil(t, err) } // run the tx through the anteHandler and ensure it fails with the given code -func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool, expErr error) { +func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.TxI, simulate bool, expErr error) { _, err := anteHandler(ctx, tx, simulate) require.NotNil(t, err) require.True(t, errors.Is(expErr, err)) @@ -63,7 +63,7 @@ func TestSimulateGasCost(t *testing.T) { require.NoError(t, err) // set up msgs and fee - var tx sdk.Tx + var tx sdk.TxI msg1 := types.NewTestMsg(addr1, addr2) msg2 := types.NewTestMsg(addr3, addr1) msg3 := types.NewTestMsg(addr2, addr3) @@ -100,7 +100,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { priv3, _, addr3 := types.KeyTestPubAddr() // msg and signatures - var tx sdk.Tx + var tx sdk.TxI msg1 := types.NewTestMsg(addr1, addr2) msg2 := types.NewTestMsg(addr1, addr3) fee := types.NewTestStdFee() @@ -161,7 +161,7 @@ func TestAnteHandlerAccountNumbers(t *testing.T) { require.NoError(t, err) // msg and signatures - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) fee := types.NewTestStdFee() @@ -219,7 +219,7 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) { require.NoError(t, err) // msg and signatures - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) fee := types.NewTestStdFee() @@ -281,7 +281,7 @@ func TestAnteHandlerSequences(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr3, types.NewTestCoins()) // msg and signatures - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) fee := types.NewTestStdFee() @@ -345,7 +345,7 @@ func TestAnteHandlerFees(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc1) // msg and signatures - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := types.NewTestStdFee() @@ -388,7 +388,7 @@ func TestAnteHandlerMemoGas(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc1) // msg and signatures - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := types.NewStdFee(0, sdk.NewCoins(sdk.NewInt64Coin("atom", 0))) @@ -439,7 +439,7 @@ func TestAnteHandlerMultiSigner(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr3, types.NewTestCoins()) // set up msgs and fee - var tx sdk.Tx + var tx sdk.TxI msg1 := types.NewTestMsg(addr1, addr2) msg2 := types.NewTestMsg(addr3, addr1) msg3 := types.NewTestMsg(addr2, addr3) @@ -483,7 +483,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc2) app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins()) - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) msgs := []sdk.Msg{msg} fee := types.NewTestStdFee() @@ -560,7 +560,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc2) app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins()) - var tx sdk.Tx + var tx sdk.TxI // test good tx and set public key msg := types.NewTestMsg(addr1) @@ -685,7 +685,7 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr, types.NewTestCoins()) } - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8) msgs := []sdk.Msg{msg} fee := types.NewTestStdFee() @@ -719,7 +719,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc1) app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 150))) - var tx sdk.Tx + var tx sdk.TxI msg := types.NewTestMsg(addr1) privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := types.NewTestStdFee() diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 41ba96d8bb73..5fc4c223080a 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -25,7 +25,7 @@ func NewValidateBasicDecorator() ValidateBasicDecorator { return ValidateBasicDecorator{} } -func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { // no need to validate basic on recheck tx, call next antehandler if ctx.IsReCheckTx() { return next(ctx, tx, simulate) @@ -40,7 +40,7 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat // Tx must have GetMemo() method to use ValidateMemoDecorator type TxWithMemo interface { - sdk.Tx + sdk.TxI GetMemo() string } @@ -57,7 +57,7 @@ func NewValidateMemoDecorator(ak AccountKeeper) ValidateMemoDecorator { } } -func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { memoTx, ok := tx.(TxWithMemo) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") @@ -95,7 +95,7 @@ func NewConsumeGasForTxSizeDecorator(ak AccountKeeper) ConsumeTxSizeGasDecorator } } -func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 5b1044c58664..85d7ee05c665 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -15,7 +15,7 @@ var ( // FeeTx defines the interface to be implemented by Tx to use the FeeDecorators type FeeTx interface { - sdk.Tx + sdk.TxI GetGas() uint64 GetFee() sdk.Coins FeePayer() sdk.AccAddress @@ -33,7 +33,7 @@ func NewMempoolFeeDecorator() MempoolFeeDecorator { return MempoolFeeDecorator{} } -func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { feeTx, ok := tx.(FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") @@ -82,7 +82,7 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper) DeductFeeDecor } } -func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { feeTx, ok := tx.(FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 1e3e8eb68d67..57246cdf8268 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -14,7 +14,7 @@ var ( // GasTx defines a Tx with a GetGas() method which is needed to use SetUpContextDecorator type GasTx interface { - sdk.Tx + sdk.TxI GetGas() uint64 } @@ -29,7 +29,7 @@ func NewSetUpContextDecorator() SetUpContextDecorator { return SetUpContextDecorator{} } -func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { // all transactions must implement GasTx gasTx, ok := tx.(GasTx) if !ok { diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index 698a0ecedbd1..c2ee4287541e 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -80,7 +80,7 @@ func TestRecoverPanic(t *testing.T) { type OutOfGasDecorator struct{} // AnteDecorator that will throw OutOfGas panic -func (ogd OutOfGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (ogd OutOfGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { overLimit := ctx.GasMeter().Limit() + 1 // Should panic with outofgas error @@ -92,6 +92,6 @@ func (ogd OutOfGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo type PanicDecorator struct{} -func (pd PanicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (pd PanicDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { panic("random error") } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 93ae0f3b4ae4..2aebf1401cee 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -37,7 +37,7 @@ type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pub // SigVerifiableTx defines a Tx interface for all signature verification decorators type SigVerifiableTx interface { - sdk.Tx + sdk.TxI GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place @@ -57,7 +57,7 @@ func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { } } -func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") @@ -114,7 +114,7 @@ func NewSigGasConsumeDecorator(ak AccountKeeper, sigGasConsumer SignatureVerific } } -func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") @@ -167,7 +167,7 @@ func NewSigVerificationDecorator(ak AccountKeeper) SigVerificationDecorator { } } -func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { // no need to verify signatures on recheck tx if ctx.IsReCheckTx() { return next(ctx, tx, simulate) @@ -234,7 +234,7 @@ func NewIncrementSequenceDecorator(ak AccountKeeper) IncrementSequenceDecorator } } -func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { // no need to increment sequence on RecheckTx if ctx.IsReCheckTx() && !simulate { return next(ctx, tx, simulate) @@ -272,7 +272,7 @@ func NewValidateSigCountDecorator(ak AccountKeeper) ValidateSigCountDecorator { } } -func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") diff --git a/x/auth/client/query.go b/x/auth/client/query.go index 85bd747bc3c5..c16776a08e37 100644 --- a/x/auth/client/query.go +++ b/x/auth/client/query.go @@ -169,7 +169,7 @@ func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.R return sdk.NewResponseResultTx(resTx, tx, resBlock.Block.Time.Format(time.RFC3339)), nil } -func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { +func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.TxI, error) { var tx types.StdTx err := cdc.UnmarshalBinaryBare(txBytes, &tx) diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index ab2ce267ece3..970f39a6b1d0 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -103,7 +103,7 @@ func TestDefaultTxEncoder(t *testing.T) { func TestConfiguredTxEncoder(t *testing.T) { cdc := makeCodec() - customEncoder := func(tx sdk.Tx) ([]byte, error) { + customEncoder := func(tx sdk.TxI) ([]byte, error) { return json.Marshal(tx) } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 16d7f319408b..efa7a03a0a53 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -140,9 +140,9 @@ func CountSubKeys(pub crypto.PubKey) int { // DEPRECATED // --------------------------------------------------------------------------- -var _ sdk.Tx = (*StdTx)(nil) +var _ sdk.TxI = (*StdTx)(nil) -// StdTx is a standard way to wrap a Msg with Fee and Signatures. +// StdTx is a standard way to wrap a Msg with FeeI and Signatures. // NOTE: the first signature is the fee payer (Signatures must not be nil). type StdTx struct { Msgs []sdk.Msg `json:"msg" yaml:"msg"` @@ -319,7 +319,7 @@ type StdSignature struct { // DefaultTxDecoder logic for standard transaction decoding func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { - return func(txBytes []byte) (sdk.Tx, error) { + return func(txBytes []byte) (sdk.TxI, error) { var tx = StdTx{} if len(txBytes) == 0 { @@ -339,7 +339,7 @@ func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { // DefaultTxEncoder logic for standard transaction encoding func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder { - return func(tx sdk.Tx) ([]byte, error) { + return func(tx sdk.TxI) ([]byte, error) { return cdc.MarshalBinaryBare(tx) } } diff --git a/x/auth/types/test_utils.go b/x/auth/types/test_utils.go index 4c0d801af377..15c724587bec 100644 --- a/x/auth/types/test_utils.go +++ b/x/auth/types/test_utils.go @@ -31,7 +31,7 @@ func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { return key, pub, addr } -func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx { +func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.TxI { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "") @@ -48,7 +48,7 @@ func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums return tx } -func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx { +func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.TxI { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo) @@ -65,7 +65,7 @@ func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, return tx } -func NewTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.Tx { +func NewTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.TxI { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { sig, err := priv.Sign(signBytes) diff --git a/x/genutil/client/rest/query.go b/x/genutil/client/rest/query.go index 0159223e8e7c..b737443fc2bf 100644 --- a/x/genutil/client/rest/query.go +++ b/x/genutil/client/rest/query.go @@ -32,7 +32,7 @@ func QueryGenesisTxs(cliCtx context.CLIContext, w http.ResponseWriter) { } genState := types.GetGenesisStateFromAppState(cliCtx.Codec, appState) - genTxs := make([]sdk.Tx, len(genState.GenTxs)) + genTxs := make([]sdk.TxI, len(genState.GenTxs)) for i, tx := range genState.GenTxs { err := cliCtx.Codec.UnmarshalJSON(tx, &genTxs[i]) if err != nil { diff --git a/x/ibc/ante/ante.go b/x/ibc/ante/ante.go index 82484be5a32e..b542bd886ef2 100644 --- a/x/ibc/ante/ante.go +++ b/x/ibc/ante/ante.go @@ -25,7 +25,7 @@ func NewProofVerificationDecorator(clientKeeper client.Keeper, channelKeeper cha // AnteHandle executes MsgUpdateClient, MsgPacket, MsgAcknowledgement, MsgTimeout. // The packet execution messages are then passed to the respective application handlers. -func (pvr ProofVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (pvr ProofVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { for _, msg := range tx.GetMsgs() { var err error switch msg := msg.(type) { diff --git a/x/ibc/ante/ante_test.go b/x/ibc/ante/ante_test.go index 11cf8047ee8a..2e113f97966b 100644 --- a/x/ibc/ante/ante_test.go +++ b/x/ibc/ante/ante_test.go @@ -74,7 +74,7 @@ func queryProof(chain *TestChain, key string) (proof commitmenttypes.MerkleProof return } -func (suite *HandlerTestSuite) newTx(msg sdk.Msg) sdk.Tx { +func (suite *HandlerTestSuite) newTx(msg sdk.Msg) sdk.TxI { return authtypes.StdTx{ Msgs: []sdk.Msg{msg}, } From 43086239fc9e2ad6e6480ed065dffa905711cbe4 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 13:34:12 -0400 Subject: [PATCH 02/54] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5eaf5478da0..1ca9c8ec80c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,7 @@ information on how to implement the new `Keyring` interface. * [\#5858](https://github.com/cosmos/cosmos-sdk/pull/5858) Make Keyring store keys by name and address's hexbytes representation. * (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Remove APIs for getting and setting `x/evidence` parameters. `BaseApp` now uses a `ParamStore` to manage Tendermint consensus parameters which is managed via the `x/params` `Substore` type. * (export) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) `AppExporter` now returns ABCI consensus parameters to be included in marshaled exported state. These parameters must be returned from the application via the `BaseApp`. +* (types) [\#6214](https://github.com/cosmos/cosmos-sdk/pull/6214) `Tx` and `Fee` interfaces were renamed to `TxI` and `FeeI` respectively ### Features From d8703ef9d923fc71eeef62c8acfdaa0f02c4b11c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 13:49:42 -0400 Subject: [PATCH 03/54] Add proto doc strings --- types/types.proto | 63 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/types/types.proto b/types/types.proto index 79fa5d1b53d4..252f0e45f410 100644 --- a/types/types.proto +++ b/types/types.proto @@ -80,49 +80,91 @@ message SimulationResponse { Result result = 2; } +// Tx is the standard type used for broadcasting transactions message Tx { option (gogoproto.stringer) = true; + // body is the processable content of the transaction TxBody body = 1; + + // auth_info is the authorization related content of the transaction, specifically + // signers, signer modes and fee AuthInfo auth_info = 2; + + // signatures are the raw binary signatures of signers specified by body and auth_info repeated bytes signatures = 3; } +// SignDoc is the standard type used for signing transaction in SIGN_MODE_DIRECT message SignDoc { option (gogoproto.stringer) = true; + // body is the TxBody from Tx TxBody body = 1; + + // auth_info is the AuthInfo from Tx AuthInfo auth_info = 2; + + // chain_id is the unique identifier of the chain this transaction targets. + // It prevents signed transactions from being used on another chain by an + // attacker string chain_id = 3; + + // account_number is the account number of the account in state uint64 account_number = 4; + // account_sequence starts at 1 rather than 0 to avoid the case where // the default 0 value must be omitted in protobuf serialization uint64 account_sequence = 5; } +// TxBody is the body of a transaction that all signers sign over message TxBody { option (gogoproto.stringer) = true; + // messages are the processable content of the transaction repeated google.protobuf.Any messages = 1; + + // memo is any arbitrary memo to be added to the transaction string memo = 2; + + // timeout is the block height after which this transaction will not + // be processed by the chain int64 timeout_height = 3; + + // extension_options are arbitrary options that can be added by chains + // when the default options are not sufficient. If any of these are present + // and can't be handled, the transaction will be rejected repeated google.protobuf.Any extension_options = 1023; + + // extension_options are arbitrary options that can be added by chains + // when the default options are not sufficient. If any of these are present + // and can't be handled, they will be ignored + repeated google.protobuf.Any non_critical_extension_options = 2047; } +// AuthInfo describes the fee and signer modes that are used to sign a transaction message AuthInfo { option (gogoproto.stringer) = true; + // signer_infos is the list of signer infos which corresponds with + // Tx.signatures and expected signers derived from TxBody.messages. All signers + // are expected to occur in the same order in each of these locations repeated SignerInfo signer_infos = 1; - // The first signer is the primary signer and the one which pays the fee + + // Fee is the fee and gas limit for the transaction. The first signer is the + // primary signer and the one which pays the fee Fee fee = 2; } message SignerInfo { option (gogoproto.stringer) = true; - // PublicKey key is optional for accounts that already exist in state + // public_key is the public key of the signer. It is optional for accounts + // that already exist in state google.protobuf.Any public_key = 1; - // ModeInfo describes the signing mode of the signer and is a nested + + // mode_info describes the signing mode of the signer and is a nested // structure to support nested multisig pubkey's ModeInfo mode_info = 2; } @@ -131,6 +173,7 @@ message ModeInfo { option (gogoproto.stringer) = true; oneof sum { + // single is a Single single = 1; Multi multi = 2; } @@ -140,6 +183,7 @@ message ModeInfo { message Single { option (gogoproto.stringer) = true; + // mode is the signing mode of the single signer SignMode mode = 1; } @@ -149,19 +193,28 @@ message ModeInfo { // bitarray specifies which keys within the multisig are signing CompactBitArray bitarray = 1; + // mode_infos is the corresponding modes of the signers of the multisig // which could include nested multisig public keys repeated ModeInfo mode_infos = 2; } } +// SignMode represents a signing mode with its own security guarantees enum SignMode { + // SIGN_MODE_UNSPECIFIED specifies an unknown signing mode and will be rejected SIGN_MODE_UNSPECIFIED = 0; + // SIGN_MODE_DIRECT specifies a signing mode which uses SignDoc and is verified + // with raw bytes from Tx SIGN_MODE_DIRECT = 1; + // SIGN_MODE_TEXTUAL is a future signing mode that will verify some human-readable + // textual representation on top of the binary representation from SIGN_MODE_DIRECT SIGN_MODE_TEXTUAL = 2; + // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses + // Amino JSON and will be removed in the future SIGN_MODE_LEGACY_AMINO_JSON = 127; } @@ -173,8 +226,12 @@ message Fee { option (gogoproto.equal) = true; option (gogoproto.stringer) = true; + // amount is the amount of coins to be paid as a fee repeated Coin amount = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "Coins"]; + + // gas_limit is the maximum gas that can be used in transaction processing + // before an out of gas error occurs uint64 gas_limit = 2; } From 4a889c8e403dcbcbbfbd6c436f3911559f6e34fc Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 13:52:43 -0400 Subject: [PATCH 04/54] Add proto doc strings --- types/types.proto | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/types.proto b/types/types.proto index 252f0e45f410..e897630b3e9d 100644 --- a/types/types.proto +++ b/types/types.proto @@ -157,6 +157,7 @@ message AuthInfo { Fee fee = 2; } +// SignerInfo describes the public key and signing mode of a single top-level signer message SignerInfo { option (gogoproto.stringer) = true; @@ -169,12 +170,16 @@ message SignerInfo { ModeInfo mode_info = 2; } +// ModeInfo describes the signing mode of a single or nested multisig signer message ModeInfo { option (gogoproto.stringer) = true; + // sum is the oneof that specifies whether this represents a single or nested + // multisig signer oneof sum { - // single is a + // single represents a single signer Single single = 1; + // multi represents a nested multisig signer Multi multi = 2; } From 7f09389987ba915771869cf1a399c18a4a64ed09 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 14:10:30 -0400 Subject: [PATCH 05/54] ws --- types/types.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/types/types.proto b/types/types.proto index e897630b3e9d..6614897b3ea5 100644 --- a/types/types.proto +++ b/types/types.proto @@ -178,6 +178,7 @@ message ModeInfo { // multisig signer oneof sum { // single represents a single signer + Single single = 1; // multi represents a nested multisig signer Multi multi = 2; From b695a248434330410b4b6dd3900da33e1533f1b0 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 14:10:47 -0400 Subject: [PATCH 06/54] ws --- types/types.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/types.proto b/types/types.proto index 6614897b3ea5..70e360b861be 100644 --- a/types/types.proto +++ b/types/types.proto @@ -178,8 +178,8 @@ message ModeInfo { // multisig signer oneof sum { // single represents a single signer - Single single = 1; + // multi represents a nested multisig signer Multi multi = 2; } From 4818e1b237b650da63490408e5b972f0eb45617d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 13 May 2020 15:58:00 -0400 Subject: [PATCH 07/54] Implement SIGN_MODE_DIRECT for single signer mode --- types/tx.go | 45 ++++++ types/types.pb.go | 302 +++++++++++++++++++++++++++------------ x/auth/ante/sigverify.go | 4 +- x/auth/ante/tx.go | 195 +++++++++++++++++++++++++ x/auth/ante/types.proto | 27 ++++ x/auth/types/stdtx.go | 4 +- 6 files changed, 481 insertions(+), 96 deletions(-) create mode 100644 types/tx.go create mode 100644 x/auth/ante/tx.go create mode 100644 x/auth/ante/types.proto diff --git a/types/tx.go b/types/tx.go new file mode 100644 index 000000000000..1b8312066c01 --- /dev/null +++ b/types/tx.go @@ -0,0 +1,45 @@ +package types + +import ( + "github.com/tendermint/tendermint/crypto" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +) + +var _ codectypes.UnpackInterfacesMessage = &Tx{} +var _ codectypes.UnpackInterfacesMessage = &TxBody{} +var _ codectypes.UnpackInterfacesMessage = &SignDoc{} + +func (m *Tx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + return m.Body.UnpackInterfaces(unpacker) +} + +func (m *SignDoc) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + return m.Body.UnpackInterfaces(unpacker) +} + +func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, any := range m.Messages { + var msg Msg + err := unpacker.UnpackAny(any, &msg) + if err != nil { + return err + } + } + return nil +} + +func (m *SignerInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var pubkey crypto.PubKey + return unpacker.UnpackAny(m.PublicKey, &pubkey) +} + +func (m *AuthInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, si := range m.SignerInfos { + err := si.UnpackInterfaces(unpacker) + if err != nil { + return err + } + } + return nil +} diff --git a/types/types.pb.go b/types/types.pb.go index 01184a4d631b..9201610e0d80 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -27,12 +27,20 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// SignMode represents a signing mode with its own security guarantees type SignMode int32 const ( - SignMode_SIGN_MODE_UNSPECIFIED SignMode = 0 - SignMode_SIGN_MODE_DIRECT SignMode = 1 - SignMode_SIGN_MODE_TEXTUAL SignMode = 2 + // SIGN_MODE_UNSPECIFIED specifies an unknown signing mode and will be rejected + SignMode_SIGN_MODE_UNSPECIFIED SignMode = 0 + // SIGN_MODE_DIRECT specifies a signing mode which uses SignDoc and is verified + // with raw bytes from Tx + SignMode_SIGN_MODE_DIRECT SignMode = 1 + // SIGN_MODE_TEXTUAL is a future signing mode that will verify some human-readable + // textual representation on top of the binary representation from SIGN_MODE_DIRECT + SignMode_SIGN_MODE_TEXTUAL SignMode = 2 + // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses + // Amino JSON and will be removed in the future SignMode_SIGN_MODE_LEGACY_AMINO_JSON SignMode = 127 ) @@ -416,10 +424,15 @@ func (m *SimulationResponse) GetResult() *Result { return nil } +// Tx is the standard type used for broadcasting transactions type Tx struct { - Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` - AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` - Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` + // body is the processable content of the transaction + Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` + // auth_info is the authorization related content of the transaction, specifically + // signers, signer modes and fee + AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` + // signatures are the raw binary signatures of signers specified by body and auth_info + Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` } func (m *Tx) Reset() { *m = Tx{} } @@ -475,11 +488,18 @@ func (m *Tx) GetSignatures() [][]byte { return nil } +// SignDoc is the standard type used for signing transaction in SIGN_MODE_DIRECT type SignDoc struct { - Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` - AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` - ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - AccountNumber uint64 `protobuf:"varint,4,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` + // body is the TxBody from Tx + Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` + // auth_info is the AuthInfo from Tx + AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` + // chain_id is the unique identifier of the chain this transaction targets. + // It prevents signed transactions from being used on another chain by an + // attacker + ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // account_number is the account number of the account in state + AccountNumber uint64 `protobuf:"varint,4,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` // account_sequence starts at 1 rather than 0 to avoid the case where // the default 0 value must be omitted in protobuf serialization AccountSequence uint64 `protobuf:"varint,5,opt,name=account_sequence,json=accountSequence,proto3" json:"account_sequence,omitempty"` @@ -552,11 +572,23 @@ func (m *SignDoc) GetAccountSequence() uint64 { return 0 } +// TxBody is the body of a transaction that all signers sign over type TxBody struct { - Messages []*types1.Any `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` - Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"` - TimeoutHeight int64 `protobuf:"varint,3,opt,name=timeout_height,json=timeoutHeight,proto3" json:"timeout_height,omitempty"` + // messages are the processable content of the transaction + Messages []*types1.Any `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` + // memo is any arbitrary memo to be added to the transaction + Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"` + // timeout is the block height after which this transaction will not + // be processed by the chain + TimeoutHeight int64 `protobuf:"varint,3,opt,name=timeout_height,json=timeoutHeight,proto3" json:"timeout_height,omitempty"` + // extension_options are arbitrary options that can be added by chains + // when the default options are not sufficient. If any of these are present + // and can't be handled, the transaction will be rejected ExtensionOptions []*types1.Any `protobuf:"bytes,1023,rep,name=extension_options,json=extensionOptions,proto3" json:"extension_options,omitempty"` + // extension_options are arbitrary options that can be added by chains + // when the default options are not sufficient. If any of these are present + // and can't be handled, they will be ignored + NonCriticalExtensionOptions []*types1.Any `protobuf:"bytes,2047,rep,name=non_critical_extension_options,json=nonCriticalExtensionOptions,proto3" json:"non_critical_extension_options,omitempty"` } func (m *TxBody) Reset() { *m = TxBody{} } @@ -619,9 +651,21 @@ func (m *TxBody) GetExtensionOptions() []*types1.Any { return nil } +func (m *TxBody) GetNonCriticalExtensionOptions() []*types1.Any { + if m != nil { + return m.NonCriticalExtensionOptions + } + return nil +} + +// AuthInfo describes the fee and signer modes that are used to sign a transaction type AuthInfo struct { + // signer_infos is the list of signer infos which corresponds with + // Tx.signatures and expected signers derived from TxBody.messages. All signers + // are expected to occur in the same order in each of these locations SignerInfos []*SignerInfo `protobuf:"bytes,1,rep,name=signer_infos,json=signerInfos,proto3" json:"signer_infos,omitempty"` - // The first signer is the primary signer and the one which pays the fee + // Fee is the fee and gas limit for the transaction. The first signer is the + // primary signer and the one which pays the fee Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` } @@ -671,10 +715,12 @@ func (m *AuthInfo) GetFee() *Fee { return nil } +// SignerInfo describes the public key and signing mode of a single top-level signer type SignerInfo struct { - // PublicKey key is optional for accounts that already exist in state + // public_key is the public key of the signer. It is optional for accounts + // that already exist in state PublicKey *types1.Any `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` - // ModeInfo describes the signing mode of the signer and is a nested + // mode_info describes the signing mode of the signer and is a nested // structure to support nested multisig pubkey's ModeInfo *ModeInfo `protobuf:"bytes,2,opt,name=mode_info,json=modeInfo,proto3" json:"mode_info,omitempty"` } @@ -725,7 +771,11 @@ func (m *SignerInfo) GetModeInfo() *ModeInfo { return nil } +// ModeInfo describes the signing mode of a single or nested multisig signer type ModeInfo struct { + // sum is the oneof that specifies whether this represents a single or nested + // multisig signer + // // Types that are valid to be assigned to Sum: // *ModeInfo_Single_ // *ModeInfo_Multi_ @@ -812,6 +862,7 @@ func (*ModeInfo) XXX_OneofWrappers() []interface{} { // Single is the mode info for a single signer. It is structured as a message // to allow for additional fields such as locale for SIGN_MODE_TEXTUAL in the future type ModeInfo_Single struct { + // mode is the signing mode of the single signer Mode SignMode `protobuf:"varint,1,opt,name=mode,proto3,enum=cosmos_sdk.v1.SignMode" json:"mode,omitempty"` } @@ -913,7 +964,10 @@ func (m *ModeInfo_Multi) GetModeInfos() []*ModeInfo { // gas to be used by the transaction. The ratio yields an effective "gasprice", // which must be above some miminum to be accepted into the mempool. type Fee struct { - Amount Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=Coins" json:"amount"` + // amount is the amount of coins to be paid as a fee + Amount Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=Coins" json:"amount"` + // gas_limit is the maximum gas that can be used in transaction processing + // before an out of gas error occurs GasLimit uint64 `protobuf:"varint,2,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"` } @@ -1029,81 +1083,83 @@ func init() { func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } var fileDescriptor_2c0f90c600ad7e2e = []byte{ - // 1181 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4d, 0x73, 0x1b, 0x45, - 0x13, 0xd6, 0x5a, 0xb2, 0x2c, 0xb7, 0xe5, 0x58, 0x9e, 0xc4, 0xef, 0x2b, 0x3b, 0x44, 0x72, 0x89, - 0x8f, 0x4a, 0x02, 0x59, 0x81, 0x13, 0x28, 0x4a, 0xe1, 0xa2, 0xb5, 0x14, 0x47, 0x21, 0xb6, 0x53, - 0x23, 0x07, 0x08, 0x97, 0xad, 0xd5, 0xee, 0x78, 0x35, 0x15, 0xed, 0x8e, 0xd8, 0x99, 0x0d, 0xd1, - 0x81, 0x22, 0xdc, 0xa8, 0xe2, 0xc2, 0x4f, 0xc8, 0x99, 0x3f, 0xc1, 0x35, 0xdc, 0x72, 0x4c, 0x51, - 0x60, 0xc0, 0xbe, 0x70, 0xce, 0x91, 0x0b, 0xd4, 0x7c, 0xc8, 0x22, 0x32, 0xce, 0x81, 0x2a, 0x2e, - 0xab, 0x9e, 0xee, 0x67, 0xfa, 0xe3, 0x99, 0x9e, 0x1e, 0xc1, 0xb2, 0x18, 0x0d, 0x09, 0xaf, 0xab, - 0xaf, 0x3d, 0x4c, 0x98, 0x60, 0x68, 0xd1, 0x67, 0x3c, 0x62, 0xdc, 0xe5, 0xc1, 0x7d, 0xfb, 0xc1, - 0x3b, 0x6b, 0x6f, 0x88, 0x3e, 0x4d, 0x02, 0x77, 0xe8, 0x25, 0x62, 0x54, 0x57, 0x88, 0x7a, 0xc8, - 0x42, 0x36, 0x91, 0xf4, 0xb6, 0xb5, 0xab, 0x27, 0x71, 0x82, 0xc4, 0x01, 0x49, 0x22, 0x1a, 0x8b, - 0xba, 0xd7, 0xf3, 0x69, 0xfd, 0x44, 0xac, 0xb5, 0xd5, 0x90, 0xb1, 0x70, 0x40, 0x34, 0xbe, 0x97, - 0xee, 0xd7, 0xbd, 0x78, 0xa4, 0x4d, 0xb5, 0x2d, 0xc8, 0x6d, 0x32, 0x1a, 0xa3, 0x73, 0x30, 0x1b, - 0x90, 0x98, 0x45, 0x65, 0x6b, 0xdd, 0xba, 0x38, 0x8f, 0xf5, 0x02, 0xbd, 0x0a, 0x79, 0x2f, 0x62, - 0x69, 0x2c, 0xca, 0x33, 0x52, 0xed, 0x2c, 0x3c, 0x39, 0xa8, 0x66, 0x7e, 0x3c, 0xa8, 0x66, 0x3b, - 0xb1, 0xc0, 0xc6, 0xd4, 0xc8, 0xfd, 0xfe, 0xb8, 0x6a, 0xd5, 0x6e, 0xc1, 0x5c, 0x8b, 0xf8, 0xff, - 0xc6, 0x57, 0x8b, 0xf8, 0x53, 0xbe, 0x2e, 0x41, 0xa1, 0x13, 0x8b, 0x3b, 0x8a, 0xa7, 0x0b, 0x90, - 0xa5, 0xb1, 0xd0, 0xae, 0x5e, 0x8c, 0x2f, 0xf5, 0x12, 0xda, 0x22, 0xfe, 0x31, 0x34, 0x20, 0xfe, - 0x34, 0x54, 0xba, 0x97, 0xfa, 0x9a, 0x03, 0xc5, 0x8f, 0xbc, 0x41, 0x33, 0x08, 0x12, 0xc2, 0x39, - 0xe1, 0xe8, 0x2d, 0x98, 0xf7, 0xc6, 0x8b, 0xb2, 0xb5, 0x9e, 0xbd, 0x58, 0x74, 0xce, 0xfc, 0x71, - 0x50, 0x85, 0x09, 0x08, 0x4f, 0x00, 0x8d, 0xdc, 0xa3, 0x9f, 0xd6, 0xad, 0x1a, 0x83, 0xb9, 0x2d, - 0x8f, 0x77, 0xe2, 0x7d, 0x86, 0xae, 0x01, 0x84, 0x1e, 0x77, 0x3f, 0xf7, 0x62, 0x41, 0x02, 0x15, - 0x34, 0xe7, 0xac, 0x3c, 0x3f, 0xa8, 0x2e, 0x8f, 0xbc, 0x68, 0xd0, 0xa8, 0x4d, 0x6c, 0x35, 0x3c, - 0x1f, 0x7a, 0xfc, 0x63, 0x25, 0x23, 0x1b, 0x0a, 0xd2, 0x92, 0x72, 0x12, 0x28, 0x1e, 0x72, 0xce, - 0xd9, 0xe7, 0x07, 0xd5, 0xa5, 0xc9, 0x1e, 0x69, 0xa9, 0xe1, 0xb9, 0xd0, 0xe3, 0x77, 0xa5, 0x34, - 0x84, 0x3c, 0x26, 0x3c, 0x1d, 0x08, 0x84, 0x20, 0x17, 0x78, 0xc2, 0x53, 0x91, 0x8a, 0x58, 0xc9, - 0xa8, 0x04, 0xd9, 0x01, 0x0b, 0x35, 0xa1, 0x58, 0x8a, 0xa8, 0x01, 0x79, 0xf2, 0x80, 0xc4, 0x82, - 0x97, 0xb3, 0xeb, 0xd9, 0x8b, 0x0b, 0x1b, 0xaf, 0xd8, 0x93, 0xf6, 0xb0, 0x65, 0x7b, 0xd8, 0xba, - 0x31, 0xda, 0x12, 0xe4, 0xe4, 0x24, 0x49, 0xd8, 0xec, 0x68, 0xe4, 0xbe, 0x7e, 0x5c, 0xcd, 0xd4, - 0x1e, 0x59, 0x80, 0xba, 0x34, 0x4a, 0x07, 0x9e, 0xa0, 0x2c, 0xc6, 0x84, 0x0f, 0x59, 0xcc, 0x09, - 0xba, 0xae, 0x13, 0xa7, 0xf1, 0x3e, 0x53, 0x29, 0x2c, 0x6c, 0xfc, 0xcf, 0x7e, 0xa1, 0x85, 0x6d, - 0x43, 0x8c, 0x53, 0x90, 0x4e, 0x9f, 0x1e, 0x54, 0x2d, 0x55, 0x85, 0xe2, 0xea, 0x0a, 0xe4, 0x13, - 0x55, 0x85, 0x4a, 0x75, 0x61, 0x63, 0x65, 0x6a, 0xab, 0x2e, 0x11, 0x1b, 0x50, 0xed, 0x1b, 0x0b, - 0x66, 0xf6, 0x1e, 0xa2, 0x4b, 0x90, 0xeb, 0xb1, 0x60, 0x64, 0xc2, 0x4d, 0xef, 0xd9, 0x7b, 0xe8, - 0xb0, 0x60, 0x84, 0x15, 0x04, 0x5d, 0x83, 0x79, 0x2f, 0x15, 0x7d, 0x9d, 0x9e, 0x8e, 0xf1, 0xff, - 0x29, 0x7c, 0x33, 0x15, 0x7d, 0x99, 0x0c, 0x2e, 0x78, 0x46, 0x42, 0x15, 0x00, 0x4e, 0xc3, 0xd8, - 0x13, 0x69, 0x42, 0x34, 0x61, 0x45, 0xfc, 0x37, 0x8d, 0x39, 0xf3, 0x9f, 0x2d, 0x98, 0xeb, 0xd2, - 0x30, 0x6e, 0x31, 0xff, 0xbf, 0x4f, 0x69, 0x15, 0x0a, 0x7e, 0xdf, 0xa3, 0xb1, 0x4b, 0x83, 0x72, - 0x56, 0x1d, 0xeb, 0x9c, 0x5a, 0x77, 0x02, 0xf4, 0x3a, 0x9c, 0xf1, 0x7c, 0x5f, 0x5e, 0x13, 0x37, - 0x4e, 0xa3, 0x1e, 0x49, 0xca, 0x39, 0xd9, 0x40, 0x78, 0xd1, 0x68, 0x77, 0x94, 0x12, 0x5d, 0x82, - 0xd2, 0x18, 0xc6, 0xc9, 0x67, 0x29, 0x89, 0x7d, 0x52, 0x9e, 0x55, 0xc0, 0x25, 0xa3, 0xef, 0x1a, - 0xb5, 0xa9, 0xef, 0x7b, 0x0b, 0xf2, 0x3a, 0x73, 0xf4, 0x36, 0x14, 0x22, 0xc2, 0xb9, 0x17, 0x9a, - 0x1b, 0xb1, 0xb0, 0x71, 0xce, 0xd6, 0xb3, 0xc3, 0x1e, 0xcf, 0x0e, 0xbb, 0x19, 0x8f, 0xf0, 0x31, - 0x4a, 0x76, 0x65, 0x44, 0x22, 0x66, 0x5a, 0x50, 0xc9, 0x32, 0x51, 0x41, 0x23, 0xc2, 0x52, 0xe1, - 0xf6, 0x09, 0x0d, 0xfb, 0x42, 0x55, 0x92, 0xc5, 0x8b, 0x46, 0x7b, 0x53, 0x29, 0x91, 0x03, 0xcb, - 0xe4, 0xa1, 0x20, 0x31, 0xa7, 0x2c, 0x76, 0xd9, 0x50, 0x76, 0x1b, 0x2f, 0xff, 0x39, 0xf7, 0x92, - 0xb0, 0xa5, 0x63, 0xfc, 0xae, 0x86, 0x9b, 0x0a, 0x04, 0x14, 0xc6, 0x54, 0xa2, 0x0f, 0xa0, 0x28, - 0x4f, 0x90, 0x24, 0x8a, 0xf8, 0x71, 0x19, 0xab, 0x53, 0xcc, 0x77, 0x15, 0x44, 0x71, 0xbf, 0xc0, - 0x8f, 0x65, 0x8e, 0x5e, 0x83, 0xec, 0x3e, 0x21, 0xe6, 0xb8, 0xd0, 0xd4, 0xa6, 0x1b, 0x84, 0x60, - 0x69, 0x36, 0x51, 0xbf, 0x00, 0x98, 0xb8, 0x41, 0x57, 0x01, 0x86, 0x69, 0x6f, 0x40, 0x7d, 0xf7, - 0x3e, 0x19, 0xf7, 0xc7, 0x3f, 0x57, 0x31, 0xaf, 0x71, 0x1f, 0x12, 0xd5, 0x23, 0x11, 0x0b, 0xc8, - 0xcb, 0x7a, 0x64, 0x9b, 0x05, 0x44, 0xf7, 0x48, 0x64, 0x24, 0x13, 0xfe, 0x87, 0x19, 0x28, 0x8c, - 0x8d, 0xe8, 0x7d, 0xc8, 0x73, 0x1a, 0x87, 0x03, 0x62, 0x22, 0x57, 0x4e, 0xf1, 0x62, 0x77, 0x15, - 0xea, 0x66, 0x06, 0x1b, 0x3c, 0x7a, 0x17, 0x66, 0xa3, 0x74, 0x20, 0xa8, 0x09, 0x7f, 0xe1, 0xb4, - 0x8d, 0xdb, 0x12, 0x74, 0x33, 0x83, 0x35, 0x7a, 0xed, 0x3a, 0xe4, 0xb5, 0x2b, 0xf4, 0x26, 0xe4, - 0x64, 0x66, 0x2a, 0xf0, 0x99, 0x13, 0xe9, 0x4b, 0x86, 0xa4, 0x0f, 0xac, 0x40, 0x3a, 0xf5, 0xb5, - 0xaf, 0x2c, 0x98, 0x55, 0xfe, 0x50, 0x03, 0x0a, 0x3d, 0x2a, 0xbc, 0x24, 0xf1, 0x46, 0xa7, 0x64, - 0xbe, 0xc9, 0xa2, 0xa1, 0xe7, 0x0b, 0x87, 0x8a, 0xa6, 0x44, 0xe1, 0x63, 0x3c, 0x7a, 0x0f, 0xe0, - 0x98, 0x3c, 0x5e, 0x9e, 0x51, 0xe7, 0x7c, 0x2a, 0x7b, 0xf3, 0x63, 0xf6, 0x4c, 0xcf, 0xe8, 0xaf, - 0x33, 0x0b, 0x59, 0x9e, 0x46, 0xb5, 0x01, 0x64, 0x6f, 0x10, 0x22, 0x87, 0xa7, 0x79, 0xa2, 0x74, - 0xd7, 0x9c, 0x3d, 0x91, 0x0b, 0x8d, 0x9d, 0x45, 0x39, 0xde, 0xbe, 0xfb, 0xa5, 0x3a, 0x2b, 0x57, - 0x7c, 0xfc, 0x72, 0xa1, 0xf3, 0x20, 0xa7, 0xbc, 0x3b, 0xa0, 0x11, 0xd5, 0x53, 0x2e, 0x87, 0xe5, - 0xc0, 0xbc, 0x2d, 0xd7, 0x8d, 0xa2, 0x9c, 0xac, 0xf2, 0x69, 0x53, 0x27, 0x77, 0x0f, 0x96, 0xa6, - 0xaa, 0x42, 0x97, 0xd5, 0x5d, 0x48, 0x3c, 0xb7, 0x47, 0x05, 0x77, 0xb9, 0x60, 0x89, 0x79, 0x53, - 0x16, 0xf1, 0x92, 0x32, 0x38, 0x54, 0xf0, 0xae, 0x52, 0xcb, 0xe7, 0x95, 0x0c, 0x48, 0xc4, 0x55, - 0x94, 0x22, 0xd6, 0x0b, 0x5d, 0xcf, 0x65, 0x0e, 0x85, 0x31, 0xe3, 0x68, 0x15, 0x56, 0xba, 0x9d, - 0xad, 0x1d, 0x77, 0x7b, 0xb7, 0xd5, 0x76, 0xef, 0xee, 0x74, 0xef, 0xb4, 0x37, 0x3b, 0x37, 0x3a, - 0xed, 0x56, 0x29, 0x83, 0xce, 0x41, 0x69, 0x62, 0x6a, 0x75, 0x70, 0x7b, 0x73, 0xaf, 0x64, 0xa1, - 0x15, 0x58, 0x9e, 0x68, 0xf7, 0xda, 0x9f, 0xec, 0xdd, 0x6d, 0xde, 0x2e, 0xcd, 0xa0, 0x2a, 0x9c, - 0x9f, 0xa8, 0x6f, 0xb7, 0xb7, 0x9a, 0x9b, 0xf7, 0xdc, 0xe6, 0x76, 0x67, 0x67, 0xd7, 0xbd, 0xd5, - 0xdd, 0xdd, 0x29, 0x7d, 0xe9, 0xb4, 0x9e, 0xfd, 0x56, 0xc9, 0x3c, 0x3a, 0xac, 0x64, 0x9e, 0x1c, - 0x56, 0xac, 0xa7, 0x87, 0x15, 0xeb, 0xd7, 0xc3, 0x8a, 0xf5, 0xed, 0x51, 0x25, 0xf3, 0xf4, 0xa8, - 0x92, 0x79, 0x76, 0x54, 0xc9, 0x7c, 0x5a, 0x0b, 0xa9, 0xe8, 0xa7, 0x3d, 0xdb, 0x67, 0x51, 0x5d, - 0x53, 0x6a, 0x7e, 0xae, 0xf0, 0xe0, 0xbe, 0xfe, 0xab, 0xd2, 0xcb, 0xab, 0x4b, 0x72, 0xf5, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xb6, 0xa8, 0x9a, 0x6e, 0x2c, 0x09, 0x00, 0x00, + // 1207 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xbf, 0x73, 0x1b, 0xc5, + 0x17, 0xd7, 0x59, 0xb2, 0x2c, 0x3f, 0xcb, 0xb1, 0xbc, 0x89, 0xbf, 0x5f, 0xd9, 0x21, 0x92, 0x47, + 0xfc, 0x98, 0x24, 0x10, 0x09, 0x9c, 0xc0, 0x30, 0x0a, 0x8d, 0xce, 0x52, 0x1c, 0x85, 0xd8, 0xce, + 0x9c, 0x1c, 0x20, 0x69, 0x6e, 0x4e, 0x77, 0xeb, 0xd3, 0x4e, 0xee, 0x76, 0xc5, 0xed, 0x5e, 0x88, + 0x0a, 0x86, 0xd0, 0x31, 0x43, 0x43, 0x4f, 0x93, 0x9a, 0xbf, 0x24, 0x74, 0x29, 0x33, 0x0c, 0x18, + 0x70, 0x1a, 0xea, 0x94, 0x34, 0x30, 0xfb, 0x43, 0x16, 0x91, 0xe3, 0x14, 0xcc, 0xd0, 0xc8, 0x6f, + 0xdf, 0xfb, 0xbc, 0xdf, 0x9f, 0xdb, 0x35, 0x2c, 0x8b, 0xd1, 0x10, 0xf3, 0x86, 0xfa, 0xad, 0x0f, + 0x13, 0x26, 0x18, 0x5a, 0xf4, 0x19, 0x8f, 0x19, 0x77, 0x79, 0x70, 0xaf, 0x7e, 0xff, 0xbd, 0xb5, + 0xb7, 0xc4, 0x80, 0x24, 0x81, 0x3b, 0xf4, 0x12, 0x31, 0x6a, 0x28, 0x44, 0x23, 0x64, 0x21, 0x9b, + 0x48, 0xda, 0x6d, 0xed, 0xf2, 0x71, 0x9c, 0xc0, 0x34, 0xc0, 0x49, 0x4c, 0xa8, 0x68, 0x78, 0x7d, + 0x9f, 0x34, 0x8e, 0xe5, 0x5a, 0x5b, 0x0d, 0x19, 0x0b, 0x23, 0xac, 0xf1, 0xfd, 0x74, 0xbf, 0xe1, + 0xd1, 0x91, 0x36, 0xd5, 0xb6, 0x20, 0xb7, 0xc9, 0x08, 0x45, 0x67, 0x60, 0x36, 0xc0, 0x94, 0xc5, + 0x65, 0x6b, 0xdd, 0x3a, 0x3f, 0xef, 0xe8, 0x03, 0x7a, 0x1d, 0xf2, 0x5e, 0xcc, 0x52, 0x2a, 0xca, + 0x33, 0x52, 0x6d, 0x2f, 0x3c, 0x3e, 0xa8, 0x66, 0x7e, 0x3a, 0xa8, 0x66, 0xbb, 0x54, 0x38, 0xc6, + 0xd4, 0xcc, 0xfd, 0xf1, 0xa8, 0x6a, 0xd5, 0x6e, 0xc0, 0x5c, 0x1b, 0xfb, 0xff, 0x26, 0x56, 0x1b, + 0xfb, 0x53, 0xb1, 0x2e, 0x40, 0xa1, 0x4b, 0xc5, 0x2d, 0x35, 0xa7, 0x73, 0x90, 0x25, 0x54, 0xe8, + 0x50, 0x2f, 0xe6, 0x97, 0x7a, 0x09, 0x6d, 0x63, 0xff, 0x08, 0x1a, 0x60, 0x7f, 0x1a, 0x2a, 0xc3, + 0x4b, 0x7d, 0xcd, 0x86, 0xe2, 0x27, 0x5e, 0xd4, 0x0a, 0x82, 0x04, 0x73, 0x8e, 0x39, 0x7a, 0x07, + 0xe6, 0xbd, 0xf1, 0xa1, 0x6c, 0xad, 0x67, 0xcf, 0x17, 0xed, 0x53, 0x7f, 0x1e, 0x54, 0x61, 0x02, + 0x72, 0x26, 0x80, 0x66, 0xee, 0xe1, 0xcf, 0xeb, 0x56, 0x8d, 0xc1, 0xdc, 0x96, 0xc7, 0xbb, 0x74, + 0x9f, 0xa1, 0x2b, 0x00, 0xa1, 0xc7, 0xdd, 0x2f, 0x3c, 0x2a, 0x70, 0xa0, 0x92, 0xe6, 0xec, 0x95, + 0xe7, 0x07, 0xd5, 0xe5, 0x91, 0x17, 0x47, 0xcd, 0xda, 0xc4, 0x56, 0x73, 0xe6, 0x43, 0x8f, 0x7f, + 0xaa, 0x64, 0x54, 0x87, 0x82, 0xb4, 0xa4, 0x1c, 0x07, 0x6a, 0x0e, 0x39, 0xfb, 0xf4, 0xf3, 0x83, + 0xea, 0xd2, 0xc4, 0x47, 0x5a, 0x6a, 0xce, 0x5c, 0xe8, 0xf1, 0xdb, 0x52, 0x1a, 0x42, 0xde, 0xc1, + 0x3c, 0x8d, 0x04, 0x42, 0x90, 0x0b, 0x3c, 0xe1, 0xa9, 0x4c, 0x45, 0x47, 0xc9, 0xa8, 0x04, 0xd9, + 0x88, 0x85, 0x7a, 0xa0, 0x8e, 0x14, 0x51, 0x13, 0xf2, 0xf8, 0x3e, 0xa6, 0x82, 0x97, 0xb3, 0xeb, + 0xd9, 0xf3, 0x0b, 0x1b, 0xaf, 0xd5, 0x27, 0xf4, 0xa8, 0x4b, 0x7a, 0xd4, 0x35, 0x31, 0x3a, 0x12, + 0x64, 0xe7, 0xe4, 0x90, 0x1c, 0xe3, 0xd1, 0xcc, 0x7d, 0xf3, 0xa8, 0x9a, 0xa9, 0x3d, 0xb4, 0x00, + 0xf5, 0x48, 0x9c, 0x46, 0x9e, 0x20, 0x8c, 0x3a, 0x98, 0x0f, 0x19, 0xe5, 0x18, 0x5d, 0xd5, 0x85, + 0x13, 0xba, 0xcf, 0x54, 0x09, 0x0b, 0x1b, 0xff, 0xab, 0xbf, 0x40, 0xe1, 0xba, 0x19, 0x8c, 0x5d, + 0x90, 0x41, 0x9f, 0x1c, 0x54, 0x2d, 0xd5, 0x85, 0x9a, 0xd5, 0x25, 0xc8, 0x27, 0xaa, 0x0b, 0x55, + 0xea, 0xc2, 0xc6, 0xca, 0x94, 0xab, 0x6e, 0xd1, 0x31, 0xa0, 0xda, 0xb7, 0x16, 0xcc, 0xec, 0x3d, + 0x40, 0x17, 0x20, 0xd7, 0x67, 0xc1, 0xc8, 0xa4, 0x9b, 0xf6, 0xd9, 0x7b, 0x60, 0xb3, 0x60, 0xe4, + 0x28, 0x08, 0xba, 0x02, 0xf3, 0x5e, 0x2a, 0x06, 0xba, 0x3c, 0x9d, 0xe3, 0xff, 0x53, 0xf8, 0x56, + 0x2a, 0x06, 0xb2, 0x18, 0xa7, 0xe0, 0x19, 0x09, 0x55, 0x00, 0x38, 0x09, 0xa9, 0x27, 0xd2, 0x04, + 0xeb, 0x81, 0x15, 0x9d, 0x7f, 0x68, 0xcc, 0xce, 0x7f, 0xb1, 0x60, 0xae, 0x47, 0x42, 0xda, 0x66, + 0xfe, 0x7f, 0x5f, 0xd2, 0x2a, 0x14, 0xfc, 0x81, 0x47, 0xa8, 0x4b, 0x82, 0x72, 0x56, 0xad, 0x75, + 0x4e, 0x9d, 0xbb, 0x01, 0x7a, 0x13, 0x4e, 0x79, 0xbe, 0x2f, 0x3f, 0x13, 0x97, 0xa6, 0x71, 0x1f, + 0x27, 0xe5, 0x9c, 0x24, 0x90, 0xb3, 0x68, 0xb4, 0x3b, 0x4a, 0x89, 0x2e, 0x40, 0x69, 0x0c, 0xe3, + 0xf8, 0xf3, 0x14, 0x53, 0x1f, 0x97, 0x67, 0x15, 0x70, 0xc9, 0xe8, 0x7b, 0x46, 0x6d, 0xfa, 0xfb, + 0x7e, 0x06, 0xf2, 0xba, 0x72, 0xf4, 0x2e, 0x14, 0x62, 0xcc, 0xb9, 0x17, 0x9a, 0x2f, 0x62, 0x61, + 0xe3, 0x4c, 0x5d, 0xdf, 0x1d, 0xf5, 0xf1, 0xdd, 0x51, 0x6f, 0xd1, 0x91, 0x73, 0x84, 0x92, 0xac, + 0x8c, 0x71, 0xcc, 0x0c, 0x05, 0x95, 0x2c, 0x0b, 0x15, 0x24, 0xc6, 0x2c, 0x15, 0xee, 0x00, 0x93, + 0x70, 0x20, 0x54, 0x27, 0x59, 0x67, 0xd1, 0x68, 0xaf, 0x2b, 0x25, 0xb2, 0x61, 0x19, 0x3f, 0x10, + 0x98, 0x72, 0xc2, 0xa8, 0xcb, 0x86, 0x92, 0x6d, 0xbc, 0xfc, 0xd7, 0xdc, 0x2b, 0xd2, 0x96, 0x8e, + 0xf0, 0xbb, 0x1a, 0x8e, 0xee, 0x42, 0x85, 0x32, 0xea, 0xfa, 0x09, 0x11, 0xc4, 0xf7, 0x22, 0xf7, + 0x25, 0x01, 0x97, 0x5e, 0x11, 0xf0, 0x2c, 0x65, 0x74, 0xd3, 0xf8, 0x76, 0xa6, 0x62, 0x9b, 0xe9, + 0x08, 0x28, 0x8c, 0xd7, 0x84, 0x3e, 0x82, 0xa2, 0x64, 0x07, 0x4e, 0xd4, 0x52, 0xc7, 0x23, 0x5a, + 0x9d, 0xda, 0x6a, 0x4f, 0x41, 0xd4, 0x5e, 0x17, 0xf8, 0x91, 0xcc, 0xd1, 0x1b, 0x90, 0xdd, 0xc7, + 0xd8, 0x50, 0x01, 0x4d, 0x39, 0x5d, 0xc3, 0xd8, 0x91, 0x66, 0x93, 0xf5, 0x4b, 0x80, 0x49, 0x18, + 0x74, 0x19, 0x60, 0x98, 0xf6, 0x23, 0xe2, 0xbb, 0xf7, 0xf0, 0x98, 0x7b, 0x2f, 0x6f, 0x68, 0x5e, + 0xe3, 0x3e, 0xc6, 0x8a, 0x7f, 0x31, 0x0b, 0xf0, 0xab, 0xf8, 0xb7, 0xcd, 0x02, 0xac, 0xf9, 0x17, + 0x1b, 0xc9, 0xa4, 0xff, 0x71, 0x06, 0x0a, 0x63, 0x23, 0xfa, 0x10, 0xf2, 0x9c, 0xd0, 0x30, 0xc2, + 0x26, 0x73, 0xe5, 0x84, 0x28, 0xf5, 0x9e, 0x42, 0x5d, 0xcf, 0x38, 0x06, 0x8f, 0xde, 0x87, 0xd9, + 0x38, 0x8d, 0x04, 0x31, 0xe9, 0xcf, 0x9d, 0xe4, 0xb8, 0x2d, 0x41, 0xd7, 0x33, 0x8e, 0x46, 0xaf, + 0x5d, 0x85, 0xbc, 0x0e, 0x85, 0xde, 0x86, 0x9c, 0xac, 0x4c, 0x25, 0x3e, 0x75, 0xac, 0x7c, 0x39, + 0x21, 0x19, 0xc3, 0x51, 0x20, 0x5d, 0xfa, 0xda, 0xd7, 0x16, 0xcc, 0xaa, 0x78, 0xa8, 0x09, 0x85, + 0x3e, 0x11, 0x5e, 0x92, 0x78, 0xa3, 0x13, 0x2a, 0xdf, 0x64, 0xf1, 0xd0, 0xf3, 0x85, 0x4d, 0x44, + 0x4b, 0xa2, 0x9c, 0x23, 0x3c, 0xfa, 0x00, 0xe0, 0x68, 0x78, 0xbc, 0x3c, 0xa3, 0xf6, 0x7c, 0xe2, + 0xf4, 0xe6, 0xc7, 0xd3, 0x33, 0x9c, 0xd1, 0xbf, 0xf6, 0x2c, 0x64, 0x79, 0x1a, 0xd7, 0x22, 0xc8, + 0x5e, 0xc3, 0x58, 0x5e, 0xcc, 0xe6, 0xf9, 0xd3, 0xac, 0x39, 0x7d, 0xac, 0x16, 0x42, 0xed, 0x45, + 0x79, 0x75, 0xfe, 0xf0, 0x6b, 0x75, 0x56, 0x9e, 0xf8, 0xf8, 0x55, 0x44, 0x67, 0x41, 0xbe, 0x20, + 0x6e, 0x44, 0x62, 0xa2, 0x6f, 0xd0, 0x9c, 0x23, 0x2f, 0xe3, 0x9b, 0xf2, 0xdc, 0x2c, 0xca, 0x5b, + 0x5b, 0x3e, 0x9b, 0x6a, 0x73, 0x77, 0x60, 0x69, 0xaa, 0x2b, 0x74, 0x51, 0x7d, 0x67, 0x89, 0xe7, + 0xf6, 0x89, 0xe0, 0x2e, 0x17, 0x2c, 0x31, 0xef, 0xd5, 0xa2, 0xb3, 0xa4, 0x0c, 0x36, 0x11, 0xbc, + 0xa7, 0xd4, 0xf2, 0xe9, 0xc6, 0x11, 0x8e, 0xb9, 0xca, 0x52, 0x74, 0xf4, 0x41, 0xf7, 0x73, 0x91, + 0x43, 0x61, 0x3c, 0x71, 0xb4, 0x0a, 0x2b, 0xbd, 0xee, 0xd6, 0x8e, 0xbb, 0xbd, 0xdb, 0xee, 0xb8, + 0xb7, 0x77, 0x7a, 0xb7, 0x3a, 0x9b, 0xdd, 0x6b, 0xdd, 0x4e, 0xbb, 0x94, 0x41, 0x67, 0xa0, 0x34, + 0x31, 0xb5, 0xbb, 0x4e, 0x67, 0x73, 0xaf, 0x64, 0xa1, 0x15, 0x58, 0x9e, 0x68, 0xf7, 0x3a, 0x9f, + 0xed, 0xdd, 0x6e, 0xdd, 0x2c, 0xcd, 0xa0, 0x2a, 0x9c, 0x9d, 0xa8, 0x6f, 0x76, 0xb6, 0x5a, 0x9b, + 0x77, 0xdc, 0xd6, 0x76, 0x77, 0x67, 0xd7, 0xbd, 0xd1, 0xdb, 0xdd, 0x29, 0x7d, 0x65, 0xb7, 0x9f, + 0xfe, 0x5e, 0xc9, 0x3c, 0x3c, 0xac, 0x64, 0x1e, 0x1f, 0x56, 0xac, 0x27, 0x87, 0x15, 0xeb, 0xb7, + 0xc3, 0x8a, 0xf5, 0xdd, 0xb3, 0x4a, 0xe6, 0xc9, 0xb3, 0x4a, 0xe6, 0xe9, 0xb3, 0x4a, 0xe6, 0x6e, + 0x2d, 0x24, 0x62, 0x90, 0xf6, 0xeb, 0x3e, 0x8b, 0x1b, 0x7a, 0xa4, 0xe6, 0xcf, 0x25, 0x1e, 0xdc, + 0xd3, 0xff, 0x06, 0xf5, 0xf3, 0xea, 0x23, 0xb9, 0xfc, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1a, + 0x0d, 0xb3, 0x66, 0x88, 0x09, 0x00, 0x00, } func (this *Coin) Equal(that interface{}) bool { @@ -1639,6 +1695,22 @@ func (m *TxBody) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.NonCriticalExtensionOptions) > 0 { + for iNdEx := len(m.NonCriticalExtensionOptions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NonCriticalExtensionOptions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x7f + i-- + dAtA[i] = 0xfa + } + } if len(m.ExtensionOptions) > 0 { for iNdEx := len(m.ExtensionOptions) - 1; iNdEx >= 0; iNdEx-- { { @@ -2214,6 +2286,12 @@ func (m *TxBody) Size() (n int) { n += 2 + l + sovTypes(uint64(l)) } } + if len(m.NonCriticalExtensionOptions) > 0 { + for _, e := range m.NonCriticalExtensionOptions { + l = e.Size() + n += 2 + l + sovTypes(uint64(l)) + } + } return n } @@ -2410,11 +2488,17 @@ func (this *TxBody) String() string { repeatedStringForExtensionOptions += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," } repeatedStringForExtensionOptions += "}" + repeatedStringForNonCriticalExtensionOptions := "[]*Any{" + for _, f := range this.NonCriticalExtensionOptions { + repeatedStringForNonCriticalExtensionOptions += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," + } + repeatedStringForNonCriticalExtensionOptions += "}" s := strings.Join([]string{`&TxBody{`, `Messages:` + repeatedStringForMessages + `,`, `Memo:` + fmt.Sprintf("%v", this.Memo) + `,`, `TimeoutHeight:` + fmt.Sprintf("%v", this.TimeoutHeight) + `,`, `ExtensionOptions:` + repeatedStringForExtensionOptions + `,`, + `NonCriticalExtensionOptions:` + repeatedStringForNonCriticalExtensionOptions + `,`, `}`, }, "") return s @@ -3900,6 +3984,40 @@ func (m *TxBody) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2047: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NonCriticalExtensionOptions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NonCriticalExtensionOptions = append(m.NonCriticalExtensionOptions, &types1.Any{}) + if err := m.NonCriticalExtensionOptions[len(m.NonCriticalExtensionOptions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 2aebf1401cee..2d7fe3fa16bf 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -41,7 +41,7 @@ type SigVerifiableTx interface { GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignBytes(ctx sdk.Context, acc exported.Account) []byte + GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, error) } // SetPubKeyDecorator sets PubKeys in context for any signer which does not already have pubkey set @@ -198,7 +198,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simu } // retrieve signBytes of tx - signBytes := sigTx.GetSignBytes(ctx, signerAccs[i]) + signBytes, _ := sigTx.GetSignBytes(ctx, signerAccs[i]) // retrieve pubkey pubKey := signerAccs[i].GetPubKey() diff --git a/x/auth/ante/tx.go b/x/auth/ante/tx.go new file mode 100644 index 000000000000..dd1389885501 --- /dev/null +++ b/x/auth/ante/tx.go @@ -0,0 +1,195 @@ +package ante + +import ( + "fmt" + + "github.com/tendermint/tendermint/crypto" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +type DecodedTx struct { + *sdk.Tx + Raw *TxRaw + Msgs []sdk.Msg + PubKeys []crypto.PubKey + Signers []sdk.AccAddress + SignerInfoMap map[string]*sdk.SignerInfo +} + +var _ sdk.TxI = DecodedTx{} +var _ SigVerifiableTx = DecodedTx{} +var _ FeeTx = DecodedTx{} +var _ TxWithMemo = DecodedTx{} + +var DefaultTxDecoder sdk.TxDecoder = func(txBytes []byte) (sdk.TxI, error) { + var raw TxRaw + err := raw.Unmarshal(txBytes) + if err != nil { + return nil, err + } + + var tx sdk.Tx + err = tx.Unmarshal(txBytes) + if err != nil { + return nil, err + } + + anyMsgs := tx.Body.Messages + msgs := make([]sdk.Msg, len(anyMsgs)) + for i, any := range anyMsgs { + msg, ok := any.GetCachedValue().(sdk.Msg) + if !ok { + return nil, fmt.Errorf("can't decode sdk.Msg from %+v", any) + } + msgs[i] = msg + } + + var signers []sdk.AccAddress + seen := map[string]bool{} + + for _, msg := range msgs { + for _, addr := range msg.GetSigners() { + if !seen[addr.String()] { + signers = append(signers, addr) + seen[addr.String()] = true + } + } + } + + nSigners := len(signers) + signerInfos := tx.AuthInfo.SignerInfos + signerInfoMap := map[string]*sdk.SignerInfo{} + pubKeys := make([]crypto.PubKey, len(signerInfos)) + for i, si := range signerInfos { + any := si.PublicKey + pubKey, ok := any.GetCachedValue().(crypto.PubKey) + if !ok { + return nil, fmt.Errorf("can't decode PublicKey from %+v", any) + } + pubKeys[i] = pubKey + + if i < nSigners { + signerInfoMap[signers[i].String()] = si + } + } + + return DecodedTx{ + Tx: &tx, + Raw: &raw, + Msgs: msgs, + PubKeys: pubKeys, + Signers: signers, + SignerInfoMap: signerInfoMap, + }, nil +} + +func (d DecodedTx) GetMsgs() []sdk.Msg { + return d.Msgs +} + +func (d DecodedTx) ValidateBasic() error { + sigs := d.Signatures + + if d.GetGas() > auth.MaxGasWanted { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, + "invalid gas supplied; %d > %d", d.GetGas(), auth.MaxGasWanted, + ) + } + if d.GetFee().IsAnyNegative() { + return sdkerrors.Wrapf( + sdkerrors.ErrInsufficientFee, + "invalid fee provided: %s", d.GetFee(), + ) + } + if len(sigs) == 0 { + return sdkerrors.ErrNoSignatures + } + if len(sigs) != len(d.GetSigners()) { + return sdkerrors.Wrapf( + sdkerrors.ErrUnauthorized, + "wrong number of signers; expected %d, got %d", d.GetSigners(), len(sigs), + ) + } + + return nil +} + +func (d DecodedTx) GetSigners() []sdk.AccAddress { + return d.Signers +} + +func (d DecodedTx) GetPubKeys() []crypto.PubKey { + return d.PubKeys +} + +func (d DecodedTx) GetSignBytes(ctx sdk.Context, acc authexported.Account) ([]byte, error) { + address := acc.GetAddress() + signerInfo, ok := d.SignerInfoMap[address.String()] + if !ok { + return nil, fmt.Errorf("missing SignerInfo for address %s", address.String()) + } + + genesis := ctx.BlockHeight() == 0 + chainID := ctx.ChainID() + var accNum uint64 + if !genesis { + accNum = acc.GetAccountNumber() + } + + switch modeInfo := signerInfo.ModeInfo.Sum.(type) { + case *sdk.ModeInfo_Single_: + switch modeInfo.Single.Mode { + case sdk.SignMode_SIGN_MODE_UNSPECIFIED: + return nil, fmt.Errorf("unspecified sign mode") + case sdk.SignMode_SIGN_MODE_DIRECT: + return DirectSignBytes(d.Raw.BodyBytes, d.Raw.AuthInfoBytes, chainID, accNum, acc.GetSequence()) + case sdk.SignMode_SIGN_MODE_TEXTUAL: + return nil, fmt.Errorf("SIGN_MODE_TEXTUAL is not supported yet") + case sdk.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + return auth.StdSignBytes( + chainID, accNum, acc.GetSequence(), auth.StdFee{Amount: d.GetFee(), Gas: d.GetGas()}, d.Msgs, d.Body.Memo, + ), nil + } + case *sdk.ModeInfo_Multi_: + return nil, fmt.Errorf("multisig mode info is not supported by GetSignBytes") + default: + return nil, fmt.Errorf("unexpected ModeInfo") + } + return nil, fmt.Errorf("unexpected") +} + +func DirectSignBytes(bodyBz, authInfoBz []byte, chainID string, accnum, sequence uint64) ([]byte, error) { + signDoc := SignDocRaw{ + BodyBytes: bodyBz, + AuthInfoBytes: authInfoBz, + ChainId: chainID, + AccountNumber: accnum, + AccountSequence: sequence, + } + return signDoc.Marshal() +} + +func (d DecodedTx) GetGas() uint64 { + return d.AuthInfo.Fee.GasLimit +} + +func (d DecodedTx) GetFee() sdk.Coins { + return d.AuthInfo.Fee.Amount +} + +func (d DecodedTx) FeePayer() sdk.AccAddress { + signers := d.GetSigners() + if signers != nil { + return signers[0] + } + return sdk.AccAddress{} +} + +func (d DecodedTx) GetMemo() string { + return d.Body.Memo +} diff --git a/x/auth/ante/types.proto b/x/auth/ante/types.proto new file mode 100644 index 000000000000..d8e5d0943e72 --- /dev/null +++ b/x/auth/ante/types.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package cosmos_sdk.v1.signing; + +option go_package = "github.com/cosmos/cosmos-sdk/x/auth/ante"; + +// TxRaw is using for transaction decoding and verification +message TxRaw { + bytes body_bytes = 1; + + bytes auth_info_bytes = 2; + + repeated bytes signatures = 3; +} + +// SignDocRaw is used for verifying signatures with SIGN_MODE_DIRECT +message SignDocRaw { + bytes body_bytes = 1; + + bytes auth_info_bytes = 2; + + string chain_id = 3; + + uint64 account_number = 4; + + uint64 account_sequence = 5; +} diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index efa7a03a0a53..770b01e8c0e9 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -245,7 +245,7 @@ func (tx StdTx) GetPubKeys() []crypto.PubKey { } // GetSignBytes returns the signBytes of the tx for a given signer -func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) []byte { +func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, error) { genesis := ctx.BlockHeight() == 0 chainID := ctx.ChainID() var accNum uint64 @@ -255,7 +255,7 @@ func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) []byte { return StdSignBytes( chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, - ) + ), nil } // GetGas returns the Gas in StdFee From 0d875e163e8e679ec9f873aab1adb8c7e6d3152a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 15 May 2020 10:10:50 -0400 Subject: [PATCH 08/54] WIP --- baseapp/baseapp.go | 2 +- baseapp/baseapp_test.go | 16 +- baseapp/helpers.go | 6 +- client/tx/tx.go | 2 +- crypto/types/types.pb.go | 110 +-- server/mock/tx.go | 6 +- std/tx.go | 2 +- tests/mocks/types_handler.go | 2 +- types/codec.go | 2 +- types/config_test.go | 4 +- types/handler.go | 8 +- types/handler_test.go | 2 +- types/result.go | 4 +- types/result_test.go | 8 +- .../ante/tx.go => types/tx/raw/decoded_tx.go | 14 +- types/tx/raw/types.pb.go | 787 ++++++++++++++++++ {x/auth/ante => types/tx/raw}/types.proto | 4 +- types/tx_msg.go | 6 +- x/auth/ante/ante_test.go | 28 +- x/auth/ante/basic.go | 8 +- x/auth/ante/fee.go | 6 +- x/auth/ante/setup.go | 4 +- x/auth/ante/setup_test.go | 4 +- x/auth/ante/sigverify.go | 20 +- x/auth/client/query.go | 2 +- x/auth/client/tx_test.go | 2 +- x/auth/types/stdtx.go | 6 +- x/auth/types/test_utils.go | 6 +- x/genutil/client/rest/query.go | 2 +- x/ibc/ante/ante.go | 2 +- x/ibc/ante/ante_test.go | 2 +- 31 files changed, 937 insertions(+), 140 deletions(-) rename x/auth/ante/tx.go => types/tx/raw/decoded_tx.go (95%) create mode 100644 types/tx/raw/types.pb.go rename {x/auth/ante => types/tx/raw}/types.proto (82%) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 976ac1f525ee..e9d0d2baa087 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -467,7 +467,7 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context // Note, gas execution info is always returned. A reference to a Result is // returned if the tx does not run out of gas and if all the messages are valid // and execute successfully. An error is returned otherwise. -func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.TxI) (gInfo sdk.GasInfo, result *sdk.Result, err error) { +func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, err error) { // NOTE: GasWanted should be returned by the AnteHandler. GasUsed is // determined by the GasMeter. We need access to the context to get the gas // meter so we initialize upfront. diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 75c76b29df95..79d6cb5f5ab5 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -648,7 +648,7 @@ func (msg msgCounter2) ValidateBasic() error { // amino decode func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { - return func(txBytes []byte) (sdk.TxI, error) { + return func(txBytes []byte) (sdk.Tx, error) { var tx txTest if len(txBytes) == 0 { return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty") @@ -664,7 +664,7 @@ func testTxDecoder(cdc *codec.Codec) sdk.TxDecoder { } func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler { - return func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithEventManager(sdk.NewEventManager()) store := newCtx.KVStore(capKey) txTest := tx.(txTest) @@ -942,7 +942,7 @@ func TestSimulateTx(t *testing.T) { gasConsumed := uint64(5) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasConsumed)) return }) @@ -1008,7 +1008,7 @@ func TestSimulateTx(t *testing.T) { func TestRunInvalidTransaction(t *testing.T) { anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { return }) } @@ -1111,7 +1111,7 @@ func TestRunInvalidTransaction(t *testing.T) { func TestTxGasLimits(t *testing.T) { gasGranted := uint64(10) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) // AnteHandlers must have their own defer/recover in order for the BaseApp @@ -1199,7 +1199,7 @@ func TestTxGasLimits(t *testing.T) { func TestMaxBlockGasLimits(t *testing.T) { gasGranted := uint64(10) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) defer func() { @@ -1368,7 +1368,7 @@ func TestBaseAppAnteHandler(t *testing.T) { func TestGasConsumptionBadTx(t *testing.T) { gasWanted := uint64(5) anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasWanted)) defer func() { @@ -1439,7 +1439,7 @@ func TestGasConsumptionBadTx(t *testing.T) { func TestQuery(t *testing.T) { key, value := []byte("hello"), []byte("goodbye") anteOpt := func(bapp *BaseApp) { - bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.TxI, simulate bool) (newCtx sdk.Context, err error) { + bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { store := ctx.KVStore(capKey1) store.Set(key, value) return diff --git a/baseapp/helpers.go b/baseapp/helpers.go index b8ca928406cf..085d6b4ed642 100644 --- a/baseapp/helpers.go +++ b/baseapp/helpers.go @@ -10,15 +10,15 @@ import ( var isAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString -func (app *BaseApp) Check(tx sdk.TxI) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) Check(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeCheck, nil, tx) } -func (app *BaseApp) Simulate(txBytes []byte, tx sdk.TxI) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) Simulate(txBytes []byte, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeSimulate, txBytes, tx) } -func (app *BaseApp) Deliver(tx sdk.TxI) (sdk.GasInfo, *sdk.Result, error) { +func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeDeliver, nil, tx) } diff --git a/client/tx/tx.go b/client/tx/tx.go index f87a135586f3..db55aacc96df 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -48,7 +48,7 @@ type ( // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. ClientTx interface { - sdk.TxI + sdk.Tx codec.ProtoMarshaler SetMsgs(...sdk.Msg) error diff --git a/crypto/types/types.pb.go b/crypto/types/types.pb.go index f859315e093e..394067599fca 100644 --- a/crypto/types/types.pb.go +++ b/crypto/types/types.pb.go @@ -218,25 +218,25 @@ func (m *PubKeyMultisigThreshold) GetPubKeys() []*PublicKey { return nil } -// Multisignature wraps the signatures from a PubKeyMultisigThreshold. +// MultiSignature wraps the signatures from a PubKeyMultisigThreshold. // See cosmos_sdk.tx.v1.ModeInfo.Multi for how to specify which signers signed // and with which modes -type Multisignature struct { +type MultiSignature struct { Sigs [][]byte `protobuf:"bytes,1,rep,name=sigs,proto3" json:"sigs,omitempty"` } -func (m *Multisignature) Reset() { *m = Multisignature{} } -func (m *Multisignature) String() string { return proto.CompactTextString(m) } -func (*Multisignature) ProtoMessage() {} -func (*Multisignature) Descriptor() ([]byte, []int) { +func (m *MultiSignature) Reset() { *m = MultiSignature{} } +func (m *MultiSignature) String() string { return proto.CompactTextString(m) } +func (*MultiSignature) ProtoMessage() {} +func (*MultiSignature) Descriptor() ([]byte, []int) { return fileDescriptor_2165b2a1badb1b0c, []int{2} } -func (m *Multisignature) XXX_Unmarshal(b []byte) error { +func (m *MultiSignature) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *Multisignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MultiSignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_Multisignature.Marshal(b, m, deterministic) + return xxx_messageInfo_MultiSignature.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -246,19 +246,19 @@ func (m *Multisignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return b[:n], nil } } -func (m *Multisignature) XXX_Merge(src proto.Message) { - xxx_messageInfo_Multisignature.Merge(m, src) +func (m *MultiSignature) XXX_Merge(src proto.Message) { + xxx_messageInfo_MultiSignature.Merge(m, src) } -func (m *Multisignature) XXX_Size() int { +func (m *MultiSignature) XXX_Size() int { return m.Size() } -func (m *Multisignature) XXX_DiscardUnknown() { - xxx_messageInfo_Multisignature.DiscardUnknown(m) +func (m *MultiSignature) XXX_DiscardUnknown() { + xxx_messageInfo_MultiSignature.DiscardUnknown(m) } -var xxx_messageInfo_Multisignature proto.InternalMessageInfo +var xxx_messageInfo_MultiSignature proto.InternalMessageInfo -func (m *Multisignature) GetSigs() [][]byte { +func (m *MultiSignature) GetSigs() [][]byte { if m != nil { return m.Sigs } @@ -324,45 +324,45 @@ func (m *CompactBitArray) GetElems() []byte { func init() { proto.RegisterType((*PublicKey)(nil), "cosmos_sdk.crypto.v1.PublicKey") proto.RegisterType((*PubKeyMultisigThreshold)(nil), "cosmos_sdk.crypto.v1.PubKeyMultisigThreshold") - proto.RegisterType((*Multisignature)(nil), "cosmos_sdk.crypto.v1.Multisignature") + proto.RegisterType((*MultiSignature)(nil), "cosmos_sdk.crypto.v1.MultiSignature") proto.RegisterType((*CompactBitArray)(nil), "cosmos_sdk.crypto.v1.CompactBitArray") } func init() { proto.RegisterFile("crypto/types/types.proto", fileDescriptor_2165b2a1badb1b0c) } var fileDescriptor_2165b2a1badb1b0c = []byte{ - // 486 bytes of a gzipped FileDescriptorProto + // 488 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xdd, 0x8a, 0xd3, 0x40, - 0x14, 0x6e, 0xda, 0xad, 0xb5, 0xb3, 0xeb, 0x56, 0x87, 0x82, 0xd9, 0x82, 0x49, 0x09, 0x22, 0x55, - 0xd8, 0x84, 0x54, 0xaa, 0xe8, 0xdd, 0x66, 0x6f, 0x16, 0x8a, 0x50, 0xb2, 0x5e, 0x88, 0x37, 0x21, - 0x3f, 0x63, 0x1a, 0x9a, 0x64, 0xc2, 0x9c, 0x89, 0x38, 0x2f, 0x21, 0x3e, 0x88, 0x0f, 0xe2, 0xe5, - 0x5e, 0x7a, 0x55, 0x24, 0x7d, 0x83, 0x7d, 0x02, 0xd9, 0x4c, 0xb2, 0x5d, 0xc4, 0xbd, 0x49, 0x66, - 0xce, 0xf7, 0x9d, 0x2f, 0xdf, 0x77, 0x4e, 0x90, 0x1a, 0x32, 0x51, 0x70, 0x6a, 0x71, 0x51, 0x10, - 0x90, 0x4f, 0xb3, 0x60, 0x94, 0x53, 0x3c, 0x0e, 0x29, 0x64, 0x14, 0x3c, 0x88, 0x36, 0xa6, 0x24, - 0x99, 0x5f, 0xed, 0xc9, 0x0b, 0xbe, 0x4e, 0x58, 0xe4, 0x15, 0x3e, 0xe3, 0xc2, 0xaa, 0x89, 0x56, - 0x4c, 0x63, 0xba, 0x3f, 0xc9, 0xee, 0xc9, 0x49, 0x4c, 0x69, 0x9c, 0x12, 0x49, 0x09, 0xca, 0x2f, - 0x96, 0x9f, 0x0b, 0x09, 0x19, 0xdf, 0xbb, 0x68, 0xb8, 0x2a, 0x83, 0x34, 0x09, 0x97, 0x44, 0x60, - 0x0d, 0x0d, 0x81, 0x84, 0xc5, 0x7c, 0xf1, 0x66, 0x63, 0xab, 0xca, 0x54, 0x99, 0x1d, 0x5d, 0x74, - 0xdc, 0x7d, 0x09, 0x4f, 0xd0, 0x80, 0x44, 0xf3, 0xc5, 0xc2, 0x7e, 0xa7, 0x76, 0x1b, 0xb4, 0x2d, - 0xdc, 0x60, 0xc0, 0x24, 0xd6, 0x6b, 0xb1, 0xa6, 0x80, 0x97, 0xe8, 0x61, 0x56, 0xa6, 0x3c, 0x81, - 0x24, 0x56, 0x0f, 0xa6, 0xca, 0xec, 0x70, 0x7e, 0x6a, 0xfe, 0x2f, 0x91, 0xb9, 0x2a, 0x83, 0x25, - 0x11, 0x1f, 0x1a, 0xee, 0xc7, 0x35, 0x23, 0xb0, 0xa6, 0x69, 0x74, 0xd1, 0x71, 0x6f, 0x05, 0xee, - 0x98, 0x64, 0xb6, 0xda, 0xff, 0xc7, 0x24, 0xb3, 0xf1, 0x02, 0x21, 0x3f, 0x17, 0x5e, 0x51, 0x06, - 0x1b, 0x22, 0xd4, 0x51, 0xfd, 0xb9, 0xb1, 0x29, 0x47, 0x60, 0xb6, 0x23, 0x30, 0xcf, 0x72, 0x71, - 0xd3, 0xe6, 0xe7, 0x62, 0x55, 0x13, 0x9d, 0x3e, 0xea, 0x41, 0x99, 0x19, 0x3f, 0x15, 0xf4, 0xf4, - 0x1e, 0x17, 0xf8, 0x2d, 0x1a, 0xf2, 0xf6, 0x52, 0x8f, 0xe7, 0x91, 0x73, 0x52, 0x6d, 0x75, 0x65, - 0x79, 0xbd, 0xd5, 0x1f, 0x0b, 0x3f, 0x4b, 0xdf, 0x1b, 0xb7, 0xb8, 0xe1, 0xee, 0xb9, 0xf8, 0x13, - 0x1a, 0x48, 0x3b, 0xa0, 0x76, 0xa7, 0xbd, 0xd9, 0xe1, 0x5c, 0xbf, 0x37, 0xbe, 0xdc, 0x84, 0xf3, - 0xac, 0xda, 0xea, 0x03, 0xe9, 0x03, 0xae, 0xb7, 0xfa, 0xb1, 0x54, 0x6f, 0x44, 0x0c, 0xb7, 0x95, - 0x33, 0x9e, 0xa3, 0xe3, 0xd6, 0x67, 0xee, 0xf3, 0x92, 0x11, 0x8c, 0xd1, 0x01, 0x24, 0x31, 0xa8, - 0xca, 0xb4, 0x37, 0x3b, 0x72, 0xeb, 0xb3, 0x71, 0x89, 0x46, 0xe7, 0x34, 0x2b, 0xfc, 0x90, 0x3b, - 0x09, 0x3f, 0x63, 0xcc, 0x17, 0xf8, 0x15, 0x7a, 0x42, 0xbe, 0x71, 0xe6, 0x7b, 0x41, 0xc2, 0xc1, - 0x03, 0x4e, 0x19, 0x69, 0x32, 0xb9, 0xa3, 0x1a, 0x70, 0x12, 0x0e, 0x97, 0x75, 0x19, 0x8f, 0x51, - 0x9f, 0xa4, 0x24, 0x03, 0xb9, 0x74, 0x57, 0x5e, 0x9c, 0xf3, 0x5f, 0x95, 0xa6, 0x5c, 0x55, 0x9a, - 0xf2, 0xa7, 0xd2, 0x94, 0x1f, 0x3b, 0xad, 0x73, 0xb5, 0xd3, 0x3a, 0xbf, 0x77, 0x5a, 0xe7, 0xf3, - 0xcb, 0x38, 0xe1, 0xeb, 0x32, 0x30, 0x43, 0x9a, 0x59, 0x32, 0x67, 0xf3, 0x3a, 0x85, 0x68, 0x63, - 0xdd, 0xfd, 0xc9, 0x83, 0x07, 0xf5, 0x42, 0x5e, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x57, 0x64, - 0xcc, 0x04, 0xfb, 0x02, 0x00, 0x00, + 0x18, 0x4d, 0xda, 0xad, 0xb5, 0xb3, 0xeb, 0x56, 0x87, 0x82, 0xd9, 0x82, 0x49, 0x09, 0x22, 0x55, + 0xd8, 0x84, 0x54, 0xaa, 0xe8, 0xdd, 0x66, 0x6f, 0x16, 0x8a, 0x50, 0x52, 0x2f, 0xc4, 0x9b, 0x90, + 0x9f, 0x31, 0x1d, 0x9a, 0x64, 0xc2, 0xcc, 0x44, 0x9c, 0x97, 0x10, 0x1f, 0xc4, 0x07, 0xf1, 0x72, + 0x2f, 0xbd, 0x2a, 0x92, 0xbe, 0xc1, 0x3e, 0x81, 0x6c, 0x26, 0xd9, 0x2e, 0x62, 0x6f, 0x92, 0x99, + 0xef, 0x9c, 0xef, 0xe4, 0x9c, 0xef, 0x0b, 0xd0, 0x22, 0x2a, 0x0a, 0x4e, 0x6c, 0x2e, 0x0a, 0xc4, + 0xe4, 0xd3, 0x2a, 0x28, 0xe1, 0x04, 0x8e, 0x22, 0xc2, 0x32, 0xc2, 0x7c, 0x16, 0x6f, 0x2c, 0x49, + 0xb2, 0xbe, 0x3a, 0xe3, 0x17, 0x7c, 0x8d, 0x69, 0xec, 0x17, 0x01, 0xe5, 0xc2, 0xae, 0x89, 0x76, + 0x42, 0x12, 0xb2, 0x3f, 0xc9, 0xee, 0xf1, 0x59, 0x42, 0x48, 0x92, 0x22, 0x49, 0x09, 0xcb, 0x2f, + 0x76, 0x90, 0x0b, 0x09, 0x99, 0xdf, 0x3b, 0x60, 0xb0, 0x2c, 0xc3, 0x14, 0x47, 0x0b, 0x24, 0xa0, + 0x0e, 0x06, 0x0c, 0x45, 0xc5, 0x6c, 0xfe, 0x66, 0xe3, 0x68, 0xea, 0x44, 0x9d, 0x9e, 0x5c, 0x29, + 0xde, 0xbe, 0x04, 0xc7, 0xa0, 0x8f, 0xe2, 0xd9, 0x7c, 0xee, 0xbc, 0xd3, 0x3a, 0x0d, 0xda, 0x16, + 0x6e, 0x31, 0x46, 0x25, 0xd6, 0x6d, 0xb1, 0xa6, 0x00, 0x17, 0xe0, 0x61, 0x56, 0xa6, 0x1c, 0x33, + 0x9c, 0x68, 0x47, 0x13, 0x75, 0x7a, 0x3c, 0x3b, 0xb7, 0xfe, 0x97, 0xc8, 0x5a, 0x96, 0xe1, 0x02, + 0x89, 0x0f, 0x0d, 0xf7, 0xe3, 0x9a, 0x22, 0xb6, 0x26, 0x69, 0x7c, 0xa5, 0x78, 0x77, 0x02, 0xf7, + 0x4c, 0x52, 0x47, 0xeb, 0xfd, 0x63, 0x92, 0x3a, 0x70, 0x0e, 0x40, 0x90, 0x0b, 0xbf, 0x28, 0xc3, + 0x0d, 0x12, 0xda, 0xb0, 0xfe, 0xdc, 0xc8, 0x92, 0x23, 0xb0, 0xda, 0x11, 0x58, 0x17, 0xb9, 0xb8, + 0x6d, 0x0b, 0x72, 0xb1, 0xac, 0x89, 0x6e, 0x0f, 0x74, 0x59, 0x99, 0x99, 0x3f, 0x55, 0xf0, 0xf4, + 0x80, 0x0b, 0xf8, 0x16, 0x0c, 0x78, 0x7b, 0xa9, 0xc7, 0xf3, 0xc8, 0x3d, 0xab, 0xb6, 0x86, 0xba, + 0xb8, 0xd9, 0x1a, 0x8f, 0x45, 0x90, 0xa5, 0xef, 0xcd, 0x3b, 0xdc, 0xf4, 0xf6, 0x5c, 0xf8, 0x09, + 0xf4, 0xa5, 0x1d, 0xa6, 0x75, 0x26, 0xdd, 0xe9, 0xf1, 0xcc, 0x38, 0x18, 0x5f, 0x6e, 0xc2, 0x7d, + 0x56, 0x6d, 0x8d, 0xbe, 0xf4, 0xc1, 0x6e, 0xb6, 0xc6, 0xa9, 0x54, 0x6f, 0x44, 0x4c, 0xaf, 0x95, + 0x33, 0x9f, 0x83, 0xd3, 0xda, 0xe7, 0x0a, 0x27, 0x79, 0xc0, 0x4b, 0x8a, 0x20, 0x04, 0x47, 0x0c, + 0x27, 0x4c, 0x53, 0x27, 0xdd, 0xe9, 0x89, 0x57, 0x9f, 0xcd, 0x15, 0x18, 0x5e, 0x92, 0xac, 0x08, + 0x22, 0xee, 0x62, 0x7e, 0x41, 0x69, 0x20, 0xe0, 0x2b, 0xf0, 0x04, 0x7d, 0xe3, 0x34, 0xf0, 0x43, + 0xcc, 0x99, 0xcf, 0x38, 0xa1, 0xa8, 0xc9, 0xe4, 0x0d, 0x6b, 0xc0, 0xc5, 0x9c, 0xad, 0xea, 0x32, + 0x1c, 0x81, 0x1e, 0x4a, 0x51, 0xc6, 0xe4, 0xd2, 0x3d, 0x79, 0x71, 0x2f, 0x7f, 0x55, 0xba, 0x7a, + 0x5d, 0xe9, 0xea, 0x9f, 0x4a, 0x57, 0x7f, 0xec, 0x74, 0xe5, 0x7a, 0xa7, 0x2b, 0xbf, 0x77, 0xba, + 0xf2, 0xf9, 0x65, 0x82, 0xf9, 0xba, 0x0c, 0xad, 0x88, 0x64, 0xb6, 0xcc, 0xd9, 0xbc, 0xce, 0x59, + 0xbc, 0xb1, 0xef, 0xff, 0xe4, 0xe1, 0x83, 0x7a, 0x21, 0xaf, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, + 0x82, 0xd0, 0x7b, 0xf3, 0xfb, 0x02, 0x00, 0x00, } func (m *PublicKey) Marshal() (dAtA []byte, err error) { @@ -545,7 +545,7 @@ func (m *PubKeyMultisigThreshold) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *Multisignature) Marshal() (dAtA []byte, err error) { +func (m *MultiSignature) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -555,12 +555,12 @@ func (m *Multisignature) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *Multisignature) MarshalTo(dAtA []byte) (int, error) { +func (m *MultiSignature) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *Multisignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MultiSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -725,7 +725,7 @@ func (m *PubKeyMultisigThreshold) Size() (n int) { return n } -func (m *Multisignature) Size() (n int) { +func (m *MultiSignature) Size() (n int) { if m == nil { return 0 } @@ -1123,7 +1123,7 @@ func (m *PubKeyMultisigThreshold) Unmarshal(dAtA []byte) error { } return nil } -func (m *Multisignature) Unmarshal(dAtA []byte) error { +func (m *MultiSignature) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1146,10 +1146,10 @@ func (m *Multisignature) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Multisignature: wiretype end group for non-group") + return fmt.Errorf("proto: MultiSignature: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Multisignature: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MultiSignature: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/server/mock/tx.go b/server/mock/tx.go index beec27133a01..27441051ce8a 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -16,7 +16,7 @@ type kvstoreTx struct { bytes []byte } -var _ sdk.TxI = kvstoreTx{} +var _ sdk.Tx = kvstoreTx{} func NewTx(key, value string) kvstoreTx { bytes := fmt.Sprintf("%s=%s", key, value) @@ -58,8 +58,8 @@ func (tx kvstoreTx) GetSigners() []sdk.AccAddress { // takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has // all the signatures and can be used to authenticate. -func decodeTx(txBytes []byte) (sdk.TxI, error) { - var tx sdk.TxI +func decodeTx(txBytes []byte) (sdk.Tx, error) { + var tx sdk.Tx split := bytes.Split(txBytes, []byte("=")) if len(split) == 1 { diff --git a/std/tx.go b/std/tx.go index a6f709eb56cf..f027efb40198 100644 --- a/std/tx.go +++ b/std/tx.go @@ -11,7 +11,7 @@ import ( ) var ( - _ sdk.TxI = (*Transaction)(nil) + _ sdk.Tx = (*Transaction)(nil) _ clientx.ClientTx = (*Transaction)(nil) _ clientx.Generator = TxGenerator{} _ clientx.ClientFee = &StdFee{} diff --git a/tests/mocks/types_handler.go b/tests/mocks/types_handler.go index 4025236a5c91..da80614ae884 100644 --- a/tests/mocks/types_handler.go +++ b/tests/mocks/types_handler.go @@ -34,7 +34,7 @@ func (m *MockAnteDecorator) EXPECT() *MockAnteDecoratorMockRecorder { } // AnteHandle mocks base method -func (m *MockAnteDecorator) AnteHandle(ctx types.Context, tx types.TxI, simulate bool, next types.AnteHandler) (types.Context, error) { +func (m *MockAnteDecorator) AnteHandle(ctx types.Context, tx types.Tx, simulate bool, next types.AnteHandler) (types.Context, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AnteHandle", ctx, tx, simulate, next) ret0, _ := ret[0].(types.Context) diff --git a/types/codec.go b/types/codec.go index 65e9b6e084ad..c00d95b2ee84 100644 --- a/types/codec.go +++ b/types/codec.go @@ -11,7 +11,7 @@ import ( // Register the sdk message type func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*Msg)(nil), nil) - cdc.RegisterInterface((*TxI)(nil), nil) + cdc.RegisterInterface((*Tx)(nil), nil) } // Register the sdk message type diff --git a/types/config_test.go b/types/config_test.go index 512ed107c99c..df208e32f361 100644 --- a/types/config_test.go +++ b/types/config_test.go @@ -24,9 +24,9 @@ func TestConfig_SetTxEncoder(t *testing.T) { mockErr := errors.New("test") config := sdk.NewConfig() require.Nil(t, config.GetTxEncoder()) - encFunc := sdk.TxEncoder(func(tx sdk.TxI) ([]byte, error) { return nil, nil }) + encFunc := sdk.TxEncoder(func(tx sdk.Tx) ([]byte, error) { return nil, nil }) config.SetTxEncoder(encFunc) - _, err := config.GetTxEncoder()(sdk.TxI(nil)) + _, err := config.GetTxEncoder()(sdk.Tx(nil)) require.Error(t, mockErr, err) config.Seal() diff --git a/types/handler.go b/types/handler.go index 62e6072fb34e..03d1f02d5806 100644 --- a/types/handler.go +++ b/types/handler.go @@ -5,11 +5,11 @@ type Handler func(ctx Context, msg Msg) (*Result, error) // AnteHandler authenticates transactions, before their internal messages are handled. // If newCtx.IsZero(), ctx is used instead. -type AnteHandler func(ctx Context, tx TxI, simulate bool) (newCtx Context, err error) +type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, err error) // AnteDecorator wraps the next AnteHandler to perform custom pre- and post-processing. type AnteDecorator interface { - AnteHandle(ctx Context, tx TxI, simulate bool, next AnteHandler) (newCtx Context, err error) + AnteHandle(ctx Context, tx Tx, simulate bool, next AnteHandler) (newCtx Context, err error) } // ChainDecorator chains AnteDecorators together with each AnteDecorator @@ -36,7 +36,7 @@ func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler { chain = append(chain, Terminator{}) } - return func(ctx Context, tx TxI, simulate bool) (Context, error) { + return func(ctx Context, tx Tx, simulate bool) (Context, error) { return chain[0].AnteHandle(ctx, tx, simulate, ChainAnteDecorators(chain[1:]...)) } } @@ -61,6 +61,6 @@ func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler { type Terminator struct{} // Simply return provided Context and nil error -func (t Terminator) AnteHandle(ctx Context, _ TxI, _ bool, _ AnteHandler) (Context, error) { +func (t Terminator) AnteHandle(ctx Context, _ Tx, _ bool, _ AnteHandler) (Context, error) { return ctx, nil } diff --git a/types/handler_test.go b/types/handler_test.go index 0470954009b1..670da2fccb55 100644 --- a/types/handler_test.go +++ b/types/handler_test.go @@ -15,7 +15,7 @@ func TestChainAnteDecorators(t *testing.T) { // test panic require.Nil(t, sdk.ChainAnteDecorators([]sdk.AnteDecorator{}...)) - ctx, tx := sdk.Context{}, sdk.TxI(nil) + ctx, tx := sdk.Context{}, sdk.Tx(nil) mockCtrl := gomock.NewController(t) mockAnteDecorator1 := mocks.NewMockAnteDecorator(mockCtrl) mockAnteDecorator1.EXPECT().AnteHandle(gomock.Eq(ctx), gomock.Eq(tx), true, gomock.Any()).Times(1) diff --git a/types/result.go b/types/result.go index f7cc38d00443..41fad03b0cff 100644 --- a/types/result.go +++ b/types/result.go @@ -79,12 +79,12 @@ type TxResponse struct { Info string `json:"info,omitempty"` GasWanted int64 `json:"gas_wanted,omitempty"` GasUsed int64 `json:"gas_used,omitempty"` - Tx TxI `json:"tx,omitempty"` + Tx Tx `json:"tx,omitempty"` Timestamp string `json:"timestamp,omitempty"` } // NewResponseResultTx returns a TxResponse given a ResultTx from tendermint -func NewResponseResultTx(res *ctypes.ResultTx, tx TxI, timestamp string) TxResponse { +func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) TxResponse { if res == nil { return TxResponse{} } diff --git a/types/result_test.go b/types/result_test.go index 06af4e12db6b..70f7d98fbbdb 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -91,12 +91,12 @@ func TestResponseResultTx(t *testing.T) { Info: "info", GasWanted: 100, GasUsed: 90, - Tx: sdk.TxI(nil), + Tx: sdk.Tx(nil), Timestamp: "timestamp", } - require.Equal(t, want, sdk.NewResponseResultTx(resultTx, sdk.TxI(nil), "timestamp")) - require.Equal(t, sdk.TxResponse{}, sdk.NewResponseResultTx(nil, sdk.TxI(nil), "timestamp")) + require.Equal(t, want, sdk.NewResponseResultTx(resultTx, sdk.Tx(nil), "timestamp")) + require.Equal(t, sdk.TxResponse{}, sdk.NewResponseResultTx(nil, sdk.Tx(nil), "timestamp")) require.Equal(t, `Response: Height: 10 TxHash: 74657374 @@ -108,7 +108,7 @@ func TestResponseResultTx(t *testing.T) { GasWanted: 100 GasUsed: 90 Codespace: codespace - Timestamp: timestamp`, sdk.NewResponseResultTx(resultTx, sdk.TxI(nil), "timestamp").String()) + Timestamp: timestamp`, sdk.NewResponseResultTx(resultTx, sdk.Tx(nil), "timestamp").String()) require.True(t, sdk.TxResponse{}.Empty()) require.False(t, want.Empty()) diff --git a/x/auth/ante/tx.go b/types/tx/raw/decoded_tx.go similarity index 95% rename from x/auth/ante/tx.go rename to types/tx/raw/decoded_tx.go index dd1389885501..16f29d3521fd 100644 --- a/x/auth/ante/tx.go +++ b/types/tx/raw/decoded_tx.go @@ -1,8 +1,10 @@ -package ante +package raw import ( "fmt" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,12 +22,12 @@ type DecodedTx struct { SignerInfoMap map[string]*sdk.SignerInfo } -var _ sdk.TxI = DecodedTx{} -var _ SigVerifiableTx = DecodedTx{} -var _ FeeTx = DecodedTx{} -var _ TxWithMemo = DecodedTx{} +var _ sdk.Tx = DecodedTx{} +var _ ante.SigVerifiableTx = DecodedTx{} +var _ ante.FeeTx = DecodedTx{} +var _ ante.TxWithMemo = DecodedTx{} -var DefaultTxDecoder sdk.TxDecoder = func(txBytes []byte) (sdk.TxI, error) { +var DefaultTxDecoder sdk.TxDecoder = func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := raw.Unmarshal(txBytes) if err != nil { diff --git a/types/tx/raw/types.pb.go b/types/tx/raw/types.pb.go new file mode 100644 index 000000000000..423b8669ab2a --- /dev/null +++ b/types/tx/raw/types.pb.go @@ -0,0 +1,787 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: types/tx/raw/types.proto + +package raw + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + 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 + +// TxRaw is using for transaction decoding and verification +type TxRaw struct { + BodyBytes []byte `protobuf:"bytes,1,opt,name=body_bytes,json=bodyBytes,proto3" json:"body_bytes,omitempty"` + AuthInfoBytes []byte `protobuf:"bytes,2,opt,name=auth_info_bytes,json=authInfoBytes,proto3" json:"auth_info_bytes,omitempty"` + Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` +} + +func (m *TxRaw) Reset() { *m = TxRaw{} } +func (m *TxRaw) String() string { return proto.CompactTextString(m) } +func (*TxRaw) ProtoMessage() {} +func (*TxRaw) Descriptor() ([]byte, []int) { + return fileDescriptor_e2501207b76f25b1, []int{0} +} +func (m *TxRaw) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxRaw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxRaw.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 *TxRaw) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxRaw.Merge(m, src) +} +func (m *TxRaw) XXX_Size() int { + return m.Size() +} +func (m *TxRaw) XXX_DiscardUnknown() { + xxx_messageInfo_TxRaw.DiscardUnknown(m) +} + +var xxx_messageInfo_TxRaw proto.InternalMessageInfo + +func (m *TxRaw) GetBodyBytes() []byte { + if m != nil { + return m.BodyBytes + } + return nil +} + +func (m *TxRaw) GetAuthInfoBytes() []byte { + if m != nil { + return m.AuthInfoBytes + } + return nil +} + +func (m *TxRaw) GetSignatures() [][]byte { + if m != nil { + return m.Signatures + } + return nil +} + +// SignDocRaw is used for verifying signatures with SIGN_MODE_DIRECT +type SignDocRaw struct { + BodyBytes []byte `protobuf:"bytes,1,opt,name=body_bytes,json=bodyBytes,proto3" json:"body_bytes,omitempty"` + AuthInfoBytes []byte `protobuf:"bytes,2,opt,name=auth_info_bytes,json=authInfoBytes,proto3" json:"auth_info_bytes,omitempty"` + ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + AccountNumber uint64 `protobuf:"varint,4,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` + AccountSequence uint64 `protobuf:"varint,5,opt,name=account_sequence,json=accountSequence,proto3" json:"account_sequence,omitempty"` +} + +func (m *SignDocRaw) Reset() { *m = SignDocRaw{} } +func (m *SignDocRaw) String() string { return proto.CompactTextString(m) } +func (*SignDocRaw) ProtoMessage() {} +func (*SignDocRaw) Descriptor() ([]byte, []int) { + return fileDescriptor_e2501207b76f25b1, []int{1} +} +func (m *SignDocRaw) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignDocRaw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignDocRaw.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 *SignDocRaw) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignDocRaw.Merge(m, src) +} +func (m *SignDocRaw) XXX_Size() int { + return m.Size() +} +func (m *SignDocRaw) XXX_DiscardUnknown() { + xxx_messageInfo_SignDocRaw.DiscardUnknown(m) +} + +var xxx_messageInfo_SignDocRaw proto.InternalMessageInfo + +func (m *SignDocRaw) GetBodyBytes() []byte { + if m != nil { + return m.BodyBytes + } + return nil +} + +func (m *SignDocRaw) GetAuthInfoBytes() []byte { + if m != nil { + return m.AuthInfoBytes + } + return nil +} + +func (m *SignDocRaw) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" +} + +func (m *SignDocRaw) GetAccountNumber() uint64 { + if m != nil { + return m.AccountNumber + } + return 0 +} + +func (m *SignDocRaw) GetAccountSequence() uint64 { + if m != nil { + return m.AccountSequence + } + return 0 +} + +func init() { + proto.RegisterType((*TxRaw)(nil), "cosmos_sdk.tx.raw.v1.TxRaw") + proto.RegisterType((*SignDocRaw)(nil), "cosmos_sdk.tx.raw.v1.SignDocRaw") +} + +func init() { proto.RegisterFile("types/tx/raw/types.proto", fileDescriptor_e2501207b76f25b1) } + +var fileDescriptor_e2501207b76f25b1 = []byte{ + // 299 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0xd1, 0x31, 0x4e, 0xf3, 0x30, + 0x14, 0xc0, 0xf1, 0xfa, 0x6b, 0xfb, 0x41, 0x9f, 0x5a, 0x8a, 0x22, 0x06, 0x33, 0x60, 0x45, 0x95, + 0x40, 0xe9, 0x40, 0x22, 0xc4, 0x0d, 0x0a, 0x4b, 0x17, 0x86, 0x94, 0x89, 0x25, 0x72, 0x1c, 0xb7, + 0xb5, 0xaa, 0xda, 0x25, 0xb6, 0x69, 0x73, 0x0b, 0x8e, 0xc4, 0xc8, 0xd8, 0x91, 0x11, 0x25, 0x17, + 0x41, 0x71, 0x83, 0xd4, 0x03, 0x30, 0x59, 0xef, 0xa7, 0xbf, 0x64, 0xe9, 0x3d, 0xc0, 0xa6, 0xd8, + 0x70, 0x1d, 0x99, 0x5d, 0x94, 0xd3, 0x6d, 0xe4, 0x86, 0x70, 0x93, 0x2b, 0xa3, 0xbc, 0x0b, 0xa6, + 0xf4, 0x5a, 0xe9, 0x44, 0x67, 0xab, 0xd0, 0xec, 0xc2, 0x9c, 0x6e, 0xc3, 0xb7, 0xbb, 0x91, 0x84, + 0xee, 0xf3, 0x2e, 0xa6, 0x5b, 0xef, 0x0a, 0x20, 0x55, 0x59, 0x91, 0xa4, 0x85, 0xe1, 0x1a, 0x23, + 0x1f, 0x05, 0xfd, 0xb8, 0x57, 0xcb, 0xa4, 0x06, 0xef, 0x06, 0x86, 0xd4, 0x9a, 0x65, 0x22, 0xe4, + 0x5c, 0x35, 0xcd, 0x3f, 0xd7, 0x0c, 0x6a, 0x9e, 0xca, 0xb9, 0x3a, 0x74, 0x04, 0x40, 0x8b, 0x85, + 0xa4, 0xc6, 0xe6, 0x5c, 0xe3, 0xb6, 0xdf, 0x0e, 0xfa, 0xf1, 0x91, 0x8c, 0x3e, 0x10, 0xc0, 0x4c, + 0x2c, 0xe4, 0xa3, 0x62, 0x7f, 0xf8, 0xeb, 0x25, 0x9c, 0xb2, 0x25, 0x15, 0x32, 0x11, 0x19, 0x6e, + 0xfb, 0x28, 0xe8, 0xc5, 0x27, 0x6e, 0x9e, 0x66, 0xde, 0x35, 0x9c, 0x51, 0xc6, 0x94, 0x95, 0x26, + 0x91, 0x76, 0x9d, 0xf2, 0x1c, 0x77, 0x7c, 0x14, 0x74, 0xe2, 0x41, 0xa3, 0x4f, 0x0e, 0xbd, 0x31, + 0x9c, 0xff, 0x66, 0x9a, 0xbf, 0x5a, 0x2e, 0x19, 0xc7, 0x5d, 0x17, 0x0e, 0x1b, 0x9f, 0x35, 0x3c, + 0x79, 0xf8, 0x2c, 0x09, 0xda, 0x97, 0x04, 0x7d, 0x97, 0x04, 0xbd, 0x57, 0xa4, 0xb5, 0xaf, 0x48, + 0xeb, 0xab, 0x22, 0xad, 0x97, 0xf1, 0x42, 0x98, 0xa5, 0x4d, 0x43, 0xa6, 0xd6, 0xd1, 0x61, 0xdb, + 0xcd, 0x73, 0xab, 0xb3, 0x55, 0x74, 0x7c, 0x99, 0xf4, 0xbf, 0x3b, 0xca, 0xfd, 0x4f, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xa2, 0xbe, 0x03, 0xb1, 0xb0, 0x01, 0x00, 0x00, +} + +func (m *TxRaw) 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 *TxRaw) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TxRaw) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signatures) > 0 { + for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Signatures[iNdEx]) + copy(dAtA[i:], m.Signatures[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Signatures[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.AuthInfoBytes) > 0 { + i -= len(m.AuthInfoBytes) + copy(dAtA[i:], m.AuthInfoBytes) + i = encodeVarintTypes(dAtA, i, uint64(len(m.AuthInfoBytes))) + i-- + dAtA[i] = 0x12 + } + if len(m.BodyBytes) > 0 { + i -= len(m.BodyBytes) + copy(dAtA[i:], m.BodyBytes) + i = encodeVarintTypes(dAtA, i, uint64(len(m.BodyBytes))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SignDocRaw) 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 *SignDocRaw) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignDocRaw) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AccountSequence != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.AccountSequence)) + i-- + dAtA[i] = 0x28 + } + if m.AccountNumber != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.AccountNumber)) + i-- + dAtA[i] = 0x20 + } + if len(m.ChainId) > 0 { + i -= len(m.ChainId) + copy(dAtA[i:], m.ChainId) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ChainId))) + i-- + dAtA[i] = 0x1a + } + if len(m.AuthInfoBytes) > 0 { + i -= len(m.AuthInfoBytes) + copy(dAtA[i:], m.AuthInfoBytes) + i = encodeVarintTypes(dAtA, i, uint64(len(m.AuthInfoBytes))) + i-- + dAtA[i] = 0x12 + } + if len(m.BodyBytes) > 0 { + i -= len(m.BodyBytes) + copy(dAtA[i:], m.BodyBytes) + i = encodeVarintTypes(dAtA, i, uint64(len(m.BodyBytes))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *TxRaw) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BodyBytes) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.AuthInfoBytes) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Signatures) > 0 { + for _, b := range m.Signatures { + l = len(b) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *SignDocRaw) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BodyBytes) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.AuthInfoBytes) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.AccountNumber != 0 { + n += 1 + sovTypes(uint64(m.AccountNumber)) + } + if m.AccountSequence != 0 { + n += 1 + sovTypes(uint64(m.AccountSequence)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *TxRaw) 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 ErrIntOverflowTypes + } + 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: TxRaw: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TxRaw: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BodyBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BodyBytes = append(m.BodyBytes[:0], dAtA[iNdEx:postIndex]...) + if m.BodyBytes == nil { + m.BodyBytes = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthInfoBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AuthInfoBytes = append(m.AuthInfoBytes[:0], dAtA[iNdEx:postIndex]...) + if m.AuthInfoBytes == nil { + m.AuthInfoBytes = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) + copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignDocRaw) 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 ErrIntOverflowTypes + } + 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: SignDocRaw: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignDocRaw: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BodyBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BodyBytes = append(m.BodyBytes[:0], dAtA[iNdEx:postIndex]...) + if m.BodyBytes == nil { + m.BodyBytes = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthInfoBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AuthInfoBytes = append(m.AuthInfoBytes[:0], dAtA[iNdEx:postIndex]...) + if m.AuthInfoBytes == nil { + m.AuthInfoBytes = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) + } + m.AccountNumber = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountNumber |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountSequence", wireType) + } + m.AccountSequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountSequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auth/ante/types.proto b/types/tx/raw/types.proto similarity index 82% rename from x/auth/ante/types.proto rename to types/tx/raw/types.proto index d8e5d0943e72..4297fc74bbd5 100644 --- a/x/auth/ante/types.proto +++ b/types/tx/raw/types.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package cosmos_sdk.v1.signing; +package cosmos_sdk.tx.raw.v1; -option go_package = "github.com/cosmos/cosmos-sdk/x/auth/ante"; +option go_package = "github.com/cosmos/cosmos-sdk/types/tx/raw"; // TxRaw is using for transaction decoding and verification message TxRaw { diff --git a/types/tx_msg.go b/types/tx_msg.go index 7eac35522c48..bf921727285e 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -46,7 +46,7 @@ type ( } // Tx defines the interface a transaction must fulfill. - TxI interface { + Tx interface { // Gets the all the transaction's messages. GetMsgs() []Msg @@ -57,10 +57,10 @@ type ( ) // TxDecoder unmarshals transaction bytes -type TxDecoder func(txBytes []byte) (TxI, error) +type TxDecoder func(txBytes []byte) (Tx, error) // TxEncoder marshals transaction to bytes -type TxEncoder func(tx TxI) ([]byte, error) +type TxEncoder func(tx Tx) ([]byte, error) //__________________________________________________________ diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 6157298eaaa5..9278caff2b0d 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -21,13 +21,13 @@ import ( ) // run the tx through the anteHandler and ensure its valid -func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.TxI, simulate bool) { +func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool) { _, err := anteHandler(ctx, tx, simulate) require.Nil(t, err) } // run the tx through the anteHandler and ensure it fails with the given code -func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.TxI, simulate bool, expErr error) { +func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool, expErr error) { _, err := anteHandler(ctx, tx, simulate) require.NotNil(t, err) require.True(t, errors.Is(expErr, err)) @@ -63,7 +63,7 @@ func TestSimulateGasCost(t *testing.T) { require.NoError(t, err) // set up msgs and fee - var tx sdk.TxI + var tx sdk.Tx msg1 := types.NewTestMsg(addr1, addr2) msg2 := types.NewTestMsg(addr3, addr1) msg3 := types.NewTestMsg(addr2, addr3) @@ -100,7 +100,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { priv3, _, addr3 := types.KeyTestPubAddr() // msg and signatures - var tx sdk.TxI + var tx sdk.Tx msg1 := types.NewTestMsg(addr1, addr2) msg2 := types.NewTestMsg(addr1, addr3) fee := types.NewTestStdFee() @@ -161,7 +161,7 @@ func TestAnteHandlerAccountNumbers(t *testing.T) { require.NoError(t, err) // msg and signatures - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) fee := types.NewTestStdFee() @@ -219,7 +219,7 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) { require.NoError(t, err) // msg and signatures - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) fee := types.NewTestStdFee() @@ -281,7 +281,7 @@ func TestAnteHandlerSequences(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr3, types.NewTestCoins()) // msg and signatures - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) fee := types.NewTestStdFee() @@ -345,7 +345,7 @@ func TestAnteHandlerFees(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc1) // msg and signatures - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := types.NewTestStdFee() @@ -388,7 +388,7 @@ func TestAnteHandlerMemoGas(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc1) // msg and signatures - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := types.NewStdFee(0, sdk.NewCoins(sdk.NewInt64Coin("atom", 0))) @@ -439,7 +439,7 @@ func TestAnteHandlerMultiSigner(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr3, types.NewTestCoins()) // set up msgs and fee - var tx sdk.TxI + var tx sdk.Tx msg1 := types.NewTestMsg(addr1, addr2) msg2 := types.NewTestMsg(addr3, addr1) msg3 := types.NewTestMsg(addr2, addr3) @@ -483,7 +483,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc2) app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins()) - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) msgs := []sdk.Msg{msg} fee := types.NewTestStdFee() @@ -560,7 +560,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc2) app.BankKeeper.SetBalances(ctx, addr2, types.NewTestCoins()) - var tx sdk.TxI + var tx sdk.Tx // test good tx and set public key msg := types.NewTestMsg(addr1) @@ -685,7 +685,7 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr, types.NewTestCoins()) } - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8) msgs := []sdk.Msg{msg} fee := types.NewTestStdFee() @@ -719,7 +719,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) { app.AccountKeeper.SetAccount(ctx, acc1) app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 150))) - var tx sdk.TxI + var tx sdk.Tx msg := types.NewTestMsg(addr1) privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := types.NewTestStdFee() diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 5fc4c223080a..41ba96d8bb73 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -25,7 +25,7 @@ func NewValidateBasicDecorator() ValidateBasicDecorator { return ValidateBasicDecorator{} } -func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { // no need to validate basic on recheck tx, call next antehandler if ctx.IsReCheckTx() { return next(ctx, tx, simulate) @@ -40,7 +40,7 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simula // Tx must have GetMemo() method to use ValidateMemoDecorator type TxWithMemo interface { - sdk.TxI + sdk.Tx GetMemo() string } @@ -57,7 +57,7 @@ func NewValidateMemoDecorator(ak AccountKeeper) ValidateMemoDecorator { } } -func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { memoTx, ok := tx.(TxWithMemo) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") @@ -95,7 +95,7 @@ func NewConsumeGasForTxSizeDecorator(ak AccountKeeper) ConsumeTxSizeGasDecorator } } -func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 85d7ee05c665..5b1044c58664 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -15,7 +15,7 @@ var ( // FeeTx defines the interface to be implemented by Tx to use the FeeDecorators type FeeTx interface { - sdk.TxI + sdk.Tx GetGas() uint64 GetFee() sdk.Coins FeePayer() sdk.AccAddress @@ -33,7 +33,7 @@ func NewMempoolFeeDecorator() MempoolFeeDecorator { return MempoolFeeDecorator{} } -func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { feeTx, ok := tx.(FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") @@ -82,7 +82,7 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper) DeductFeeDecor } } -func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { feeTx, ok := tx.(FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 57246cdf8268..1e3e8eb68d67 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -14,7 +14,7 @@ var ( // GasTx defines a Tx with a GetGas() method which is needed to use SetUpContextDecorator type GasTx interface { - sdk.TxI + sdk.Tx GetGas() uint64 } @@ -29,7 +29,7 @@ func NewSetUpContextDecorator() SetUpContextDecorator { return SetUpContextDecorator{} } -func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { // all transactions must implement GasTx gasTx, ok := tx.(GasTx) if !ok { diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index c2ee4287541e..698a0ecedbd1 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -80,7 +80,7 @@ func TestRecoverPanic(t *testing.T) { type OutOfGasDecorator struct{} // AnteDecorator that will throw OutOfGas panic -func (ogd OutOfGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (ogd OutOfGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { overLimit := ctx.GasMeter().Limit() + 1 // Should panic with outofgas error @@ -92,6 +92,6 @@ func (ogd OutOfGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bo type PanicDecorator struct{} -func (pd PanicDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (pd PanicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { panic("random error") } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 2d7fe3fa16bf..9719b3cfeaa1 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -37,7 +37,15 @@ type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pub // SigVerifiableTx defines a Tx interface for all signature verification decorators type SigVerifiableTx interface { - sdk.TxI + sdk.Tx + GetSignatures() [][]byte + GetSigners() []sdk.AccAddress + GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place + GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, error) +} + +type SigVerifiableTx interface { + sdk.Tx GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place @@ -57,7 +65,7 @@ func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { } } -func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") @@ -114,7 +122,7 @@ func NewSigGasConsumeDecorator(ak AccountKeeper, sigGasConsumer SignatureVerific } } -func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") @@ -167,7 +175,7 @@ func NewSigVerificationDecorator(ak AccountKeeper) SigVerificationDecorator { } } -func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { +func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { // no need to verify signatures on recheck tx if ctx.IsReCheckTx() { return next(ctx, tx, simulate) @@ -234,7 +242,7 @@ func NewIncrementSequenceDecorator(ak AccountKeeper) IncrementSequenceDecorator } } -func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { // no need to increment sequence on RecheckTx if ctx.IsReCheckTx() && !simulate { return next(ctx, tx, simulate) @@ -272,7 +280,7 @@ func NewValidateSigCountDecorator(ak AccountKeeper) ValidateSigCountDecorator { } } -func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { sigTx, ok := tx.(SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") diff --git a/x/auth/client/query.go b/x/auth/client/query.go index c16776a08e37..85bd747bc3c5 100644 --- a/x/auth/client/query.go +++ b/x/auth/client/query.go @@ -169,7 +169,7 @@ func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.R return sdk.NewResponseResultTx(resTx, tx, resBlock.Block.Time.Format(time.RFC3339)), nil } -func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.TxI, error) { +func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { var tx types.StdTx err := cdc.UnmarshalBinaryBare(txBytes, &tx) diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 970f39a6b1d0..ab2ce267ece3 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -103,7 +103,7 @@ func TestDefaultTxEncoder(t *testing.T) { func TestConfiguredTxEncoder(t *testing.T) { cdc := makeCodec() - customEncoder := func(tx sdk.TxI) ([]byte, error) { + customEncoder := func(tx sdk.Tx) ([]byte, error) { return json.Marshal(tx) } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 770b01e8c0e9..4af9ba26556a 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -140,7 +140,7 @@ func CountSubKeys(pub crypto.PubKey) int { // DEPRECATED // --------------------------------------------------------------------------- -var _ sdk.TxI = (*StdTx)(nil) +var _ sdk.Tx = (*StdTx)(nil) // StdTx is a standard way to wrap a Msg with FeeI and Signatures. // NOTE: the first signature is the fee payer (Signatures must not be nil). @@ -319,7 +319,7 @@ type StdSignature struct { // DefaultTxDecoder logic for standard transaction decoding func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { - return func(txBytes []byte) (sdk.TxI, error) { + return func(txBytes []byte) (sdk.Tx, error) { var tx = StdTx{} if len(txBytes) == 0 { @@ -339,7 +339,7 @@ func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { // DefaultTxEncoder logic for standard transaction encoding func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder { - return func(tx sdk.TxI) ([]byte, error) { + return func(tx sdk.Tx) ([]byte, error) { return cdc.MarshalBinaryBare(tx) } } diff --git a/x/auth/types/test_utils.go b/x/auth/types/test_utils.go index 15c724587bec..4c0d801af377 100644 --- a/x/auth/types/test_utils.go +++ b/x/auth/types/test_utils.go @@ -31,7 +31,7 @@ func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { return key, pub, addr } -func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.TxI { +func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "") @@ -48,7 +48,7 @@ func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums return tx } -func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.TxI { +func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo) @@ -65,7 +65,7 @@ func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, return tx } -func NewTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.TxI { +func NewTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { sig, err := priv.Sign(signBytes) diff --git a/x/genutil/client/rest/query.go b/x/genutil/client/rest/query.go index b737443fc2bf..0159223e8e7c 100644 --- a/x/genutil/client/rest/query.go +++ b/x/genutil/client/rest/query.go @@ -32,7 +32,7 @@ func QueryGenesisTxs(cliCtx context.CLIContext, w http.ResponseWriter) { } genState := types.GetGenesisStateFromAppState(cliCtx.Codec, appState) - genTxs := make([]sdk.TxI, len(genState.GenTxs)) + genTxs := make([]sdk.Tx, len(genState.GenTxs)) for i, tx := range genState.GenTxs { err := cliCtx.Codec.UnmarshalJSON(tx, &genTxs[i]) if err != nil { diff --git a/x/ibc/ante/ante.go b/x/ibc/ante/ante.go index b542bd886ef2..82484be5a32e 100644 --- a/x/ibc/ante/ante.go +++ b/x/ibc/ante/ante.go @@ -25,7 +25,7 @@ func NewProofVerificationDecorator(clientKeeper client.Keeper, channelKeeper cha // AnteHandle executes MsgUpdateClient, MsgPacket, MsgAcknowledgement, MsgTimeout. // The packet execution messages are then passed to the respective application handlers. -func (pvr ProofVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.TxI, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { +func (pvr ProofVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { for _, msg := range tx.GetMsgs() { var err error switch msg := msg.(type) { diff --git a/x/ibc/ante/ante_test.go b/x/ibc/ante/ante_test.go index 99c41e7f05f5..727a82a751f1 100644 --- a/x/ibc/ante/ante_test.go +++ b/x/ibc/ante/ante_test.go @@ -75,7 +75,7 @@ func queryProof(chain *TestChain, key string) (proof commitmenttypes.MerkleProof return } -func (suite *HandlerTestSuite) newTx(msg sdk.Msg) sdk.TxI { +func (suite *HandlerTestSuite) newTx(msg sdk.Msg) sdk.Tx { return authtypes.StdTx{ Msgs: []sdk.Msg{msg}, } From 6e6142c7214f5f77bc1db19212096568a4da56f6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 14:32:23 -0400 Subject: [PATCH 09/54] Cleanup --- client/tx/tx.go | 4 +- types/{ => tx}/tx.go | 0 types/tx_msg.go | 4 +- types/types.pb.go | 4334 +++++++---------------------------------- types/types.proto | 175 -- x/auth/types/stdtx.go | 2 +- 6 files changed, 669 insertions(+), 3850 deletions(-) rename types/{ => tx}/tx.go (100%) diff --git a/client/tx/tx.go b/client/tx/tx.go index db55aacc96df..7ae89d0aff53 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -32,7 +32,7 @@ type ( } ClientFee interface { - sdk.FeeI + sdk.Fee SetGas(uint64) SetAmount(sdk.Coins) } @@ -54,7 +54,7 @@ type ( SetMsgs(...sdk.Msg) error GetSignatures() []sdk.Signature SetSignatures(...ClientSignature) error - GetFee() sdk.FeeI + GetFee() sdk.Fee SetFee(ClientFee) error GetMemo() string SetMemo(string) diff --git a/types/tx.go b/types/tx/tx.go similarity index 100% rename from types/tx.go rename to types/tx/tx.go diff --git a/types/tx_msg.go b/types/tx_msg.go index bf921727285e..9123cd9be94a 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -31,9 +31,9 @@ type ( GetSigners() []AccAddress } - // FeeI defines an interface for an application application-defined concrete + // Fee defines an interface for an application application-defined concrete // transaction type to be able to set and return the transaction fee. - FeeI interface { + Fee interface { GetGas() uint64 GetAmount() Coins } diff --git a/types/types.pb.go b/types/types.pb.go index 9201610e0d80..6b4d9813ab5f 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -5,7 +5,6 @@ package types import ( fmt "fmt" - types1 "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/tendermint/tendermint/abci/types" @@ -27,45 +26,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// SignMode represents a signing mode with its own security guarantees -type SignMode int32 - -const ( - // SIGN_MODE_UNSPECIFIED specifies an unknown signing mode and will be rejected - SignMode_SIGN_MODE_UNSPECIFIED SignMode = 0 - // SIGN_MODE_DIRECT specifies a signing mode which uses SignDoc and is verified - // with raw bytes from Tx - SignMode_SIGN_MODE_DIRECT SignMode = 1 - // SIGN_MODE_TEXTUAL is a future signing mode that will verify some human-readable - // textual representation on top of the binary representation from SIGN_MODE_DIRECT - SignMode_SIGN_MODE_TEXTUAL SignMode = 2 - // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses - // Amino JSON and will be removed in the future - SignMode_SIGN_MODE_LEGACY_AMINO_JSON SignMode = 127 -) - -var SignMode_name = map[int32]string{ - 0: "SIGN_MODE_UNSPECIFIED", - 1: "SIGN_MODE_DIRECT", - 2: "SIGN_MODE_TEXTUAL", - 127: "SIGN_MODE_LEGACY_AMINO_JSON", -} - -var SignMode_value = map[string]int32{ - "SIGN_MODE_UNSPECIFIED": 0, - "SIGN_MODE_DIRECT": 1, - "SIGN_MODE_TEXTUAL": 2, - "SIGN_MODE_LEGACY_AMINO_JSON": 127, -} - -func (x SignMode) String() string { - return proto.EnumName(SignMode_name, int32(x)) -} - -func (SignMode) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{0} -} - // Coin defines a token with a denomination and an amount. // // NOTE: The amount field is an Int which implements the custom method @@ -424,3419 +384,574 @@ func (m *SimulationResponse) GetResult() *Result { return nil } -// Tx is the standard type used for broadcasting transactions -type Tx struct { - // body is the processable content of the transaction - Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` - // auth_info is the authorization related content of the transaction, specifically - // signers, signer modes and fee - AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` - // signatures are the raw binary signatures of signers specified by body and auth_info - Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` -} - -func (m *Tx) Reset() { *m = Tx{} } -func (*Tx) ProtoMessage() {} -func (*Tx) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{8} -} -func (m *Tx) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Tx) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Tx.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 *Tx) XXX_Merge(src proto.Message) { - xxx_messageInfo_Tx.Merge(m, src) -} -func (m *Tx) XXX_Size() int { - return m.Size() -} -func (m *Tx) XXX_DiscardUnknown() { - xxx_messageInfo_Tx.DiscardUnknown(m) +func init() { + proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin") + proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin") + proto.RegisterType((*IntProto)(nil), "cosmos_sdk.v1.IntProto") + proto.RegisterType((*DecProto)(nil), "cosmos_sdk.v1.DecProto") + proto.RegisterType((*ValAddresses)(nil), "cosmos_sdk.v1.ValAddresses") + proto.RegisterType((*GasInfo)(nil), "cosmos_sdk.v1.GasInfo") + proto.RegisterType((*Result)(nil), "cosmos_sdk.v1.Result") + proto.RegisterType((*SimulationResponse)(nil), "cosmos_sdk.v1.SimulationResponse") } -var xxx_messageInfo_Tx proto.InternalMessageInfo +func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } -func (m *Tx) GetBody() *TxBody { - if m != nil { - return m.Body - } - return nil +var fileDescriptor_2c0f90c600ad7e2e = []byte{ + // 534 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4f, 0x6f, 0xd3, 0x4e, + 0x10, 0xb5, 0x7f, 0xf6, 0x2f, 0x7f, 0x36, 0xe1, 0x4f, 0x17, 0x8a, 0xa2, 0x0a, 0xec, 0xc8, 0x48, + 0x28, 0x48, 0xd4, 0x16, 0x29, 0xa7, 0x70, 0xc2, 0x04, 0x55, 0xe1, 0x84, 0x16, 0x01, 0x12, 0x97, + 0x68, 0xe3, 0xdd, 0xba, 0x56, 0xe3, 0xdd, 0xc8, 0xbb, 0x29, 0xca, 0x2d, 0x47, 0x8e, 0x7c, 0x84, + 0x7e, 0x9c, 0x1e, 0x73, 0xac, 0x10, 0xb2, 0x20, 0xb9, 0x70, 0xee, 0x91, 0x13, 0xda, 0xb5, 0xc1, + 0x6a, 0x7a, 0xe3, 0x92, 0xcc, 0xce, 0xbc, 0x79, 0x33, 0xf3, 0xfc, 0xc0, 0x8e, 0x5c, 0xcc, 0xa8, + 0x08, 0xf4, 0xaf, 0x3f, 0xcb, 0xb8, 0xe4, 0xf0, 0x46, 0xc4, 0x45, 0xca, 0xc5, 0x58, 0x90, 0x13, + 0xff, 0xf4, 0xe9, 0xde, 0x23, 0x79, 0x9c, 0x64, 0x64, 0x3c, 0xc3, 0x99, 0x5c, 0x04, 0x1a, 0x11, + 0xc4, 0x3c, 0xe6, 0x55, 0x54, 0xb4, 0xed, 0x1d, 0x5c, 0xc7, 0x49, 0xca, 0x08, 0xcd, 0xd2, 0x84, + 0xc9, 0x00, 0x4f, 0xa2, 0x24, 0xb8, 0x36, 0xcb, 0x3b, 0x04, 0xf6, 0x4b, 0x9e, 0x30, 0x78, 0x17, + 0xfc, 0x4f, 0x28, 0xe3, 0x69, 0xc7, 0xec, 0x9a, 0xbd, 0x26, 0x2a, 0x1e, 0xf0, 0x21, 0xa8, 0xe1, + 0x94, 0xcf, 0x99, 0xec, 0xfc, 0xa7, 0xd2, 0x61, 0xeb, 0x3c, 0x77, 0x8d, 0xaf, 0xb9, 0x6b, 0x8d, + 0x98, 0x44, 0x65, 0x69, 0x60, 0xff, 0x3c, 0x73, 0x4d, 0xef, 0x35, 0xa8, 0x0f, 0x69, 0xf4, 0x2f, + 0x5c, 0x43, 0x1a, 0x6d, 0x71, 0x3d, 0x06, 0x8d, 0x11, 0x93, 0x6f, 0xb4, 0x18, 0x0f, 0x80, 0x95, + 0x30, 0x59, 0x50, 0x5d, 0x9d, 0xaf, 0xf2, 0x0a, 0x3a, 0xa4, 0xd1, 0x5f, 0x28, 0xa1, 0xd1, 0x36, + 0x54, 0xd1, 0xab, 0xbc, 0x17, 0x82, 0xf6, 0x7b, 0x3c, 0x7d, 0x41, 0x48, 0x46, 0x85, 0xa0, 0x02, + 0x3e, 0x01, 0x4d, 0xfc, 0xe7, 0xd1, 0x31, 0xbb, 0x56, 0xaf, 0x1d, 0xde, 0xfc, 0x95, 0xbb, 0xa0, + 0x02, 0xa1, 0x0a, 0x30, 0xb0, 0x97, 0xdf, 0xba, 0xa6, 0xc7, 0x41, 0xfd, 0x10, 0x8b, 0x11, 0x3b, + 0xe2, 0xf0, 0x19, 0x00, 0x31, 0x16, 0xe3, 0x4f, 0x98, 0x49, 0x4a, 0xf4, 0x50, 0x3b, 0xdc, 0xbd, + 0xcc, 0xdd, 0x9d, 0x05, 0x4e, 0xa7, 0x03, 0xaf, 0xaa, 0x79, 0xa8, 0x19, 0x63, 0xf1, 0x41, 0xc7, + 0xd0, 0x07, 0x0d, 0x55, 0x99, 0x0b, 0x4a, 0xb4, 0x0e, 0x76, 0x78, 0xe7, 0x32, 0x77, 0x6f, 0x55, + 0x3d, 0xaa, 0xe2, 0xa1, 0x7a, 0x8c, 0xc5, 0x3b, 0x15, 0xcd, 0x40, 0x0d, 0x51, 0x31, 0x9f, 0x4a, + 0x08, 0x81, 0x4d, 0xb0, 0xc4, 0x7a, 0x52, 0x1b, 0xe9, 0x18, 0xde, 0x06, 0xd6, 0x94, 0xc7, 0x85, + 0xa0, 0x48, 0x85, 0x70, 0x00, 0x6a, 0xf4, 0x94, 0x32, 0x29, 0x3a, 0x56, 0xd7, 0xea, 0xb5, 0xfa, + 0xf7, 0xfd, 0xca, 0x03, 0xbe, 0xf2, 0x80, 0x5f, 0x7c, 0xfd, 0x57, 0x0a, 0x14, 0xda, 0x4a, 0x24, + 0x54, 0x76, 0x0c, 0xec, 0xcf, 0x67, 0xae, 0xe1, 0x2d, 0x4d, 0x00, 0xdf, 0x26, 0xe9, 0x7c, 0x8a, + 0x65, 0xc2, 0x19, 0xa2, 0x62, 0xc6, 0x99, 0xa0, 0xf0, 0x79, 0xb1, 0x78, 0xc2, 0x8e, 0xb8, 0x5e, + 0xa1, 0xd5, 0xbf, 0xe7, 0x5f, 0xf1, 0xa9, 0x5f, 0x0a, 0x13, 0x36, 0x14, 0xe9, 0x2a, 0x77, 0x4d, + 0x7d, 0x85, 0xd6, 0x6a, 0x1f, 0xd4, 0x32, 0x7d, 0x85, 0x5e, 0xb5, 0xd5, 0xdf, 0xdd, 0x6a, 0x2d, + 0x4e, 0x44, 0x25, 0x28, 0x1c, 0x5e, 0xfc, 0x70, 0x8c, 0xe5, 0xda, 0x31, 0xce, 0xd7, 0x8e, 0xb9, + 0x5a, 0x3b, 0xe6, 0xf7, 0xb5, 0x63, 0x7e, 0xd9, 0x38, 0xc6, 0x6a, 0xe3, 0x18, 0x17, 0x1b, 0xc7, + 0xf8, 0xe8, 0xc5, 0x89, 0x3c, 0x9e, 0x4f, 0xfc, 0x88, 0xa7, 0x41, 0x41, 0x55, 0xfe, 0xed, 0x0b, + 0x72, 0x52, 0x18, 0x7c, 0x52, 0xd3, 0x0e, 0x3f, 0xf8, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x0e, 0xe8, + 0xc3, 0x0c, 0x62, 0x03, 0x00, 0x00, } -func (m *Tx) GetAuthInfo() *AuthInfo { - if m != nil { - return m.AuthInfo +func (this *Coin) Equal(that interface{}) bool { + if that == nil { + return this == nil } - return nil -} -func (m *Tx) GetSignatures() [][]byte { - if m != nil { - return m.Signatures + that1, ok := that.(*Coin) + if !ok { + that2, ok := that.(Coin) + if ok { + that1 = &that2 + } else { + return false + } } - return nil -} - -// SignDoc is the standard type used for signing transaction in SIGN_MODE_DIRECT -type SignDoc struct { - // body is the TxBody from Tx - Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` - // auth_info is the AuthInfo from Tx - AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` - // chain_id is the unique identifier of the chain this transaction targets. - // It prevents signed transactions from being used on another chain by an - // attacker - ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - // account_number is the account number of the account in state - AccountNumber uint64 `protobuf:"varint,4,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` - // account_sequence starts at 1 rather than 0 to avoid the case where - // the default 0 value must be omitted in protobuf serialization - AccountSequence uint64 `protobuf:"varint,5,opt,name=account_sequence,json=accountSequence,proto3" json:"account_sequence,omitempty"` + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Denom != that1.Denom { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true } +func (this *DecCoin) Equal(that interface{}) bool { + if that == nil { + return this == nil + } -func (m *SignDoc) Reset() { *m = SignDoc{} } -func (*SignDoc) ProtoMessage() {} -func (*SignDoc) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{9} -} -func (m *SignDoc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SignDoc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SignDoc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err + that1, ok := that.(*DecCoin) + if !ok { + that2, ok := that.(DecCoin) + if ok { + that1 = &that2 + } else { + return false } - return b[:n], nil } -} -func (m *SignDoc) XXX_Merge(src proto.Message) { - xxx_messageInfo_SignDoc.Merge(m, src) -} -func (m *SignDoc) XXX_Size() int { - return m.Size() -} -func (m *SignDoc) XXX_DiscardUnknown() { - xxx_messageInfo_SignDoc.DiscardUnknown(m) -} - -var xxx_messageInfo_SignDoc proto.InternalMessageInfo - -func (m *SignDoc) GetBody() *TxBody { - if m != nil { - return m.Body + if that1 == nil { + return this == nil + } else if this == nil { + return false } - return nil + if this.Denom != that1.Denom { + return false + } + if !this.Amount.Equal(that1.Amount) { + return false + } + return true } - -func (m *SignDoc) GetAuthInfo() *AuthInfo { - if m != nil { - return m.AuthInfo +func (m *Coin) 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 nil + return dAtA[:n], nil } -func (m *SignDoc) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" +func (m *Coin) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *SignDoc) GetAccountNumber() uint64 { - if m != nil { - return m.AccountNumber +func (m *Coin) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) } - return 0 + i-- + dAtA[i] = 0x12 + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } -func (m *SignDoc) GetAccountSequence() uint64 { - if m != nil { - return m.AccountSequence +func (m *DecCoin) 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 0 + return dAtA[:n], nil } -// TxBody is the body of a transaction that all signers sign over -type TxBody struct { - // messages are the processable content of the transaction - Messages []*types1.Any `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` - // memo is any arbitrary memo to be added to the transaction - Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"` - // timeout is the block height after which this transaction will not - // be processed by the chain - TimeoutHeight int64 `protobuf:"varint,3,opt,name=timeout_height,json=timeoutHeight,proto3" json:"timeout_height,omitempty"` - // extension_options are arbitrary options that can be added by chains - // when the default options are not sufficient. If any of these are present - // and can't be handled, the transaction will be rejected - ExtensionOptions []*types1.Any `protobuf:"bytes,1023,rep,name=extension_options,json=extensionOptions,proto3" json:"extension_options,omitempty"` - // extension_options are arbitrary options that can be added by chains - // when the default options are not sufficient. If any of these are present - // and can't be handled, they will be ignored - NonCriticalExtensionOptions []*types1.Any `protobuf:"bytes,2047,rep,name=non_critical_extension_options,json=nonCriticalExtensionOptions,proto3" json:"non_critical_extension_options,omitempty"` +func (m *DecCoin) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *TxBody) Reset() { *m = TxBody{} } -func (*TxBody) ProtoMessage() {} -func (*TxBody) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{10} -} -func (m *TxBody) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *TxBody) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_TxBody.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (m *DecCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err } - return b[:n], nil + i = encodeVarintTypes(dAtA, i, uint64(size)) } -} -func (m *TxBody) XXX_Merge(src proto.Message) { - xxx_messageInfo_TxBody.Merge(m, src) -} -func (m *TxBody) XXX_Size() int { - return m.Size() -} -func (m *TxBody) XXX_DiscardUnknown() { - xxx_messageInfo_TxBody.DiscardUnknown(m) -} - -var xxx_messageInfo_TxBody proto.InternalMessageInfo - -func (m *TxBody) GetMessages() []*types1.Any { - if m != nil { - return m.Messages + i-- + dAtA[i] = 0x12 + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa } - return nil + return len(dAtA) - i, nil } -func (m *TxBody) GetMemo() string { - if m != nil { - return m.Memo +func (m *IntProto) 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 "" + return dAtA[:n], nil } -func (m *TxBody) GetTimeoutHeight() int64 { - if m != nil { - return m.TimeoutHeight - } - return 0 +func (m *IntProto) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *TxBody) GetExtensionOptions() []*types1.Any { - if m != nil { - return m.ExtensionOptions +func (m *IntProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Int.Size() + i -= size + if _, err := m.Int.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTypes(dAtA, i, uint64(size)) } - return nil + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil } -func (m *TxBody) GetNonCriticalExtensionOptions() []*types1.Any { - if m != nil { - return m.NonCriticalExtensionOptions +func (m *DecProto) 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 nil + return dAtA[:n], nil } -// AuthInfo describes the fee and signer modes that are used to sign a transaction -type AuthInfo struct { - // signer_infos is the list of signer infos which corresponds with - // Tx.signatures and expected signers derived from TxBody.messages. All signers - // are expected to occur in the same order in each of these locations - SignerInfos []*SignerInfo `protobuf:"bytes,1,rep,name=signer_infos,json=signerInfos,proto3" json:"signer_infos,omitempty"` - // Fee is the fee and gas limit for the transaction. The first signer is the - // primary signer and the one which pays the fee - Fee *Fee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` +func (m *DecProto) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *AuthInfo) Reset() { *m = AuthInfo{} } -func (*AuthInfo) ProtoMessage() {} -func (*AuthInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{11} -} -func (m *AuthInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *AuthInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_AuthInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (m *DecProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Dec.Size() + i -= size + if _, err := m.Dec.MarshalTo(dAtA[i:]); err != nil { + return 0, err } - return b[:n], nil - } -} -func (m *AuthInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_AuthInfo.Merge(m, src) -} -func (m *AuthInfo) XXX_Size() int { - return m.Size() -} -func (m *AuthInfo) XXX_DiscardUnknown() { - xxx_messageInfo_AuthInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_AuthInfo proto.InternalMessageInfo - -func (m *AuthInfo) GetSignerInfos() []*SignerInfo { - if m != nil { - return m.SignerInfos + i = encodeVarintTypes(dAtA, i, uint64(size)) } - return nil + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil } -func (m *AuthInfo) GetFee() *Fee { - if m != nil { - return m.Fee +func (m *ValAddresses) 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 nil + return dAtA[:n], nil } -// SignerInfo describes the public key and signing mode of a single top-level signer -type SignerInfo struct { - // public_key is the public key of the signer. It is optional for accounts - // that already exist in state - PublicKey *types1.Any `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` - // mode_info describes the signing mode of the signer and is a nested - // structure to support nested multisig pubkey's - ModeInfo *ModeInfo `protobuf:"bytes,2,opt,name=mode_info,json=modeInfo,proto3" json:"mode_info,omitempty"` +func (m *ValAddresses) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *SignerInfo) Reset() { *m = SignerInfo{} } -func (*SignerInfo) ProtoMessage() {} -func (*SignerInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{12} -} -func (m *SignerInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SignerInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SignerInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (m *ValAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0xa } - return b[:n], nil - } -} -func (m *SignerInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_SignerInfo.Merge(m, src) -} -func (m *SignerInfo) XXX_Size() int { - return m.Size() -} -func (m *SignerInfo) XXX_DiscardUnknown() { - xxx_messageInfo_SignerInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_SignerInfo proto.InternalMessageInfo - -func (m *SignerInfo) GetPublicKey() *types1.Any { - if m != nil { - return m.PublicKey } - return nil + return len(dAtA) - i, nil } -func (m *SignerInfo) GetModeInfo() *ModeInfo { - if m != nil { - return m.ModeInfo +func (m *GasInfo) 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 nil + return dAtA[:n], nil } -// ModeInfo describes the signing mode of a single or nested multisig signer -type ModeInfo struct { - // sum is the oneof that specifies whether this represents a single or nested - // multisig signer - // - // Types that are valid to be assigned to Sum: - // *ModeInfo_Single_ - // *ModeInfo_Multi_ - Sum isModeInfo_Sum `protobuf_oneof:"sum"` +func (m *GasInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ModeInfo) Reset() { *m = ModeInfo{} } -func (*ModeInfo) ProtoMessage() {} -func (*ModeInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{13} -} -func (m *ModeInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ModeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ModeInfo.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 *GasInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.GasUsed != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.GasUsed)) + i-- + dAtA[i] = 0x10 } + if m.GasWanted != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.GasWanted)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } -func (m *ModeInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModeInfo.Merge(m, src) -} -func (m *ModeInfo) XXX_Size() int { - return m.Size() -} -func (m *ModeInfo) XXX_DiscardUnknown() { - xxx_messageInfo_ModeInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_ModeInfo proto.InternalMessageInfo -type isModeInfo_Sum interface { - isModeInfo_Sum() - MarshalTo([]byte) (int, error) - Size() int +func (m *Result) 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 } -type ModeInfo_Single_ struct { - Single *ModeInfo_Single `protobuf:"bytes,1,opt,name=single,proto3,oneof" json:"single,omitempty"` -} -type ModeInfo_Multi_ struct { - Multi *ModeInfo_Multi `protobuf:"bytes,2,opt,name=multi,proto3,oneof" json:"multi,omitempty"` +func (m *Result) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (*ModeInfo_Single_) isModeInfo_Sum() {} -func (*ModeInfo_Multi_) isModeInfo_Sum() {} - -func (m *ModeInfo) GetSum() isModeInfo_Sum { - if m != nil { - return m.Sum +func (m *Result) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Events) > 0 { + for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Events[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } - return nil -} - -func (m *ModeInfo) GetSingle() *ModeInfo_Single { - if x, ok := m.GetSum().(*ModeInfo_Single_); ok { - return x.Single + if len(m.Log) > 0 { + i -= len(m.Log) + copy(dAtA[i:], m.Log) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Log))) + i-- + dAtA[i] = 0x12 } - return nil -} - -func (m *ModeInfo) GetMulti() *ModeInfo_Multi { - if x, ok := m.GetSum().(*ModeInfo_Multi_); ok { - return x.Multi + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa } - return nil + return len(dAtA) - i, nil } -// XXX_OneofWrappers is for the internal use of the proto package. -func (*ModeInfo) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*ModeInfo_Single_)(nil), - (*ModeInfo_Multi_)(nil), +func (m *SimulationResponse) 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 } -// Single is the mode info for a single signer. It is structured as a message -// to allow for additional fields such as locale for SIGN_MODE_TEXTUAL in the future -type ModeInfo_Single struct { - // mode is the signing mode of the single signer - Mode SignMode `protobuf:"varint,1,opt,name=mode,proto3,enum=cosmos_sdk.v1.SignMode" json:"mode,omitempty"` +func (m *SimulationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ModeInfo_Single) Reset() { *m = ModeInfo_Single{} } -func (*ModeInfo_Single) ProtoMessage() {} -func (*ModeInfo_Single) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{13, 0} -} -func (m *ModeInfo_Single) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ModeInfo_Single) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ModeInfo_Single.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (m *SimulationResponse) 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 = encodeVarintTypes(dAtA, i, uint64(size)) } - return b[:n], nil - } -} -func (m *ModeInfo_Single) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModeInfo_Single.Merge(m, src) -} -func (m *ModeInfo_Single) XXX_Size() int { - return m.Size() -} -func (m *ModeInfo_Single) XXX_DiscardUnknown() { - xxx_messageInfo_ModeInfo_Single.DiscardUnknown(m) -} - -var xxx_messageInfo_ModeInfo_Single proto.InternalMessageInfo - -func (m *ModeInfo_Single) GetMode() SignMode { - if m != nil { - return m.Mode + i-- + dAtA[i] = 0x12 } - return SignMode_SIGN_MODE_UNSPECIFIED -} - -// Multi is the mode info for a multisig public key -type ModeInfo_Multi struct { - // bitarray specifies which keys within the multisig are signing - Bitarray *CompactBitArray `protobuf:"bytes,1,opt,name=bitarray,proto3" json:"bitarray,omitempty"` - // mode_infos is the corresponding modes of the signers of the multisig - // which could include nested multisig public keys - ModeInfos []*ModeInfo `protobuf:"bytes,2,rep,name=mode_infos,json=modeInfos,proto3" json:"mode_infos,omitempty"` -} - -func (m *ModeInfo_Multi) Reset() { *m = ModeInfo_Multi{} } -func (*ModeInfo_Multi) ProtoMessage() {} -func (*ModeInfo_Multi) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{13, 1} -} -func (m *ModeInfo_Multi) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ModeInfo_Multi) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ModeInfo_Multi.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) + { + size, err := m.GasInfo.MarshalToSizedBuffer(dAtA[:i]) if err != nil { - return nil, err + return 0, err } - return b[:n], nil + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil } -func (m *ModeInfo_Multi) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModeInfo_Multi.Merge(m, src) -} -func (m *ModeInfo_Multi) XXX_Size() int { - return m.Size() -} -func (m *ModeInfo_Multi) XXX_DiscardUnknown() { - xxx_messageInfo_ModeInfo_Multi.DiscardUnknown(m) -} - -var xxx_messageInfo_ModeInfo_Multi proto.InternalMessageInfo -func (m *ModeInfo_Multi) GetBitarray() *CompactBitArray { - if m != nil { - return m.Bitarray +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ } - return nil + dAtA[offset] = uint8(v) + return base } - -func (m *ModeInfo_Multi) GetModeInfos() []*ModeInfo { - if m != nil { - return m.ModeInfos +func (m *Coin) Size() (n int) { + if m == nil { + return 0 } - return nil -} - -// Fee includes the amount of coins paid in fees and the maximum -// gas to be used by the transaction. The ratio yields an effective "gasprice", -// which must be above some miminum to be accepted into the mempool. -type Fee struct { - // amount is the amount of coins to be paid as a fee - Amount Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=Coins" json:"amount"` - // gas_limit is the maximum gas that can be used in transaction processing - // before an out of gas error occurs - GasLimit uint64 `protobuf:"varint,2,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"` -} - -func (m *Fee) Reset() { *m = Fee{} } -func (*Fee) ProtoMessage() {} -func (*Fee) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{14} -} -func (m *Fee) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Fee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Fee.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) } -} -func (m *Fee) XXX_Merge(src proto.Message) { - xxx_messageInfo_Fee.Merge(m, src) -} -func (m *Fee) XXX_Size() int { - return m.Size() -} -func (m *Fee) XXX_DiscardUnknown() { - xxx_messageInfo_Fee.DiscardUnknown(m) -} - -var xxx_messageInfo_Fee proto.InternalMessageInfo - -// CompactBitArray is an implementation of a space efficient bit array. -// This is used to ensure that the encoded data takes up a minimal amount of -// space after proto encoding. -// This is not thread safe, and is not intended for concurrent usage. -type CompactBitArray struct { - ExtraBitsStored uint32 `protobuf:"varint,1,opt,name=extra_bits_stored,json=extraBitsStored,proto3" json:"extra_bits_stored,omitempty"` - Elems []byte `protobuf:"bytes,2,opt,name=elems,proto3" json:"elems,omitempty"` + l = m.Amount.Size() + n += 1 + l + sovTypes(uint64(l)) + return n } -func (m *CompactBitArray) Reset() { *m = CompactBitArray{} } -func (*CompactBitArray) ProtoMessage() {} -func (*CompactBitArray) Descriptor() ([]byte, []int) { - return fileDescriptor_2c0f90c600ad7e2e, []int{15} -} -func (m *CompactBitArray) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CompactBitArray) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_CompactBitArray.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 *DecCoin) Size() (n int) { + if m == nil { + return 0 } -} -func (m *CompactBitArray) XXX_Merge(src proto.Message) { - xxx_messageInfo_CompactBitArray.Merge(m, src) -} -func (m *CompactBitArray) XXX_Size() int { - return m.Size() -} -func (m *CompactBitArray) XXX_DiscardUnknown() { - xxx_messageInfo_CompactBitArray.DiscardUnknown(m) -} - -var xxx_messageInfo_CompactBitArray proto.InternalMessageInfo - -func (m *CompactBitArray) GetExtraBitsStored() uint32 { - if m != nil { - return m.ExtraBitsStored + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) } - return 0 + l = m.Amount.Size() + n += 1 + l + sovTypes(uint64(l)) + return n } -func (m *CompactBitArray) GetElems() []byte { - if m != nil { - return m.Elems +func (m *IntProto) Size() (n int) { + if m == nil { + return 0 } - return nil -} - -func init() { - proto.RegisterEnum("cosmos_sdk.v1.SignMode", SignMode_name, SignMode_value) - proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin") - proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin") - proto.RegisterType((*IntProto)(nil), "cosmos_sdk.v1.IntProto") - proto.RegisterType((*DecProto)(nil), "cosmos_sdk.v1.DecProto") - proto.RegisterType((*ValAddresses)(nil), "cosmos_sdk.v1.ValAddresses") - proto.RegisterType((*GasInfo)(nil), "cosmos_sdk.v1.GasInfo") - proto.RegisterType((*Result)(nil), "cosmos_sdk.v1.Result") - proto.RegisterType((*SimulationResponse)(nil), "cosmos_sdk.v1.SimulationResponse") - proto.RegisterType((*Tx)(nil), "cosmos_sdk.v1.Tx") - proto.RegisterType((*SignDoc)(nil), "cosmos_sdk.v1.SignDoc") - proto.RegisterType((*TxBody)(nil), "cosmos_sdk.v1.TxBody") - proto.RegisterType((*AuthInfo)(nil), "cosmos_sdk.v1.AuthInfo") - proto.RegisterType((*SignerInfo)(nil), "cosmos_sdk.v1.SignerInfo") - proto.RegisterType((*ModeInfo)(nil), "cosmos_sdk.v1.ModeInfo") - proto.RegisterType((*ModeInfo_Single)(nil), "cosmos_sdk.v1.ModeInfo.Single") - proto.RegisterType((*ModeInfo_Multi)(nil), "cosmos_sdk.v1.ModeInfo.Multi") - proto.RegisterType((*Fee)(nil), "cosmos_sdk.v1.Fee") - proto.RegisterType((*CompactBitArray)(nil), "cosmos_sdk.v1.CompactBitArray") + var l int + _ = l + l = m.Int.Size() + n += 1 + l + sovTypes(uint64(l)) + return n } -func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } - -var fileDescriptor_2c0f90c600ad7e2e = []byte{ - // 1207 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xbf, 0x73, 0x1b, 0xc5, - 0x17, 0xd7, 0x59, 0xb2, 0x2c, 0x3f, 0xcb, 0xb1, 0xbc, 0x89, 0xbf, 0x5f, 0xd9, 0x21, 0x92, 0x47, - 0xfc, 0x98, 0x24, 0x10, 0x09, 0x9c, 0xc0, 0x30, 0x0a, 0x8d, 0xce, 0x52, 0x1c, 0x85, 0xd8, 0xce, - 0x9c, 0x1c, 0x20, 0x69, 0x6e, 0x4e, 0x77, 0xeb, 0xd3, 0x4e, 0xee, 0x76, 0xc5, 0xed, 0x5e, 0x88, - 0x0a, 0x86, 0xd0, 0x31, 0x43, 0x43, 0x4f, 0x93, 0x9a, 0xbf, 0x24, 0x74, 0x29, 0x33, 0x0c, 0x18, - 0x70, 0x1a, 0xea, 0x94, 0x34, 0x30, 0xfb, 0x43, 0x16, 0x91, 0xe3, 0x14, 0xcc, 0xd0, 0xc8, 0x6f, - 0xdf, 0xfb, 0xbc, 0xdf, 0x9f, 0xdb, 0x35, 0x2c, 0x8b, 0xd1, 0x10, 0xf3, 0x86, 0xfa, 0xad, 0x0f, - 0x13, 0x26, 0x18, 0x5a, 0xf4, 0x19, 0x8f, 0x19, 0x77, 0x79, 0x70, 0xaf, 0x7e, 0xff, 0xbd, 0xb5, - 0xb7, 0xc4, 0x80, 0x24, 0x81, 0x3b, 0xf4, 0x12, 0x31, 0x6a, 0x28, 0x44, 0x23, 0x64, 0x21, 0x9b, - 0x48, 0xda, 0x6d, 0xed, 0xf2, 0x71, 0x9c, 0xc0, 0x34, 0xc0, 0x49, 0x4c, 0xa8, 0x68, 0x78, 0x7d, - 0x9f, 0x34, 0x8e, 0xe5, 0x5a, 0x5b, 0x0d, 0x19, 0x0b, 0x23, 0xac, 0xf1, 0xfd, 0x74, 0xbf, 0xe1, - 0xd1, 0x91, 0x36, 0xd5, 0xb6, 0x20, 0xb7, 0xc9, 0x08, 0x45, 0x67, 0x60, 0x36, 0xc0, 0x94, 0xc5, - 0x65, 0x6b, 0xdd, 0x3a, 0x3f, 0xef, 0xe8, 0x03, 0x7a, 0x1d, 0xf2, 0x5e, 0xcc, 0x52, 0x2a, 0xca, - 0x33, 0x52, 0x6d, 0x2f, 0x3c, 0x3e, 0xa8, 0x66, 0x7e, 0x3a, 0xa8, 0x66, 0xbb, 0x54, 0x38, 0xc6, - 0xd4, 0xcc, 0xfd, 0xf1, 0xa8, 0x6a, 0xd5, 0x6e, 0xc0, 0x5c, 0x1b, 0xfb, 0xff, 0x26, 0x56, 0x1b, - 0xfb, 0x53, 0xb1, 0x2e, 0x40, 0xa1, 0x4b, 0xc5, 0x2d, 0x35, 0xa7, 0x73, 0x90, 0x25, 0x54, 0xe8, - 0x50, 0x2f, 0xe6, 0x97, 0x7a, 0x09, 0x6d, 0x63, 0xff, 0x08, 0x1a, 0x60, 0x7f, 0x1a, 0x2a, 0xc3, - 0x4b, 0x7d, 0xcd, 0x86, 0xe2, 0x27, 0x5e, 0xd4, 0x0a, 0x82, 0x04, 0x73, 0x8e, 0x39, 0x7a, 0x07, - 0xe6, 0xbd, 0xf1, 0xa1, 0x6c, 0xad, 0x67, 0xcf, 0x17, 0xed, 0x53, 0x7f, 0x1e, 0x54, 0x61, 0x02, - 0x72, 0x26, 0x80, 0x66, 0xee, 0xe1, 0xcf, 0xeb, 0x56, 0x8d, 0xc1, 0xdc, 0x96, 0xc7, 0xbb, 0x74, - 0x9f, 0xa1, 0x2b, 0x00, 0xa1, 0xc7, 0xdd, 0x2f, 0x3c, 0x2a, 0x70, 0xa0, 0x92, 0xe6, 0xec, 0x95, - 0xe7, 0x07, 0xd5, 0xe5, 0x91, 0x17, 0x47, 0xcd, 0xda, 0xc4, 0x56, 0x73, 0xe6, 0x43, 0x8f, 0x7f, - 0xaa, 0x64, 0x54, 0x87, 0x82, 0xb4, 0xa4, 0x1c, 0x07, 0x6a, 0x0e, 0x39, 0xfb, 0xf4, 0xf3, 0x83, - 0xea, 0xd2, 0xc4, 0x47, 0x5a, 0x6a, 0xce, 0x5c, 0xe8, 0xf1, 0xdb, 0x52, 0x1a, 0x42, 0xde, 0xc1, - 0x3c, 0x8d, 0x04, 0x42, 0x90, 0x0b, 0x3c, 0xe1, 0xa9, 0x4c, 0x45, 0x47, 0xc9, 0xa8, 0x04, 0xd9, - 0x88, 0x85, 0x7a, 0xa0, 0x8e, 0x14, 0x51, 0x13, 0xf2, 0xf8, 0x3e, 0xa6, 0x82, 0x97, 0xb3, 0xeb, - 0xd9, 0xf3, 0x0b, 0x1b, 0xaf, 0xd5, 0x27, 0xf4, 0xa8, 0x4b, 0x7a, 0xd4, 0x35, 0x31, 0x3a, 0x12, - 0x64, 0xe7, 0xe4, 0x90, 0x1c, 0xe3, 0xd1, 0xcc, 0x7d, 0xf3, 0xa8, 0x9a, 0xa9, 0x3d, 0xb4, 0x00, - 0xf5, 0x48, 0x9c, 0x46, 0x9e, 0x20, 0x8c, 0x3a, 0x98, 0x0f, 0x19, 0xe5, 0x18, 0x5d, 0xd5, 0x85, - 0x13, 0xba, 0xcf, 0x54, 0x09, 0x0b, 0x1b, 0xff, 0xab, 0xbf, 0x40, 0xe1, 0xba, 0x19, 0x8c, 0x5d, - 0x90, 0x41, 0x9f, 0x1c, 0x54, 0x2d, 0xd5, 0x85, 0x9a, 0xd5, 0x25, 0xc8, 0x27, 0xaa, 0x0b, 0x55, - 0xea, 0xc2, 0xc6, 0xca, 0x94, 0xab, 0x6e, 0xd1, 0x31, 0xa0, 0xda, 0xb7, 0x16, 0xcc, 0xec, 0x3d, - 0x40, 0x17, 0x20, 0xd7, 0x67, 0xc1, 0xc8, 0xa4, 0x9b, 0xf6, 0xd9, 0x7b, 0x60, 0xb3, 0x60, 0xe4, - 0x28, 0x08, 0xba, 0x02, 0xf3, 0x5e, 0x2a, 0x06, 0xba, 0x3c, 0x9d, 0xe3, 0xff, 0x53, 0xf8, 0x56, - 0x2a, 0x06, 0xb2, 0x18, 0xa7, 0xe0, 0x19, 0x09, 0x55, 0x00, 0x38, 0x09, 0xa9, 0x27, 0xd2, 0x04, - 0xeb, 0x81, 0x15, 0x9d, 0x7f, 0x68, 0xcc, 0xce, 0x7f, 0xb1, 0x60, 0xae, 0x47, 0x42, 0xda, 0x66, - 0xfe, 0x7f, 0x5f, 0xd2, 0x2a, 0x14, 0xfc, 0x81, 0x47, 0xa8, 0x4b, 0x82, 0x72, 0x56, 0xad, 0x75, - 0x4e, 0x9d, 0xbb, 0x01, 0x7a, 0x13, 0x4e, 0x79, 0xbe, 0x2f, 0x3f, 0x13, 0x97, 0xa6, 0x71, 0x1f, - 0x27, 0xe5, 0x9c, 0x24, 0x90, 0xb3, 0x68, 0xb4, 0x3b, 0x4a, 0x89, 0x2e, 0x40, 0x69, 0x0c, 0xe3, - 0xf8, 0xf3, 0x14, 0x53, 0x1f, 0x97, 0x67, 0x15, 0x70, 0xc9, 0xe8, 0x7b, 0x46, 0x6d, 0xfa, 0xfb, - 0x7e, 0x06, 0xf2, 0xba, 0x72, 0xf4, 0x2e, 0x14, 0x62, 0xcc, 0xb9, 0x17, 0x9a, 0x2f, 0x62, 0x61, - 0xe3, 0x4c, 0x5d, 0xdf, 0x1d, 0xf5, 0xf1, 0xdd, 0x51, 0x6f, 0xd1, 0x91, 0x73, 0x84, 0x92, 0xac, - 0x8c, 0x71, 0xcc, 0x0c, 0x05, 0x95, 0x2c, 0x0b, 0x15, 0x24, 0xc6, 0x2c, 0x15, 0xee, 0x00, 0x93, - 0x70, 0x20, 0x54, 0x27, 0x59, 0x67, 0xd1, 0x68, 0xaf, 0x2b, 0x25, 0xb2, 0x61, 0x19, 0x3f, 0x10, - 0x98, 0x72, 0xc2, 0xa8, 0xcb, 0x86, 0x92, 0x6d, 0xbc, 0xfc, 0xd7, 0xdc, 0x2b, 0xd2, 0x96, 0x8e, - 0xf0, 0xbb, 0x1a, 0x8e, 0xee, 0x42, 0x85, 0x32, 0xea, 0xfa, 0x09, 0x11, 0xc4, 0xf7, 0x22, 0xf7, - 0x25, 0x01, 0x97, 0x5e, 0x11, 0xf0, 0x2c, 0x65, 0x74, 0xd3, 0xf8, 0x76, 0xa6, 0x62, 0x9b, 0xe9, - 0x08, 0x28, 0x8c, 0xd7, 0x84, 0x3e, 0x82, 0xa2, 0x64, 0x07, 0x4e, 0xd4, 0x52, 0xc7, 0x23, 0x5a, - 0x9d, 0xda, 0x6a, 0x4f, 0x41, 0xd4, 0x5e, 0x17, 0xf8, 0x91, 0xcc, 0xd1, 0x1b, 0x90, 0xdd, 0xc7, - 0xd8, 0x50, 0x01, 0x4d, 0x39, 0x5d, 0xc3, 0xd8, 0x91, 0x66, 0x93, 0xf5, 0x4b, 0x80, 0x49, 0x18, - 0x74, 0x19, 0x60, 0x98, 0xf6, 0x23, 0xe2, 0xbb, 0xf7, 0xf0, 0x98, 0x7b, 0x2f, 0x6f, 0x68, 0x5e, - 0xe3, 0x3e, 0xc6, 0x8a, 0x7f, 0x31, 0x0b, 0xf0, 0xab, 0xf8, 0xb7, 0xcd, 0x02, 0xac, 0xf9, 0x17, - 0x1b, 0xc9, 0xa4, 0xff, 0x71, 0x06, 0x0a, 0x63, 0x23, 0xfa, 0x10, 0xf2, 0x9c, 0xd0, 0x30, 0xc2, - 0x26, 0x73, 0xe5, 0x84, 0x28, 0xf5, 0x9e, 0x42, 0x5d, 0xcf, 0x38, 0x06, 0x8f, 0xde, 0x87, 0xd9, - 0x38, 0x8d, 0x04, 0x31, 0xe9, 0xcf, 0x9d, 0xe4, 0xb8, 0x2d, 0x41, 0xd7, 0x33, 0x8e, 0x46, 0xaf, - 0x5d, 0x85, 0xbc, 0x0e, 0x85, 0xde, 0x86, 0x9c, 0xac, 0x4c, 0x25, 0x3e, 0x75, 0xac, 0x7c, 0x39, - 0x21, 0x19, 0xc3, 0x51, 0x20, 0x5d, 0xfa, 0xda, 0xd7, 0x16, 0xcc, 0xaa, 0x78, 0xa8, 0x09, 0x85, - 0x3e, 0x11, 0x5e, 0x92, 0x78, 0xa3, 0x13, 0x2a, 0xdf, 0x64, 0xf1, 0xd0, 0xf3, 0x85, 0x4d, 0x44, - 0x4b, 0xa2, 0x9c, 0x23, 0x3c, 0xfa, 0x00, 0xe0, 0x68, 0x78, 0xbc, 0x3c, 0xa3, 0xf6, 0x7c, 0xe2, - 0xf4, 0xe6, 0xc7, 0xd3, 0x33, 0x9c, 0xd1, 0xbf, 0xf6, 0x2c, 0x64, 0x79, 0x1a, 0xd7, 0x22, 0xc8, - 0x5e, 0xc3, 0x58, 0x5e, 0xcc, 0xe6, 0xf9, 0xd3, 0xac, 0x39, 0x7d, 0xac, 0x16, 0x42, 0xed, 0x45, - 0x79, 0x75, 0xfe, 0xf0, 0x6b, 0x75, 0x56, 0x9e, 0xf8, 0xf8, 0x55, 0x44, 0x67, 0x41, 0xbe, 0x20, - 0x6e, 0x44, 0x62, 0xa2, 0x6f, 0xd0, 0x9c, 0x23, 0x2f, 0xe3, 0x9b, 0xf2, 0xdc, 0x2c, 0xca, 0x5b, - 0x5b, 0x3e, 0x9b, 0x6a, 0x73, 0x77, 0x60, 0x69, 0xaa, 0x2b, 0x74, 0x51, 0x7d, 0x67, 0x89, 0xe7, - 0xf6, 0x89, 0xe0, 0x2e, 0x17, 0x2c, 0x31, 0xef, 0xd5, 0xa2, 0xb3, 0xa4, 0x0c, 0x36, 0x11, 0xbc, - 0xa7, 0xd4, 0xf2, 0xe9, 0xc6, 0x11, 0x8e, 0xb9, 0xca, 0x52, 0x74, 0xf4, 0x41, 0xf7, 0x73, 0x91, - 0x43, 0x61, 0x3c, 0x71, 0xb4, 0x0a, 0x2b, 0xbd, 0xee, 0xd6, 0x8e, 0xbb, 0xbd, 0xdb, 0xee, 0xb8, - 0xb7, 0x77, 0x7a, 0xb7, 0x3a, 0x9b, 0xdd, 0x6b, 0xdd, 0x4e, 0xbb, 0x94, 0x41, 0x67, 0xa0, 0x34, - 0x31, 0xb5, 0xbb, 0x4e, 0x67, 0x73, 0xaf, 0x64, 0xa1, 0x15, 0x58, 0x9e, 0x68, 0xf7, 0x3a, 0x9f, - 0xed, 0xdd, 0x6e, 0xdd, 0x2c, 0xcd, 0xa0, 0x2a, 0x9c, 0x9d, 0xa8, 0x6f, 0x76, 0xb6, 0x5a, 0x9b, - 0x77, 0xdc, 0xd6, 0x76, 0x77, 0x67, 0xd7, 0xbd, 0xd1, 0xdb, 0xdd, 0x29, 0x7d, 0x65, 0xb7, 0x9f, - 0xfe, 0x5e, 0xc9, 0x3c, 0x3c, 0xac, 0x64, 0x1e, 0x1f, 0x56, 0xac, 0x27, 0x87, 0x15, 0xeb, 0xb7, - 0xc3, 0x8a, 0xf5, 0xdd, 0xb3, 0x4a, 0xe6, 0xc9, 0xb3, 0x4a, 0xe6, 0xe9, 0xb3, 0x4a, 0xe6, 0x6e, - 0x2d, 0x24, 0x62, 0x90, 0xf6, 0xeb, 0x3e, 0x8b, 0x1b, 0x7a, 0xa4, 0xe6, 0xcf, 0x25, 0x1e, 0xdc, - 0xd3, 0xff, 0x06, 0xf5, 0xf3, 0xea, 0x23, 0xb9, 0xfc, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1a, - 0x0d, 0xb3, 0x66, 0x88, 0x09, 0x00, 0x00, +func (m *DecProto) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Dec.Size() + n += 1 + l + sovTypes(uint64(l)) + return n } -func (this *Coin) Equal(that interface{}) bool { - if that == nil { - return this == nil +func (m *ValAddresses) Size() (n int) { + if m == nil { + return 0 } - - that1, ok := that.(*Coin) - if !ok { - that2, ok := that.(Coin) - if ok { - that1 = &that2 - } else { - return false + var l int + _ = l + if len(m.Addresses) > 0 { + for _, b := range m.Addresses { + l = len(b) + n += 1 + l + sovTypes(uint64(l)) } } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Denom != that1.Denom { - return false - } - if !this.Amount.Equal(that1.Amount) { - return false - } - return true + return n } -func (this *DecCoin) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - that1, ok := that.(*DecCoin) - if !ok { - that2, ok := that.(DecCoin) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false +func (m *GasInfo) Size() (n int) { + if m == nil { + return 0 } - if this.Denom != that1.Denom { - return false + var l int + _ = l + if m.GasWanted != 0 { + n += 1 + sovTypes(uint64(m.GasWanted)) } - if !this.Amount.Equal(that1.Amount) { - return false + if m.GasUsed != 0 { + n += 1 + sovTypes(uint64(m.GasUsed)) } - return true + return n } -func (this *Fee) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - that1, ok := that.(*Fee) - if !ok { - that2, ok := that.(Fee) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Amount) != len(that1.Amount) { - return false - } - for i := range this.Amount { - if !this.Amount[i].Equal(&that1.Amount[i]) { - return false - } - } - if this.GasLimit != that1.GasLimit { - return false - } - return true -} -func (m *Coin) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (m *Result) Size() (n int) { + if m == nil { + return 0 } - return dAtA[:n], nil -} - -func (m *Coin) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Coin) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i var l int _ = l - { - size := m.Amount.Size() - i -= size - if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTypes(dAtA, i, uint64(size)) + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) } - i-- - dAtA[i] = 0x12 - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) - i-- - dAtA[i] = 0xa + l = len(m.Log) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) } - return len(dAtA) - i, nil -} - -func (m *DecCoin) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err + if len(m.Events) > 0 { + for _, e := range m.Events { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } } - return dAtA[:n], nil -} - -func (m *DecCoin) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) + return n } -func (m *DecCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Amount.Size() - i -= size - if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Denom))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *IntProto) 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 *IntProto) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *IntProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Int.Size() - i -= size - if _, err := m.Int.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *DecProto) 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 *DecProto) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *DecProto) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.Dec.Size() - i -= size - if _, err := m.Dec.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *ValAddresses) 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 *ValAddresses) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ValAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Addresses) > 0 { - for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Addresses[iNdEx]) - copy(dAtA[i:], m.Addresses[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Addresses[iNdEx]))) - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *GasInfo) 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 *GasInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GasInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.GasUsed != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.GasUsed)) - i-- - dAtA[i] = 0x10 - } - if m.GasWanted != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.GasWanted)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *Result) 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 *Result) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Result) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Events) > 0 { - for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Events[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.Log) > 0 { - i -= len(m.Log) - copy(dAtA[i:], m.Log) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Log))) - i-- - dAtA[i] = 0x12 - } - if len(m.Data) > 0 { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *SimulationResponse) 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 *SimulationResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SimulationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i +func (m *SimulationResponse) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l + l = m.GasInfo.Size() + n += 1 + l + sovTypes(uint64(l)) if m.Result != nil { - { - size, err := m.Result.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - { - size, err := m.GasInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *Tx) 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 *Tx) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Tx) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Signatures) > 0 { - for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Signatures[iNdEx]) - copy(dAtA[i:], m.Signatures[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Signatures[iNdEx]))) - i-- - dAtA[i] = 0x1a - } - } - if m.AuthInfo != nil { - { - size, err := m.AuthInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Body != nil { - { - size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *SignDoc) 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 *SignDoc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SignDoc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.AccountSequence != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.AccountSequence)) - i-- - dAtA[i] = 0x28 - } - if m.AccountNumber != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.AccountNumber)) - i-- - dAtA[i] = 0x20 - } - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintTypes(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0x1a - } - if m.AuthInfo != nil { - { - size, err := m.AuthInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Body != nil { - { - size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *TxBody) 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 *TxBody) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *TxBody) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.NonCriticalExtensionOptions) > 0 { - for iNdEx := len(m.NonCriticalExtensionOptions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.NonCriticalExtensionOptions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x7f - i-- - dAtA[i] = 0xfa - } - } - if len(m.ExtensionOptions) > 0 { - for iNdEx := len(m.ExtensionOptions) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ExtensionOptions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3f - i-- - dAtA[i] = 0xfa - } - } - if m.TimeoutHeight != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.TimeoutHeight)) - i-- - dAtA[i] = 0x18 - } - if len(m.Memo) > 0 { - i -= len(m.Memo) - copy(dAtA[i:], m.Memo) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Memo))) - i-- - dAtA[i] = 0x12 - } - if len(m.Messages) > 0 { - for iNdEx := len(m.Messages) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Messages[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *AuthInfo) 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 *AuthInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *AuthInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Fee != nil { - { - size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.SignerInfos) > 0 { - for iNdEx := len(m.SignerInfos) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.SignerInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *SignerInfo) 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 *SignerInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SignerInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ModeInfo != nil { - { - size, err := m.ModeInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.PublicKey != nil { - { - size, err := m.PublicKey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ModeInfo) 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 *ModeInfo) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ModeInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Sum != nil { - { - size := m.Sum.Size() - i -= size - if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *ModeInfo_Single_) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ModeInfo_Single_) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.Single != nil { - { - size, err := m.Single.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} -func (m *ModeInfo_Multi_) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ModeInfo_Multi_) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.Multi != nil { - { - size, err := m.Multi.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - return len(dAtA) - i, nil -} -func (m *ModeInfo_Single) 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 *ModeInfo_Single) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ModeInfo_Single) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Mode != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.Mode)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *ModeInfo_Multi) 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 *ModeInfo_Multi) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ModeInfo_Multi) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ModeInfos) > 0 { - for iNdEx := len(m.ModeInfos) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.ModeInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - if m.Bitarray != nil { - { - size, err := m.Bitarray.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *Fee) 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 *Fee) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.GasLimit != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.GasLimit)) - i-- - dAtA[i] = 0x10 - } - if len(m.Amount) > 0 { - for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *CompactBitArray) 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 *CompactBitArray) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CompactBitArray) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Elems) > 0 { - i -= len(m.Elems) - copy(dAtA[i:], m.Elems) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Elems))) - i-- - dAtA[i] = 0x12 - } - if m.ExtraBitsStored != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.ExtraBitsStored)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Coin) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = m.Amount.Size() - n += 1 + l + sovTypes(uint64(l)) - return n -} - -func (m *DecCoin) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = m.Amount.Size() - n += 1 + l + sovTypes(uint64(l)) - return n -} - -func (m *IntProto) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Int.Size() - n += 1 + l + sovTypes(uint64(l)) - return n -} - -func (m *DecProto) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Dec.Size() - n += 1 + l + sovTypes(uint64(l)) - return n -} - -func (m *ValAddresses) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Addresses) > 0 { - for _, b := range m.Addresses { - l = len(b) - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - -func (m *GasInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.GasWanted != 0 { - n += 1 + sovTypes(uint64(m.GasWanted)) - } - if m.GasUsed != 0 { - n += 1 + sovTypes(uint64(m.GasUsed)) - } - return n -} - -func (m *Result) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Data) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = len(m.Log) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - if len(m.Events) > 0 { - for _, e := range m.Events { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - -func (m *SimulationResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.GasInfo.Size() - n += 1 + l + sovTypes(uint64(l)) - if m.Result != nil { - l = m.Result.Size() - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - -func (m *Tx) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Body != nil { - l = m.Body.Size() - n += 1 + l + sovTypes(uint64(l)) - } - if m.AuthInfo != nil { - l = m.AuthInfo.Size() - n += 1 + l + sovTypes(uint64(l)) - } - if len(m.Signatures) > 0 { - for _, b := range m.Signatures { - l = len(b) - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - -func (m *SignDoc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Body != nil { - l = m.Body.Size() - n += 1 + l + sovTypes(uint64(l)) - } - if m.AuthInfo != nil { - l = m.AuthInfo.Size() - n += 1 + l + sovTypes(uint64(l)) - } - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - if m.AccountNumber != 0 { - n += 1 + sovTypes(uint64(m.AccountNumber)) - } - if m.AccountSequence != 0 { - n += 1 + sovTypes(uint64(m.AccountSequence)) - } - return n -} - -func (m *TxBody) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Messages) > 0 { - for _, e := range m.Messages { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - l = len(m.Memo) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - if m.TimeoutHeight != 0 { - n += 1 + sovTypes(uint64(m.TimeoutHeight)) - } - if len(m.ExtensionOptions) > 0 { - for _, e := range m.ExtensionOptions { - l = e.Size() - n += 2 + l + sovTypes(uint64(l)) - } - } - if len(m.NonCriticalExtensionOptions) > 0 { - for _, e := range m.NonCriticalExtensionOptions { - l = e.Size() - n += 2 + l + sovTypes(uint64(l)) - } - } - return n -} - -func (m *AuthInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.SignerInfos) > 0 { - for _, e := range m.SignerInfos { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - if m.Fee != nil { - l = m.Fee.Size() - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - -func (m *SignerInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.PublicKey != nil { - l = m.PublicKey.Size() - n += 1 + l + sovTypes(uint64(l)) - } - if m.ModeInfo != nil { - l = m.ModeInfo.Size() - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - -func (m *ModeInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Sum != nil { - n += m.Sum.Size() - } - return n -} - -func (m *ModeInfo_Single_) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Single != nil { - l = m.Single.Size() - n += 1 + l + sovTypes(uint64(l)) - } - return n -} -func (m *ModeInfo_Multi_) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Multi != nil { - l = m.Multi.Size() - n += 1 + l + sovTypes(uint64(l)) - } - return n -} -func (m *ModeInfo_Single) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Mode != 0 { - n += 1 + sovTypes(uint64(m.Mode)) - } - return n -} - -func (m *ModeInfo_Multi) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Bitarray != nil { - l = m.Bitarray.Size() - n += 1 + l + sovTypes(uint64(l)) - } - if len(m.ModeInfos) > 0 { - for _, e := range m.ModeInfos { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - -func (m *Fee) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Amount) > 0 { - for _, e := range m.Amount { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - if m.GasLimit != 0 { - n += 1 + sovTypes(uint64(m.GasLimit)) - } - return n -} - -func (m *CompactBitArray) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ExtraBitsStored != 0 { - n += 1 + sovTypes(uint64(m.ExtraBitsStored)) - } - l = len(m.Elems) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *ValAddresses) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ValAddresses{`, - `Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`, - `}`, - }, "") - return s -} -func (this *Tx) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Tx{`, - `Body:` + strings.Replace(this.Body.String(), "TxBody", "TxBody", 1) + `,`, - `AuthInfo:` + strings.Replace(this.AuthInfo.String(), "AuthInfo", "AuthInfo", 1) + `,`, - `Signatures:` + fmt.Sprintf("%v", this.Signatures) + `,`, - `}`, - }, "") - return s -} -func (this *SignDoc) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&SignDoc{`, - `Body:` + strings.Replace(this.Body.String(), "TxBody", "TxBody", 1) + `,`, - `AuthInfo:` + strings.Replace(this.AuthInfo.String(), "AuthInfo", "AuthInfo", 1) + `,`, - `ChainId:` + fmt.Sprintf("%v", this.ChainId) + `,`, - `AccountNumber:` + fmt.Sprintf("%v", this.AccountNumber) + `,`, - `AccountSequence:` + fmt.Sprintf("%v", this.AccountSequence) + `,`, - `}`, - }, "") - return s -} -func (this *TxBody) String() string { - if this == nil { - return "nil" - } - repeatedStringForMessages := "[]*Any{" - for _, f := range this.Messages { - repeatedStringForMessages += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," - } - repeatedStringForMessages += "}" - repeatedStringForExtensionOptions := "[]*Any{" - for _, f := range this.ExtensionOptions { - repeatedStringForExtensionOptions += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," - } - repeatedStringForExtensionOptions += "}" - repeatedStringForNonCriticalExtensionOptions := "[]*Any{" - for _, f := range this.NonCriticalExtensionOptions { - repeatedStringForNonCriticalExtensionOptions += strings.Replace(fmt.Sprintf("%v", f), "Any", "types1.Any", 1) + "," - } - repeatedStringForNonCriticalExtensionOptions += "}" - s := strings.Join([]string{`&TxBody{`, - `Messages:` + repeatedStringForMessages + `,`, - `Memo:` + fmt.Sprintf("%v", this.Memo) + `,`, - `TimeoutHeight:` + fmt.Sprintf("%v", this.TimeoutHeight) + `,`, - `ExtensionOptions:` + repeatedStringForExtensionOptions + `,`, - `NonCriticalExtensionOptions:` + repeatedStringForNonCriticalExtensionOptions + `,`, - `}`, - }, "") - return s -} -func (this *AuthInfo) String() string { - if this == nil { - return "nil" - } - repeatedStringForSignerInfos := "[]*SignerInfo{" - for _, f := range this.SignerInfos { - repeatedStringForSignerInfos += strings.Replace(f.String(), "SignerInfo", "SignerInfo", 1) + "," - } - repeatedStringForSignerInfos += "}" - s := strings.Join([]string{`&AuthInfo{`, - `SignerInfos:` + repeatedStringForSignerInfos + `,`, - `Fee:` + strings.Replace(this.Fee.String(), "Fee", "Fee", 1) + `,`, - `}`, - }, "") - return s -} -func (this *SignerInfo) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&SignerInfo{`, - `PublicKey:` + strings.Replace(fmt.Sprintf("%v", this.PublicKey), "Any", "types1.Any", 1) + `,`, - `ModeInfo:` + strings.Replace(this.ModeInfo.String(), "ModeInfo", "ModeInfo", 1) + `,`, - `}`, - }, "") - return s -} -func (this *ModeInfo) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ModeInfo{`, - `Sum:` + fmt.Sprintf("%v", this.Sum) + `,`, - `}`, - }, "") - return s -} -func (this *ModeInfo_Single_) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ModeInfo_Single_{`, - `Single:` + strings.Replace(fmt.Sprintf("%v", this.Single), "ModeInfo_Single", "ModeInfo_Single", 1) + `,`, - `}`, - }, "") - return s -} -func (this *ModeInfo_Multi_) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ModeInfo_Multi_{`, - `Multi:` + strings.Replace(fmt.Sprintf("%v", this.Multi), "ModeInfo_Multi", "ModeInfo_Multi", 1) + `,`, - `}`, - }, "") - return s -} -func (this *ModeInfo_Single) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&ModeInfo_Single{`, - `Mode:` + fmt.Sprintf("%v", this.Mode) + `,`, - `}`, - }, "") - return s -} -func (this *ModeInfo_Multi) String() string { - if this == nil { - return "nil" - } - repeatedStringForModeInfos := "[]*ModeInfo{" - for _, f := range this.ModeInfos { - repeatedStringForModeInfos += strings.Replace(f.String(), "ModeInfo", "ModeInfo", 1) + "," - } - repeatedStringForModeInfos += "}" - s := strings.Join([]string{`&ModeInfo_Multi{`, - `Bitarray:` + strings.Replace(this.Bitarray.String(), "CompactBitArray", "CompactBitArray", 1) + `,`, - `ModeInfos:` + repeatedStringForModeInfos + `,`, - `}`, - }, "") - return s -} -func (this *Fee) String() string { - if this == nil { - return "nil" - } - repeatedStringForAmount := "[]Coin{" - for _, f := range this.Amount { - repeatedStringForAmount += fmt.Sprintf("%v", f) + "," - } - repeatedStringForAmount += "}" - s := strings.Join([]string{`&Fee{`, - `Amount:` + repeatedStringForAmount + `,`, - `GasLimit:` + fmt.Sprintf("%v", this.GasLimit) + `,`, - `}`, - }, "") - return s -} -func (this *CompactBitArray) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&CompactBitArray{`, - `ExtraBitsStored:` + fmt.Sprintf("%v", this.ExtraBitsStored) + `,`, - `Elems:` + fmt.Sprintf("%v", this.Elems) + `,`, - `}`, - }, "") - return s -} -func valueToStringTypes(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *Coin) 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 ErrIntOverflowTypes - } - 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: Coin: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Coin: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Denom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DecCoin) 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 ErrIntOverflowTypes - } - 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: DecCoin: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DecCoin: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Denom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *IntProto) 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 ErrIntOverflowTypes - } - 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: IntProto: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DecProto) 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 ErrIntOverflowTypes - } - 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: DecProto: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ValAddresses) 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 ErrIntOverflowTypes - } - 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: ValAddresses: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx)) - copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *GasInfo) 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 ErrIntOverflowTypes - } - 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: GasInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GasInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) - } - m.GasWanted = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GasWanted |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) - } - m.GasUsed = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GasUsed |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Result) 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 ErrIntOverflowTypes - } - 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: Result: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Result: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Log = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Events = append(m.Events, types.Event{}) - if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SimulationResponse) 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 ErrIntOverflowTypes - } - 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: SimulationResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SimulationResponse: 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 ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - 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 ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Result == nil { - m.Result = &Result{} - } - if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Tx) 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 ErrIntOverflowTypes - } - 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: Tx: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Tx: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Body == nil { - m.Body = &TxBody{} - } - if err := m.Body.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthInfo == nil { - m.AuthInfo = &AuthInfo{} - } - if err := m.AuthInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) - copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SignDoc) 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 ErrIntOverflowTypes - } - 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: SignDoc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SignDoc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Body == nil { - m.Body = &TxBody{} - } - if err := m.Body.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthInfo == nil { - m.AuthInfo = &AuthInfo{} - } - if err := m.AuthInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) - } - m.AccountNumber = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AccountNumber |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AccountSequence", wireType) - } - m.AccountSequence = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AccountSequence |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } + l = m.Result.Size() + n += 1 + l + sovTypes(uint64(l)) } + return n +} - if iNdEx > l { - return io.ErrUnexpectedEOF +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ValAddresses) String() string { + if this == nil { + return "nil" } - return nil + s := strings.Join([]string{`&ValAddresses{`, + `Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`, + `}`, + }, "") + return s +} +func valueToStringTypes(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) } -func (m *TxBody) Unmarshal(dAtA []byte) error { +func (m *Coin) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3859,49 +974,15 @@ func (m *TxBody) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: TxBody: wiretype end group for non-group") + return fmt.Errorf("proto: Coin: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: TxBody: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Coin: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Messages", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Messages = append(m.Messages, &types1.Any{}) - if err := m.Messages[len(m.Messages)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -3929,187 +1010,13 @@ func (m *TxBody) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Memo = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TimeoutHeight", wireType) - } - m.TimeoutHeight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TimeoutHeight |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 1023: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExtensionOptions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ExtensionOptions = append(m.ExtensionOptions, &types1.Any{}) - if err := m.ExtensionOptions[len(m.ExtensionOptions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2047: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NonCriticalExtensionOptions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NonCriticalExtensionOptions = append(m.NonCriticalExtensionOptions, &types1.Any{}) - if err := m.NonCriticalExtensionOptions[len(m.NonCriticalExtensionOptions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *AuthInfo) 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 ErrIntOverflowTypes - } - 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: AuthInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: AuthInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignerInfos", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SignerInfos = append(m.SignerInfos, &SignerInfo{}) - if err := m.SignerInfos[len(m.SignerInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Denom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4119,25 +1026,23 @@ func (m *AuthInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Fee == nil { - m.Fee = &Fee{} - } - if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -4165,7 +1070,7 @@ func (m *AuthInfo) Unmarshal(dAtA []byte) error { } return nil } -func (m *SignerInfo) Unmarshal(dAtA []byte) error { +func (m *DecCoin) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4188,17 +1093,17 @@ func (m *SignerInfo) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: SignerInfo: wiretype end group for non-group") + return fmt.Errorf("proto: DecCoin: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: SignerInfo: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: DecCoin: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4208,33 +1113,29 @@ func (m *SignerInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if m.PublicKey == nil { - m.PublicKey = &types1.Any{} - } - if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Denom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ModeInfo", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4244,25 +1145,23 @@ func (m *SignerInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if m.ModeInfo == nil { - m.ModeInfo = &ModeInfo{} - } - if err := m.ModeInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -4290,7 +1189,7 @@ func (m *SignerInfo) Unmarshal(dAtA []byte) error { } return nil } -func (m *ModeInfo) Unmarshal(dAtA []byte) error { +func (m *IntProto) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4313,17 +1212,17 @@ func (m *ModeInfo) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ModeInfo: wiretype end group for non-group") + return fmt.Errorf("proto: IntProto: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ModeInfo: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Single", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4333,32 +1232,84 @@ func (m *ModeInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - v := &ModeInfo_Single{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - m.Sum = &ModeInfo_Single_{v} iNdEx = postIndex - case 2: + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DecProto) 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 ErrIntOverflowTypes + } + 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: DecProto: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Multi", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4368,26 +1319,25 @@ func (m *ModeInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - v := &ModeInfo_Multi{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - m.Sum = &ModeInfo_Multi_{v} iNdEx = postIndex default: iNdEx = preIndex @@ -4413,7 +1363,7 @@ func (m *ModeInfo) Unmarshal(dAtA []byte) error { } return nil } -func (m *ModeInfo_Single) Unmarshal(dAtA []byte) error { +func (m *ValAddresses) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4436,17 +1386,17 @@ func (m *ModeInfo_Single) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Single: wiretype end group for non-group") + return fmt.Errorf("proto: ValAddresses: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Single: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Mode", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) } - m.Mode = 0 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4456,11 +1406,24 @@ func (m *ModeInfo_Single) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Mode |= SignMode(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx)) + copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -4485,7 +1448,7 @@ func (m *ModeInfo_Single) Unmarshal(dAtA []byte) error { } return nil } -func (m *ModeInfo_Multi) Unmarshal(dAtA []byte) error { +func (m *GasInfo) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4508,17 +1471,17 @@ func (m *ModeInfo_Multi) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Multi: wiretype end group for non-group") + return fmt.Errorf("proto: GasInfo: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Multi: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: GasInfo: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Bitarray", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) } - var msglen int + m.GasWanted = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4528,33 +1491,16 @@ func (m *ModeInfo_Multi) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.GasWanted |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Bitarray == nil { - m.Bitarray = &CompactBitArray{} - } - if err := m.Bitarray.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ModeInfos", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) } - var msglen int + m.GasUsed = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4564,26 +1510,11 @@ func (m *ModeInfo_Multi) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.GasUsed |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ModeInfos = append(m.ModeInfos, &ModeInfo{}) - if err := m.ModeInfos[len(m.ModeInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -4608,7 +1539,7 @@ func (m *ModeInfo_Multi) Unmarshal(dAtA []byte) error { } return nil } -func (m *Fee) Unmarshal(dAtA []byte) error { +func (m *Result) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4631,17 +1562,17 @@ func (m *Fee) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Fee: wiretype end group for non-group") + return fmt.Errorf("proto: Result: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Fee: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Result: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) } - var msglen int + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4651,31 +1582,63 @@ func (m *Fee) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + if byteLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Amount = append(m.Amount, Coin{}) - if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} } iNdEx = postIndex case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasLimit", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Log = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) } - m.GasLimit = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4685,11 +1648,26 @@ func (m *Fee) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.GasLimit |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Events = append(m.Events, types.Event{}) + if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -4714,7 +1692,7 @@ func (m *Fee) Unmarshal(dAtA []byte) error { } return nil } -func (m *CompactBitArray) Unmarshal(dAtA []byte) error { +func (m *SimulationResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4737,17 +1715,17 @@ func (m *CompactBitArray) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: CompactBitArray: wiretype end group for non-group") + return fmt.Errorf("proto: SimulationResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: CompactBitArray: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: SimulationResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExtraBitsStored", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GasInfo", wireType) } - m.ExtraBitsStored = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4757,16 +1735,30 @@ func (m *CompactBitArray) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ExtraBitsStored |= uint32(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + 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 Elems", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) } - var byteLen int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -4776,24 +1768,26 @@ func (m *CompactBitArray) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + byteLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Elems = append(m.Elems[:0], dAtA[iNdEx:postIndex]...) - if m.Elems == nil { - m.Elems = []byte{} + if m.Result == nil { + m.Result = &Result{} + } + if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: diff --git a/types/types.proto b/types/types.proto index 70e360b861be..c26219caa789 100644 --- a/types/types.proto +++ b/types/types.proto @@ -3,7 +3,6 @@ package cosmos_sdk.v1; import "third_party/proto/gogoproto/gogo.proto"; import "third_party/proto/tendermint/abci/types/types.proto"; -import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/types"; option (gogoproto.goproto_stringer_all) = false; @@ -79,177 +78,3 @@ message SimulationResponse { GasInfo gas_info = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; Result result = 2; } - -// Tx is the standard type used for broadcasting transactions -message Tx { - option (gogoproto.stringer) = true; - - // body is the processable content of the transaction - TxBody body = 1; - - // auth_info is the authorization related content of the transaction, specifically - // signers, signer modes and fee - AuthInfo auth_info = 2; - - // signatures are the raw binary signatures of signers specified by body and auth_info - repeated bytes signatures = 3; -} - -// SignDoc is the standard type used for signing transaction in SIGN_MODE_DIRECT -message SignDoc { - option (gogoproto.stringer) = true; - - // body is the TxBody from Tx - TxBody body = 1; - - // auth_info is the AuthInfo from Tx - AuthInfo auth_info = 2; - - // chain_id is the unique identifier of the chain this transaction targets. - // It prevents signed transactions from being used on another chain by an - // attacker - string chain_id = 3; - - // account_number is the account number of the account in state - uint64 account_number = 4; - - // account_sequence starts at 1 rather than 0 to avoid the case where - // the default 0 value must be omitted in protobuf serialization - uint64 account_sequence = 5; -} - -// TxBody is the body of a transaction that all signers sign over -message TxBody { - option (gogoproto.stringer) = true; - - // messages are the processable content of the transaction - repeated google.protobuf.Any messages = 1; - - // memo is any arbitrary memo to be added to the transaction - string memo = 2; - - // timeout is the block height after which this transaction will not - // be processed by the chain - int64 timeout_height = 3; - - // extension_options are arbitrary options that can be added by chains - // when the default options are not sufficient. If any of these are present - // and can't be handled, the transaction will be rejected - repeated google.protobuf.Any extension_options = 1023; - - // extension_options are arbitrary options that can be added by chains - // when the default options are not sufficient. If any of these are present - // and can't be handled, they will be ignored - repeated google.protobuf.Any non_critical_extension_options = 2047; -} - -// AuthInfo describes the fee and signer modes that are used to sign a transaction -message AuthInfo { - option (gogoproto.stringer) = true; - - // signer_infos is the list of signer infos which corresponds with - // Tx.signatures and expected signers derived from TxBody.messages. All signers - // are expected to occur in the same order in each of these locations - repeated SignerInfo signer_infos = 1; - - // Fee is the fee and gas limit for the transaction. The first signer is the - // primary signer and the one which pays the fee - Fee fee = 2; -} - -// SignerInfo describes the public key and signing mode of a single top-level signer -message SignerInfo { - option (gogoproto.stringer) = true; - - // public_key is the public key of the signer. It is optional for accounts - // that already exist in state - google.protobuf.Any public_key = 1; - - // mode_info describes the signing mode of the signer and is a nested - // structure to support nested multisig pubkey's - ModeInfo mode_info = 2; -} - -// ModeInfo describes the signing mode of a single or nested multisig signer -message ModeInfo { - option (gogoproto.stringer) = true; - - // sum is the oneof that specifies whether this represents a single or nested - // multisig signer - oneof sum { - // single represents a single signer - Single single = 1; - - // multi represents a nested multisig signer - Multi multi = 2; - } - - // Single is the mode info for a single signer. It is structured as a message - // to allow for additional fields such as locale for SIGN_MODE_TEXTUAL in the future - message Single { - option (gogoproto.stringer) = true; - - // mode is the signing mode of the single signer - SignMode mode = 1; - } - - // Multi is the mode info for a multisig public key - message Multi { - option (gogoproto.stringer) = true; - - // bitarray specifies which keys within the multisig are signing - CompactBitArray bitarray = 1; - - // mode_infos is the corresponding modes of the signers of the multisig - // which could include nested multisig public keys - repeated ModeInfo mode_infos = 2; - } -} - -// SignMode represents a signing mode with its own security guarantees -enum SignMode { - // SIGN_MODE_UNSPECIFIED specifies an unknown signing mode and will be rejected - SIGN_MODE_UNSPECIFIED = 0; - - // SIGN_MODE_DIRECT specifies a signing mode which uses SignDoc and is verified - // with raw bytes from Tx - SIGN_MODE_DIRECT = 1; - - // SIGN_MODE_TEXTUAL is a future signing mode that will verify some human-readable - // textual representation on top of the binary representation from SIGN_MODE_DIRECT - SIGN_MODE_TEXTUAL = 2; - - // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses - // Amino JSON and will be removed in the future - SIGN_MODE_LEGACY_AMINO_JSON = 127; -} - -// Fee includes the amount of coins paid in fees and the maximum -// gas to be used by the transaction. The ratio yields an effective "gasprice", -// which must be above some miminum to be accepted into the mempool. -message Fee { - option (gogoproto.goproto_getters) = false; - option (gogoproto.equal) = true; - option (gogoproto.stringer) = true; - - // amount is the amount of coins to be paid as a fee - repeated Coin amount = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "Coins"]; - - // gas_limit is the maximum gas that can be used in transaction processing - // before an out of gas error occurs - uint64 gas_limit = 2; -} - -// CompactBitArray is an implementation of a space efficient bit array. -// This is used to ensure that the encoded data takes up a minimal amount of -// space after proto encoding. -// This is not thread safe, and is not intended for concurrent usage. -message CompactBitArray { -// option (gogoproto.sizer) = false; -// option (gogoproto.goproto_stringer) = false; - option (gogoproto.stringer) = true; - - uint32 extra_bits_stored = 1; - bytes elems = 2; -} diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index fe3191d2e256..66ee669e3374 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -143,7 +143,7 @@ func CountSubKeys(pub crypto.PubKey) int { var _ sdk.Tx = (*StdTx)(nil) -// StdTx is a standard way to wrap a Msg with FeeI and Signatures. +// StdTx is a standard way to wrap a Msg with Fee and Signatures. // NOTE: the first signature is the fee payer (Signatures must not be nil). type StdTx struct { Msgs []sdk.Msg `json:"msg" yaml:"msg"` From c6386599fafb880741d585f2c5597bec4eba5ffc Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 15:24:42 -0400 Subject: [PATCH 10/54] WIP on proto ante handlers --- types/tx/raw/decoded_tx.go | 120 +++++++++++++++++---------------- x/auth/ante/ante.go | 23 +++++++ x/auth/ante/sigverify.go | 12 +--- x/auth/ante/sigverify_proto.go | 99 +++++++++++++++++++++++++++ x/auth/types/stdtx.go | 4 +- 5 files changed, 188 insertions(+), 70 deletions(-) create mode 100644 x/auth/ante/sigverify_proto.go diff --git a/types/tx/raw/decoded_tx.go b/types/tx/raw/decoded_tx.go index 16f29d3521fd..19fe9227349f 100644 --- a/types/tx/raw/decoded_tx.go +++ b/types/tx/raw/decoded_tx.go @@ -3,6 +3,9 @@ package raw import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/tendermint/tendermint/crypto" @@ -14,79 +17,80 @@ import ( ) type DecodedTx struct { - *sdk.Tx + *types.Tx Raw *TxRaw Msgs []sdk.Msg PubKeys []crypto.PubKey Signers []sdk.AccAddress - SignerInfoMap map[string]*sdk.SignerInfo + SignerInfoMap map[string]*types.SignerInfo } var _ sdk.Tx = DecodedTx{} -var _ ante.SigVerifiableTx = DecodedTx{} var _ ante.FeeTx = DecodedTx{} var _ ante.TxWithMemo = DecodedTx{} -var DefaultTxDecoder sdk.TxDecoder = func(txBytes []byte) (sdk.Tx, error) { - var raw TxRaw - err := raw.Unmarshal(txBytes) - if err != nil { - return nil, err - } +func DefaultTxDecoder(cdc codec.Marshaler) sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + var raw TxRaw + err := cdc.UnmarshalBinaryBare(txBytes, &raw) + if err != nil { + return nil, err + } - var tx sdk.Tx - err = tx.Unmarshal(txBytes) - if err != nil { - return nil, err - } + var tx types.Tx + err = cdc.UnmarshalBinaryBare(txBytes, &tx) + if err != nil { + return nil, err + } - anyMsgs := tx.Body.Messages - msgs := make([]sdk.Msg, len(anyMsgs)) - for i, any := range anyMsgs { - msg, ok := any.GetCachedValue().(sdk.Msg) - if !ok { - return nil, fmt.Errorf("can't decode sdk.Msg from %+v", any) + anyMsgs := tx.Body.Messages + msgs := make([]sdk.Msg, len(anyMsgs)) + for i, any := range anyMsgs { + msg, ok := any.GetCachedValue().(sdk.Msg) + if !ok { + return nil, fmt.Errorf("can't decode sdk.Msg from %+v", any) + } + msgs[i] = msg } - msgs[i] = msg - } - var signers []sdk.AccAddress - seen := map[string]bool{} + var signers []sdk.AccAddress + seen := map[string]bool{} - for _, msg := range msgs { - for _, addr := range msg.GetSigners() { - if !seen[addr.String()] { - signers = append(signers, addr) - seen[addr.String()] = true + for _, msg := range msgs { + for _, addr := range msg.GetSigners() { + if !seen[addr.String()] { + signers = append(signers, addr) + seen[addr.String()] = true + } } } - } - nSigners := len(signers) - signerInfos := tx.AuthInfo.SignerInfos - signerInfoMap := map[string]*sdk.SignerInfo{} - pubKeys := make([]crypto.PubKey, len(signerInfos)) - for i, si := range signerInfos { - any := si.PublicKey - pubKey, ok := any.GetCachedValue().(crypto.PubKey) - if !ok { - return nil, fmt.Errorf("can't decode PublicKey from %+v", any) - } - pubKeys[i] = pubKey + nSigners := len(signers) + signerInfos := tx.AuthInfo.SignerInfos + signerInfoMap := map[string]*types.SignerInfo{} + pubKeys := make([]crypto.PubKey, len(signerInfos)) + for i, si := range signerInfos { + any := si.PublicKey + pubKey, ok := any.GetCachedValue().(crypto.PubKey) + if !ok { + return nil, fmt.Errorf("can't decode PublicKey from %+v", any) + } + pubKeys[i] = pubKey - if i < nSigners { - signerInfoMap[signers[i].String()] = si + if i < nSigners { + signerInfoMap[signers[i].String()] = si + } } - } - return DecodedTx{ - Tx: &tx, - Raw: &raw, - Msgs: msgs, - PubKeys: pubKeys, - Signers: signers, - SignerInfoMap: signerInfoMap, - }, nil + return DecodedTx{ + Tx: &tx, + Raw: &raw, + Msgs: msgs, + PubKeys: pubKeys, + Signers: signers, + SignerInfoMap: signerInfoMap, + }, nil + } } func (d DecodedTx) GetMsgs() []sdk.Msg { @@ -144,20 +148,20 @@ func (d DecodedTx) GetSignBytes(ctx sdk.Context, acc authexported.Account) ([]by } switch modeInfo := signerInfo.ModeInfo.Sum.(type) { - case *sdk.ModeInfo_Single_: + case *types.ModeInfo_Single_: switch modeInfo.Single.Mode { - case sdk.SignMode_SIGN_MODE_UNSPECIFIED: + case types.SignMode_SIGN_MODE_UNSPECIFIED: return nil, fmt.Errorf("unspecified sign mode") - case sdk.SignMode_SIGN_MODE_DIRECT: + case types.SignMode_SIGN_MODE_DIRECT: return DirectSignBytes(d.Raw.BodyBytes, d.Raw.AuthInfoBytes, chainID, accNum, acc.GetSequence()) - case sdk.SignMode_SIGN_MODE_TEXTUAL: + case types.SignMode_SIGN_MODE_TEXTUAL: return nil, fmt.Errorf("SIGN_MODE_TEXTUAL is not supported yet") - case sdk.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + case types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: return auth.StdSignBytes( chainID, accNum, acc.GetSequence(), auth.StdFee{Amount: d.GetFee(), Gas: d.GetGas()}, d.Msgs, d.Body.Memo, ), nil } - case *sdk.ModeInfo_Multi_: + case *types.ModeInfo_Multi_: return nil, fmt.Errorf("multisig mode info is not supported by GetSignBytes") default: return nil, fmt.Errorf("unexpected ModeInfo") diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index ab9e804b958f..df00f1c45e2b 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -29,3 +29,26 @@ func NewAnteHandler( ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator ) } + +// NewProtoAnteHandler returns an AnteHandler that checks and increments sequence +// numbers, checks signatures & account numbers, and deducts fees from the first +// signer for the protobuf Tx format. +func NewProtoAnteHandler( + ak AccountKeeper, bankKeeper types.BankKeeper, ibcKeeper ibckeeper.Keeper, + sigGasConsumer SignatureVerificationGasConsumer, +) sdk.AnteHandler { + return sdk.ChainAnteDecorators( + NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + NewMempoolFeeDecorator(), + NewValidateBasicDecorator(), + NewValidateMemoDecorator(ak), + NewConsumeGasForTxSizeDecorator(ak), + NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators + NewValidateSigCountDecorator(ak), + NewDeductFeeDecorator(ak, bankKeeper), + NewSigGasConsumeDecorator(ak, sigGasConsumer), + NewSigVerificationDecorator(ak), + NewIncrementSequenceDecorator(ak), + ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator + ) +} diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 9719b3cfeaa1..93ae0f3b4ae4 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -41,15 +41,7 @@ type SigVerifiableTx interface { GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, error) -} - -type SigVerifiableTx interface { - sdk.Tx - GetSignatures() [][]byte - GetSigners() []sdk.AccAddress - GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, error) + GetSignBytes(ctx sdk.Context, acc exported.Account) []byte } // SetPubKeyDecorator sets PubKeys in context for any signer which does not already have pubkey set @@ -206,7 +198,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } // retrieve signBytes of tx - signBytes, _ := sigTx.GetSignBytes(ctx, signerAccs[i]) + signBytes := sigTx.GetSignBytes(ctx, signerAccs[i]) // retrieve pubkey pubKey := signerAccs[i].GetPubKey() diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go new file mode 100644 index 000000000000..d48b4a62a418 --- /dev/null +++ b/x/auth/ante/sigverify_proto.go @@ -0,0 +1,99 @@ +package ante + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx/raw" + "github.com/cosmos/cosmos-sdk/x/auth/exported" +) + +type SignModeVerifier interface { + GetSignBytes(tx raw.DecodedTx) ([]byte, error) +} + +type ProtoSigVerificationDecorator struct { + ak AccountKeeper + signModeVerifiers map[types.SignMode]SignModeVerifier +} + +func NewProtoSigVerificationDecorator(ak AccountKeeper) ProtoSigVerificationDecorator { + return ProtoSigVerificationDecorator{ + ak: ak, + } +} + +func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { + // no need to verify signatures on recheck tx + if ctx.IsReCheckTx() { + return next(ctx, tx, simulate) + } + sigTx, ok := tx.(raw.DecodedTx) + if !ok { + return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") + } + + // stdSigs contains the sequence number, account number, and signatures. + // When simulating, this would just be a 0-length slice. + sigs := sigTx.GetSignatures() + + // stdSigs contains the sequence number, account number, and signatures. + // When simulating, this would just be a 0-length slice. + signerAddrs := sigTx.GetSigners() + signerAccs := make([]exported.Account, len(signerAddrs)) + + for _, si := range sigTx.AuthInfo.SignerInfos { + switch mi := si.ModeInfo.Sum.(type) { + case *types.ModeInfo_Single_: + verifier, found := svd.signModeVerifiers[mi.Single.Mode] + if !found { + return ctx, fmt.Errorf("can't verify sign mode %s", mi.Single.Mode.String()) + } + bz, err := verifier.GetSignBytes(sigTx) + if err != nil { + return ctx, err + } + // retrieve pubkey + pubKey := signerAccs[i].GetPubKey() + if !simulate && pubKey == nil { + return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") + } + + // verify signature + if !simulate && !pubKey.VerifyBytes(signBytes, sig) { + return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") + } + case *types.ModeInfo_Multi_: + } + } + + // check that signer length and signature length are the same + if len(sigs) != len(signerAddrs) { + return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) + } + + for i, sig := range sigs { + signerAccs[i], err = GetSignerAcc(ctx, svd.ak, signerAddrs[i]) + if err != nil { + return ctx, err + } + + // retrieve signBytes of tx + signBytes := sigTx.GetSignBytes(ctx, signerAccs[i]) + + // retrieve pubkey + pubKey := signerAccs[i].GetPubKey() + if !simulate && pubKey == nil { + return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") + } + + // verify signature + if !simulate && !pubKey.VerifyBytes(signBytes, sig) { + return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") + } + } + + return next(ctx, tx, simulate) +} diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 66ee669e3374..3f5eb1e41076 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -246,7 +246,7 @@ func (tx StdTx) GetPubKeys() []crypto.PubKey { } // GetSignBytes returns the signBytes of the tx for a given signer -func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, error) { +func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) []byte { genesis := ctx.BlockHeight() == 0 chainID := ctx.ChainID() var accNum uint64 @@ -256,7 +256,7 @@ func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) ([]byte, err return StdSignBytes( chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, - ), nil + ) } // GetGas returns the Gas in StdFee From 40911b8a2f37b3737272c3903451cc68cd980f84 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 13:08:41 -0400 Subject: [PATCH 11/54] WIP on proto signing handlers --- types/tx/{raw => signing}/decoded_tx.go | 97 +++++--------------- types/tx/signing/direct.go | 26 ++++++ types/tx/signing/handler.go | 20 +++++ types/tx/signing/legacy_amino_json.go | 20 +++++ types/tx/{raw => signing}/types.pb.go | 62 ++++++------- types/tx/{raw => signing}/types.proto | 4 +- types/tx/types.pb.go | 115 ++++++++++++------------ types/tx/types.proto | 2 +- x/auth/ante/sigverify.go | 9 +- x/auth/ante/sigverify_proto.go | 77 ++++++++-------- 10 files changed, 227 insertions(+), 205 deletions(-) rename types/tx/{raw => signing}/decoded_tx.go (52%) create mode 100644 types/tx/signing/direct.go create mode 100644 types/tx/signing/handler.go create mode 100644 types/tx/signing/legacy_amino_json.go rename types/tx/{raw => signing}/types.pb.go (88%) rename types/tx/{raw => signing}/types.proto (80%) diff --git a/types/tx/raw/decoded_tx.go b/types/tx/signing/decoded_tx.go similarity index 52% rename from types/tx/raw/decoded_tx.go rename to types/tx/signing/decoded_tx.go index 19fe9227349f..a0dbfb7c51f8 100644 --- a/types/tx/raw/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -1,35 +1,37 @@ -package raw +package signing import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" - types "github.com/cosmos/cosmos-sdk/types/tx" - - "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/ante" auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) type DecodedTx struct { *types.Tx - Raw *TxRaw - Msgs []sdk.Msg - PubKeys []crypto.PubKey - Signers []sdk.AccAddress - SignerInfoMap map[string]*types.SignerInfo + Raw *TxRaw + Msgs []sdk.Msg + PubKeys []crypto.PubKey + Signers []sdk.AccAddress } var _ sdk.Tx = DecodedTx{} var _ ante.FeeTx = DecodedTx{} var _ ante.TxWithMemo = DecodedTx{} +var _ ante.HasPubKeysTx = DecodedTx{} + +type PublicKeyDecoder func(key *cryptotypes.PublicKey) (crypto.PubKey, error) -func DefaultTxDecoder(cdc codec.Marshaler) sdk.TxDecoder { +func DefaultTxDecoder(cdc codec.Marshaler, pubKeyDecoder PublicKeyDecoder) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := cdc.UnmarshalBinaryBare(txBytes, &raw) @@ -65,30 +67,22 @@ func DefaultTxDecoder(cdc codec.Marshaler) sdk.TxDecoder { } } - nSigners := len(signers) signerInfos := tx.AuthInfo.SignerInfos - signerInfoMap := map[string]*types.SignerInfo{} pubKeys := make([]crypto.PubKey, len(signerInfos)) for i, si := range signerInfos { - any := si.PublicKey - pubKey, ok := any.GetCachedValue().(crypto.PubKey) - if !ok { - return nil, fmt.Errorf("can't decode PublicKey from %+v", any) + pubKey, err := pubKeyDecoder(si.PublicKey) + if err != nil { + return nil, errors.Wrap(err, "can't decode public key") } pubKeys[i] = pubKey - - if i < nSigners { - signerInfoMap[signers[i].String()] = si - } } return DecodedTx{ - Tx: &tx, - Raw: &raw, - Msgs: msgs, - PubKeys: pubKeys, - Signers: signers, - SignerInfoMap: signerInfoMap, + Tx: &tx, + Raw: &raw, + Msgs: msgs, + PubKeys: pubKeys, + Signers: signers, }, nil } } @@ -133,53 +127,6 @@ func (d DecodedTx) GetPubKeys() []crypto.PubKey { return d.PubKeys } -func (d DecodedTx) GetSignBytes(ctx sdk.Context, acc authexported.Account) ([]byte, error) { - address := acc.GetAddress() - signerInfo, ok := d.SignerInfoMap[address.String()] - if !ok { - return nil, fmt.Errorf("missing SignerInfo for address %s", address.String()) - } - - genesis := ctx.BlockHeight() == 0 - chainID := ctx.ChainID() - var accNum uint64 - if !genesis { - accNum = acc.GetAccountNumber() - } - - switch modeInfo := signerInfo.ModeInfo.Sum.(type) { - case *types.ModeInfo_Single_: - switch modeInfo.Single.Mode { - case types.SignMode_SIGN_MODE_UNSPECIFIED: - return nil, fmt.Errorf("unspecified sign mode") - case types.SignMode_SIGN_MODE_DIRECT: - return DirectSignBytes(d.Raw.BodyBytes, d.Raw.AuthInfoBytes, chainID, accNum, acc.GetSequence()) - case types.SignMode_SIGN_MODE_TEXTUAL: - return nil, fmt.Errorf("SIGN_MODE_TEXTUAL is not supported yet") - case types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: - return auth.StdSignBytes( - chainID, accNum, acc.GetSequence(), auth.StdFee{Amount: d.GetFee(), Gas: d.GetGas()}, d.Msgs, d.Body.Memo, - ), nil - } - case *types.ModeInfo_Multi_: - return nil, fmt.Errorf("multisig mode info is not supported by GetSignBytes") - default: - return nil, fmt.Errorf("unexpected ModeInfo") - } - return nil, fmt.Errorf("unexpected") -} - -func DirectSignBytes(bodyBz, authInfoBz []byte, chainID string, accnum, sequence uint64) ([]byte, error) { - signDoc := SignDocRaw{ - BodyBytes: bodyBz, - AuthInfoBytes: authInfoBz, - ChainId: chainID, - AccountNumber: accnum, - AccountSequence: sequence, - } - return signDoc.Marshal() -} - func (d DecodedTx) GetGas() uint64 { return d.AuthInfo.Fee.GasLimit } diff --git a/types/tx/signing/direct.go b/types/tx/signing/direct.go new file mode 100644 index 000000000000..11c636806315 --- /dev/null +++ b/types/tx/signing/direct.go @@ -0,0 +1,26 @@ +package signing + +import types "github.com/cosmos/cosmos-sdk/types/tx" + +type DirectModeHandler struct{} + +var _ SignModeHandler = DirectModeHandler{} + +func (DirectModeHandler) Mode() types.SignMode { + return types.SignMode_SIGN_MODE_DIRECT +} + +func (DirectModeHandler) GetSignBytes(data SigningData, tx DecodedTx) ([]byte, error) { + return DirectSignBytes(tx.Raw.BodyBytes, tx.Raw.AuthInfoBytes, data.ChainID, data.AccountNumber, data.AccountSequence) +} + +func DirectSignBytes(bodyBz, authInfoBz []byte, chainID string, accnum, sequence uint64) ([]byte, error) { + signDoc := SignDocRaw{ + BodyBytes: bodyBz, + AuthInfoBytes: authInfoBz, + ChainId: chainID, + AccountNumber: accnum, + AccountSequence: sequence, + } + return signDoc.Marshal() +} diff --git a/types/tx/signing/handler.go b/types/tx/signing/handler.go new file mode 100644 index 000000000000..cebee8e22641 --- /dev/null +++ b/types/tx/signing/handler.go @@ -0,0 +1,20 @@ +package signing + +import ( + "github.com/tendermint/tendermint/crypto" + + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +type SigningData struct { + ModeInfo *types.ModeInfo_Single + PublicKey crypto.PubKey + ChainID string + AccountNumber uint64 + AccountSequence uint64 +} + +type SignModeHandler interface { + Mode() types.SignMode + GetSignBytes(data SigningData, tx DecodedTx) ([]byte, error) +} diff --git a/types/tx/signing/legacy_amino_json.go b/types/tx/signing/legacy_amino_json.go new file mode 100644 index 000000000000..6ab1038e7990 --- /dev/null +++ b/types/tx/signing/legacy_amino_json.go @@ -0,0 +1,20 @@ +package signing + +import ( + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth" +) + +type LegacyAminoJSONHandler struct{} + +var _ SignModeHandler = LegacyAminoJSONHandler{} + +func (LegacyAminoJSONHandler) Mode() types.SignMode { + return types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON +} + +func (LegacyAminoJSONHandler) GetSignBytes(data SigningData, tx DecodedTx) ([]byte, error) { + return auth.StdSignBytes( + data.ChainID, data.AccountNumber, data.AccountSequence, auth.StdFee{Amount: tx.GetFee(), Gas: tx.GetGas()}, tx.Msgs, tx.Body.Memo, + ), nil +} diff --git a/types/tx/raw/types.pb.go b/types/tx/signing/types.pb.go similarity index 88% rename from types/tx/raw/types.pb.go rename to types/tx/signing/types.pb.go index 423b8669ab2a..257b474c95c1 100644 --- a/types/tx/raw/types.pb.go +++ b/types/tx/signing/types.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: types/tx/raw/types.proto +// source: types/tx/signing/types.proto -package raw +package signing import ( fmt "fmt" @@ -33,7 +33,7 @@ func (m *TxRaw) Reset() { *m = TxRaw{} } func (m *TxRaw) String() string { return proto.CompactTextString(m) } func (*TxRaw) ProtoMessage() {} func (*TxRaw) Descriptor() ([]byte, []int) { - return fileDescriptor_e2501207b76f25b1, []int{0} + return fileDescriptor_52d5d5e2efced9ba, []int{0} } func (m *TxRaw) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -96,7 +96,7 @@ func (m *SignDocRaw) Reset() { *m = SignDocRaw{} } func (m *SignDocRaw) String() string { return proto.CompactTextString(m) } func (*SignDocRaw) ProtoMessage() {} func (*SignDocRaw) Descriptor() ([]byte, []int) { - return fileDescriptor_e2501207b76f25b1, []int{1} + return fileDescriptor_52d5d5e2efced9ba, []int{1} } func (m *SignDocRaw) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -161,33 +161,33 @@ func (m *SignDocRaw) GetAccountSequence() uint64 { } func init() { - proto.RegisterType((*TxRaw)(nil), "cosmos_sdk.tx.raw.v1.TxRaw") - proto.RegisterType((*SignDocRaw)(nil), "cosmos_sdk.tx.raw.v1.SignDocRaw") -} - -func init() { proto.RegisterFile("types/tx/raw/types.proto", fileDescriptor_e2501207b76f25b1) } - -var fileDescriptor_e2501207b76f25b1 = []byte{ - // 299 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0xd1, 0x31, 0x4e, 0xf3, 0x30, - 0x14, 0xc0, 0xf1, 0xfa, 0x6b, 0xfb, 0x41, 0x9f, 0x5a, 0x8a, 0x22, 0x06, 0x33, 0x60, 0x45, 0x95, - 0x40, 0xe9, 0x40, 0x22, 0xc4, 0x0d, 0x0a, 0x4b, 0x17, 0x86, 0x94, 0x89, 0x25, 0x72, 0x1c, 0xb7, - 0xb5, 0xaa, 0xda, 0x25, 0xb6, 0x69, 0x73, 0x0b, 0x8e, 0xc4, 0xc8, 0xd8, 0x91, 0x11, 0x25, 0x17, - 0x41, 0x71, 0x83, 0xd4, 0x03, 0x30, 0x59, 0xef, 0xa7, 0xbf, 0x64, 0xe9, 0x3d, 0xc0, 0xa6, 0xd8, - 0x70, 0x1d, 0x99, 0x5d, 0x94, 0xd3, 0x6d, 0xe4, 0x86, 0x70, 0x93, 0x2b, 0xa3, 0xbc, 0x0b, 0xa6, - 0xf4, 0x5a, 0xe9, 0x44, 0x67, 0xab, 0xd0, 0xec, 0xc2, 0x9c, 0x6e, 0xc3, 0xb7, 0xbb, 0x91, 0x84, - 0xee, 0xf3, 0x2e, 0xa6, 0x5b, 0xef, 0x0a, 0x20, 0x55, 0x59, 0x91, 0xa4, 0x85, 0xe1, 0x1a, 0x23, - 0x1f, 0x05, 0xfd, 0xb8, 0x57, 0xcb, 0xa4, 0x06, 0xef, 0x06, 0x86, 0xd4, 0x9a, 0x65, 0x22, 0xe4, - 0x5c, 0x35, 0xcd, 0x3f, 0xd7, 0x0c, 0x6a, 0x9e, 0xca, 0xb9, 0x3a, 0x74, 0x04, 0x40, 0x8b, 0x85, - 0xa4, 0xc6, 0xe6, 0x5c, 0xe3, 0xb6, 0xdf, 0x0e, 0xfa, 0xf1, 0x91, 0x8c, 0x3e, 0x10, 0xc0, 0x4c, - 0x2c, 0xe4, 0xa3, 0x62, 0x7f, 0xf8, 0xeb, 0x25, 0x9c, 0xb2, 0x25, 0x15, 0x32, 0x11, 0x19, 0x6e, - 0xfb, 0x28, 0xe8, 0xc5, 0x27, 0x6e, 0x9e, 0x66, 0xde, 0x35, 0x9c, 0x51, 0xc6, 0x94, 0x95, 0x26, - 0x91, 0x76, 0x9d, 0xf2, 0x1c, 0x77, 0x7c, 0x14, 0x74, 0xe2, 0x41, 0xa3, 0x4f, 0x0e, 0xbd, 0x31, - 0x9c, 0xff, 0x66, 0x9a, 0xbf, 0x5a, 0x2e, 0x19, 0xc7, 0x5d, 0x17, 0x0e, 0x1b, 0x9f, 0x35, 0x3c, - 0x79, 0xf8, 0x2c, 0x09, 0xda, 0x97, 0x04, 0x7d, 0x97, 0x04, 0xbd, 0x57, 0xa4, 0xb5, 0xaf, 0x48, - 0xeb, 0xab, 0x22, 0xad, 0x97, 0xf1, 0x42, 0x98, 0xa5, 0x4d, 0x43, 0xa6, 0xd6, 0xd1, 0x61, 0xdb, - 0xcd, 0x73, 0xab, 0xb3, 0x55, 0x74, 0x7c, 0x99, 0xf4, 0xbf, 0x3b, 0xca, 0xfd, 0x4f, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xa2, 0xbe, 0x03, 0xb1, 0xb0, 0x01, 0x00, 0x00, + proto.RegisterType((*TxRaw)(nil), "cosmos_sdk.tx.signing.v1.TxRaw") + proto.RegisterType((*SignDocRaw)(nil), "cosmos_sdk.tx.signing.v1.SignDocRaw") +} + +func init() { proto.RegisterFile("types/tx/signing/types.proto", fileDescriptor_52d5d5e2efced9ba) } + +var fileDescriptor_52d5d5e2efced9ba = []byte{ + // 297 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0xd1, 0xc1, 0x4a, 0xc3, 0x30, + 0x18, 0xc0, 0xf1, 0xc5, 0x6d, 0xea, 0x3e, 0x36, 0x27, 0x3d, 0x45, 0xd0, 0x50, 0x06, 0x4a, 0x3d, + 0xac, 0x45, 0x7c, 0x83, 0x21, 0xc8, 0x2e, 0x1e, 0x3a, 0x4f, 0x5e, 0x4a, 0x9b, 0x66, 0x5d, 0x18, + 0x4b, 0xe6, 0x92, 0xe8, 0xfa, 0x16, 0x3e, 0x92, 0x47, 0x8f, 0x3b, 0x7a, 0x94, 0xf6, 0x45, 0xa4, + 0x59, 0x04, 0xf1, 0xec, 0x29, 0xe4, 0xc7, 0x9f, 0x04, 0xbe, 0x0f, 0xce, 0x75, 0xb9, 0x66, 0x2a, + 0xd2, 0xdb, 0x48, 0xf1, 0x42, 0x70, 0x51, 0x44, 0x16, 0xc2, 0xf5, 0x46, 0x6a, 0xe9, 0x61, 0x2a, + 0xd5, 0x4a, 0xaa, 0x44, 0xe5, 0xcb, 0x50, 0x6f, 0x43, 0x97, 0x84, 0x2f, 0x37, 0x23, 0x01, 0xdd, + 0xc7, 0x6d, 0x9c, 0xbe, 0x7a, 0x17, 0x00, 0x99, 0xcc, 0xcb, 0x24, 0x2b, 0x35, 0x53, 0x18, 0xf9, + 0x28, 0xe8, 0xc7, 0xbd, 0x46, 0x26, 0x0d, 0x78, 0x57, 0x30, 0x4c, 0x8d, 0x5e, 0x24, 0x5c, 0xcc, + 0xa5, 0x6b, 0x0e, 0x6c, 0x33, 0x68, 0x78, 0x2a, 0xe6, 0x72, 0xdf, 0x11, 0x80, 0xe6, 0xf5, 0x54, + 0x9b, 0x0d, 0x53, 0xb8, 0xed, 0xb7, 0x83, 0x7e, 0xfc, 0x4b, 0x46, 0xef, 0x08, 0x60, 0xc6, 0x0b, + 0x71, 0x27, 0xe9, 0x3f, 0xfe, 0x7a, 0x06, 0xc7, 0x74, 0x91, 0x72, 0x91, 0xf0, 0x1c, 0xb7, 0x7d, + 0x14, 0xf4, 0xe2, 0x23, 0x7b, 0x9f, 0xe6, 0xde, 0x25, 0x9c, 0xa4, 0x94, 0x4a, 0x23, 0x74, 0x22, + 0xcc, 0x2a, 0x63, 0x1b, 0xdc, 0xf1, 0x51, 0xd0, 0x89, 0x07, 0x4e, 0x1f, 0x2c, 0x7a, 0xd7, 0x70, + 0xfa, 0x93, 0x29, 0xf6, 0x6c, 0x98, 0xa0, 0x0c, 0x77, 0x6d, 0x38, 0x74, 0x3e, 0x73, 0x3c, 0xb9, + 0xff, 0xa8, 0x08, 0xda, 0x55, 0x04, 0x7d, 0x55, 0x04, 0xbd, 0xd5, 0xa4, 0xb5, 0xab, 0x49, 0xeb, + 0xb3, 0x26, 0xad, 0xa7, 0x71, 0xc1, 0xf5, 0xc2, 0x64, 0x21, 0x95, 0xab, 0x68, 0x3f, 0x71, 0x77, + 0x8c, 0x55, 0xbe, 0x8c, 0xfe, 0x6e, 0x28, 0x3b, 0xb4, 0xcb, 0xb9, 0xfd, 0x0e, 0x00, 0x00, 0xff, + 0xff, 0x34, 0x9a, 0xbd, 0x5a, 0xbc, 0x01, 0x00, 0x00, } func (m *TxRaw) Marshal() (dAtA []byte, err error) { diff --git a/types/tx/raw/types.proto b/types/tx/signing/types.proto similarity index 80% rename from types/tx/raw/types.proto rename to types/tx/signing/types.proto index 4297fc74bbd5..541cd68ba63e 100644 --- a/types/tx/raw/types.proto +++ b/types/tx/signing/types.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package cosmos_sdk.tx.raw.v1; +package cosmos_sdk.tx.signing.v1; -option go_package = "github.com/cosmos/cosmos-sdk/types/tx/raw"; +option go_package = "github.com/cosmos/cosmos-sdk/types/tx/signing"; // TxRaw is using for transaction decoding and verification message TxRaw { diff --git a/types/tx/types.pb.go b/types/tx/types.pb.go index 303324b4ed23..57b4c4d83410 100644 --- a/types/tx/types.pb.go +++ b/types/tx/types.pb.go @@ -365,7 +365,7 @@ func (m *AuthInfo) GetFee() *Fee { type SignerInfo struct { // public_key is the public key of the signer. It is optional for accounts // that already exist in state - PublicKey *types.Any `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + PublicKey *types1.PublicKey `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` // mode_info describes the signing mode of the signer and is a nested // structure to support nested multisig pubkey's ModeInfo *ModeInfo `protobuf:"bytes,2,opt,name=mode_info,json=modeInfo,proto3" json:"mode_info,omitempty"` @@ -404,7 +404,7 @@ func (m *SignerInfo) XXX_DiscardUnknown() { var xxx_messageInfo_SignerInfo proto.InternalMessageInfo -func (m *SignerInfo) GetPublicKey() *types.Any { +func (m *SignerInfo) GetPublicKey() *types1.PublicKey { if m != nil { return m.PublicKey } @@ -684,60 +684,61 @@ func init() { func init() { proto.RegisterFile("types/tx/types.proto", fileDescriptor_1c6ac8fa65877134) } var fileDescriptor_1c6ac8fa65877134 = []byte{ - // 842 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x4d, 0x6f, 0xe3, 0x44, - 0x18, 0x8e, 0x93, 0x34, 0x4d, 0xde, 0xee, 0x47, 0x3a, 0xb4, 0x92, 0x9b, 0xa2, 0x34, 0x44, 0x2a, - 0x04, 0x04, 0xce, 0xb2, 0x7b, 0x60, 0x11, 0x87, 0x55, 0x92, 0xa6, 0xdb, 0x40, 0x9b, 0xa2, 0x49, - 0x56, 0x82, 0x95, 0x90, 0xe5, 0xd8, 0x53, 0x67, 0xd4, 0x78, 0x26, 0x78, 0xc6, 0x28, 0xe1, 0x82, - 0x38, 0x70, 0xe2, 0xc2, 0x85, 0x3f, 0xc1, 0x2f, 0x59, 0x71, 0xda, 0x23, 0x17, 0x3e, 0xd4, 0xfe, - 0x10, 0x90, 0xc7, 0xe3, 0xa4, 0x6a, 0x4a, 0xb8, 0x71, 0xca, 0xeb, 0x67, 0x9e, 0xe7, 0x99, 0xf7, - 0x2b, 0x36, 0xec, 0xc8, 0xf9, 0x94, 0x88, 0xa6, 0x9c, 0x35, 0x55, 0x60, 0x4d, 0x43, 0x2e, 0x39, - 0x2a, 0xbb, 0x5c, 0x04, 0x5c, 0xd8, 0xc2, 0xbb, 0xb4, 0xe4, 0xcc, 0xfa, 0xe6, 0xc3, 0xca, 0xdb, - 0x72, 0x4c, 0x43, 0xcf, 0x9e, 0x3a, 0xa1, 0x9c, 0x37, 0x15, 0xa9, 0xe9, 0x73, 0x9f, 0x2f, 0xa3, - 0x44, 0x59, 0xd9, 0xd6, 0x7e, 0x4b, 0xb3, 0x8a, 0xe9, 0x86, 0xf3, 0xa9, 0xe4, 0xcd, 0xd5, 0x93, - 0x3d, 0x9f, 0x73, 0x7f, 0x42, 0x12, 0xbf, 0x51, 0x74, 0xd1, 0x74, 0xd8, 0x3c, 0x39, 0xaa, 0xff, - 0x68, 0x40, 0x76, 0x38, 0x43, 0xef, 0x43, 0x7e, 0xc4, 0xbd, 0xb9, 0x69, 0xd4, 0x8c, 0xc6, 0xd6, - 0x63, 0xd3, 0xba, 0x9d, 0x97, 0x35, 0x9c, 0xb5, 0xb9, 0x37, 0xc7, 0x8a, 0x85, 0x3e, 0x82, 0x92, - 0x13, 0xc9, 0xb1, 0x4d, 0xd9, 0x05, 0x37, 0xb3, 0x4a, 0x52, 0x59, 0x95, 0xb4, 0x22, 0x39, 0xee, - 0xb1, 0x0b, 0x8e, 0x8b, 0x8e, 0x8e, 0x50, 0x15, 0x40, 0x50, 0x9f, 0x39, 0x32, 0x0a, 0x89, 0x30, - 0x73, 0xb5, 0x5c, 0xe3, 0x1e, 0xbe, 0x81, 0xd4, 0x7f, 0x37, 0x60, 0x73, 0x40, 0x7d, 0x76, 0xc4, - 0xdd, 0xff, 0x2b, 0xa5, 0x3d, 0x28, 0xba, 0x63, 0x87, 0x32, 0x9b, 0x7a, 0x66, 0xae, 0x66, 0x34, - 0x4a, 0x78, 0x53, 0x3d, 0xf7, 0x3c, 0x74, 0x08, 0x0f, 0x1c, 0xd7, 0xe5, 0x11, 0x93, 0x36, 0x8b, - 0x82, 0x11, 0x09, 0xcd, 0x7c, 0xcd, 0x68, 0xe4, 0xf1, 0x7d, 0x8d, 0xf6, 0x15, 0x88, 0xde, 0x85, - 0x72, 0x4a, 0x13, 0xe4, 0xeb, 0x88, 0x30, 0x97, 0x98, 0x1b, 0x8a, 0xf8, 0x50, 0xe3, 0x03, 0x0d, - 0xd7, 0x7f, 0xce, 0x42, 0x21, 0x49, 0x1b, 0x3d, 0x82, 0x62, 0x40, 0x84, 0x70, 0x7c, 0x22, 0x4c, - 0xa3, 0x96, 0x6b, 0x6c, 0x3d, 0xde, 0xb1, 0x92, 0x31, 0x59, 0xe9, 0x98, 0xac, 0x16, 0x9b, 0xe3, - 0x05, 0x0b, 0x21, 0xc8, 0x07, 0x24, 0x48, 0xaa, 0x2b, 0x61, 0x15, 0xc7, 0x29, 0x4a, 0x1a, 0x10, - 0x1e, 0x49, 0x7b, 0x4c, 0xa8, 0x3f, 0x96, 0xaa, 0x86, 0x1c, 0xbe, 0xaf, 0xd1, 0x13, 0x05, 0xa2, - 0x36, 0x6c, 0x93, 0x99, 0x24, 0x4c, 0x50, 0xce, 0x6c, 0x3e, 0x95, 0x94, 0x33, 0x61, 0xfe, 0xbd, - 0xb9, 0xe6, 0xda, 0xf2, 0x82, 0x7f, 0x9e, 0xd0, 0xd1, 0x4b, 0xa8, 0x32, 0xce, 0x6c, 0x37, 0xa4, - 0x92, 0xba, 0xce, 0xc4, 0xbe, 0xc3, 0xf0, 0xe1, 0x1a, 0xc3, 0x7d, 0xc6, 0x59, 0x47, 0x6b, 0xbb, - 0xb7, 0xbc, 0xeb, 0x12, 0x8a, 0xe9, 0x68, 0xd0, 0x33, 0xb8, 0x17, 0x6f, 0x04, 0x09, 0xd5, 0x2c, - 0xd3, 0xe6, 0xbc, 0xb9, 0x3a, 0xcc, 0x81, 0x62, 0xa9, 0x71, 0x6e, 0x89, 0x45, 0x2c, 0xd0, 0x3b, - 0x90, 0xbb, 0x20, 0x44, 0x2f, 0xc1, 0xee, 0xaa, 0xee, 0x98, 0x10, 0x1c, 0x33, 0xea, 0xdf, 0x02, - 0x2c, 0x3d, 0xd0, 0x13, 0x80, 0x69, 0x34, 0x9a, 0x50, 0xd7, 0xbe, 0x24, 0xe9, 0xd6, 0xdd, 0x5d, - 0x4a, 0x29, 0xe1, 0x7d, 0x46, 0xd4, 0xda, 0x05, 0xdc, 0x23, 0xff, 0xb1, 0x76, 0x67, 0xdc, 0x23, - 0xc9, 0xda, 0x05, 0x3a, 0xaa, 0xff, 0x9a, 0x85, 0x62, 0x0a, 0xa3, 0x4f, 0xa0, 0x20, 0x28, 0xf3, - 0x27, 0x44, 0x5f, 0xfb, 0xd6, 0xbf, 0x5b, 0x58, 0x03, 0x45, 0x3c, 0xc9, 0x60, 0x2d, 0x41, 0x4f, - 0x61, 0x23, 0x88, 0x26, 0x92, 0xea, 0xeb, 0x6b, 0x6b, 0xb4, 0x67, 0x31, 0xef, 0x24, 0x83, 0x13, - 0x41, 0xe5, 0x29, 0x14, 0x12, 0x37, 0x64, 0x41, 0x3e, 0xce, 0x4c, 0x5d, 0xff, 0xe0, 0xae, 0x0a, - 0xe2, 0x3e, 0xc5, 0x36, 0x58, 0xf1, 0x2a, 0x3f, 0x18, 0xb0, 0xa1, 0xcc, 0x50, 0x0b, 0x8a, 0x23, - 0x2a, 0x9d, 0x30, 0x74, 0xd2, 0x9e, 0x1d, 0xde, 0x54, 0x27, 0xaf, 0xa4, 0xd8, 0xa1, 0xc3, 0x83, - 0xa9, 0xe3, 0xca, 0x36, 0x95, 0xad, 0x98, 0x8c, 0x17, 0x32, 0xf4, 0x31, 0xc0, 0xa2, 0x87, 0xc2, - 0xcc, 0xaa, 0x71, 0xaf, 0x6b, 0x62, 0x29, 0x6d, 0xa2, 0x68, 0x6f, 0x40, 0x4e, 0x44, 0x41, 0xfd, - 0x7b, 0x03, 0x72, 0xc7, 0x84, 0xa0, 0xaf, 0xa0, 0xe0, 0x04, 0xf1, 0x1f, 0x4e, 0x2f, 0xcd, 0x1b, - 0x37, 0x5d, 0x54, 0x0e, 0x94, 0xb5, 0x1f, 0xbd, 0xfa, 0xe3, 0x20, 0xf3, 0xcb, 0x9f, 0x07, 0x0d, - 0x9f, 0xca, 0x71, 0x34, 0xb2, 0x5c, 0x1e, 0x34, 0x13, 0x9a, 0xfe, 0xf9, 0x40, 0x78, 0x97, 0xfa, - 0xf5, 0x19, 0x0b, 0x04, 0xd6, 0xa6, 0x68, 0x1f, 0x4a, 0xbe, 0x23, 0xec, 0x09, 0x0d, 0xa8, 0x54, - 0xdd, 0xce, 0xe3, 0xa2, 0xef, 0x88, 0xd3, 0xf8, 0xf9, 0x3d, 0x01, 0xc5, 0xb4, 0x49, 0x68, 0x0f, - 0x76, 0x07, 0xbd, 0xe7, 0x7d, 0xfb, 0xec, 0xfc, 0xa8, 0x6b, 0xbf, 0xe8, 0x0f, 0x3e, 0xef, 0x76, - 0x7a, 0xc7, 0xbd, 0xee, 0x51, 0x39, 0x83, 0x76, 0xa0, 0xbc, 0x3c, 0x3a, 0xea, 0xe1, 0x6e, 0x67, - 0x58, 0x36, 0xd0, 0x2e, 0x6c, 0x2f, 0xd1, 0x61, 0xf7, 0x8b, 0xe1, 0x8b, 0xd6, 0x69, 0x39, 0x8b, - 0x0e, 0x60, 0x7f, 0x09, 0x9f, 0x76, 0x9f, 0xb7, 0x3a, 0x5f, 0xda, 0xad, 0xb3, 0x5e, 0xff, 0xdc, - 0xfe, 0x74, 0x70, 0xde, 0x2f, 0x7f, 0xd7, 0x7e, 0xf6, 0xea, 0xaa, 0x6a, 0xbc, 0xbe, 0xaa, 0x1a, - 0x7f, 0x5d, 0x55, 0x8d, 0x9f, 0xae, 0xab, 0x99, 0xd7, 0xd7, 0xd5, 0xcc, 0x6f, 0xd7, 0xd5, 0xcc, - 0xcb, 0xc3, 0xf5, 0xd5, 0xe9, 0xcf, 0xd0, 0xa8, 0xa0, 0x16, 0xfb, 0xc9, 0x3f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0xa9, 0x40, 0x9c, 0x90, 0x9f, 0x06, 0x00, 0x00, + // 851 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0x8e, 0x93, 0x34, 0x4d, 0x5e, 0xf7, 0x47, 0x3a, 0xb4, 0x92, 0x9b, 0xa2, 0x34, 0x44, 0x2a, + 0x04, 0x04, 0xce, 0xb2, 0x1c, 0x58, 0x84, 0xc4, 0x2a, 0x49, 0xd3, 0x6d, 0xa0, 0x4d, 0x57, 0x93, + 0xac, 0x04, 0x2b, 0x21, 0xcb, 0xb1, 0xa7, 0xce, 0xa8, 0xf1, 0x4c, 0xf0, 0x8c, 0x51, 0x72, 0x42, + 0x1c, 0xf6, 0xc4, 0x85, 0x0b, 0xff, 0x04, 0x7f, 0xc9, 0x8a, 0xd3, 0x1e, 0xb9, 0xf0, 0x43, 0xed, + 0x1f, 0x02, 0xf2, 0x78, 0x9c, 0x54, 0x9b, 0x12, 0x6e, 0x7b, 0xca, 0x9b, 0x6f, 0xbe, 0xef, 0x9b, + 0x37, 0xef, 0xbd, 0x89, 0x61, 0x47, 0xce, 0xa7, 0x44, 0x34, 0xe5, 0xac, 0xa9, 0x02, 0x6b, 0x1a, + 0x72, 0xc9, 0x51, 0xd9, 0xe5, 0x22, 0xe0, 0xc2, 0x16, 0xde, 0xa5, 0x25, 0x67, 0xd6, 0xf7, 0x1f, + 0x57, 0xde, 0x95, 0x63, 0x1a, 0x7a, 0xf6, 0xd4, 0x09, 0xe5, 0xbc, 0xa9, 0x48, 0x4d, 0x9f, 0xfb, + 0x7c, 0x19, 0x25, 0xca, 0xca, 0xb6, 0xf6, 0x5b, 0x9a, 0x55, 0x4c, 0x37, 0x9c, 0x4f, 0x25, 0x6f, + 0xae, 0xee, 0xec, 0xf9, 0x9c, 0xfb, 0x13, 0x92, 0xf8, 0x8d, 0xa2, 0x8b, 0xa6, 0xc3, 0xe6, 0xc9, + 0x56, 0xfd, 0x27, 0x03, 0xb2, 0xc3, 0x19, 0xfa, 0x10, 0xf2, 0x23, 0xee, 0xcd, 0x4d, 0xa3, 0x66, + 0x34, 0xb6, 0x1e, 0x9a, 0xd6, 0xeb, 0x79, 0x59, 0xc3, 0x59, 0x9b, 0x7b, 0x73, 0xac, 0x58, 0xe8, + 0x53, 0x28, 0x39, 0x91, 0x1c, 0xdb, 0x94, 0x5d, 0x70, 0x33, 0xab, 0x24, 0x95, 0x55, 0x49, 0x2b, + 0x92, 0xe3, 0x1e, 0xbb, 0xe0, 0xb8, 0xe8, 0xe8, 0x08, 0x55, 0x01, 0x04, 0xf5, 0x99, 0x23, 0xa3, + 0x90, 0x08, 0x33, 0x57, 0xcb, 0x35, 0xee, 0xe0, 0x1b, 0x48, 0xfd, 0x0f, 0x03, 0x36, 0x07, 0xd4, + 0x67, 0x47, 0xdc, 0x7d, 0x53, 0x29, 0xed, 0x41, 0xd1, 0x1d, 0x3b, 0x94, 0xd9, 0xd4, 0x33, 0x73, + 0x35, 0xa3, 0x51, 0xc2, 0x9b, 0x6a, 0xdd, 0xf3, 0xd0, 0x21, 0xdc, 0x73, 0x5c, 0x97, 0x47, 0x4c, + 0xda, 0x2c, 0x0a, 0x46, 0x24, 0x34, 0xf3, 0x35, 0xa3, 0x91, 0xc7, 0x77, 0x35, 0xda, 0x57, 0x20, + 0x7a, 0x1f, 0xca, 0x29, 0x4d, 0x90, 0xef, 0x22, 0xc2, 0x5c, 0x62, 0x6e, 0x28, 0xe2, 0x7d, 0x8d, + 0x0f, 0x34, 0x5c, 0xff, 0x25, 0x0b, 0x85, 0x24, 0x6d, 0xf4, 0x00, 0x8a, 0x01, 0x11, 0xc2, 0xf1, + 0x89, 0x30, 0x8d, 0x5a, 0xae, 0xb1, 0xf5, 0x70, 0xc7, 0x4a, 0xda, 0x64, 0xa5, 0x6d, 0xb2, 0x5a, + 0x6c, 0x8e, 0x17, 0x2c, 0x84, 0x20, 0x1f, 0x90, 0x20, 0xb9, 0x5d, 0x09, 0xab, 0x38, 0x4e, 0x51, + 0xd2, 0x80, 0xf0, 0x48, 0xda, 0x63, 0x42, 0xfd, 0xb1, 0x54, 0x77, 0xc8, 0xe1, 0xbb, 0x1a, 0x3d, + 0x51, 0x20, 0x6a, 0xc3, 0x36, 0x99, 0x49, 0xc2, 0x04, 0xe5, 0xcc, 0xe6, 0x53, 0x49, 0x39, 0x13, + 0xe6, 0x3f, 0x9b, 0x6b, 0x8e, 0x2d, 0x2f, 0xf8, 0xe7, 0x09, 0x1d, 0x3d, 0x87, 0x2a, 0xe3, 0xcc, + 0x76, 0x43, 0x2a, 0xa9, 0xeb, 0x4c, 0xec, 0x5b, 0x0c, 0xef, 0xaf, 0x31, 0xdc, 0x67, 0x9c, 0x75, + 0xb4, 0xb6, 0xfb, 0x9a, 0x77, 0x5d, 0x42, 0x31, 0x6d, 0x0d, 0x7a, 0x0c, 0x77, 0xe2, 0x89, 0x20, + 0xa1, 0xea, 0x65, 0x5a, 0x9c, 0xb7, 0x57, 0x9b, 0x39, 0x50, 0x2c, 0xd5, 0xce, 0x2d, 0xb1, 0x88, + 0x05, 0x7a, 0x0f, 0x72, 0x17, 0x84, 0xe8, 0x21, 0xd8, 0x5d, 0xd5, 0x1d, 0x13, 0x82, 0x63, 0x46, + 0xfd, 0x85, 0x01, 0xb0, 0x34, 0x41, 0x5f, 0x00, 0x4c, 0xa3, 0xd1, 0x84, 0xba, 0xf6, 0x25, 0x49, + 0xc7, 0xee, 0xe0, 0xa6, 0x3c, 0x79, 0x5f, 0xb1, 0xc5, 0x53, 0xc5, 0xfb, 0x8a, 0xcc, 0x71, 0x69, + 0x9a, 0x86, 0xf1, 0x08, 0x06, 0xdc, 0x23, 0xff, 0x33, 0x82, 0x67, 0xdc, 0x23, 0xc9, 0x08, 0x06, + 0x3a, 0xaa, 0xff, 0x96, 0x85, 0x62, 0x0a, 0xa3, 0xcf, 0xa1, 0x20, 0x28, 0xf3, 0x27, 0x44, 0x67, + 0xf0, 0xce, 0x7f, 0x5b, 0x58, 0x03, 0x45, 0x3c, 0xc9, 0x60, 0x2d, 0x41, 0x8f, 0x60, 0x23, 0x88, + 0x26, 0x92, 0xea, 0xe3, 0x6b, 0x6b, 0xb4, 0x67, 0x31, 0xef, 0x24, 0x83, 0x13, 0x41, 0xe5, 0x11, + 0x14, 0x12, 0x37, 0x64, 0x41, 0x3e, 0xce, 0x4c, 0x1d, 0x7f, 0xef, 0xb6, 0x1b, 0xc4, 0x25, 0x8b, + 0x6d, 0xb0, 0xe2, 0x55, 0x5e, 0x18, 0xb0, 0xa1, 0xcc, 0x50, 0x0b, 0x8a, 0x23, 0x2a, 0x9d, 0x30, + 0x74, 0xd2, 0xf2, 0x1d, 0xde, 0x5e, 0xbe, 0x0e, 0x0f, 0xa6, 0x8e, 0x2b, 0xdb, 0x54, 0xb6, 0x62, + 0x32, 0x5e, 0xc8, 0xd0, 0x67, 0x00, 0x8b, 0x1a, 0x0a, 0x33, 0xab, 0x5a, 0xbf, 0xae, 0x88, 0xa5, + 0xb4, 0x88, 0xa2, 0xbd, 0x01, 0x39, 0x11, 0x05, 0xf5, 0x1f, 0x0d, 0xc8, 0x1d, 0x13, 0x82, 0xbe, + 0x85, 0x82, 0x13, 0xc4, 0x8f, 0x4f, 0x0f, 0xd0, 0x5b, 0x37, 0x5d, 0x54, 0x0e, 0x94, 0xb5, 0x1f, + 0xbc, 0xfc, 0xf3, 0x20, 0xf3, 0xeb, 0x5f, 0x07, 0x0d, 0x9f, 0xca, 0x71, 0x34, 0xb2, 0x5c, 0x1e, + 0x34, 0x13, 0x9a, 0xfe, 0xf9, 0x48, 0x78, 0x97, 0xfa, 0xaf, 0x34, 0x16, 0x08, 0xac, 0x4d, 0xd1, + 0x3e, 0x94, 0x7c, 0x47, 0xd8, 0x13, 0x1a, 0x50, 0xa9, 0xaa, 0x9d, 0xc7, 0x45, 0xdf, 0x11, 0xa7, + 0xf1, 0xfa, 0x03, 0x01, 0xc5, 0xb4, 0x48, 0x68, 0x0f, 0x76, 0x07, 0xbd, 0x27, 0x7d, 0xfb, 0xec, + 0xfc, 0xa8, 0x6b, 0x3f, 0xeb, 0x0f, 0x9e, 0x76, 0x3b, 0xbd, 0xe3, 0x5e, 0xf7, 0xa8, 0x9c, 0x41, + 0x3b, 0x50, 0x5e, 0x6e, 0x1d, 0xf5, 0x70, 0xb7, 0x33, 0x2c, 0x1b, 0x68, 0x17, 0xb6, 0x97, 0xe8, + 0xb0, 0xfb, 0xf5, 0xf0, 0x59, 0xeb, 0xb4, 0x9c, 0x45, 0x07, 0xb0, 0xbf, 0x84, 0x4f, 0xbb, 0x4f, + 0x5a, 0x9d, 0x6f, 0xec, 0xd6, 0x59, 0xaf, 0x7f, 0x6e, 0x7f, 0x39, 0x38, 0xef, 0x97, 0x7f, 0x68, + 0x3f, 0x7e, 0x79, 0x55, 0x35, 0x5e, 0x5d, 0x55, 0x8d, 0xbf, 0xaf, 0xaa, 0xc6, 0xcf, 0xd7, 0xd5, + 0xcc, 0xab, 0xeb, 0x6a, 0xe6, 0xf7, 0xeb, 0x6a, 0xe6, 0xf9, 0xe1, 0xfa, 0xdb, 0xe9, 0x4f, 0xd2, + 0xa8, 0xa0, 0xde, 0xeb, 0x27, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x75, 0x71, 0xbd, 0xe5, 0xab, + 0x06, 0x00, 0x00, } func (m *Tx) Marshal() (dAtA []byte, err error) { @@ -2192,7 +2193,7 @@ func (m *SignerInfo) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.PublicKey == nil { - m.PublicKey = &types.Any{} + m.PublicKey = &types1.PublicKey{} } if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/types/tx/types.proto b/types/tx/types.proto index 4f9a468966ed..64c1d4e5228f 100644 --- a/types/tx/types.proto +++ b/types/tx/types.proto @@ -81,7 +81,7 @@ message AuthInfo { message SignerInfo { // public_key is the public key of the signer. It is optional for accounts // that already exist in state - google.protobuf.Any public_key = 1; + cosmos_sdk.crypto.v1.PublicKey public_key = 1; // mode_info describes the signing mode of the signer and is a nested // structure to support nested multisig pubkey's diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 0b17b05bc446..fbbfb170b86c 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -37,10 +37,15 @@ type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pub // SigVerifiableTx defines a Tx interface for all signature verification decorators type SigVerifiableTx interface { sdk.Tx + HasPubKeysTx GetSignatures() [][]byte + GetSignBytes(ctx sdk.Context, acc types.AccountI) []byte +} + +type HasPubKeysTx interface { + sdk.Tx GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignBytes(ctx sdk.Context, acc types.AccountI) []byte } // SetPubKeyDecorator sets PubKeys in context for any signer which does not already have pubkey set @@ -57,7 +62,7 @@ func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { } func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(SigVerifiableTx) + sigTx, ok := tx.(HasPubKeysTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index d48b4a62a418..980c9bab4179 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -6,17 +6,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/cosmos/cosmos-sdk/types/tx/raw" - "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + "github.com/cosmos/cosmos-sdk/x/auth" ) -type SignModeVerifier interface { - GetSignBytes(tx raw.DecodedTx) ([]byte, error) -} - type ProtoSigVerificationDecorator struct { ak AccountKeeper - signModeVerifiers map[types.SignMode]SignModeVerifier + signModeVerifiers map[types.SignMode]signing.SignModeHandler } func NewProtoSigVerificationDecorator(ak AccountKeeper) ProtoSigVerificationDecorator { @@ -30,7 +26,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, if ctx.IsReCheckTx() { return next(ctx, tx, simulate) } - sigTx, ok := tx.(raw.DecodedTx) + sigTx, ok := tx.(signing.DecodedTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -42,32 +38,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. signerAddrs := sigTx.GetSigners() - signerAccs := make([]exported.Account, len(signerAddrs)) - - for _, si := range sigTx.AuthInfo.SignerInfos { - switch mi := si.ModeInfo.Sum.(type) { - case *types.ModeInfo_Single_: - verifier, found := svd.signModeVerifiers[mi.Single.Mode] - if !found { - return ctx, fmt.Errorf("can't verify sign mode %s", mi.Single.Mode.String()) - } - bz, err := verifier.GetSignBytes(sigTx) - if err != nil { - return ctx, err - } - // retrieve pubkey - pubKey := signerAccs[i].GetPubKey() - if !simulate && pubKey == nil { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") - } - - // verify signature - if !simulate && !pubKey.VerifyBytes(signBytes, sig) { - return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") - } - case *types.ModeInfo_Multi_: - } - } + signerAccs := make([]auth.AccountI, len(signerAddrs)) // check that signer length and signature length are the same if len(sigs) != len(signerAddrs) { @@ -75,13 +46,45 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } for i, sig := range sigs { - signerAccs[i], err = GetSignerAcc(ctx, svd.ak, signerAddrs[i]) + var signBytes []byte + + signerAcc, err := GetSignerAcc(ctx, svd.ak, signerAddrs[i]) if err != nil { return ctx, err } - // retrieve signBytes of tx - signBytes := sigTx.GetSignBytes(ctx, signerAccs[i]) + signerAccs[i] = signerAcc + + signerInfo := sigTx.AuthInfo.SignerInfos[i] + + switch mi := signerInfo.ModeInfo.Sum.(type) { + case *types.ModeInfo_Single_: + single := mi.Single + verifier, found := svd.signModeVerifiers[single.Mode] + if !found { + return ctx, fmt.Errorf("can't verify sign mode %s", single.Mode.String()) + } + genesis := ctx.BlockHeight() == 0 + var accNum uint64 + if !genesis { + accNum = signerAcc.GetAccountNumber() + } + data := signing.SigningData{ + ModeInfo: single, + PublicKey: signerAcc.GetPubKey(), + ChainID: ctx.ChainID(), + AccountNumber: accNum, + AccountSequence: signerAcc.GetSequence(), + } + signBytes, err = verifier.GetSignBytes(data, sigTx) + if err != nil { + return ctx, err + } + case *types.ModeInfo_Multi_: + panic("TODO: can't handle multisignatures yet") + default: + panic("unexpected ModeInfo type") + } // retrieve pubkey pubKey := signerAccs[i].GetPubKey() From 75e9ad5b2c498b2ac47073d50edab00170353cf1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 14:40:12 -0400 Subject: [PATCH 12/54] WIP on multisigs --- crypto/types/codec.go | 36 ++ crypto/types/multisig/threshold_pubkey.go | 82 +++++ crypto/types/types.pb.go | 412 +++++++++++++++++++--- crypto/types/types.proto | 24 +- types/tx/signing/decoded_tx.go | 6 +- types/tx/types.pb.go | 111 +++--- 6 files changed, 565 insertions(+), 106 deletions(-) create mode 100644 crypto/types/codec.go diff --git a/crypto/types/codec.go b/crypto/types/codec.go new file mode 100644 index 000000000000..f71a823b99b4 --- /dev/null +++ b/crypto/types/codec.go @@ -0,0 +1,36 @@ +package types + +import ( + "fmt" + + "github.com/tendermint/tendermint/crypto" + ed255192 "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/tendermint/tendermint/crypto/sr25519" +) + +type PublicKeyCodec interface { + Decode(key *PublicKey) (crypto.PubKey, error) + Encode(key crypto.PubKey) (*PublicKey, error) +} + +type DefaultPublicKeyCodec struct{} + +var _ PublicKeyCodec = DefaultPublicKeyCodec{} + +func (DefaultPublicKeyCodec) Decode(key *PublicKey) (crypto.PubKey, error) { + panic("implement me") +} + +func (DefaultPublicKeyCodec) Encode(key crypto.PubKey) (*PublicKey, error) { + switch key := key.(type) { + case secp256k1.PubKeySecp256k1: + return &PublicKey{Sum: &PublicKey_Secp256K1{Secp256K1: key[:]}}, nil + case ed255192.PubKeyEd25519: + return &PublicKey{Sum: &PublicKey_Ed25519{Ed25519: key[:]}}, nil + case sr25519.PubKeySr25519: + return &PublicKey{Sum: &PublicKey_Sr25519{Sr25519: key[:]}}, nil + default: + return nil, fmt.Errorf("can't encode PubKey of type %T", key) + } +} diff --git a/crypto/types/multisig/threshold_pubkey.go b/crypto/types/multisig/threshold_pubkey.go index 3e0deb83b594..8ea64336c622 100644 --- a/crypto/types/multisig/threshold_pubkey.go +++ b/crypto/types/multisig/threshold_pubkey.go @@ -1,7 +1,12 @@ package multisig import ( + "fmt" + "github.com/tendermint/tendermint/crypto" + + "github.com/cosmos/cosmos-sdk/crypto/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) // PubKey implements a K of N threshold multisig. @@ -67,6 +72,83 @@ func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool { return true } +type DecodedMultisignature struct { + ModeInfo *txtypes.ModeInfo_Multi + Signatures [][]byte +} + +type GetSignBytesFunc func(single *txtypes.ModeInfo_Single) ([]byte, error) + +type MultisigPubKey interface { + VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool +} + +func DecodeMultisignatures(bz []byte) ([][]byte, error) { + multisig := types.MultiSignature{} + err := multisig.Unmarshal(bz) + if err != nil { + return nil, err + } + if len(multisig.XXX_unrecognized) > 0 { + return nil, fmt.Errorf("rejecting unrecognized fields found in MultiSignature") + } + return multisig.Sigs, nil +} + +func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool { + bitarray := sig.ModeInfo.Bitarray + sigs := sig.Signatures + size := bitarray.Size() + // ensure bit array is the correct size + if len(pk.PubKeys) != size { + return false + } + // ensure size of signature list + if len(sigs) < int(pk.K) || len(sigs) > size { + return false + } + // ensure at least k signatures are set + if bitarray.NumTrueBitsBefore(size) < int(pk.K) { + return false + } + // index in the list of signatures which we are concerned with. + sigIndex := 0 + for i := 0; i < size; i++ { + if bitarray.GetIndex(i) { + mi := sig.ModeInfo.ModeInfos[sigIndex] + switch mi := mi.Sum.(type) { + case *txtypes.ModeInfo_Single_: + msg, err := getSignBytes(mi.Single) + if err != nil { + return false + } + if !pk.PubKeys[i].VerifyBytes(msg, sigs[sigIndex]) { + return false + } + case *txtypes.ModeInfo_Multi_: + nestedMultisigPk, ok := pk.PubKeys[i].(MultisigPubKey) + if !ok { + return false + } + nestedSigs, err := DecodeMultisignatures(sigs[sigIndex]) + if err != nil { + return false + } + if !nestedMultisigPk.VerifyMultisignature(getSignBytes, DecodedMultisignature{ + ModeInfo: mi.Multi, + Signatures: nestedSigs, + }) { + return false + } + default: + return false + } + sigIndex++ + } + } + return true +} + // Bytes returns the amino encoded version of the PubKey func (pk PubKey) Bytes() []byte { return cdc.MustMarshalBinaryBare(pk) diff --git a/crypto/types/types.pb.go b/crypto/types/types.pb.go index 6887feafd90f..7833f8d708a4 100644 --- a/crypto/types/types.pb.go +++ b/crypto/types/types.pb.go @@ -34,6 +34,7 @@ type PublicKey struct { // *PublicKey_Sr25519 // *PublicKey_Multisig // *PublicKey_Secp256R1 + // *PublicKey_AminoMultisig // *PublicKey_AnyPubkey Sum isPublicKey_Sum `protobuf_oneof:"sum"` } @@ -92,16 +93,20 @@ type PublicKey_Multisig struct { type PublicKey_Secp256R1 struct { Secp256R1 []byte `protobuf:"bytes,5,opt,name=secp256r1,proto3,oneof" json:"secp256r1,omitempty"` } +type PublicKey_AminoMultisig struct { + AminoMultisig *LegacyAminoPubKeyMultisigThreshold `protobuf:"bytes,6,opt,name=amino_multisig,json=aminoMultisig,proto3,oneof" json:"amino_multisig,omitempty"` +} type PublicKey_AnyPubkey struct { AnyPubkey *types.Any `protobuf:"bytes,15,opt,name=any_pubkey,json=anyPubkey,proto3,oneof" json:"any_pubkey,omitempty"` } -func (*PublicKey_Secp256K1) isPublicKey_Sum() {} -func (*PublicKey_Ed25519) isPublicKey_Sum() {} -func (*PublicKey_Sr25519) isPublicKey_Sum() {} -func (*PublicKey_Multisig) isPublicKey_Sum() {} -func (*PublicKey_Secp256R1) isPublicKey_Sum() {} -func (*PublicKey_AnyPubkey) isPublicKey_Sum() {} +func (*PublicKey_Secp256K1) isPublicKey_Sum() {} +func (*PublicKey_Ed25519) isPublicKey_Sum() {} +func (*PublicKey_Sr25519) isPublicKey_Sum() {} +func (*PublicKey_Multisig) isPublicKey_Sum() {} +func (*PublicKey_Secp256R1) isPublicKey_Sum() {} +func (*PublicKey_AminoMultisig) isPublicKey_Sum() {} +func (*PublicKey_AnyPubkey) isPublicKey_Sum() {} func (m *PublicKey) GetSum() isPublicKey_Sum { if m != nil { @@ -145,6 +150,13 @@ func (m *PublicKey) GetSecp256R1() []byte { return nil } +func (m *PublicKey) GetAminoMultisig() *LegacyAminoPubKeyMultisigThreshold { + if x, ok := m.GetSum().(*PublicKey_AminoMultisig); ok { + return x.AminoMultisig + } + return nil +} + func (m *PublicKey) GetAnyPubkey() *types.Any { if x, ok := m.GetSum().(*PublicKey_AnyPubkey); ok { return x.AnyPubkey @@ -160,6 +172,7 @@ func (*PublicKey) XXX_OneofWrappers() []interface{} { (*PublicKey_Sr25519)(nil), (*PublicKey_Multisig)(nil), (*PublicKey_Secp256R1)(nil), + (*PublicKey_AminoMultisig)(nil), (*PublicKey_AnyPubkey)(nil), } } @@ -222,7 +235,8 @@ func (m *PubKeyMultisigThreshold) GetPubKeys() []*PublicKey { // See cosmos_sdk.tx.v1.ModeInfo.Multi for how to specify which signers signed // and with which modes type MultiSignature struct { - Sigs [][]byte `protobuf:"bytes,1,rep,name=sigs,proto3" json:"sigs,omitempty"` + Sigs [][]byte `protobuf:"bytes,1,rep,name=sigs,proto3" json:"sigs,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *MultiSignature) Reset() { *m = MultiSignature{} } @@ -320,49 +334,109 @@ func (m *CompactBitArray) GetElems() []byte { return nil } +// LegacyAminoPubKeyMultisigThreshold specifies a PubKeyMultisigThreshold that +// uses a legacy amino address which is passed along with the key. This type of +// key can only be used with existing accounts in state as the address is hard-coded +type LegacyAminoPubKeyMultisigThreshold struct { + Key *PubKeyMultisigThreshold `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Address []byte `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *LegacyAminoPubKeyMultisigThreshold) Reset() { *m = LegacyAminoPubKeyMultisigThreshold{} } +func (m *LegacyAminoPubKeyMultisigThreshold) String() string { return proto.CompactTextString(m) } +func (*LegacyAminoPubKeyMultisigThreshold) ProtoMessage() {} +func (*LegacyAminoPubKeyMultisigThreshold) Descriptor() ([]byte, []int) { + return fileDescriptor_2165b2a1badb1b0c, []int{4} +} +func (m *LegacyAminoPubKeyMultisigThreshold) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LegacyAminoPubKeyMultisigThreshold) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LegacyAminoPubKeyMultisigThreshold.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 *LegacyAminoPubKeyMultisigThreshold) XXX_Merge(src proto.Message) { + xxx_messageInfo_LegacyAminoPubKeyMultisigThreshold.Merge(m, src) +} +func (m *LegacyAminoPubKeyMultisigThreshold) XXX_Size() int { + return m.Size() +} +func (m *LegacyAminoPubKeyMultisigThreshold) XXX_DiscardUnknown() { + xxx_messageInfo_LegacyAminoPubKeyMultisigThreshold.DiscardUnknown(m) +} + +var xxx_messageInfo_LegacyAminoPubKeyMultisigThreshold proto.InternalMessageInfo + +func (m *LegacyAminoPubKeyMultisigThreshold) GetKey() *PubKeyMultisigThreshold { + if m != nil { + return m.Key + } + return nil +} + +func (m *LegacyAminoPubKeyMultisigThreshold) GetAddress() []byte { + if m != nil { + return m.Address + } + return nil +} + func init() { proto.RegisterType((*PublicKey)(nil), "cosmos_sdk.crypto.v1.PublicKey") proto.RegisterType((*PubKeyMultisigThreshold)(nil), "cosmos_sdk.crypto.v1.PubKeyMultisigThreshold") proto.RegisterType((*MultiSignature)(nil), "cosmos_sdk.crypto.v1.MultiSignature") proto.RegisterType((*CompactBitArray)(nil), "cosmos_sdk.crypto.v1.CompactBitArray") + proto.RegisterType((*LegacyAminoPubKeyMultisigThreshold)(nil), "cosmos_sdk.crypto.v1.LegacyAminoPubKeyMultisigThreshold") } func init() { proto.RegisterFile("crypto/types/types.proto", fileDescriptor_2165b2a1badb1b0c) } var fileDescriptor_2165b2a1badb1b0c = []byte{ - // 501 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xcd, 0x6a, 0xdb, 0x40, - 0x18, 0x94, 0xec, 0xb8, 0x8e, 0x37, 0x69, 0xdc, 0x2e, 0x86, 0x2a, 0x86, 0x4a, 0x46, 0x94, 0xe2, - 0x16, 0x22, 0x61, 0x17, 0xb7, 0x34, 0xb7, 0x28, 0x97, 0x80, 0x29, 0x18, 0xa5, 0x87, 0x52, 0x28, - 0x42, 0x3f, 0x5b, 0x79, 0xb1, 0xa4, 0x15, 0xbb, 0xab, 0xd2, 0x7d, 0x89, 0xd2, 0x63, 0x8f, 0xe9, - 0xbd, 0x0f, 0xd2, 0x63, 0x8e, 0x3d, 0x99, 0x22, 0xbf, 0x41, 0x9e, 0xa0, 0x44, 0x2b, 0xc5, 0xa1, - 0x24, 0x17, 0x69, 0xf7, 0x9b, 0xf9, 0x46, 0x33, 0xdf, 0x27, 0xa0, 0x85, 0x54, 0xe4, 0x9c, 0xd8, - 0x5c, 0xe4, 0x88, 0xc9, 0xa7, 0x95, 0x53, 0xc2, 0x09, 0x1c, 0x84, 0x84, 0xa5, 0x84, 0x79, 0x2c, - 0x5a, 0x59, 0x92, 0x64, 0x7d, 0x99, 0x0c, 0x9f, 0xf3, 0x25, 0xa6, 0x91, 0x97, 0xfb, 0x94, 0x0b, - 0xbb, 0x22, 0xda, 0x31, 0x89, 0xc9, 0xf6, 0x24, 0xbb, 0x87, 0x87, 0x31, 0x21, 0x71, 0x82, 0x24, - 0x25, 0x28, 0x3e, 0xdb, 0x7e, 0x26, 0x24, 0x64, 0x7e, 0x6b, 0x81, 0xde, 0xa2, 0x08, 0x12, 0x1c, - 0xce, 0x91, 0x80, 0x3a, 0xe8, 0x31, 0x14, 0xe6, 0xd3, 0xd9, 0xeb, 0xd5, 0x44, 0x53, 0x47, 0xea, - 0x78, 0xff, 0x4c, 0x71, 0xb7, 0x25, 0x38, 0x04, 0x5d, 0x14, 0x4d, 0x67, 0xb3, 0xc9, 0x5b, 0xad, - 0x55, 0xa3, 0x4d, 0xe1, 0x1a, 0x63, 0x54, 0x62, 0xed, 0x06, 0xab, 0x0b, 0x70, 0x0e, 0x76, 0xd3, - 0x22, 0xe1, 0x98, 0xe1, 0x58, 0xdb, 0x19, 0xa9, 0xe3, 0xbd, 0xe9, 0x91, 0x75, 0x57, 0x22, 0x6b, - 0x51, 0x04, 0x73, 0x24, 0xde, 0xd5, 0xdc, 0xf7, 0x4b, 0x8a, 0xd8, 0x92, 0x24, 0xd1, 0x99, 0xe2, - 0xde, 0x08, 0xdc, 0x32, 0x49, 0x27, 0x5a, 0xe7, 0x3f, 0x93, 0x74, 0x02, 0x67, 0x00, 0xf8, 0x99, - 0xf0, 0xf2, 0x22, 0x58, 0x21, 0xa1, 0xf5, 0xab, 0xcf, 0x0d, 0x2c, 0x39, 0x02, 0xab, 0x19, 0x81, - 0x75, 0x92, 0x89, 0xeb, 0x36, 0x3f, 0x13, 0x8b, 0x8a, 0xe8, 0x74, 0x40, 0x9b, 0x15, 0xa9, 0xf9, - 0x4b, 0x05, 0x4f, 0xee, 0x71, 0x01, 0xdf, 0x80, 0x1e, 0x6f, 0x2e, 0xd5, 0x78, 0x1e, 0x3a, 0x87, - 0xe5, 0xda, 0x50, 0xe7, 0x57, 0x6b, 0xe3, 0x91, 0xf0, 0xd3, 0xe4, 0xd8, 0xbc, 0xc1, 0x4d, 0x77, - 0xcb, 0x85, 0x1f, 0x40, 0x57, 0xda, 0x61, 0x5a, 0x6b, 0xd4, 0x1e, 0xef, 0x4d, 0x8d, 0x7b, 0xe3, - 0xcb, 0x4d, 0x38, 0x4f, 0xcb, 0xb5, 0xd1, 0x95, 0x3e, 0xd8, 0xd5, 0xda, 0x38, 0x90, 0xea, 0xb5, - 0x88, 0xe9, 0x36, 0x72, 0xe6, 0x33, 0x70, 0x50, 0xf9, 0x3c, 0xc7, 0x71, 0xe6, 0xf3, 0x82, 0x22, - 0x08, 0xc1, 0x0e, 0xc3, 0x31, 0xd3, 0xd4, 0x51, 0x7b, 0xbc, 0xef, 0x56, 0x67, 0xf3, 0x13, 0xe8, - 0x9f, 0x92, 0x34, 0xf7, 0x43, 0xee, 0x60, 0x7e, 0x42, 0xa9, 0x2f, 0xe0, 0x4b, 0xf0, 0x18, 0x7d, - 0xe5, 0xd4, 0xf7, 0x02, 0xcc, 0x99, 0xc7, 0x38, 0xa1, 0xa8, 0xce, 0xe4, 0xf6, 0x2b, 0xc0, 0xc1, - 0x9c, 0x9d, 0x57, 0x65, 0x38, 0x00, 0x1d, 0x94, 0xa0, 0x94, 0xc9, 0xa5, 0xbb, 0xf2, 0x72, 0xbc, - 0xfb, 0xe3, 0xc2, 0x50, 0x2e, 0x7e, 0x1a, 0x8a, 0x73, 0xfa, 0xbb, 0xd4, 0xd5, 0xcb, 0x52, 0x57, - 0xff, 0x96, 0xba, 0xfa, 0x7d, 0xa3, 0x2b, 0x97, 0x1b, 0x5d, 0xf9, 0xb3, 0xd1, 0x95, 0x8f, 0x2f, - 0x62, 0xcc, 0x97, 0x45, 0x60, 0x85, 0x24, 0xb5, 0x65, 0xe2, 0xfa, 0x75, 0xc4, 0xa2, 0x95, 0x7d, - 0xfb, 0x77, 0x0f, 0x1e, 0x54, 0xab, 0x79, 0xf5, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x1e, 0xd7, 0x43, - 0xb2, 0x05, 0x03, 0x00, 0x00, + // 571 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xcd, 0x6a, 0xdb, 0x4c, + 0x14, 0x95, 0xe2, 0x24, 0x4e, 0x26, 0x7f, 0xdf, 0x37, 0x04, 0xaa, 0x04, 0x2a, 0x19, 0x2d, 0x8a, + 0x1b, 0x88, 0x84, 0x5d, 0xdc, 0x9f, 0x6c, 0x4a, 0x94, 0x4d, 0xc0, 0x2d, 0x18, 0xa5, 0x8b, 0x52, + 0x28, 0x62, 0x24, 0x4d, 0x65, 0x61, 0x49, 0x23, 0x66, 0x46, 0xa5, 0xb3, 0xea, 0x2b, 0x74, 0xd9, + 0x65, 0xb2, 0xef, 0x83, 0x74, 0xe9, 0x65, 0x57, 0xa6, 0xd8, 0x4f, 0xd0, 0x3c, 0x41, 0xb1, 0x46, + 0xb2, 0x43, 0x89, 0x29, 0x74, 0x63, 0xcf, 0xdc, 0x73, 0xe6, 0x9c, 0x33, 0x73, 0xaf, 0x80, 0x16, + 0x50, 0x91, 0x73, 0x62, 0x73, 0x91, 0x63, 0x26, 0x7f, 0xad, 0x9c, 0x12, 0x4e, 0xe0, 0x61, 0x40, + 0x58, 0x4a, 0x98, 0xc7, 0xc2, 0x91, 0x25, 0x49, 0xd6, 0xc7, 0xce, 0xf1, 0x23, 0x3e, 0x8c, 0x69, + 0xe8, 0xe5, 0x88, 0x72, 0x61, 0x97, 0x44, 0x3b, 0x22, 0x11, 0x59, 0xae, 0xe4, 0xe9, 0xe3, 0xa3, + 0x88, 0x90, 0x28, 0xc1, 0x92, 0xe2, 0x17, 0x1f, 0x6c, 0x94, 0x09, 0x09, 0x99, 0xbf, 0xd6, 0xc0, + 0xf6, 0xa0, 0xf0, 0x93, 0x38, 0xe8, 0x63, 0x01, 0x75, 0xb0, 0xcd, 0x70, 0x90, 0x77, 0x7b, 0x4f, + 0x47, 0x1d, 0x4d, 0x6d, 0xa9, 0xed, 0xdd, 0x4b, 0xc5, 0x5d, 0x96, 0xe0, 0x31, 0x68, 0xe2, 0xb0, + 0xdb, 0xeb, 0x75, 0x5e, 0x68, 0x6b, 0x15, 0x5a, 0x17, 0xe6, 0x18, 0xa3, 0x12, 0x6b, 0xd4, 0x58, + 0x55, 0x80, 0x7d, 0xb0, 0x95, 0x16, 0x09, 0x8f, 0x59, 0x1c, 0x69, 0xeb, 0x2d, 0xb5, 0xbd, 0xd3, + 0x3d, 0xb5, 0xee, 0xbb, 0x91, 0x35, 0x28, 0xfc, 0x3e, 0x16, 0xaf, 0x2b, 0xee, 0x9b, 0x21, 0xc5, + 0x6c, 0x48, 0x92, 0xf0, 0x52, 0x71, 0x17, 0x02, 0x77, 0x42, 0xd2, 0x8e, 0xb6, 0xf1, 0x47, 0x48, + 0xda, 0x81, 0x08, 0xec, 0xa3, 0x34, 0xce, 0x88, 0xb7, 0xb0, 0xdc, 0x2c, 0x2d, 0x9f, 0xdf, 0x6f, + 0xf9, 0x0a, 0x47, 0x28, 0x10, 0xe7, 0xf3, 0x13, 0xab, 0xdd, 0xf7, 0x4a, 0xc5, 0x1a, 0x81, 0x3d, + 0x00, 0x50, 0x26, 0xbc, 0xbc, 0xf0, 0x47, 0x58, 0x68, 0x07, 0xa5, 0xfc, 0xa1, 0x25, 0x5f, 0xd9, + 0xaa, 0x5f, 0xd9, 0x3a, 0xcf, 0xc4, 0x3c, 0x19, 0xca, 0xc4, 0xa0, 0x24, 0x3a, 0x1b, 0xa0, 0xc1, + 0x8a, 0xd4, 0xfc, 0xa6, 0x82, 0x07, 0x2b, 0xac, 0xe0, 0x33, 0xb0, 0xcd, 0xeb, 0x4d, 0xd9, 0x81, + 0x3d, 0xe7, 0x68, 0x3a, 0x31, 0xd4, 0xfe, 0xed, 0xc4, 0xf8, 0x4f, 0xa0, 0x34, 0x39, 0x33, 0x17, + 0xb8, 0xe9, 0x2e, 0xb9, 0xf0, 0x2d, 0x68, 0xca, 0x38, 0x4c, 0x5b, 0x6b, 0x35, 0xda, 0x3b, 0x5d, + 0x63, 0xe5, 0x0b, 0xcb, 0x66, 0x3b, 0x0f, 0xa7, 0x13, 0xa3, 0x29, 0x73, 0xb0, 0xdb, 0x89, 0xb1, + 0x2f, 0xd5, 0x2b, 0x11, 0xd3, 0xad, 0xe5, 0xcc, 0x13, 0xb0, 0x5f, 0xe6, 0xbc, 0x8a, 0xa3, 0x0c, + 0xf1, 0x82, 0x62, 0x08, 0xc1, 0x3a, 0x8b, 0x23, 0xa6, 0xa9, 0xad, 0x46, 0x7b, 0xd7, 0x2d, 0xd7, + 0x67, 0xeb, 0xe3, 0x1b, 0x43, 0x35, 0xdf, 0x83, 0x83, 0x0b, 0x92, 0xe6, 0x28, 0xe0, 0x4e, 0xcc, + 0xcf, 0x29, 0x45, 0x02, 0x9e, 0x80, 0xff, 0xf1, 0x27, 0x4e, 0x91, 0xe7, 0xc7, 0x9c, 0x79, 0x8c, + 0x13, 0x8a, 0xab, 0x9b, 0xb9, 0x07, 0x25, 0xe0, 0xc4, 0x9c, 0x5d, 0x95, 0x65, 0x78, 0x08, 0x36, + 0x70, 0x82, 0x53, 0x26, 0xa7, 0xcb, 0x95, 0x9b, 0xb3, 0xad, 0xaf, 0xd7, 0x86, 0x72, 0x7d, 0x63, + 0x28, 0xe6, 0x67, 0x60, 0xfe, 0xbd, 0x5d, 0xf0, 0x25, 0x68, 0xcc, 0xdb, 0xa2, 0xfe, 0xc3, 0xa0, + 0xb9, 0xf3, 0x93, 0x50, 0x03, 0x4d, 0x14, 0x86, 0x14, 0xb3, 0x3a, 0x48, 0xbd, 0x75, 0x2e, 0xbe, + 0x4f, 0x75, 0x75, 0x3c, 0xd5, 0xd5, 0x9f, 0x53, 0x5d, 0xfd, 0x32, 0xd3, 0x95, 0xf1, 0x4c, 0x57, + 0x7e, 0xcc, 0x74, 0xe5, 0xdd, 0xe3, 0x28, 0xe6, 0xc3, 0xc2, 0xb7, 0x02, 0x92, 0xda, 0xd2, 0xb1, + 0xfa, 0x3b, 0x65, 0xe1, 0xc8, 0xbe, 0xfb, 0x61, 0xfb, 0x9b, 0xe5, 0x84, 0x3c, 0xf9, 0x1d, 0x00, + 0x00, 0xff, 0xff, 0x72, 0x3e, 0x39, 0x5c, 0xef, 0x03, 0x00, 0x00, } func (m *PublicKey) Marshal() (dAtA []byte, err error) { @@ -482,6 +556,27 @@ func (m *PublicKey_Secp256R1) MarshalToSizedBuffer(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } +func (m *PublicKey_AminoMultisig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_AminoMultisig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.AminoMultisig != nil { + { + size, err := m.AminoMultisig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + return len(dAtA) - i, nil +} func (m *PublicKey_AnyPubkey) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) @@ -565,6 +660,10 @@ func (m *MultiSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } if len(m.Sigs) > 0 { for iNdEx := len(m.Sigs) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Sigs[iNdEx]) @@ -612,6 +711,48 @@ func (m *CompactBitArray) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *LegacyAminoPubKeyMultisigThreshold) 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 *LegacyAminoPubKeyMultisigThreshold) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LegacyAminoPubKeyMultisigThreshold) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if m.Key != nil { + { + size, err := m.Key.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { offset -= sovTypes(v) base := offset @@ -695,6 +836,18 @@ func (m *PublicKey_Secp256R1) Size() (n int) { } return n } +func (m *PublicKey_AminoMultisig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.AminoMultisig != nil { + l = m.AminoMultisig.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} func (m *PublicKey_AnyPubkey) Size() (n int) { if m == nil { return 0 @@ -737,6 +890,26 @@ func (m *MultiSignature) Size() (n int) { n += 1 + l + sovTypes(uint64(l)) } } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *LegacyAminoPubKeyMultisigThreshold) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Key != nil { + l = m.Key.Size() + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } return n } @@ -942,6 +1115,41 @@ func (m *PublicKey) Unmarshal(dAtA []byte) error { copy(v, dAtA[iNdEx:postIndex]) m.Sum = &PublicKey_Secp256R1{v} iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AminoMultisig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &LegacyAminoPubKeyMultisigThreshold{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &PublicKey_AminoMultisig{v} + iNdEx = postIndex case 15: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AnyPubkey", wireType) @@ -1183,6 +1391,7 @@ func (m *MultiSignature) Unmarshal(dAtA []byte) error { if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -1298,6 +1507,129 @@ func (m *CompactBitArray) Unmarshal(dAtA []byte) error { } return nil } +func (m *LegacyAminoPubKeyMultisigThreshold) 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 ErrIntOverflowTypes + } + 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: LegacyAminoPubKeyMultisigThreshold: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LegacyAminoPubKeyMultisigThreshold: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Key == nil { + m.Key = &PubKeyMultisigThreshold{} + } + if err := m.Key.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTypes(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/crypto/types/types.proto b/crypto/types/types.proto index 2496ad8e30d6..2aeb36b8f854 100644 --- a/crypto/types/types.proto +++ b/crypto/types/types.proto @@ -10,11 +10,12 @@ option go_package = "github.com/cosmos/cosmos-sdk/crypto/types"; message PublicKey { // sum specifies which type of public key is wrapped oneof sum { - bytes secp256k1 = 1; - bytes ed25519 = 2; - bytes sr25519 = 3; - PubKeyMultisigThreshold multisig = 4; - bytes secp256r1 = 5; + bytes secp256k1 = 1; + bytes ed25519 = 2; + bytes sr25519 = 3; + PubKeyMultisigThreshold multisig = 4; + bytes secp256r1 = 5; + LegacyAminoPubKeyMultisigThreshold amino_multisig = 6; // any_pubkey can be used for any pubkey that an app may use which is // not explicitly defined in the oneof @@ -26,14 +27,15 @@ message PublicKey { // keys and a threshold message PubKeyMultisigThreshold { uint32 threshold = 1 [(gogoproto.customname) = "K", (gogoproto.moretags) = "yaml:\"threshold\""]; - repeated PublicKey pubkeys = 2 [(gogoproto.customname) = "PubKeys", (gogoproto.moretags) = "yaml:\"pubkeys\""]; + repeated PublicKey public_keys = 2 [(gogoproto.customname) = "PubKeys", (gogoproto.moretags) = "yaml:\"pubkeys\""]; } // MultiSignature wraps the signatures from a PubKeyMultisigThreshold. // See cosmos_sdk.tx.v1.ModeInfo.Multi for how to specify which signers signed // and with which modes message MultiSignature { - repeated bytes sigs = 1; + option (gogoproto.goproto_unrecognized) = true; + repeated bytes signatures = 1; } // CompactBitArray is an implementation of a space efficient bit array. @@ -47,3 +49,11 @@ message CompactBitArray { uint32 extra_bits_stored = 1; bytes elems = 2; } + +// LegacyAminoPubKeyMultisigThreshold specifies a PubKeyMultisigThreshold that +// uses a legacy amino address which is passed along with the key. This type of +// key can only be used with existing accounts in state as the address is hard-coded +message LegacyAminoPubKeyMultisigThreshold { + PubKeyMultisigThreshold key = 1; + bytes address = 2; +} diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index a0dbfb7c51f8..755dbab68219 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -29,9 +29,7 @@ var _ ante.FeeTx = DecodedTx{} var _ ante.TxWithMemo = DecodedTx{} var _ ante.HasPubKeysTx = DecodedTx{} -type PublicKeyDecoder func(key *cryptotypes.PublicKey) (crypto.PubKey, error) - -func DefaultTxDecoder(cdc codec.Marshaler, pubKeyDecoder PublicKeyDecoder) sdk.TxDecoder { +func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := cdc.UnmarshalBinaryBare(txBytes, &raw) @@ -70,7 +68,7 @@ func DefaultTxDecoder(cdc codec.Marshaler, pubKeyDecoder PublicKeyDecoder) sdk.T signerInfos := tx.AuthInfo.SignerInfos pubKeys := make([]crypto.PubKey, len(signerInfos)) for i, si := range signerInfos { - pubKey, err := pubKeyDecoder(si.PublicKey) + pubKey, err := keyCodec.Decode(si.PublicKey) if err != nil { return nil, errors.Wrap(err, "can't decode public key") } diff --git a/types/tx/types.pb.go b/types/tx/types.pb.go index 16e2ac453b56..e46ce5a7ff0d 100644 --- a/types/tx/types.pb.go +++ b/types/tx/types.pb.go @@ -365,7 +365,7 @@ func (m *AuthInfo) GetFee() *Fee { type SignerInfo struct { // public_key is the public key of the signer. It is optional for accounts // that already exist in state - PublicKey *types.Any `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + PublicKey *types1.PublicKey `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` // mode_info describes the signing mode of the signer and is a nested // structure to support nested multisig pubkey's ModeInfo *ModeInfo `protobuf:"bytes,2,opt,name=mode_info,json=modeInfo,proto3" json:"mode_info,omitempty"` @@ -404,7 +404,7 @@ func (m *SignerInfo) XXX_DiscardUnknown() { var xxx_messageInfo_SignerInfo proto.InternalMessageInfo -func (m *SignerInfo) GetPublicKey() *types.Any { +func (m *SignerInfo) GetPublicKey() *types1.PublicKey { if m != nil { return m.PublicKey } @@ -684,60 +684,61 @@ func init() { func init() { proto.RegisterFile("types/tx/types.proto", fileDescriptor_1c6ac8fa65877134) } var fileDescriptor_1c6ac8fa65877134 = []byte{ - // 842 bytes of a gzipped FileDescriptorProto + // 849 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x4d, 0x6f, 0xe3, 0x44, 0x18, 0x8e, 0x93, 0x34, 0x4d, 0xde, 0xee, 0x47, 0x3a, 0xb4, 0x92, 0x9b, 0xa2, 0x34, 0x44, 0x2a, - 0x04, 0x04, 0xce, 0xb2, 0x7b, 0x60, 0x11, 0x87, 0x55, 0x92, 0xa6, 0xdb, 0x40, 0x9b, 0xa2, 0x49, - 0x56, 0x82, 0x95, 0x90, 0xe5, 0xd8, 0x53, 0x67, 0xd4, 0x78, 0x26, 0x78, 0xc6, 0x28, 0xe1, 0x82, - 0x38, 0x70, 0xe2, 0xc2, 0x85, 0x3f, 0xc1, 0x2f, 0x59, 0x71, 0xda, 0x23, 0x17, 0x3e, 0xd4, 0xfe, - 0x10, 0x90, 0xc7, 0xe3, 0xa4, 0x6a, 0x4a, 0xb8, 0x71, 0xca, 0xeb, 0xc7, 0xcf, 0xf3, 0xcc, 0xfb, - 0x95, 0x31, 0xec, 0xc8, 0xf9, 0x94, 0x88, 0xa6, 0x9c, 0x35, 0x55, 0x60, 0x4d, 0x43, 0x2e, 0x39, - 0x2a, 0xbb, 0x5c, 0x04, 0x5c, 0xd8, 0xc2, 0xbb, 0xb4, 0xe4, 0xcc, 0xfa, 0xe6, 0xc3, 0xca, 0xdb, - 0x72, 0x4c, 0x43, 0xcf, 0x9e, 0x3a, 0xa1, 0x9c, 0x37, 0x15, 0xa9, 0xe9, 0x73, 0x9f, 0x2f, 0xa3, - 0x44, 0x59, 0x31, 0xdd, 0x70, 0x3e, 0x95, 0xbc, 0xa9, 0x6d, 0x97, 0x9e, 0x95, 0xed, 0x55, 0x68, - 0xcf, 0xe7, 0xdc, 0x9f, 0x90, 0xc4, 0x6f, 0x14, 0x5d, 0x34, 0x1d, 0x36, 0x4f, 0x5e, 0xd5, 0x7f, - 0x34, 0x20, 0x3b, 0x9c, 0xa1, 0xf7, 0x21, 0x3f, 0xe2, 0xde, 0xdc, 0x34, 0x6a, 0x46, 0x63, 0xeb, - 0xb1, 0x69, 0xdd, 0xce, 0xcb, 0x1a, 0xce, 0xda, 0xdc, 0x9b, 0x63, 0xc5, 0x42, 0x1f, 0x41, 0xc9, - 0x89, 0xe4, 0xd8, 0xa6, 0xec, 0x82, 0x9b, 0x59, 0x25, 0xa9, 0xac, 0x4a, 0x5a, 0x91, 0x1c, 0xf7, - 0xd8, 0x05, 0xc7, 0x45, 0x47, 0x47, 0xa8, 0x0a, 0x20, 0xa8, 0xcf, 0x1c, 0x19, 0x85, 0x44, 0x98, - 0xb9, 0x5a, 0xae, 0x71, 0x0f, 0xdf, 0x40, 0xea, 0xbf, 0x1b, 0xb0, 0x39, 0xa0, 0x3e, 0x3b, 0xe2, - 0xee, 0xff, 0x95, 0xd2, 0x1e, 0x14, 0xdd, 0xb1, 0x43, 0x99, 0x4d, 0x3d, 0x33, 0x57, 0x33, 0x1a, - 0x25, 0xbc, 0xa9, 0x9e, 0x7b, 0x1e, 0x3a, 0x84, 0x07, 0x8e, 0xeb, 0xf2, 0x88, 0x49, 0x9b, 0x45, - 0xc1, 0x88, 0x84, 0x66, 0xbe, 0x66, 0x34, 0xf2, 0xf8, 0xbe, 0x46, 0xfb, 0x0a, 0x44, 0xef, 0x42, - 0x39, 0xa5, 0x09, 0xf2, 0x75, 0x44, 0x98, 0x4b, 0xcc, 0x0d, 0x45, 0x7c, 0xa8, 0xf1, 0x81, 0x86, - 0xeb, 0x3f, 0x67, 0xa1, 0x90, 0xa4, 0x8d, 0x1e, 0x41, 0x31, 0x20, 0x42, 0x38, 0x3e, 0x11, 0xa6, - 0x51, 0xcb, 0x35, 0xb6, 0x1e, 0xef, 0x58, 0xc9, 0x98, 0xac, 0x74, 0x4c, 0x56, 0x8b, 0xcd, 0xf1, - 0x82, 0x85, 0x10, 0xe4, 0x03, 0x12, 0x24, 0xd5, 0x95, 0xb0, 0x8a, 0xe3, 0x14, 0x25, 0x0d, 0x08, - 0x8f, 0xa4, 0x3d, 0x26, 0xd4, 0x1f, 0x4b, 0x55, 0x43, 0x0e, 0xdf, 0xd7, 0xe8, 0x89, 0x02, 0x51, - 0x1b, 0xb6, 0xc9, 0x4c, 0x12, 0x26, 0x28, 0x67, 0x36, 0x9f, 0x4a, 0xca, 0x99, 0x30, 0xff, 0xde, - 0x5c, 0x73, 0x6c, 0x79, 0xc1, 0x3f, 0x4f, 0xe8, 0xe8, 0x25, 0x54, 0x19, 0x67, 0xb6, 0x1b, 0x52, - 0x49, 0x5d, 0x67, 0x62, 0xdf, 0x61, 0xf8, 0x70, 0x8d, 0xe1, 0x3e, 0xe3, 0xac, 0xa3, 0xb5, 0xdd, - 0x5b, 0xde, 0x75, 0x09, 0xc5, 0x74, 0x34, 0xe8, 0x19, 0xdc, 0x8b, 0x37, 0x82, 0x84, 0x6a, 0x96, - 0x69, 0x73, 0xde, 0x5c, 0x1d, 0xe6, 0x40, 0xb1, 0xd4, 0x38, 0xb7, 0xc4, 0x22, 0x16, 0xe8, 0x1d, - 0xc8, 0x5d, 0x10, 0xa2, 0x97, 0x60, 0x77, 0x55, 0x77, 0x4c, 0x08, 0x8e, 0x19, 0xf5, 0x6f, 0x01, - 0x96, 0x1e, 0xe8, 0x09, 0xc0, 0x34, 0x1a, 0x4d, 0xa8, 0x6b, 0x5f, 0x92, 0x74, 0xeb, 0xee, 0x2e, - 0xa5, 0x94, 0xf0, 0x3e, 0x23, 0x6a, 0xed, 0x02, 0xee, 0x91, 0xff, 0x58, 0xbb, 0x33, 0xee, 0x91, - 0x64, 0xed, 0x02, 0x1d, 0xd5, 0x7f, 0xcd, 0x42, 0x31, 0x85, 0xd1, 0x27, 0x50, 0x10, 0x94, 0xf9, - 0x13, 0xa2, 0x8f, 0x7d, 0xeb, 0xdf, 0x2d, 0xac, 0x81, 0x22, 0x9e, 0x64, 0xb0, 0x96, 0xa0, 0xa7, - 0xb0, 0x11, 0x44, 0x13, 0x49, 0xf5, 0xf1, 0xb5, 0x35, 0xda, 0xb3, 0x98, 0x77, 0x92, 0xc1, 0x89, - 0xa0, 0xf2, 0x14, 0x0a, 0x89, 0x1b, 0xb2, 0x20, 0x1f, 0x67, 0xa6, 0x8e, 0x7f, 0x70, 0x57, 0x05, - 0x71, 0x9f, 0x62, 0x1b, 0xac, 0x78, 0x95, 0x1f, 0x0c, 0xd8, 0x50, 0x66, 0xa8, 0x05, 0xc5, 0x11, - 0x95, 0x4e, 0x18, 0x3a, 0x69, 0xcf, 0x0e, 0x6f, 0xaa, 0x93, 0x5b, 0x2a, 0x76, 0xe8, 0xf0, 0x60, - 0xea, 0xb8, 0xb2, 0x4d, 0x65, 0x2b, 0x26, 0xe3, 0x85, 0x0c, 0x7d, 0x0c, 0xb0, 0xe8, 0xa1, 0x30, - 0xb3, 0x6a, 0xdc, 0xeb, 0x9a, 0x58, 0x4a, 0x9b, 0x28, 0xda, 0x1b, 0x90, 0x13, 0x51, 0x50, 0xff, - 0xde, 0x80, 0xdc, 0x31, 0x21, 0xe8, 0x2b, 0x28, 0x38, 0x41, 0xfc, 0x87, 0xd3, 0x4b, 0xf3, 0xc6, - 0x4d, 0x17, 0x95, 0x03, 0x65, 0xed, 0x47, 0xaf, 0xfe, 0x38, 0xc8, 0xfc, 0xf2, 0xe7, 0x41, 0xc3, - 0xa7, 0x72, 0x1c, 0x8d, 0x2c, 0x97, 0x07, 0xcd, 0x84, 0xa6, 0x7f, 0x3e, 0x10, 0xde, 0xa5, 0xbe, - 0x3e, 0x63, 0x81, 0xc0, 0xda, 0x14, 0xed, 0x43, 0xc9, 0x77, 0x84, 0x3d, 0xa1, 0x01, 0x95, 0xaa, - 0xdb, 0x79, 0x5c, 0xf4, 0x1d, 0x71, 0x1a, 0x3f, 0xbf, 0x27, 0xa0, 0x98, 0x36, 0x09, 0xed, 0xc1, - 0xee, 0xa0, 0xf7, 0xbc, 0x6f, 0x9f, 0x9d, 0x1f, 0x75, 0xed, 0x17, 0xfd, 0xc1, 0xe7, 0xdd, 0x4e, - 0xef, 0xb8, 0xd7, 0x3d, 0x2a, 0x67, 0xd0, 0x0e, 0x94, 0x97, 0xaf, 0x8e, 0x7a, 0xb8, 0xdb, 0x19, - 0x96, 0x0d, 0xb4, 0x0b, 0xdb, 0x4b, 0x74, 0xd8, 0xfd, 0x62, 0xf8, 0xa2, 0x75, 0x5a, 0xce, 0xa2, - 0x03, 0xd8, 0x5f, 0xc2, 0xa7, 0xdd, 0xe7, 0xad, 0xce, 0x97, 0x76, 0xeb, 0xac, 0xd7, 0x3f, 0xb7, - 0x3f, 0x1d, 0x9c, 0xf7, 0xcb, 0xdf, 0xb5, 0x9f, 0xbd, 0xba, 0xaa, 0x1a, 0xaf, 0xaf, 0xaa, 0xc6, - 0x5f, 0x57, 0x55, 0xe3, 0xa7, 0xeb, 0x6a, 0xe6, 0xf5, 0x75, 0x35, 0xf3, 0xdb, 0x75, 0x35, 0xf3, - 0xf2, 0x70, 0x7d, 0x75, 0xfa, 0x33, 0x34, 0x2a, 0xa8, 0xc5, 0x7e, 0xf2, 0x4f, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x28, 0x03, 0x76, 0x89, 0x9f, 0x06, 0x00, 0x00, + 0x04, 0x04, 0xce, 0xb2, 0x1c, 0x58, 0x84, 0xc4, 0x2a, 0x49, 0xd3, 0x6d, 0xa0, 0x4d, 0x57, 0x93, + 0xac, 0x04, 0x2b, 0x21, 0xcb, 0xb1, 0xa7, 0xce, 0xa8, 0xf1, 0x4c, 0xf0, 0x8c, 0x51, 0x72, 0x42, + 0x1c, 0xf6, 0xc4, 0x85, 0x0b, 0x7f, 0x82, 0x5f, 0xb2, 0xe2, 0xb4, 0x47, 0x2e, 0x7c, 0xa8, 0xfd, + 0x21, 0x20, 0x8f, 0xc7, 0x49, 0xb5, 0x29, 0xe1, 0xb6, 0xa7, 0xbc, 0x7e, 0xfc, 0x3c, 0xcf, 0xbc, + 0x5f, 0x13, 0xc3, 0x8e, 0x9c, 0x4f, 0x89, 0x68, 0xca, 0x59, 0x53, 0x05, 0xd6, 0x34, 0xe4, 0x92, + 0xa3, 0xb2, 0xcb, 0x45, 0xc0, 0x85, 0x2d, 0xbc, 0x4b, 0x4b, 0xce, 0xac, 0xef, 0x3f, 0xae, 0xbc, + 0x2b, 0xc7, 0x34, 0xf4, 0xec, 0xa9, 0x13, 0xca, 0x79, 0x53, 0x91, 0x9a, 0x3e, 0xf7, 0xf9, 0x32, + 0x4a, 0x94, 0x15, 0xd3, 0x0d, 0xe7, 0x53, 0xc9, 0x9b, 0xda, 0x76, 0xe9, 0x59, 0xd9, 0x5e, 0x85, + 0xf6, 0x7c, 0xce, 0xfd, 0x09, 0x49, 0xfc, 0x46, 0xd1, 0x45, 0xd3, 0x61, 0xf3, 0xe4, 0x55, 0xfd, + 0x27, 0x03, 0xb2, 0xc3, 0x19, 0xfa, 0x10, 0xf2, 0x23, 0xee, 0xcd, 0x4d, 0xa3, 0x66, 0x34, 0xb6, + 0x1e, 0x9a, 0xd6, 0xeb, 0x79, 0x59, 0xc3, 0x59, 0x9b, 0x7b, 0x73, 0xac, 0x58, 0xe8, 0x53, 0x28, + 0x39, 0x91, 0x1c, 0xdb, 0x94, 0x5d, 0x70, 0x33, 0xab, 0x24, 0x95, 0x55, 0x49, 0x2b, 0x92, 0xe3, + 0x1e, 0xbb, 0xe0, 0xb8, 0xe8, 0xe8, 0x08, 0x55, 0x01, 0x04, 0xf5, 0x99, 0x23, 0xa3, 0x90, 0x08, + 0x33, 0x57, 0xcb, 0x35, 0xee, 0xe0, 0x1b, 0x48, 0xfd, 0x0f, 0x03, 0x36, 0x07, 0xd4, 0x67, 0x47, + 0xdc, 0x7d, 0x53, 0x29, 0xed, 0x41, 0xd1, 0x1d, 0x3b, 0x94, 0xd9, 0xd4, 0x33, 0x73, 0x35, 0xa3, + 0x51, 0xc2, 0x9b, 0xea, 0xb9, 0xe7, 0xa1, 0x43, 0xb8, 0xe7, 0xb8, 0x2e, 0x8f, 0x98, 0xb4, 0x59, + 0x14, 0x8c, 0x48, 0x68, 0xe6, 0x6b, 0x46, 0x23, 0x8f, 0xef, 0x6a, 0xb4, 0xaf, 0x40, 0xf4, 0x3e, + 0x94, 0x53, 0x9a, 0x20, 0xdf, 0x45, 0x84, 0xb9, 0xc4, 0xdc, 0x50, 0xc4, 0xfb, 0x1a, 0x1f, 0x68, + 0xb8, 0xfe, 0x4b, 0x16, 0x0a, 0x49, 0xda, 0xe8, 0x01, 0x14, 0x03, 0x22, 0x84, 0xe3, 0x13, 0x61, + 0x1a, 0xb5, 0x5c, 0x63, 0xeb, 0xe1, 0x8e, 0x95, 0x8c, 0xc9, 0x4a, 0xc7, 0x64, 0xb5, 0xd8, 0x1c, + 0x2f, 0x58, 0x08, 0x41, 0x3e, 0x20, 0x41, 0x52, 0x5d, 0x09, 0xab, 0x38, 0x4e, 0x51, 0xd2, 0x80, + 0xf0, 0x48, 0xda, 0x63, 0x42, 0xfd, 0xb1, 0x54, 0x35, 0xe4, 0xf0, 0x5d, 0x8d, 0x9e, 0x28, 0x10, + 0xb5, 0x61, 0x9b, 0xcc, 0x24, 0x61, 0x82, 0x72, 0x66, 0xf3, 0xa9, 0xa4, 0x9c, 0x09, 0xf3, 0x9f, + 0xcd, 0x35, 0xc7, 0x96, 0x17, 0xfc, 0xf3, 0x84, 0x8e, 0x9e, 0x43, 0x95, 0x71, 0x66, 0xbb, 0x21, + 0x95, 0xd4, 0x75, 0x26, 0xf6, 0x2d, 0x86, 0xf7, 0xd7, 0x18, 0xee, 0x33, 0xce, 0x3a, 0x5a, 0xdb, + 0x7d, 0xcd, 0xbb, 0x2e, 0xa1, 0x98, 0x8e, 0x06, 0x3d, 0x86, 0x3b, 0xf1, 0x46, 0x90, 0x50, 0xcd, + 0x32, 0x6d, 0xce, 0xdb, 0xab, 0xc3, 0x1c, 0x28, 0x96, 0x1a, 0xe7, 0x96, 0x58, 0xc4, 0x02, 0xbd, + 0x07, 0xb9, 0x0b, 0x42, 0xf4, 0x12, 0xec, 0xae, 0xea, 0x8e, 0x09, 0xc1, 0x31, 0xa3, 0xfe, 0xc2, + 0x00, 0x58, 0x9a, 0xa0, 0x2f, 0x00, 0xa6, 0xd1, 0x68, 0x42, 0x5d, 0xfb, 0x92, 0xa4, 0x6b, 0x77, + 0x70, 0x53, 0x9e, 0x5c, 0xb9, 0xd8, 0xe2, 0xa9, 0xe2, 0x7d, 0x45, 0xe6, 0xb8, 0x34, 0x4d, 0xc3, + 0x78, 0x05, 0x03, 0xee, 0x91, 0xff, 0x59, 0xc1, 0x33, 0xee, 0x91, 0x64, 0x05, 0x03, 0x1d, 0xd5, + 0x7f, 0xcb, 0x42, 0x31, 0x85, 0xd1, 0xe7, 0x50, 0x10, 0x94, 0xf9, 0x13, 0xa2, 0x33, 0x78, 0xe7, + 0xbf, 0x2d, 0xac, 0x81, 0x22, 0x9e, 0x64, 0xb0, 0x96, 0xa0, 0x47, 0xb0, 0x11, 0x44, 0x13, 0x49, + 0xf5, 0xf1, 0xb5, 0x35, 0xda, 0xb3, 0x98, 0x77, 0x92, 0xc1, 0x89, 0xa0, 0xf2, 0x08, 0x0a, 0x89, + 0x1b, 0xb2, 0x20, 0x1f, 0x67, 0xa6, 0x8e, 0xbf, 0x77, 0x5b, 0x05, 0x71, 0xcb, 0x62, 0x1b, 0xac, + 0x78, 0x95, 0x17, 0x06, 0x6c, 0x28, 0x33, 0xd4, 0x82, 0xe2, 0x88, 0x4a, 0x27, 0x0c, 0x9d, 0xb4, + 0x7d, 0x87, 0xb7, 0xb7, 0xaf, 0xc3, 0x83, 0xa9, 0xe3, 0xca, 0x36, 0x95, 0xad, 0x98, 0x8c, 0x17, + 0x32, 0xf4, 0x19, 0xc0, 0xa2, 0x87, 0xc2, 0xcc, 0xaa, 0xd1, 0xaf, 0x6b, 0x62, 0x29, 0x6d, 0xa2, + 0x68, 0x6f, 0x40, 0x4e, 0x44, 0x41, 0xfd, 0x47, 0x03, 0x72, 0xc7, 0x84, 0xa0, 0x6f, 0xa1, 0xe0, + 0x04, 0xf1, 0xe5, 0xd3, 0x0b, 0xf4, 0xd6, 0x4d, 0x17, 0x95, 0x03, 0x65, 0xed, 0x07, 0x2f, 0xff, + 0x3c, 0xc8, 0xfc, 0xfa, 0xd7, 0x41, 0xc3, 0xa7, 0x72, 0x1c, 0x8d, 0x2c, 0x97, 0x07, 0xcd, 0x84, + 0xa6, 0x7f, 0x3e, 0x12, 0xde, 0xa5, 0xfe, 0x2b, 0x8d, 0x05, 0x02, 0x6b, 0x53, 0xb4, 0x0f, 0x25, + 0xdf, 0x11, 0xf6, 0x84, 0x06, 0x54, 0xaa, 0x6e, 0xe7, 0x71, 0xd1, 0x77, 0xc4, 0x69, 0xfc, 0xfc, + 0x81, 0x80, 0x62, 0xda, 0x24, 0xb4, 0x07, 0xbb, 0x83, 0xde, 0x93, 0xbe, 0x7d, 0x76, 0x7e, 0xd4, + 0xb5, 0x9f, 0xf5, 0x07, 0x4f, 0xbb, 0x9d, 0xde, 0x71, 0xaf, 0x7b, 0x54, 0xce, 0xa0, 0x1d, 0x28, + 0x2f, 0x5f, 0x1d, 0xf5, 0x70, 0xb7, 0x33, 0x2c, 0x1b, 0x68, 0x17, 0xb6, 0x97, 0xe8, 0xb0, 0xfb, + 0xf5, 0xf0, 0x59, 0xeb, 0xb4, 0x9c, 0x45, 0x07, 0xb0, 0xbf, 0x84, 0x4f, 0xbb, 0x4f, 0x5a, 0x9d, + 0x6f, 0xec, 0xd6, 0x59, 0xaf, 0x7f, 0x6e, 0x7f, 0x39, 0x38, 0xef, 0x97, 0x7f, 0x68, 0x3f, 0x7e, + 0x79, 0x55, 0x35, 0x5e, 0x5d, 0x55, 0x8d, 0xbf, 0xaf, 0xaa, 0xc6, 0xcf, 0xd7, 0xd5, 0xcc, 0xab, + 0xeb, 0x6a, 0xe6, 0xf7, 0xeb, 0x6a, 0xe6, 0xf9, 0xe1, 0xfa, 0xea, 0xf4, 0x27, 0x69, 0x54, 0x50, + 0xf7, 0xf5, 0x93, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x86, 0x44, 0xd6, 0x71, 0xab, 0x06, 0x00, + 0x00, } func (m *Tx) Marshal() (dAtA []byte, err error) { @@ -2192,7 +2193,7 @@ func (m *SignerInfo) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.PublicKey == nil { - m.PublicKey = &types.Any{} + m.PublicKey = &types1.PublicKey{} } if err := m.PublicKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err From 33a9ff080e766ff7704d2934524e1a01093c6883 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 15:09:19 -0400 Subject: [PATCH 13/54] WIP on keys, simapp --- crypto/types/codec.go | 36 --------- crypto/types/codec/codec.go | 90 +++++++++++++++++++++++ crypto/types/multisig/threshold_pubkey.go | 4 +- simapp/amino.go | 27 +++++++ simapp/app.go | 22 +----- simapp/cmd/simcli/main.go | 2 +- simapp/cmd/simd/main.go | 2 +- simapp/proto.go | 39 ++++++++++ std/codec.go | 16 ---- types/tx/signing/decoded_tx.go | 4 +- x/auth/ante/ante.go | 2 +- x/auth/simulation/decoder_test.go | 2 +- x/auth/types/common_test.go | 4 +- x/auth/vesting/types/common_test.go | 4 +- x/bank/keeper/keeper_test.go | 2 +- x/capability/simulation/decoder_test.go | 2 +- x/distribution/simulation/decoder_test.go | 2 +- x/gov/keeper/common_test.go | 2 +- x/gov/simulation/decoder_test.go | 2 +- x/mint/simulation/decoder_test.go | 2 +- x/slashing/simulation/decoder_test.go | 2 +- x/staking/simulation/decoder_test.go | 2 +- 22 files changed, 179 insertions(+), 91 deletions(-) delete mode 100644 crypto/types/codec.go create mode 100644 crypto/types/codec/codec.go create mode 100644 simapp/amino.go create mode 100644 simapp/proto.go diff --git a/crypto/types/codec.go b/crypto/types/codec.go deleted file mode 100644 index f71a823b99b4..000000000000 --- a/crypto/types/codec.go +++ /dev/null @@ -1,36 +0,0 @@ -package types - -import ( - "fmt" - - "github.com/tendermint/tendermint/crypto" - ed255192 "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/tendermint/tendermint/crypto/sr25519" -) - -type PublicKeyCodec interface { - Decode(key *PublicKey) (crypto.PubKey, error) - Encode(key crypto.PubKey) (*PublicKey, error) -} - -type DefaultPublicKeyCodec struct{} - -var _ PublicKeyCodec = DefaultPublicKeyCodec{} - -func (DefaultPublicKeyCodec) Decode(key *PublicKey) (crypto.PubKey, error) { - panic("implement me") -} - -func (DefaultPublicKeyCodec) Encode(key crypto.PubKey) (*PublicKey, error) { - switch key := key.(type) { - case secp256k1.PubKeySecp256k1: - return &PublicKey{Sum: &PublicKey_Secp256K1{Secp256K1: key[:]}}, nil - case ed255192.PubKeyEd25519: - return &PublicKey{Sum: &PublicKey_Ed25519{Ed25519: key[:]}}, nil - case sr25519.PubKeySr25519: - return &PublicKey{Sum: &PublicKey_Sr25519{Sr25519: key[:]}}, nil - default: - return nil, fmt.Errorf("can't encode PubKey of type %T", key) - } -} diff --git a/crypto/types/codec/codec.go b/crypto/types/codec/codec.go new file mode 100644 index 000000000000..363d7e812fb2 --- /dev/null +++ b/crypto/types/codec/codec.go @@ -0,0 +1,90 @@ +package codec + +import ( + "fmt" + "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + + "github.com/tendermint/tendermint/crypto" + ed255192 "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/tendermint/tendermint/crypto/sr25519" +) + +type PublicKeyCodec interface { + Decode(key *types.PublicKey) (crypto.PubKey, error) + Encode(key crypto.PubKey) (*types.PublicKey, error) +} + +type DefaultPublicKeyCodec struct{} + +var _ PublicKeyCodec = DefaultPublicKeyCodec{} + +func (cdc DefaultPublicKeyCodec) Decode(key *types.PublicKey) (crypto.PubKey, error) { + switch key := key.Sum.(type) { + case *types.PublicKey_Secp256K1: + n := len(key.Secp256K1) + if n != secp256k1.PubKeySecp256k1Size { + return nil, fmt.Errorf("wrong length %d for secp256k1 public key", n) + } + var res secp256k1.PubKeySecp256k1 + copy(res[:], key.Secp256K1) + return res, nil + case *types.PublicKey_Ed25519: + n := len(key.Ed25519) + if n != ed255192.PubKeyEd25519Size { + return nil, fmt.Errorf("wrong length %d for ed25519 public key", n) + } + var res ed255192.PubKeyEd25519 + copy(res[:], key.Ed25519) + return res, nil + case *types.PublicKey_Sr25519: + n := len(key.Sr25519) + if n != sr25519.PubKeySr25519Size { + return nil, fmt.Errorf("wrong length %d for sr25519 public key", n) + } + var res sr25519.PubKeySr25519 + copy(res[:], key.Sr25519) + return res, nil + case *types.PublicKey_Multisig: + pubKeys := key.Multisig.PubKeys + resKeys := make([]crypto.PubKey, len(pubKeys)) + for i, k := range pubKeys { + dk, err := cdc.Decode(k) + if err != nil { + return nil, err + } + resKeys[i] = dk + } + return multisig.NewPubKeyMultisigThreshold(key.Multisig.K, resKeys), nil + default: + return nil, fmt.Errorf("can't encode PubKey of type %T", key) + } +} + +func (cdc DefaultPublicKeyCodec) Encode(key crypto.PubKey) (*types.PublicKey, error) { + switch key := key.(type) { + case secp256k1.PubKeySecp256k1: + return &types.PublicKey{Sum: &types.PublicKey_Secp256K1{Secp256K1: key[:]}}, nil + case ed255192.PubKeyEd25519: + return &types.PublicKey{Sum: &types.PublicKey_Ed25519{Ed25519: key[:]}}, nil + case sr25519.PubKeySr25519: + return &types.PublicKey{Sum: &types.PublicKey_Sr25519{Sr25519: key[:]}}, nil + case multisig.PubKey: + pubKeys := key.PubKeys + resKeys := make([]*types.PublicKey, len(pubKeys)) + for i, k := range pubKeys { + dk, err := cdc.Encode(k) + if err != nil { + return nil, err + } + resKeys[i] = dk + } + return &types.PublicKey{Sum: &types.PublicKey_Multisig{Multisig: &types.PubKeyMultisigThreshold{ + K: key.K, + PubKeys: resKeys, + }}}, nil + default: + return nil, fmt.Errorf("can't encode PubKey of type %T", key) + } +} diff --git a/crypto/types/multisig/threshold_pubkey.go b/crypto/types/multisig/threshold_pubkey.go index 8ea64336c622..75de9cc9f402 100644 --- a/crypto/types/multisig/threshold_pubkey.go +++ b/crypto/types/multisig/threshold_pubkey.go @@ -11,7 +11,7 @@ import ( // PubKey implements a K of N threshold multisig. type PubKey struct { - K uint `json:"threshold"` + K uint32 `json:"threshold"` PubKeys []crypto.PubKey `json:"pubkeys"` } @@ -19,7 +19,7 @@ var _ crypto.PubKey = PubKey{} // NewPubKeyMultisigThreshold returns a new PubKeyMultisigThreshold. // Panics if len(pubkeys) < k or 0 >= k. -func NewPubKeyMultisigThreshold(k int, pubkeys []crypto.PubKey) crypto.PubKey { +func NewPubKeyMultisigThreshold(k uint32, pubkeys []crypto.PubKey) crypto.PubKey { if k <= 0 { panic("threshold k of n multisignature: k <= 0") } diff --git a/simapp/amino.go b/simapp/amino.go new file mode 100644 index 000000000000..918fd4e66e23 --- /dev/null +++ b/simapp/amino.go @@ -0,0 +1,27 @@ +// +build amino_test + +package simapp + +import "github.com/cosmos/cosmos-sdk/codec" + +func SimappTxDecoder() types.TxDecoder { + return auth.DefaultTxDecoder(cdc) +} + +// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by +// simapp. It is useful for tests and clients who do not want to construct the +// full simapp +func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { + cdc := std.MakeCodec(ModuleBasics) + interfaceRegistry := codectypes.NewInterfaceRegistry() + std.RegisterInterfaces(interfaceRegistry) + ModuleBasics.RegisterInterfaceModules(interfaceRegistry) + appCodec := codec.NewAminoCodec(cdc) + return appCodec, nil, cdc +} + +func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { + return ante.NewAnteHandler( + ak, bk, ibcK, ante.DefaultSigVerificationGasConsumer, + ) +} diff --git a/simapp/app.go b/simapp/app.go index e13a361b8af4..02c38cf06081 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -4,8 +4,6 @@ import ( "io" "os" - "github.com/cosmos/cosmos-sdk/codec/types" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" @@ -143,9 +141,9 @@ func NewSimApp( ) *SimApp { // TODO: Remove cdc in favor of appCodec once all modules are migrated. - appCodec, cdc := MakeCodecs() + appCodec, _, cdc := MakeCodecs() - bApp := baseapp.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, SimappTxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) @@ -335,9 +333,7 @@ func NewSimApp( app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) app.SetAnteHandler( - ante.NewAnteHandler( - app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer, - ), + NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper), ) app.SetEndBlocker(app.EndBlocker) @@ -361,18 +357,6 @@ func NewSimApp( return app } -// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by -// simapp. It is useful for tests and clients who do not want to construct the -// full simapp -func MakeCodecs() (*std.Codec, *codec.Codec) { - cdc := std.MakeCodec(ModuleBasics) - interfaceRegistry := types.NewInterfaceRegistry() - std.RegisterInterfaces(interfaceRegistry) - ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - appCodec := std.NewAppCodec(cdc, interfaceRegistry) - return appCodec, cdc -} - // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index d2207f31dd74..722bc7f1f28f 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -25,7 +25,7 @@ import ( ) var ( - appCodec, cdc = simapp.MakeCodecs() + appCodec, _, cdc = simapp.MakeCodecs() ) func init() { diff --git a/simapp/cmd/simd/main.go b/simapp/cmd/simd/main.go index 7078a453885b..5e0787070988 100644 --- a/simapp/cmd/simd/main.go +++ b/simapp/cmd/simd/main.go @@ -29,7 +29,7 @@ const flagInvCheckPeriod = "inv-check-period" var invCheckPeriod uint func main() { - appCodec, cdc := simapp.MakeCodecs() + appCodec, _, cdc := simapp.MakeCodecs() config := sdk.GetConfig() config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub) diff --git a/simapp/proto.go b/simapp/proto.go new file mode 100644 index 000000000000..dbdfa257a7e1 --- /dev/null +++ b/simapp/proto.go @@ -0,0 +1,39 @@ +// +build !amino_test + +package simapp + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/types/codec" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/ibc" +) + +func SimappTxDecoder() types.TxDecoder { + cdc, _, _ := MakeCodecs() + return signing.DefaultTxDecoder(cdc, cryptocodec.DefaultPublicKeyCodec{}) +} + +// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by +// simapp. It is useful for tests and clients who do not want to construct the +// full simapp +func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { + cdc := std.MakeCodec(ModuleBasics) + interfaceRegistry := codectypes.NewInterfaceRegistry() + std.RegisterInterfaces(interfaceRegistry) + ModuleBasics.RegisterInterfaceModules(interfaceRegistry) + appCodec := codec.NewHybridCodec(cdc, interfaceRegistry) + return appCodec, nil, cdc +} + +func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { + return ante.NewProtoAnteHandler( + ak, bk, ibcK, ante.DefaultSigVerificationGasConsumer, + ) +} diff --git a/std/codec.go b/std/codec.go index eeb8f038c9e0..b3df5cd88330 100644 --- a/std/codec.go +++ b/std/codec.go @@ -8,22 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/vesting" ) -// Codec defines the application-level codec. This codec contains all the -// required module-specific codecs that are to be provided upon initialization. -type Codec struct { - codec.Marshaler - - // Keep reference to the amino codec to allow backwards compatibility along - // with type, and interface registration. - amino *codec.Codec - - anyUnpacker types.AnyUnpacker -} - -func NewAppCodec(amino *codec.Codec, anyUnpacker types.AnyUnpacker) *Codec { - return &Codec{Marshaler: codec.NewHybridCodec(amino, anyUnpacker), amino: amino, anyUnpacker: anyUnpacker} -} - // ---------------------------------------------------------------------------- // necessary types and interfaces registered. This codec is provided to all the // modules the application depends on. diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index 755dbab68219..99df9bfdf289 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -2,13 +2,13 @@ package signing import ( "fmt" + codec2 "github.com/cosmos/cosmos-sdk/crypto/types/codec" "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" @@ -29,7 +29,7 @@ var _ ante.FeeTx = DecodedTx{} var _ ante.TxWithMemo = DecodedTx{} var _ ante.HasPubKeysTx = DecodedTx{} -func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder { +func DefaultTxDecoder(cdc codec.Marshaler, keyCodec codec2.PublicKeyCodec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := cdc.UnmarshalBinaryBare(txBytes, &raw) diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index df00f1c45e2b..400706066d62 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -47,7 +47,7 @@ func NewProtoAnteHandler( NewValidateSigCountDecorator(ak), NewDeductFeeDecorator(ak, bankKeeper), NewSigGasConsumeDecorator(ak, sigGasConsumer), - NewSigVerificationDecorator(ak), + NewProtoSigVerificationDecorator(ak), NewIncrementSequenceDecorator(ak), ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator ) diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index 6603d0083cb9..57e150f2b951 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -22,7 +22,7 @@ var ( func TestDecodeStore(t *testing.T) { app := simapp.Setup(false) - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() acc := types.NewBaseAccountWithAddress(delAddr1) dec := simulation.NewDecodeStore(app.AccountKeeper) diff --git a/x/auth/types/common_test.go b/x/auth/types/common_test.go index 4f361059ad3c..8eac4d021a80 100644 --- a/x/auth/types/common_test.go +++ b/x/auth/types/common_test.go @@ -5,6 +5,6 @@ import ( ) var ( - app = simapp.Setup(false) - appCodec, _ = simapp.MakeCodecs() + app = simapp.Setup(false) + appCodec, _, _ = simapp.MakeCodecs() ) diff --git a/x/auth/vesting/types/common_test.go b/x/auth/vesting/types/common_test.go index 4f361059ad3c..8eac4d021a80 100644 --- a/x/auth/vesting/types/common_test.go +++ b/x/auth/vesting/types/common_test.go @@ -5,6 +5,6 @@ import ( ) var ( - app = simapp.Setup(false) - appCodec, _ = simapp.MakeCodecs() + app = simapp.Setup(false) + appCodec, _, _ = simapp.MakeCodecs() ) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 8c23ef3e44ac..a2d9695b629d 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -207,7 +207,7 @@ func (suite *IntegrationTestSuite) TestSupply_MintCoins() { func (suite *IntegrationTestSuite) TestSupply_BurnCoins() { app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1}) - appCodec, _ := simapp.MakeCodecs() + appCodec, _, _ := simapp.MakeCodecs() // add module accounts to supply keeper maccPerms := simapp.GetMaccPerms() diff --git a/x/capability/simulation/decoder_test.go b/x/capability/simulation/decoder_test.go index 8f10e9085421..6b2f9ec0032e 100644 --- a/x/capability/simulation/decoder_test.go +++ b/x/capability/simulation/decoder_test.go @@ -14,7 +14,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() dec := simulation.NewDecodeStore(cdc) capOwners := types.CapabilityOwners{ diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 7fddb1625c7b..75ddee153864 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -23,7 +23,7 @@ var ( ) func TestDecodeDistributionStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() dec := simulation.NewDecodeStore(cdc) decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.OneDec())} diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 2cac40eb6223..684df32ef572 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -16,7 +16,7 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd valAddrs := simapp.ConvertAddrsToValAddrs(addrs) pks := simapp.CreateTestPubKeys(5) - appCodec, _ := simapp.MakeCodecs() + appCodec, _, _ := simapp.MakeCodecs() app.StakingKeeper = staking.NewKeeper( appCodec, app.GetKey(staking.StoreKey), diff --git a/x/gov/simulation/decoder_test.go b/x/gov/simulation/decoder_test.go index 20087f4a11ef..e82b0452c1f7 100644 --- a/x/gov/simulation/decoder_test.go +++ b/x/gov/simulation/decoder_test.go @@ -23,7 +23,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() dec := simulation.NewDecodeStore(cdc) endTime := time.Now().UTC() diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 0d69dc331b03..fb7fb95c5c72 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -15,7 +15,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() dec := simulation.NewDecodeStore(cdc) minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15)) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 8fbe78823846..8e788912fd6d 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -27,7 +27,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() dec := simulation.NewDecodeStore(cdc) info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 2d98a6615b0d..593dcc243ff6 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -32,7 +32,7 @@ func makeTestCodec() (cdc *codec.Codec) { } func TestDecodeStore(t *testing.T) { - cdc, _ := simapp.MakeCodecs() + cdc, _, _ := simapp.MakeCodecs() dec := simulation.NewDecodeStore(cdc) bondTime := time.Now().UTC() From b0c30715529ea263aa87f4397d05d7a78d4893d5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 15:23:08 -0400 Subject: [PATCH 14/54] implement multisig in ante handler --- crypto/{types => }/codec/codec.go | 3 +- crypto/{types => }/multisig/codec.go | 0 crypto/{types => }/multisig/multisignature.go | 0 .../{types => }/multisig/threshold_pubkey.go | 2 +- .../multisig/threshold_pubkey_test.go | 0 simapp/proto.go | 2 +- types/tx/signing/decoded_tx.go | 3 +- x/auth/ante/sigverify_proto.go | 94 +++++++++++++------ 8 files changed, 69 insertions(+), 35 deletions(-) rename crypto/{types => }/codec/codec.go (98%) rename crypto/{types => }/multisig/codec.go (100%) rename crypto/{types => }/multisig/multisignature.go (100%) rename crypto/{types => }/multisig/threshold_pubkey.go (99%) rename crypto/{types => }/multisig/threshold_pubkey_test.go (100%) diff --git a/crypto/types/codec/codec.go b/crypto/codec/codec.go similarity index 98% rename from crypto/types/codec/codec.go rename to crypto/codec/codec.go index 363d7e812fb2..92be7fff900e 100644 --- a/crypto/types/codec/codec.go +++ b/crypto/codec/codec.go @@ -2,8 +2,9 @@ package codec import ( "fmt" + + "github.com/cosmos/cosmos-sdk/crypto/multisig" "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/crypto/types/multisig" "github.com/tendermint/tendermint/crypto" ed255192 "github.com/tendermint/tendermint/crypto/ed25519" diff --git a/crypto/types/multisig/codec.go b/crypto/multisig/codec.go similarity index 100% rename from crypto/types/multisig/codec.go rename to crypto/multisig/codec.go diff --git a/crypto/types/multisig/multisignature.go b/crypto/multisig/multisignature.go similarity index 100% rename from crypto/types/multisig/multisignature.go rename to crypto/multisig/multisignature.go diff --git a/crypto/types/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go similarity index 99% rename from crypto/types/multisig/threshold_pubkey.go rename to crypto/multisig/threshold_pubkey.go index 75de9cc9f402..a48d685e0e36 100644 --- a/crypto/types/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -11,7 +11,7 @@ import ( // PubKey implements a K of N threshold multisig. type PubKey struct { - K uint32 `json:"threshold"` + K uint32 `json:"threshold"` PubKeys []crypto.PubKey `json:"pubkeys"` } diff --git a/crypto/types/multisig/threshold_pubkey_test.go b/crypto/multisig/threshold_pubkey_test.go similarity index 100% rename from crypto/types/multisig/threshold_pubkey_test.go rename to crypto/multisig/threshold_pubkey_test.go diff --git a/simapp/proto.go b/simapp/proto.go index dbdfa257a7e1..06b3a4813d94 100644 --- a/simapp/proto.go +++ b/simapp/proto.go @@ -5,7 +5,7 @@ package simapp import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/types/codec" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index 99df9bfdf289..20527c75cf5a 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -2,7 +2,8 @@ package signing import ( "fmt" - codec2 "github.com/cosmos/cosmos-sdk/crypto/types/codec" + + codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/pkg/errors" diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 980c9bab4179..e872c4e1a55f 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -3,6 +3,8 @@ package ante import ( "fmt" + "github.com/cosmos/cosmos-sdk/crypto/multisig" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" @@ -46,8 +48,6 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } for i, sig := range sigs { - var signBytes []byte - signerAcc, err := GetSignerAcc(ctx, svd.ak, signerAddrs[i]) if err != nil { return ctx, err @@ -57,46 +57,78 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, signerInfo := sigTx.AuthInfo.SignerInfos[i] + // retrieve pubkey + pubKey := signerAccs[i].GetPubKey() + if !simulate && pubKey == nil { + return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") + } + switch mi := signerInfo.ModeInfo.Sum.(type) { case *types.ModeInfo_Single_: single := mi.Single - verifier, found := svd.signModeVerifiers[single.Mode] - if !found { - return ctx, fmt.Errorf("can't verify sign mode %s", single.Mode.String()) - } - genesis := ctx.BlockHeight() == 0 - var accNum uint64 - if !genesis { - accNum = signerAcc.GetAccountNumber() - } - data := signing.SigningData{ - ModeInfo: single, - PublicKey: signerAcc.GetPubKey(), - ChainID: ctx.ChainID(), - AccountNumber: accNum, - AccountSequence: signerAcc.GetSequence(), - } - signBytes, err = verifier.GetSignBytes(data, sigTx) + + signBytes, err := svd.getSignBytesSingle(ctx, single, signerAcc, sigTx) if err != nil { return ctx, err } + + // verify signature + if !simulate && !pubKey.VerifyBytes(signBytes, sig) { + return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") + } case *types.ModeInfo_Multi_: - panic("TODO: can't handle multisignatures yet") + multisigPubKey, ok := pubKey.(multisig.MultisigPubKey) + if !ok { + return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "key is not a multisig pubkey, but ModeInfo.Multi is used") + } + + if !simulate { + multiSigs, err := multisig.DecodeMultisignatures(sig) + if err != nil { + return ctx, sdkerrors.Wrap(err, "cannot decode MultiSignature") + } + + decodedMultisig := multisig.DecodedMultisignature{ + ModeInfo: mi.Multi, + Signatures: multiSigs, + } + + if !multisigPubKey.VerifyMultisignature( + func(single *types.ModeInfo_Single) ([]byte, error) { + return svd.getSignBytesSingle(ctx, single, signerAcc, sigTx) + }, decodedMultisig, + ) { + return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") + } + } default: panic("unexpected ModeInfo type") } - - // retrieve pubkey - pubKey := signerAccs[i].GetPubKey() - if !simulate && pubKey == nil { - return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") - } - - // verify signature - if !simulate && !pubKey.VerifyBytes(signBytes, sig) { - return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") - } } return next(ctx, tx, simulate) } + +func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, single *types.ModeInfo_Single, signerAcc auth.AccountI, sigTx signing.DecodedTx) ([]byte, error) { + verifier, found := svd.signModeVerifiers[single.Mode] + if !found { + return nil, fmt.Errorf("can't verify sign mode %s", single.Mode.String()) + } + genesis := ctx.BlockHeight() == 0 + var accNum uint64 + if !genesis { + accNum = signerAcc.GetAccountNumber() + } + data := signing.SigningData{ + ModeInfo: single, + PublicKey: signerAcc.GetPubKey(), + ChainID: ctx.ChainID(), + AccountNumber: accNum, + AccountSequence: signerAcc.GetSequence(), + } + signBytes, err := verifier.GetSignBytes(data, sigTx) + if err != nil { + return nil, err + } + return signBytes, nil +} From f21b8234d6775b0f833e3eed4e7f0ad146b918cd Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 15:26:11 -0400 Subject: [PATCH 15/54] Refactoring --- crypto/codec/{codec.go => default.go} | 7 +------ crypto/multisig/threshold_pubkey.go | 17 +++-------------- crypto/types/codec.go | 8 ++++++++ crypto/types/multisig.go | 14 ++++++++++++++ types/tx/signing/decoded_tx.go | 4 ++-- x/auth/ante/sigverify_proto.go | 6 ++++-- 6 files changed, 32 insertions(+), 24 deletions(-) rename crypto/codec/{codec.go => default.go} (93%) create mode 100644 crypto/types/codec.go create mode 100644 crypto/types/multisig.go diff --git a/crypto/codec/codec.go b/crypto/codec/default.go similarity index 93% rename from crypto/codec/codec.go rename to crypto/codec/default.go index 92be7fff900e..eb8ed9a34f92 100644 --- a/crypto/codec/codec.go +++ b/crypto/codec/default.go @@ -12,14 +12,9 @@ import ( "github.com/tendermint/tendermint/crypto/sr25519" ) -type PublicKeyCodec interface { - Decode(key *types.PublicKey) (crypto.PubKey, error) - Encode(key crypto.PubKey) (*types.PublicKey, error) -} - type DefaultPublicKeyCodec struct{} -var _ PublicKeyCodec = DefaultPublicKeyCodec{} +var _ types.PublicKeyCodec = DefaultPublicKeyCodec{} func (cdc DefaultPublicKeyCodec) Decode(key *types.PublicKey) (crypto.PubKey, error) { switch key := key.Sum.(type) { diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index a48d685e0e36..fce8e0fa7d6f 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -72,17 +72,6 @@ func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool { return true } -type DecodedMultisignature struct { - ModeInfo *txtypes.ModeInfo_Multi - Signatures [][]byte -} - -type GetSignBytesFunc func(single *txtypes.ModeInfo_Single) ([]byte, error) - -type MultisigPubKey interface { - VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool -} - func DecodeMultisignatures(bz []byte) ([][]byte, error) { multisig := types.MultiSignature{} err := multisig.Unmarshal(bz) @@ -95,7 +84,7 @@ func DecodeMultisignatures(bz []byte) ([][]byte, error) { return multisig.Sigs, nil } -func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool { +func (pk PubKey) VerifyMultisignature(getSignBytes types.GetSignBytesFunc, sig types.DecodedMultisignature) bool { bitarray := sig.ModeInfo.Bitarray sigs := sig.Signatures size := bitarray.Size() @@ -126,7 +115,7 @@ func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig Decoded return false } case *txtypes.ModeInfo_Multi_: - nestedMultisigPk, ok := pk.PubKeys[i].(MultisigPubKey) + nestedMultisigPk, ok := pk.PubKeys[i].(types.MultisigPubKey) if !ok { return false } @@ -134,7 +123,7 @@ func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig Decoded if err != nil { return false } - if !nestedMultisigPk.VerifyMultisignature(getSignBytes, DecodedMultisignature{ + if !nestedMultisigPk.VerifyMultisignature(getSignBytes, types.DecodedMultisignature{ ModeInfo: mi.Multi, Signatures: nestedSigs, }) { diff --git a/crypto/types/codec.go b/crypto/types/codec.go new file mode 100644 index 000000000000..f32c81b317cb --- /dev/null +++ b/crypto/types/codec.go @@ -0,0 +1,8 @@ +package types + +import "github.com/tendermint/tendermint/crypto" + +type PublicKeyCodec interface { + Decode(key *PublicKey) (crypto.PubKey, error) + Encode(key crypto.PubKey) (*PublicKey, error) +} diff --git a/crypto/types/multisig.go b/crypto/types/multisig.go new file mode 100644 index 000000000000..5c20d27d7428 --- /dev/null +++ b/crypto/types/multisig.go @@ -0,0 +1,14 @@ +package types + +import types "github.com/cosmos/cosmos-sdk/types/tx" + +type DecodedMultisignature struct { + ModeInfo *types.ModeInfo_Multi + Signatures [][]byte +} + +type GetSignBytesFunc func(single *types.ModeInfo_Single) ([]byte, error) + +type MultisigPubKey interface { + VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool +} diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index 20527c75cf5a..ade97d7e8eea 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -3,7 +3,7 @@ package signing import ( "fmt" - codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" + types2 "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/pkg/errors" @@ -30,7 +30,7 @@ var _ ante.FeeTx = DecodedTx{} var _ ante.TxWithMemo = DecodedTx{} var _ ante.HasPubKeysTx = DecodedTx{} -func DefaultTxDecoder(cdc codec.Marshaler, keyCodec codec2.PublicKeyCodec) sdk.TxDecoder { +func DefaultTxDecoder(cdc codec.Marshaler, keyCodec types2.PublicKeyCodec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := cdc.UnmarshalBinaryBare(txBytes, &raw) diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index e872c4e1a55f..95cdbc9356b8 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -3,6 +3,8 @@ package ante import ( "fmt" + types2 "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" @@ -77,7 +79,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") } case *types.ModeInfo_Multi_: - multisigPubKey, ok := pubKey.(multisig.MultisigPubKey) + multisigPubKey, ok := pubKey.(types2.MultisigPubKey) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "key is not a multisig pubkey, but ModeInfo.Multi is used") } @@ -88,7 +90,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return ctx, sdkerrors.Wrap(err, "cannot decode MultiSignature") } - decodedMultisig := multisig.DecodedMultisignature{ + decodedMultisig := types2.DecodedMultisignature{ ModeInfo: mi.Multi, Signatures: multiSigs, } From c4b35df28dab63a69bff7e16b4d8c999b48999aa Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:24:59 -0400 Subject: [PATCH 16/54] Fix build errors --- crypto/{types => multisig}/multisig.go | 2 +- crypto/multisig/threshold_pubkey.go | 10 +++---- simapp/app.go | 23 ++++++++-------- simapp/cmd/simd/genaccounts.go | 4 +-- simapp/export.go | 4 +-- types/tx/signing/decoded_tx.go | 13 +++++----- types/tx/signing/legacy_amino_json.go | 2 +- types/tx/tx.go | 20 ++------------ x/auth/ante/basic.go | 13 +++------- x/auth/ante/fee.go | 16 ++++-------- x/auth/ante/sigverify.go | 28 ++++++-------------- x/auth/ante/sigverify_proto.go | 8 +++--- x/auth/ante/types/types.go | 36 ++++++++++++++++++++++++++ 13 files changed, 85 insertions(+), 94 deletions(-) rename crypto/{types => multisig}/multisig.go (95%) create mode 100644 x/auth/ante/types/types.go diff --git a/crypto/types/multisig.go b/crypto/multisig/multisig.go similarity index 95% rename from crypto/types/multisig.go rename to crypto/multisig/multisig.go index 5c20d27d7428..4a871ef9f6cf 100644 --- a/crypto/types/multisig.go +++ b/crypto/multisig/multisig.go @@ -1,4 +1,4 @@ -package types +package multisig import types "github.com/cosmos/cosmos-sdk/types/tx" diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index fce8e0fa7d6f..36e54bebfc48 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -23,7 +23,7 @@ func NewPubKeyMultisigThreshold(k uint32, pubkeys []crypto.PubKey) crypto.PubKey if k <= 0 { panic("threshold k of n multisignature: k <= 0") } - if len(pubkeys) < k { + if len(pubkeys) < int(k) { panic("threshold k of n multisignature: len(pubkeys) < k") } for _, pubkey := range pubkeys { @@ -31,7 +31,7 @@ func NewPubKeyMultisigThreshold(k uint32, pubkeys []crypto.PubKey) crypto.PubKey panic("nil pubkey") } } - return PubKey{uint(k), pubkeys} + return PubKey{k, pubkeys} } // VerifyBytes expects sig to be an amino encoded version of a MultiSignature. @@ -84,7 +84,7 @@ func DecodeMultisignatures(bz []byte) ([][]byte, error) { return multisig.Sigs, nil } -func (pk PubKey) VerifyMultisignature(getSignBytes types.GetSignBytesFunc, sig types.DecodedMultisignature) bool { +func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool { bitarray := sig.ModeInfo.Bitarray sigs := sig.Signatures size := bitarray.Size() @@ -115,7 +115,7 @@ func (pk PubKey) VerifyMultisignature(getSignBytes types.GetSignBytesFunc, sig t return false } case *txtypes.ModeInfo_Multi_: - nestedMultisigPk, ok := pk.PubKeys[i].(types.MultisigPubKey) + nestedMultisigPk, ok := pk.PubKeys[i].(MultisigPubKey) if !ok { return false } @@ -123,7 +123,7 @@ func (pk PubKey) VerifyMultisignature(getSignBytes types.GetSignBytesFunc, sig t if err != nil { return false } - if !nestedMultisigPk.VerifyMultisignature(getSignBytes, types.DecodedMultisignature{ + if !nestedMultisigPk.VerifyMultisignature(getSignBytes, DecodedMultisignature{ ModeInfo: mi.Multi, Signatures: nestedSigs, }) { diff --git a/simapp/app.go b/simapp/app.go index 02c38cf06081..cca5099b93c2 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -94,8 +93,8 @@ var _ App = (*SimApp)(nil) // capabilities aren't needed for testing. type SimApp struct { *baseapp.BaseApp - cdc *codec.Codec - appCodec *std.Codec + amino *codec.Codec + marshaler codec.Marshaler invCheckPeriod uint @@ -140,7 +139,7 @@ func NewSimApp( homePath string, invCheckPeriod uint, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - // TODO: Remove cdc in favor of appCodec once all modules are migrated. + // TODO: Remove amino in favor of marshaler once all modules are migrated. appCodec, _, cdc := MakeCodecs() bApp := baseapp.NewBaseApp(appName, logger, db, SimappTxDecoder(), baseAppOptions...) @@ -158,8 +157,8 @@ func NewSimApp( app := &SimApp{ BaseApp: bApp, - cdc: cdc, - appCodec: appCodec, + amino: cdc, + marshaler: appCodec, invCheckPeriod: invCheckPeriod, keys: keys, tkeys: tkeys, @@ -233,7 +232,7 @@ func NewSimApp( // TODO: remove amino codec dependency once Tendermint version is upgraded with // protobuf changes app.IBCKeeper = ibc.NewKeeper( - app.cdc, appCodec, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper, + app.amino, appCodec, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper, ) // Create Transfer Keepers @@ -373,8 +372,8 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re // InitChainer application update at chain initialization func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { var genesisState GenesisState - app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) - return app.mm.InitGenesis(ctx, app.cdc, genesisState) + app.amino.MustUnmarshalJSON(req.AppStateBytes, &genesisState) + return app.mm.InitGenesis(ctx, app.amino, genesisState) } // LoadHeight loads a particular height @@ -407,15 +406,15 @@ func (app *SimApp) BlacklistedAccAddrs() map[string]bool { // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. func (app *SimApp) Codec() *codec.Codec { - return app.cdc + return app.amino } // AppCodec returns SimApp's app codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. -func (app *SimApp) AppCodec() *std.Codec { - return app.appCodec +func (app *SimApp) AppCodec() codec.Marshaler { + return app.marshaler } // GetKey returns the KVStoreKey for the provided store key. diff --git a/simapp/cmd/simd/genaccounts.go b/simapp/cmd/simd/genaccounts.go index 0268b5405420..7e6d395abaac 100644 --- a/simapp/cmd/simd/genaccounts.go +++ b/simapp/cmd/simd/genaccounts.go @@ -7,8 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/std" - "github.com/spf13/cobra" "github.com/spf13/viper" @@ -34,7 +32,7 @@ const ( // AddGenesisAccountCmd returns add-genesis-account cobra Command. func AddGenesisAccountCmd( - ctx *server.Context, depCdc *codec.Codec, cdc *std.Codec, defaultNodeHome, defaultClientHome string, + ctx *server.Context, depCdc *codec.Codec, cdc codec.Marshaler, defaultNodeHome, defaultClientHome string, ) *cobra.Command { cmd := &cobra.Command{ diff --git a/simapp/export.go b/simapp/export.go index 84e442fafa2b..1c145d804455 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -27,8 +27,8 @@ func (app *SimApp) ExportAppStateAndValidators( app.prepForZeroHeightGenesis(ctx, jailWhiteList) } - genState := app.mm.ExportGenesis(ctx, app.cdc) - appState, err = codec.MarshalJSONIndent(app.cdc, genState) + genState := app.mm.ExportGenesis(ctx, app.amino) + appState, err = codec.MarshalJSONIndent(app.amino, genState) if err != nil { return nil, nil, nil, err } diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index ade97d7e8eea..9813cfdd8194 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -3,17 +3,16 @@ package signing import ( "fmt" - types2 "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/cosmos/cosmos-sdk/x/auth/ante" + antetypes "github.com/cosmos/cosmos-sdk/x/auth/ante/types" auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -26,11 +25,11 @@ type DecodedTx struct { } var _ sdk.Tx = DecodedTx{} -var _ ante.FeeTx = DecodedTx{} -var _ ante.TxWithMemo = DecodedTx{} -var _ ante.HasPubKeysTx = DecodedTx{} +var _ antetypes.FeeTx = DecodedTx{} +var _ antetypes.TxWithMemo = DecodedTx{} +var _ antetypes.HasPubKeysTx = DecodedTx{} -func DefaultTxDecoder(cdc codec.Marshaler, keyCodec types2.PublicKeyCodec) sdk.TxDecoder { +func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := cdc.UnmarshalBinaryBare(txBytes, &raw) diff --git a/types/tx/signing/legacy_amino_json.go b/types/tx/signing/legacy_amino_json.go index 6ab1038e7990..59e02cf6cd3d 100644 --- a/types/tx/signing/legacy_amino_json.go +++ b/types/tx/signing/legacy_amino_json.go @@ -2,7 +2,7 @@ package signing import ( types "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/cosmos/cosmos-sdk/x/auth" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) type LegacyAminoJSONHandler struct{} diff --git a/types/tx/tx.go b/types/tx/tx.go index 1b8312066c01..89d4db23ca12 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -1,9 +1,8 @@ package types import ( - "github.com/tendermint/tendermint/crypto" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) var _ codectypes.UnpackInterfacesMessage = &Tx{} @@ -20,7 +19,7 @@ func (m *SignDoc) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { for _, any := range m.Messages { - var msg Msg + var msg sdk.Msg err := unpacker.UnpackAny(any, &msg) if err != nil { return err @@ -28,18 +27,3 @@ func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { } return nil } - -func (m *SignerInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - var pubkey crypto.PubKey - return unpacker.UnpackAny(m.PublicKey, &pubkey) -} - -func (m *AuthInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - for _, si := range m.SignerInfos { - err := si.UnpackInterfaces(unpacker) - if err != nil { - return err - } - } - return nil -} diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 41ba96d8bb73..a74e5e74144b 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + types2 "github.com/cosmos/cosmos-sdk/x/auth/ante/types" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" @@ -12,7 +13,7 @@ import ( ) var ( - _ TxWithMemo = (*types.StdTx)(nil) // assert StdTx implements TxWithMemo + _ types2.TxWithMemo = (*types.StdTx)(nil) // assert StdTx implements TxWithMemo ) // ValidateBasicDecorator will call tx.ValidateBasic and return any non-nil error. @@ -38,12 +39,6 @@ func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat return next(ctx, tx, simulate) } -// Tx must have GetMemo() method to use ValidateMemoDecorator -type TxWithMemo interface { - sdk.Tx - GetMemo() string -} - // ValidateMemoDecorator will validate memo given the parameters passed in // If memo is too large decorator returns with error, otherwise call next AnteHandler // CONTRACT: Tx must implement TxWithMemo interface @@ -58,7 +53,7 @@ func NewValidateMemoDecorator(ak AccountKeeper) ValidateMemoDecorator { } func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - memoTx, ok := tx.(TxWithMemo) + memoTx, ok := tx.(types2.TxWithMemo) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -96,7 +91,7 @@ func NewConsumeGasForTxSizeDecorator(ak AccountKeeper) ConsumeTxSizeGasDecorator } func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(SigVerifiableTx) + sigTx, ok := tx.(types2.SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 900caf18d578..7ad17204c218 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -3,23 +3,17 @@ package ante import ( "fmt" + types2 "github.com/cosmos/cosmos-sdk/x/auth/ante/types" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" ) var ( - _ FeeTx = (*types.StdTx)(nil) // assert StdTx implements FeeTx + _ types2.FeeTx = (*types.StdTx)(nil) // assert StdTx implements FeeTx ) -// FeeTx defines the interface to be implemented by Tx to use the FeeDecorators -type FeeTx interface { - sdk.Tx - GetGas() uint64 - GetFee() sdk.Coins - FeePayer() sdk.AccAddress -} - // MempoolFeeDecorator will check if the transaction's fee is at least as large // as the local validator's minimum gasFee (defined in validator config). // If fee is too low, decorator returns error and tx is rejected from mempool. @@ -33,7 +27,7 @@ func NewMempoolFeeDecorator() MempoolFeeDecorator { } func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - feeTx, ok := tx.(FeeTx) + feeTx, ok := tx.(types2.FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } @@ -82,7 +76,7 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper) DeductFeeDecor } func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - feeTx, ok := tx.(FeeTx) + feeTx, ok := tx.(types2.FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index fbbfb170b86c..f0a18b4934b1 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -4,6 +4,8 @@ import ( "bytes" "encoding/hex" + types2 "github.com/cosmos/cosmos-sdk/x/auth/ante/types" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/multisig" @@ -20,7 +22,7 @@ var ( simSecp256k1Pubkey secp256k1.PubKeySecp256k1 simSecp256k1Sig [64]byte - _ SigVerifiableTx = (*types.StdTx)(nil) // assert StdTx implements SigVerifiableTx + _ types2.SigVerifiableTx = (*types.StdTx)(nil) // assert StdTx implements SigVerifiableTx ) func init() { @@ -34,20 +36,6 @@ func init() { // This is where apps can define their own PubKey type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params) error -// SigVerifiableTx defines a Tx interface for all signature verification decorators -type SigVerifiableTx interface { - sdk.Tx - HasPubKeysTx - GetSignatures() [][]byte - GetSignBytes(ctx sdk.Context, acc types.AccountI) []byte -} - -type HasPubKeysTx interface { - sdk.Tx - GetSigners() []sdk.AccAddress - GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place -} - // SetPubKeyDecorator sets PubKeys in context for any signer which does not already have pubkey set // PubKeys must be set in context for all signers before any other sigverify decorators run // CONTRACT: Tx must implement SigVerifiableTx interface @@ -62,7 +50,7 @@ func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { } func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(HasPubKeysTx) + sigTx, ok := tx.(types2.HasPubKeysTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } @@ -119,7 +107,7 @@ func NewSigGasConsumeDecorator(ak AccountKeeper, sigGasConsumer SignatureVerific } func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - sigTx, ok := tx.(SigVerifiableTx) + sigTx, ok := tx.(types2.SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -176,7 +164,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul if ctx.IsReCheckTx() { return next(ctx, tx, simulate) } - sigTx, ok := tx.(SigVerifiableTx) + sigTx, ok := tx.(types2.SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -244,7 +232,7 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim return next(ctx, tx, simulate) } - sigTx, ok := tx.(SigVerifiableTx) + sigTx, ok := tx.(types2.SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -277,7 +265,7 @@ func NewValidateSigCountDecorator(ak AccountKeeper) ValidateSigCountDecorator { } func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(SigVerifiableTx) + sigTx, ok := tx.(types2.SigVerifiableTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") } diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 95cdbc9356b8..83c74d8dd080 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -3,15 +3,13 @@ package ante import ( "fmt" - types2 "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) type ProtoSigVerificationDecorator struct { @@ -79,7 +77,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") } case *types.ModeInfo_Multi_: - multisigPubKey, ok := pubKey.(types2.MultisigPubKey) + multisigPubKey, ok := pubKey.(multisig.MultisigPubKey) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "key is not a multisig pubkey, but ModeInfo.Multi is used") } @@ -90,7 +88,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return ctx, sdkerrors.Wrap(err, "cannot decode MultiSignature") } - decodedMultisig := types2.DecodedMultisignature{ + decodedMultisig := multisig.DecodedMultisignature{ ModeInfo: mi.Multi, Signatures: multiSigs, } diff --git a/x/auth/ante/types/types.go b/x/auth/ante/types/types.go new file mode 100644 index 000000000000..d262685b96ea --- /dev/null +++ b/x/auth/ante/types/types.go @@ -0,0 +1,36 @@ +package types + +import ( + "github.com/tendermint/tendermint/crypto" + + "github.com/cosmos/cosmos-sdk/types" + types2 "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// FeeTx defines the interface to be implemented by Tx to use the FeeDecorators +type FeeTx interface { + types.Tx + GetGas() uint64 + GetFee() types.Coins + FeePayer() types.AccAddress +} + +// Tx must have GetMemo() method to use ValidateMemoDecorator +type TxWithMemo interface { + types.Tx + GetMemo() string +} + +// SigVerifiableTx defines a Tx interface for all signature verification decorators +type SigVerifiableTx interface { + types.Tx + HasPubKeysTx + GetSignatures() [][]byte + GetSignBytes(ctx types.Context, acc types2.AccountI) []byte +} + +type HasPubKeysTx interface { + types.Tx + GetSigners() []types.AccAddress + GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place +} From 91f2b3d54f7d24c8e22b9f41978775ab8327512c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:28:51 -0400 Subject: [PATCH 17/54] Add split integration tests --- .github/workflows/integration-test.yml | 54 ++++++++++++++++++++++++++ .github/workflows/test.yml | 20 ---------- Makefile | 8 ++++ 3 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/integration-test.yml diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 000000000000..d8670f64e470 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,54 @@ +name: Integration Tests (CLI) +on: + pull_request: + push: + branches: + - master +jobs: + cleanup-runs: + runs-on: ubuntu-latest + steps: + - uses: rokroskar/workflow-run-cleanup-action@master + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'" + + protobuf: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v1 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - name: build-sim + run: | + make build-sim + if: "env.GIT_DIFF != ''" + - name: cli-test + run: | + make test-integration + if: "env.GIT_DIFF != ''" + + amino: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v1 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - name: build-sim + run: | + make build-sim-aino + if: "env.GIT_DIFF != ''" + - name: cli-test + run: | + make test-integration-amino + if: "env.GIT_DIFF != ''" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 200f474bebbb..e3ff42eea496 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,23 +49,3 @@ jobs: file: ./coverage.txt # optional fail_ci_if_error: true if: "env.GIT_DIFF != ''" - - integration-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 - id: git_diff - with: - SUFFIX_FILTER: | - .go - .mod - .sum - - name: build-sim - run: | - make build-sim - if: "env.GIT_DIFF != ''" - - name: cli-test - run: | - make test-integration - if: "env.GIT_DIFF != ''" diff --git a/Makefile b/Makefile index e060ea27c6b4..f8d2e0a93ddf 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,11 @@ build-sim: go.sum go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simd go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simcli +build-sim-amino: go.sum + mkdir -p $(BUILDDIR) + go build -mod=readonly $(BUILD_FLAGS) -tags test_amino -o $(BUILDDIR) ./simapp/cmd/simd + go build -mod=readonly $(BUILD_FLAGS) -tags test_amino -o $(BUILDDIR) ./simapp/cmd/simcli + .PHONY: \ build \ build-sim @@ -126,6 +131,9 @@ test-race: test-integration: build-sim BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 -tags='ledger test_ledger_mock cli_test' -run ^TestCLI `go list ./.../cli/...` +test-integration-amino: build-sim-amino + BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 -tags='ledger test_ledger_mock cli_test test_amino' -run ^TestCLI `go list ./.../cli/...` + .PHONY: test test-all test-ledger-mock test-ledger test-unit test-race test-sim-nondeterminism: From 87409ac72a8a65a367e1306048f70f32a1820d8d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:34:09 -0400 Subject: [PATCH 18/54] Setup test_amino --- simapp/amino.go | 13 +++++++++++-- simapp/cmd/simcli/amino.go | 17 +++++++++++++++++ simapp/cmd/simcli/main.go | 9 +-------- simapp/cmd/simcli/proto.go | 17 +++++++++++++++++ simapp/proto.go | 2 +- 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 simapp/cmd/simcli/amino.go create mode 100644 simapp/cmd/simcli/proto.go diff --git a/simapp/amino.go b/simapp/amino.go index 918fd4e66e23..193c2a967d0a 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -1,8 +1,17 @@ -// +build amino_test +// +build test_amino package simapp -import "github.com/cosmos/cosmos-sdk/codec" +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/ibc" +) func SimappTxDecoder() types.TxDecoder { return auth.DefaultTxDecoder(cdc) diff --git a/simapp/cmd/simcli/amino.go b/simapp/cmd/simcli/amino.go new file mode 100644 index 000000000000..e8629deda79c --- /dev/null +++ b/simapp/cmd/simcli/amino.go @@ -0,0 +1,17 @@ +// +build test_amino + +package main + +import ( + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func MakeTxCLIContext() context.CLIContext { + cliCtx := context.CLIContext{} + return cliCtx. + WithJSONMarshaler(appCodec). + WithTxGenerator(types.StdTxGenerator{Cdc: cdc}). + WithAccountRetriever(types.NewAccountRetriever(appCodec)). + WithCodec(cdc) +} diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 5876d1e7b2bb..28ff6feb7744 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -10,7 +10,6 @@ import ( "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/lcd" @@ -21,7 +20,6 @@ import ( authclient "github.com/cosmos/cosmos-sdk/x/auth/client" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" - "github.com/cosmos/cosmos-sdk/x/auth/types" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ) @@ -118,12 +116,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { RunE: client.ValidateCmd, } - cliCtx := context.CLIContext{} - cliCtx = cliCtx. - WithJSONMarshaler(appCodec). - WithTxGenerator(types.StdTxGenerator{Cdc: cdc}). - WithAccountRetriever(types.NewAccountRetriever(appCodec)). - WithCodec(cdc) + cliCtx := MakeTxCLIContext() txCmd.AddCommand( bankcmd.NewSendTxCmd(cliCtx), diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go new file mode 100644 index 000000000000..85ec62bf17e3 --- /dev/null +++ b/simapp/cmd/simcli/proto.go @@ -0,0 +1,17 @@ +// +build !test_amino + +package main + +import ( + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func MakeTxCLIContext() context.CLIContext { + cliCtx := context.CLIContext{} + return cliCtx. + WithJSONMarshaler(appCodec). + WithTxGenerator(types.StdTxGenerator{Cdc: cdc}). + WithAccountRetriever(types.NewAccountRetriever(appCodec)). + WithCodec(cdc) +} diff --git a/simapp/proto.go b/simapp/proto.go index 06b3a4813d94..1c72cafdd085 100644 --- a/simapp/proto.go +++ b/simapp/proto.go @@ -1,4 +1,4 @@ -// +build !amino_test +// +build !test_amino package simapp From 2267516345d10a67c5318062276af9d0dfd1a0af Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:44:57 -0400 Subject: [PATCH 19/54] WIP on proto tx generator --- simapp/cmd/simcli/main.go | 2 +- simapp/cmd/simcli/proto.go | 7 ++- types/tx/signing/tx_generator.go | 94 ++++++++++++++++++++++++++++++++ types/tx/tx.go | 40 ++++++++++++++ 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 types/tx/signing/tx_generator.go diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 28ff6feb7744..1f26bb847600 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -24,7 +24,7 @@ import ( ) var ( - appCodec, _, cdc = simapp.MakeCodecs() + appCodec, interfaceRegistry, cdc = simapp.MakeCodecs() ) func init() { diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index 85ec62bf17e3..1298bc3ba585 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -4,14 +4,17 @@ package main import ( "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ) func MakeTxCLIContext() context.CLIContext { cliCtx := context.CLIContext{} + protoCdc := codec.NewProtoCodec(interfaceRegistry) return cliCtx. - WithJSONMarshaler(appCodec). - WithTxGenerator(types.StdTxGenerator{Cdc: cdc}). + WithJSONMarshaler(protoCdc). + WithTxGenerator(signing.TxGenerator{Marshaler: protoCdc}). WithAccountRetriever(types.NewAccountRetriever(appCodec)). WithCodec(cdc) } diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go new file mode 100644 index 000000000000..ecc6490051ef --- /dev/null +++ b/types/tx/signing/tx_generator.go @@ -0,0 +1,94 @@ +package signing + +import ( + "fmt" + + "github.com/gogo/protobuf/proto" + + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +type TxGenerator struct { + Marshaler codec.Marshaler +} + +var _ context.TxGenerator = TxGenerator{} + +func (t TxGenerator) NewTx() context.TxBuilder { + return TxBuilder{} +} + +func (t TxGenerator) NewFee() context.ClientFee { + panic("implement me") +} + +func (t TxGenerator) NewSignature() context.ClientSignature { + panic("implement me") +} + +func (t TxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { + ptx, ok := tx.(*types.Tx) + if !ok { + return nil, fmt.Errorf("expected protobuf Tx, got %T", tx) + } + return t.Marshaler.MarshalBinaryBare(ptx) +} + +type TxBuilder struct { + *types.Tx +} + +var _ context.TxBuilder = TxBuilder{} + +func (t TxBuilder) GetTx() sdk.Tx { + return t.Tx +} + +func (t TxBuilder) SetMsgs(msgs ...sdk.Msg) error { + anys := make([]*codectypes.Any, len(msgs)) + for i, msg := range msgs { + pmsg, ok := msg.(proto.Message) + if !ok { + return fmt.Errorf("cannot proto marshal %T", msg) + } + any, err := codectypes.NewAnyWithValue(pmsg) + if err != nil { + return err + } + anys[i] = any + } + t.Body.Messages = anys + return nil +} + +func (t TxBuilder) GetSignatures() []sdk.Signature { + panic("implement me") +} + +func (t TxBuilder) SetSignatures(signature ...context.ClientSignature) error { + panic("implement me") +} + +func (t TxBuilder) GetFee() sdk.Fee { + panic("implement me") +} + +func (t TxBuilder) SetFee(fee context.ClientFee) error { + panic("implement me") +} + +func (t TxBuilder) GetMemo() string { + panic("implement me") +} + +func (t TxBuilder) SetMemo(s string) { + panic("implement me") +} + +func (t TxBuilder) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { + panic("implement me") +} diff --git a/types/tx/tx.go b/types/tx/tx.go index 89d4db23ca12..5d90f52a5618 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -27,3 +27,43 @@ func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { } return nil } + +var _ sdk.Tx = &Tx{} + +func (tx *Tx) GetMsgs() []sdk.Msg { + anys := tx.Body.Messages + res := make([]sdk.Msg, len(anys)) + for i, any := range anys { + msg := any.GetCachedValue().(sdk.Msg) + res[i] = msg + } + return res +} + +func (tx *Tx) ValidateBasic() error { + // TODO + //stdSigs := tx.GetSignatures() + // + //if tx.Fee.Gas > MaxGasWanted { + // return sdkerrors.Wrapf( + // sdkerrors.ErrInvalidRequest, + // "invalid gas supplied; %d > %d", tx.Fee.Gas, MaxGasWanted, + // ) + //} + //if tx.Fee.Amount.IsAnyNegative() { + // return sdkerrors.Wrapf( + // sdkerrors.ErrInsufficientFee, + // "invalid fee provided: %s", tx.Fee.Amount, + // ) + //} + //if len(stdSigs) == 0 { + // return sdkerrors.ErrNoSignatures + //} + //if len(stdSigs) != len(tx.GetSigners()) { + // return sdkerrors.Wrapf( + // sdkerrors.ErrUnauthorized, + // "wrong number of signers; expected %d, got %d", tx.GetSigners(), len(stdSigs), + // ) + //} + return nil +} From 2d6955c1d164f7585672b1f2937bf8dbbc00c625 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:45:55 -0400 Subject: [PATCH 20/54] typo --- .github/workflows/integration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index d8670f64e470..93495960489f 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -46,7 +46,7 @@ jobs: .sum - name: build-sim run: | - make build-sim-aino + make build-sim-amino if: "env.GIT_DIFF != ''" - name: cli-test run: | From c9ecb0ebb5bf68f81ef4dbbf352b45d5ae15ef53 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 10:29:12 -0400 Subject: [PATCH 21/54] Fix tests --- client/tx/tx_test.go | 2 +- crypto/multisig/threshold_pubkey_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 85f6973679ef..2e8f9ebef4f5 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -16,7 +16,7 @@ import ( ) func NewTestTxGenerator() context.TxGenerator { - _, cdc := simapp.MakeCodecs() + _, _, cdc := simapp.MakeCodecs() return types.StdTxGenerator{Cdc: cdc} } diff --git a/crypto/multisig/threshold_pubkey_test.go b/crypto/multisig/threshold_pubkey_test.go index 11ea2f0c4536..2168edd71aa9 100644 --- a/crypto/multisig/threshold_pubkey_test.go +++ b/crypto/multisig/threshold_pubkey_test.go @@ -18,7 +18,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { pkSet1, sigSet1 := generatePubKeysAndSignatures(5, []byte{1, 2, 3, 4}) cases := []struct { msg []byte - k int + k uint32 pubkeys []crypto.PubKey signingIndices []int // signatures should be the same size as signingIndices. @@ -38,7 +38,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { multisigKey := NewPubKeyMultisigThreshold(tc.k, tc.pubkeys) multisignature := NewMultisig(len(tc.pubkeys)) - for i := 0; i < tc.k-1; i++ { + for i := uint32(0); i < tc.k-1; i++ { signingIndex := tc.signingIndices[i] require.NoError( t, @@ -56,7 +56,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { ) require.Equal( t, - i+1, + int(i+1), len(multisignature.Sigs), "adding a signature for the same pubkey twice increased signature count by 2, tc %d", tcIndex, ) @@ -82,7 +82,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { "multisig failed after k good signatures, tc %d", tcIndex, ) - for i := tc.k + 1; i < len(tc.signingIndices); i++ { + for i := int(tc.k) + 1; i < len(tc.signingIndices); i++ { signingIndex := tc.signingIndices[i] require.NoError( @@ -92,7 +92,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { bz := multisignature.Marshal() require.Equal( t, - tc.passAfterKSignatures[i-tc.k-1], + tc.passAfterKSignatures[i-int(tc.k)-1], multisigKey.VerifyBytes(tc.msg, bz), "multisig didn't verify as expected after k sigs, tc %d, i %d", tcIndex, i, ) From 77ad336c2eb5b079b7ad6fd74e4b85f93ead6a48 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 10:52:21 -0400 Subject: [PATCH 22/54] Split proto/amino unit tests --- .github/workflows/test.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3ff42eea496..9591d6cb480e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Code Coverage +name: Unit Tests/Coverage on: pull_request: push: @@ -13,7 +13,7 @@ jobs: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'" - test-coverage-upload: + protobuf: runs-on: ubuntu-latest steps: - uses: actions/setup-go@v2-beta @@ -49,3 +49,24 @@ jobs: file: ./coverage.txt # optional fail_ci_if_error: true if: "env.GIT_DIFF != ''" + + amino: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v2-beta + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v1 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - name: build + run: | + make build + if: "env.GIT_DIFF != ''" + - name: unit tests + run: | + go test ./... -mod=readonly -timeout 12m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock test_amino' + if: "env.GIT_DIFF != ''" From ca25ce80376b21384a2ef61e66aeb816a4b85ef8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 11:03:13 -0400 Subject: [PATCH 23/54] Fix amino --- .github/workflows/integration-test.yml | 2 +- .github/workflows/test.yml | 2 +- simapp/amino.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 93495960489f..044c7c593c8d 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -1,4 +1,4 @@ -name: Integration Tests (CLI) +name: CLI Tests on: pull_request: push: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9591d6cb480e..df352fa35389 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Unit Tests/Coverage +name: Unit Tests on: pull_request: push: diff --git a/simapp/amino.go b/simapp/amino.go index 193c2a967d0a..92ca9376c9d4 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -14,6 +14,7 @@ import ( ) func SimappTxDecoder() types.TxDecoder { + _, _, cdc := MakeCodecs() return auth.DefaultTxDecoder(cdc) } From 3cf884c851b3c9a0c3b6a42bd7a0317805dfc853 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 11:37:19 -0400 Subject: [PATCH 24/54] Fix tests --- x/auth/keeper/keeper_test.go | 4 +--- x/evidence/keeper/querier_test.go | 15 ++++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index e3f5d7f3d88b..0863e08a2d55 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -5,9 +5,7 @@ import ( "github.com/stretchr/testify/require" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/std" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -108,7 +106,7 @@ func TestSupply_ValidatePermissions(t *testing.T) { maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} maccPerms[randomPerm] = []string{"random"} - appCodec := std.NewAppCodec(app.Codec(), codectypes.NewInterfaceRegistry()) + appCodec, _, _ := simapp.MakeCodecs() keeper := auth.NewAccountKeeper( appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), types.ProtoBaseAccount, maccPerms, diff --git a/x/evidence/keeper/querier_test.go b/x/evidence/keeper/querier_test.go index 7433f099a074..249d1a8dabb1 100644 --- a/x/evidence/keeper/querier_test.go +++ b/x/evidence/keeper/querier_test.go @@ -3,14 +3,11 @@ package keeper_test import ( "strings" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - - "github.com/cosmos/cosmos-sdk/std" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/x/evidence/exported" "github.com/cosmos/cosmos-sdk/x/evidence/types" - - abci "github.com/tendermint/tendermint/abci/types" ) const ( @@ -20,7 +17,7 @@ const ( func (suite *KeeperTestSuite) TestQueryEvidence_Existing() { ctx := suite.ctx.WithIsCheckTx(false) numEvidence := 100 - cdc := std.NewAppCodec(suite.app.Codec(), codectypes.NewInterfaceRegistry()) + cdc, _, _ := simapp.MakeCodecs() evidence := suite.populateEvidence(ctx, numEvidence) query := abci.RequestQuery{ @@ -39,7 +36,7 @@ func (suite *KeeperTestSuite) TestQueryEvidence_Existing() { func (suite *KeeperTestSuite) TestQueryEvidence_NonExisting() { ctx := suite.ctx.WithIsCheckTx(false) - cdc := std.NewAppCodec(suite.app.Codec(), codectypes.NewInterfaceRegistry()) + cdc, _, _ := simapp.MakeCodecs() numEvidence := 100 suite.populateEvidence(ctx, numEvidence) @@ -55,7 +52,7 @@ func (suite *KeeperTestSuite) TestQueryEvidence_NonExisting() { func (suite *KeeperTestSuite) TestQueryAllEvidence() { ctx := suite.ctx.WithIsCheckTx(false) - cdc := std.NewAppCodec(suite.app.Codec(), codectypes.NewInterfaceRegistry()) + cdc, _, _ := simapp.MakeCodecs() numEvidence := 100 suite.populateEvidence(ctx, numEvidence) @@ -75,7 +72,7 @@ func (suite *KeeperTestSuite) TestQueryAllEvidence() { func (suite *KeeperTestSuite) TestQueryAllEvidence_InvalidPagination() { ctx := suite.ctx.WithIsCheckTx(false) - cdc := std.NewAppCodec(suite.app.Codec(), codectypes.NewInterfaceRegistry()) + cdc, _, _ := simapp.MakeCodecs() numEvidence := 100 suite.populateEvidence(ctx, numEvidence) From 7af5d55ee6c773bbb707fd6ace4ec155a60e2299 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 11:50:19 -0400 Subject: [PATCH 25/54] fix cli tests --- tests/cli/fixtures.go | 9 ++++----- tests/cli/simd_test.go | 7 +------ x/auth/types/genesis.go | 2 +- x/bank/types/genesis.go | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/cli/fixtures.go b/tests/cli/fixtures.go index 564514ddc114..966baa6c4094 100644 --- a/tests/cli/fixtures.go +++ b/tests/cli/fixtures.go @@ -6,18 +6,17 @@ import ( "path/filepath" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" tmtypes "github.com/tendermint/tendermint/types" - "github.com/cosmos/cosmos-sdk/std" - - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" ) var ( - cdc = std.MakeCodec(simapp.ModuleBasics) + cdc, _, _ = simapp.MakeCodecs() ) // Fixtures is used to setup the testing environment @@ -32,7 +31,7 @@ type Fixtures struct { SimdHome string SimcliHome string P2PAddr string - Cdc *codec.Codec + Cdc codec.JSONMarshaler T *testing.T } diff --git a/tests/cli/simd_test.go b/tests/cli/simd_test.go index 2be36dc8e93a..8814d93a2404 100644 --- a/tests/cli/simd_test.go +++ b/tests/cli/simd_test.go @@ -11,8 +11,6 @@ import ( "github.com/stretchr/testify/require" tmtypes "github.com/tendermint/tendermint/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/tests/cli" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" @@ -99,10 +97,7 @@ func TestCLISimdAddGenesisAccount(t *testing.T) { genesisState := f.GenesisState() - interfaceRegistry := codectypes.NewInterfaceRegistry() - appCodec := std.NewAppCodec(f.Cdc, interfaceRegistry) - - accounts := auth.GetGenesisStateFromAppState(appCodec, genesisState).Accounts + accounts := auth.GetGenesisStateFromAppState(f.Cdc, genesisState).Accounts balances := bank.GetGenesisStateFromAppState(f.Cdc, genesisState).Balances balancesSet := make(map[string]sdk.Coins) diff --git a/x/auth/types/genesis.go b/x/auth/types/genesis.go index 6e6631e1e8e5..7a4df84b62b0 100644 --- a/x/auth/types/genesis.go +++ b/x/auth/types/genesis.go @@ -29,7 +29,7 @@ func DefaultGenesisState() GenesisState { // GetGenesisStateFromAppState returns x/auth GenesisState given raw application // genesis state. -func GetGenesisStateFromAppState(cdc codec.Marshaler, appState map[string]json.RawMessage) GenesisState { +func GetGenesisStateFromAppState(cdc codec.JSONMarshaler, appState map[string]json.RawMessage) GenesisState { var genesisState GenesisState if appState[ModuleName] != nil { diff --git a/x/bank/types/genesis.go b/x/bank/types/genesis.go index 2ff55476e6c9..d744c2a16cb3 100644 --- a/x/bank/types/genesis.go +++ b/x/bank/types/genesis.go @@ -65,7 +65,7 @@ func DefaultGenesisState() GenesisState { // GetGenesisStateFromAppState returns x/bank GenesisState given raw application // genesis state. -func GetGenesisStateFromAppState(cdc *codec.Codec, appState map[string]json.RawMessage) GenesisState { +func GetGenesisStateFromAppState(cdc codec.JSONMarshaler, appState map[string]json.RawMessage) GenesisState { var genesisState GenesisState if appState[ModuleName] != nil { From f9f31246d669234c981072bf03342633f3daf779 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 12:01:47 -0400 Subject: [PATCH 26/54] Fix CLi test --- tests/cli/fixtures.go | 60 ++++++++++++----------- tests/cli/helpers.go | 2 +- tests/cli/simd_test.go | 4 +- x/auth/client/cli/cli_test.go | 14 +++--- x/bank/client/cli/cli_test.go | 2 +- x/bank/client/testutil/helpers.go | 8 +-- x/distribution/client/cli/cli_test.go | 6 +-- x/distribution/client/testutil/helpers.go | 2 +- x/gov/client/cli/cli_test.go | 6 +-- x/gov/client/testutil/helpers.go | 18 +++---- x/slashing/client/testutil/helpers.go | 4 +- x/staking/client/cli/cli_test.go | 2 +- x/staking/client/testutil/helpers.go | 10 ++-- 13 files changed, 71 insertions(+), 67 deletions(-) diff --git a/tests/cli/fixtures.go b/tests/cli/fixtures.go index 966baa6c4094..c0e5afe10129 100644 --- a/tests/cli/fixtures.go +++ b/tests/cli/fixtures.go @@ -6,6 +6,8 @@ import ( "path/filepath" "testing" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/stretchr/testify/require" @@ -15,24 +17,22 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" ) -var ( - cdc, _, _ = simapp.MakeCodecs() -) - // Fixtures is used to setup the testing environment type Fixtures struct { - BuildDir string - RootDir string - SimdBinary string - SimcliBinary string - ChainID string - RPCAddr string - Port string - SimdHome string - SimcliHome string - P2PAddr string - Cdc codec.JSONMarshaler - T *testing.T + BuildDir string + RootDir string + SimdBinary string + SimcliBinary string + ChainID string + RPCAddr string + Port string + SimdHome string + SimcliHome string + P2PAddr string + JSONMarshaler codec.JSONMarshaler + Amino *codec.Codec + InterfaceRegistry types.InterfaceRegistry + T *testing.T } // NewFixtures creates a new instance of Fixtures with many vars set @@ -51,18 +51,22 @@ func NewFixtures(t *testing.T) *Fixtures { t.Skip("builddir is empty, skipping") } + cdc, interfaceRegistry, amino := simapp.MakeCodecs() + return &Fixtures{ - T: t, - BuildDir: buildDir, - RootDir: tmpDir, - SimdBinary: filepath.Join(buildDir, "simd"), - SimcliBinary: filepath.Join(buildDir, "simcli"), - SimdHome: filepath.Join(tmpDir, ".simd"), - SimcliHome: filepath.Join(tmpDir, ".simcli"), - RPCAddr: servAddr, - P2PAddr: p2pAddr, - Cdc: cdc, - Port: port, + T: t, + BuildDir: buildDir, + RootDir: tmpDir, + SimdBinary: filepath.Join(buildDir, "simd"), + SimcliBinary: filepath.Join(buildDir, "simcli"), + SimdHome: filepath.Join(tmpDir, ".simd"), + SimcliHome: filepath.Join(tmpDir, ".simcli"), + RPCAddr: servAddr, + P2PAddr: p2pAddr, + JSONMarshaler: cdc, + InterfaceRegistry: interfaceRegistry, + Amino: amino, + Port: port, } } @@ -77,6 +81,6 @@ func (f Fixtures) GenesisState() simapp.GenesisState { require.NoError(f.T, err) var appState simapp.GenesisState - require.NoError(f.T, f.Cdc.UnmarshalJSON(genDoc.AppState, &appState)) + require.NoError(f.T, f.JSONMarshaler.UnmarshalJSON(genDoc.AppState, &appState)) return appState } diff --git a/tests/cli/helpers.go b/tests/cli/helpers.go index 35c5d31b4bc6..44c91860d107 100644 --- a/tests/cli/helpers.go +++ b/tests/cli/helpers.go @@ -168,7 +168,7 @@ func (f *Fixtures) QueryTxs(page, limit int, events ...string) *sdk.SearchTxsRes out, _ := tests.ExecuteT(f.T, cmd, "") var result sdk.SearchTxsResult - err := f.Cdc.UnmarshalJSON([]byte(out), &result) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &result) require.NoError(f.T, err, "out %v\n, err %v", out, err) return &result } diff --git a/tests/cli/simd_test.go b/tests/cli/simd_test.go index 8814d93a2404..8b5aeab74082 100644 --- a/tests/cli/simd_test.go +++ b/tests/cli/simd_test.go @@ -97,8 +97,8 @@ func TestCLISimdAddGenesisAccount(t *testing.T) { genesisState := f.GenesisState() - accounts := auth.GetGenesisStateFromAppState(f.Cdc, genesisState).Accounts - balances := bank.GetGenesisStateFromAppState(f.Cdc, genesisState).Balances + accounts := auth.GetGenesisStateFromAppState(f.JSONMarshaler, genesisState).Accounts + balances := bank.GetGenesisStateFromAppState(f.JSONMarshaler, genesisState).Balances balancesSet := make(map[string]sdk.Coins) for _, b := range balances { diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 66a7cc9f28ab..f2a78d04502d 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -45,7 +45,7 @@ func TestCLIValidateSignatures(t *testing.T) { success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name()) require.True(t, success) - stdTx := cli.UnmarshalStdTx(t, f.Cdc, stdout) + stdTx := cli.UnmarshalStdTx(t, f.Amino, stdout) require.Equal(t, len(stdTx.Msgs), 1) require.Equal(t, 1, len(stdTx.GetSignatures())) @@ -61,7 +61,7 @@ func TestCLIValidateSignatures(t *testing.T) { // modify the transaction stdTx.Memo = "MODIFIED-ORIGINAL-TX-BAD" - bz := cli.MarshalStdTx(t, f.Cdc, stdTx) + bz := cli.MarshalStdTx(t, f.Amino, stdTx) modSignedTxFile, cleanup := tests.WriteToNewTempFile(t, string(bz)) t.Cleanup(cleanup) @@ -89,7 +89,7 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { success, stdout, stderr := bankcli.TxSend(f, fooAddr.String(), barAddr, sdk.NewCoin(cli.Denom, sendTokens), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg := cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg := cli.UnmarshalStdTx(t, f.Amino, stdout) require.Equal(t, msg.Fee.Gas, uint64(flags.DefaultGasLimit)) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) @@ -99,7 +99,7 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg = cli.UnmarshalStdTx(t, f.Amino, stdout) require.Equal(t, msg.Fee.Gas, uint64(100)) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) @@ -108,7 +108,7 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { success, stdout, stderr = bankcli.TxSend(f, fooAddr.String(), barAddr, sdk.NewCoin(cli.Denom, sendTokens), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg = cli.UnmarshalStdTx(t, f.Amino, stdout) require.True(t, msg.Fee.Gas > 0) require.Equal(t, len(msg.Msgs), 1) @@ -135,7 +135,7 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { // Sign transaction success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name()) require.True(t, success) - msg = cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg = cli.UnmarshalStdTx(t, f.Amino, stdout) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 1, len(msg.GetSignatures())) require.Equal(t, fooAddr.String(), msg.GetSigners()[0].String()) @@ -258,7 +258,7 @@ func TestCLIEncode(t *testing.T) { // Check that the transaction decodes as epxceted var decodedTx auth.StdTx - require.Nil(t, f.Cdc.UnmarshalBinaryBare(decodedBytes, &decodedTx)) + require.Nil(t, f.JSONMarshaler.UnmarshalBinaryBare(decodedBytes, &decodedTx)) require.Equal(t, "deadbeef", decodedTx.Memo) } diff --git a/x/bank/client/cli/cli_test.go b/x/bank/client/cli/cli_test.go index 743d348731ad..848857046a8c 100644 --- a/x/bank/client/cli/cli_test.go +++ b/x/bank/client/cli/cli_test.go @@ -55,7 +55,7 @@ func TestCLISend(t *testing.T) { ) require.Empty(t, stderr) require.True(t, success) - msg := cli.UnmarshalStdTx(f.T, f.Cdc, stdout) + msg := cli.UnmarshalStdTx(f.T, f.Amino, stdout) t.Log(msg) require.NotZero(t, msg.Fee.Gas) require.Len(t, msg.Msgs, 1) diff --git a/x/bank/client/testutil/helpers.go b/x/bank/client/testutil/helpers.go index c09de98ac873..c7609683c2fa 100644 --- a/x/bank/client/testutil/helpers.go +++ b/x/bank/client/testutil/helpers.go @@ -32,7 +32,7 @@ func QueryAccount(f *cli.Fixtures, address sdk.AccAddress, flags ...string) auth value := initRes["value"] var acc auth.BaseAccount - err = f.Cdc.UnmarshalJSON(value, &acc) + err = f.JSONMarshaler.UnmarshalJSON(value, &acc) require.NoError(f.T, err, "value %v, err %v", string(value), err) return acc @@ -46,7 +46,7 @@ func QueryBalances(f *cli.Fixtures, address sdk.AccAddress, flags ...string) sdk var balances sdk.Coins - require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &balances), "out %v\n", out) + require.NoError(f.T, f.JSONMarshaler.UnmarshalJSON([]byte(out), &balances), "out %v\n", out) return balances } @@ -57,7 +57,7 @@ func QueryTotalSupply(f *cli.Fixtures, flags ...string) (totalSupply sdk.Coins) res, errStr := tests.ExecuteT(f.T, cmd, "") require.Empty(f.T, errStr) - err := f.Cdc.UnmarshalJSON([]byte(res), &totalSupply) + err := f.JSONMarshaler.UnmarshalJSON([]byte(res), &totalSupply) require.NoError(f.T, err) return totalSupply } @@ -69,7 +69,7 @@ func QueryTotalSupplyOf(f *cli.Fixtures, denom string, flags ...string) sdk.Int require.Empty(f.T, errStr) var supplyOf sdk.Int - err := f.Cdc.UnmarshalJSON([]byte(res), &supplyOf) + err := f.JSONMarshaler.UnmarshalJSON([]byte(res), &supplyOf) require.NoError(f.T, err) return supplyOf } diff --git a/x/distribution/client/cli/cli_test.go b/x/distribution/client/cli/cli_test.go index d2c63acd69c1..d5301f9b9276 100644 --- a/x/distribution/client/cli/cli_test.go +++ b/x/distribution/client/cli/cli_test.go @@ -22,18 +22,18 @@ func TestCLIWithdrawRewards(t *testing.T) { genesisState := f.GenesisState() inflationMin := sdk.MustNewDecFromStr("1.0") var mintData mint.GenesisState - f.Cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData) + f.JSONMarshaler.UnmarshalJSON(genesisState[mint.ModuleName], &mintData) mintData.Minter.Inflation = inflationMin mintData.Params.InflationMin = inflationMin mintData.Params.InflationMax = sdk.MustNewDecFromStr("1.0") - mintDataBz, err := f.Cdc.MarshalJSON(mintData) + mintDataBz, err := f.JSONMarshaler.MarshalJSON(mintData) require.NoError(t, err) genesisState[mint.ModuleName] = mintDataBz genFile := filepath.Join(f.SimdHome, "config", "genesis.json") genDoc, err := tmtypes.GenesisDocFromFile(genFile) require.NoError(t, err) - genDoc.AppState, err = f.Cdc.MarshalJSON(genesisState) + genDoc.AppState, err = f.JSONMarshaler.MarshalJSON(genesisState) require.NoError(t, genDoc.SaveAs(genFile)) // start simd server diff --git a/x/distribution/client/testutil/helpers.go b/x/distribution/client/testutil/helpers.go index 975d31674a64..202e703f76e4 100644 --- a/x/distribution/client/testutil/helpers.go +++ b/x/distribution/client/testutil/helpers.go @@ -24,7 +24,7 @@ func QueryRewards(f *cli.Fixtures, delAddr sdk.AccAddress, flags ...string) dist require.Empty(f.T, errStr) var rewards distribution.QueryDelegatorTotalRewardsResponse - err := f.Cdc.UnmarshalJSON([]byte(res), &rewards) + err := f.JSONMarshaler.UnmarshalJSON([]byte(res), &rewards) require.NoError(f.T, err) return rewards } diff --git a/x/gov/client/cli/cli_test.go b/x/gov/client/cli/cli_test.go index e77a0a241a3d..8f99fd59baab 100644 --- a/x/gov/client/cli/cli_test.go +++ b/x/gov/client/cli/cli_test.go @@ -42,7 +42,7 @@ func TestCLISubmitProposal(t *testing.T) { fooAddr.String(), "Text", "Test", "test", sdk.NewCoin(cli.Denom, proposalTokens), "--generate-only", "-y") require.True(t, success) require.Empty(t, stderr) - msg := cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg := cli.UnmarshalStdTx(t, f.Amino, stdout) require.NotZero(t, msg.Fee.Gas) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) @@ -80,7 +80,7 @@ func TestCLISubmitProposal(t *testing.T) { success, stdout, stderr = testutil.TxGovDeposit(f, 1, fooAddr.String(), sdk.NewCoin(cli.Denom, depositTokens), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg = cli.UnmarshalStdTx(t, f.Amino, stdout) require.NotZero(t, msg.Fee.Gas) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) @@ -114,7 +114,7 @@ func TestCLISubmitProposal(t *testing.T) { success, stdout, stderr = testutil.TxGovVote(f, 1, gov.OptionYes, fooAddr.String(), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Cdc, stdout) + msg = cli.UnmarshalStdTx(t, f.Amino, stdout) require.NotZero(t, msg.Fee.Gas) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) diff --git a/x/gov/client/testutil/helpers.go b/x/gov/client/testutil/helpers.go index f6be84a5f1aa..8f7184d5e3ab 100644 --- a/x/gov/client/testutil/helpers.go +++ b/x/gov/client/testutil/helpers.go @@ -22,7 +22,7 @@ func QueryGovParamDeposit(f *cli.Fixtures) gov.DepositParams { out, _ := tests.ExecuteT(f.T, cmd, "") var depositParam gov.DepositParams - err := f.Cdc.UnmarshalJSON([]byte(out), &depositParam) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &depositParam) require.NoError(f.T, err, "out %v\n, err %v", out, err) return depositParam } @@ -33,7 +33,7 @@ func QueryGovParamVoting(f *cli.Fixtures) gov.VotingParams { out, _ := tests.ExecuteT(f.T, cmd, "") var votingParam gov.VotingParams - err := f.Cdc.UnmarshalJSON([]byte(out), &votingParam) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &votingParam) require.NoError(f.T, err, "out %v\n, err %v", out, err) return votingParam } @@ -44,7 +44,7 @@ func QueryGovParamTallying(f *cli.Fixtures) gov.TallyParams { out, _ := tests.ExecuteT(f.T, cmd, "") var tallyingParam gov.TallyParams - err := f.Cdc.UnmarshalJSON([]byte(out), &tallyingParam) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &tallyingParam) require.NoError(f.T, err, "out %v\n, err %v", out, err) return tallyingParam } @@ -55,7 +55,7 @@ func QueryGovProposal(f *cli.Fixtures, proposalID int, flags ...string) gov.Prop out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") var proposal gov.Proposal - err := f.Cdc.UnmarshalJSON([]byte(out), &proposal) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &proposal) require.NoError(f.T, err, "out %v\n, err %v", out, err) return proposal } @@ -70,7 +70,7 @@ func QueryGovProposals(f *cli.Fixtures, flags ...string) gov.Proposals { require.Empty(f.T, stderr) var out gov.Proposals - err := f.Cdc.UnmarshalJSON([]byte(stdout), &out) + err := f.JSONMarshaler.UnmarshalJSON([]byte(stdout), &out) require.NoError(f.T, err) return out } @@ -81,7 +81,7 @@ func QueryGovVote(f *cli.Fixtures, proposalID int, voter sdk.AccAddress, flags . out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") var vote gov.Vote - err := f.Cdc.UnmarshalJSON([]byte(out), &vote) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &vote) require.NoError(f.T, err, "out %v\n, err %v", out, err) return vote } @@ -92,7 +92,7 @@ func QueryGovVotes(f *cli.Fixtures, proposalID int, flags ...string) []gov.Vote out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") var votes []gov.Vote - err := f.Cdc.UnmarshalJSON([]byte(out), &votes) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &votes) require.NoError(f.T, err, "out %v\n, err %v", out, err) return votes } @@ -103,7 +103,7 @@ func QueryGovDeposit(f *cli.Fixtures, proposalID int, depositor sdk.AccAddress, out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") var deposit gov.Deposit - err := f.Cdc.UnmarshalJSON([]byte(out), &deposit) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &deposit) require.NoError(f.T, err, "out %v\n, err %v", out, err) return deposit } @@ -114,7 +114,7 @@ func QueryGovDeposits(f *cli.Fixtures, propsalID int, flags ...string) []gov.Dep out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") var deposits []gov.Deposit - err := f.Cdc.UnmarshalJSON([]byte(out), &deposits) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &deposits) require.NoError(f.T, err, "out %v\n, err %v", out, err) return deposits } diff --git a/x/slashing/client/testutil/helpers.go b/x/slashing/client/testutil/helpers.go index 48ce2401a101..95ff01bb45ef 100644 --- a/x/slashing/client/testutil/helpers.go +++ b/x/slashing/client/testutil/helpers.go @@ -17,7 +17,7 @@ func QuerySigningInfo(f *cli.Fixtures, val string) slashing.ValidatorSigningInfo require.Empty(f.T, errStr) var sinfo slashing.ValidatorSigningInfo - err := f.Cdc.UnmarshalJSON([]byte(res), &sinfo) + err := f.JSONMarshaler.UnmarshalJSON([]byte(res), &sinfo) require.NoError(f.T, err) return sinfo } @@ -29,7 +29,7 @@ func QuerySlashingParams(f *cli.Fixtures) slashing.Params { require.Empty(f.T, errStr) var params slashing.Params - err := f.Cdc.UnmarshalJSON([]byte(res), ¶ms) + err := f.JSONMarshaler.UnmarshalJSON([]byte(res), ¶ms) require.NoError(f.T, err) return params } diff --git a/x/staking/client/cli/cli_test.go b/x/staking/client/cli/cli_test.go index 24ee0026ce58..857041a0fe54 100644 --- a/x/staking/client/cli/cli_test.go +++ b/x/staking/client/cli/cli_test.go @@ -39,7 +39,7 @@ func TestCLICreateValidator(t *testing.T) { require.True(f.T, success) require.Empty(f.T, stderr) - msg := cli.UnmarshalStdTx(f.T, f.Cdc, stdout) + msg := cli.UnmarshalStdTx(f.T, f.Amino, stdout) require.NotZero(t, msg.Fee.Gas) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) diff --git a/x/staking/client/testutil/helpers.go b/x/staking/client/testutil/helpers.go index b9694d2e93d5..a42b006e5c7e 100644 --- a/x/staking/client/testutil/helpers.go +++ b/x/staking/client/testutil/helpers.go @@ -37,7 +37,7 @@ func QueryStakingValidator(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...str var validator staking.Validator - err := f.Cdc.UnmarshalJSON([]byte(out), &validator) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &validator) require.NoError(f.T, err, "out %v\n, err %v", out, err) return validator @@ -50,7 +50,7 @@ func QueryStakingUnbondingDelegationsFrom(f *cli.Fixtures, valAddr sdk.ValAddres var ubds []staking.UnbondingDelegation - err := f.Cdc.UnmarshalJSON([]byte(out), &ubds) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &ubds) require.NoError(f.T, err, "out %v\n, err %v", out, err) return ubds @@ -63,7 +63,7 @@ func QueryStakingDelegationsTo(f *cli.Fixtures, valAddr sdk.ValAddress, flags .. var delegations []staking.Delegation - err := f.Cdc.UnmarshalJSON([]byte(out), &delegations) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &delegations) require.NoError(f.T, err, "out %v\n, err %v", out, err) return delegations @@ -76,7 +76,7 @@ func QueryStakingPool(f *cli.Fixtures, flags ...string) staking.Pool { var pool staking.Pool - err := f.Cdc.UnmarshalJSON([]byte(out), &pool) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), &pool) require.NoError(f.T, err, "out %v\n, err %v", out, err) return pool @@ -89,7 +89,7 @@ func QueryStakingParameters(f *cli.Fixtures, flags ...string) staking.Params { var params staking.Params - err := f.Cdc.UnmarshalJSON([]byte(out), ¶ms) + err := f.JSONMarshaler.UnmarshalJSON([]byte(out), ¶ms) require.NoError(f.T, err, "out %v\n, err %v", out, err) return params From d8f9d0714f7448aedf544f91cf98aa3a5882adcb Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 13:11:57 -0400 Subject: [PATCH 27/54] Fix some amino store errors --- codec/amino_codec.go | 8 +++++++ codec/any.go | 44 ----------------------------------- codec/codec.go | 8 +++++++ codec/hybrid_codec.go | 12 +++++++++- codec/proto_codec.go | 27 +++++++++++++++++++++ x/auth/keeper/keeper.go | 4 ++-- x/bank/keeper/keeper.go | 4 ++-- x/distribution/types/codec.go | 1 + x/evidence/keeper/keeper.go | 4 ++-- 9 files changed, 61 insertions(+), 51 deletions(-) delete mode 100644 codec/any.go diff --git a/codec/amino_codec.go b/codec/amino_codec.go index a7cf476bae88..f22b4a0fd31c 100644 --- a/codec/amino_codec.go +++ b/codec/amino_codec.go @@ -43,3 +43,11 @@ func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshale func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) { ac.Codec.MustUnmarshalBinaryLengthPrefixed(bz, ptr) } + +func (ac *AminoCodec) MarshalAny(iface interface{}) ([]byte, error) { + return ac.Codec.MarshalBinaryBare(iface) +} + +func (ac *AminoCodec) UnmarshalAny(bz []byte, iface interface{}) error { + return ac.Codec.UnmarshalBinaryBare(bz, iface) +} diff --git a/codec/any.go b/codec/any.go deleted file mode 100644 index 91543b14ff52..000000000000 --- a/codec/any.go +++ /dev/null @@ -1,44 +0,0 @@ -package codec - -import ( - "fmt" - - "github.com/gogo/protobuf/proto" - - "github.com/cosmos/cosmos-sdk/codec/types" -) - -// MarshalAny is a convenience function for packing the provided value in an -// Any and then proto marshaling it to bytes -func MarshalAny(m Marshaler, x interface{}) ([]byte, error) { - msg, ok := x.(proto.Message) - if !ok { - return nil, fmt.Errorf("can't proto marshal %T", x) - } - - any := &types.Any{} - err := any.Pack(msg) - if err != nil { - return nil, err - } - - return m.MarshalBinaryBare(any) -} - -// UnmarshalAny is a convenience function for proto unmarshaling an Any from -// bz and then unpacking it to the interface pointer passed in as iface using -// the provided AnyUnpacker or returning an error -// -// Ex: -// var x MyInterface -// err := UnmarshalAny(unpacker, &x, bz) -func UnmarshalAny(m Marshaler, iface interface{}, bz []byte) error { - any := &types.Any{} - - err := m.UnmarshalBinaryBare(bz, any) - if err != nil { - return err - } - - return m.UnpackAny(any, iface) -} diff --git a/codec/codec.go b/codec/codec.go index dee51a9da789..83ad47d49b96 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -32,6 +32,14 @@ type ( UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) + // MarshalAny marshals the provided interface value as an Any for protobuf + // or as a concrete type with Amino + MarshalAny(iface interface{}) ([]byte, error) + + // UnmarshalAny marshals the provided interface value as an Any for protobuf + // or as a concrete type with Amino + UnmarshalAny(bz []byte, iface interface{}) error + JSONMarshaler types.AnyUnpacker } diff --git a/codec/hybrid_codec.go b/codec/hybrid_codec.go index 7fbd109a3db0..504443f5861f 100644 --- a/codec/hybrid_codec.go +++ b/codec/hybrid_codec.go @@ -1,6 +1,8 @@ package codec -import "github.com/cosmos/cosmos-sdk/codec/types" +import ( + "github.com/cosmos/cosmos-sdk/codec/types" +) // HybridCodec defines a codec that utilizes Protobuf for binary encoding // and Amino for JSON encoding. @@ -64,6 +66,14 @@ func (hc *HybridCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) { hc.amino.MustUnmarshalJSON(bz, ptr) } +func (hc *HybridCodec) MarshalAny(iface interface{}) ([]byte, error) { + return hc.proto.MarshalAny(iface) +} + +func (hc *HybridCodec) UnmarshalAny(bz []byte, iface interface{}) error { + return hc.proto.UnmarshalAny(bz, iface) +} + func (hc *HybridCodec) UnpackAny(any *types.Any, iface interface{}) error { return hc.proto.UnpackAny(any, iface) } diff --git a/codec/proto_codec.go b/codec/proto_codec.go index 2c9825db704b..03c187e410d3 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "fmt" + "github.com/gogo/protobuf/proto" "strings" "github.com/cosmos/cosmos-sdk/codec/types" @@ -134,6 +135,32 @@ func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) { } } +func (pc *ProtoCodec) MarshalAny(ptr interface{}) ([]byte, error) { + msg, ok := ptr.(proto.Message) + if !ok { + return nil, fmt.Errorf("can't proto marshal %T", ptr) + } + + any := &types.Any{} + err := any.Pack(msg) + if err != nil { + return nil, err + } + + return pc.MarshalBinaryBare(any) +} + +func (pc *ProtoCodec) UnmarshalAny(bz []byte, iface interface{}) error { + any := &types.Any{} + + err := pc.UnmarshalBinaryBare(bz, any) + if err != nil { + return err + } + + return pc.UnpackAny(any, iface) +} + func (pc *ProtoCodec) UnpackAny(any *types.Any, iface interface{}) error { return pc.anyUnpacker.UnpackAny(any, iface) } diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 13018004cc24..ed27aa0a1f0d 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -188,7 +188,7 @@ func (ak AccountKeeper) decodeAccount(bz []byte) types.AccountI { // the Marshaler interface, it is treated as a Proto-defined message and // serialized that way. Otherwise, it falls back on the internal Amino codec. func (ak AccountKeeper) MarshalAccount(accountI types.AccountI) ([]byte, error) { - return codec.MarshalAny(ak.cdc, accountI) + return ak.cdc.MarshalAny(accountI) } // UnmarshalEvidence returns an Evidence interface from raw encoded evidence @@ -196,7 +196,7 @@ func (ak AccountKeeper) MarshalAccount(accountI types.AccountI) ([]byte, error) // failure. func (ak AccountKeeper) UnmarshalAccount(bz []byte) (types.AccountI, error) { var acc types.AccountI - if err := codec.UnmarshalAny(ak.cdc, &acc, bz); err != nil { + if err := ak.cdc.UnmarshalAny(bz, &acc); err != nil { return nil, err } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index d50655566959..c9d2dfcff63f 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -351,7 +351,7 @@ func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt // the Marshaler interface, it is treated as a Proto-defined message and // serialized that way. Otherwise, it falls back on the internal Amino codec. func (k BaseKeeper) MarshalSupply(supplyI exported.SupplyI) ([]byte, error) { - return codec.MarshalAny(k.cdc, supplyI) + return k.cdc.MarshalAny(supplyI) } // UnmarshalSupply returns a Supply interface from raw encoded supply @@ -359,7 +359,7 @@ func (k BaseKeeper) MarshalSupply(supplyI exported.SupplyI) ([]byte, error) { // failure. func (k BaseKeeper) UnmarshalSupply(bz []byte) (exported.SupplyI, error) { var evi exported.SupplyI - if err := codec.UnmarshalAny(k.cdc, &evi, bz); err != nil { + if err := k.cdc.UnmarshalAny(bz, &evi); err != nil { return nil, err } diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index d0d329c9bc0d..8bc90ef9a745 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -15,6 +15,7 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil) cdc.RegisterConcrete(MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool", nil) cdc.RegisterConcrete(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) + cdc.RegisterConcrete(FeePool{}, "cosmos-sdk/FeePool", nil) } func RegisterInterfaces(registry types.InterfaceRegistry) { diff --git a/x/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index ce629ff0bc4d..861129169212 100644 --- a/x/evidence/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -173,7 +173,7 @@ func (k Keeper) MustMarshalEvidence(evidence exported.Evidence) []byte { // the Marshaler interface, it is treated as a Proto-defined message and // serialized that way. Otherwise, it falls back on the internal Amino codec. func (k Keeper) MarshalEvidence(evidenceI exported.Evidence) ([]byte, error) { - return codec.MarshalAny(k.cdc, evidenceI) + return k.cdc.MarshalAny(evidenceI) } // UnmarshalEvidence returns an Evidence interface from raw encoded evidence @@ -181,7 +181,7 @@ func (k Keeper) MarshalEvidence(evidenceI exported.Evidence) ([]byte, error) { // failure. func (k Keeper) UnmarshalEvidence(bz []byte) (exported.Evidence, error) { var evi exported.Evidence - if err := codec.UnmarshalAny(k.cdc, &evi, bz); err != nil { + if err := k.cdc.UnmarshalAny(bz, &evi); err != nil { return nil, err } From c12fefa6baf2d046c883501eb01515cc28084ead Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 13:13:14 -0400 Subject: [PATCH 28/54] Switch to using HybridCodec with test_amino for now --- simapp/amino.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/amino.go b/simapp/amino.go index 92ca9376c9d4..71d8824076dc 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -26,7 +26,7 @@ func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) interfaceRegistry := codectypes.NewInterfaceRegistry() std.RegisterInterfaces(interfaceRegistry) ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - appCodec := codec.NewAminoCodec(cdc) + appCodec := codec.HybridCodec(cdc, interfaceRegistry) return appCodec, nil, cdc } From ab4ea68b1cae836495b13ed6d49f148bfbb6aa58 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 13:16:06 -0400 Subject: [PATCH 29/54] Switch to using HybridCodec with test_amino for now --- simapp/amino.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/amino.go b/simapp/amino.go index 71d8824076dc..24a7303ab6b8 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -26,7 +26,7 @@ func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) interfaceRegistry := codectypes.NewInterfaceRegistry() std.RegisterInterfaces(interfaceRegistry) ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - appCodec := codec.HybridCodec(cdc, interfaceRegistry) + appCodec := codec.NewHybridCodec(cdc, interfaceRegistry) return appCodec, nil, cdc } From 66fc4975ff288c921af90b90ab243af992bae8f7 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 13:29:39 -0400 Subject: [PATCH 30/54] fix cli test --- x/auth/client/cli/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index f2a78d04502d..42662e9fe24d 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -258,7 +258,7 @@ func TestCLIEncode(t *testing.T) { // Check that the transaction decodes as epxceted var decodedTx auth.StdTx - require.Nil(t, f.JSONMarshaler.UnmarshalBinaryBare(decodedBytes, &decodedTx)) + require.Nil(t, f.Amino.UnmarshalBinaryBare(decodedBytes, &decodedTx)) require.Equal(t, "deadbeef", decodedTx.Memo) } From 2a30b8c59a87955a00336fb208f51eb23d05b0b0 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 22 May 2020 14:50:13 -0400 Subject: [PATCH 31/54] WIP on proto signing --- simapp/amino.go | 6 ++ simapp/app.go | 81 +++++++++-------- simapp/cmd/simcli/amino.go | 2 +- simapp/cmd/simcli/main.go | 10 +-- simapp/cmd/simcli/proto.go | 9 +- simapp/encoding.go | 16 ++++ simapp/helpers/test_helpers.go | 43 ++++++--- simapp/proto.go | 27 +++--- simapp/test_helpers.go | 22 ++--- types/tx/fee.go | 15 ++++ types/tx/signing/signature.go | 55 ++++++++++++ types/tx/signing/tx_builder.go | 111 ++++++++++++++++++++++++ types/tx/signing/tx_generator.go | 88 ++++++------------- x/bank/app_test.go | 12 +-- x/bank/bench_test.go | 4 +- x/bank/simulation/operations.go | 20 +---- x/distribution/simulation/operations.go | 40 +-------- x/gov/simulation/operations.go | 30 +------ x/slashing/simulation/operations.go | 10 +-- x/staking/simulation/operations.go | 50 ++--------- 20 files changed, 363 insertions(+), 288 deletions(-) create mode 100644 simapp/encoding.go create mode 100644 types/tx/fee.go create mode 100644 types/tx/signing/signature.go create mode 100644 types/tx/signing/tx_builder.go diff --git a/simapp/amino.go b/simapp/amino.go index 24a7303ab6b8..24819a44e177 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -7,6 +7,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/bank" @@ -18,6 +19,11 @@ func SimappTxDecoder() types.TxDecoder { return auth.DefaultTxDecoder(cdc) } +func MakeTxGenerator() signing.TxGenerator { + _, _, cdc := MakeCodecs() + return types.StdTxGenerator{Cdc: cdc} +} + // MakeCodecs constructs the *std.Codec and *codec.Codec instances used by // simapp. It is useful for tests and clients who do not want to construct the // full simapp diff --git a/simapp/app.go b/simapp/app.go index cca5099b93c2..88ebdfb10b0c 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -93,8 +93,9 @@ var _ App = (*SimApp)(nil) // capabilities aren't needed for testing. type SimApp struct { *baseapp.BaseApp - amino *codec.Codec - marshaler codec.Marshaler + amino *codec.Codec + marshaler codec.Marshaler + encodingConfig EncodingConfig invCheckPeriod uint @@ -140,9 +141,10 @@ func NewSimApp( ) *SimApp { // TODO: Remove amino in favor of marshaler once all modules are migrated. - appCodec, _, cdc := MakeCodecs() + encodingConfig := MakeEncodingConfig() + marshaler := encodingConfig.Marshaler - bApp := baseapp.NewBaseApp(appName, logger, db, SimappTxDecoder(), baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxDecoder, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) @@ -157,8 +159,9 @@ func NewSimApp( app := &SimApp{ BaseApp: bApp, - amino: cdc, - marshaler: appCodec, + amino: encodingConfig.Amino, + marshaler: encodingConfig.Marshaler, + encodingConfig: encodingConfig, invCheckPeriod: invCheckPeriod, keys: keys, tkeys: tkeys, @@ -167,7 +170,7 @@ func NewSimApp( } // init params keeper and subspaces - app.ParamsKeeper = params.NewKeeper(appCodec, keys[params.StoreKey], tkeys[params.TStoreKey]) + app.ParamsKeeper = params.NewKeeper(marshaler, keys[params.StoreKey], tkeys[params.TStoreKey]) app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace) app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) @@ -181,35 +184,35 @@ func NewSimApp( bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(std.ConsensusParamsKeyTable())) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capability.NewKeeper(appCodec, keys[capability.StoreKey], memKeys[capability.MemStoreKey]) + app.CapabilityKeeper = capability.NewKeeper(marshaler, keys[capability.StoreKey], memKeys[capability.MemStoreKey]) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibc.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(transfer.ModuleName) // add keepers app.AccountKeeper = auth.NewAccountKeeper( - appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, maccPerms, + marshaler, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, maccPerms, ) app.BankKeeper = bank.NewBaseKeeper( - appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), + marshaler, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), ) stakingKeeper := staking.NewKeeper( - appCodec, keys[staking.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[staking.ModuleName], + marshaler, keys[staking.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[staking.ModuleName], ) app.MintKeeper = mint.NewKeeper( - appCodec, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, + marshaler, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, app.AccountKeeper, app.BankKeeper, auth.FeeCollectorName, ) app.DistrKeeper = distr.NewKeeper( - appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.AccountKeeper, app.BankKeeper, + marshaler, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.AccountKeeper, app.BankKeeper, &stakingKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( - appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + marshaler, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.BankKeeper, auth.FeeCollectorName, ) - app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], appCodec, homePath) + app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], marshaler, homePath) // register the proposal types govRouter := gov.NewRouter() @@ -218,7 +221,7 @@ func NewSimApp( AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) app.GovKeeper = gov.NewKeeper( - appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.AccountKeeper, app.BankKeeper, + marshaler, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.AccountKeeper, app.BankKeeper, &stakingKeeper, govRouter, ) @@ -232,12 +235,12 @@ func NewSimApp( // TODO: remove amino codec dependency once Tendermint version is upgraded with // protobuf changes app.IBCKeeper = ibc.NewKeeper( - app.amino, appCodec, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper, + app.amino, marshaler, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper, ) // Create Transfer Keepers app.TransferKeeper = transfer.NewKeeper( - appCodec, keys[transfer.StoreKey], + marshaler, keys[transfer.StoreKey], app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, ) @@ -250,7 +253,7 @@ func NewSimApp( // create evidence keeper with router evidenceKeeper := evidence.NewKeeper( - appCodec, keys[evidence.StoreKey], &app.StakingKeeper, app.SlashingKeeper, + marshaler, keys[evidence.StoreKey], &app.StakingKeeper, app.SlashingKeeper, ) evidenceRouter := evidence.NewRouter(). AddRoute(ibcclient.RouterKey, ibcclient.HandlerClientMisbehaviour(app.IBCKeeper.ClientKeeper)) @@ -262,15 +265,15 @@ func NewSimApp( // must be passed by reference here. app.mm = module.NewManager( genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx), - auth.NewAppModule(appCodec, app.AccountKeeper), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), + auth.NewAppModule(marshaler, app.AccountKeeper), + bank.NewAppModule(marshaler, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(marshaler, *app.CapabilityKeeper), crisis.NewAppModule(&app.CrisisKeeper), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + gov.NewAppModule(marshaler, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(marshaler, app.MintKeeper, app.AccountKeeper), + slashing.NewAppModule(marshaler, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + distr.NewAppModule(marshaler, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + staking.NewAppModule(marshaler, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), ibc.NewAppModule(app.IBCKeeper), @@ -307,14 +310,14 @@ func NewSimApp( // NOTE: this is not required apps that don't use the simulator for fuzz testing // transactions app.sm = module.NewSimulationManager( - auth.NewAppModule(appCodec, app.AccountKeeper), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - capability.NewAppModule(appCodec, *app.CapabilityKeeper), - gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + auth.NewAppModule(marshaler, app.AccountKeeper), + bank.NewAppModule(marshaler, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(marshaler, *app.CapabilityKeeper), + gov.NewAppModule(marshaler, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(marshaler, app.MintKeeper, app.AccountKeeper), + staking.NewAppModule(marshaler, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + distr.NewAppModule(marshaler, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(marshaler, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), evidence.NewAppModule(app.EvidenceKeeper), ibc.NewAppModule(app.IBCKeeper), @@ -417,6 +420,14 @@ func (app *SimApp) AppCodec() codec.Marshaler { return app.marshaler } +// GetEncodingConfig returns SimApp's EncodingConfig +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *SimApp) GetEncodingConfig() EncodingConfig { + return app.encodingConfig +} + // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. diff --git a/simapp/cmd/simcli/amino.go b/simapp/cmd/simcli/amino.go index e8629deda79c..d6fdc18dcb69 100644 --- a/simapp/cmd/simcli/amino.go +++ b/simapp/cmd/simcli/amino.go @@ -11,7 +11,7 @@ func MakeTxCLIContext() context.CLIContext { cliCtx := context.CLIContext{} return cliCtx. WithJSONMarshaler(appCodec). - WithTxGenerator(types.StdTxGenerator{Cdc: cdc}). + WithTxGenerator(MakeTxGenerator()). WithAccountRetriever(types.NewAccountRetriever(appCodec)). WithCodec(cdc) } diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 1f26bb847600..b212d6af52fb 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -24,11 +24,11 @@ import ( ) var ( - appCodec, interfaceRegistry, cdc = simapp.MakeCodecs() + encodingConfig = simapp.MakeEncodingConfig() ) func init() { - authclient.Codec = appCodec + authclient.Codec = encodingConfig.Marshaler } func main() { @@ -61,10 +61,10 @@ func main() { rootCmd.AddCommand( rpc.StatusCommand(), client.ConfigCmd(simapp.DefaultCLIHome), - queryCmd(cdc), - txCmd(cdc), + queryCmd(encodingConfig.Amino), + txCmd(encodingConfig.Amino), flags.LineBreak, - lcd.ServeCommand(cdc, registerRoutes), + lcd.ServeCommand(encodingConfig.Amino, registerRoutes), flags.LineBreak, keys.Commands(), flags.LineBreak, diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index 1298bc3ba585..ea022c7bdd88 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -5,16 +5,15 @@ package main import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ) func MakeTxCLIContext() context.CLIContext { cliCtx := context.CLIContext{} - protoCdc := codec.NewProtoCodec(interfaceRegistry) + protoCdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) return cliCtx. WithJSONMarshaler(protoCdc). - WithTxGenerator(signing.TxGenerator{Marshaler: protoCdc}). - WithAccountRetriever(types.NewAccountRetriever(appCodec)). - WithCodec(cdc) + WithTxGenerator(encodingConfig.TxGenerator). + WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). + WithCodec(encodingConfig.Amino) } diff --git a/simapp/encoding.go b/simapp/encoding.go new file mode 100644 index 000000000000..ae06c93f8a73 --- /dev/null +++ b/simapp/encoding.go @@ -0,0 +1,16 @@ +package simapp + +import ( + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type EncodingConfig struct { + InterfaceRegistry types.InterfaceRegistry + Marshaler codec.Marshaler + TxDecoder sdk.TxDecoder + TxGenerator context.TxGenerator + Amino *codec.Codec +} diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index ff807ff29ece..c7c8452f6995 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -4,11 +4,12 @@ import ( "math/rand" "time" + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/auth" ) // SimAppChainID hardcoded chainID for simulation @@ -18,13 +19,12 @@ const ( ) // GenTx generates a signed mock transaction. -func GenTx(msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) auth.StdTx { - fee := auth.StdFee{ - Amount: feeAmt, - Gas: gas, - } +func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) sdk.Tx { + fee := gen.NewFee() + fee.SetAmount(feeAmt) + fee.SetGas(gas) - sigs := make([]auth.StdSignature, len(priv)) + sigs := make([]context.ClientSignature, len(priv)) // create a random length memo r := rand.New(rand.NewSource(time.Now().UnixNano())) @@ -33,16 +33,33 @@ func GenTx(msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums for i, p := range priv { // use a empty chainID for ease of testing - sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo)) + clientSig := gen.NewSignature() + clientSig.SetPubKey(p.PubKey()) + + sigs[i] = clientSig + } + + tx := gen.NewTx() + tx.SetMsgs(msgs...) + tx.SetFee(fee) + tx.SetSignatures(sigs...) + tx.SetMemo(memo) + + for i, p := range priv { + // use a empty chainID for ease of testing + signBytes, err := tx.CanonicalSignBytes(chainID, accnums[i], seq[i]) if err != nil { panic(err) } - - sigs[i] = auth.StdSignature{ - PubKey: p.PubKey().Bytes(), - Signature: sig, + sig, err := p.Sign(signBytes) + if err != nil { + panic(err) } + + sigs[i].SetSignature(sig) } - return auth.NewStdTx(msgs, fee, sigs, memo) + tx.SetSignatures(sigs...) + + return tx.GetTx() } diff --git a/simapp/proto.go b/simapp/proto.go index 1c72cafdd085..83e74077821d 100644 --- a/simapp/proto.go +++ b/simapp/proto.go @@ -15,21 +15,26 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc" ) -func SimappTxDecoder() types.TxDecoder { - cdc, _, _ := MakeCodecs() - return signing.DefaultTxDecoder(cdc, cryptocodec.DefaultPublicKeyCodec{}) -} - -// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by -// simapp. It is useful for tests and clients who do not want to construct the -// full simapp -func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { +func MakeEncodingConfig() EncodingConfig { cdc := std.MakeCodec(ModuleBasics) interfaceRegistry := codectypes.NewInterfaceRegistry() std.RegisterInterfaces(interfaceRegistry) ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - appCodec := codec.NewHybridCodec(cdc, interfaceRegistry) - return appCodec, nil, cdc + marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) + pubKeyCodec := cryptocodec.DefaultPublicKeyCodec{} + + return EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxDecoder: signing.DefaultTxDecoder(marshaler, pubKeyCodec), + TxGenerator: signing.NewTxGenerator(marshaler, pubKeyCodec), + Amino: cdc, + } +} + +func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { + cfg := MakeEncodingConfig() + return cfg.Marshaler, cfg.InterfaceRegistry, cfg.Amino } func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 7b17fe743044..0ca6ea1a793a 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -7,6 +7,8 @@ import ( "strconv" "testing" + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -239,11 +241,11 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.C // the parameter 'expPass' against the result. A corresponding result is // returned. func SignCheckDeliver( - t *testing.T, cdc *codec.Codec, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg, + t *testing.T, txGen context.TxGenerator, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg, accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { - tx := helpers.GenTx( + txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, @@ -253,7 +255,7 @@ func SignCheckDeliver( priv..., ) - txBytes, err := cdc.MarshalBinaryBare(tx) + txBytes, err := txGen.MarshalTx(tx) require.Nil(t, err) // Must simulate now as CheckTx doesn't run Msgs anymore @@ -288,18 +290,10 @@ func SignCheckDeliver( // GenSequenceOfTxs generates a set of signed transactions of messages, such // that they differ only by having the sequence numbers incremented between // every transaction. -func GenSequenceOfTxs(msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []auth.StdTx { - txs := make([]auth.StdTx, numToGenerate) +func GenSequenceOfTxs(txGen context.TxGenerator, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []sdk.Tx { + txs := make([]sdk.Tx, numToGenerate) for i := 0; i < numToGenerate; i++ { - txs[i] = helpers.GenTx( - msgs, - sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, - "", - accNums, - initSeqNums, - priv..., - ) + txs[i] = helpers.GenTx(txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, "", accNums, initSeqNums, priv...) incrementAllSequenceNumbers(initSeqNums) } diff --git a/types/tx/fee.go b/types/tx/fee.go new file mode 100644 index 000000000000..9b6e9dca392d --- /dev/null +++ b/types/tx/fee.go @@ -0,0 +1,15 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +func (m *Fee) GetGas() uint64 { + return m.GasLimit +} + +func (m *Fee) SetGas(u uint64) { + m.GasLimit = u +} + +func (m *Fee) SetAmount(coins sdk.Coins) { + m.Amount = coins +} diff --git a/types/tx/signing/signature.go b/types/tx/signing/signature.go new file mode 100644 index 000000000000..dd0a6cb7708d --- /dev/null +++ b/types/tx/signing/signature.go @@ -0,0 +1,55 @@ +package signing + +import ( + "github.com/tendermint/tendermint/crypto" + + "github.com/cosmos/cosmos-sdk/client/context" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +type ClientSignature struct { + pubKey *cryptotypes.PublicKey + signature []byte + modeInfo *types.ModeInfo + codec cryptotypes.PublicKeyCodec +} + +type ModeInfoSignature interface { + context.ClientSignature + GetModeInfo() *types.ModeInfo + SetModeInfo(modeInfo *types.ModeInfo) +} + +func (c ClientSignature) GetPubKey() crypto.PubKey { + pk, err := c.codec.Decode(c.pubKey) + if err != nil { + panic(err) + } + return pk +} + +func (c ClientSignature) GetSignature() []byte { + return c.signature +} + +func (c *ClientSignature) SetPubKey(key crypto.PubKey) error { + pk, err := c.codec.Encode(key) + if err != nil { + return err + } + c.pubKey = pk + return nil +} + +func (c *ClientSignature) SetSignature(bytes []byte) { + c.signature = bytes +} + +func (c *ClientSignature) GetModeInfo() *types.ModeInfo { + return c.modeInfo +} + +func (c *ClientSignature) SetModeInfo(modeInfo *types.ModeInfo) { + c.modeInfo = modeInfo +} diff --git a/types/tx/signing/tx_builder.go b/types/tx/signing/tx_builder.go new file mode 100644 index 000000000000..ca9efce75374 --- /dev/null +++ b/types/tx/signing/tx_builder.go @@ -0,0 +1,111 @@ +package signing + +import ( + "fmt" + + "github.com/gogo/protobuf/proto" + + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +type TxBuilder struct { + *types.Tx + Marshaler codec.Marshaler + PubKeyCodec cryptotypes.PublicKeyCodec +} + +var _ context.TxBuilder = TxBuilder{} + +func (t TxBuilder) GetTx() sdk.Tx { + return t.Tx +} + +func (t TxBuilder) SetMsgs(msgs ...sdk.Msg) error { + anys := make([]*codectypes.Any, len(msgs)) + for i, msg := range msgs { + pmsg, ok := msg.(proto.Message) + if !ok { + return fmt.Errorf("cannot proto marshal %T", msg) + } + any, err := codectypes.NewAnyWithValue(pmsg) + if err != nil { + return err + } + anys[i] = any + } + t.Body.Messages = anys + return nil +} + +func (t TxBuilder) GetSignatures() []sdk.Signature { + signerInfos := t.Tx.AuthInfo.SignerInfos + rawSigs := t.Tx.Signatures + n := len(signerInfos) + res := make([]sdk.Signature, n) + for i, si := range signerInfos { + res[i] = ClientSignature{ + pubKey: si.PublicKey, + signature: rawSigs[i], + modeInfo: si.ModeInfo, + } + } + return res +} + +func (t TxBuilder) SetSignatures(signatures ...context.ClientSignature) error { + n := len(signatures) + signerInfos := make([]*types.SignerInfo, n) + rawSigs := make([][]byte, n) + for i, sig := range signatures { + csig, ok := sig.(*ClientSignature) + if !ok { + return fmt.Errorf("expected ClientSignature, got %T", sig) + } + rawSigs[i] = csig.signature + signerInfos[i] = &types.SignerInfo{ + PublicKey: csig.pubKey, + ModeInfo: csig.modeInfo, + } + } + t.Tx.AuthInfo.SignerInfos = signerInfos + t.Tx.Signatures = rawSigs + return nil +} + +func (t TxBuilder) GetFee() sdk.Fee { + return t.Tx.AuthInfo.Fee +} + +func (t TxBuilder) SetFee(fee context.ClientFee) error { + t.Tx.AuthInfo.Fee = &types.Fee{ + Amount: fee.GetAmount(), + GasLimit: fee.GetGas(), + } + return nil +} + +func (t TxBuilder) GetMemo() string { + return t.Tx.Body.Memo +} + +func (t TxBuilder) SetMemo(s string) { + t.Tx.Body.Memo = s +} + +func (t TxBuilder) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { + bodyBz, err := t.Marshaler.MarshalBinaryBare(t.Body) + if err != nil { + return nil, err + } + aiBz, err := t.Marshaler.MarshalBinaryBare(t.AuthInfo) + if err != nil { + + return nil, err + } + return DirectSignBytes(bodyBz, aiBz, cid, num, seq) +} diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index ecc6490051ef..dd47a6b43c9f 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -3,31 +3,52 @@ package signing import ( "fmt" - "github.com/gogo/protobuf/proto" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types/tx" ) type TxGenerator struct { - Marshaler codec.Marshaler + Marshaler codec.Marshaler + PubKeyCodec cryptotypes.PublicKeyCodec +} + +func NewTxGenerator(marshaler codec.Marshaler, pubKeyCodec cryptotypes.PublicKeyCodec) *TxGenerator { + return &TxGenerator{Marshaler: marshaler, PubKeyCodec: pubKeyCodec} } var _ context.TxGenerator = TxGenerator{} func (t TxGenerator) NewTx() context.TxBuilder { - return TxBuilder{} + return TxBuilder{ + Tx: &types.Tx{ + Body: &types.TxBody{}, + AuthInfo: &types.AuthInfo{}, + Signatures: nil, + }, + Marshaler: t.Marshaler, + PubKeyCodec: t.PubKeyCodec, + } } func (t TxGenerator) NewFee() context.ClientFee { - panic("implement me") + return &types.Fee{} } func (t TxGenerator) NewSignature() context.ClientSignature { - panic("implement me") + return &ClientSignature{ + modeInfo: &types.ModeInfo{ + Sum: &types.ModeInfo_Single_{ + Single: &types.ModeInfo_Single{ + Mode: types.SignMode_SIGN_MODE_DIRECT, + }, + }, + }, + codec: t.PubKeyCodec, + } } func (t TxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { @@ -37,58 +58,3 @@ func (t TxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { } return t.Marshaler.MarshalBinaryBare(ptx) } - -type TxBuilder struct { - *types.Tx -} - -var _ context.TxBuilder = TxBuilder{} - -func (t TxBuilder) GetTx() sdk.Tx { - return t.Tx -} - -func (t TxBuilder) SetMsgs(msgs ...sdk.Msg) error { - anys := make([]*codectypes.Any, len(msgs)) - for i, msg := range msgs { - pmsg, ok := msg.(proto.Message) - if !ok { - return fmt.Errorf("cannot proto marshal %T", msg) - } - any, err := codectypes.NewAnyWithValue(pmsg) - if err != nil { - return err - } - anys[i] = any - } - t.Body.Messages = anys - return nil -} - -func (t TxBuilder) GetSignatures() []sdk.Signature { - panic("implement me") -} - -func (t TxBuilder) SetSignatures(signature ...context.ClientSignature) error { - panic("implement me") -} - -func (t TxBuilder) GetFee() sdk.Fee { - panic("implement me") -} - -func (t TxBuilder) SetFee(fee context.ClientFee) error { - panic("implement me") -} - -func (t TxBuilder) GetMemo() string { - panic("implement me") -} - -func (t TxBuilder) SetMemo(s string) { - panic("implement me") -} - -func (t TxBuilder) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { - panic("implement me") -} diff --git a/x/bank/app_test.go b/x/bank/app_test.go index c30cfc9f1cc2..a7a88a79f31d 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -111,7 +111,7 @@ func TestSendNotEnoughBalance(t *testing.T) { sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) + _, _, err = simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{sdk.NewInt64Coin("foocoin", 67)}) @@ -178,7 +178,7 @@ func TestSendToModuleAcc(t *testing.T) { origSeq := res1.GetSequence() header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{test.msg}, []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1) + _, _, err = simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, []sdk.Msg{test.msg}, []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1) if test.expPass { require.NoError(t, err) } else { @@ -248,7 +248,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + _, _, err := simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) if tc.expPass { require.NoError(t, err) } else { @@ -299,7 +299,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + _, _, err := simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { @@ -353,7 +353,7 @@ func TestMsgMultiSendMultipleInOut(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + _, _, err := simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { @@ -405,7 +405,7 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + _, _, err := simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index a66e8d593d61..0261686eac01 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -33,7 +33,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { benchmarkApp.Commit() // Precompute all txs - txs := simapp.GenSequenceOfTxs([]sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) + txs := simapp.GenSequenceOfTxs(simapp.MakeEncodingConfig().TxGenerator, []sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) b.ResetTimer() height := int64(3) @@ -73,7 +73,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) { benchmarkApp.Commit() // Precompute all txs - txs := simapp.GenSequenceOfTxs([]sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) + txs := simapp.GenSequenceOfTxs(simapp.MakeEncodingConfig().TxGenerator, []sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) b.ResetTimer() height := int64(3) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 5974266acd73..8e5d4c5c2c86 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -104,15 +104,7 @@ func sendMsgSend( } } - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - privkeys..., - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, privkeys...) _, _, err = app.Deliver(tx) if err != nil { @@ -246,15 +238,7 @@ func sendMsgMultiSend( } } - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - accountNumbers, - sequenceNumbers, - privkeys..., - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, accountNumbers, sequenceNumbers, privkeys...) _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index cd1fbaa02061..5751d7230fe2 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -100,15 +100,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -147,15 +139,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -197,15 +181,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -247,15 +223,7 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k } msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - funder.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, funder.PrivKey) _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 05d47bee7e8e..33b5ececee12 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -142,15 +142,7 @@ func SimulateSubmitProposal( } } - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -224,15 +216,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } } - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -282,15 +266,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee return simtypes.NoOpMsg(types.ModuleName), nil, err } - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 112f598ab652..4e922fb31625 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -86,15 +86,7 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, res, err := app.Deliver(tx) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index c608ac7f6e1c..a65ce8cca890 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -151,15 +151,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k msg := types.NewMsgCreateValidator(address, simAccount.PubKey, selfDelegation, description, commission, sdk.OneInt()) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -217,15 +209,7 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -286,15 +270,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -368,15 +344,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper return simtypes.NoOpMsg(types.ModuleName), nil, err } - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -473,15 +441,7 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k sdk.NewCoin(k.BondDenom(ctx), redAmt), ) - tx := helpers.GenTx( - []sdk.Msg{msg}, - fees, - helpers.DefaultGenTxGas, - chainID, - []uint64{account.GetAccountNumber()}, - []uint64{account.GetSequence()}, - simAccount.PrivKey, - ) + tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { From 8e442a900edf465e9b55ded3854cd748b84a7c87 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 26 May 2020 13:07:09 -0400 Subject: [PATCH 32/54] Fix tests --- codec/any_test.go | 10 +++++----- x/slashing/app_test.go | 5 +++-- x/staking/app_test.go | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/codec/any_test.go b/codec/any_test.go index dbca831008f8..9cc0d8e4d7ff 100644 --- a/codec/any_test.go +++ b/codec/any_test.go @@ -26,29 +26,29 @@ func TestMarshalAny(t *testing.T) { cdc := NewProtoCodec(registry) kitty := &testdata.Cat{Moniker: "Kitty"} - bz, err := MarshalAny(cdc, kitty) + bz, err := cdc.MarshalAny(kitty) require.NoError(t, err) var animal testdata.Animal // empty registry should fail - err = UnmarshalAny(cdc, &animal, bz) + err = cdc.UnmarshalAny(bz, &animal) require.Error(t, err) // wrong type registration should fail registry.RegisterImplementations((*testdata.Animal)(nil), &testdata.Dog{}) - err = UnmarshalAny(cdc, &animal, bz) + err = cdc.UnmarshalAny(bz, &animal) require.Error(t, err) // should pass registry = NewTestInterfaceRegistry() cdc = NewProtoCodec(registry) - err = UnmarshalAny(cdc, &animal, bz) + err = cdc.UnmarshalAny(bz, &animal) require.NoError(t, err) require.Equal(t, kitty, animal) // nil should fail registry = NewTestInterfaceRegistry() - err = UnmarshalAny(cdc, nil, bz) + err = cdc.UnmarshalAny(bz, nil) require.Error(t, err) } diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index cc82ebd33996..256d1cc629f7 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -64,7 +64,8 @@ func TestSlashingMsgs(t *testing.T) { ) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -81,7 +82,7 @@ func TestSlashingMsgs(t *testing.T) { // unjail should fail with unknown validator header = abci.Header{Height: app.LastBlockHeight() + 1} - _, res, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{unjailMsg}, []uint64{0}, []uint64{1}, false, false, priv1) + _, res, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{unjailMsg}, []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) require.Nil(t, res) require.True(t, errors.Is(slashing.ErrValidatorNotJailed, err)) diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 635898ee923d..0a58872e8390 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -69,7 +69,8 @@ func TestStakingMsgs(t *testing.T) { ) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -89,7 +90,7 @@ func TestStakingMsgs(t *testing.T) { editValidatorMsg := staking.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil) header = abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1) + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1) require.NoError(t, err) validator = checkValidator(t, app, sdk.ValAddress(addr1), true) From 1f2aee7ed17d2a4d76aae2fcd1b3e1e34143f189 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 26 May 2020 14:07:03 -0400 Subject: [PATCH 33/54] Make sdk.Msg implement proto.Message --- crypto/multisig/threshold_pubkey.go | 2 +- crypto/types/types.pb.go | 102 ++++----- server/mock/tx.go | 13 ++ types/tx_msg.go | 15 ++ x/bank/app_test.go | 3 +- x/bank/handler.go | 8 +- x/bank/simulation/operations.go | 9 +- x/bank/types/msgs.go | 8 +- x/crisis/handler.go | 4 +- x/crisis/types/msgs.go | 4 +- x/distribution/handler.go | 16 +- x/distribution/types/msg.go | 16 +- x/evidence/types/msgs.go | 4 +- x/genutil/collect.go | 2 +- x/genutil/types/genesis_state.go | 2 +- x/gov/client/utils/query.go | 8 +- x/gov/handler.go | 8 +- x/gov/types/msgs.go | 12 +- x/ibc-transfer/handler.go | 4 +- x/ibc-transfer/types/msgs.go | 4 +- x/ibc/03-connection/handler.go | 8 +- x/ibc/03-connection/types/msgs.go | 24 +- x/ibc/04-channel/handler.go | 12 +- x/ibc/04-channel/types/msgs.go | 54 ++--- x/ibc/07-tendermint/types/msgs.go | 42 +++- x/ibc/09-localhost/types/msgs.go | 11 +- x/ibc/09-localhost/types/types.pb.go | 328 +++++++++++++++++++++++++++ x/ibc/09-localhost/types/types.proto | 11 + x/ibc/ante/ante.go | 6 +- x/ibc/handler.go | 26 +-- x/slashing/handler.go | 4 +- x/slashing/keeper/test_common.go | 6 +- x/slashing/types/msg.go | 4 +- x/staking/handler.go | 20 +- x/staking/types/msg.go | 20 +- 35 files changed, 609 insertions(+), 211 deletions(-) create mode 100644 x/ibc/09-localhost/types/types.pb.go create mode 100644 x/ibc/09-localhost/types/types.proto diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index 36e54bebfc48..55bce0c4f2a4 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -81,7 +81,7 @@ func DecodeMultisignatures(bz []byte) ([][]byte, error) { if len(multisig.XXX_unrecognized) > 0 { return nil, fmt.Errorf("rejecting unrecognized fields found in MultiSignature") } - return multisig.Sigs, nil + return multisig.Signatures, nil } func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool { diff --git a/crypto/types/types.pb.go b/crypto/types/types.pb.go index 7833f8d708a4..b9226268a71b 100644 --- a/crypto/types/types.pb.go +++ b/crypto/types/types.pb.go @@ -181,7 +181,7 @@ func (*PublicKey) XXX_OneofWrappers() []interface{} { // keys and a threshold type PubKeyMultisigThreshold struct { K uint32 `protobuf:"varint,1,opt,name=threshold,proto3" json:"threshold,omitempty" yaml:"threshold"` - PubKeys []*PublicKey `protobuf:"bytes,2,rep,name=pubkeys,proto3" json:"pubkeys,omitempty" yaml:"pubkeys"` + PubKeys []*PublicKey `protobuf:"bytes,2,rep,name=public_keys,json=publicKeys,proto3" json:"public_keys,omitempty" yaml:"pubkeys"` } func (m *PubKeyMultisigThreshold) Reset() { *m = PubKeyMultisigThreshold{} } @@ -235,7 +235,7 @@ func (m *PubKeyMultisigThreshold) GetPubKeys() []*PublicKey { // See cosmos_sdk.tx.v1.ModeInfo.Multi for how to specify which signers signed // and with which modes type MultiSignature struct { - Sigs [][]byte `protobuf:"bytes,1,rep,name=sigs,proto3" json:"sigs,omitempty"` + Signatures [][]byte `protobuf:"bytes,1,rep,name=signatures,proto3" json:"signatures,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -272,9 +272,9 @@ func (m *MultiSignature) XXX_DiscardUnknown() { var xxx_messageInfo_MultiSignature proto.InternalMessageInfo -func (m *MultiSignature) GetSigs() [][]byte { +func (m *MultiSignature) GetSignatures() [][]byte { if m != nil { - return m.Sigs + return m.Signatures } return nil } @@ -400,43 +400,43 @@ func init() { func init() { proto.RegisterFile("crypto/types/types.proto", fileDescriptor_2165b2a1badb1b0c) } var fileDescriptor_2165b2a1badb1b0c = []byte{ - // 571 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xcd, 0x6a, 0xdb, 0x4c, - 0x14, 0x95, 0xe2, 0x24, 0x4e, 0x26, 0x7f, 0xdf, 0x37, 0x04, 0xaa, 0x04, 0x2a, 0x19, 0x2d, 0x8a, - 0x1b, 0x88, 0x84, 0x5d, 0xdc, 0x9f, 0x6c, 0x4a, 0x94, 0x4d, 0xc0, 0x2d, 0x18, 0xa5, 0x8b, 0x52, - 0x28, 0x62, 0x24, 0x4d, 0x65, 0x61, 0x49, 0x23, 0x66, 0x46, 0xa5, 0xb3, 0xea, 0x2b, 0x74, 0xd9, - 0x65, 0xb2, 0xef, 0x83, 0x74, 0xe9, 0x65, 0x57, 0xa6, 0xd8, 0x4f, 0xd0, 0x3c, 0x41, 0xb1, 0x46, - 0xb2, 0x43, 0x89, 0x29, 0x74, 0x63, 0xcf, 0xdc, 0x73, 0xe6, 0x9c, 0x33, 0x73, 0xaf, 0x80, 0x16, - 0x50, 0x91, 0x73, 0x62, 0x73, 0x91, 0x63, 0x26, 0x7f, 0xad, 0x9c, 0x12, 0x4e, 0xe0, 0x61, 0x40, - 0x58, 0x4a, 0x98, 0xc7, 0xc2, 0x91, 0x25, 0x49, 0xd6, 0xc7, 0xce, 0xf1, 0x23, 0x3e, 0x8c, 0x69, - 0xe8, 0xe5, 0x88, 0x72, 0x61, 0x97, 0x44, 0x3b, 0x22, 0x11, 0x59, 0xae, 0xe4, 0xe9, 0xe3, 0xa3, - 0x88, 0x90, 0x28, 0xc1, 0x92, 0xe2, 0x17, 0x1f, 0x6c, 0x94, 0x09, 0x09, 0x99, 0xbf, 0xd6, 0xc0, - 0xf6, 0xa0, 0xf0, 0x93, 0x38, 0xe8, 0x63, 0x01, 0x75, 0xb0, 0xcd, 0x70, 0x90, 0x77, 0x7b, 0x4f, - 0x47, 0x1d, 0x4d, 0x6d, 0xa9, 0xed, 0xdd, 0x4b, 0xc5, 0x5d, 0x96, 0xe0, 0x31, 0x68, 0xe2, 0xb0, - 0xdb, 0xeb, 0x75, 0x5e, 0x68, 0x6b, 0x15, 0x5a, 0x17, 0xe6, 0x18, 0xa3, 0x12, 0x6b, 0xd4, 0x58, - 0x55, 0x80, 0x7d, 0xb0, 0x95, 0x16, 0x09, 0x8f, 0x59, 0x1c, 0x69, 0xeb, 0x2d, 0xb5, 0xbd, 0xd3, - 0x3d, 0xb5, 0xee, 0xbb, 0x91, 0x35, 0x28, 0xfc, 0x3e, 0x16, 0xaf, 0x2b, 0xee, 0x9b, 0x21, 0xc5, - 0x6c, 0x48, 0x92, 0xf0, 0x52, 0x71, 0x17, 0x02, 0x77, 0x42, 0xd2, 0x8e, 0xb6, 0xf1, 0x47, 0x48, - 0xda, 0x81, 0x08, 0xec, 0xa3, 0x34, 0xce, 0x88, 0xb7, 0xb0, 0xdc, 0x2c, 0x2d, 0x9f, 0xdf, 0x6f, - 0xf9, 0x0a, 0x47, 0x28, 0x10, 0xe7, 0xf3, 0x13, 0xab, 0xdd, 0xf7, 0x4a, 0xc5, 0x1a, 0x81, 0x3d, - 0x00, 0x50, 0x26, 0xbc, 0xbc, 0xf0, 0x47, 0x58, 0x68, 0x07, 0xa5, 0xfc, 0xa1, 0x25, 0x5f, 0xd9, - 0xaa, 0x5f, 0xd9, 0x3a, 0xcf, 0xc4, 0x3c, 0x19, 0xca, 0xc4, 0xa0, 0x24, 0x3a, 0x1b, 0xa0, 0xc1, - 0x8a, 0xd4, 0xfc, 0xa6, 0x82, 0x07, 0x2b, 0xac, 0xe0, 0x33, 0xb0, 0xcd, 0xeb, 0x4d, 0xd9, 0x81, - 0x3d, 0xe7, 0x68, 0x3a, 0x31, 0xd4, 0xfe, 0xed, 0xc4, 0xf8, 0x4f, 0xa0, 0x34, 0x39, 0x33, 0x17, - 0xb8, 0xe9, 0x2e, 0xb9, 0xf0, 0x2d, 0x68, 0xca, 0x38, 0x4c, 0x5b, 0x6b, 0x35, 0xda, 0x3b, 0x5d, - 0x63, 0xe5, 0x0b, 0xcb, 0x66, 0x3b, 0x0f, 0xa7, 0x13, 0xa3, 0x29, 0x73, 0xb0, 0xdb, 0x89, 0xb1, - 0x2f, 0xd5, 0x2b, 0x11, 0xd3, 0xad, 0xe5, 0xcc, 0x13, 0xb0, 0x5f, 0xe6, 0xbc, 0x8a, 0xa3, 0x0c, - 0xf1, 0x82, 0x62, 0x08, 0xc1, 0x3a, 0x8b, 0x23, 0xa6, 0xa9, 0xad, 0x46, 0x7b, 0xd7, 0x2d, 0xd7, - 0x67, 0xeb, 0xe3, 0x1b, 0x43, 0x35, 0xdf, 0x83, 0x83, 0x0b, 0x92, 0xe6, 0x28, 0xe0, 0x4e, 0xcc, - 0xcf, 0x29, 0x45, 0x02, 0x9e, 0x80, 0xff, 0xf1, 0x27, 0x4e, 0x91, 0xe7, 0xc7, 0x9c, 0x79, 0x8c, - 0x13, 0x8a, 0xab, 0x9b, 0xb9, 0x07, 0x25, 0xe0, 0xc4, 0x9c, 0x5d, 0x95, 0x65, 0x78, 0x08, 0x36, - 0x70, 0x82, 0x53, 0x26, 0xa7, 0xcb, 0x95, 0x9b, 0xb3, 0xad, 0xaf, 0xd7, 0x86, 0x72, 0x7d, 0x63, - 0x28, 0xe6, 0x67, 0x60, 0xfe, 0xbd, 0x5d, 0xf0, 0x25, 0x68, 0xcc, 0xdb, 0xa2, 0xfe, 0xc3, 0xa0, - 0xb9, 0xf3, 0x93, 0x50, 0x03, 0x4d, 0x14, 0x86, 0x14, 0xb3, 0x3a, 0x48, 0xbd, 0x75, 0x2e, 0xbe, - 0x4f, 0x75, 0x75, 0x3c, 0xd5, 0xd5, 0x9f, 0x53, 0x5d, 0xfd, 0x32, 0xd3, 0x95, 0xf1, 0x4c, 0x57, - 0x7e, 0xcc, 0x74, 0xe5, 0xdd, 0xe3, 0x28, 0xe6, 0xc3, 0xc2, 0xb7, 0x02, 0x92, 0xda, 0xd2, 0xb1, - 0xfa, 0x3b, 0x65, 0xe1, 0xc8, 0xbe, 0xfb, 0x61, 0xfb, 0x9b, 0xe5, 0x84, 0x3c, 0xf9, 0x1d, 0x00, - 0x00, 0xff, 0xff, 0x72, 0x3e, 0x39, 0x5c, 0xef, 0x03, 0x00, 0x00, + // 574 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x8b, 0xd3, 0x40, + 0x18, 0x4e, 0xb6, 0xfb, 0x39, 0xfb, 0xa5, 0xc3, 0x82, 0xd9, 0x05, 0x93, 0x92, 0x83, 0x54, 0x61, + 0x13, 0x5a, 0xe9, 0xaa, 0xbd, 0x48, 0xb3, 0x97, 0x85, 0x2a, 0x94, 0xac, 0x27, 0x41, 0xc2, 0x24, + 0x19, 0xd3, 0xd0, 0x24, 0x13, 0x66, 0x26, 0xe2, 0x9c, 0xfc, 0x0b, 0x1e, 0x3d, 0xee, 0xfe, 0x06, + 0xff, 0x84, 0xc7, 0x1e, 0x3d, 0x15, 0x69, 0x7f, 0x81, 0xfb, 0x0b, 0xa4, 0x99, 0xa6, 0x2d, 0xb2, + 0x45, 0xf0, 0x92, 0xe4, 0x7d, 0x9f, 0x67, 0xe6, 0x79, 0xde, 0x8f, 0x00, 0x2d, 0xa0, 0x22, 0xe7, + 0xc4, 0xe6, 0x22, 0xc7, 0x4c, 0x3e, 0xad, 0x9c, 0x12, 0x4e, 0xe0, 0x49, 0x40, 0x58, 0x4a, 0x98, + 0xc7, 0xc2, 0xa1, 0x25, 0x49, 0xd6, 0xa7, 0xe6, 0xd9, 0x13, 0x3e, 0x88, 0x69, 0xe8, 0xe5, 0x88, + 0x72, 0x61, 0x97, 0x44, 0x3b, 0x22, 0x11, 0x59, 0x7e, 0xc9, 0xd3, 0x67, 0xa7, 0x11, 0x21, 0x51, + 0x82, 0x25, 0xc5, 0x2f, 0x3e, 0xda, 0x28, 0x13, 0x12, 0x32, 0x7f, 0x6f, 0x80, 0xbd, 0x7e, 0xe1, + 0x27, 0x71, 0xd0, 0xc3, 0x02, 0xea, 0x60, 0x8f, 0xe1, 0x20, 0x6f, 0xb5, 0x2f, 0x86, 0x4d, 0x4d, + 0xad, 0xab, 0x8d, 0x83, 0x2b, 0xc5, 0x5d, 0xa6, 0xe0, 0x19, 0xd8, 0xc1, 0x61, 0xab, 0xdd, 0x6e, + 0xbe, 0xd2, 0x36, 0xe6, 0x68, 0x95, 0x98, 0x61, 0x8c, 0x4a, 0xac, 0x56, 0x61, 0xf3, 0x04, 0xec, + 0x81, 0xdd, 0xb4, 0x48, 0x78, 0xcc, 0xe2, 0x48, 0xdb, 0xac, 0xab, 0x8d, 0xfd, 0xd6, 0xb9, 0x75, + 0x5f, 0x45, 0x56, 0xbf, 0xf0, 0x7b, 0x58, 0xbc, 0x9d, 0x73, 0xdf, 0x0d, 0x28, 0x66, 0x03, 0x92, + 0x84, 0x57, 0x8a, 0xbb, 0xb8, 0x60, 0xc5, 0x24, 0x6d, 0x6a, 0x5b, 0x7f, 0x99, 0xa4, 0x4d, 0x88, + 0xc0, 0x11, 0x4a, 0xe3, 0x8c, 0x78, 0x0b, 0xc9, 0xed, 0x52, 0xf2, 0xe5, 0xfd, 0x92, 0x6f, 0x70, + 0x84, 0x02, 0xd1, 0x9d, 0x9d, 0x58, 0xaf, 0x7e, 0x58, 0xde, 0x58, 0x21, 0xb0, 0x0d, 0x00, 0xca, + 0x84, 0x97, 0x17, 0xfe, 0x10, 0x0b, 0xed, 0xb8, 0xbc, 0xfe, 0xc4, 0x92, 0x5d, 0xb6, 0xaa, 0x2e, + 0x5b, 0xdd, 0x4c, 0xcc, 0x9c, 0xa1, 0x4c, 0xf4, 0x4b, 0xa2, 0xb3, 0x05, 0x6a, 0xac, 0x48, 0xcd, + 0xef, 0x2a, 0x78, 0xb4, 0x46, 0x0a, 0xbe, 0x00, 0x7b, 0xbc, 0x0a, 0xca, 0x09, 0x1c, 0x3a, 0xa7, + 0x93, 0xb1, 0xa1, 0xf6, 0xee, 0xc6, 0xc6, 0x03, 0x81, 0xd2, 0xa4, 0x63, 0x2e, 0x70, 0xd3, 0x5d, + 0x72, 0xa1, 0x07, 0xf6, 0xf3, 0x72, 0x8e, 0xde, 0x10, 0x0b, 0xa6, 0x6d, 0xd4, 0x6b, 0x8d, 0xfd, + 0x96, 0xb1, 0xb6, 0xcb, 0x72, 0xe0, 0xce, 0xe3, 0xc9, 0xd8, 0xd8, 0x91, 0x5e, 0xd8, 0xdd, 0xd8, + 0x38, 0x92, 0x0a, 0xb2, 0x2e, 0x66, 0xba, 0x20, 0xaf, 0x98, 0xcc, 0xbc, 0x00, 0x47, 0xa5, 0xdd, + 0xeb, 0x38, 0xca, 0x10, 0x2f, 0x28, 0x86, 0x3a, 0x00, 0xac, 0x0a, 0x98, 0xa6, 0xd6, 0x6b, 0x8d, + 0x03, 0x77, 0x25, 0xd3, 0xd9, 0x1c, 0xdd, 0x1a, 0xaa, 0xf9, 0x01, 0x1c, 0x5f, 0x92, 0x34, 0x47, + 0x01, 0x77, 0x62, 0xde, 0xa5, 0x14, 0x09, 0xf8, 0x0c, 0x3c, 0xc4, 0x9f, 0x39, 0x45, 0x9e, 0x1f, + 0x73, 0xe6, 0x31, 0x4e, 0x28, 0x9e, 0x17, 0xeb, 0x1e, 0x97, 0x80, 0x13, 0x73, 0x76, 0x5d, 0xa6, + 0xe1, 0x09, 0xd8, 0xc2, 0x09, 0x4e, 0x99, 0x5c, 0x38, 0x57, 0x06, 0x9d, 0xdd, 0x6f, 0x37, 0x86, + 0x72, 0x73, 0x6b, 0x28, 0xe6, 0x17, 0x60, 0xfe, 0x7b, 0x82, 0xf0, 0x35, 0xa8, 0xcd, 0x26, 0xa5, + 0xfe, 0xc7, 0xee, 0xb9, 0xb3, 0x93, 0x50, 0x03, 0x3b, 0x28, 0x0c, 0x29, 0x66, 0x95, 0x91, 0x2a, + 0x74, 0x2e, 0x7f, 0x4c, 0x74, 0x75, 0x34, 0xd1, 0xd5, 0x5f, 0x13, 0x5d, 0xfd, 0x3a, 0xd5, 0x95, + 0xd1, 0x54, 0x57, 0x7e, 0x4e, 0x75, 0xe5, 0xfd, 0xd3, 0x28, 0xe6, 0x83, 0xc2, 0xb7, 0x02, 0x92, + 0xda, 0x52, 0x71, 0xfe, 0x3a, 0x67, 0xe1, 0xd0, 0x5e, 0xfd, 0xd7, 0xfd, 0xed, 0x72, 0x69, 0x9e, + 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x76, 0x08, 0x4c, 0x4e, 0x02, 0x04, 0x00, 0x00, } func (m *PublicKey) Marshal() (dAtA []byte, err error) { @@ -664,11 +664,11 @@ func (m *MultiSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } - if len(m.Sigs) > 0 { - for iNdEx := len(m.Sigs) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Sigs[iNdEx]) - copy(dAtA[i:], m.Sigs[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Sigs[iNdEx]))) + if len(m.Signatures) > 0 { + for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Signatures[iNdEx]) + copy(dAtA[i:], m.Signatures[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Signatures[iNdEx]))) i-- dAtA[i] = 0xa } @@ -884,8 +884,8 @@ func (m *MultiSignature) Size() (n int) { } var l int _ = l - if len(m.Sigs) > 0 { - for _, b := range m.Sigs { + if len(m.Signatures) > 0 { + for _, b := range m.Signatures { l = len(b) n += 1 + l + sovTypes(uint64(l)) } @@ -1346,7 +1346,7 @@ func (m *MultiSignature) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sigs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1373,8 +1373,8 @@ func (m *MultiSignature) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Sigs = append(m.Sigs, make([]byte, postIndex-iNdEx)) - copy(m.Sigs[len(m.Sigs)-1], dAtA[iNdEx:postIndex]) + m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) + copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/server/mock/tx.go b/server/mock/tx.go index 27441051ce8a..e83a3f1a868b 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -16,7 +16,20 @@ type kvstoreTx struct { bytes []byte } +func (tx kvstoreTx) Reset() { + panic("implement me") +} + +func (tx kvstoreTx) String() string { + panic("implement me") +} + +func (tx kvstoreTx) ProtoMessage() { + panic("implement me") +} + var _ sdk.Tx = kvstoreTx{} +var _ sdk.Msg = kvstoreTx{} func NewTx(key, value string) kvstoreTx { bytes := fmt.Sprintf("%s=%s", key, value) diff --git a/types/tx_msg.go b/types/tx_msg.go index 9123cd9be94a..a84d361538b7 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -3,12 +3,15 @@ package types import ( "encoding/json" + "github.com/gogo/protobuf/proto" + "github.com/tendermint/tendermint/crypto" ) type ( // Msg defines the interface a transaction message must fulfill. Msg interface { + proto.Message // Return the message type. // Must be alphanumeric or empty. @@ -71,6 +74,18 @@ type TestMsg struct { signers []AccAddress } +func (msg *TestMsg) Reset() { + panic("implement me") +} + +func (msg *TestMsg) String() string { + panic("implement me") +} + +func (msg *TestMsg) ProtoMessage() { + panic("implement me") +} + func NewTestMsg(addrs ...AccAddress) *TestMsg { return &TestMsg{ signers: addrs, diff --git a/x/bank/app_test.go b/x/bank/app_test.go index a7a88a79f31d..b4d8f0edbfc1 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -405,7 +405,8 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txGen := app.GetEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { diff --git a/x/bank/handler.go b/x/bank/handler.go index 5ec0033bce82..6cd77d22a7fe 100644 --- a/x/bank/handler.go +++ b/x/bank/handler.go @@ -13,10 +13,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case types.MsgSend: + case *types.MsgSend: return handleMsgSend(ctx, k, msg) - case types.MsgMultiSend: + case *types.MsgMultiSend: return handleMsgMultiSend(ctx, k, msg) default: @@ -26,7 +26,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { } // Handle MsgSend. -func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgSend) (*sdk.Result, error) { +func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg *types.MsgSend) (*sdk.Result, error) { if !k.GetSendEnabled(ctx) { return nil, types.ErrSendDisabled } @@ -51,7 +51,7 @@ func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgSend) (*sdk.Re } // Handle MsgMultiSend. -func handleMsgMultiSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgMultiSend) (*sdk.Result, error) { +func handleMsgMultiSend(ctx sdk.Context, k keeper.Keeper, msg *types.MsgMultiSend) (*sdk.Result, error) { // NOTE: totalIn == totalOut should already have been checked if !k.GetSendEnabled(ctx) { return nil, types.ErrSendDisabled diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 8e5d4c5c2c86..be9adf05ff29 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -85,7 +85,7 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio // nolint: interfacer func sendMsgSend( r *rand.Rand, app *baseapp.BaseApp, bk keeper.Keeper, ak types.AccountKeeper, - msg types.MsgSend, ctx sdk.Context, chainID string, privkeys []crypto.PrivKey, + msg *types.MsgSend, ctx sdk.Context, chainID string, privkeys []crypto.PrivKey, ) error { var ( @@ -190,7 +190,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope } } - msg := types.MsgMultiSend{ + msg := &types.MsgMultiSend{ Inputs: inputs, Outputs: outputs, } @@ -207,10 +207,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope // sendMsgMultiSend sends a transaction with a MsgMultiSend from a provided random // account. // nolint: interfacer -func sendMsgMultiSend( - r *rand.Rand, app *baseapp.BaseApp, bk keeper.Keeper, ak types.AccountKeeper, - msg types.MsgMultiSend, ctx sdk.Context, chainID string, privkeys []crypto.PrivKey, -) error { +func sendMsgMultiSend(r *rand.Rand, app *baseapp.BaseApp, bk keeper.Keeper, ak types.AccountKeeper, msg *types.MsgMultiSend, ctx sdk.Context, chainID string, privkeys []crypto.PrivKey) error { accountNumbers := make([]uint64, len(msg.Inputs)) sequenceNumbers := make([]uint64, len(msg.Inputs)) diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index f250eb20751e..ead54cc9a6c7 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -5,11 +5,11 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -var _ sdk.Msg = MsgSend{} +var _ sdk.Msg = &MsgSend{} // NewMsgSend - construct arbitrary multi-in, multi-out send msg. -func NewMsgSend(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) MsgSend { - return MsgSend{FromAddress: fromAddr, ToAddress: toAddr, Amount: amount} +func NewMsgSend(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgSend { + return &MsgSend{FromAddress: fromAddr, ToAddress: toAddr, Amount: amount} } // Route Implements Msg. @@ -49,7 +49,7 @@ func (msg MsgSend) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.FromAddress} } -var _ sdk.Msg = MsgMultiSend{} +var _ sdk.Msg = &MsgMultiSend{} // NewMsgMultiSend - construct arbitrary multi-in, multi-out send msg. func NewMsgMultiSend(in []Input, out []Output) MsgMultiSend { diff --git a/x/crisis/handler.go b/x/crisis/handler.go index 733207c10040..83c7fd7ac421 100644 --- a/x/crisis/handler.go +++ b/x/crisis/handler.go @@ -15,7 +15,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case types.MsgVerifyInvariant: + case *types.MsgVerifyInvariant: return handleMsgVerifyInvariant(ctx, msg, k) default: @@ -24,7 +24,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { } } -func handleMsgVerifyInvariant(ctx sdk.Context, msg types.MsgVerifyInvariant, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgVerifyInvariant(ctx sdk.Context, msg *types.MsgVerifyInvariant, k keeper.Keeper) (*sdk.Result, error) { constantFee := sdk.NewCoins(k.GetConstantFee(ctx)) if err := k.SendCoinsFromAccountToFeeCollector(ctx, msg.Sender, constantFee); err != nil { diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index 349977fc8f3f..4d3a2fa3c212 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -9,9 +9,9 @@ var _ sdk.Msg = &MsgVerifyInvariant{} // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object func NewMsgVerifyInvariant(sender sdk.AccAddress, invariantModuleName, - invariantRoute string) MsgVerifyInvariant { + invariantRoute string) *MsgVerifyInvariant { - return MsgVerifyInvariant{ + return &MsgVerifyInvariant{ Sender: sender, InvariantModuleName: invariantModuleName, InvariantRoute: invariantRoute, diff --git a/x/distribution/handler.go b/x/distribution/handler.go index fa6ea6ec67e0..2e8c86ce0376 100644 --- a/x/distribution/handler.go +++ b/x/distribution/handler.go @@ -13,16 +13,16 @@ func NewHandler(k keeper.Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case types.MsgSetWithdrawAddress: + case *types.MsgSetWithdrawAddress: return handleMsgModifyWithdrawAddress(ctx, msg, k) - case types.MsgWithdrawDelegatorReward: + case *types.MsgWithdrawDelegatorReward: return handleMsgWithdrawDelegatorReward(ctx, msg, k) - case types.MsgWithdrawValidatorCommission: + case *types.MsgWithdrawValidatorCommission: return handleMsgWithdrawValidatorCommission(ctx, msg, k) - case types.MsgFundCommunityPool: + case *types.MsgFundCommunityPool: return handleMsgFundCommunityPool(ctx, msg, k) default: @@ -33,7 +33,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { // These functions assume everything has been authenticated (ValidateBasic passed, and signatures checked) -func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAddress, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg *types.MsgSetWithdrawAddress, k keeper.Keeper) (*sdk.Result, error) { err := k.SetWithdrawAddr(ctx, msg.DelegatorAddress, msg.WithdrawAddress) if err != nil { return nil, err @@ -50,7 +50,7 @@ func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAdd return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDelegatorReward, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg *types.MsgWithdrawDelegatorReward, k keeper.Keeper) (*sdk.Result, error) { _, err := k.WithdrawDelegationRewards(ctx, msg.DelegatorAddress, msg.ValidatorAddress) if err != nil { return nil, err @@ -67,7 +67,7 @@ func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDele return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg types.MsgWithdrawValidatorCommission, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg *types.MsgWithdrawValidatorCommission, k keeper.Keeper) (*sdk.Result, error) { _, err := k.WithdrawValidatorCommission(ctx, msg.ValidatorAddress) if err != nil { return nil, err @@ -84,7 +84,7 @@ func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg types.MsgWithdraw return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgFundCommunityPool(ctx sdk.Context, msg types.MsgFundCommunityPool, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgFundCommunityPool(ctx sdk.Context, msg *types.MsgFundCommunityPool, k keeper.Keeper) (*sdk.Result, error) { if err := k.FundCommunityPool(ctx, msg.Amount, msg.Depositor); err != nil { return nil, err } diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index 4641c95663e9..3fdeb0d75d76 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -9,8 +9,8 @@ import ( // Verify interface at compile time var _, _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorCommission{} -func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress { - return MsgSetWithdrawAddress{ +func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { + return &MsgSetWithdrawAddress{ DelegatorAddress: delAddr, WithdrawAddress: withdrawAddr, } @@ -42,8 +42,8 @@ func (msg MsgSetWithdrawAddress) ValidateBasic() error { return nil } -func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegatorReward { - return MsgWithdrawDelegatorReward{ +func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) *MsgWithdrawDelegatorReward { + return &MsgWithdrawDelegatorReward{ DelegatorAddress: delAddr, ValidatorAddress: valAddr, } @@ -74,8 +74,8 @@ func (msg MsgWithdrawDelegatorReward) ValidateBasic() error { return nil } -func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) MsgWithdrawValidatorCommission { - return MsgWithdrawValidatorCommission{ +func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) *MsgWithdrawValidatorCommission { + return &MsgWithdrawValidatorCommission{ ValidatorAddress: valAddr, } } @@ -106,8 +106,8 @@ const TypeMsgFundCommunityPool = "fund_community_pool" // NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and // a funding amount. -func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) MsgFundCommunityPool { - return MsgFundCommunityPool{ +func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFundCommunityPool { + return &MsgFundCommunityPool{ Amount: amount, Depositor: depositor, } diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index 223904b1dc6b..1d6875cbfc38 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -17,9 +17,9 @@ const ( ) var ( - _ sdk.Msg = MsgSubmitEvidence{} + _ sdk.Msg = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} - _ exported.MsgSubmitEvidence = MsgSubmitEvidence{} + _ exported.MsgSubmitEvidence = &MsgSubmitEvidence{} ) // NewMsgSubmitEvidence returns a new MsgSubmitEvidence with a signer/submitter. diff --git a/x/genutil/collect.go b/x/genutil/collect.go index f02ae9b323f9..e7d3d35c03c0 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -133,7 +133,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker, genTxsDir string, } // TODO abstract out staking message validation back to staking - msg := msgs[0].(stakingtypes.MsgCreateValidator) + msg := msgs[0].(*stakingtypes.MsgCreateValidator) // validate delegator and validator addresses and funds against the accounts in the state delAddr := msg.DelegatorAddress.String() diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index 453ecdedc9a4..e8ec56f8a15f 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -112,7 +112,7 @@ func ValidateGenesis(genesisState GenesisState) error { } // TODO: abstract back to staking - if _, ok := msgs[0].(stakingtypes.MsgCreateValidator); !ok { + if _, ok := msgs[0].(*stakingtypes.MsgCreateValidator); !ok { return fmt.Errorf( "genesis transaction %v does not contain a MsgCreateValidator", i) } diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index 3b092ccccf0a..d8fda5e87918 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -55,7 +55,7 @@ func QueryDepositsByTxQuery(cliCtx context.CLIContext, params types.QueryProposa for _, info := range searchResult.Txs { for _, msg := range info.Tx.GetMsgs() { if msg.Type() == types.TypeMsgDeposit { - depMsg := msg.(types.MsgDeposit) + depMsg := msg.(*types.MsgDeposit) deposits = append(deposits, types.Deposit{ Depositor: depMsg.Depositor, @@ -96,7 +96,7 @@ func QueryVotesByTxQuery(cliCtx context.CLIContext, params types.QueryProposalVo for _, info := range searchResult.Txs { for _, msg := range info.Tx.GetMsgs() { if msg.Type() == types.TypeMsgVote { - voteMsg := msg.(types.MsgVote) + voteMsg := msg.(*types.MsgVote) votes = append(votes, types.Vote{ Voter: voteMsg.Voter, @@ -140,7 +140,7 @@ func QueryVoteByTxQuery(cliCtx context.CLIContext, params types.QueryVoteParams) for _, msg := range info.Tx.GetMsgs() { // there should only be a single vote under the given conditions if msg.Type() == types.TypeMsgVote { - voteMsg := msg.(types.MsgVote) + voteMsg := msg.(*types.MsgVote) vote := types.Vote{ Voter: voteMsg.Voter, @@ -180,7 +180,7 @@ func QueryDepositByTxQuery(cliCtx context.CLIContext, params types.QueryDepositP for _, msg := range info.Tx.GetMsgs() { // there should only be a single deposit under the given conditions if msg.Type() == types.TypeMsgDeposit { - depMsg := msg.(types.MsgDeposit) + depMsg := msg.(*types.MsgDeposit) deposit := types.Deposit{ Depositor: depMsg.Depositor, diff --git a/x/gov/handler.go b/x/gov/handler.go index 02edefcdbd80..2805e4f87953 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -14,13 +14,13 @@ func NewHandler(keeper Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case MsgDeposit: + case *MsgDeposit: return handleMsgDeposit(ctx, keeper, msg) case MsgSubmitProposalI: return handleMsgSubmitProposal(ctx, keeper, msg) - case MsgVote: + case *MsgVote: return handleMsgVote(ctx, keeper, msg) default: @@ -63,7 +63,7 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos }, nil } -func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) (*sdk.Result, error) { +func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg *MsgDeposit) (*sdk.Result, error) { votingStarted, err := keeper.AddDeposit(ctx, msg.ProposalID, msg.Depositor, msg.Amount) if err != nil { return nil, err @@ -89,7 +89,7 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) (*sdk.Resu return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) (*sdk.Result, error) { +func handleMsgVote(ctx sdk.Context, keeper Keeper, msg *MsgVote) (*sdk.Result, error) { err := keeper.AddVote(ctx, msg.ProposalID, msg.Voter, msg.Option) if err != nil { return nil, err diff --git a/x/gov/types/msgs.go b/x/gov/types/msgs.go index a818ee2a3c48..c6d57b87df98 100644 --- a/x/gov/types/msgs.go +++ b/x/gov/types/msgs.go @@ -20,9 +20,9 @@ const ( ) var ( - _, _, _ sdk.Msg = MsgSubmitProposal{}, MsgDeposit{}, MsgVote{} + _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{} _ MsgSubmitProposalI = &MsgSubmitProposal{} - _ types.UnpackInterfacesMessage = MsgSubmitProposal{} + _ types.UnpackInterfacesMessage = &MsgSubmitProposal{} ) // MsgSubmitProposalI defines the specific interface a concrete message must @@ -143,8 +143,8 @@ func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error { } // NewMsgDeposit creates a new MsgDeposit instance -func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins) MsgDeposit { - return MsgDeposit{proposalID, depositor, amount} +func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins) *MsgDeposit { + return &MsgDeposit{proposalID, depositor, amount} } // Route implements Msg @@ -186,8 +186,8 @@ func (msg MsgDeposit) GetSigners() []sdk.AccAddress { } // NewMsgVote creates a message to cast a vote on an active proposal -func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) MsgVote { - return MsgVote{proposalID, voter, option} +func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) *MsgVote { + return &MsgVote{proposalID, voter, option} } // Route implements Msg diff --git a/x/ibc-transfer/handler.go b/x/ibc-transfer/handler.go index 0745febdf645..f5e30fc1f880 100644 --- a/x/ibc-transfer/handler.go +++ b/x/ibc-transfer/handler.go @@ -11,7 +11,7 @@ func NewHandler(k Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case MsgTransfer: + case *MsgTransfer: return handleMsgTransfer(ctx, k, msg) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ICS-20 transfer message type: %T", msg) @@ -20,7 +20,7 @@ func NewHandler(k Keeper) sdk.Handler { } // See createOutgoingPacket in spec:https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay -func handleMsgTransfer(ctx sdk.Context, k Keeper, msg MsgTransfer) (*sdk.Result, error) { +func handleMsgTransfer(ctx sdk.Context, k Keeper, msg *MsgTransfer) (*sdk.Result, error) { if err := k.SendTransfer( ctx, msg.SourcePort, msg.SourceChannel, msg.DestinationHeight, msg.Amount, msg.Sender, msg.Receiver, ); err != nil { diff --git a/x/ibc-transfer/types/msgs.go b/x/ibc-transfer/types/msgs.go index 6b0eb8c92434..eb69fbf220e2 100644 --- a/x/ibc-transfer/types/msgs.go +++ b/x/ibc-transfer/types/msgs.go @@ -14,8 +14,8 @@ const ( // NewMsgTransfer creates a new MsgTransfer instance func NewMsgTransfer( sourcePort, sourceChannel string, destHeight uint64, amount sdk.Coins, sender sdk.AccAddress, receiver string, -) MsgTransfer { - return MsgTransfer{ +) *MsgTransfer { + return &MsgTransfer{ SourcePort: sourcePort, SourceChannel: sourceChannel, DestinationHeight: destHeight, diff --git a/x/ibc/03-connection/handler.go b/x/ibc/03-connection/handler.go index fc89687a7669..1b3c7a4342b1 100644 --- a/x/ibc/03-connection/handler.go +++ b/x/ibc/03-connection/handler.go @@ -6,7 +6,7 @@ import ( ) // HandleMsgConnectionOpenInit defines the sdk.Handler for MsgConnectionOpenInit -func HandleMsgConnectionOpenInit(ctx sdk.Context, k Keeper, msg MsgConnectionOpenInit) (*sdk.Result, error) { +func HandleMsgConnectionOpenInit(ctx sdk.Context, k Keeper, msg *MsgConnectionOpenInit) (*sdk.Result, error) { if err := k.ConnOpenInit( ctx, msg.ConnectionID, msg.ClientID, msg.Counterparty, ); err != nil { @@ -32,7 +32,7 @@ func HandleMsgConnectionOpenInit(ctx sdk.Context, k Keeper, msg MsgConnectionOpe } // HandleMsgConnectionOpenTry defines the sdk.Handler for MsgConnectionOpenTry -func HandleMsgConnectionOpenTry(ctx sdk.Context, k Keeper, msg MsgConnectionOpenTry) (*sdk.Result, error) { +func HandleMsgConnectionOpenTry(ctx sdk.Context, k Keeper, msg *MsgConnectionOpenTry) (*sdk.Result, error) { if err := k.ConnOpenTry( ctx, msg.ConnectionID, msg.Counterparty, msg.ClientID, msg.CounterpartyVersions, msg.ProofInit, msg.ProofConsensus, @@ -60,7 +60,7 @@ func HandleMsgConnectionOpenTry(ctx sdk.Context, k Keeper, msg MsgConnectionOpen } // HandleMsgConnectionOpenAck defines the sdk.Handler for MsgConnectionOpenAck -func HandleMsgConnectionOpenAck(ctx sdk.Context, k Keeper, msg MsgConnectionOpenAck) (*sdk.Result, error) { +func HandleMsgConnectionOpenAck(ctx sdk.Context, k Keeper, msg *MsgConnectionOpenAck) (*sdk.Result, error) { if err := k.ConnOpenAck( ctx, msg.ConnectionID, msg.Version, msg.ProofTry, msg.ProofConsensus, msg.ProofHeight, msg.ConsensusHeight, @@ -85,7 +85,7 @@ func HandleMsgConnectionOpenAck(ctx sdk.Context, k Keeper, msg MsgConnectionOpen } // HandleMsgConnectionOpenConfirm defines the sdk.Handler for MsgConnectionOpenConfirm -func HandleMsgConnectionOpenConfirm(ctx sdk.Context, k Keeper, msg MsgConnectionOpenConfirm) (*sdk.Result, error) { +func HandleMsgConnectionOpenConfirm(ctx sdk.Context, k Keeper, msg *MsgConnectionOpenConfirm) (*sdk.Result, error) { if err := k.ConnOpenConfirm( ctx, msg.ConnectionID, msg.ProofAck, msg.ProofHeight, ); err != nil { diff --git a/x/ibc/03-connection/types/msgs.go b/x/ibc/03-connection/types/msgs.go index f459abd6c916..669525040cc4 100644 --- a/x/ibc/03-connection/types/msgs.go +++ b/x/ibc/03-connection/types/msgs.go @@ -9,16 +9,16 @@ import ( host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) -var _ sdk.Msg = MsgConnectionOpenInit{} +var _ sdk.Msg = &MsgConnectionOpenInit{} // NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance func NewMsgConnectionOpenInit( connectionID, clientID, counterpartyConnectionID, counterpartyClientID string, counterpartyPrefix commitmenttypes.MerklePrefix, signer sdk.AccAddress, -) MsgConnectionOpenInit { +) *MsgConnectionOpenInit { counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix) - return MsgConnectionOpenInit{ + return &MsgConnectionOpenInit{ ConnectionID: connectionID, ClientID: clientID, Counterparty: counterparty, @@ -60,7 +60,7 @@ func (msg MsgConnectionOpenInit) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgConnectionOpenTry{} +var _ sdk.Msg = &MsgConnectionOpenTry{} // NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance func NewMsgConnectionOpenTry( @@ -68,9 +68,9 @@ func NewMsgConnectionOpenTry( counterpartyClientID string, counterpartyPrefix commitmenttypes.MerklePrefix, counterpartyVersions []string, proofInit, proofConsensus commitmenttypes.MerkleProof, proofHeight, consensusHeight uint64, signer sdk.AccAddress, -) MsgConnectionOpenTry { +) *MsgConnectionOpenTry { counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix) - return MsgConnectionOpenTry{ + return &MsgConnectionOpenTry{ ConnectionID: connectionID, ClientID: clientID, Counterparty: counterparty, @@ -140,15 +140,15 @@ func (msg MsgConnectionOpenTry) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgConnectionOpenAck{} +var _ sdk.Msg = &MsgConnectionOpenAck{} // NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance func NewMsgConnectionOpenAck( connectionID string, proofTry, proofConsensus commitmenttypes.MerkleProof, proofHeight, consensusHeight uint64, version string, signer sdk.AccAddress, -) MsgConnectionOpenAck { - return MsgConnectionOpenAck{ +) *MsgConnectionOpenAck { + return &MsgConnectionOpenAck{ ConnectionID: connectionID, ProofTry: proofTry, ProofConsensus: proofConsensus, @@ -208,14 +208,14 @@ func (msg MsgConnectionOpenAck) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgConnectionOpenConfirm{} +var _ sdk.Msg = &MsgConnectionOpenConfirm{} // NewMsgConnectionOpenConfirm creates a new MsgConnectionOpenConfirm instance func NewMsgConnectionOpenConfirm( connectionID string, proofAck commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgConnectionOpenConfirm { - return MsgConnectionOpenConfirm{ +) *MsgConnectionOpenConfirm { + return &MsgConnectionOpenConfirm{ ConnectionID: connectionID, ProofAck: proofAck, ProofHeight: proofHeight, diff --git a/x/ibc/04-channel/handler.go b/x/ibc/04-channel/handler.go index c79c2991f254..47c2ba805e7f 100644 --- a/x/ibc/04-channel/handler.go +++ b/x/ibc/04-channel/handler.go @@ -8,7 +8,7 @@ import ( ) // HandleMsgChannelOpenInit defines the sdk.Handler for MsgChannelOpenInit -func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, portCap *capability.Capability, msg types.MsgChannelOpenInit) (*sdk.Result, *capability.Capability, error) { +func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, portCap *capability.Capability, msg *MsgChannelOpenInit) (*sdk.Result, *capability.Capability, error) { capKey, err := k.ChanOpenInit( ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortID, msg.ChannelID, portCap, msg.Channel.Counterparty, msg.Channel.Version, @@ -38,7 +38,7 @@ func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, portCap *capabil } // HandleMsgChannelOpenTry defines the sdk.Handler for MsgChannelOpenTry -func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, portCap *capability.Capability, msg types.MsgChannelOpenTry) (*sdk.Result, *capability.Capability, error) { +func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, portCap *capability.Capability, msg *MsgChannelOpenTry) (*sdk.Result, *capability.Capability, error) { capKey, err := k.ChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortID, msg.ChannelID, portCap, msg.Channel.Counterparty, msg.Channel.Version, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, ) @@ -67,7 +67,7 @@ func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, portCap *capabili } // HandleMsgChannelOpenAck defines the sdk.Handler for MsgChannelOpenAck -func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg types.MsgChannelOpenAck) (*sdk.Result, error) { +func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg *MsgChannelOpenAck) (*sdk.Result, error) { err := k.ChanOpenAck( ctx, msg.PortID, msg.ChannelID, channelCap, msg.CounterpartyVersion, msg.ProofTry, msg.ProofHeight, ) @@ -93,7 +93,7 @@ func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capab } // HandleMsgChannelOpenConfirm defines the sdk.Handler for MsgChannelOpenConfirm -func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg types.MsgChannelOpenConfirm) (*sdk.Result, error) { +func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg *MsgChannelOpenConfirm) (*sdk.Result, error) { err := k.ChanOpenConfirm(ctx, msg.PortID, msg.ChannelID, channelCap, msg.ProofAck, msg.ProofHeight) if err != nil { return nil, err @@ -117,7 +117,7 @@ func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *c } // HandleMsgChannelCloseInit defines the sdk.Handler for MsgChannelCloseInit -func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg types.MsgChannelCloseInit) (*sdk.Result, error) { +func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg *MsgChannelCloseInit) (*sdk.Result, error) { err := k.ChanCloseInit(ctx, msg.PortID, msg.ChannelID, channelCap) if err != nil { return nil, err @@ -141,7 +141,7 @@ func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *cap } // HandleMsgChannelCloseConfirm defines the sdk.Handler for MsgChannelCloseConfirm -func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg types.MsgChannelCloseConfirm) (*sdk.Result, error) { +func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capability.Capability, msg *MsgChannelCloseConfirm) (*sdk.Result, error) { err := k.ChanCloseConfirm(ctx, msg.PortID, msg.ChannelID, channelCap, msg.ProofInit, msg.ProofHeight) if err != nil { return nil, err diff --git a/x/ibc/04-channel/types/msgs.go b/x/ibc/04-channel/types/msgs.go index 1c3c617acb1e..ab5427a0272d 100644 --- a/x/ibc/04-channel/types/msgs.go +++ b/x/ibc/04-channel/types/msgs.go @@ -10,16 +10,16 @@ import ( host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) -var _ sdk.Msg = MsgChannelOpenInit{} +var _ sdk.Msg = &MsgChannelOpenInit{} // NewMsgChannelOpenInit creates a new MsgChannelCloseInit MsgChannelOpenInit func NewMsgChannelOpenInit( portID, channelID string, version string, channelOrder Order, connectionHops []string, counterpartyPortID, counterpartyChannelID string, signer sdk.AccAddress, -) MsgChannelOpenInit { +) *MsgChannelOpenInit { counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := NewChannel(INIT, channelOrder, counterparty, connectionHops, version) - return MsgChannelOpenInit{ + return &MsgChannelOpenInit{ PortID: portID, ChannelID: channelID, Channel: channel, @@ -59,17 +59,17 @@ func (msg MsgChannelOpenInit) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgChannelOpenTry{} +var _ sdk.Msg = &MsgChannelOpenTry{} // NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance func NewMsgChannelOpenTry( portID, channelID, version string, channelOrder Order, connectionHops []string, counterpartyPortID, counterpartyChannelID, counterpartyVersion string, proofInit commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgChannelOpenTry { +) *MsgChannelOpenTry { counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := NewChannel(INIT, channelOrder, counterparty, connectionHops, version) - return MsgChannelOpenTry{ + return &MsgChannelOpenTry{ PortID: portID, ChannelID: channelID, Channel: channel, @@ -124,14 +124,14 @@ func (msg MsgChannelOpenTry) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgChannelOpenAck{} +var _ sdk.Msg = &MsgChannelOpenAck{} // NewMsgChannelOpenAck creates a new MsgChannelOpenAck instance func NewMsgChannelOpenAck( portID, channelID string, cpv string, proofTry commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgChannelOpenAck { - return MsgChannelOpenAck{ +) *MsgChannelOpenAck { + return &MsgChannelOpenAck{ PortID: portID, ChannelID: channelID, CounterpartyVersion: cpv, @@ -185,14 +185,14 @@ func (msg MsgChannelOpenAck) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgChannelOpenConfirm{} +var _ sdk.Msg = &MsgChannelOpenConfirm{} // NewMsgChannelOpenConfirm creates a new MsgChannelOpenConfirm instance func NewMsgChannelOpenConfirm( portID, channelID string, proofAck commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgChannelOpenConfirm { - return MsgChannelOpenConfirm{ +) *MsgChannelOpenConfirm { + return &MsgChannelOpenConfirm{ PortID: portID, ChannelID: channelID, ProofAck: proofAck, @@ -242,13 +242,13 @@ func (msg MsgChannelOpenConfirm) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgChannelCloseInit{} +var _ sdk.Msg = &MsgChannelCloseInit{} // NewMsgChannelCloseInit creates a new MsgChannelCloseInit instance func NewMsgChannelCloseInit( portID string, channelID string, signer sdk.AccAddress, -) MsgChannelCloseInit { - return MsgChannelCloseInit{ +) *MsgChannelCloseInit { + return &MsgChannelCloseInit{ PortID: portID, ChannelID: channelID, Signer: signer, @@ -287,14 +287,14 @@ func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgChannelCloseConfirm{} +var _ sdk.Msg = &MsgChannelCloseConfirm{} // NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance func NewMsgChannelCloseConfirm( portID, channelID string, proofInit commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgChannelCloseConfirm { - return MsgChannelCloseConfirm{ +) *MsgChannelCloseConfirm { + return &MsgChannelCloseConfirm{ PortID: portID, ChannelID: channelID, ProofInit: proofInit, @@ -344,14 +344,14 @@ func (msg MsgChannelCloseConfirm) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.Signer} } -var _ sdk.Msg = MsgPacket{} +var _ sdk.Msg = &MsgPacket{} // NewMsgPacket constructs new MsgPacket func NewMsgPacket( packet Packet, proof commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgPacket { - return MsgPacket{ +) *MsgPacket { + return &MsgPacket{ Packet: packet, Proof: proof, ProofHeight: proofHeight, @@ -404,14 +404,14 @@ func (msg MsgPacket) Type() string { return "ics04/opaque" } -var _ sdk.Msg = MsgTimeout{} +var _ sdk.Msg = &MsgTimeout{} // NewMsgTimeout constructs new MsgTimeout func NewMsgTimeout( packet Packet, nextSequenceRecv uint64, proof commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, -) MsgTimeout { - return MsgTimeout{ +) *MsgTimeout { + return &MsgTimeout{ Packet: packet, NextSequenceRecv: nextSequenceRecv, Proof: proof, @@ -458,12 +458,12 @@ func (msg MsgTimeout) Type() string { return "ics04/timeout" } -var _ sdk.Msg = MsgAcknowledgement{} +var _ sdk.Msg = &MsgAcknowledgement{} // NewMsgAcknowledgement constructs a new MsgAcknowledgement func NewMsgAcknowledgement( - packet Packet, ack []byte, proof commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress) MsgAcknowledgement { - return MsgAcknowledgement{ + packet Packet, ack []byte, proof commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress) *MsgAcknowledgement { + return &MsgAcknowledgement{ Packet: packet, Acknowledgement: ack, Proof: proof, diff --git a/x/ibc/07-tendermint/types/msgs.go b/x/ibc/07-tendermint/types/msgs.go index 3fcc15e1b662..b0d155062478 100644 --- a/x/ibc/07-tendermint/types/msgs.go +++ b/x/ibc/07-tendermint/types/msgs.go @@ -23,9 +23,9 @@ const ( ) var ( - _ clientexported.MsgCreateClient = MsgCreateClient{} - _ clientexported.MsgUpdateClient = MsgUpdateClient{} - _ evidenceexported.MsgSubmitEvidence = MsgSubmitClientMisbehaviour{} + _ clientexported.MsgCreateClient = &MsgCreateClient{} + _ clientexported.MsgUpdateClient = &MsgUpdateClient{} + _ evidenceexported.MsgSubmitEvidence = &MsgSubmitClientMisbehaviour{} ) // MsgCreateClient defines a message to create an IBC client @@ -39,6 +39,18 @@ type MsgCreateClient struct { Signer sdk.AccAddress `json:"address" yaml:"address"` } +func (msg MsgCreateClient) Reset() { + panic("implement me") +} + +func (msg MsgCreateClient) String() string { + panic("implement me") +} + +func (msg MsgCreateClient) ProtoMessage() { + panic("implement me") +} + // NewMsgCreateClient creates a new MsgCreateClient instance func NewMsgCreateClient( id string, header Header, trustLevel tmmath.Fraction, @@ -129,6 +141,18 @@ type MsgUpdateClient struct { Signer sdk.AccAddress `json:"address" yaml:"address"` } +func (msg MsgUpdateClient) Reset() { + panic("implement me") +} + +func (msg MsgUpdateClient) String() string { + panic("implement me") +} + +func (msg MsgUpdateClient) ProtoMessage() { + panic("implement me") +} + // NewMsgUpdateClient creates a new MsgUpdateClient instance func NewMsgUpdateClient(id string, header Header, signer sdk.AccAddress) MsgUpdateClient { return MsgUpdateClient{ @@ -183,6 +207,18 @@ type MsgSubmitClientMisbehaviour struct { Submitter sdk.AccAddress `json:"submitter" yaml:"submitter"` } +func (msg MsgSubmitClientMisbehaviour) Reset() { + panic("implement me") +} + +func (msg MsgSubmitClientMisbehaviour) String() string { + panic("implement me") +} + +func (msg MsgSubmitClientMisbehaviour) ProtoMessage() { + panic("implement me") +} + // NewMsgSubmitClientMisbehaviour creates a new MsgSubmitClientMisbehaviour // instance. func NewMsgSubmitClientMisbehaviour(e evidenceexported.Evidence, s sdk.AccAddress) MsgSubmitClientMisbehaviour { diff --git a/x/ibc/09-localhost/types/msgs.go b/x/ibc/09-localhost/types/msgs.go index 8b526f446a05..efd3c89057c6 100644 --- a/x/ibc/09-localhost/types/msgs.go +++ b/x/ibc/09-localhost/types/msgs.go @@ -13,17 +13,12 @@ const ( ) var ( - _ clientexported.MsgCreateClient = MsgCreateClient{} + _ clientexported.MsgCreateClient = &MsgCreateClient{} ) -// MsgCreateClient defines a message to create an IBC client -type MsgCreateClient struct { - Signer sdk.AccAddress `json:"address" yaml:"address"` -} - // NewMsgCreateClient creates a new MsgCreateClient instance -func NewMsgCreateClient(signer sdk.AccAddress) MsgCreateClient { - return MsgCreateClient{ +func NewMsgCreateClient(signer sdk.AccAddress) *MsgCreateClient { + return &MsgCreateClient{ Signer: signer, } } diff --git a/x/ibc/09-localhost/types/types.pb.go b/x/ibc/09-localhost/types/types.pb.go new file mode 100644 index 000000000000..2d8fed4c98bb --- /dev/null +++ b/x/ibc/09-localhost/types/types.pb.go @@ -0,0 +1,328 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/ibc/09-localhost/types/types.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + 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 + +// MsgCreateClient defines a message to create an IBC client +type MsgCreateClient struct { + Signer github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=signer,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"signer,omitempty"` +} + +func (m *MsgCreateClient) Reset() { *m = MsgCreateClient{} } +func (m *MsgCreateClient) String() string { return proto.CompactTextString(m) } +func (*MsgCreateClient) ProtoMessage() {} +func (*MsgCreateClient) Descriptor() ([]byte, []int) { + return fileDescriptor_a8da40ad8942fbdc, []int{0} +} +func (m *MsgCreateClient) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateClient) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateClient.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 *MsgCreateClient) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateClient.Merge(m, src) +} +func (m *MsgCreateClient) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateClient) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateClient.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateClient proto.InternalMessageInfo + +func (m *MsgCreateClient) GetSigner() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Signer + } + return nil +} + +func init() { + proto.RegisterType((*MsgCreateClient)(nil), "cosmos_sdk.ibc.localhost.v1.MsgCreateClient") +} + +func init() { + proto.RegisterFile("x/ibc/09-localhost/types/types.proto", fileDescriptor_a8da40ad8942fbdc) +} + +var fileDescriptor_a8da40ad8942fbdc = []byte{ + // 220 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xa9, 0xd0, 0xcf, 0x4c, + 0x4a, 0xd6, 0x37, 0xb0, 0xd4, 0xcd, 0xc9, 0x4f, 0x4e, 0xcc, 0xc9, 0xc8, 0x2f, 0x2e, 0xd1, 0x2f, + 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xd2, 0xc9, 0xf9, + 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x99, 0x49, 0xc9, 0x7a, 0x70, 0xb5, 0x7a, + 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, 0x95, 0xfa, + 0x60, 0xf5, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0xc4, 0x10, 0xa5, 0x18, 0x2e, 0x7e, 0xdf, + 0xe2, 0x74, 0xe7, 0xa2, 0xd4, 0xc4, 0x92, 0x54, 0xe7, 0x9c, 0xcc, 0xd4, 0xbc, 0x12, 0x21, 0x4f, + 0x2e, 0xb6, 0xe2, 0xcc, 0xf4, 0xbc, 0xd4, 0x22, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x1e, 0x27, 0xc3, + 0x5f, 0xf7, 0xe4, 0x75, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x21, + 0xd6, 0x42, 0x29, 0xdd, 0xe2, 0x94, 0x6c, 0xa8, 0xab, 0x1c, 0x93, 0x93, 0x1d, 0x53, 0x52, 0x8a, + 0x52, 0x8b, 0x8b, 0x83, 0xa0, 0x06, 0x38, 0xf9, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, + 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, + 0x1c, 0x43, 0x94, 0x29, 0x5e, 0x03, 0x71, 0xf9, 0x3f, 0x89, 0x0d, 0xec, 0x6a, 0x63, 0x40, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x9c, 0xe5, 0xb5, 0xd4, 0x22, 0x01, 0x00, 0x00, +} + +func (m *MsgCreateClient) 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 *MsgCreateClient) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateClient) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreateClient) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreateClient) 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 ErrIntOverflowTypes + } + 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: MsgCreateClient: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateClient: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = append(m.Signer[:0], dAtA[iNdEx:postIndex]...) + if m.Signer == nil { + m.Signer = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ibc/09-localhost/types/types.proto b/x/ibc/09-localhost/types/types.proto new file mode 100644 index 000000000000..087ec3b8c6f5 --- /dev/null +++ b/x/ibc/09-localhost/types/types.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package cosmos_sdk.ibc.localhost.v1; + +import "third_party/proto/gogoproto/gogo.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"; + +// MsgCreateClient defines a message to create an IBC client +message MsgCreateClient { + bytes signer = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; +} diff --git a/x/ibc/ante/ante.go b/x/ibc/ante/ante.go index 82484be5a32e..02873900c3c3 100644 --- a/x/ibc/ante/ante.go +++ b/x/ibc/ante/ante.go @@ -31,11 +31,11 @@ func (pvr ProofVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim switch msg := msg.(type) { case clientexported.MsgUpdateClient: _, err = pvr.clientKeeper.UpdateClient(ctx, msg.GetClientID(), msg.GetHeader()) - case channel.MsgPacket: + case *channel.MsgPacket: _, err = pvr.channelKeeper.RecvPacket(ctx, msg.Packet, msg.Proof, msg.ProofHeight) - case channel.MsgAcknowledgement: + case *channel.MsgAcknowledgement: _, err = pvr.channelKeeper.AcknowledgePacket(ctx, msg.Packet, msg.Acknowledgement, msg.Proof, msg.ProofHeight) - case channel.MsgTimeout: + case *channel.MsgTimeout: _, err = pvr.channelKeeper.TimeoutPacket(ctx, msg.Packet, msg.Proof, msg.ProofHeight, msg.NextSequenceRecv) } diff --git a/x/ibc/handler.go b/x/ibc/handler.go index f5f3f4b7d5e3..6f13cbafe096 100644 --- a/x/ibc/handler.go +++ b/x/ibc/handler.go @@ -24,20 +24,20 @@ func NewHandler(k Keeper) sdk.Handler { return &sdk.Result{}, nil // IBC connection msgs - case connection.MsgConnectionOpenInit: + case *connection.MsgConnectionOpenInit: return connection.HandleMsgConnectionOpenInit(ctx, k.ConnectionKeeper, msg) - case connection.MsgConnectionOpenTry: + case *connection.MsgConnectionOpenTry: return connection.HandleMsgConnectionOpenTry(ctx, k.ConnectionKeeper, msg) - case connection.MsgConnectionOpenAck: + case *connection.MsgConnectionOpenAck: return connection.HandleMsgConnectionOpenAck(ctx, k.ConnectionKeeper, msg) - case connection.MsgConnectionOpenConfirm: + case *connection.MsgConnectionOpenConfirm: return connection.HandleMsgConnectionOpenConfirm(ctx, k.ConnectionKeeper, msg) // IBC channel msgs - case channel.MsgChannelOpenInit: + case *channel.MsgChannelOpenInit: // Lookup module by port capability module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortID) if err != nil { @@ -60,7 +60,7 @@ func NewHandler(k Keeper) sdk.Handler { return res, nil - case channel.MsgChannelOpenTry: + case *channel.MsgChannelOpenTry: // Lookup module by port capability module, portCap, err := k.PortKeeper.LookupModuleByPort(ctx, msg.PortID) if err != nil { @@ -82,7 +82,7 @@ func NewHandler(k Keeper) sdk.Handler { return res, nil - case channel.MsgChannelOpenAck: + case *channel.MsgChannelOpenAck: // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortID, msg.ChannelID) if err != nil { @@ -100,7 +100,7 @@ func NewHandler(k Keeper) sdk.Handler { } return channel.HandleMsgChannelOpenAck(ctx, k.ChannelKeeper, cap, msg) - case channel.MsgChannelOpenConfirm: + case *channel.MsgChannelOpenConfirm: // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortID, msg.ChannelID) if err != nil { @@ -118,7 +118,7 @@ func NewHandler(k Keeper) sdk.Handler { } return channel.HandleMsgChannelOpenConfirm(ctx, k.ChannelKeeper, cap, msg) - case channel.MsgChannelCloseInit: + case *channel.MsgChannelCloseInit: // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortID, msg.ChannelID) if err != nil { @@ -136,7 +136,7 @@ func NewHandler(k Keeper) sdk.Handler { } return channel.HandleMsgChannelCloseInit(ctx, k.ChannelKeeper, cap, msg) - case channel.MsgChannelCloseConfirm: + case *channel.MsgChannelCloseConfirm: // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortID, msg.ChannelID) if err != nil { @@ -155,7 +155,7 @@ func NewHandler(k Keeper) sdk.Handler { return channel.HandleMsgChannelCloseConfirm(ctx, k.ChannelKeeper, cap, msg) // IBC packet msgs get routed to the appropriate module callback - case channel.MsgPacket: + case *channel.MsgPacket: // Lookup module by channel capability module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) if err != nil { @@ -169,7 +169,7 @@ func NewHandler(k Keeper) sdk.Handler { } return cbs.OnRecvPacket(ctx, msg.Packet) - case channel.MsgAcknowledgement: + case *channel.MsgAcknowledgement: // Lookup module by channel capability module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { @@ -183,7 +183,7 @@ func NewHandler(k Keeper) sdk.Handler { } return cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement) - case channel.MsgTimeout: + case *channel.MsgTimeout: // Lookup module by channel capability module, cap, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) if err != nil { diff --git a/x/slashing/handler.go b/x/slashing/handler.go index 91d3c49d1e47..c4a5b9f12b9e 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -12,7 +12,7 @@ func NewHandler(k Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case MsgUnjail: + case *MsgUnjail: return handleMsgUnjail(ctx, msg, k) default: @@ -23,7 +23,7 @@ func NewHandler(k Keeper) sdk.Handler { // Validators must submit a transaction to unjail itself after // having been jailed (and thus unbonded) for downtime -func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) (*sdk.Result, error) { +func handleMsgUnjail(ctx sdk.Context, msg *MsgUnjail, k Keeper) (*sdk.Result, error) { err := k.Unjail(ctx, msg.ValidatorAddr) if err != nil { return nil, err diff --git a/x/slashing/keeper/test_common.go b/x/slashing/keeper/test_common.go index 9d76664a53e8..7ce3fd8a0129 100644 --- a/x/slashing/keeper/test_common.go +++ b/x/slashing/keeper/test_common.go @@ -5,6 +5,8 @@ package keeper import ( "github.com/tendermint/tendermint/crypto" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" @@ -26,7 +28,7 @@ func TestParams() types.Params { return params } -func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator { +func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) return staking.NewMsgCreateValidator( @@ -35,7 +37,7 @@ func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt ) } -func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delAmount sdk.Int) staking.MsgDelegate { +func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delAmount sdk.Int) *stakingtypes.MsgDelegate { amount := sdk.NewCoin(sdk.DefaultBondDenom, delAmount) return staking.NewMsgDelegate(delAddr, valAddr, amount) } diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 000f695ca2d4..f287cc54551f 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -8,8 +8,8 @@ import ( var _ sdk.Msg = &MsgUnjail{} // NewMsgUnjail creates a new MsgUnjail instance -func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { - return MsgUnjail{ +func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail { + return &MsgUnjail{ ValidatorAddr: validatorAddr, } } diff --git a/x/staking/handler.go b/x/staking/handler.go index d75deea5e91e..c7157d30b97f 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -18,19 +18,19 @@ func NewHandler(k keeper.Keeper) sdk.Handler { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case types.MsgCreateValidator: + case *types.MsgCreateValidator: return handleMsgCreateValidator(ctx, msg, k) - case types.MsgEditValidator: + case *types.MsgEditValidator: return handleMsgEditValidator(ctx, msg, k) - case types.MsgDelegate: + case *types.MsgDelegate: return handleMsgDelegate(ctx, msg, k) - case types.MsgBeginRedelegate: + case *types.MsgBeginRedelegate: return handleMsgBeginRedelegate(ctx, msg, k) - case types.MsgUndelegate: + case *types.MsgUndelegate: return handleMsgUndelegate(ctx, msg, k) default: @@ -42,7 +42,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { // These functions assume everything has been authenticated, // now we just perform action and save -func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgCreateValidator(ctx sdk.Context, msg *types.MsgCreateValidator, k keeper.Keeper) (*sdk.Result, error) { // check to see if the pubkey or sender has been registered before if _, found := k.GetValidator(ctx, msg.ValidatorAddress); found { return nil, ErrValidatorOwnerExists @@ -121,7 +121,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgEditValidator(ctx sdk.Context, msg *types.MsgEditValidator, k keeper.Keeper) (*sdk.Result, error) { // validator must already be registered validator, found := k.GetValidator(ctx, msg.ValidatorAddress) if !found { @@ -178,7 +178,7 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgDelegate(ctx sdk.Context, msg *types.MsgDelegate, k keeper.Keeper) (*sdk.Result, error) { validator, found := k.GetValidator(ctx, msg.ValidatorAddress) if !found { return nil, ErrNoValidatorFound @@ -210,7 +210,7 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper) return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgUndelegate(ctx sdk.Context, msg *types.MsgUndelegate, k keeper.Keeper) (*sdk.Result, error) { shares, err := k.ValidateUnbondAmount( ctx, msg.DelegatorAddress, msg.ValidatorAddress, msg.Amount.Amount, ) @@ -250,7 +250,7 @@ func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keep return &sdk.Result{Data: completionTimeBz, Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgBeginRedelegate(ctx sdk.Context, msg types.MsgBeginRedelegate, k keeper.Keeper) (*sdk.Result, error) { +func handleMsgBeginRedelegate(ctx sdk.Context, msg *types.MsgBeginRedelegate, k keeper.Keeper) (*sdk.Result, error) { shares, err := k.ValidateUnbondAmount( ctx, msg.DelegatorAddress, msg.ValidatorSrcAddress, msg.Amount.Amount, ) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 10ad750560a7..47f25a01e83d 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -22,13 +22,13 @@ var ( func NewMsgCreateValidator( valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin, description Description, commission CommissionRates, minSelfDelegation sdk.Int, -) MsgCreateValidator { +) *MsgCreateValidator { var pkStr string if pubKey != nil { pkStr = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubKey) } - return MsgCreateValidator{ + return &MsgCreateValidator{ Description: description, DelegatorAddress: sdk.AccAddress(valAddr), ValidatorAddress: valAddr, @@ -113,8 +113,8 @@ func (msg MsgCreateValidator) ValidateBasic() error { } // NewMsgEditValidator creates a new MsgEditValidator instance -func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) MsgEditValidator { - return MsgEditValidator{ +func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) *MsgEditValidator { + return &MsgEditValidator{ Description: description, CommissionRate: newRate, ValidatorAddress: valAddr, @@ -163,8 +163,8 @@ func (msg MsgEditValidator) ValidateBasic() error { } // NewMsgDelegate creates a new MsgDelegate instance. -func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgDelegate { - return MsgDelegate{ +func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) *MsgDelegate { + return &MsgDelegate{ DelegatorAddress: delAddr, ValidatorAddress: valAddr, Amount: amount, @@ -208,8 +208,8 @@ func (msg MsgDelegate) ValidateBasic() error { // NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance. func NewMsgBeginRedelegate( delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin, -) MsgBeginRedelegate { - return MsgBeginRedelegate{ +) *MsgBeginRedelegate { + return &MsgBeginRedelegate{ DelegatorAddress: delAddr, ValidatorSrcAddress: valSrcAddr, ValidatorDstAddress: valDstAddr, @@ -256,8 +256,8 @@ func (msg MsgBeginRedelegate) ValidateBasic() error { } // NewMsgUndelegate creates a new MsgUndelegate instance. -func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgUndelegate { - return MsgUndelegate{ +func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) *MsgUndelegate { + return &MsgUndelegate{ DelegatorAddress: delAddr, ValidatorAddress: valAddr, Amount: amount, From f61c345b3ca9758e4c5aad4d976c75705b252f8b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 26 May 2020 15:19:36 -0400 Subject: [PATCH 34/54] Fix tests --- baseapp/abci.go | 7 +------ baseapp/baseapp_test.go | 14 ++++++++++++-- baseapp/helpers.go | 11 +++++++++-- simapp/test_helpers.go | 2 +- types/tx/signing/decoded_tx.go | 2 +- x/auth/ante/ante.go | 6 +++++- x/auth/ante/basic.go | 2 +- x/auth/ante/sigverify.go | 8 ++++---- x/auth/ante/sigverify_proto.go | 15 ++++++++++----- x/auth/ante/types/types.go | 6 +++--- x/bank/app_test.go | 15 ++++++++------- x/bank/types/msgs_test.go | 2 +- 12 files changed, 56 insertions(+), 34 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 72173ada2226..1e6c5f6464ba 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -323,12 +323,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res case "simulate": txBytes := req.Data - tx, err := app.txDecoder(txBytes) - if err != nil { - return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to decode tx")) - } - - gInfo, res, err := app.Simulate(txBytes, tx) + gInfo, res, _, err := app.Simulate(txBytes) if err != nil { return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to simulate tx")) } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 79d6cb5f5ab5..ceec039f2cbb 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -594,6 +594,11 @@ type msgCounter struct { FailOnHandler bool } +// Implements proto.Message +func (msg msgCounter) Reset() { panic("implement me") } +func (msg msgCounter) String() string { panic("implement me") } +func (msg msgCounter) ProtoMessage() { panic("implement me") } + // Implements Msg func (msg msgCounter) Route() string { return routeMsgCounter } func (msg msgCounter) Type() string { return "counter1" } @@ -634,6 +639,11 @@ type msgCounter2 struct { Counter int64 } +// Implements proto.Message +func (msg msgCounter2) Reset() { panic("implement me") } +func (msg msgCounter2) String() string { panic("implement me") } +func (msg msgCounter2) ProtoMessage() { panic("implement me") } + // Implements Msg func (msg msgCounter2) Route() string { return routeMsgCounter2 } func (msg msgCounter2) Type() string { return "counter2" } @@ -974,13 +984,13 @@ func TestSimulateTx(t *testing.T) { require.Nil(t, err) // simulate a message, check gas reported - gInfo, result, err := app.Simulate(txBytes, tx) + gInfo, result, _, err := app.Simulate(txBytes) require.NoError(t, err) require.NotNil(t, result) require.Equal(t, gasConsumed, gInfo.GasUsed) // simulate again, same result - gInfo, result, err = app.Simulate(txBytes, tx) + gInfo, result, _, err = app.Simulate(txBytes) require.NoError(t, err) require.NotNil(t, result) require.Equal(t, gasConsumed, gInfo.GasUsed) diff --git a/baseapp/helpers.go b/baseapp/helpers.go index c69a8ba82925..fbc5a2e8e8db 100644 --- a/baseapp/helpers.go +++ b/baseapp/helpers.go @@ -3,6 +3,8 @@ package baseapp import ( abci "github.com/tendermint/tendermint/abci/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -10,8 +12,13 @@ func (app *BaseApp) Check(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { return app.runTx(runTxModeCheck, nil, tx) } -func (app *BaseApp) Simulate(txBytes []byte, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { - return app.runTx(runTxModeSimulate, txBytes, tx) +func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, sdk.Tx, error) { + tx, err := app.txDecoder(txBytes) + if err != nil { + return sdk.GasInfo{}, nil, nil, sdkerrors.Wrap(err, "failed to decode tx") + } + gi, r, err := app.runTx(runTxModeSimulate, txBytes, tx) + return gi, r, tx, err } func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 0ca6ea1a793a..7caa3080db32 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -259,7 +259,7 @@ func SignCheckDeliver( require.Nil(t, err) // Must simulate now as CheckTx doesn't run Msgs anymore - _, res, err := app.Simulate(txBytes, tx) + _, res, tx, err := app.Simulate(txBytes) if expSimPass { require.NoError(t, err) diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index 9813cfdd8194..d389c519029e 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -27,7 +27,7 @@ type DecodedTx struct { var _ sdk.Tx = DecodedTx{} var _ antetypes.FeeTx = DecodedTx{} var _ antetypes.TxWithMemo = DecodedTx{} -var _ antetypes.HasPubKeysTx = DecodedTx{} +var _ antetypes.SigTx = DecodedTx{} func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 400706066d62..749e20542b0d 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -2,6 +2,7 @@ package ante import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ibcante "github.com/cosmos/cosmos-sdk/x/ibc/ante" ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper" @@ -47,7 +48,10 @@ func NewProtoAnteHandler( NewValidateSigCountDecorator(ak), NewDeductFeeDecorator(ak, bankKeeper), NewSigGasConsumeDecorator(ak, sigGasConsumer), - NewProtoSigVerificationDecorator(ak), + NewProtoSigVerificationDecorator(ak, []signing.SignModeHandler{ + signing.DirectModeHandler{}, + signing.LegacyAminoJSONHandler{}, + }), NewIncrementSequenceDecorator(ak), ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator ) diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index a74e5e74144b..44de45b07692 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -91,7 +91,7 @@ func NewConsumeGasForTxSizeDecorator(ak AccountKeeper) ConsumeTxSizeGasDecorator } func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(types2.SigVerifiableTx) + sigTx, ok := tx.(types2.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index f0a18b4934b1..e14fe51a4335 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -50,7 +50,7 @@ func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { } func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(types2.HasPubKeysTx) + sigTx, ok := tx.(types2.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } @@ -107,7 +107,7 @@ func NewSigGasConsumeDecorator(ak AccountKeeper, sigGasConsumer SignatureVerific } func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - sigTx, ok := tx.(types2.SigVerifiableTx) + sigTx, ok := tx.(types2.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -232,7 +232,7 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim return next(ctx, tx, simulate) } - sigTx, ok := tx.(types2.SigVerifiableTx) + sigTx, ok := tx.(types2.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -265,7 +265,7 @@ func NewValidateSigCountDecorator(ak AccountKeeper) ValidateSigCountDecorator { } func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(types2.SigVerifiableTx) + sigTx, ok := tx.(types2.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") } diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 83c74d8dd080..5004ee77d66d 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -13,13 +13,18 @@ import ( ) type ProtoSigVerificationDecorator struct { - ak AccountKeeper - signModeVerifiers map[types.SignMode]signing.SignModeHandler + ak AccountKeeper + signModeHandlers map[types.SignMode]signing.SignModeHandler } -func NewProtoSigVerificationDecorator(ak AccountKeeper) ProtoSigVerificationDecorator { +func NewProtoSigVerificationDecorator(ak AccountKeeper, signModeHandlers []signing.SignModeHandler) ProtoSigVerificationDecorator { + handlerMap := make(map[types.SignMode]signing.SignModeHandler) + for _, h := range signModeHandlers { + handlerMap[h.Mode()] = h + } return ProtoSigVerificationDecorator{ - ak: ak, + ak: ak, + signModeHandlers: handlerMap, } } @@ -110,7 +115,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, single *types.ModeInfo_Single, signerAcc auth.AccountI, sigTx signing.DecodedTx) ([]byte, error) { - verifier, found := svd.signModeVerifiers[single.Mode] + verifier, found := svd.signModeHandlers[single.Mode] if !found { return nil, fmt.Errorf("can't verify sign mode %s", single.Mode.String()) } diff --git a/x/auth/ante/types/types.go b/x/auth/ante/types/types.go index d262685b96ea..f9e34f0f9aad 100644 --- a/x/auth/ante/types/types.go +++ b/x/auth/ante/types/types.go @@ -24,13 +24,13 @@ type TxWithMemo interface { // SigVerifiableTx defines a Tx interface for all signature verification decorators type SigVerifiableTx interface { types.Tx - HasPubKeysTx - GetSignatures() [][]byte + SigTx GetSignBytes(ctx types.Context, acc types2.AccountI) []byte } -type HasPubKeysTx interface { +type SigTx interface { types.Tx + GetSignatures() [][]byte GetSigners() []types.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place } diff --git a/x/bank/app_test.go b/x/bank/app_test.go index b4d8f0edbfc1..252dd9ec73ee 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -49,18 +49,18 @@ var ( sendMsg1 = types.NewMsgSend(addr1, addr2, coins) - multiSendMsg1 = types.MsgMultiSend{ + multiSendMsg1 = &types.MsgMultiSend{ Inputs: []types.Input{types.NewInput(addr1, coins)}, Outputs: []types.Output{types.NewOutput(addr2, coins)}, } - multiSendMsg2 = types.MsgMultiSend{ + multiSendMsg2 = &types.MsgMultiSend{ Inputs: []types.Input{types.NewInput(addr1, coins)}, Outputs: []types.Output{ types.NewOutput(addr2, halfCoins), types.NewOutput(addr3, halfCoins), }, } - multiSendMsg3 = types.MsgMultiSend{ + multiSendMsg3 = &types.MsgMultiSend{ Inputs: []types.Input{ types.NewInput(addr1, coins), types.NewInput(addr4, coins), @@ -70,7 +70,7 @@ var ( types.NewOutput(addr3, coins), }, } - multiSendMsg4 = types.MsgMultiSend{ + multiSendMsg4 = &types.MsgMultiSend{ Inputs: []types.Input{ types.NewInput(addr2, coins), }, @@ -78,7 +78,7 @@ var ( types.NewOutput(addr1, coins), }, } - multiSendMsg5 = types.MsgMultiSend{ + multiSendMsg5 = &types.MsgMultiSend{ Inputs: []types.Input{ types.NewInput(addr1, coins), }, @@ -111,7 +111,8 @@ func TestSendNotEnoughBalance(t *testing.T) { sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.GetEncodingConfig().TxGenerator, app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) + txGen := app.GetEncodingConfig().TxGenerator + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{sdk.NewInt64Coin("foocoin", 67)}) @@ -128,7 +129,7 @@ func TestSendToModuleAcc(t *testing.T) { tests := []struct { name string fromBalance sdk.Coins - msg types.MsgSend + msg *types.MsgSend expSimPass bool expPass bool expFromBalance sdk.Coins diff --git a/x/bank/types/msgs_test.go b/x/bank/types/msgs_test.go index 2a09c1b9f728..a0fe50b2bf40 100644 --- a/x/bank/types/msgs_test.go +++ b/x/bank/types/msgs_test.go @@ -31,7 +31,7 @@ func TestMsgSendValidation(t *testing.T) { cases := []struct { valid bool - tx MsgSend + tx *MsgSend }{ {true, NewMsgSend(addr1, addr2, atom123)}, // valid send {true, NewMsgSend(addr1, addr2, atom123eth123)}, // valid send with multiple coins From c59d51f4d6446f2dbfc513472d785435d6e9876c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 26 May 2020 15:37:28 -0400 Subject: [PATCH 35/54] Fix amino tests --- simapp/amino.go | 32 ++++++++++++++---------------- x/bank/types/codec.go | 4 ++-- x/crisis/types/codec.go | 2 +- x/distribution/types/codec.go | 8 ++++---- x/evidence/types/codec.go | 2 +- x/gov/types/codec.go | 4 ++-- x/ibc-transfer/types/codec.go | 2 +- x/ibc/03-connection/types/codec.go | 8 ++++---- x/ibc/04-channel/types/codec.go | 18 ++++++++--------- x/ibc/07-tendermint/types/codec.go | 6 +++--- x/ibc/09-localhost/types/codec.go | 2 +- x/slashing/types/codec.go | 2 +- x/staking/types/codec.go | 10 +++++----- 13 files changed, 49 insertions(+), 51 deletions(-) diff --git a/simapp/amino.go b/simapp/amino.go index 24819a44e177..ae20711db67e 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -7,33 +7,31 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" ) -func SimappTxDecoder() types.TxDecoder { - _, _, cdc := MakeCodecs() - return auth.DefaultTxDecoder(cdc) -} - -func MakeTxGenerator() signing.TxGenerator { - _, _, cdc := MakeCodecs() - return types.StdTxGenerator{Cdc: cdc} -} - -// MakeCodecs constructs the *std.Codec and *codec.Codec instances used by -// simapp. It is useful for tests and clients who do not want to construct the -// full simapp -func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { +func MakeEncodingConfig() EncodingConfig { cdc := std.MakeCodec(ModuleBasics) interfaceRegistry := codectypes.NewInterfaceRegistry() std.RegisterInterfaces(interfaceRegistry) ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - appCodec := codec.NewHybridCodec(cdc, interfaceRegistry) - return appCodec, nil, cdc + marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) + return EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxDecoder: authtypes.DefaultTxDecoder(cdc), + TxGenerator: authtypes.StdTxGenerator{Cdc: cdc}, + Amino: cdc, + } +} + +func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { + cfg := MakeEncodingConfig() + return cfg.Marshaler, cfg.InterfaceRegistry, cfg.Amino } func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 74874835ef2a..69a181382453 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -12,8 +12,8 @@ import ( func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.SupplyI)(nil), nil) cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) - cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/MsgSend", nil) - cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil) + cdc.RegisterConcrete(&MsgSend{}, "cosmos-sdk/MsgSend", nil) + cdc.RegisterConcrete(&MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil) } func RegisterInterfaces(registry types.InterfaceRegistry) { diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 04802607cbe3..5f319bf00b29 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -8,7 +8,7 @@ import ( // RegisterCodec registers the necessary x/crisis interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil) + cdc.RegisterConcrete(&MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil) } var ( diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 8bc90ef9a745..e3b2bf9e37db 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -10,10 +10,10 @@ import ( // RegisterCodec registers the necessary x/distribution interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil) - cdc.RegisterConcrete(MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission", nil) - cdc.RegisterConcrete(MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil) - cdc.RegisterConcrete(MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool", nil) + cdc.RegisterConcrete(&MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil) + cdc.RegisterConcrete(&MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission", nil) + cdc.RegisterConcrete(&MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil) + cdc.RegisterConcrete(&MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool", nil) cdc.RegisterConcrete(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) cdc.RegisterConcrete(FeePool{}, "cosmos-sdk/FeePool", nil) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 01b0af59677b..3a23356a1f47 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -11,7 +11,7 @@ import ( // evidence module. func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.Evidence)(nil), nil) - cdc.RegisterConcrete(MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence", nil) + cdc.RegisterConcrete(&MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence", nil) cdc.RegisterConcrete(&Equivocation{}, "cosmos-sdk/Equivocation", nil) } diff --git a/x/gov/types/codec.go b/x/gov/types/codec.go index 2397c1f87d92..ee53c71c4582 100644 --- a/x/gov/types/codec.go +++ b/x/gov/types/codec.go @@ -11,8 +11,8 @@ import ( func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*Content)(nil), nil) cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil) - cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil) - cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/MsgVote", nil) + cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil) + cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/MsgVote", nil) cdc.RegisterConcrete(&TextProposal{}, "cosmos-sdk/TextProposal", nil) } diff --git a/x/ibc-transfer/types/codec.go b/x/ibc-transfer/types/codec.go index ddf55f4f8485..2e16ce038e7a 100644 --- a/x/ibc-transfer/types/codec.go +++ b/x/ibc-transfer/types/codec.go @@ -10,7 +10,7 @@ import ( // RegisterCodec registers the IBC transfer types func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgTransfer{}, "cosmos-sdk/MsgTransfer", nil) + cdc.RegisterConcrete(&MsgTransfer{}, "cosmos-sdk/MsgTransfer", nil) cdc.RegisterConcrete(FungibleTokenPacketData{}, "cosmos-sdk/PacketDataTransfer", nil) } diff --git a/x/ibc/03-connection/types/codec.go b/x/ibc/03-connection/types/codec.go index 5ae9aa6ed89f..f5ebbbe6bdb1 100644 --- a/x/ibc/03-connection/types/codec.go +++ b/x/ibc/03-connection/types/codec.go @@ -14,10 +14,10 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*exported.CounterpartyI)(nil), nil) cdc.RegisterConcrete(ConnectionEnd{}, "ibc/connection/ConnectionEnd", nil) - cdc.RegisterConcrete(MsgConnectionOpenInit{}, "ibc/connection/MsgConnectionOpenInit", nil) - cdc.RegisterConcrete(MsgConnectionOpenTry{}, "ibc/connection/MsgConnectionOpenTry", nil) - cdc.RegisterConcrete(MsgConnectionOpenAck{}, "ibc/connection/MsgConnectionOpenAck", nil) - cdc.RegisterConcrete(MsgConnectionOpenConfirm{}, "ibc/connection/MsgConnectionOpenConfirm", nil) + cdc.RegisterConcrete(&MsgConnectionOpenInit{}, "ibc/connection/MsgConnectionOpenInit", nil) + cdc.RegisterConcrete(&MsgConnectionOpenTry{}, "ibc/connection/MsgConnectionOpenTry", nil) + cdc.RegisterConcrete(&MsgConnectionOpenAck{}, "ibc/connection/MsgConnectionOpenAck", nil) + cdc.RegisterConcrete(&MsgConnectionOpenConfirm{}, "ibc/connection/MsgConnectionOpenConfirm", nil) } // RegisterInterfaces register the ibc interfaces submodule implementations to protobuf diff --git a/x/ibc/04-channel/types/codec.go b/x/ibc/04-channel/types/codec.go index 66e0e65ac331..01b4bbe03537 100644 --- a/x/ibc/04-channel/types/codec.go +++ b/x/ibc/04-channel/types/codec.go @@ -14,15 +14,15 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(Channel{}, "ibc/channel/Channel", nil) cdc.RegisterConcrete(Packet{}, "ibc/channel/Packet", nil) - cdc.RegisterConcrete(MsgChannelOpenInit{}, "ibc/channel/MsgChannelOpenInit", nil) - cdc.RegisterConcrete(MsgChannelOpenTry{}, "ibc/channel/MsgChannelOpenTry", nil) - cdc.RegisterConcrete(MsgChannelOpenAck{}, "ibc/channel/MsgChannelOpenAck", nil) - cdc.RegisterConcrete(MsgChannelOpenConfirm{}, "ibc/channel/MsgChannelOpenConfirm", nil) - cdc.RegisterConcrete(MsgChannelCloseInit{}, "ibc/channel/MsgChannelCloseInit", nil) - cdc.RegisterConcrete(MsgChannelCloseConfirm{}, "ibc/channel/MsgChannelCloseConfirm", nil) - cdc.RegisterConcrete(MsgPacket{}, "ibc/channel/MsgPacket", nil) - cdc.RegisterConcrete(MsgAcknowledgement{}, "ibc/channel/MsgAcknowledgement", nil) - cdc.RegisterConcrete(MsgTimeout{}, "ibc/channel/MsgTimeout", nil) + cdc.RegisterConcrete(&MsgChannelOpenInit{}, "ibc/channel/MsgChannelOpenInit", nil) + cdc.RegisterConcrete(&MsgChannelOpenTry{}, "ibc/channel/MsgChannelOpenTry", nil) + cdc.RegisterConcrete(&MsgChannelOpenAck{}, "ibc/channel/MsgChannelOpenAck", nil) + cdc.RegisterConcrete(&MsgChannelOpenConfirm{}, "ibc/channel/MsgChannelOpenConfirm", nil) + cdc.RegisterConcrete(&MsgChannelCloseInit{}, "ibc/channel/MsgChannelCloseInit", nil) + cdc.RegisterConcrete(&MsgChannelCloseConfirm{}, "ibc/channel/MsgChannelCloseConfirm", nil) + cdc.RegisterConcrete(&MsgPacket{}, "ibc/channel/MsgPacket", nil) + cdc.RegisterConcrete(&MsgAcknowledgement{}, "ibc/channel/MsgAcknowledgement", nil) + cdc.RegisterConcrete(&MsgTimeout{}, "ibc/channel/MsgTimeout", nil) } // RegisterInterfaces register the ibc channel submodule interfaces to protobuf diff --git a/x/ibc/07-tendermint/types/codec.go b/x/ibc/07-tendermint/types/codec.go index 086b23aae43d..2ac179d62c63 100644 --- a/x/ibc/07-tendermint/types/codec.go +++ b/x/ibc/07-tendermint/types/codec.go @@ -13,9 +13,9 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(ConsensusState{}, "ibc/client/tendermint/ConsensusState", nil) cdc.RegisterConcrete(Header{}, "ibc/client/tendermint/Header", nil) cdc.RegisterConcrete(Evidence{}, "ibc/client/tendermint/Evidence", nil) - cdc.RegisterConcrete(MsgCreateClient{}, "ibc/client/tendermint/MsgCreateClient", nil) - cdc.RegisterConcrete(MsgUpdateClient{}, "ibc/client/tendermint/MsgUpdateClient", nil) - cdc.RegisterConcrete(MsgSubmitClientMisbehaviour{}, "ibc/client/tendermint/MsgSubmitClientMisbehaviour", nil) + cdc.RegisterConcrete(&MsgCreateClient{}, "ibc/client/tendermint/MsgCreateClient", nil) + cdc.RegisterConcrete(&MsgUpdateClient{}, "ibc/client/tendermint/MsgUpdateClient", nil) + cdc.RegisterConcrete(&MsgSubmitClientMisbehaviour{}, "ibc/client/tendermint/MsgSubmitClientMisbehaviour", nil) SetSubModuleCodec(cdc) } diff --git a/x/ibc/09-localhost/types/codec.go b/x/ibc/09-localhost/types/codec.go index 67a9431fa589..a0dff8718cfd 100644 --- a/x/ibc/09-localhost/types/codec.go +++ b/x/ibc/09-localhost/types/codec.go @@ -15,7 +15,7 @@ var SubModuleCdc *codec.Codec // RegisterCodec registers the localhost types func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(ClientState{}, "ibc/client/localhost/ClientState", nil) - cdc.RegisterConcrete(MsgCreateClient{}, "ibc/client/localhost/MsgCreateClient", nil) + cdc.RegisterConcrete(&MsgCreateClient{}, "ibc/client/localhost/MsgCreateClient", nil) SetSubModuleCodec(cdc) } diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 2d257b39ab06..088c2977c1e1 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -7,7 +7,7 @@ import ( // RegisterCodec registers concrete types on codec func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) + cdc.RegisterConcrete(&MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } var ( diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index d6e4811e9447..bc33edd5eee3 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -8,11 +8,11 @@ import ( // RegisterCodec registers the necessary x/staking interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) - cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) - cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) - cdc.RegisterConcrete(MsgUndelegate{}, "cosmos-sdk/MsgUndelegate", nil) - cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) + cdc.RegisterConcrete(&MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) + cdc.RegisterConcrete(&MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) + cdc.RegisterConcrete(&MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) + cdc.RegisterConcrete(&MsgUndelegate{}, "cosmos-sdk/MsgUndelegate", nil) + cdc.RegisterConcrete(&MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) } var ( From f089efb235847fd87e5e174bea257fd90aa440d6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 26 May 2020 15:59:35 -0400 Subject: [PATCH 36/54] Fix amino build --- simapp/cmd/simcli/amino.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/simapp/cmd/simcli/amino.go b/simapp/cmd/simcli/amino.go index d6fdc18dcb69..05e8a6b84307 100644 --- a/simapp/cmd/simcli/amino.go +++ b/simapp/cmd/simcli/amino.go @@ -4,14 +4,16 @@ package main import ( "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" ) func MakeTxCLIContext() context.CLIContext { cliCtx := context.CLIContext{} + aminoCdc := codec.NewAminoCodec(encodingConfig.Amino) return cliCtx. - WithJSONMarshaler(appCodec). - WithTxGenerator(MakeTxGenerator()). - WithAccountRetriever(types.NewAccountRetriever(appCodec)). - WithCodec(cdc) + WithJSONMarshaler(aminoCdc). + WithTxGenerator(encodingConfig.TxGenerator). + WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). + WithCodec(encodingConfig.Amino) } From 759dd35d8d716526d3dadd80b58a040bf363ec4a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 27 May 2020 10:02:59 -0400 Subject: [PATCH 37/54] Fix tests --- x/evidence/keeper/infraction_test.go | 4 +++- x/evidence/types/msgs.go | 8 ++++---- x/slashing/app_test.go | 2 +- x/slashing/module.go | 6 ++++++ x/slashing/types/codec.go | 7 +++++++ x/staking/module.go | 7 +++++++ x/staking/types/codec.go | 11 +++++++++++ 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/x/evidence/keeper/infraction_test.go b/x/evidence/keeper/infraction_test.go index 5c2f1198725a..850818b95a31 100644 --- a/x/evidence/keeper/infraction_test.go +++ b/x/evidence/keeper/infraction_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "time" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/staking" @@ -10,7 +12,7 @@ import ( "github.com/tendermint/tendermint/crypto" ) -func newTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator { +func newTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) return staking.NewMsgCreateValidator( address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index 1d6875cbfc38..aca411ef9d3a 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -23,16 +23,16 @@ var ( ) // NewMsgSubmitEvidence returns a new MsgSubmitEvidence with a signer/submitter. -func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (MsgSubmitEvidence, error) { +func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (*MsgSubmitEvidence, error) { msg, ok := evi.(proto.Message) if !ok { - return MsgSubmitEvidence{}, fmt.Errorf("cannot proto marshal %T", evi) + return nil, fmt.Errorf("cannot proto marshal %T", evi) } any, err := types.NewAnyWithValue(msg) if err != nil { - return MsgSubmitEvidence{Submitter: s}, err + return nil, err } - return MsgSubmitEvidence{Submitter: s, Evidence: any}, nil + return &MsgSubmitEvidence{Submitter: s, Evidence: any}, nil } // Route returns the MsgSubmitEvidence's route. diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 256d1cc629f7..c1493ea328ad 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -76,7 +76,7 @@ func TestSlashingMsgs(t *testing.T) { require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddress) require.Equal(t, sdk.Bonded, validator.Status) require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens())) - unjailMsg := slashing.MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.GetConsPubKey().Address())} + unjailMsg := &slashing.MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.GetConsPubKey().Address())} checkValidatorSigningInfo(t, app, sdk.ConsAddress(addr1), true) diff --git a/x/slashing/module.go b/x/slashing/module.go index 0bc65c296c1d..2312c6eed1a4 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gorilla/mux" "github.com/spf13/cobra" @@ -76,6 +78,10 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { return cli.GetQueryCmd(StoreKey, cdc) } +func (b AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + //____________________________________________________________________________ // AppModule implements an application module for the slashing module. diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 088c2977c1e1..dae5a5ddda30 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -3,6 +3,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // RegisterCodec registers concrete types on codec @@ -10,6 +11,12 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) } +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgUnjail{}, + ) +} + var ( amino = codec.New() diff --git a/x/staking/module.go b/x/staking/module.go index 4d6c9fc6f81f..25b8dfa51a9c 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -5,6 +5,8 @@ import ( "fmt" "math/rand" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gorilla/mux" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -29,6 +31,7 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} + _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the staking module. @@ -100,6 +103,10 @@ func (AppModuleBasic) BuildCreateValidatorMsg(cliCtx context.CLIContext, return cli.BuildCreateValidatorMsg(cliCtx, txBldr) } +func (b AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + //____________________________________________________________________________ // AppModule implements an application module for the staking module. diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index bc33edd5eee3..5d0c8a7d7219 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -3,6 +3,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // RegisterCodec registers the necessary x/staking interfaces and concrete types @@ -15,6 +16,16 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) } +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCreateValidator{}, + &MsgEditValidator{}, + &MsgDelegate{}, + &MsgUndelegate{}, + &MsgBeginRedelegate{}, + ) +} + var ( amino = codec.New() From bcada32b1f077b919f48b98b9bd421484ef339d8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 27 May 2020 10:05:54 -0400 Subject: [PATCH 38/54] Switch proto cli tests to amino JSON --- simapp/cmd/simcli/proto.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index ea022c7bdd88..b176ee75cf53 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -10,7 +10,7 @@ import ( func MakeTxCLIContext() context.CLIContext { cliCtx := context.CLIContext{} - protoCdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) + protoCdc := codec.NewHybridCodec(encodingConfig.Amino, encodingConfig.InterfaceRegistry) return cliCtx. WithJSONMarshaler(protoCdc). WithTxGenerator(encodingConfig.TxGenerator). From e83ca5fe851148358189e81ad0d2b48147c4ac84 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 27 May 2020 10:23:34 -0400 Subject: [PATCH 39/54] Fix tests --- x/ibc-transfer/types/msgs_test.go | 4 +-- x/ibc/03-connection/types/msgs_test.go | 16 ++++++------ x/ibc/04-channel/types/msgs_test.go | 36 +++++++++++++------------- x/staking/app_test.go | 4 +-- x/staking/common_test.go | 4 +-- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/x/ibc-transfer/types/msgs_test.go b/x/ibc-transfer/types/msgs_test.go index c3d6a9ea28b2..6b332fc4d839 100644 --- a/x/ibc-transfer/types/msgs_test.go +++ b/x/ibc-transfer/types/msgs_test.go @@ -48,7 +48,7 @@ func TestMsgTransferType(t *testing.T) { // TestMsgTransferValidation tests ValidateBasic for MsgTransfer func TestMsgTransferValidation(t *testing.T) { - testMsgs := []MsgTransfer{ + testMsgs := []*MsgTransfer{ NewMsgTransfer(validPort, validChannel, 10, coins, addr1, addr2), // valid msg NewMsgTransfer(invalidShortPort, validChannel, 10, coins, addr1, addr2), // too short port id NewMsgTransfer(invalidLongPort, validChannel, 10, coins, addr1, addr2), // too long port id @@ -64,7 +64,7 @@ func TestMsgTransferValidation(t *testing.T) { } testCases := []struct { - msg MsgTransfer + msg *MsgTransfer expPass bool errMsg string }{ diff --git a/x/ibc/03-connection/types/msgs_test.go b/x/ibc/03-connection/types/msgs_test.go index bc542e1be405..50dccb40a71d 100644 --- a/x/ibc/03-connection/types/msgs_test.go +++ b/x/ibc/03-connection/types/msgs_test.go @@ -56,7 +56,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []MsgConnectionOpenInit{ + testMsgs := []*MsgConnectionOpenInit{ NewMsgConnectionOpenInit("test/conn1", "clienttotesta", "connectiontotest", "clienttotest", prefix, signer), NewMsgConnectionOpenInit("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, signer), NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "test/conn1", "clienttotest", prefix, signer), @@ -67,7 +67,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() { } var testCases = []struct { - msg MsgConnectionOpenInit + msg *MsgConnectionOpenInit expPass bool errMsg string }{ @@ -94,7 +94,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { prefix := commitmenttypes.NewMerklePrefix([]byte("storePrefixKey")) signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []MsgConnectionOpenTry{ + testMsgs := []*MsgConnectionOpenTry{ NewMsgConnectionOpenTry("test/conn1", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "ibc/test", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer), @@ -110,7 +110,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { } var testCases = []struct { - msg MsgConnectionOpenTry + msg *MsgConnectionOpenTry expPass bool errMsg string }{ @@ -141,7 +141,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() { func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []MsgConnectionOpenAck{ + testMsgs := []*MsgConnectionOpenAck{ NewMsgConnectionOpenAck("test/conn1", suite.proof, suite.proof, 10, 10, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", emptyProof, suite.proof, 10, 10, "1.0.0", signer), NewMsgConnectionOpenAck("ibcconntest", suite.proof, emptyProof, 10, 10, "1.0.0", signer), @@ -152,7 +152,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "1.0.0", signer), } var testCases = []struct { - msg MsgConnectionOpenAck + msg *MsgConnectionOpenAck expPass bool errMsg string }{ @@ -179,7 +179,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() { func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() { signer, _ := sdk.AccAddressFromBech32("cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht") - testMsgs := []MsgConnectionOpenConfirm{ + testMsgs := []*MsgConnectionOpenConfirm{ NewMsgConnectionOpenConfirm("test/conn1", suite.proof, 10, signer), NewMsgConnectionOpenConfirm("ibcconntest", emptyProof, 10, signer), NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 0, signer), @@ -188,7 +188,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() { } var testCases = []struct { - msg MsgConnectionOpenConfirm + msg *MsgConnectionOpenConfirm expPass bool errMsg string }{ diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index 8d7d659f839f..beaa9645b936 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -79,7 +79,7 @@ func TestMsgTestSuite(t *testing.T) { // TestMsgChannelOpenInit tests ValidateBasic for MsgChannelOpenInit func (suite *MsgTestSuite) TestMsgChannelOpenInit() { - testMsgs := []MsgChannelOpenInit{ + testMsgs := []*MsgChannelOpenInit{ NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id @@ -98,7 +98,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenInit() { } testCases := []struct { - msg MsgChannelOpenInit + msg *MsgChannelOpenInit expPass bool errMsg string }{ @@ -131,7 +131,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenInit() { // TestMsgChannelOpenTry tests ValidateBasic for MsgChannelOpenTry func (suite *MsgTestSuite) TestMsgChannelOpenTry() { - testMsgs := []MsgChannelOpenTry{ + testMsgs := []*MsgChannelOpenTry{ NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id @@ -152,7 +152,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenTry() { } testCases := []struct { - msg MsgChannelOpenTry + msg *MsgChannelOpenTry expPass bool errMsg string }{ @@ -187,7 +187,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenTry() { // TestMsgChannelOpenAck tests ValidateBasic for MsgChannelOpenAck func (suite *MsgTestSuite) TestMsgChannelOpenAck() { - testMsgs := []MsgChannelOpenAck{ + testMsgs := []*MsgChannelOpenAck{ NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 1, addr), // valid msg NewMsgChannelOpenAck(invalidShortPort, "testchannel", "1.0", suite.proof, 1, addr), // too short port id NewMsgChannelOpenAck(invalidLongPort, "testchannel", "1.0", suite.proof, 1, addr), // too long port id @@ -201,7 +201,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenAck() { } testCases := []struct { - msg MsgChannelOpenAck + msg *MsgChannelOpenAck expPass bool errMsg string }{ @@ -229,7 +229,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenAck() { // TestMsgChannelOpenConfirm tests ValidateBasic for MsgChannelOpenConfirm func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() { - testMsgs := []MsgChannelOpenConfirm{ + testMsgs := []*MsgChannelOpenConfirm{ NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg NewMsgChannelOpenConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id NewMsgChannelOpenConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id @@ -242,7 +242,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() { } testCases := []struct { - msg MsgChannelOpenConfirm + msg *MsgChannelOpenConfirm expPass bool errMsg string }{ @@ -269,7 +269,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() { // TestMsgChannelCloseInit tests ValidateBasic for MsgChannelCloseInit func (suite *MsgTestSuite) TestMsgChannelCloseInit() { - testMsgs := []MsgChannelCloseInit{ + testMsgs := []*MsgChannelCloseInit{ NewMsgChannelCloseInit("testportid", "testchannel", addr), // valid msg NewMsgChannelCloseInit(invalidShortPort, "testchannel", addr), // too short port id NewMsgChannelCloseInit(invalidLongPort, "testchannel", addr), // too long port id @@ -280,7 +280,7 @@ func (suite *MsgTestSuite) TestMsgChannelCloseInit() { } testCases := []struct { - msg MsgChannelCloseInit + msg *MsgChannelCloseInit expPass bool errMsg string }{ @@ -305,7 +305,7 @@ func (suite *MsgTestSuite) TestMsgChannelCloseInit() { // TestMsgChannelCloseConfirm tests ValidateBasic for MsgChannelCloseConfirm func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() { - testMsgs := []MsgChannelCloseConfirm{ + testMsgs := []*MsgChannelCloseConfirm{ NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 1, addr), // valid msg NewMsgChannelCloseConfirm(invalidShortPort, "testchannel", suite.proof, 1, addr), // too short port id NewMsgChannelCloseConfirm(invalidLongPort, "testchannel", suite.proof, 1, addr), // too long port id @@ -318,7 +318,7 @@ func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() { } testCases := []struct { - msg MsgChannelCloseConfirm + msg *MsgChannelCloseConfirm expPass bool errMsg string }{ @@ -378,7 +378,7 @@ func TestMsgPacketType(t *testing.T) { // TestMsgPacketValidation tests ValidateBasic for MsgPacket func TestMsgPacketValidation(t *testing.T) { - testMsgs := []MsgPacket{ + testMsgs := []*MsgPacket{ NewMsgPacket(packet, proof, 1, addr1), // valid msg NewMsgPacket(packet, proof, 0, addr1), // proof height is zero NewMsgPacket(packet, invalidProofs2, 1, addr1), // proof contain empty proof @@ -387,7 +387,7 @@ func TestMsgPacketValidation(t *testing.T) { } testCases := []struct { - msg MsgPacket + msg *MsgPacket expPass bool errMsg string }{ @@ -431,7 +431,7 @@ func TestMsgPacketGetSigners(t *testing.T) { // TestMsgTimeout tests ValidateBasic for MsgTimeout func (suite *MsgTestSuite) TestMsgTimeout() { - testMsgs := []MsgTimeout{ + testMsgs := []*MsgTimeout{ NewMsgTimeout(packet, 1, proof, 1, addr), NewMsgTimeout(packet, 1, proof, 0, addr), NewMsgTimeout(packet, 1, proof, 1, emptyAddr), @@ -440,7 +440,7 @@ func (suite *MsgTestSuite) TestMsgTimeout() { } testCases := []struct { - msg MsgTimeout + msg *MsgTimeout expPass bool errMsg string }{ @@ -463,7 +463,7 @@ func (suite *MsgTestSuite) TestMsgTimeout() { // TestMsgAcknowledgement tests ValidateBasic for MsgAcknowledgement func (suite *MsgTestSuite) TestMsgAcknowledgement() { - testMsgs := []MsgAcknowledgement{ + testMsgs := []*MsgAcknowledgement{ NewMsgAcknowledgement(packet, packet.GetData(), proof, 1, addr), NewMsgAcknowledgement(packet, packet.GetData(), proof, 0, addr), NewMsgAcknowledgement(packet, packet.GetData(), proof, 1, emptyAddr), @@ -473,7 +473,7 @@ func (suite *MsgTestSuite) TestMsgAcknowledgement() { } testCases := []struct { - msg MsgAcknowledgement + msg *MsgAcknowledgement expPass bool errMsg string }{ diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 0a58872e8390..230495087287 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -101,7 +101,7 @@ func TestStakingMsgs(t *testing.T) { delegateMsg := staking.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2) + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2) require.NoError(t, err) simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -110,7 +110,7 @@ func TestStakingMsgs(t *testing.T) { // begin unbonding beginUnbondingMsg := staking.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2) + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2) require.NoError(t, err) // delegation should exist anymore diff --git a/x/staking/common_test.go b/x/staking/common_test.go index c897cd019d33..772a936ff6bb 100644 --- a/x/staking/common_test.go +++ b/x/staking/common_test.go @@ -25,13 +25,13 @@ var ( PKs = simapp.CreateTestPubKeys(500) ) -func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator { +func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *staking.MsgCreateValidator { return types.NewMsgCreateValidator( address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), staking.Description{}, commissionRates, sdk.OneInt(), ) } -func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) staking.MsgDelegate { +func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) *staking.MsgDelegate { amount := sdk.NewCoin(sdk.DefaultBondDenom, amt) return staking.NewMsgDelegate(delAddr, valAddr, amount) } From f8584aea2bd8a4940e9a5b43ac7a1a75d65e357a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 27 May 2020 13:46:17 -0400 Subject: [PATCH 40/54] Fix sims --- crypto/types/codec.go | 28 +++++ crypto/types/types.go | 26 ++++ crypto/types/types.pb.go | 90 ++++++-------- crypto/types/types.proto | 2 + simapp/amino.go | 24 ---- simapp/app.go | 6 +- simapp/encoding.go | 24 ++-- simapp/params/amino.go | 23 ++++ simapp/params/encoding.go | 16 +++ simapp/params/proto.go | 25 ++++ simapp/proto.go | 27 ---- std/codec.go | 10 +- types/tx/signing/decoded_tx.go | 120 ++---------------- types/tx/signing/direct.go | 10 +- types/tx/signing/handler.go | 2 +- types/tx/signing/legacy_amino_json.go | 4 +- types/tx/signing/tx_generator.go | 2 +- types/tx/tx.go | 159 ++++++++++++++++++------ x/auth/ante/sigverify_proto.go | 6 +- x/bank/simulation/operations.go | 6 +- x/distribution/simulation/operations.go | 12 +- x/gov/simulation/operations.go | 9 +- x/slashing/simulation/operations.go | 3 +- x/staking/simulation/operations.go | 15 ++- 24 files changed, 357 insertions(+), 292 deletions(-) create mode 100644 crypto/types/types.go create mode 100644 simapp/params/amino.go create mode 100644 simapp/params/encoding.go create mode 100644 simapp/params/proto.go diff --git a/crypto/types/codec.go b/crypto/types/codec.go index f32c81b317cb..5ad14dbe278a 100644 --- a/crypto/types/codec.go +++ b/crypto/types/codec.go @@ -6,3 +6,31 @@ type PublicKeyCodec interface { Decode(key *PublicKey) (crypto.PubKey, error) Encode(key crypto.PubKey) (*PublicKey, error) } + +type publicKeyCodecCacheMiddleware struct { + cdc PublicKeyCodec +} + +func CacheWrapCodec(cdc PublicKeyCodec) PublicKeyCodec { + return publicKeyCodecCacheMiddleware{cdc: cdc} +} + +var _ PublicKeyCodec = publicKeyCodecCacheMiddleware{} + +func (p publicKeyCodecCacheMiddleware) Decode(key *PublicKey) (crypto.PubKey, error) { + res, err := p.cdc.Decode(key) + if err != nil { + return nil, err + } + key.cachedValue = res + return res, nil +} + +func (p publicKeyCodecCacheMiddleware) Encode(key crypto.PubKey) (*PublicKey, error) { + res, err := p.cdc.Encode(key) + if err != nil { + return nil, err + } + res.cachedValue = key + return res, nil +} diff --git a/crypto/types/types.go b/crypto/types/types.go new file mode 100644 index 000000000000..8361271c69ae --- /dev/null +++ b/crypto/types/types.go @@ -0,0 +1,26 @@ +package types + +import "github.com/tendermint/tendermint/crypto" + +// PublicKey specifies a public key +type PublicKey struct { + // sum specifies which type of public key is wrapped + // + // Types that are valid to be assigned to Sum: + // *PublicKey_Secp256K1 + // *PublicKey_Ed25519 + // *PublicKey_Sr25519 + // *PublicKey_Multisig + // *PublicKey_Secp256R1 + // *PublicKey_AminoMultisig + // *PublicKey_AnyPubkey + Sum isPublicKey_Sum `protobuf_oneof:"sum"` + + cachedValue crypto.PubKey +} + +// GetCachedPubKey returns the cached PubKey instance wrapped in the PublicKey. +// This will only be set if the PublicKeyCodec is cache-wrapped using CacheWrapCodec +func (pk PublicKey) GetCachedPubKey() crypto.PubKey { + return pk.cachedValue +} diff --git a/crypto/types/types.pb.go b/crypto/types/types.pb.go index b9226268a71b..db28309be5a2 100644 --- a/crypto/types/types.pb.go +++ b/crypto/types/types.pb.go @@ -24,21 +24,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// PublicKey specifies a public key -type PublicKey struct { - // sum specifies which type of public key is wrapped - // - // Types that are valid to be assigned to Sum: - // *PublicKey_Secp256K1 - // *PublicKey_Ed25519 - // *PublicKey_Sr25519 - // *PublicKey_Multisig - // *PublicKey_Secp256R1 - // *PublicKey_AminoMultisig - // *PublicKey_AnyPubkey - Sum isPublicKey_Sum `protobuf_oneof:"sum"` -} - func (m *PublicKey) Reset() { *m = PublicKey{} } func (m *PublicKey) String() string { return proto.CompactTextString(m) } func (*PublicKey) ProtoMessage() {} @@ -400,43 +385,44 @@ func init() { func init() { proto.RegisterFile("crypto/types/types.proto", fileDescriptor_2165b2a1badb1b0c) } var fileDescriptor_2165b2a1badb1b0c = []byte{ - // 574 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x8b, 0xd3, 0x40, - 0x18, 0x4e, 0xb6, 0xfb, 0x39, 0xfb, 0xa5, 0xc3, 0x82, 0xd9, 0x05, 0x93, 0x92, 0x83, 0x54, 0x61, - 0x13, 0x5a, 0xe9, 0xaa, 0xbd, 0x48, 0xb3, 0x97, 0x85, 0x2a, 0x94, 0xac, 0x27, 0x41, 0xc2, 0x24, - 0x19, 0xd3, 0xd0, 0x24, 0x13, 0x66, 0x26, 0xe2, 0x9c, 0xfc, 0x0b, 0x1e, 0x3d, 0xee, 0xfe, 0x06, - 0xff, 0x84, 0xc7, 0x1e, 0x3d, 0x15, 0x69, 0x7f, 0x81, 0xfb, 0x0b, 0xa4, 0x99, 0xa6, 0x2d, 0xb2, - 0x45, 0xf0, 0x92, 0xe4, 0x7d, 0x9f, 0x67, 0xe6, 0x79, 0xde, 0x8f, 0x00, 0x2d, 0xa0, 0x22, 0xe7, - 0xc4, 0xe6, 0x22, 0xc7, 0x4c, 0x3e, 0xad, 0x9c, 0x12, 0x4e, 0xe0, 0x49, 0x40, 0x58, 0x4a, 0x98, - 0xc7, 0xc2, 0xa1, 0x25, 0x49, 0xd6, 0xa7, 0xe6, 0xd9, 0x13, 0x3e, 0x88, 0x69, 0xe8, 0xe5, 0x88, - 0x72, 0x61, 0x97, 0x44, 0x3b, 0x22, 0x11, 0x59, 0x7e, 0xc9, 0xd3, 0x67, 0xa7, 0x11, 0x21, 0x51, - 0x82, 0x25, 0xc5, 0x2f, 0x3e, 0xda, 0x28, 0x13, 0x12, 0x32, 0x7f, 0x6f, 0x80, 0xbd, 0x7e, 0xe1, - 0x27, 0x71, 0xd0, 0xc3, 0x02, 0xea, 0x60, 0x8f, 0xe1, 0x20, 0x6f, 0xb5, 0x2f, 0x86, 0x4d, 0x4d, - 0xad, 0xab, 0x8d, 0x83, 0x2b, 0xc5, 0x5d, 0xa6, 0xe0, 0x19, 0xd8, 0xc1, 0x61, 0xab, 0xdd, 0x6e, - 0xbe, 0xd2, 0x36, 0xe6, 0x68, 0x95, 0x98, 0x61, 0x8c, 0x4a, 0xac, 0x56, 0x61, 0xf3, 0x04, 0xec, - 0x81, 0xdd, 0xb4, 0x48, 0x78, 0xcc, 0xe2, 0x48, 0xdb, 0xac, 0xab, 0x8d, 0xfd, 0xd6, 0xb9, 0x75, - 0x5f, 0x45, 0x56, 0xbf, 0xf0, 0x7b, 0x58, 0xbc, 0x9d, 0x73, 0xdf, 0x0d, 0x28, 0x66, 0x03, 0x92, - 0x84, 0x57, 0x8a, 0xbb, 0xb8, 0x60, 0xc5, 0x24, 0x6d, 0x6a, 0x5b, 0x7f, 0x99, 0xa4, 0x4d, 0x88, - 0xc0, 0x11, 0x4a, 0xe3, 0x8c, 0x78, 0x0b, 0xc9, 0xed, 0x52, 0xf2, 0xe5, 0xfd, 0x92, 0x6f, 0x70, - 0x84, 0x02, 0xd1, 0x9d, 0x9d, 0x58, 0xaf, 0x7e, 0x58, 0xde, 0x58, 0x21, 0xb0, 0x0d, 0x00, 0xca, - 0x84, 0x97, 0x17, 0xfe, 0x10, 0x0b, 0xed, 0xb8, 0xbc, 0xfe, 0xc4, 0x92, 0x5d, 0xb6, 0xaa, 0x2e, - 0x5b, 0xdd, 0x4c, 0xcc, 0x9c, 0xa1, 0x4c, 0xf4, 0x4b, 0xa2, 0xb3, 0x05, 0x6a, 0xac, 0x48, 0xcd, - 0xef, 0x2a, 0x78, 0xb4, 0x46, 0x0a, 0xbe, 0x00, 0x7b, 0xbc, 0x0a, 0xca, 0x09, 0x1c, 0x3a, 0xa7, - 0x93, 0xb1, 0xa1, 0xf6, 0xee, 0xc6, 0xc6, 0x03, 0x81, 0xd2, 0xa4, 0x63, 0x2e, 0x70, 0xd3, 0x5d, - 0x72, 0xa1, 0x07, 0xf6, 0xf3, 0x72, 0x8e, 0xde, 0x10, 0x0b, 0xa6, 0x6d, 0xd4, 0x6b, 0x8d, 0xfd, - 0x96, 0xb1, 0xb6, 0xcb, 0x72, 0xe0, 0xce, 0xe3, 0xc9, 0xd8, 0xd8, 0x91, 0x5e, 0xd8, 0xdd, 0xd8, - 0x38, 0x92, 0x0a, 0xb2, 0x2e, 0x66, 0xba, 0x20, 0xaf, 0x98, 0xcc, 0xbc, 0x00, 0x47, 0xa5, 0xdd, - 0xeb, 0x38, 0xca, 0x10, 0x2f, 0x28, 0x86, 0x3a, 0x00, 0xac, 0x0a, 0x98, 0xa6, 0xd6, 0x6b, 0x8d, - 0x03, 0x77, 0x25, 0xd3, 0xd9, 0x1c, 0xdd, 0x1a, 0xaa, 0xf9, 0x01, 0x1c, 0x5f, 0x92, 0x34, 0x47, - 0x01, 0x77, 0x62, 0xde, 0xa5, 0x14, 0x09, 0xf8, 0x0c, 0x3c, 0xc4, 0x9f, 0x39, 0x45, 0x9e, 0x1f, - 0x73, 0xe6, 0x31, 0x4e, 0x28, 0x9e, 0x17, 0xeb, 0x1e, 0x97, 0x80, 0x13, 0x73, 0x76, 0x5d, 0xa6, - 0xe1, 0x09, 0xd8, 0xc2, 0x09, 0x4e, 0x99, 0x5c, 0x38, 0x57, 0x06, 0x9d, 0xdd, 0x6f, 0x37, 0x86, - 0x72, 0x73, 0x6b, 0x28, 0xe6, 0x17, 0x60, 0xfe, 0x7b, 0x82, 0xf0, 0x35, 0xa8, 0xcd, 0x26, 0xa5, - 0xfe, 0xc7, 0xee, 0xb9, 0xb3, 0x93, 0x50, 0x03, 0x3b, 0x28, 0x0c, 0x29, 0x66, 0x95, 0x91, 0x2a, - 0x74, 0x2e, 0x7f, 0x4c, 0x74, 0x75, 0x34, 0xd1, 0xd5, 0x5f, 0x13, 0x5d, 0xfd, 0x3a, 0xd5, 0x95, - 0xd1, 0x54, 0x57, 0x7e, 0x4e, 0x75, 0xe5, 0xfd, 0xd3, 0x28, 0xe6, 0x83, 0xc2, 0xb7, 0x02, 0x92, - 0xda, 0x52, 0x71, 0xfe, 0x3a, 0x67, 0xe1, 0xd0, 0x5e, 0xfd, 0xd7, 0xfd, 0xed, 0x72, 0x69, 0x9e, - 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x76, 0x08, 0x4c, 0x4e, 0x02, 0x04, 0x00, 0x00, + // 582 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x8b, 0xd3, 0x4e, + 0x1c, 0x4e, 0xb6, 0xfb, 0x3a, 0xfb, 0xf6, 0xff, 0x0f, 0x0b, 0x66, 0x17, 0x4c, 0x4a, 0x0e, 0x52, + 0x85, 0x4d, 0x68, 0xa5, 0xab, 0xf6, 0x22, 0x9b, 0xbd, 0x2c, 0x54, 0xa1, 0x64, 0x3d, 0x09, 0x12, + 0x26, 0xc9, 0x98, 0x86, 0x26, 0x99, 0x30, 0x33, 0x11, 0xe7, 0xe4, 0x57, 0xf0, 0xe8, 0x71, 0xfb, + 0x19, 0xfc, 0x12, 0x1e, 0x7b, 0xf4, 0x54, 0xa4, 0xfd, 0x02, 0xb2, 0x17, 0xaf, 0xd2, 0x4c, 0xd3, + 0x16, 0xd9, 0x22, 0x78, 0x49, 0xf2, 0xfb, 0x3d, 0xcf, 0xcc, 0xf3, 0xfc, 0x5e, 0x02, 0xb4, 0x80, + 0x8a, 0x9c, 0x13, 0x9b, 0x8b, 0x1c, 0x33, 0xf9, 0xb4, 0x72, 0x4a, 0x38, 0x81, 0x27, 0x01, 0x61, + 0x29, 0x61, 0x1e, 0x0b, 0x07, 0x96, 0x24, 0x59, 0x1f, 0x9a, 0x67, 0x8f, 0x78, 0x3f, 0xa6, 0xa1, + 0x97, 0x23, 0xca, 0x85, 0x5d, 0x12, 0xed, 0x88, 0x44, 0x64, 0xf9, 0x25, 0x4f, 0x9f, 0x9d, 0x46, + 0x84, 0x44, 0x09, 0x96, 0x14, 0xbf, 0x78, 0x6f, 0xa3, 0x4c, 0x48, 0xc8, 0xfc, 0xb5, 0x01, 0xf6, + 0x7a, 0x85, 0x9f, 0xc4, 0x41, 0x17, 0x0b, 0xa8, 0x83, 0x3d, 0x86, 0x83, 0xbc, 0xd5, 0xbe, 0x18, + 0x34, 0x35, 0xb5, 0xae, 0x36, 0x0e, 0xae, 0x15, 0x77, 0x99, 0x82, 0x67, 0x60, 0x07, 0x87, 0xad, + 0x76, 0xbb, 0xf9, 0x42, 0xdb, 0x98, 0xa3, 0x55, 0x62, 0x86, 0x31, 0x2a, 0xb1, 0x5a, 0x85, 0xcd, + 0x13, 0xb0, 0x0b, 0x76, 0xd3, 0x22, 0xe1, 0x31, 0x8b, 0x23, 0x6d, 0xb3, 0xae, 0x36, 0xf6, 0x5b, + 0xe7, 0xd6, 0x7d, 0x15, 0x59, 0xbd, 0xc2, 0xef, 0x62, 0xf1, 0x7a, 0xce, 0x7d, 0xd3, 0xa7, 0x98, + 0xf5, 0x49, 0x12, 0x5e, 0x2b, 0xee, 0xe2, 0x82, 0x15, 0x93, 0xb4, 0xa9, 0x6d, 0xfd, 0x61, 0x92, + 0x36, 0x21, 0x02, 0x47, 0x28, 0x8d, 0x33, 0xe2, 0x2d, 0x24, 0xb7, 0x4b, 0xc9, 0xe7, 0xf7, 0x4b, + 0xbe, 0xc2, 0x11, 0x0a, 0xc4, 0xe5, 0xec, 0xc4, 0x7a, 0xf5, 0xc3, 0xf2, 0xc6, 0x0a, 0x81, 0x6d, + 0x00, 0x50, 0x26, 0xbc, 0xbc, 0xf0, 0x07, 0x58, 0x68, 0xc7, 0xe5, 0xf5, 0x27, 0x96, 0xec, 0xb2, + 0x55, 0x75, 0xd9, 0xba, 0xcc, 0xc4, 0xcc, 0x19, 0xca, 0x44, 0xaf, 0x24, 0x76, 0x36, 0x7f, 0x0e, + 0x0d, 0xc5, 0xd9, 0x02, 0x35, 0x56, 0xa4, 0xe6, 0x57, 0x15, 0x3c, 0x58, 0x23, 0x08, 0x9f, 0x81, + 0x3d, 0x5e, 0x05, 0xe5, 0x1c, 0x0e, 0x9d, 0xd3, 0xc9, 0xd8, 0x50, 0xbb, 0x77, 0x63, 0xe3, 0x3f, + 0x81, 0xd2, 0xa4, 0x63, 0x2e, 0x70, 0xd3, 0x5d, 0x72, 0xa1, 0x07, 0xf6, 0xf3, 0x72, 0x9a, 0xde, + 0x00, 0x0b, 0xa6, 0x6d, 0xd4, 0x6b, 0x8d, 0xfd, 0x96, 0xb1, 0xb6, 0xd7, 0x72, 0xec, 0xce, 0xc3, + 0xc9, 0xd8, 0xd8, 0x91, 0x5e, 0xd8, 0xdd, 0xd8, 0x38, 0x92, 0x0a, 0xb2, 0x3a, 0x66, 0xba, 0x20, + 0xaf, 0x98, 0xcc, 0xbc, 0x00, 0x47, 0xa5, 0xdd, 0x9b, 0x38, 0xca, 0x10, 0x2f, 0x28, 0x86, 0x3a, + 0x00, 0xac, 0x0a, 0x98, 0xa6, 0xd6, 0x6b, 0x8d, 0x03, 0x77, 0x25, 0xd3, 0xd9, 0x1c, 0x0d, 0x0d, + 0xd5, 0x7c, 0x07, 0x8e, 0xaf, 0x48, 0x9a, 0xa3, 0x80, 0x3b, 0x31, 0xbf, 0xa4, 0x14, 0x09, 0xf8, + 0x04, 0xfc, 0x8f, 0x3f, 0x72, 0x8a, 0x3c, 0x3f, 0xe6, 0xcc, 0x63, 0x9c, 0x50, 0x3c, 0x2f, 0xd6, + 0x3d, 0x2e, 0x01, 0x27, 0xe6, 0xec, 0xa6, 0x4c, 0xc3, 0x13, 0xb0, 0x85, 0x13, 0x9c, 0x32, 0xb9, + 0x76, 0xae, 0x0c, 0x3a, 0xbb, 0x5f, 0x6e, 0x0d, 0xe5, 0x76, 0x68, 0x28, 0xe6, 0x27, 0x60, 0xfe, + 0x7d, 0x8e, 0xf0, 0x25, 0xa8, 0xcd, 0xe6, 0xa5, 0xfe, 0xc3, 0x06, 0xba, 0xb3, 0x93, 0x50, 0x03, + 0x3b, 0x28, 0x0c, 0x29, 0x66, 0x95, 0x91, 0x2a, 0x74, 0xae, 0xbe, 0x4d, 0x74, 0x75, 0x34, 0xd1, + 0xd5, 0x1f, 0x13, 0x5d, 0xfd, 0x3c, 0xd5, 0x95, 0xd1, 0x54, 0x57, 0xbe, 0x4f, 0x75, 0xe5, 0xed, + 0xe3, 0x28, 0xe6, 0xfd, 0xc2, 0xb7, 0x02, 0x92, 0xda, 0x52, 0x71, 0xfe, 0x3a, 0x67, 0xe1, 0xc0, + 0x5e, 0xfd, 0xe3, 0xfd, 0xed, 0x72, 0x75, 0x9e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x56, + 0xa0, 0xa2, 0x08, 0x04, 0x00, 0x00, } func (m *PublicKey) Marshal() (dAtA []byte, err error) { diff --git a/crypto/types/types.proto b/crypto/types/types.proto index 2aeb36b8f854..104d7e52941b 100644 --- a/crypto/types/types.proto +++ b/crypto/types/types.proto @@ -21,6 +21,8 @@ message PublicKey { // not explicitly defined in the oneof google.protobuf.Any any_pubkey = 15; // 15 is largest field that occupies one byte } + + option (gogoproto.typedecl) = false; } // PubKeyMultisigThreshold specifies a public key type which nests multiple public diff --git a/simapp/amino.go b/simapp/amino.go index ae20711db67e..911dbec25e44 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -3,37 +3,13 @@ package simapp import ( - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" ) -func MakeEncodingConfig() EncodingConfig { - cdc := std.MakeCodec(ModuleBasics) - interfaceRegistry := codectypes.NewInterfaceRegistry() - std.RegisterInterfaces(interfaceRegistry) - ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) - return EncodingConfig{ - InterfaceRegistry: interfaceRegistry, - Marshaler: marshaler, - TxDecoder: authtypes.DefaultTxDecoder(cdc), - TxGenerator: authtypes.StdTxGenerator{Cdc: cdc}, - Amino: cdc, - } -} - -func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { - cfg := MakeEncodingConfig() - return cfg.Marshaler, cfg.InterfaceRegistry, cfg.Amino -} - func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { return ante.NewAnteHandler( ak, bk, ibcK, ante.DefaultSigVerificationGasConsumer, diff --git a/simapp/app.go b/simapp/app.go index 88ebdfb10b0c..ba7ddd8d0d0c 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -4,6 +4,8 @@ import ( "io" "os" + params2 "github.com/cosmos/cosmos-sdk/simapp/params" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" @@ -95,7 +97,7 @@ type SimApp struct { *baseapp.BaseApp amino *codec.Codec marshaler codec.Marshaler - encodingConfig EncodingConfig + encodingConfig params2.EncodingConfig invCheckPeriod uint @@ -424,7 +426,7 @@ func (app *SimApp) AppCodec() codec.Marshaler { // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. -func (app *SimApp) GetEncodingConfig() EncodingConfig { +func (app *SimApp) GetEncodingConfig() params2.EncodingConfig { return app.encodingConfig } diff --git a/simapp/encoding.go b/simapp/encoding.go index ae06c93f8a73..916272813036 100644 --- a/simapp/encoding.go +++ b/simapp/encoding.go @@ -1,16 +1,22 @@ package simapp import ( - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/std" ) -type EncodingConfig struct { - InterfaceRegistry types.InterfaceRegistry - Marshaler codec.Marshaler - TxDecoder sdk.TxDecoder - TxGenerator context.TxGenerator - Amino *codec.Codec +func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { + cfg := MakeEncodingConfig() + return cfg.Marshaler, cfg.InterfaceRegistry, cfg.Amino +} + +func MakeEncodingConfig() params.EncodingConfig { + encodingConfig := params.MakeEncodingConfig() + std.RegisterCodec(encodingConfig.Amino) + std.RegisterInterfaces(encodingConfig.InterfaceRegistry) + ModuleBasics.RegisterCodec(encodingConfig.Amino) + ModuleBasics.RegisterInterfaceModules(encodingConfig.InterfaceRegistry) + return encodingConfig } diff --git a/simapp/params/amino.go b/simapp/params/amino.go new file mode 100644 index 000000000000..dc7cdfb8a63a --- /dev/null +++ b/simapp/params/amino.go @@ -0,0 +1,23 @@ +// +build test_amino + +package params + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func MakeEncodingConfig() EncodingConfig { + cdc := codec.New() + interfaceRegistry := types.NewInterfaceRegistry() + marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) + + return EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxDecoder: authtypes.DefaultTxDecoder(cdc), + TxGenerator: authtypes.StdTxGenerator{Cdc: cdc}, + Amino: cdc, + } +} diff --git a/simapp/params/encoding.go b/simapp/params/encoding.go new file mode 100644 index 000000000000..801c0415ccc0 --- /dev/null +++ b/simapp/params/encoding.go @@ -0,0 +1,16 @@ +package params + +import ( + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type EncodingConfig struct { + InterfaceRegistry types.InterfaceRegistry + Marshaler codec.Marshaler + TxDecoder sdk.TxDecoder + TxGenerator context.TxGenerator + Amino *codec.Codec +} diff --git a/simapp/params/proto.go b/simapp/params/proto.go new file mode 100644 index 000000000000..0d2bf2594465 --- /dev/null +++ b/simapp/params/proto.go @@ -0,0 +1,25 @@ +// +build !test_amino + +package params + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/types/tx/signing" +) + +func MakeEncodingConfig() EncodingConfig { + cdc := codec.New() + interfaceRegistry := types.NewInterfaceRegistry() + marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) + pubKeyCodec := cryptocodec.DefaultPublicKeyCodec{} + + return EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxDecoder: signing.DefaultTxDecoder(marshaler, pubKeyCodec), + TxGenerator: signing.NewTxGenerator(marshaler, pubKeyCodec), + Amino: cdc, + } +} diff --git a/simapp/proto.go b/simapp/proto.go index 83e74077821d..ce4c3741bfe3 100644 --- a/simapp/proto.go +++ b/simapp/proto.go @@ -3,40 +3,13 @@ package simapp import ( - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" ) -func MakeEncodingConfig() EncodingConfig { - cdc := std.MakeCodec(ModuleBasics) - interfaceRegistry := codectypes.NewInterfaceRegistry() - std.RegisterInterfaces(interfaceRegistry) - ModuleBasics.RegisterInterfaceModules(interfaceRegistry) - marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) - pubKeyCodec := cryptocodec.DefaultPublicKeyCodec{} - - return EncodingConfig{ - InterfaceRegistry: interfaceRegistry, - Marshaler: marshaler, - TxDecoder: signing.DefaultTxDecoder(marshaler, pubKeyCodec), - TxGenerator: signing.NewTxGenerator(marshaler, pubKeyCodec), - Amino: cdc, - } -} - -func MakeCodecs() (codec.Marshaler, codectypes.InterfaceRegistry, *codec.Codec) { - cfg := MakeEncodingConfig() - return cfg.Marshaler, cfg.InterfaceRegistry, cfg.Amino -} - func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { return ante.NewProtoAnteHandler( ak, bk, ibcK, ante.DefaultSigVerificationGasConsumer, diff --git a/std/codec.go b/std/codec.go index b3df5cd88330..7c04eedf59e3 100644 --- a/std/codec.go +++ b/std/codec.go @@ -18,13 +18,17 @@ func MakeCodec(bm module.BasicManager) *codec.Codec { cdc := codec.New() bm.RegisterCodec(cdc) - vesting.RegisterCodec(cdc) - sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) + RegisterCodec(cdc) return cdc } +func RegisterCodec(cdc *codec.Codec) { + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + vesting.RegisterCodec(cdc) +} + // RegisterInterfaces registers Interfaces from sdk/types and vesting func RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) { sdk.RegisterInterfaces(interfaceRegistry) diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index d389c519029e..df4a0e070176 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -1,35 +1,22 @@ package signing import ( - "fmt" - - "github.com/pkg/errors" - - "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" - antetypes "github.com/cosmos/cosmos-sdk/x/auth/ante/types" - auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) type DecodedTx struct { *types.Tx - Raw *TxRaw - Msgs []sdk.Msg - PubKeys []crypto.PubKey - Signers []sdk.AccAddress + Raw *TxRaw } -var _ sdk.Tx = DecodedTx{} -var _ antetypes.FeeTx = DecodedTx{} -var _ antetypes.TxWithMemo = DecodedTx{} -var _ antetypes.SigTx = DecodedTx{} +var _ types.ProtoTx = DecodedTx{} func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder { + keyCodec = cryptotypes.CacheWrapCodec(keyCodec) + return func(txBytes []byte) (sdk.Tx, error) { var raw TxRaw err := cdc.UnmarshalBinaryBare(txBytes, &raw) @@ -43,104 +30,17 @@ func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) return nil, err } - anyMsgs := tx.Body.Messages - msgs := make([]sdk.Msg, len(anyMsgs)) - for i, any := range anyMsgs { - msg, ok := any.GetCachedValue().(sdk.Msg) - if !ok { - return nil, fmt.Errorf("can't decode sdk.Msg from %+v", any) - } - msgs[i] = msg - } - - var signers []sdk.AccAddress - seen := map[string]bool{} - - for _, msg := range msgs { - for _, addr := range msg.GetSigners() { - if !seen[addr.String()] { - signers = append(signers, addr) - seen[addr.String()] = true - } - } - } - - signerInfos := tx.AuthInfo.SignerInfos - pubKeys := make([]crypto.PubKey, len(signerInfos)) - for i, si := range signerInfos { - pubKey, err := keyCodec.Decode(si.PublicKey) - if err != nil { - return nil, errors.Wrap(err, "can't decode public key") - } - pubKeys[i] = pubKey - } - return DecodedTx{ - Tx: &tx, - Raw: &raw, - Msgs: msgs, - PubKeys: pubKeys, - Signers: signers, + Tx: &tx, + Raw: &raw, }, nil } } -func (d DecodedTx) GetMsgs() []sdk.Msg { - return d.Msgs -} - -func (d DecodedTx) ValidateBasic() error { - sigs := d.Signatures - - if d.GetGas() > auth.MaxGasWanted { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "invalid gas supplied; %d > %d", d.GetGas(), auth.MaxGasWanted, - ) - } - if d.GetFee().IsAnyNegative() { - return sdkerrors.Wrapf( - sdkerrors.ErrInsufficientFee, - "invalid fee provided: %s", d.GetFee(), - ) - } - if len(sigs) == 0 { - return sdkerrors.ErrNoSignatures - } - if len(sigs) != len(d.GetSigners()) { - return sdkerrors.Wrapf( - sdkerrors.ErrUnauthorized, - "wrong number of signers; expected %d, got %d", d.GetSigners(), len(sigs), - ) - } - - return nil -} - -func (d DecodedTx) GetSigners() []sdk.AccAddress { - return d.Signers -} - -func (d DecodedTx) GetPubKeys() []crypto.PubKey { - return d.PubKeys -} - -func (d DecodedTx) GetGas() uint64 { - return d.AuthInfo.Fee.GasLimit -} - -func (d DecodedTx) GetFee() sdk.Coins { - return d.AuthInfo.Fee.Amount -} - -func (d DecodedTx) FeePayer() sdk.AccAddress { - signers := d.GetSigners() - if signers != nil { - return signers[0] - } - return sdk.AccAddress{} +func (m DecodedTx) GetBodyBytes() []byte { + return m.Raw.BodyBytes } -func (d DecodedTx) GetMemo() string { - return d.Body.Memo +func (m DecodedTx) GetAuthInfoBytes() []byte { + return m.Raw.AuthInfoBytes } diff --git a/types/tx/signing/direct.go b/types/tx/signing/direct.go index 11c636806315..01f4e07edaa5 100644 --- a/types/tx/signing/direct.go +++ b/types/tx/signing/direct.go @@ -1,6 +1,8 @@ package signing -import types "github.com/cosmos/cosmos-sdk/types/tx" +import ( + types "github.com/cosmos/cosmos-sdk/types/tx" +) type DirectModeHandler struct{} @@ -10,8 +12,10 @@ func (DirectModeHandler) Mode() types.SignMode { return types.SignMode_SIGN_MODE_DIRECT } -func (DirectModeHandler) GetSignBytes(data SigningData, tx DecodedTx) ([]byte, error) { - return DirectSignBytes(tx.Raw.BodyBytes, tx.Raw.AuthInfoBytes, data.ChainID, data.AccountNumber, data.AccountSequence) +func (DirectModeHandler) GetSignBytes(data SigningData, tx types.ProtoTx) ([]byte, error) { + bodyBz := tx.GetBodyBytes() + authInfoBz := tx.GetAuthInfoBytes() + return DirectSignBytes(bodyBz, authInfoBz, data.ChainID, data.AccountNumber, data.AccountSequence) } func DirectSignBytes(bodyBz, authInfoBz []byte, chainID string, accnum, sequence uint64) ([]byte, error) { diff --git a/types/tx/signing/handler.go b/types/tx/signing/handler.go index cebee8e22641..3746ef232fdf 100644 --- a/types/tx/signing/handler.go +++ b/types/tx/signing/handler.go @@ -16,5 +16,5 @@ type SigningData struct { type SignModeHandler interface { Mode() types.SignMode - GetSignBytes(data SigningData, tx DecodedTx) ([]byte, error) + GetSignBytes(data SigningData, tx types.ProtoTx) ([]byte, error) } diff --git a/types/tx/signing/legacy_amino_json.go b/types/tx/signing/legacy_amino_json.go index 59e02cf6cd3d..ec6089d5c6e8 100644 --- a/types/tx/signing/legacy_amino_json.go +++ b/types/tx/signing/legacy_amino_json.go @@ -13,8 +13,8 @@ func (LegacyAminoJSONHandler) Mode() types.SignMode { return types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON } -func (LegacyAminoJSONHandler) GetSignBytes(data SigningData, tx DecodedTx) ([]byte, error) { +func (LegacyAminoJSONHandler) GetSignBytes(data SigningData, tx types.ProtoTx) ([]byte, error) { return auth.StdSignBytes( - data.ChainID, data.AccountNumber, data.AccountSequence, auth.StdFee{Amount: tx.GetFee(), Gas: tx.GetGas()}, tx.Msgs, tx.Body.Memo, + data.ChainID, data.AccountNumber, data.AccountSequence, auth.StdFee{Amount: tx.GetFee(), Gas: tx.GetGas()}, tx.GetMsgs(), tx.GetBody().Memo, ), nil } diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index dd47a6b43c9f..3834c11ce415 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -17,7 +17,7 @@ type TxGenerator struct { } func NewTxGenerator(marshaler codec.Marshaler, pubKeyCodec cryptotypes.PublicKeyCodec) *TxGenerator { - return &TxGenerator{Marshaler: marshaler, PubKeyCodec: pubKeyCodec} + return &TxGenerator{Marshaler: marshaler, PubKeyCodec: cryptotypes.CacheWrapCodec(pubKeyCodec)} } var _ context.TxGenerator = TxGenerator{} diff --git a/types/tx/tx.go b/types/tx/tx.go index 5d90f52a5618..dd9c7b91bf51 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -1,10 +1,129 @@ package types import ( + "github.com/tendermint/tendermint/crypto" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + antetypes "github.com/cosmos/cosmos-sdk/x/auth/ante/types" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) +type ProtoTx interface { + sdk.Tx + antetypes.FeeTx + antetypes.TxWithMemo + antetypes.SigTx + + GetBody() *TxBody + GetAuthInfo() *AuthInfo + GetSignatures() [][]byte + + GetBodyBytes() []byte + GetAuthInfoBytes() []byte +} + +var _ ProtoTx = &Tx{} + +func (tx *Tx) GetMsgs() []sdk.Msg { + anys := tx.Body.Messages + res := make([]sdk.Msg, len(anys)) + for i, any := range anys { + msg := any.GetCachedValue().(sdk.Msg) + res[i] = msg + } + return res +} + +func (tx *Tx) ValidateBasic() error { + sigs := tx.GetSignatures() + + if tx.GetGas() > auth.MaxGasWanted { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidRequest, + "invalid gas supplied; %d > %d", tx.GetGas(), auth.MaxGasWanted, + ) + } + if tx.GetFee().IsAnyNegative() { + return sdkerrors.Wrapf( + sdkerrors.ErrInsufficientFee, + "invalid fee provided: %s", tx.GetFee(), + ) + } + if len(sigs) == 0 { + return sdkerrors.ErrNoSignatures + } + if len(sigs) != len(tx.GetSigners()) { + return sdkerrors.Wrapf( + sdkerrors.ErrUnauthorized, + "wrong number of signers; expected %d, got %d", tx.GetSigners(), len(sigs), + ) + } + + return nil +} + +func (m *Tx) GetGas() uint64 { + return m.AuthInfo.Fee.GasLimit +} + +func (m *Tx) GetFee() sdk.Coins { + return m.AuthInfo.Fee.Amount +} + +func (m *Tx) FeePayer() sdk.AccAddress { + signers := m.GetSigners() + if signers != nil { + return signers[0] + } + return sdk.AccAddress{} +} + +func (m *Tx) GetMemo() string { + return m.Body.Memo +} + +func (m *Tx) GetSigners() []sdk.AccAddress { + var signers []sdk.AccAddress + seen := map[string]bool{} + + for _, msg := range m.GetMsgs() { + for _, addr := range msg.GetSigners() { + if !seen[addr.String()] { + signers = append(signers, addr) + seen[addr.String()] = true + } + } + } + return signers +} + +func (m *Tx) GetPubKeys() []crypto.PubKey { + signerInfos := m.AuthInfo.SignerInfos + res := make([]crypto.PubKey, len(signerInfos)) + for i, si := range signerInfos { + res[i] = si.PublicKey.GetCachedPubKey() + } + return res +} + +func (m *Tx) GetBodyBytes() []byte { + bz, err := m.Body.Marshal() + if err != nil { + panic(err) + } + return bz +} + +func (m *Tx) GetAuthInfoBytes() []byte { + bz, err := m.AuthInfo.Marshal() + if err != nil { + panic(err) + } + return bz +} + var _ codectypes.UnpackInterfacesMessage = &Tx{} var _ codectypes.UnpackInterfacesMessage = &TxBody{} var _ codectypes.UnpackInterfacesMessage = &SignDoc{} @@ -27,43 +146,3 @@ func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { } return nil } - -var _ sdk.Tx = &Tx{} - -func (tx *Tx) GetMsgs() []sdk.Msg { - anys := tx.Body.Messages - res := make([]sdk.Msg, len(anys)) - for i, any := range anys { - msg := any.GetCachedValue().(sdk.Msg) - res[i] = msg - } - return res -} - -func (tx *Tx) ValidateBasic() error { - // TODO - //stdSigs := tx.GetSignatures() - // - //if tx.Fee.Gas > MaxGasWanted { - // return sdkerrors.Wrapf( - // sdkerrors.ErrInvalidRequest, - // "invalid gas supplied; %d > %d", tx.Fee.Gas, MaxGasWanted, - // ) - //} - //if tx.Fee.Amount.IsAnyNegative() { - // return sdkerrors.Wrapf( - // sdkerrors.ErrInsufficientFee, - // "invalid fee provided: %s", tx.Fee.Amount, - // ) - //} - //if len(stdSigs) == 0 { - // return sdkerrors.ErrNoSignatures - //} - //if len(stdSigs) != len(tx.GetSigners()) { - // return sdkerrors.Wrapf( - // sdkerrors.ErrUnauthorized, - // "wrong number of signers; expected %d, got %d", tx.GetSigners(), len(stdSigs), - // ) - //} - return nil -} diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 5004ee77d66d..c540e6c2768b 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -33,7 +33,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, if ctx.IsReCheckTx() { return next(ctx, tx, simulate) } - sigTx, ok := tx.(signing.DecodedTx) + sigTx, ok := tx.(types.ProtoTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -60,7 +60,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, signerAccs[i] = signerAcc - signerInfo := sigTx.AuthInfo.SignerInfos[i] + signerInfo := sigTx.GetAuthInfo().SignerInfos[i] // retrieve pubkey pubKey := signerAccs[i].GetPubKey() @@ -114,7 +114,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return next(ctx, tx, simulate) } -func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, single *types.ModeInfo_Single, signerAcc auth.AccountI, sigTx signing.DecodedTx) ([]byte, error) { +func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, single *types.ModeInfo_Single, signerAcc auth.AccountI, sigTx types.ProtoTx) ([]byte, error) { verifier, found := svd.signModeHandlers[single.Mode] if !found { return nil, fmt.Errorf("can't verify sign mode %s", single.Mode.String()) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index e0763892fe3c..2e8d4f22b2df 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -104,7 +104,8 @@ func sendMsgSend( } } - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, privkeys...) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, privkeys...) _, _, err = app.Deliver(tx) if err != nil { @@ -235,7 +236,8 @@ func sendMsgMultiSend(r *rand.Rand, app *baseapp.BaseApp, bk keeper.Keeper, ak t } } - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, accountNumbers, sequenceNumbers, privkeys...) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, accountNumbers, sequenceNumbers, privkeys...) _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 8d0b9ad1db3f..01aec0c6ead9 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -100,7 +100,8 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -139,7 +140,8 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -181,7 +183,8 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -223,7 +226,8 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k } msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, funder.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, funder.PrivKey) _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index c15c07b7d71a..4a8783d365d0 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -142,7 +142,8 @@ func SimulateSubmitProposal( } } - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -216,7 +217,8 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } } - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -266,7 +268,8 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err } - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index f0db4bd84c98..72899cb072ee 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -86,7 +86,8 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, res, err := app.Deliver(tx) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 8f8913b07d56..46286ee2cf32 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -151,7 +151,8 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k msg := types.NewMsgCreateValidator(address, simAccount.PubKey, selfDelegation, description, commission, sdk.OneInt()) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -209,7 +210,8 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -269,7 +271,8 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -343,7 +346,8 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err } - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { @@ -440,7 +444,8 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k sdk.NewCoin(k.BondDenom(ctx), redAmt), ) - tx := helpers.GenTx(nil, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx := helpers.GenTx(txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, simAccount.PrivKey) _, _, err = app.Deliver(tx) if err != nil { From 2e797a151701b2fd13035340f37567973ba9c059 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 27 May 2020 17:37:21 -0400 Subject: [PATCH 41/54] test fixes --- client/context/tx_generator.go | 20 +++---- client/tx/tx.go | 6 +- codec/types/types_test.go | 13 +++++ simapp/amino.go | 13 +++++ simapp/app.go | 4 +- simapp/cmd/simcli/proto.go | 2 +- simapp/helpers/test_helpers.go | 2 +- simapp/params/amino.go | 1 + simapp/params/encoding.go | 1 + simapp/params/proto.go | 4 +- simapp/proto.go | 6 ++ simapp/test_helpers.go | 2 +- tests/cli/fixtures.go | 17 +++--- tests/cli/helpers.go | 27 ++++++--- types/tx/signing/amino.go | 99 ++++++++++++++++++++++++++++++++ types/tx/signing/decoded_tx.go | 24 +++++++- types/tx/signing/json.go | 31 ++++++++++ types/tx/signing/tx_generator.go | 20 +++---- types/tx/tx.go | 8 +++ types/types.proto | 69 +++++++++++++--------- x/auth/client/cli/cli_test.go | 30 +++++----- x/auth/types/client_tx.go | 8 +-- x/auth/types/stdtx.go | 19 ++++++ x/bank/client/cli/cli_test.go | 6 +- x/genutil/alias.go | 3 - x/genutil/genesis.go | 6 +- x/genutil/gentx.go | 14 +++-- x/genutil/module.go | 24 +++++--- x/gov/client/cli/cli_test.go | 18 +++--- x/staking/client/cli/cli_test.go | 6 +- 30 files changed, 375 insertions(+), 128 deletions(-) create mode 100644 types/tx/signing/amino.go create mode 100644 types/tx/signing/json.go diff --git a/client/context/tx_generator.go b/client/context/tx_generator.go index ff023fcec06f..28c15f453c8f 100644 --- a/client/context/tx_generator.go +++ b/client/context/tx_generator.go @@ -3,7 +3,7 @@ package context import ( "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) type ( @@ -11,20 +11,20 @@ type ( // application-defined concrete transaction type. The type returned must // implement TxBuilder. TxGenerator interface { - NewTx() TxBuilder + NewTxBuilder() TxBuilder NewFee() ClientFee NewSignature() ClientSignature - MarshalTx(tx types.Tx) ([]byte, error) + TxEncoder() sdk.TxEncoder } ClientFee interface { - types.Fee + sdk.Fee SetGas(uint64) - SetAmount(types.Coins) + SetAmount(sdk.Coins) } ClientSignature interface { - types.Signature + sdk.Signature SetPubKey(crypto.PubKey) error SetSignature([]byte) } @@ -34,12 +34,12 @@ type ( // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. TxBuilder interface { - GetTx() types.Tx + GetTx() sdk.Tx - SetMsgs(...types.Msg) error - GetSignatures() []types.Signature + SetMsgs(...sdk.Msg) error + GetSignatures() []sdk.Signature SetSignatures(...ClientSignature) error - GetFee() types.Fee + GetFee() sdk.Fee SetFee(ClientFee) error GetMemo() string SetMemo(string) diff --git a/client/tx/tx.go b/client/tx/tx.go index b7548cda1058..bd8ae75baaa1 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -213,7 +213,7 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (context.TxBuilder, error) { clientFee.SetAmount(fees) clientFee.SetGas(txf.gas) - tx := txf.txGenerator.NewTx() + tx := txf.txGenerator.NewTxBuilder() tx.SetMemo(txf.memo) if err := tx.SetFee(clientFee); err != nil { @@ -248,7 +248,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { return nil, err } - return txf.txGenerator.MarshalTx(tx.GetTx()) + return txf.txGenerator.TxEncoder()(tx.GetTx()) } // CalculateGas simulates the execution of a transaction and returns the @@ -338,7 +338,7 @@ func Sign(txf Factory, name, passphrase string, tx context.TxBuilder) ([]byte, e return nil, err } - return txf.txGenerator.MarshalTx(tx.GetTx()) + return txf.txGenerator.TxEncoder()(tx.GetTx()) } // GasEstimateResponse defines a response definition for tx gas estimation. diff --git a/codec/types/types_test.go b/codec/types/types_test.go index d55dd38a6a4a..dd1d4530a865 100644 --- a/codec/types/types_test.go +++ b/codec/types/types_test.go @@ -3,6 +3,8 @@ package types_test import ( "testing" + "github.com/gogo/protobuf/jsonpb" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/stretchr/testify/require" @@ -131,3 +133,14 @@ func TestNested(t *testing.T) { require.Equal(t, spot, hhha2.TheHasHasAnimal().TheHasAnimal().TheAnimal()) } + +func TestAny_ProtoJSON(t *testing.T) { + spot := &testdata.Dog{Name: "Spot"} + any, err := types.NewAnyWithValue(spot) + require.NoError(t, err) + + jm := &jsonpb.Marshaler{} + json, err := jm.MarshalToString(any) + require.NoError(t, err) + require.Equal(t, "{\"@type\":\"/cosmos_sdk.codec.v1.Dog\",\"name\":\"Spot\"}", json) +} diff --git a/simapp/amino.go b/simapp/amino.go index 911dbec25e44..f0b905ba62bf 100644 --- a/simapp/amino.go +++ b/simapp/amino.go @@ -3,13 +3,26 @@ package simapp import ( + "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" ) +func AminoJSONTxDecoder(cfg params.EncodingConfig) types.TxDecoder { + return func(txBytes []byte) (types.Tx, error) { + var tx authtypes.StdTx + err := cfg.Marshaler.UnmarshalJSON(txBytes, &tx) + if err != nil { + return nil, err + } + return tx, nil + } +} + func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { return ante.NewAnteHandler( ak, bk, ibcK, ante.DefaultSigVerificationGasConsumer, diff --git a/simapp/app.go b/simapp/app.go index ba7ddd8d0d0c..a64ab6797443 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -266,7 +266,9 @@ func NewSimApp( // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. app.mm = module.NewManager( - genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx), + genutil.NewAppModule( + app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, + AminoJSONTxDecoder(encodingConfig), encodingConfig.TxGenerator.TxEncoder()), auth.NewAppModule(marshaler, app.AccountKeeper), bank.NewAppModule(marshaler, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(marshaler, *app.CapabilityKeeper), diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index b176ee75cf53..ea022c7bdd88 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -10,7 +10,7 @@ import ( func MakeTxCLIContext() context.CLIContext { cliCtx := context.CLIContext{} - protoCdc := codec.NewHybridCodec(encodingConfig.Amino, encodingConfig.InterfaceRegistry) + protoCdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) return cliCtx. WithJSONMarshaler(protoCdc). WithTxGenerator(encodingConfig.TxGenerator). diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index c7c8452f6995..7cba4000dc8d 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -39,7 +39,7 @@ func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64 sigs[i] = clientSig } - tx := gen.NewTx() + tx := gen.NewTxBuilder() tx.SetMsgs(msgs...) tx.SetFee(fee) tx.SetSignatures(sigs...) diff --git a/simapp/params/amino.go b/simapp/params/amino.go index dc7cdfb8a63a..e34cdb6118a9 100644 --- a/simapp/params/amino.go +++ b/simapp/params/amino.go @@ -17,6 +17,7 @@ func MakeEncodingConfig() EncodingConfig { InterfaceRegistry: interfaceRegistry, Marshaler: marshaler, TxDecoder: authtypes.DefaultTxDecoder(cdc), + TxJSONDecoder: authtypes.DefaultJSONTxDecoder(cdc), TxGenerator: authtypes.StdTxGenerator{Cdc: cdc}, Amino: cdc, } diff --git a/simapp/params/encoding.go b/simapp/params/encoding.go index 801c0415ccc0..5f2f5d04a778 100644 --- a/simapp/params/encoding.go +++ b/simapp/params/encoding.go @@ -11,6 +11,7 @@ type EncodingConfig struct { InterfaceRegistry types.InterfaceRegistry Marshaler codec.Marshaler TxDecoder sdk.TxDecoder + TxJSONDecoder sdk.TxDecoder TxGenerator context.TxGenerator Amino *codec.Codec } diff --git a/simapp/params/proto.go b/simapp/params/proto.go index 0d2bf2594465..f98335b1e4af 100644 --- a/simapp/params/proto.go +++ b/simapp/params/proto.go @@ -14,12 +14,14 @@ func MakeEncodingConfig() EncodingConfig { interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) pubKeyCodec := cryptocodec.DefaultPublicKeyCodec{} + txGen := signing.NewTxGenerator(marshaler, pubKeyCodec) return EncodingConfig{ InterfaceRegistry: interfaceRegistry, Marshaler: marshaler, TxDecoder: signing.DefaultTxDecoder(marshaler, pubKeyCodec), - TxGenerator: signing.NewTxGenerator(marshaler, pubKeyCodec), + TxJSONDecoder: signing.DefaultJSONTxDecoder(marshaler, pubKeyCodec), + TxGenerator: txGen, Amino: cdc, } } diff --git a/simapp/proto.go b/simapp/proto.go index ce4c3741bfe3..6a68416a9193 100644 --- a/simapp/proto.go +++ b/simapp/proto.go @@ -3,13 +3,19 @@ package simapp import ( + "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/ibc" ) +func AminoJSONTxDecoder(enc params.EncodingConfig) types.TxDecoder { + return signing.AminoJSONTxDecoder(enc.Marshaler, enc.TxGenerator) +} + func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, ibcK ibc.Keeper) types.AnteHandler { return ante.NewProtoAnteHandler( ak, bk, ibcK, ante.DefaultSigVerificationGasConsumer, diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 7caa3080db32..22e8df873524 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -255,7 +255,7 @@ func SignCheckDeliver( priv..., ) - txBytes, err := txGen.MarshalTx(tx) + txBytes, err := txGen.TxEncoder()(tx) require.Nil(t, err) // Must simulate now as CheckTx doesn't run Msgs anymore diff --git a/tests/cli/fixtures.go b/tests/cli/fixtures.go index c0e5afe10129..bcec1516afbc 100644 --- a/tests/cli/fixtures.go +++ b/tests/cli/fixtures.go @@ -6,15 +6,14 @@ import ( "path/filepath" "testing" - "github.com/cosmos/cosmos-sdk/codec/types" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/stretchr/testify/require" tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/params" ) // Fixtures is used to setup the testing environment @@ -32,6 +31,7 @@ type Fixtures struct { JSONMarshaler codec.JSONMarshaler Amino *codec.Codec InterfaceRegistry types.InterfaceRegistry + EncodingConfig params.EncodingConfig T *testing.T } @@ -51,7 +51,7 @@ func NewFixtures(t *testing.T) *Fixtures { t.Skip("builddir is empty, skipping") } - cdc, interfaceRegistry, amino := simapp.MakeCodecs() + encodingConfig := simapp.MakeEncodingConfig() return &Fixtures{ T: t, @@ -63,9 +63,10 @@ func NewFixtures(t *testing.T) *Fixtures { SimcliHome: filepath.Join(tmpDir, ".simcli"), RPCAddr: servAddr, P2PAddr: p2pAddr, - JSONMarshaler: cdc, - InterfaceRegistry: interfaceRegistry, - Amino: amino, + JSONMarshaler: encodingConfig.Marshaler, + InterfaceRegistry: encodingConfig.InterfaceRegistry, + Amino: encodingConfig.Amino, + EncodingConfig: encodingConfig, Port: port, } } diff --git a/tests/cli/helpers.go b/tests/cli/helpers.go index 44c91860d107..f7989a59d3e4 100644 --- a/tests/cli/helpers.go +++ b/tests/cli/helpers.go @@ -7,14 +7,14 @@ import ( "path/filepath" "strings" + "github.com/cosmos/cosmos-sdk/x/auth/ante/types" + "github.com/stretchr/testify/require" clientkeys "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" ) var ( @@ -191,18 +191,29 @@ func AddFlags(cmd string, flags []string) string { return strings.TrimSpace(cmd) } -func UnmarshalStdTx(t require.TestingT, c *codec.Codec, s string) (stdTx auth.StdTx) { - require.Nil(t, c.UnmarshalJSON([]byte(s), &stdTx)) - return +type CLITx interface { + types.SigTx + types.FeeTx + types.TxWithMemo + + SetMemo(string) +} + +func (f Fixtures) UnmarshalTxJSON(s string) CLITx { + tx, err := f.EncodingConfig.TxJSONDecoder([]byte(s)) + require.Nil(f.T, err) + sigTx, ok := tx.(CLITx) + require.True(f.T, ok, "couldn't decode tx") + return sigTx } func buildEventsQueryString(events []string) string { return strings.Join(events, "&") } -func MarshalStdTx(t require.TestingT, c *codec.Codec, stdTx auth.StdTx) []byte { - bz, err := c.MarshalBinaryBare(stdTx) - require.NoError(t, err) +func (f Fixtures) MarshalTx(tx sdk.Tx) []byte { + bz, err := f.EncodingConfig.TxGenerator.TxEncoder()(tx) + require.NoError(f.T, err) return bz } diff --git a/types/tx/signing/amino.go b/types/tx/signing/amino.go new file mode 100644 index 000000000000..0c57551867dd --- /dev/null +++ b/types/tx/signing/amino.go @@ -0,0 +1,99 @@ +package signing + +import ( + "fmt" + + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/multisig" + + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen context.TxGenerator) sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + var aminoTx auth.StdTx + err := aminoJsonMarshaler.UnmarshalJSON(txBytes, &aminoTx) + if err != nil { + return nil, err + } + + txBuilder := txGen.NewTxBuilder() + + // set msgs + err = txBuilder.SetMsgs(aminoTx.Msgs...) + if err != nil { + return nil, err + } + + txBuilder.SetMemo(aminoTx.Memo) + + // set fee + fee := txGen.NewFee() + fee.SetGas(aminoTx.Fee.Gas) + fee.SetAmount(aminoTx.Fee.Amount) + err = txBuilder.SetFee(fee) + if err != nil { + return nil, err + } + + n := len(aminoTx.Signatures) + clientSigs := make([]context.ClientSignature, n) + pubKeys := aminoTx.GetPubKeys() + sigs := aminoTx.GetSignatures() + + for i := 0; i < n; i++ { + csig := txGen.NewSignature() + + pubKey := pubKeys[i] + + miSig, ok := csig.(ModeInfoSignature) + if !ok { + return nil, fmt.Errorf("can't set ModeInfo") + } + miSig.SetModeInfo(makeAminoModeInfo(pubKey)) + + fmt.Printf("amino decoded pubkey: %T\n", pubKey) + err = csig.SetPubKey(pubKey) + if err != nil { + return nil, err + } + + csig.SetSignature(sigs[i]) + + clientSigs[i] = csig + } + + err = txBuilder.SetSignatures(clientSigs...) + if err != nil { + return nil, err + } + + return txBuilder.GetTx(), nil + } +} + +func makeAminoModeInfo(pk crypto.PubKey) *types.ModeInfo { + if multisigPk, ok := pk.(multisig.PubKeyMultisigThreshold); ok { + multi := &types.ModeInfo_Multi{} + for i, k := range multisigPk.PubKeys { + multi.ModeInfos[i] = makeAminoModeInfo(k) + } + return &types.ModeInfo{ + Sum: &types.ModeInfo_Multi_{ + Multi: multi, + }, + } + } else { + return &types.ModeInfo{ + Sum: &types.ModeInfo_Single_{ + Single: &types.ModeInfo_Single{ + Mode: types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + }, + }, + } + } +} diff --git a/types/tx/signing/decoded_tx.go b/types/tx/signing/decoded_tx.go index df4a0e070176..a12c39615ba9 100644 --- a/types/tx/signing/decoded_tx.go +++ b/types/tx/signing/decoded_tx.go @@ -1,6 +1,8 @@ package signing import ( + "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -9,7 +11,8 @@ import ( type DecodedTx struct { *types.Tx - Raw *TxRaw + Raw *TxRaw + PubKeys []crypto.PubKey } var _ types.ProtoTx = DecodedTx{} @@ -30,9 +33,20 @@ func DefaultTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) return nil, err } + signerInfos := tx.AuthInfo.SignerInfos + pks := make([]crypto.PubKey, len(signerInfos)) + for i, si := range signerInfos { + pk, err := keyCodec.Decode(si.PublicKey) + if err != nil { + return nil, err + } + pks[i] = pk + } + return DecodedTx{ - Tx: &tx, - Raw: &raw, + Tx: &tx, + Raw: &raw, + PubKeys: pks, }, nil } } @@ -44,3 +58,7 @@ func (m DecodedTx) GetBodyBytes() []byte { func (m DecodedTx) GetAuthInfoBytes() []byte { return m.Raw.AuthInfoBytes } + +func (m DecodedTx) GetPubKeys() []crypto.PubKey { + return m.PubKeys +} diff --git a/types/tx/signing/json.go b/types/tx/signing/json.go new file mode 100644 index 000000000000..af03cee6c17c --- /dev/null +++ b/types/tx/signing/json.go @@ -0,0 +1,31 @@ +package signing + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +func DefaultJSONTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder { + keyCodec = cryptotypes.CacheWrapCodec(keyCodec) + + return func(txBytes []byte) (sdk.Tx, error) { + var tx types.Tx + err := cdc.UnmarshalJSON(txBytes, &tx) + if err != nil { + return nil, err + } + + // this decodes pubkeys and makes sure they are cached + signerInfos := tx.AuthInfo.SignerInfos + for _, si := range signerInfos { + _, err := keyCodec.Decode(si.PublicKey) + if err != nil { + return nil, err + } + } + + return &tx, nil + } +} diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index 3834c11ce415..f7dee1814584 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -22,13 +22,9 @@ func NewTxGenerator(marshaler codec.Marshaler, pubKeyCodec cryptotypes.PublicKey var _ context.TxGenerator = TxGenerator{} -func (t TxGenerator) NewTx() context.TxBuilder { +func (t TxGenerator) NewTxBuilder() context.TxBuilder { return TxBuilder{ - Tx: &types.Tx{ - Body: &types.TxBody{}, - AuthInfo: &types.AuthInfo{}, - Signatures: nil, - }, + Tx: types.NewTx(), Marshaler: t.Marshaler, PubKeyCodec: t.PubKeyCodec, } @@ -51,10 +47,12 @@ func (t TxGenerator) NewSignature() context.ClientSignature { } } -func (t TxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { - ptx, ok := tx.(*types.Tx) - if !ok { - return nil, fmt.Errorf("expected protobuf Tx, got %T", tx) +func (t TxGenerator) TxEncoder() sdk.TxEncoder { + return func(tx sdk.Tx) ([]byte, error) { + ptx, ok := tx.(*types.Tx) + if !ok { + return nil, fmt.Errorf("expected protobuf Tx, got %T", tx) + } + return t.Marshaler.MarshalBinaryBare(ptx) } - return t.Marshaler.MarshalBinaryBare(ptx) } diff --git a/types/tx/tx.go b/types/tx/tx.go index dd9c7b91bf51..141a2661e665 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -26,6 +26,14 @@ type ProtoTx interface { var _ ProtoTx = &Tx{} +func NewTx() *Tx { + return &Tx{ + Body: &TxBody{}, + AuthInfo: &AuthInfo{}, + Signatures: nil, + } +} + func (tx *Tx) GetMsgs() []sdk.Msg { anys := tx.Body.Messages res := make([]sdk.Msg, len(anys)) diff --git a/types/types.proto b/types/types.proto index c26219caa789..56a796f06723 100644 --- a/types/types.proto +++ b/types/types.proto @@ -4,19 +4,19 @@ package cosmos_sdk.v1; import "third_party/proto/gogoproto/gogo.proto"; import "third_party/proto/tendermint/abci/types/types.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/types"; +option go_package = "github.com/cosmos/cosmos-sdk/types"; option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.stringer_all) = false; +option (gogoproto.stringer_all) = false; // Coin defines a token with a denomination and an amount. // // NOTE: The amount field is an Int which implements the custom method // signatures required by gogoproto. message Coin { - option (gogoproto.equal) = true; + option (gogoproto.equal) = true; - string denom = 1; - string amount = 2 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; + string denom = 1; + string amount = 2 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; } // DecCoin defines a token with a denomination and a decimal amount. @@ -24,57 +24,72 @@ message Coin { // NOTE: The amount field is an Dec which implements the custom method // signatures required by gogoproto. message DecCoin { - option (gogoproto.equal) = true; + option (gogoproto.equal) = true; - string denom = 1; - string amount = 2 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; + string denom = 1; + string amount = 2 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; } // IntProto defines a Protobuf wrapper around an Int object. message IntProto { - string int = 1 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; + string int = 1 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false]; } // DecProto defines a Protobuf wrapper around a Dec object. message DecProto { - string dec = 1 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; + string dec = 1 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false]; } // ValAddresses defines a repeated set of validator addresses. message ValAddresses { - option (gogoproto.stringer) = true; + option (gogoproto.stringer) = true; - repeated bytes addresses = 1 [(gogoproto.casttype) = "ValAddress"]; + repeated bytes addresses = 1 [(gogoproto.casttype) = "ValAddress"]; } // GasInfo defines tx execution gas context. message GasInfo { - // GasWanted is the maximum units of work we allow this tx to perform. - uint64 gas_wanted = 1 [(gogoproto.moretags) = "yaml:\"gas_wanted\""]; + // GasWanted is the maximum units of work we allow this tx to perform. + uint64 gas_wanted = 1 [(gogoproto.moretags) = "yaml:\"gas_wanted\""]; - // GasUsed is the amount of gas actually consumed. - uint64 gas_used = 2 [(gogoproto.moretags) = "yaml:\"gas_used\""]; + // GasUsed is the amount of gas actually consumed. + uint64 gas_used = 2 [(gogoproto.moretags) = "yaml:\"gas_used\""]; } // Result is the union of ResponseFormat and ResponseCheckTx. message Result { - option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_getters) = false; - // Data is any data returned from message or handler execution. It MUST be length - // prefixed in order to separate data from multiple message executions. - bytes data = 1; + // Data is any data returned from message or handler execution. It MUST be length + // prefixed in order to separate data from multiple message executions. + bytes data = 1; - // Log contains the log information from message or handler execution. - string log = 2; + // Log contains the log information from message or handler execution. + string log = 2; - // Events contains a slice of Event objects that were emitted during message or - // handler execution. - repeated tendermint.abci.types.Event events = 3 [(gogoproto.nullable) = false]; + // Events contains a slice of Event objects that were emitted during message or + // handler execution. + repeated tendermint.abci.types.Event events = 3 [(gogoproto.nullable) = false]; } // SimulationResponse defines the response generated when a transaction is // successfully simulated. message SimulationResponse { - GasInfo gas_info = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; - Result result = 2; + GasInfo gas_info = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; + Result result = 2; +} + +message TxResponse { + int64 height = 1; + string txhash = 2; + string codespace = 3; + uint32 code = 4; + string data = 5; + string raw_log = 6; + // Logs ABCIMessageLogs `json:"logs,omitempty"` + string info = 8; + int64 gas_wanted = 9; + int64 gas_used = 10; + // google.protobuf.Any tx = 11; + // google.protobuf.Timestamp = 12; } diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 42662e9fe24d..b4d637b476d3 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -45,9 +45,9 @@ func TestCLIValidateSignatures(t *testing.T) { success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name()) require.True(t, success) - stdTx := cli.UnmarshalStdTx(t, f.Amino, stdout) + stdTx := f.UnmarshalTxJSON(stdout) - require.Equal(t, len(stdTx.Msgs), 1) + require.Equal(t, len(stdTx.GetMsgs()), 1) require.Equal(t, 1, len(stdTx.GetSignatures())) require.Equal(t, fooAddr.String(), stdTx.GetSigners()[0].String()) @@ -60,8 +60,8 @@ func TestCLIValidateSignatures(t *testing.T) { require.True(t, success) // modify the transaction - stdTx.Memo = "MODIFIED-ORIGINAL-TX-BAD" - bz := cli.MarshalStdTx(t, f.Amino, stdTx) + stdTx.SetMemo("MODIFIED-ORIGINAL-TX-BAD") + bz := f.MarshalTx(stdTx) modSignedTxFile, cleanup := tests.WriteToNewTempFile(t, string(bz)) t.Cleanup(cleanup) @@ -89,9 +89,9 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { success, stdout, stderr := bankcli.TxSend(f, fooAddr.String(), barAddr, sdk.NewCoin(cli.Denom, sendTokens), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg := cli.UnmarshalStdTx(t, f.Amino, stdout) - require.Equal(t, msg.Fee.Gas, uint64(flags.DefaultGasLimit)) - require.Equal(t, len(msg.Msgs), 1) + msg := f.UnmarshalTxJSON(stdout) + require.Equal(t, msg.GetGas(), uint64(flags.DefaultGasLimit)) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 0, len(msg.GetSignatures())) // Test generate sendTx with --gas=$amount @@ -99,18 +99,18 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Amino, stdout) - require.Equal(t, msg.Fee.Gas, uint64(100)) - require.Equal(t, len(msg.Msgs), 1) + msg = f.UnmarshalTxJSON(stdout) + require.Equal(t, msg.GetGas(), uint64(100)) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 0, len(msg.GetSignatures())) // Test generate sendTx, estimate gas success, stdout, stderr = bankcli.TxSend(f, fooAddr.String(), barAddr, sdk.NewCoin(cli.Denom, sendTokens), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Amino, stdout) - require.True(t, msg.Fee.Gas > 0) - require.Equal(t, len(msg.Msgs), 1) + msg = f.UnmarshalTxJSON(stdout) + require.True(t, msg.GetGas() > 0) + require.Equal(t, len(msg.GetMsgs()), 1) // Write the output to disk unsignedTxFile, cleanup := tests.WriteToNewTempFile(t, stdout) @@ -135,8 +135,8 @@ func TestCLISendGenerateSignAndBroadcast(t *testing.T) { // Sign transaction success, stdout, _ = testutil.TxSign(f, cli.KeyFoo, unsignedTxFile.Name()) require.True(t, success) - msg = cli.UnmarshalStdTx(t, f.Amino, stdout) - require.Equal(t, len(msg.Msgs), 1) + msg = f.UnmarshalTxJSON(stdout) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 1, len(msg.GetSignatures())) require.Equal(t, fooAddr.String(), msg.GetSigners()[0].String()) diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index ccc0618f064c..73573bf27a09 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -81,8 +81,8 @@ type StdTxGenerator struct { var _ context.TxGenerator = StdTxGenerator{} -// NewTx implements TxGenerator.NewTx -func (s StdTxGenerator) NewTx() context.TxBuilder { +// NewTxBuilder implements TxGenerator.NewTxBuilder +func (s StdTxGenerator) NewTxBuilder() context.TxBuilder { return &StdTxBuilder{} } @@ -97,8 +97,8 @@ func (s StdTxGenerator) NewSignature() context.ClientSignature { } // MarshalTx implements TxGenerator.MarshalTx -func (s StdTxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { - return DefaultTxEncoder(s.Cdc)(tx) +func (s StdTxGenerator) TxEncoder() sdk.TxEncoder { + return DefaultTxEncoder(s.Cdc) } var _ context.ClientFee = &StdFee{} diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 4ef303d21e36..47494f45d3d6 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -337,6 +337,25 @@ func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder { } } +func DefaultJSONTxDecoder(cdc *codec.Codec) sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + var tx = StdTx{} + + if len(txBytes) == 0 { + return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx bytes are empty") + } + + // StdTx.Msg is an interface. The concrete types + // are registered by MakeTxCodec + err := cdc.UnmarshalJSON(txBytes, &tx) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + return tx, nil + } +} + // DefaultTxEncoder logic for standard transaction encoding func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { diff --git a/x/bank/client/cli/cli_test.go b/x/bank/client/cli/cli_test.go index 848857046a8c..4dbcd6af4bb1 100644 --- a/x/bank/client/cli/cli_test.go +++ b/x/bank/client/cli/cli_test.go @@ -55,10 +55,10 @@ func TestCLISend(t *testing.T) { ) require.Empty(t, stderr) require.True(t, success) - msg := cli.UnmarshalStdTx(f.T, f.Amino, stdout) + msg := f.UnmarshalTxJSON(stdout) t.Log(msg) - require.NotZero(t, msg.Fee.Gas) - require.Len(t, msg.Msgs, 1) + require.NotZero(t, msg.GetGas()) + require.Len(t, msg.GetMsgs(), 1) require.Len(t, msg.GetSignatures(), 0) // Check state didn't change diff --git a/x/genutil/alias.go b/x/genutil/alias.go index 8639a7368a01..898f27dca7a6 100644 --- a/x/genutil/alias.go +++ b/x/genutil/alias.go @@ -22,9 +22,6 @@ var ( GenesisStateFromGenDoc = types.GenesisStateFromGenDoc GenesisStateFromGenFile = types.GenesisStateFromGenFile ValidateGenesis = types.ValidateGenesis - - // variable aliases - ModuleCdc = types.ModuleCdc ) type ( diff --git a/x/genutil/genesis.go b/x/genutil/genesis.go index c8564bdc4e2d..98824b45c4f6 100644 --- a/x/genutil/genesis.go +++ b/x/genutil/genesis.go @@ -3,20 +3,20 @@ package genutil import ( abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // InitGenesis - initialize accounts and deliver genesis transactions func InitGenesis( - ctx sdk.Context, cdc *codec.Codec, stakingKeeper types.StakingKeeper, + ctx sdk.Context, stakingKeeper types.StakingKeeper, deliverTx deliverTxfn, genesisState GenesisState, + txJSONDecoder sdk.TxDecoder, txBinaryEncoder sdk.TxEncoder, ) []abci.ValidatorUpdate { var validators []abci.ValidatorUpdate if len(genesisState.GenTxs) > 0 { - validators = DeliverGenTxs(ctx, cdc, genesisState.GenTxs, stakingKeeper, deliverTx) + validators = DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txJSONDecoder, txBinaryEncoder) } return validators diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 064a67387b8b..f33031684872 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -94,15 +94,21 @@ type deliverTxfn func(abci.RequestDeliverTx) abci.ResponseDeliverTx // invokes the provided deliverTxfn with the decoded StdTx. It returns the result // of the staking module's ApplyAndReturnValidatorSetUpdates. func DeliverGenTxs( - ctx sdk.Context, cdc *codec.Codec, genTxs []json.RawMessage, + ctx sdk.Context, genTxs []json.RawMessage, stakingKeeper types.StakingKeeper, deliverTx deliverTxfn, + txJSONDecoder sdk.TxDecoder, txBinaryEncoder sdk.TxEncoder, ) []abci.ValidatorUpdate { for _, genTx := range genTxs { - var tx authtypes.StdTx - cdc.MustUnmarshalJSON(genTx, &tx) + tx, err := txJSONDecoder(genTx) + if err != nil { + panic(err) + } - bz := cdc.MustMarshalBinaryBare(tx) + bz, err := txBinaryEncoder(tx) + if err != nil { + panic(err) + } res := deliverTx(abci.RequestDeliverTx{Tx: bz}) if !res.IsOK() { diff --git a/x/genutil/module.go b/x/genutil/module.go index 11fd49381b4d..573e4e183ae0 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -63,20 +63,26 @@ func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } type AppModule struct { AppModuleBasic - accountKeeper types.AccountKeeper - stakingKeeper types.StakingKeeper - deliverTx deliverTxfn + accountKeeper types.AccountKeeper + stakingKeeper types.StakingKeeper + deliverTx deliverTxfn + txJSONDecoder sdk.TxDecoder + txBinaryEncoder sdk.TxEncoder } // NewAppModule creates a new AppModule object func NewAppModule(accountKeeper types.AccountKeeper, - stakingKeeper types.StakingKeeper, deliverTx deliverTxfn) module.AppModule { + stakingKeeper types.StakingKeeper, deliverTx deliverTxfn, + txJSONDecoder sdk.TxDecoder, txBinaryEncoder sdk.TxEncoder, +) module.AppModule { return module.NewGenesisOnlyAppModule(AppModule{ - AppModuleBasic: AppModuleBasic{}, - accountKeeper: accountKeeper, - stakingKeeper: stakingKeeper, - deliverTx: deliverTx, + AppModuleBasic: AppModuleBasic{}, + accountKeeper: accountKeeper, + stakingKeeper: stakingKeeper, + deliverTx: deliverTx, + txJSONDecoder: txJSONDecoder, + txBinaryEncoder: txBinaryEncoder, }) } @@ -85,7 +91,7 @@ func NewAppModule(accountKeeper types.AccountKeeper, func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - return InitGenesis(ctx, ModuleCdc, am.stakingKeeper, am.deliverTx, genesisState) + return InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txJSONDecoder, am.txBinaryEncoder) } // ExportGenesis returns the exported genesis state as raw bytes for the genutil diff --git a/x/gov/client/cli/cli_test.go b/x/gov/client/cli/cli_test.go index 8f99fd59baab..b7478c7425b3 100644 --- a/x/gov/client/cli/cli_test.go +++ b/x/gov/client/cli/cli_test.go @@ -42,9 +42,9 @@ func TestCLISubmitProposal(t *testing.T) { fooAddr.String(), "Text", "Test", "test", sdk.NewCoin(cli.Denom, proposalTokens), "--generate-only", "-y") require.True(t, success) require.Empty(t, stderr) - msg := cli.UnmarshalStdTx(t, f.Amino, stdout) - require.NotZero(t, msg.Fee.Gas) - require.Equal(t, len(msg.Msgs), 1) + msg := f.UnmarshalTxJSON(stdout) + require.NotZero(t, msg.GetGas()) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 0, len(msg.GetSignatures())) // Test --dry-run @@ -80,9 +80,9 @@ func TestCLISubmitProposal(t *testing.T) { success, stdout, stderr = testutil.TxGovDeposit(f, 1, fooAddr.String(), sdk.NewCoin(cli.Denom, depositTokens), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Amino, stdout) - require.NotZero(t, msg.Fee.Gas) - require.Equal(t, len(msg.Msgs), 1) + msg = f.UnmarshalTxJSON(stdout) + require.NotZero(t, msg.GetGas()) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 0, len(msg.GetSignatures())) // Run the deposit transaction @@ -114,9 +114,9 @@ func TestCLISubmitProposal(t *testing.T) { success, stdout, stderr = testutil.TxGovVote(f, 1, gov.OptionYes, fooAddr.String(), "--generate-only") require.True(t, success) require.Empty(t, stderr) - msg = cli.UnmarshalStdTx(t, f.Amino, stdout) - require.NotZero(t, msg.Fee.Gas) - require.Equal(t, len(msg.Msgs), 1) + msg = f.UnmarshalTxJSON(stdout) + require.NotZero(t, msg.GetGas()) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 0, len(msg.GetSignatures())) // Vote on the proposal diff --git a/x/staking/client/cli/cli_test.go b/x/staking/client/cli/cli_test.go index 857041a0fe54..d479bd2414c2 100644 --- a/x/staking/client/cli/cli_test.go +++ b/x/staking/client/cli/cli_test.go @@ -39,9 +39,9 @@ func TestCLICreateValidator(t *testing.T) { require.True(f.T, success) require.Empty(f.T, stderr) - msg := cli.UnmarshalStdTx(f.T, f.Amino, stdout) - require.NotZero(t, msg.Fee.Gas) - require.Equal(t, len(msg.Msgs), 1) + msg := f.UnmarshalTxJSON(stdout) + require.NotZero(t, msg.GetGas()) + require.Equal(t, len(msg.GetMsgs()), 1) require.Equal(t, 0, len(msg.GetSignatures())) // Test --dry-run From bf1bb2a7044746dec7a191a0f558229cadbc3338 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 27 May 2020 21:15:13 -0400 Subject: [PATCH 42/54] WIP on making auth cli stuff proto compatible --- client/context/broadcast.go | 22 +- client/context/context.go | 7 + client/context/tx_generator.go | 3 + codec/json.go | 7 + codec/types/any.go | 17 +- codec/types/{amino_compat.go => compat.go} | 86 +- .../{amino_compat_test.go => compat_test.go} | 0 codec/types/types_test.go | 28 + simapp/cmd/simcli/amino.go | 1 + simapp/cmd/simcli/main.go | 2 +- simapp/cmd/simcli/proto.go | 1 + types/events.go | 14 - types/result.go | 83 +- types/result_test.go | 22 +- .../{signing/handler.go => mode_handler.go} | 10 +- types/tx/signing/direct.go | 19 +- types/tx/signing/handler_map.go | 47 + types/tx/signing/legacy_amino_json.go | 20 - types/tx/signing/tx_generator.go | 5 + types/tx/tx.go | 37 +- types/types.pb.go | 2158 ++++++++++++++--- types/types.proto | 41 +- x/auth/alias.go | 1 - x/auth/ante/ante.go | 5 +- x/auth/ante/sigverify_proto.go | 13 +- x/auth/ante/types/types.go | 25 +- x/auth/client/cli/broadcast.go | 2 +- x/auth/client/cli/encode.go | 11 +- x/auth/client/cli/tx.go | 10 +- x/auth/client/cli/tx_multisign.go | 29 +- x/auth/client/cli/tx_sign.go | 9 +- x/auth/client/cli/validate_sigs.go | 108 +- x/auth/client/query.go | 20 +- x/auth/client/tx.go | 8 +- x/auth/client/tx_test.go | 2 +- x/auth/types/client_tx.go | 30 + x/auth/types/stdtx.go | 8 +- x/auth/types/txbuilder.go | 2 +- x/gov/client/utils/query.go | 10 +- 39 files changed, 2264 insertions(+), 659 deletions(-) rename codec/types/{amino_compat.go => compat.go} (69%) rename codec/types/{amino_compat_test.go => compat_test.go} (100%) rename types/tx/{signing/handler.go => mode_handler.go} (53%) create mode 100644 types/tx/signing/handler_map.go delete mode 100644 types/tx/signing/legacy_amino_json.go diff --git a/client/context/broadcast.go b/client/context/broadcast.go index 5f3d952452f6..90f3d703c3df 100644 --- a/client/context/broadcast.go +++ b/client/context/broadcast.go @@ -16,7 +16,7 @@ import ( // based on the context parameters. The result of the broadcast is parsed into // an intermediate structure which is logged if the context has a logger // defined. -func (ctx CLIContext) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) { +func (ctx CLIContext) BroadcastTx(txBytes []byte) (res *sdk.TxResponse, err error) { switch ctx.BroadcastMode { case flags.BroadcastSync: res, err = ctx.BroadcastTxSync(txBytes) @@ -28,7 +28,7 @@ func (ctx CLIContext) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error res, err = ctx.BroadcastTxCommit(txBytes) default: - return sdk.TxResponse{}, fmt.Errorf("unsupported return type %s; supported types: sync, async, block", ctx.BroadcastMode) + return nil, fmt.Errorf("unsupported return type %s; supported types: sync, async, block", ctx.BroadcastMode) } return res, err @@ -84,16 +84,16 @@ func CheckTendermintError(err error, txBytes []byte) *sdk.TxResponse { // NOTE: This should ideally not be used as the request may timeout but the tx // may still be included in a block. Use BroadcastTxAsync or BroadcastTxSync // instead. -func (ctx CLIContext) BroadcastTxCommit(txBytes []byte) (sdk.TxResponse, error) { +func (ctx CLIContext) BroadcastTxCommit(txBytes []byte) (*sdk.TxResponse, error) { node, err := ctx.GetNode() if err != nil { - return sdk.TxResponse{}, err + return nil, err } res, err := node.BroadcastTxCommit(txBytes) if err != nil { if errRes := CheckTendermintError(err, txBytes); errRes != nil { - return *errRes, nil + return errRes, nil } return sdk.NewResponseFormatBroadcastTxCommit(res), err @@ -112,15 +112,15 @@ func (ctx CLIContext) BroadcastTxCommit(txBytes []byte) (sdk.TxResponse, error) // BroadcastTxSync broadcasts transaction bytes to a Tendermint node // synchronously (i.e. returns after CheckTx execution). -func (ctx CLIContext) BroadcastTxSync(txBytes []byte) (sdk.TxResponse, error) { +func (ctx CLIContext) BroadcastTxSync(txBytes []byte) (*sdk.TxResponse, error) { node, err := ctx.GetNode() if err != nil { - return sdk.TxResponse{}, err + return nil, err } res, err := node.BroadcastTxSync(txBytes) if errRes := CheckTendermintError(err, txBytes); errRes != nil { - return *errRes, nil + return errRes, nil } return sdk.NewResponseFormatBroadcastTx(res), err @@ -128,15 +128,15 @@ func (ctx CLIContext) BroadcastTxSync(txBytes []byte) (sdk.TxResponse, error) { // BroadcastTxAsync broadcasts transaction bytes to a Tendermint node // asynchronously (i.e. returns immediately). -func (ctx CLIContext) BroadcastTxAsync(txBytes []byte) (sdk.TxResponse, error) { +func (ctx CLIContext) BroadcastTxAsync(txBytes []byte) (*sdk.TxResponse, error) { node, err := ctx.GetNode() if err != nil { - return sdk.TxResponse{}, err + return nil, err } res, err := node.BroadcastTxAsync(txBytes) if errRes := CheckTendermintError(err, txBytes); errRes != nil { - return *errRes, nil + return errRes, nil } return sdk.NewResponseFormatBroadcastTx(res), err diff --git a/client/context/context.go b/client/context/context.go index 6ea912c84359..104cae526a3c 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -28,6 +28,7 @@ type CLIContext struct { Client rpcclient.Client ChainID string JSONMarshaler codec.JSONMarshaler + TxJSONDecoder sdk.TxDecoder Input io.Reader Keyring keyring.Keyring Output io.Writer @@ -199,6 +200,12 @@ func (ctx CLIContext) WithJSONMarshaler(m codec.JSONMarshaler) CLIContext { return ctx } +// WithTxJSONDecoder returns a copy of the CLIContext with an updated JSONMarshaler. +func (ctx CLIContext) WithTxJSONDecoder(dec sdk.TxDecoder) CLIContext { + ctx.TxJSONDecoder = dec + return ctx +} + // WithCodec returns a copy of the context with an updated codec. // TODO: Deprecated (remove). func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext { diff --git a/client/context/tx_generator.go b/client/context/tx_generator.go index 28c15f453c8f..06738390a34b 100644 --- a/client/context/tx_generator.go +++ b/client/context/tx_generator.go @@ -3,6 +3,8 @@ package context import ( "github.com/tendermint/tendermint/crypto" + types "github.com/cosmos/cosmos-sdk/types/tx" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -15,6 +17,7 @@ type ( NewFee() ClientFee NewSignature() ClientSignature TxEncoder() sdk.TxEncoder + SignModeHandler() types.SignModeHandler } ClientFee interface { diff --git a/codec/json.go b/codec/json.go index 0bb44df31fd4..91629440024e 100644 --- a/codec/json.go +++ b/codec/json.go @@ -4,6 +4,8 @@ import ( "bytes" "encoding/json" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/gogo/protobuf/jsonpb" "github.com/gogo/protobuf/proto" ) @@ -25,6 +27,11 @@ func MarshalIndentFromJSON(bz []byte) ([]byte, error) { // bytes of a message. func ProtoMarshalJSON(msg proto.Message) ([]byte, error) { jm := &jsonpb.Marshaler{EmitDefaults: false, OrigName: false} + err := types.UnpackInterfaces(msg, types.ProtoJSONPacker{JsonMarshaler: jm}) + if err != nil { + return nil, err + } + buf := new(bytes.Buffer) if err := jm.Marshal(buf, msg); err != nil { diff --git a/codec/types/any.go b/codec/types/any.go index 714c0f78f21c..f7b6e79a13dd 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -49,7 +49,7 @@ type Any struct { cachedValue interface{} - aminoCompat *aminoCompat + compat *anyCompat } // NewAnyWithValue constructs a new Any packed with the value provided or @@ -83,6 +83,21 @@ func (any *Any) Pack(x proto.Message) error { return nil } +// UnsafePack packs the value x in the Any and instead of returning the error +// in the case of a packing failure, keeps the cached value. This should only +// be used in situations where compatibility is needed with amino. Amino-only +// values can safely be packed using this method when they will only be +// marshaled with amino and not protobuf +func UnsafePackAny(x interface{}) *Any { + if msg, ok := x.(proto.Message); ok { + any, err := NewAnyWithValue(msg) + if err != nil { + return any + } + } + return &Any{cachedValue: x} +} + // GetCachedValue returns the cached value from the Any if present func (any *Any) GetCachedValue() interface{} { return any.cachedValue diff --git a/codec/types/amino_compat.go b/codec/types/compat.go similarity index 69% rename from codec/types/amino_compat.go rename to codec/types/compat.go index 6cb1223510cd..a428702b7c43 100644 --- a/codec/types/amino_compat.go +++ b/codec/types/compat.go @@ -5,60 +5,62 @@ import ( "reflect" "runtime/debug" + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" amino "github.com/tendermint/go-amino" ) -type aminoCompat struct { - bz []byte - jsonBz []byte - err error +type anyCompat struct { + aminoBz []byte + jsonBz []byte + err error } -var Debug = false +var Debug = true -func aminoCompatError(errType string, x interface{}) error { +func anyCompatError(errType string, x interface{}) error { if Debug { debug.PrintStack() } return fmt.Errorf( - "amino %s Any marshaling error for %+v, this is likely because "+ + "%s marshaling error for %+v, this is likely because "+ "amino is being used directly (instead of codec.Codec which is preferred) "+ "or UnpackInterfacesMessage is not defined for some type which contains "+ "a protobuf Any either directly or via one of its members. To see a "+ "stacktrace of where the error is coming from, set the var Debug = true "+ - "in codec/types/amino_compat.go", + "in codec/types/compat.go", errType, x, ) } func (any Any) MarshalAmino() ([]byte, error) { - ac := any.aminoCompat + ac := any.compat if ac == nil { - return nil, aminoCompatError("binary unmarshal", any) + return nil, anyCompatError("amino binary unmarshal", any) } - return ac.bz, ac.err + return ac.aminoBz, ac.err } func (any *Any) UnmarshalAmino(bz []byte) error { - any.aminoCompat = &aminoCompat{ - bz: bz, - err: nil, + any.compat = &anyCompat{ + aminoBz: bz, + err: nil, } return nil } func (any Any) MarshalJSON() ([]byte, error) { - ac := any.aminoCompat + ac := any.compat if ac == nil { - return nil, aminoCompatError("JSON marshal", any) + return nil, anyCompatError("JSON marshal", any) } return ac.jsonBz, ac.err } func (any *Any) UnmarshalJSON(bz []byte) error { - any.aminoCompat = &aminoCompat{ + any.compat = &anyCompat{ jsonBz: bz, err: nil, } @@ -74,11 +76,11 @@ type AminoUnpacker struct { var _ AnyUnpacker = AminoUnpacker{} func (a AminoUnpacker) UnpackAny(any *Any, iface interface{}) error { - ac := any.aminoCompat + ac := any.compat if ac == nil { - return aminoCompatError("binary unmarshal", reflect.TypeOf(iface)) + return anyCompatError("amino binary unmarshal", reflect.TypeOf(iface)) } - err := a.Cdc.UnmarshalBinaryBare(ac.bz, iface) + err := a.Cdc.UnmarshalBinaryBare(ac.aminoBz, iface) if err != nil { return err } @@ -98,7 +100,7 @@ func (a AminoUnpacker) UnpackAny(any *Any, iface interface{}) error { // this is necessary for tests that use reflect.DeepEqual and compare // proto vs amino marshaled values - any.aminoCompat = nil + any.compat = nil return nil } @@ -117,9 +119,9 @@ func (a AminoPacker) UnpackAny(any *Any, _ interface{}) error { return err } bz, err := a.Cdc.MarshalBinaryBare(any.cachedValue) - any.aminoCompat = &aminoCompat{ - bz: bz, - err: err, + any.compat = &anyCompat{ + aminoBz: bz, + err: err, } return err } @@ -133,9 +135,9 @@ type AminoJSONUnpacker struct { var _ AnyUnpacker = AminoJSONUnpacker{} func (a AminoJSONUnpacker) UnpackAny(any *Any, iface interface{}) error { - ac := any.aminoCompat + ac := any.compat if ac == nil { - return aminoCompatError("JSON unmarshal", reflect.TypeOf(iface)) + return anyCompatError("JSON unmarshal", reflect.TypeOf(iface)) } err := a.Cdc.UnmarshalJSON(ac.jsonBz, iface) if err != nil { @@ -157,7 +159,7 @@ func (a AminoJSONUnpacker) UnpackAny(any *Any, iface interface{}) error { // this is necessary for tests that use reflect.DeepEqual and compare // proto vs amino marshaled values - any.aminoCompat = nil + any.compat = nil return nil } @@ -176,9 +178,37 @@ func (a AminoJSONPacker) UnpackAny(any *Any, _ interface{}) error { return err } bz, err := a.Cdc.MarshalJSON(any.cachedValue) - any.aminoCompat = &aminoCompat{ + any.compat = &anyCompat{ jsonBz: bz, err: err, } return err } + +// ProtoJSONPacker is an AnyUnpacker provided for compatibility with pbjson +type ProtoJSONPacker struct { + JsonMarshaler *jsonpb.Marshaler +} + +var _ AnyUnpacker = ProtoJSONPacker{} + +func (a ProtoJSONPacker) UnpackAny(any *Any, _ interface{}) error { + if any == nil { + return nil + } + + if any.cachedValue != nil { + err := UnpackInterfaces(any.cachedValue, a) + if err != nil { + return err + } + } + + bz, err := a.JsonMarshaler.MarshalToString(any) + any.compat = &anyCompat{ + jsonBz: []byte(bz), + err: err, + } + + return err +} diff --git a/codec/types/amino_compat_test.go b/codec/types/compat_test.go similarity index 100% rename from codec/types/amino_compat_test.go rename to codec/types/compat_test.go diff --git a/codec/types/types_test.go b/codec/types/types_test.go index dd1d4530a865..31ab16343671 100644 --- a/codec/types/types_test.go +++ b/codec/types/types_test.go @@ -1,6 +1,7 @@ package types_test import ( + "strings" "testing" "github.com/gogo/protobuf/jsonpb" @@ -143,4 +144,31 @@ func TestAny_ProtoJSON(t *testing.T) { json, err := jm.MarshalToString(any) require.NoError(t, err) require.Equal(t, "{\"@type\":\"/cosmos_sdk.codec.v1.Dog\",\"name\":\"Spot\"}", json) + + registry := NewTestInterfaceRegistry() + jum := &jsonpb.Unmarshaler{} + var any2 types.Any + err = jum.Unmarshal(strings.NewReader(json), &any2) + require.NoError(t, err) + var animal testdata.Animal + err = registry.UnpackAny(&any2, &animal) + require.NoError(t, err) + require.Equal(t, spot, animal) + + ha := &testdata.HasAnimal{ + Animal: any, + } + err = ha.UnpackInterfaces(types.ProtoJSONPacker{JsonMarshaler: jm}) + require.NoError(t, err) + json, err = jm.MarshalToString(ha) + require.NoError(t, err) + require.Equal(t, "{\"animal\":{\"@type\":\"/cosmos_sdk.codec.v1.Dog\",\"name\":\"Spot\"}}", json) + + require.NoError(t, err) + var ha2 testdata.HasAnimal + err = jum.Unmarshal(strings.NewReader(json), &ha2) + require.NoError(t, err) + err = ha2.UnpackInterfaces(registry) + require.NoError(t, err) + require.Equal(t, spot, ha2.Animal.GetCachedValue()) } diff --git a/simapp/cmd/simcli/amino.go b/simapp/cmd/simcli/amino.go index 05e8a6b84307..0659ba8c94ea 100644 --- a/simapp/cmd/simcli/amino.go +++ b/simapp/cmd/simcli/amino.go @@ -14,6 +14,7 @@ func MakeTxCLIContext() context.CLIContext { return cliCtx. WithJSONMarshaler(aminoCdc). WithTxGenerator(encodingConfig.TxGenerator). + WithTxJSONDecoder(encodingConfig.TxJSONDecoder). WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). WithCodec(encodingConfig.Amino) } diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index b212d6af52fb..07b247d2b0db 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -126,7 +126,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { authcmd.GetValidateSignaturesCommand(cdc), flags.LineBreak, authcmd.GetBroadcastCommand(cdc), - authcmd.GetEncodeCommand(cdc), + authcmd.GetEncodeCommand(cliCtx), authcmd.GetDecodeCommand(cdc), flags.LineBreak, ) diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index ea022c7bdd88..aeacfd4515a6 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -14,6 +14,7 @@ func MakeTxCLIContext() context.CLIContext { return cliCtx. WithJSONMarshaler(protoCdc). WithTxGenerator(encodingConfig.TxGenerator). + WithTxJSONDecoder(encodingConfig.TxJSONDecoder). WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). WithCodec(encodingConfig.Amino) } diff --git a/types/events.go b/types/events.go index 10723931e9cd..30fe1ee39de2 100644 --- a/types/events.go +++ b/types/events.go @@ -48,13 +48,6 @@ type ( // Event is a type alias for an ABCI Event Event abci.Event - // Attribute defines an attribute wrapper where the key and value are - // strings instead of raw bytes. - Attribute struct { - Key string `json:"key"` - Value string `json:"value,omitempty"` - } - // Events defines a slice of Event objects Events []Event ) @@ -141,13 +134,6 @@ var ( ) type ( - // StringAttribute defines en Event object wrapper where all the attributes - // contain key/value pairs that are strings instead of raw bytes. - StringEvent struct { - Type string `json:"type,omitempty"` - Attributes []Attribute `json:"attributes,omitempty"` - } - // StringAttributes defines a slice of StringEvents objects. StringEvents []StringEvent ) diff --git a/types/result.go b/types/result.go index 1c5340819775..0bb58d5af946 100644 --- a/types/result.go +++ b/types/result.go @@ -37,19 +37,9 @@ func (r Result) GetEvents() Events { // ABCIMessageLogs represents a slice of ABCIMessageLog. type ABCIMessageLogs []ABCIMessageLog -// ABCIMessageLog defines a structure containing an indexed tx ABCI message log. -type ABCIMessageLog struct { - MsgIndex uint16 `json:"msg_index"` - Log string `json:"log"` - - // Events contains a slice of Event objects that were emitted during some - // execution. - Events StringEvents `json:"events"` -} - func NewABCIMessageLog(i uint16, log string, events Events) ABCIMessageLog { return ABCIMessageLog{ - MsgIndex: i, + MsgIndex: uint32(i), Log: log, Events: StringifyEvents(events.ToABCIEvents()), } @@ -67,32 +57,15 @@ func (logs ABCIMessageLogs) String() (str string) { return str } -// TxResponse defines a structure containing relevant tx data and metadata. The -// tags are stringified and the log is JSON decoded. -type TxResponse struct { - Height int64 `json:"height"` - TxHash string `json:"txhash"` - Codespace string `json:"codespace,omitempty"` - Code uint32 `json:"code,omitempty"` - Data string `json:"data,omitempty"` - RawLog string `json:"raw_log,omitempty"` - Logs ABCIMessageLogs `json:"logs,omitempty"` - Info string `json:"info,omitempty"` - GasWanted int64 `json:"gas_wanted,omitempty"` - GasUsed int64 `json:"gas_used,omitempty"` - Tx Tx `json:"tx,omitempty"` - Timestamp string `json:"timestamp,omitempty"` -} - // NewResponseResultTx returns a TxResponse given a ResultTx from tendermint -func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) TxResponse { +func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) *TxResponse { if res == nil { - return TxResponse{} + return &TxResponse{} } parsedLogs, _ := ParseABCILogs(res.TxResult.Log) - return TxResponse{ + return &TxResponse{ TxHash: res.Hash.String(), Height: res.Height, Codespace: res.TxResult.Codespace, @@ -103,16 +76,16 @@ func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) TxRespon Info: res.TxResult.Info, GasWanted: res.TxResult.GasWanted, GasUsed: res.TxResult.GasUsed, - Tx: tx, + Tx: types.UnsafePackAny(tx), Timestamp: timestamp, } } // NewResponseFormatBroadcastTxCommit returns a TxResponse given a // ResultBroadcastTxCommit from tendermint. -func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) TxResponse { +func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) *TxResponse { if res == nil { - return TxResponse{} + return &TxResponse{} } if !res.CheckTx.IsOK() { @@ -122,9 +95,9 @@ func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) TxR return newTxResponseDeliverTx(res) } -func newTxResponseCheckTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { +func newTxResponseCheckTx(res *ctypes.ResultBroadcastTxCommit) *TxResponse { if res == nil { - return TxResponse{} + return nil } var txHash string @@ -134,7 +107,7 @@ func newTxResponseCheckTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { parsedLogs, _ := ParseABCILogs(res.CheckTx.Log) - return TxResponse{ + return &TxResponse{ Height: res.Height, TxHash: txHash, Codespace: res.CheckTx.Codespace, @@ -148,9 +121,9 @@ func newTxResponseCheckTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { } } -func newTxResponseDeliverTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { +func newTxResponseDeliverTx(res *ctypes.ResultBroadcastTxCommit) *TxResponse { if res == nil { - return TxResponse{} + return nil } var txHash string @@ -160,7 +133,7 @@ func newTxResponseDeliverTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { parsedLogs, _ := ParseABCILogs(res.DeliverTx.Log) - return TxResponse{ + return &TxResponse{ Height: res.Height, TxHash: txHash, Codespace: res.DeliverTx.Codespace, @@ -175,14 +148,14 @@ func newTxResponseDeliverTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { } // NewResponseFormatBroadcastTx returns a TxResponse given a ResultBroadcastTx from tendermint -func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) TxResponse { +func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) *TxResponse { if res == nil { - return TxResponse{} + return &TxResponse{} } parsedLogs, _ := ParseABCILogs(res.Log) - return TxResponse{ + return &TxResponse{ Code: res.Code, Codespace: res.Codespace, Data: res.Data.String(), @@ -240,15 +213,15 @@ func (r TxResponse) Empty() bool { // SearchTxsResult defines a structure for querying txs pageable type SearchTxsResult struct { - TotalCount int `json:"total_count"` // Count of all txs - Count int `json:"count"` // Count of txs in current page - PageNumber int `json:"page_number"` // Index of current page, start from 1 - PageTotal int `json:"page_total"` // Count of total pages - Limit int `json:"limit"` // Max count txs per page - Txs []TxResponse `json:"txs"` // List of txs in current page + TotalCount int `json:"total_count"` // Count of all txs + Count int `json:"count"` // Count of txs in current page + PageNumber int `json:"page_number"` // Index of current page, start from 1 + PageTotal int `json:"page_total"` // Count of total pages + Limit int `json:"limit"` // Max count txs per page + Txs []*TxResponse `json:"txs"` // List of txs in current page } -func NewSearchTxsResult(totalCount, count, page, limit int, txs []TxResponse) SearchTxsResult { +func NewSearchTxsResult(totalCount, count, page, limit int, txs []*TxResponse) SearchTxsResult { return SearchTxsResult{ TotalCount: totalCount, Count: count, @@ -284,5 +257,13 @@ func (s SearchTxsResult) UnpackInterfaces(unpacker types.AnyUnpacker) error { // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (r TxResponse) UnpackInterfaces(unpacker types.AnyUnpacker) error { - return types.UnpackInterfaces(r.Tx, unpacker) + var tx Tx + return unpacker.UnpackAny(r.Tx, &tx) +} + +func (r TxResponse) GetTx() Tx { + if tx, ok := r.Tx.GetCachedValue().(Tx); ok { + return tx + } + return nil } diff --git a/types/result_test.go b/types/result_test.go index 70f7d98fbbdb..56823eee6f91 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/bytes" @@ -22,7 +24,7 @@ func TestParseABCILog(t *testing.T) { require.NoError(t, err) require.Len(t, res, 1) require.Equal(t, res[0].Log, "") - require.Equal(t, res[0].MsgIndex, uint16(1)) + require.Equal(t, res[0].MsgIndex, uint32(1)) } func TestABCIMessageLog(t *testing.T) { @@ -38,14 +40,14 @@ func TestABCIMessageLog(t *testing.T) { func TestNewSearchTxsResult(t *testing.T) { t.Parallel() - got := sdk.NewSearchTxsResult(150, 20, 2, 20, []sdk.TxResponse{}) + got := sdk.NewSearchTxsResult(150, 20, 2, 20, []*sdk.TxResponse{}) require.Equal(t, sdk.SearchTxsResult{ TotalCount: 150, Count: 20, PageNumber: 2, PageTotal: 8, Limit: 20, - Txs: []sdk.TxResponse{}, + Txs: []*sdk.TxResponse{}, }, got) } @@ -80,7 +82,7 @@ func TestResponseResultTx(t *testing.T) { } logs, err := sdk.ParseABCILogs(`[]`) require.NoError(t, err) - want := sdk.TxResponse{ + want := &sdk.TxResponse{ TxHash: "74657374", Height: 10, Codespace: "codespace", @@ -91,12 +93,12 @@ func TestResponseResultTx(t *testing.T) { Info: "info", GasWanted: 100, GasUsed: 90, - Tx: sdk.Tx(nil), + Tx: &types.Any{}, Timestamp: "timestamp", } require.Equal(t, want, sdk.NewResponseResultTx(resultTx, sdk.Tx(nil), "timestamp")) - require.Equal(t, sdk.TxResponse{}, sdk.NewResponseResultTx(nil, sdk.Tx(nil), "timestamp")) + require.Equal(t, &sdk.TxResponse{}, sdk.NewResponseResultTx(nil, sdk.Tx(nil), "timestamp")) require.Equal(t, `Response: Height: 10 TxHash: 74657374 @@ -119,7 +121,7 @@ func TestResponseResultTx(t *testing.T) { Log: `[]`, Hash: bytes.HexBytes([]byte("test")), } - require.Equal(t, sdk.TxResponse{ + require.Equal(t, &sdk.TxResponse{ Code: 1, Codespace: "codespace", Data: "64617461", @@ -127,12 +129,12 @@ func TestResponseResultTx(t *testing.T) { Logs: logs, TxHash: "74657374", }, sdk.NewResponseFormatBroadcastTx(resultBroadcastTx)) - require.Equal(t, sdk.TxResponse{}, sdk.NewResponseFormatBroadcastTx(nil)) + require.Equal(t, &sdk.TxResponse{}, sdk.NewResponseFormatBroadcastTx(nil)) } func TestResponseFormatBroadcastTxCommit(t *testing.T) { // test nil - require.Equal(t, sdk.TxResponse{}, sdk.NewResponseFormatBroadcastTxCommit(nil)) + require.Equal(t, &sdk.TxResponse{}, sdk.NewResponseFormatBroadcastTxCommit(nil)) logs, err := sdk.ParseABCILogs(`[]`) require.NoError(t, err) @@ -165,7 +167,7 @@ func TestResponseFormatBroadcastTxCommit(t *testing.T) { }, } - want := sdk.TxResponse{ + want := &sdk.TxResponse{ Height: 10, TxHash: "74657374", Codespace: "codespace", diff --git a/types/tx/signing/handler.go b/types/tx/mode_handler.go similarity index 53% rename from types/tx/signing/handler.go rename to types/tx/mode_handler.go index 3746ef232fdf..3efef71fc8ba 100644 --- a/types/tx/signing/handler.go +++ b/types/tx/mode_handler.go @@ -1,13 +1,13 @@ -package signing +package types import ( "github.com/tendermint/tendermint/crypto" - types "github.com/cosmos/cosmos-sdk/types/tx" + sdk "github.com/cosmos/cosmos-sdk/types" ) type SigningData struct { - ModeInfo *types.ModeInfo_Single + ModeInfo *ModeInfo_Single PublicKey crypto.PubKey ChainID string AccountNumber uint64 @@ -15,6 +15,6 @@ type SigningData struct { } type SignModeHandler interface { - Mode() types.SignMode - GetSignBytes(data SigningData, tx types.ProtoTx) ([]byte, error) + Modes() []SignMode + GetSignBytes(data SigningData, tx sdk.Tx) ([]byte, error) } diff --git a/types/tx/signing/direct.go b/types/tx/signing/direct.go index 01f4e07edaa5..42143ab23c06 100644 --- a/types/tx/signing/direct.go +++ b/types/tx/signing/direct.go @@ -1,20 +1,27 @@ package signing import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types/tx" ) type DirectModeHandler struct{} -var _ SignModeHandler = DirectModeHandler{} +var _ types.SignModeHandler = DirectModeHandler{} -func (DirectModeHandler) Mode() types.SignMode { - return types.SignMode_SIGN_MODE_DIRECT +func (DirectModeHandler) Modes() []types.SignMode { + return []types.SignMode{types.SignMode_SIGN_MODE_DIRECT} } -func (DirectModeHandler) GetSignBytes(data SigningData, tx types.ProtoTx) ([]byte, error) { - bodyBz := tx.GetBodyBytes() - authInfoBz := tx.GetAuthInfoBytes() +func (DirectModeHandler) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { + protoTx, ok := tx.(types.ProtoTx) + if !ok { + return nil, fmt.Errorf("can only get direct sign bytes for a ProtoTx, got %T", tx) + } + bodyBz := protoTx.GetBodyBytes() + authInfoBz := protoTx.GetAuthInfoBytes() return DirectSignBytes(bodyBz, authInfoBz, data.ChainID, data.AccountNumber, data.AccountSequence) } diff --git a/types/tx/signing/handler_map.go b/types/tx/signing/handler_map.go new file mode 100644 index 000000000000..1053ce9612cb --- /dev/null +++ b/types/tx/signing/handler_map.go @@ -0,0 +1,47 @@ +package signing + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +type HandlerMap struct { + modes []types.SignMode + signModeHandlers map[types.SignMode]types.SignModeHandler +} + +var _ types.SignModeHandler = HandlerMap{} + +func NewHandlerMap(handlers []types.SignModeHandler) *HandlerMap { + handlerMap := make(map[types.SignMode]types.SignModeHandler) + var modes []types.SignMode + + for _, h := range handlers { + for _, m := range h.Modes() { + if _, have := handlerMap[m]; have { + panic(fmt.Errorf("duplicate sign mode handler for mode %s", m)) + } + handlerMap[m] = h + modes = append(modes, m) + } + } + + return &HandlerMap{ + modes: modes, + signModeHandlers: handlerMap, + } +} + +func (h HandlerMap) Modes() []types.SignMode { + return h.modes +} + +func (h HandlerMap) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { + handler, found := h.signModeHandlers[data.ModeInfo.Mode] + if !found { + return nil, fmt.Errorf("can't verify sign mode %s", data.ModeInfo.Mode.String()) + } + return handler.GetSignBytes(data, tx) +} diff --git a/types/tx/signing/legacy_amino_json.go b/types/tx/signing/legacy_amino_json.go deleted file mode 100644 index ec6089d5c6e8..000000000000 --- a/types/tx/signing/legacy_amino_json.go +++ /dev/null @@ -1,20 +0,0 @@ -package signing - -import ( - types "github.com/cosmos/cosmos-sdk/types/tx" - auth "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -type LegacyAminoJSONHandler struct{} - -var _ SignModeHandler = LegacyAminoJSONHandler{} - -func (LegacyAminoJSONHandler) Mode() types.SignMode { - return types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON -} - -func (LegacyAminoJSONHandler) GetSignBytes(data SigningData, tx types.ProtoTx) ([]byte, error) { - return auth.StdSignBytes( - data.ChainID, data.AccountNumber, data.AccountSequence, auth.StdFee{Amount: tx.GetFee(), Gas: tx.GetGas()}, tx.GetMsgs(), tx.GetBody().Memo, - ), nil -} diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index f7dee1814584..0872b1f0aa57 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -56,3 +56,8 @@ func (t TxGenerator) TxEncoder() sdk.TxEncoder { return t.Marshaler.MarshalBinaryBare(ptx) } } + +func (t TxGenerator) SignModeHandler() types.SignModeHandler { + panic("implement me") +} + diff --git a/types/tx/tx.go b/types/tx/tx.go index 141a2661e665..1494d4d32d02 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -6,15 +6,13 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - antetypes "github.com/cosmos/cosmos-sdk/x/auth/ante/types" - auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) type ProtoTx interface { sdk.Tx - antetypes.FeeTx - antetypes.TxWithMemo - antetypes.SigTx + FeeTx + TxWithMemo + SigTx GetBody() *TxBody GetAuthInfo() *AuthInfo @@ -47,10 +45,10 @@ func (tx *Tx) GetMsgs() []sdk.Msg { func (tx *Tx) ValidateBasic() error { sigs := tx.GetSignatures() - if tx.GetGas() > auth.MaxGasWanted { + if tx.GetGas() > MaxGasWanted { return sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, - "invalid gas supplied; %d > %d", tx.GetGas(), auth.MaxGasWanted, + "invalid gas supplied; %d > %d", tx.GetGas(), MaxGasWanted, ) } if tx.GetFee().IsAnyNegative() { @@ -154,3 +152,28 @@ func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { } return nil } + +// FeeTx defines the interface to be implemented by Tx to use the FeeDecorators +type FeeTx interface { + sdk.Tx + GetGas() uint64 + GetFee() sdk.Coins + FeePayer() sdk.AccAddress +} + +// Tx must have GetMemo() method to use ValidateMemoDecorator +type TxWithMemo interface { + sdk.Tx + GetMemo() string +} + +type SigTx interface { + sdk.Tx + GetSignatures() [][]byte + GetSigners() []sdk.AccAddress + GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place +} + +// MaxGasWanted defines the max gas allowed. +const MaxGasWanted = uint64((1 << 63) - 1) + diff --git a/types/types.pb.go b/types/types.pb.go index 6b4d9813ab5f..39564330ee4c 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + types1 "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/tendermint/tendermint/abci/types" @@ -384,6 +385,223 @@ func (m *SimulationResponse) GetResult() *Result { return nil } +// TxResponse defines a structure containing relevant tx data and metadata. The +// tags are stringified and the log is JSON decoded. +type TxResponse struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + TxHash string `protobuf:"bytes,2,opt,name=txhash,proto3" json:"txhash,omitempty"` + Codespace string `protobuf:"bytes,3,opt,name=codespace,proto3" json:"codespace,omitempty"` + Code uint32 `protobuf:"varint,4,opt,name=code,proto3" json:"code,omitempty"` + Data string `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"` + RawLog string `protobuf:"bytes,6,opt,name=raw_log,json=rawLog,proto3" json:"raw_log,omitempty"` + Logs ABCIMessageLogs `protobuf:"bytes,7,rep,name=logs,proto3,castrepeated=ABCIMessageLogs" json:"logs"` + Info string `protobuf:"bytes,8,opt,name=info,proto3" json:"info,omitempty"` + GasWanted int64 `protobuf:"varint,9,opt,name=gas_wanted,json=gasWanted,proto3" json:"gas_wanted,omitempty"` + GasUsed int64 `protobuf:"varint,10,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"` + Tx *types1.Any `protobuf:"bytes,11,opt,name=tx,proto3" json:"tx,omitempty"` + Timestamp string `protobuf:"bytes,12,opt,name=timestamp,proto3" json:"timestamp,omitempty"` +} + +func (m *TxResponse) Reset() { *m = TxResponse{} } +func (*TxResponse) ProtoMessage() {} +func (*TxResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{8} +} +func (m *TxResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxResponse.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 *TxResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxResponse.Merge(m, src) +} +func (m *TxResponse) XXX_Size() int { + return m.Size() +} +func (m *TxResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TxResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_TxResponse proto.InternalMessageInfo + +// ABCIMessageLog defines a structure containing an indexed tx ABCI message log. +type ABCIMessageLog struct { + MsgIndex uint32 `protobuf:"varint,1,opt,name=msg_index,json=msgIndex,proto3" json:"msg_index,omitempty"` + Log string `protobuf:"bytes,2,opt,name=log,proto3" json:"log,omitempty"` + // Events contains a slice of Event objects that were emitted during some + // execution. + Events StringEvents `protobuf:"bytes,3,rep,name=events,proto3,castrepeated=StringEvents" json:"events"` +} + +func (m *ABCIMessageLog) Reset() { *m = ABCIMessageLog{} } +func (*ABCIMessageLog) ProtoMessage() {} +func (*ABCIMessageLog) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{9} +} +func (m *ABCIMessageLog) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ABCIMessageLog) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ABCIMessageLog.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 *ABCIMessageLog) XXX_Merge(src proto.Message) { + xxx_messageInfo_ABCIMessageLog.Merge(m, src) +} +func (m *ABCIMessageLog) XXX_Size() int { + return m.Size() +} +func (m *ABCIMessageLog) XXX_DiscardUnknown() { + xxx_messageInfo_ABCIMessageLog.DiscardUnknown(m) +} + +var xxx_messageInfo_ABCIMessageLog proto.InternalMessageInfo + +func (m *ABCIMessageLog) GetMsgIndex() uint32 { + if m != nil { + return m.MsgIndex + } + return 0 +} + +func (m *ABCIMessageLog) GetLog() string { + if m != nil { + return m.Log + } + return "" +} + +func (m *ABCIMessageLog) GetEvents() StringEvents { + if m != nil { + return m.Events + } + return nil +} + +// StringAttribute defines en Event object wrapper where all the attributes +// contain key/value pairs that are strings instead of raw bytes. +type StringEvent struct { + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Attributes []Attribute `protobuf:"bytes,2,rep,name=attributes,proto3" json:"attributes"` +} + +func (m *StringEvent) Reset() { *m = StringEvent{} } +func (*StringEvent) ProtoMessage() {} +func (*StringEvent) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{10} +} +func (m *StringEvent) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StringEvent) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StringEvent.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 *StringEvent) XXX_Merge(src proto.Message) { + xxx_messageInfo_StringEvent.Merge(m, src) +} +func (m *StringEvent) XXX_Size() int { + return m.Size() +} +func (m *StringEvent) XXX_DiscardUnknown() { + xxx_messageInfo_StringEvent.DiscardUnknown(m) +} + +var xxx_messageInfo_StringEvent proto.InternalMessageInfo + +func (m *StringEvent) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *StringEvent) GetAttributes() []Attribute { + if m != nil { + return m.Attributes + } + return nil +} + +// Attribute defines an attribute wrapper where the key and value are +// strings instead of raw bytes. +type Attribute struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *Attribute) Reset() { *m = Attribute{} } +func (*Attribute) ProtoMessage() {} +func (*Attribute) Descriptor() ([]byte, []int) { + return fileDescriptor_2c0f90c600ad7e2e, []int{11} +} +func (m *Attribute) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Attribute) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Attribute.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 *Attribute) XXX_Merge(src proto.Message) { + xxx_messageInfo_Attribute.Merge(m, src) +} +func (m *Attribute) XXX_Size() int { + return m.Size() +} +func (m *Attribute) XXX_DiscardUnknown() { + xxx_messageInfo_Attribute.DiscardUnknown(m) +} + +var xxx_messageInfo_Attribute proto.InternalMessageInfo + +func (m *Attribute) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Attribute) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + func init() { proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin") proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin") @@ -393,46 +611,70 @@ func init() { proto.RegisterType((*GasInfo)(nil), "cosmos_sdk.v1.GasInfo") proto.RegisterType((*Result)(nil), "cosmos_sdk.v1.Result") proto.RegisterType((*SimulationResponse)(nil), "cosmos_sdk.v1.SimulationResponse") + proto.RegisterType((*TxResponse)(nil), "cosmos_sdk.v1.TxResponse") + proto.RegisterType((*ABCIMessageLog)(nil), "cosmos_sdk.v1.ABCIMessageLog") + proto.RegisterType((*StringEvent)(nil), "cosmos_sdk.v1.StringEvent") + proto.RegisterType((*Attribute)(nil), "cosmos_sdk.v1.Attribute") } func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) } var fileDescriptor_2c0f90c600ad7e2e = []byte{ - // 534 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x4f, 0x6f, 0xd3, 0x4e, - 0x10, 0xb5, 0x7f, 0xf6, 0x2f, 0x7f, 0x36, 0xe1, 0x4f, 0x17, 0x8a, 0xa2, 0x0a, 0xec, 0xc8, 0x48, - 0x28, 0x48, 0xd4, 0x16, 0x29, 0xa7, 0x70, 0xc2, 0x04, 0x55, 0xe1, 0x84, 0x16, 0x01, 0x12, 0x97, - 0x68, 0xe3, 0xdd, 0xba, 0x56, 0xe3, 0xdd, 0xc8, 0xbb, 0x29, 0xca, 0x2d, 0x47, 0x8e, 0x7c, 0x84, - 0x7e, 0x9c, 0x1e, 0x73, 0xac, 0x10, 0xb2, 0x20, 0xb9, 0x70, 0xee, 0x91, 0x13, 0xda, 0xb5, 0xc1, - 0x6a, 0x7a, 0xe3, 0x92, 0xcc, 0xce, 0xbc, 0x79, 0x33, 0xf3, 0xfc, 0xc0, 0x8e, 0x5c, 0xcc, 0xa8, - 0x08, 0xf4, 0xaf, 0x3f, 0xcb, 0xb8, 0xe4, 0xf0, 0x46, 0xc4, 0x45, 0xca, 0xc5, 0x58, 0x90, 0x13, - 0xff, 0xf4, 0xe9, 0xde, 0x23, 0x79, 0x9c, 0x64, 0x64, 0x3c, 0xc3, 0x99, 0x5c, 0x04, 0x1a, 0x11, - 0xc4, 0x3c, 0xe6, 0x55, 0x54, 0xb4, 0xed, 0x1d, 0x5c, 0xc7, 0x49, 0xca, 0x08, 0xcd, 0xd2, 0x84, - 0xc9, 0x00, 0x4f, 0xa2, 0x24, 0xb8, 0x36, 0xcb, 0x3b, 0x04, 0xf6, 0x4b, 0x9e, 0x30, 0x78, 0x17, - 0xfc, 0x4f, 0x28, 0xe3, 0x69, 0xc7, 0xec, 0x9a, 0xbd, 0x26, 0x2a, 0x1e, 0xf0, 0x21, 0xa8, 0xe1, - 0x94, 0xcf, 0x99, 0xec, 0xfc, 0xa7, 0xd2, 0x61, 0xeb, 0x3c, 0x77, 0x8d, 0xaf, 0xb9, 0x6b, 0x8d, - 0x98, 0x44, 0x65, 0x69, 0x60, 0xff, 0x3c, 0x73, 0x4d, 0xef, 0x35, 0xa8, 0x0f, 0x69, 0xf4, 0x2f, - 0x5c, 0x43, 0x1a, 0x6d, 0x71, 0x3d, 0x06, 0x8d, 0x11, 0x93, 0x6f, 0xb4, 0x18, 0x0f, 0x80, 0x95, - 0x30, 0x59, 0x50, 0x5d, 0x9d, 0xaf, 0xf2, 0x0a, 0x3a, 0xa4, 0xd1, 0x5f, 0x28, 0xa1, 0xd1, 0x36, - 0x54, 0xd1, 0xab, 0xbc, 0x17, 0x82, 0xf6, 0x7b, 0x3c, 0x7d, 0x41, 0x48, 0x46, 0x85, 0xa0, 0x02, - 0x3e, 0x01, 0x4d, 0xfc, 0xe7, 0xd1, 0x31, 0xbb, 0x56, 0xaf, 0x1d, 0xde, 0xfc, 0x95, 0xbb, 0xa0, - 0x02, 0xa1, 0x0a, 0x30, 0xb0, 0x97, 0xdf, 0xba, 0xa6, 0xc7, 0x41, 0xfd, 0x10, 0x8b, 0x11, 0x3b, - 0xe2, 0xf0, 0x19, 0x00, 0x31, 0x16, 0xe3, 0x4f, 0x98, 0x49, 0x4a, 0xf4, 0x50, 0x3b, 0xdc, 0xbd, - 0xcc, 0xdd, 0x9d, 0x05, 0x4e, 0xa7, 0x03, 0xaf, 0xaa, 0x79, 0xa8, 0x19, 0x63, 0xf1, 0x41, 0xc7, - 0xd0, 0x07, 0x0d, 0x55, 0x99, 0x0b, 0x4a, 0xb4, 0x0e, 0x76, 0x78, 0xe7, 0x32, 0x77, 0x6f, 0x55, - 0x3d, 0xaa, 0xe2, 0xa1, 0x7a, 0x8c, 0xc5, 0x3b, 0x15, 0xcd, 0x40, 0x0d, 0x51, 0x31, 0x9f, 0x4a, - 0x08, 0x81, 0x4d, 0xb0, 0xc4, 0x7a, 0x52, 0x1b, 0xe9, 0x18, 0xde, 0x06, 0xd6, 0x94, 0xc7, 0x85, - 0xa0, 0x48, 0x85, 0x70, 0x00, 0x6a, 0xf4, 0x94, 0x32, 0x29, 0x3a, 0x56, 0xd7, 0xea, 0xb5, 0xfa, - 0xf7, 0xfd, 0xca, 0x03, 0xbe, 0xf2, 0x80, 0x5f, 0x7c, 0xfd, 0x57, 0x0a, 0x14, 0xda, 0x4a, 0x24, - 0x54, 0x76, 0x0c, 0xec, 0xcf, 0x67, 0xae, 0xe1, 0x2d, 0x4d, 0x00, 0xdf, 0x26, 0xe9, 0x7c, 0x8a, - 0x65, 0xc2, 0x19, 0xa2, 0x62, 0xc6, 0x99, 0xa0, 0xf0, 0x79, 0xb1, 0x78, 0xc2, 0x8e, 0xb8, 0x5e, - 0xa1, 0xd5, 0xbf, 0xe7, 0x5f, 0xf1, 0xa9, 0x5f, 0x0a, 0x13, 0x36, 0x14, 0xe9, 0x2a, 0x77, 0x4d, - 0x7d, 0x85, 0xd6, 0x6a, 0x1f, 0xd4, 0x32, 0x7d, 0x85, 0x5e, 0xb5, 0xd5, 0xdf, 0xdd, 0x6a, 0x2d, - 0x4e, 0x44, 0x25, 0x28, 0x1c, 0x5e, 0xfc, 0x70, 0x8c, 0xe5, 0xda, 0x31, 0xce, 0xd7, 0x8e, 0xb9, - 0x5a, 0x3b, 0xe6, 0xf7, 0xb5, 0x63, 0x7e, 0xd9, 0x38, 0xc6, 0x6a, 0xe3, 0x18, 0x17, 0x1b, 0xc7, - 0xf8, 0xe8, 0xc5, 0x89, 0x3c, 0x9e, 0x4f, 0xfc, 0x88, 0xa7, 0x41, 0x41, 0x55, 0xfe, 0xed, 0x0b, - 0x72, 0x52, 0x18, 0x7c, 0x52, 0xd3, 0x0e, 0x3f, 0xf8, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x0e, 0xe8, - 0xc3, 0x0c, 0x62, 0x03, 0x00, 0x00, + // 862 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0xc6, 0xdb, 0xb5, 0xfd, 0xec, 0xb4, 0x74, 0x48, 0xdb, 0x6d, 0x68, 0xbc, 0xd6, 0x82, + 0x50, 0x90, 0xe8, 0x5a, 0x24, 0x9c, 0x8c, 0x84, 0x94, 0x6d, 0x50, 0xeb, 0xaa, 0x48, 0x68, 0x5b, + 0x40, 0xe2, 0x62, 0x8d, 0x77, 0x27, 0xe3, 0x55, 0xbc, 0x33, 0xd6, 0xce, 0x38, 0xb1, 0x6f, 0x39, + 0x22, 0x71, 0x80, 0x3f, 0xa1, 0x67, 0xfe, 0x92, 0x1e, 0x73, 0xac, 0x10, 0x32, 0xe0, 0x5c, 0x38, + 0xf7, 0xc8, 0x09, 0xcd, 0xcc, 0xc6, 0xbf, 0xc2, 0x89, 0x8b, 0xfd, 0x7e, 0x7c, 0xf3, 0xde, 0xbc, + 0x6f, 0xbe, 0x7d, 0x70, 0x57, 0x4e, 0x47, 0x44, 0xb4, 0xf5, 0x6f, 0x30, 0xca, 0xb9, 0xe4, 0x68, + 0x3b, 0xe6, 0x22, 0xe3, 0xa2, 0x27, 0x92, 0xd3, 0xe0, 0xec, 0xb3, 0xdd, 0x8f, 0xe5, 0x20, 0xcd, + 0x93, 0xde, 0x08, 0xe7, 0x72, 0xda, 0xd6, 0x88, 0x36, 0xe5, 0x94, 0x2f, 0x2d, 0x73, 0x6c, 0xf7, + 0xf0, 0x26, 0x4e, 0x12, 0x96, 0x90, 0x3c, 0x4b, 0x99, 0x6c, 0xe3, 0x7e, 0x9c, 0xb6, 0x6f, 0xf4, + 0xda, 0x7d, 0x48, 0x39, 0xa7, 0x43, 0x62, 0xf0, 0xfd, 0xf1, 0x49, 0x1b, 0xb3, 0xa9, 0x49, 0xf9, + 0x4f, 0xc1, 0x7e, 0xc2, 0x53, 0x86, 0x76, 0xe0, 0x56, 0x42, 0x18, 0xcf, 0x5c, 0xab, 0x65, 0xed, + 0xd7, 0x22, 0xe3, 0xa0, 0x0f, 0xc1, 0xc1, 0x19, 0x1f, 0x33, 0xe9, 0x6e, 0xa9, 0x70, 0x58, 0x7f, + 0x33, 0xf3, 0x4a, 0xbf, 0xcd, 0xbc, 0x72, 0x97, 0xc9, 0xa8, 0x48, 0x75, 0xec, 0xbf, 0x5f, 0x7b, + 0x96, 0xff, 0x1c, 0x2a, 0xc7, 0x24, 0xfe, 0x3f, 0xb5, 0x8e, 0x49, 0xbc, 0x51, 0xeb, 0x13, 0xa8, + 0x76, 0x99, 0xfc, 0x46, 0xf3, 0xb4, 0x07, 0xe5, 0x94, 0x49, 0x53, 0x6a, 0xbd, 0xbf, 0x8a, 0x2b, + 0xe8, 0x31, 0x89, 0x17, 0xd0, 0x84, 0xc4, 0x9b, 0x50, 0x55, 0x5e, 0xc5, 0xfd, 0x10, 0x1a, 0xdf, + 0xe1, 0xe1, 0x51, 0x92, 0xe4, 0x44, 0x08, 0x22, 0xd0, 0xa7, 0x50, 0xc3, 0xd7, 0x8e, 0x6b, 0xb5, + 0xca, 0xfb, 0x8d, 0xf0, 0xf6, 0x3f, 0x33, 0x0f, 0x96, 0xa0, 0x68, 0x09, 0xe8, 0xd8, 0x17, 0xbf, + 0xb7, 0x2c, 0x9f, 0x43, 0xe5, 0x29, 0x16, 0x5d, 0x76, 0xc2, 0xd1, 0xe7, 0x00, 0x14, 0x8b, 0xde, + 0x39, 0x66, 0x92, 0x24, 0xba, 0xa9, 0x1d, 0xde, 0x7b, 0x37, 0xf3, 0xee, 0x4e, 0x71, 0x36, 0xec, + 0xf8, 0xcb, 0x9c, 0x1f, 0xd5, 0x28, 0x16, 0xdf, 0x6b, 0x1b, 0x05, 0x50, 0x55, 0x99, 0xb1, 0x20, + 0x89, 0xe6, 0xc1, 0x0e, 0xdf, 0x7f, 0x37, 0xf3, 0xee, 0x2c, 0xcf, 0xa8, 0x8c, 0x1f, 0x55, 0x28, + 0x16, 0xdf, 0x2a, 0x6b, 0x04, 0x4e, 0x44, 0xc4, 0x78, 0x28, 0x11, 0x02, 0x3b, 0xc1, 0x12, 0xeb, + 0x4e, 0x8d, 0x48, 0xdb, 0xe8, 0x3d, 0x28, 0x0f, 0x39, 0x35, 0x84, 0x46, 0xca, 0x44, 0x1d, 0x70, + 0xc8, 0x19, 0x61, 0x52, 0xb8, 0xe5, 0x56, 0x79, 0xbf, 0x7e, 0xf0, 0x28, 0x58, 0xca, 0x23, 0x50, + 0xf2, 0x08, 0x8c, 0x30, 0xbe, 0x52, 0xa0, 0xd0, 0x56, 0x24, 0x45, 0xc5, 0x89, 0x8e, 0xfd, 0xe3, + 0x6b, 0xaf, 0xe4, 0x5f, 0x58, 0x80, 0x5e, 0xa6, 0xd9, 0x78, 0x88, 0x65, 0xca, 0x59, 0x44, 0xc4, + 0x88, 0x33, 0x41, 0xd0, 0x17, 0xe6, 0xe2, 0x29, 0x3b, 0xe1, 0xfa, 0x0a, 0xf5, 0x83, 0xfb, 0xc1, + 0x9a, 0x84, 0x83, 0x82, 0x98, 0xb0, 0xaa, 0x8a, 0x5e, 0xce, 0x3c, 0x4b, 0x4f, 0xa1, 0xb9, 0x7a, + 0x0c, 0x4e, 0xae, 0xa7, 0xd0, 0x57, 0xad, 0x1f, 0xdc, 0xdb, 0x38, 0x6a, 0x46, 0x8c, 0x0a, 0x90, + 0xff, 0x53, 0x19, 0xe0, 0xd5, 0x64, 0xd1, 0xfa, 0x3e, 0x38, 0x03, 0x92, 0xd2, 0x81, 0x51, 0x41, + 0x39, 0x2a, 0x3c, 0xe4, 0x83, 0x23, 0x27, 0x03, 0x2c, 0x06, 0x85, 0xa2, 0x60, 0x3e, 0xf3, 0x9c, + 0x57, 0x93, 0x67, 0x58, 0x0c, 0xa2, 0x22, 0x83, 0x1e, 0x41, 0x2d, 0xe6, 0x09, 0x11, 0x23, 0x1c, + 0x13, 0xb7, 0xac, 0x79, 0x5a, 0x06, 0x14, 0xa7, 0xca, 0x71, 0xed, 0x96, 0xb5, 0xbf, 0x1d, 0x69, + 0x7b, 0xc1, 0xf3, 0x2d, 0x0d, 0x36, 0x3c, 0x3f, 0x80, 0x4a, 0x8e, 0xcf, 0x7b, 0x8a, 0x6b, 0x47, + 0x87, 0x9d, 0x1c, 0x9f, 0xbf, 0xe0, 0x14, 0x3d, 0x07, 0x7b, 0xc8, 0xa9, 0x70, 0x2b, 0x9a, 0xec, + 0xbd, 0x8d, 0xb1, 0x8e, 0xc2, 0x27, 0xdd, 0xaf, 0x89, 0x10, 0x98, 0x92, 0x17, 0x9c, 0x86, 0x0f, + 0x14, 0x31, 0xbf, 0xfe, 0xe1, 0xdd, 0x59, 0x8f, 0x8b, 0x48, 0xd7, 0x50, 0x8d, 0x35, 0xbb, 0x55, + 0xd3, 0x58, 0xd9, 0x68, 0x6f, 0x4d, 0x64, 0x35, 0x3d, 0xfe, 0x8a, 0x9a, 0x1e, 0xae, 0xa8, 0x09, + 0x74, 0xf2, 0x5a, 0x38, 0xe8, 0x23, 0xd8, 0x92, 0x13, 0xb7, 0xae, 0xe9, 0xde, 0x09, 0xcc, 0x02, + 0x08, 0xae, 0x17, 0x40, 0x70, 0xc4, 0xa6, 0xd1, 0x96, 0x9c, 0x28, 0x7a, 0x64, 0x9a, 0x11, 0x21, + 0x71, 0x36, 0x72, 0x1b, 0x86, 0x9e, 0x45, 0xa0, 0x10, 0xc4, 0xcf, 0x16, 0xdc, 0x5e, 0xbf, 0x31, + 0xfa, 0x00, 0x6a, 0x99, 0xa0, 0xbd, 0x94, 0x25, 0x64, 0xa2, 0x1f, 0x65, 0x3b, 0xaa, 0x66, 0x82, + 0x76, 0x95, 0xff, 0x1f, 0xa2, 0x7c, 0xb6, 0x21, 0xca, 0xdd, 0x0d, 0x9e, 0x5e, 0xca, 0x3c, 0x65, + 0xd4, 0x48, 0x72, 0xa7, 0x20, 0xa9, 0xb1, 0x12, 0x14, 0x4b, 0x89, 0xea, 0xaf, 0x90, 0x42, 0x7d, + 0x25, 0xab, 0x88, 0x53, 0xa2, 0x2e, 0xd6, 0x8d, 0xb6, 0xd1, 0x97, 0x00, 0x58, 0xca, 0x3c, 0xed, + 0x8f, 0x25, 0x11, 0xee, 0x96, 0x6e, 0xeb, 0x6e, 0x3e, 0xcf, 0x35, 0xa0, 0xf8, 0x0e, 0x56, 0x4e, + 0x14, 0x8d, 0x0e, 0xa1, 0xb6, 0x00, 0xa9, 0xb9, 0x4e, 0xc9, 0xb4, 0xe8, 0xa2, 0x4c, 0xb5, 0xe8, + 0xce, 0xf0, 0x70, 0x4c, 0x8a, 0x59, 0x8d, 0x13, 0x1e, 0xbf, 0xfd, 0xab, 0x59, 0xba, 0x98, 0x37, + 0x4b, 0x6f, 0xe6, 0x4d, 0xeb, 0x72, 0xde, 0xb4, 0xfe, 0x9c, 0x37, 0xad, 0x5f, 0xae, 0x9a, 0xa5, + 0xcb, 0xab, 0x66, 0xe9, 0xed, 0x55, 0xb3, 0xf4, 0x83, 0x4f, 0x53, 0x39, 0x18, 0xf7, 0x83, 0x98, + 0x67, 0x6d, 0x73, 0xa5, 0xe2, 0xef, 0xb1, 0x48, 0x4e, 0xcd, 0xe6, 0xee, 0x3b, 0xfa, 0xad, 0x0e, + 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x55, 0x6e, 0x3e, 0xc1, 0x3b, 0x06, 0x00, 0x00, } func (this *Coin) Equal(that interface{}) bool { @@ -796,162 +1038,1137 @@ func (m *SimulationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Coin) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = m.Amount.Size() - n += 1 + l + sovTypes(uint64(l)) - return n -} - -func (m *DecCoin) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Denom) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) +func (m *TxResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - l = m.Amount.Size() - n += 1 + l + sovTypes(uint64(l)) - return n + return dAtA[:n], nil } -func (m *IntProto) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Int.Size() - n += 1 + l + sovTypes(uint64(l)) - return n +func (m *TxResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *DecProto) Size() (n int) { - if m == nil { - return 0 - } +func (m *TxResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - l = m.Dec.Size() - n += 1 + l + sovTypes(uint64(l)) - return n -} - -func (m *ValAddresses) Size() (n int) { - if m == nil { - return 0 + if len(m.Timestamp) > 0 { + i -= len(m.Timestamp) + copy(dAtA[i:], m.Timestamp) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Timestamp))) + i-- + dAtA[i] = 0x62 } - var l int - _ = l - if len(m.Addresses) > 0 { - for _, b := range m.Addresses { - l = len(b) - n += 1 + l + sovTypes(uint64(l)) + if m.Tx != nil { + { + size, err := m.Tx.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x5a } - return n -} - -func (m *GasInfo) Size() (n int) { - if m == nil { - return 0 + if m.GasUsed != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.GasUsed)) + i-- + dAtA[i] = 0x50 } - var l int - _ = l if m.GasWanted != 0 { - n += 1 + sovTypes(uint64(m.GasWanted)) + i = encodeVarintTypes(dAtA, i, uint64(m.GasWanted)) + i-- + dAtA[i] = 0x48 } - if m.GasUsed != 0 { - n += 1 + sovTypes(uint64(m.GasUsed)) + if len(m.Info) > 0 { + i -= len(m.Info) + copy(dAtA[i:], m.Info) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Info))) + i-- + dAtA[i] = 0x42 } - return n -} - -func (m *Result) Size() (n int) { - if m == nil { - return 0 + if len(m.Logs) > 0 { + for iNdEx := len(m.Logs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Logs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } } - var l int - _ = l - l = len(m.Data) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) + if len(m.RawLog) > 0 { + i -= len(m.RawLog) + copy(dAtA[i:], m.RawLog) + i = encodeVarintTypes(dAtA, i, uint64(len(m.RawLog))) + i-- + dAtA[i] = 0x32 } - l = len(m.Log) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x2a } - if len(m.Events) > 0 { - for _, e := range m.Events { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } + if m.Code != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Code)) + i-- + dAtA[i] = 0x20 } - return n -} - -func (m *SimulationResponse) Size() (n int) { - if m == nil { + if len(m.Codespace) > 0 { + i -= len(m.Codespace) + copy(dAtA[i:], m.Codespace) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Codespace))) + i-- + dAtA[i] = 0x1a + } + if len(m.TxHash) > 0 { + i -= len(m.TxHash) + copy(dAtA[i:], m.TxHash) + i = encodeVarintTypes(dAtA, i, uint64(len(m.TxHash))) + i-- + dAtA[i] = 0x12 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ABCIMessageLog) 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 *ABCIMessageLog) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ABCIMessageLog) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Events) > 0 { + for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Events[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Log) > 0 { + i -= len(m.Log) + copy(dAtA[i:], m.Log) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Log))) + i-- + dAtA[i] = 0x12 + } + if m.MsgIndex != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.MsgIndex)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *StringEvent) 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 *StringEvent) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StringEvent) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Attributes) > 0 { + for iNdEx := len(m.Attributes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Attributes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Attribute) 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 *Attribute) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Attribute) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Coin) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *DecCoin) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *IntProto) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Int.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *DecProto) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Dec.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *ValAddresses) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Addresses) > 0 { + for _, b := range m.Addresses { + l = len(b) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *GasInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.GasWanted != 0 { + n += 1 + sovTypes(uint64(m.GasWanted)) + } + if m.GasUsed != 0 { + n += 1 + sovTypes(uint64(m.GasUsed)) + } + return n +} + +func (m *Result) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Log) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Events) > 0 { + for _, e := range m.Events { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *SimulationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.GasInfo.Size() + n += 1 + l + sovTypes(uint64(l)) + if m.Result != nil { + l = m.Result.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *TxResponse) Size() (n int) { + if m == nil { return 0 } - var l int - _ = l - l = m.GasInfo.Size() - n += 1 + l + sovTypes(uint64(l)) - if m.Result != nil { - l = m.Result.Size() - n += 1 + l + sovTypes(uint64(l)) + var l int + _ = l + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + l = len(m.TxHash) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Codespace) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.Code != 0 { + n += 1 + sovTypes(uint64(m.Code)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.RawLog) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Logs) > 0 { + for _, e := range m.Logs { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + l = len(m.Info) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.GasWanted != 0 { + n += 1 + sovTypes(uint64(m.GasWanted)) + } + if m.GasUsed != 0 { + n += 1 + sovTypes(uint64(m.GasUsed)) + } + if m.Tx != nil { + l = m.Tx.Size() + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Timestamp) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ABCIMessageLog) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MsgIndex != 0 { + n += 1 + sovTypes(uint64(m.MsgIndex)) + } + l = len(m.Log) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Events) > 0 { + for _, e := range m.Events { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *StringEvent) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Type) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Attributes) > 0 { + for _, e := range m.Attributes { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Attribute) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ValAddresses) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ValAddresses{`, + `Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`, + `}`, + }, "") + return s +} +func (this *ABCIMessageLog) String() string { + if this == nil { + return "nil" + } + repeatedStringForEvents := "[]StringEvent{" + for _, f := range this.Events { + repeatedStringForEvents += strings.Replace(strings.Replace(f.String(), "StringEvent", "StringEvent", 1), `&`, ``, 1) + "," + } + repeatedStringForEvents += "}" + s := strings.Join([]string{`&ABCIMessageLog{`, + `MsgIndex:` + fmt.Sprintf("%v", this.MsgIndex) + `,`, + `Log:` + fmt.Sprintf("%v", this.Log) + `,`, + `Events:` + repeatedStringForEvents + `,`, + `}`, + }, "") + return s +} +func (this *StringEvent) String() string { + if this == nil { + return "nil" + } + repeatedStringForAttributes := "[]Attribute{" + for _, f := range this.Attributes { + repeatedStringForAttributes += fmt.Sprintf("%v", f) + "," + } + repeatedStringForAttributes += "}" + s := strings.Join([]string{`&StringEvent{`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, + `Attributes:` + repeatedStringForAttributes + `,`, + `}`, + }, "") + return s +} +func valueToStringTypes(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Coin) 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 ErrIntOverflowTypes + } + 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: Coin: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Coin: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DecCoin) 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 ErrIntOverflowTypes + } + 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: DecCoin: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DecCoin: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntProto) 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 ErrIntOverflowTypes + } + 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: IntProto: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DecProto) 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 ErrIntOverflowTypes + } + 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: DecProto: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF } - return n + return nil } +func (m *ValAddresses) 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 ErrIntOverflowTypes + } + 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: ValAddresses: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx)) + copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *ValAddresses) String() string { - if this == nil { - return "nil" + if iNdEx > l { + return io.ErrUnexpectedEOF } - s := strings.Join([]string{`&ValAddresses{`, - `Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`, - `}`, - }, "") - return s + return nil } -func valueToStringTypes(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" +func (m *GasInfo) 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 ErrIntOverflowTypes + } + 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: GasInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GasInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) + } + m.GasWanted = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasWanted |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) + } + m.GasUsed = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasUsed |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } -func (m *Coin) Unmarshal(dAtA []byte) error { +func (m *Result) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -970,19 +2187,53 @@ func (m *Coin) Unmarshal(dAtA []byte) error { if b < 0x80 { break } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Coin: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Coin: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Result: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Result: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1010,13 +2261,13 @@ func (m *Coin) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + m.Log = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1026,23 +2277,23 @@ func (m *Coin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Events = append(m.Events, types.Event{}) + if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1070,7 +2321,7 @@ func (m *Coin) Unmarshal(dAtA []byte) error { } return nil } -func (m *DecCoin) Unmarshal(dAtA []byte) error { +func (m *SimulationResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1093,17 +2344,17 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: DecCoin: wiretype end group for non-group") + return fmt.Errorf("proto: SimulationResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: DecCoin: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: SimulationResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field GasInfo", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1113,29 +2364,30 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + 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 Amount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1145,23 +2397,25 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.Result == nil { + m.Result = &Result{} + } + if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1189,7 +2443,7 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error { } return nil } -func (m *IntProto) Unmarshal(dAtA []byte) error { +func (m *TxResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1212,15 +2466,34 @@ func (m *IntProto) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: IntProto: wiretype end group for non-group") + return fmt.Errorf("proto: TxResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: TxResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TxHash", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1248,66 +2521,160 @@ func (m *IntProto) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + m.TxHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Codespace", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF } + m.Codespace = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Code", wireType) } - if skippy < 0 { + m.Code = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Code |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - if (iNdEx + skippy) < 0 { + postIndex := iNdEx + intStringLen + if postIndex < 0 { return ErrInvalidLengthTypes } - if (iNdEx + skippy) > l { + if postIndex > l { return io.ErrUnexpectedEOF } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *DecProto) 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 ErrIntOverflowTypes + m.Data = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RawLog", wireType) } - if iNdEx >= l { + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break + m.RawLog = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Logs", wireType) } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: DecProto: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Logs = append(m.Logs, ABCIMessageLog{}) + if err := m.Logs[len(m.Logs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Info", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1335,68 +2702,87 @@ func (m *DecProto) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Info = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) } - if skippy < 0 { + m.GasWanted = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasWanted |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) + } + m.GasUsed = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasUsed |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + 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 ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { return ErrInvalidLengthTypes } - if (iNdEx + skippy) < 0 { + postIndex := iNdEx + msglen + if postIndex < 0 { return ErrInvalidLengthTypes } - if (iNdEx + skippy) > l { + if postIndex > l { return io.ErrUnexpectedEOF } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ValAddresses) 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 ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF + if m.Tx == nil { + m.Tx = &types1.Any{} } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break + if err := m.Tx.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ValAddresses: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + iNdEx = postIndex + case 12: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1406,23 +2792,23 @@ func (m *ValAddresses) 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 ErrInvalidLengthTypes } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx)) - copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex]) + m.Timestamp = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -1448,7 +2834,7 @@ func (m *ValAddresses) Unmarshal(dAtA []byte) error { } return nil } -func (m *GasInfo) Unmarshal(dAtA []byte) error { +func (m *ABCIMessageLog) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1471,17 +2857,17 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: GasInfo: wiretype end group for non-group") + return fmt.Errorf("proto: ABCIMessageLog: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: GasInfo: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ABCIMessageLog: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasWanted", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgIndex", wireType) } - m.GasWanted = 0 + m.MsgIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1491,16 +2877,16 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.GasWanted |= uint64(b&0x7F) << shift + m.MsgIndex |= uint32(b&0x7F) << shift if b < 0x80 { break } } case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) } - m.GasUsed = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1510,11 +2896,58 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.GasUsed |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Log = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Events = append(m.Events, StringEvent{}) + if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -1539,7 +2972,7 @@ func (m *GasInfo) Unmarshal(dAtA []byte) error { } return nil } -func (m *Result) Unmarshal(dAtA []byte) error { +func (m *StringEvent) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1562,49 +2995,15 @@ func (m *Result) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Result: wiretype end group for non-group") + return fmt.Errorf("proto: StringEvent: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Result: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: StringEvent: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Log", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1632,11 +3031,11 @@ func (m *Result) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Log = string(dAtA[iNdEx:postIndex]) + m.Type = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1663,8 +3062,8 @@ func (m *Result) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Events = append(m.Events, types.Event{}) - if err := m.Events[len(m.Events)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Attributes = append(m.Attributes, Attribute{}) + if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1692,7 +3091,7 @@ func (m *Result) Unmarshal(dAtA []byte) error { } return nil } -func (m *SimulationResponse) Unmarshal(dAtA []byte) error { +func (m *Attribute) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1715,17 +3114,17 @@ func (m *SimulationResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: SimulationResponse: wiretype end group for non-group") + return fmt.Errorf("proto: Attribute: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: SimulationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Attribute: 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) + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1735,30 +3134,29 @@ func (m *SimulationResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.GasInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Key = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Result", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -1768,27 +3166,23 @@ func (m *SimulationResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Result == nil { - m.Result = &Result{} - } - if err := m.Result.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Value = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/types/types.proto b/types/types.proto index 56a796f06723..e1fd7ec94579 100644 --- a/types/types.proto +++ b/types/types.proto @@ -3,6 +3,7 @@ package cosmos_sdk.v1; import "third_party/proto/gogoproto/gogo.proto"; import "third_party/proto/tendermint/abci/types/types.proto"; +import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/types"; option (gogoproto.goproto_stringer_all) = false; @@ -79,17 +80,49 @@ message SimulationResponse { Result result = 2; } +// TxResponse defines a structure containing relevant tx data and metadata. The +// tags are stringified and the log is JSON decoded. message TxResponse { + option (gogoproto.goproto_getters) = false; + int64 height = 1; - string txhash = 2; + string txhash = 2 [(gogoproto.customname) = "TxHash"]; string codespace = 3; uint32 code = 4; string data = 5; string raw_log = 6; - // Logs ABCIMessageLogs `json:"logs,omitempty"` + repeated ABCIMessageLog logs = 7 [(gogoproto.castrepeated) = "ABCIMessageLogs", (gogoproto.nullable) = false]; string info = 8; int64 gas_wanted = 9; int64 gas_used = 10; - // google.protobuf.Any tx = 11; - // google.protobuf.Timestamp = 12; + google.protobuf.Any tx = 11; + string timestamp = 12; +} + +// ABCIMessageLog defines a structure containing an indexed tx ABCI message log. +message ABCIMessageLog { + option (gogoproto.stringer) = true; + + uint32 msg_index = 1; + string log = 2; + + // Events contains a slice of Event objects that were emitted during some + // execution. + repeated StringEvent events = 3 [(gogoproto.castrepeated) = "StringEvents", (gogoproto.nullable) = false]; +} + +// StringAttribute defines en Event object wrapper where all the attributes +// contain key/value pairs that are strings instead of raw bytes. +message StringEvent { + option (gogoproto.stringer) = true; + + string type = 1; + repeated Attribute attributes = 2 [(gogoproto.nullable) = false]; +} + +// Attribute defines an attribute wrapper where the key and value are +// strings instead of raw bytes. +message Attribute { + string key = 1; + string value = 2; } diff --git a/x/auth/alias.go b/x/auth/alias.go index 9895210c9d98..5abb5081e099 100644 --- a/x/auth/alias.go +++ b/x/auth/alias.go @@ -22,7 +22,6 @@ const ( DefaultSigVerifyCostSecp256k1 = types.DefaultSigVerifyCostSecp256k1 QueryAccount = types.QueryAccount QueryParams = types.QueryParams - MaxGasWanted = types.MaxGasWanted Minter = types.Minter Burner = types.Burner Staking = types.Staking diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 749e20542b0d..a70c1cfb4416 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -2,6 +2,7 @@ package ante import ( sdk "github.com/cosmos/cosmos-sdk/types" + types2 "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ibcante "github.com/cosmos/cosmos-sdk/x/ibc/ante" @@ -48,9 +49,9 @@ func NewProtoAnteHandler( NewValidateSigCountDecorator(ak), NewDeductFeeDecorator(ak, bankKeeper), NewSigGasConsumeDecorator(ak, sigGasConsumer), - NewProtoSigVerificationDecorator(ak, []signing.SignModeHandler{ + NewProtoSigVerificationDecorator(ak, []types2.SignModeHandler{ signing.DirectModeHandler{}, - signing.LegacyAminoJSONHandler{}, + types.LegacyAminoJSONHandler{}, }), NewIncrementSequenceDecorator(ak), ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index c540e6c2768b..4352a71d9bc2 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -8,19 +8,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/cosmos/cosmos-sdk/types/tx/signing" auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) type ProtoSigVerificationDecorator struct { - ak AccountKeeper - signModeHandlers map[types.SignMode]signing.SignModeHandler + ak AccountKeeper + handler types.SignModeHandler } -func NewProtoSigVerificationDecorator(ak AccountKeeper, signModeHandlers []signing.SignModeHandler) ProtoSigVerificationDecorator { - handlerMap := make(map[types.SignMode]signing.SignModeHandler) +func NewProtoSigVerificationDecorator(ak AccountKeeper, signModeHandlers []types.SignModeHandler) ProtoSigVerificationDecorator { + handlerMap := make(map[types.SignMode]types.SignModeHandler) for _, h := range signModeHandlers { - handlerMap[h.Mode()] = h + handlerMap[h.Modes()] = h } return ProtoSigVerificationDecorator{ ak: ak, @@ -124,7 +123,7 @@ func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, sin if !genesis { accNum = signerAcc.GetAccountNumber() } - data := signing.SigningData{ + data := types.SigningData{ ModeInfo: single, PublicKey: signerAcc.GetPubKey(), ChainID: ctx.ChainID(), diff --git a/x/auth/ante/types/types.go b/x/auth/ante/types/types.go index f9e34f0f9aad..29150f6ca7b0 100644 --- a/x/auth/ante/types/types.go +++ b/x/auth/ante/types/types.go @@ -1,36 +1,15 @@ package types import ( - "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" types2 "github.com/cosmos/cosmos-sdk/x/auth/types" ) -// FeeTx defines the interface to be implemented by Tx to use the FeeDecorators -type FeeTx interface { - types.Tx - GetGas() uint64 - GetFee() types.Coins - FeePayer() types.AccAddress -} - -// Tx must have GetMemo() method to use ValidateMemoDecorator -type TxWithMemo interface { - types.Tx - GetMemo() string -} - // SigVerifiableTx defines a Tx interface for all signature verification decorators type SigVerifiableTx interface { types.Tx - SigTx + txtypes.SigTx GetSignBytes(ctx types.Context, acc types2.AccountI) []byte } -type SigTx interface { - types.Tx - GetSignatures() [][]byte - GetSigners() []types.AccAddress - GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place -} diff --git a/x/auth/client/cli/broadcast.go b/x/auth/client/cli/broadcast.go index f948dbdd9b8b..3f13c39f9245 100644 --- a/x/auth/client/cli/broadcast.go +++ b/x/auth/client/cli/broadcast.go @@ -32,7 +32,7 @@ $ tx broadcast ./mytxn.json return errors.New("cannot broadcast tx during offline mode") } - stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0]) + stdTx, err := client.ReadTxFromFile(cliCtx, args[0]) if err != nil { return err } diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index 245bb0e0f675..0b8f1739ea67 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/client" ) @@ -20,7 +19,7 @@ func (txr txEncodeRespStr) String() string { // GetEncodeCommand returns the encode command to take a JSONified transaction and turn it into // Amino-serialized bytes -func GetEncodeCommand(cdc *codec.Codec) *cobra.Command { +func GetEncodeCommand(cliCtx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "encode [file]", Short: "Encode transactions generated offline", @@ -29,15 +28,15 @@ Read a transaction from , serialize it to the Amino wire protocol, and out If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { - cliCtx := context.NewCLIContext().WithCodec(cdc) + cliCtx := cliCtx.Init() - stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0]) + tx, err := client.ReadTxFromFile(cliCtx, args[0]) if err != nil { return } - // re-encode it via the Amino wire protocol - txBytes, err := cliCtx.Codec.MarshalBinaryBare(stdTx) + // re-encode it + txBytes, err := cliCtx.TxGenerator.TxEncoder()(tx) if err != nil { return err } diff --git a/x/auth/client/cli/tx.go b/x/auth/client/cli/tx.go index 742ab3547189..01a1827d3b0c 100644 --- a/x/auth/client/cli/tx.go +++ b/x/auth/client/cli/tx.go @@ -1,15 +1,15 @@ package cli import ( + "github.com/cosmos/cosmos-sdk/client/context" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" ) // GetTxCmd returns the transaction commands for this module -func GetTxCmd(cdc *codec.Codec) *cobra.Command { +func GetTxCmd(ctx context.CLIContext) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Auth transaction subcommands", @@ -18,9 +18,9 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { RunE: client.ValidateCmd, } txCmd.AddCommand( - GetMultiSignCommand(cdc), - GetSignCommand(cdc), - GetValidateSignaturesCommand(cdc), + GetMultiSignCommand(ctx), + GetSignCommand(ctx), + GetValidateSignaturesCommand(ctx), ) return txCmd } diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 42b4daada567..bfb128b52228 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -3,6 +3,7 @@ package cli import ( "bufio" "fmt" + "github.com/cosmos/cosmos-sdk/client/tx" "io/ioutil" "os" "strings" @@ -23,7 +24,7 @@ import ( ) // GetSignCommand returns the sign command -func GetMultiSignCommand(cdc *codec.Codec) *cobra.Command { +func GetMultiSignCommand(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "multisign [file] [name] [[signature]...]", Short: "Generate multisig signatures for transactions generated offline", @@ -46,7 +47,7 @@ recommended to set such parameters manually. version.ClientName, ), ), - RunE: makeMultiSignCmd(cdc), + RunE: makeMultiSignCmd(ctx), Args: cobra.MinimumNArgs(3), } @@ -57,9 +58,9 @@ recommended to set such parameters manually. return flags.PostCommands(cmd)[0] } -func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error { +func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, args []string) error) { return func(cmd *cobra.Command, args []string) (err error) { - stdTx, err := client.ReadStdTxFromFile(cdc, args[0]) + stdTx, err := client.ReadTxFromFile(cliContext, args[0]) if err != nil { return } @@ -81,8 +82,8 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - txBldr := types.NewTxBuilderFromCLI(inBuf) + cliCtx := cliContext.InitWithInput(inBuf) + txBldr := tx.NewFactoryFromCLI(inBuf) if !cliCtx.Offline { accnum, seq, err := types.NewAccountRetriever(client.Codec).GetAccountNumberSequence(cliCtx, multisigInfo.GetAddress()) @@ -95,7 +96,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) // read each signature and add it to the multisig if valid for i := 2; i < len(args); i++ { - stdSig, err := readAndUnmarshalStdSignature(cdc, args[i]) + stdSig, err := readAndUnmarshalStdSignature(cliContext, args[i]) if err != nil { return err } @@ -113,20 +114,20 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) } } - newStdSig := types.StdSignature{Signature: cdc.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck - newTx := types.NewStdTx(stdTx.GetMsgs(), stdTx.Fee, []types.StdSignature{newStdSig}, stdTx.GetMemo()) //nolint:staticcheck + newStdSig := types.StdSignature{Signature: cliContext.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck + newTx := types.NewStdTx(stdTx.GetMsgs(), stdTx.Fee, []types.StdSignature{newStdSig}, stdTx.GetMemo()) //nolint:staticcheck sigOnly := viper.GetBool(flagSigOnly) var json []byte switch { case sigOnly && cliCtx.Indent: - json, err = cdc.MarshalJSONIndent(newTx.Signatures[0], "", " ") + json, err = cliContext.MarshalJSONIndent(newTx.Signatures[0], "", " ") case sigOnly && !cliCtx.Indent: - json, err = cdc.MarshalJSON(newTx.Signatures[0]) + json, err = cliContext.MarshalJSON(newTx.Signatures[0]) case !sigOnly && cliCtx.Indent: - json, err = cdc.MarshalJSONIndent(newTx, "", " ") + json, err = cliContext.MarshalJSONIndent(newTx, "", " ") default: - json, err = cdc.MarshalJSON(newTx) + json, err = cliContext.MarshalJSON(newTx) } if err != nil { return err @@ -151,7 +152,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) } } -func readAndUnmarshalStdSignature(cdc *codec.Codec, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck +func readAndUnmarshalStdSignature(cdc context.CLIContext, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck var bytes []byte if bytes, err = ioutil.ReadFile(filename); err != nil { return diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index dc118974a61c..020df91a9494 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/cosmos/cosmos-sdk/client/context" "os" "github.com/spf13/cobra" @@ -22,7 +23,7 @@ const ( ) // GetSignCommand returns the transaction sign command. -func GetSignCommand(codec *codec.Codec) *cobra.Command { +func GetSignCommand(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "sign [file]", Short: "Sign transactions generated offline", @@ -42,7 +43,7 @@ key. It implies --signature-only. Full multisig signed transactions may eventual be generated via the 'multisign' command. `, PreRun: preSignCmd, - RunE: makeSignCmd(codec), + RunE: makeSignCmd(ctx), Args: cobra.ExactArgs(1), } @@ -71,9 +72,9 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } } -func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error { +func makeSignCmd(cdc context.CLIContext) (func(cmd *cobra.Command, args []string) error) { return func(cmd *cobra.Command, args []string) error { - cliCtx, txBldr, stdTx, err := readStdTxAndInitContexts(cdc, cmd, args[0]) + cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) if err != nil { return err } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 07846fc6e76c..1c0cfa8a61e9 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -3,6 +3,9 @@ package cli import ( "bufio" "fmt" + "github.com/cosmos/cosmos-sdk/client/tx" + multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" "strings" "github.com/spf13/cobra" @@ -10,13 +13,11 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func GetValidateSignaturesCommand(codec *codec.Codec) *cobra.Command { +func GetValidateSignaturesCommand(cliCtx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "validate-signatures [file]", Short: "Validate transactions signatures", @@ -29,16 +30,16 @@ given transaction. If the --offline flag is also set, signature validation over transaction will be not be performed as that will require RPC communication with a full node. `, PreRun: preSignCmd, - RunE: makeValidateSignaturesCmd(codec), + RunE: makeValidateSignaturesCmd(cliCtx), Args: cobra.ExactArgs(1), } return flags.PostCommands(cmd)[0] } -func makeValidateSignaturesCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error { +func makeValidateSignaturesCmd(cliCtx context.CLIContext) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - cliCtx, txBldr, stdTx, err := readStdTxAndInitContexts(cdc, cmd, args[0]) + cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cliCtx, cmd, args[0]) if err != nil { return err } @@ -55,17 +56,21 @@ func makeValidateSignaturesCmd(cdc *codec.Codec) func(cmd *cobra.Command, args [ // expected signers. In addition, if offline has not been supplied, the signature is // verified over the transaction sign bytes. Returns false if the validation fails. func printAndValidateSigs( - cmd *cobra.Command, cliCtx context.CLIContext, chainID string, stdTx types.StdTx, offline bool, + cmd *cobra.Command, cliCtx context.CLIContext, chainID string, tx sdk.Tx, offline bool, ) bool { + sigTx := tx.(txtypes.SigTx) + signModeHandler := cliCtx.TxGenerator.SignModeHandler() + cmd.Println("Signers:") - signers := stdTx.GetSigners() + signers := sigTx.GetSigners() for i, signer := range signers { cmd.Printf(" %v: %v\n", i, signer.String()) } success := true - sigs := stdTx.Signatures + sigs := sigTx.GetSignatures() + pubKeys := sigTx.GetPubKeys() cmd.Println("") cmd.Println("Signatures:") @@ -75,9 +80,10 @@ func printAndValidateSigs( for i, sig := range sigs { var ( + pubKey = pubKeys[i] multiSigHeader string multiSigMsg string - sigAddr = sdk.AccAddress(sig.GetPubKey().Address()) + sigAddr = sdk.AccAddress(pubKey.Address()) sigSanity = "OK" ) @@ -89,27 +95,74 @@ func printAndValidateSigs( // Validate the actual signature over the transaction bytes since we can // reach out to a full node to query accounts. if !offline && success { - acc, err := types.NewAccountRetriever(client.Codec).GetAccount(cliCtx, sigAddr) + accNum, accSeq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, sigAddr) if err != nil { cmd.Printf("failed to get account: %s\n", sigAddr) return false } - sigBytes := types.StdSignBytes( - chainID, acc.GetAccountNumber(), acc.GetSequence(), - stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), - ) + signingData := txtypes.SigningData{ + PublicKey: pubKey, + ChainID: chainID, + AccountNumber: accNum, + AccountSequence: accSeq, + } + + if protoTx, ok := tx.(txtypes.ProtoTx); ok { + modeInfo := protoTx.GetAuthInfo().SignerInfos[i].ModeInfo + switch modeInfo := modeInfo.Sum.(type) { + case *txtypes.ModeInfo_Single_: + signingData.ModeInfo = modeInfo.Single + sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) + if err != nil { + sigSanity = "ERROR: can't get sign bytes" + success = false + } + + if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { + sigSanity = "ERROR: signature invalid" + success = false + } + case *txtypes.ModeInfo_Multi_: + multisigs, err := multisig2.DecodeMultisignatures(sig) + if err != nil { + sigSanity = "ERROR: can't decoded multisignature" + success = false + } + + if multiPK, ok := pubKey.(multisig2.MultisigPubKey); ok { + multiPK.VerifyMultisignature(func(single *txtypes.ModeInfo_Single) ([]byte, error) { + signingData.ModeInfo = single + return signModeHandler.GetSignBytes(signingData, tx) + }, multisig2.DecodedMultisignature{ + ModeInfo: modeInfo.Multi, + Signatures: multisigs, + }) + } + default: + sigSanity = "ERROR: unexpected ModeInfo" + success = false + } + } else { + sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) + if err != nil { + sigSanity = "ERROR: can't get sign bytes" + success = false + } - if ok := sig.GetPubKey().VerifyBytes(sigBytes, sig.Signature); !ok { - sigSanity = "ERROR: signature invalid" - success = false + if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { + sigSanity = "ERROR: signature invalid" + success = false + } } } - multiPK, ok := sig.GetPubKey().(multisig.PubKeyMultisigThreshold) + multiPK, ok := pubKey.(multisig.PubKeyMultisigThreshold) if ok { var multiSig multisig.Multisignature - cliCtx.Codec.MustUnmarshalBinaryBare(sig.Signature, &multiSig) + + panic("TODO: update this:") + cliCtx.Codec.MustUnmarshalBinaryBare(sig, &multiSig) var b strings.Builder b.WriteString("\n MultiSig Signatures:\n") @@ -133,17 +186,16 @@ func printAndValidateSigs( return success } -func readStdTxAndInitContexts(cdc *codec.Codec, cmd *cobra.Command, filename string) ( - context.CLIContext, types.TxBuilder, types.StdTx, error, -) { - stdTx, err := client.ReadStdTxFromFile(cdc, filename) +func readTxAndInitContexts(cliCtx context.CLIContext, cmd *cobra.Command, filename string) (context.CLIContext, tx.Factory, sdk.Tx, error, ) { + stdTx, err := client.ReadTxFromFile(cliCtx, filename) if err != nil { - return context.CLIContext{}, types.TxBuilder{}, types.StdTx{}, err + return cliCtx, tx.Factory{}, nil, err } + inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - txBldr := types.NewTxBuilderFromCLI(inBuf) + cliCtx = cliCtx.InitWithInput(inBuf) + txFactory := tx.NewFactoryFromCLI(inBuf) - return cliCtx, txBldr, stdTx, nil + return cliCtx, txFactory, stdTx, nil } diff --git a/x/auth/client/query.go b/x/auth/client/query.go index 85bd747bc3c5..1e03fd79c6ff 100644 --- a/x/auth/client/query.go +++ b/x/auth/client/query.go @@ -74,31 +74,31 @@ func QueryTxsByEvents(cliCtx context.CLIContext, events []string, page, limit in // QueryTx queries for a single transaction by a hash string in hex format. An // error is returned if the transaction does not exist or cannot be queried. -func QueryTx(cliCtx context.CLIContext, hashHexStr string) (sdk.TxResponse, error) { +func QueryTx(cliCtx context.CLIContext, hashHexStr string) (*sdk.TxResponse, error) { hash, err := hex.DecodeString(hashHexStr) if err != nil { - return sdk.TxResponse{}, err + return nil, err } node, err := cliCtx.GetNode() if err != nil { - return sdk.TxResponse{}, err + return nil, err } resTx, err := node.Tx(hash, !cliCtx.TrustNode) if err != nil { - return sdk.TxResponse{}, err + return nil, err } if !cliCtx.TrustNode { if err = ValidateTxResult(cliCtx, resTx); err != nil { - return sdk.TxResponse{}, err + return nil, err } } resBlocks, err := getBlocksForTxResults(cliCtx, []*ctypes.ResultTx{resTx}) if err != nil { - return sdk.TxResponse{}, err + return nil, err } out, err := formatTxResult(cliCtx.Codec, resTx, resBlocks[resTx.Height]) @@ -110,9 +110,9 @@ func QueryTx(cliCtx context.CLIContext, hashHexStr string) (sdk.TxResponse, erro } // formatTxResults parses the indexed txs into a slice of TxResponse objects. -func formatTxResults(cdc *codec.Codec, resTxs []*ctypes.ResultTx, resBlocks map[int64]*ctypes.ResultBlock) ([]sdk.TxResponse, error) { +func formatTxResults(cdc *codec.Codec, resTxs []*ctypes.ResultTx, resBlocks map[int64]*ctypes.ResultBlock) ([]*sdk.TxResponse, error) { var err error - out := make([]sdk.TxResponse, len(resTxs)) + out := make([]*sdk.TxResponse, len(resTxs)) for i := range resTxs { out[i], err = formatTxResult(cdc, resTxs[i], resBlocks[resTxs[i].Height]) if err != nil { @@ -160,10 +160,10 @@ func getBlocksForTxResults(cliCtx context.CLIContext, resTxs []*ctypes.ResultTx) return resBlocks, nil } -func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.ResultBlock) (sdk.TxResponse, error) { +func formatTxResult(cdc *codec.Codec, resTx *ctypes.ResultTx, resBlock *ctypes.ResultBlock) (*sdk.TxResponse, error) { tx, err := parseTx(cdc, resTx.Tx) if err != nil { - return sdk.TxResponse{}, err + return nil, err } return sdk.NewResponseResultTx(resTx, tx, resBlock.Block.Time.Format(time.RFC3339)), nil diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 82b47082d56c..e73ff162b249 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -230,7 +230,7 @@ func SignStdTxWithSignerAddress( } // Read and decode a StdTx from the given filename. Can pass "-" to read from stdin. -func ReadStdTxFromFile(cdc *codec.Codec, filename string) (stdTx authtypes.StdTx, err error) { +func ReadTxFromFile(ctx context.CLIContext, filename string) (tx sdk.Tx, err error) { var bytes []byte if filename == "-" { @@ -243,11 +243,7 @@ func ReadStdTxFromFile(cdc *codec.Codec, filename string) (stdTx authtypes.StdTx return } - if err = cdc.UnmarshalJSON(bytes, &stdTx); err != nil { - return - } - - return + return ctx.TxJSONDecoder(bytes) } func populateAccountFromState( diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index ab2ce267ece3..0c6320a8d25b 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -129,7 +129,7 @@ func TestReadStdTxFromFile(t *testing.T) { defer os.Remove(jsonTxFile.Name()) // Read it back - decodedTx, err := ReadStdTxFromFile(cdc, jsonTxFile.Name()) + decodedTx, err := ReadTxFromFile(cdc, jsonTxFile.Name()) require.NoError(t, err) require.Equal(t, decodedTx.Memo, "foomemo") } diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 73573bf27a09..c60b1fa4f48b 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -1,6 +1,8 @@ package types import ( + "fmt" + types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/client/context" @@ -79,6 +81,10 @@ type StdTxGenerator struct { Cdc *codec.Codec } +func (s StdTxGenerator) SignModeHandler() types.SignModeHandler { + return LegacyAminoJSONHandler{} +} + var _ context.TxGenerator = StdTxGenerator{} // NewTxBuilder implements TxGenerator.NewTxBuilder @@ -125,3 +131,27 @@ func (ss *StdSignature) SetPubKey(key crypto.PubKey) error { func (ss *StdSignature) SetSignature(bytes []byte) { ss.Signature = bytes } + +type LegacyAminoJSONHandler struct{} + +var _ types.SignModeHandler = LegacyAminoJSONHandler{} + +func (LegacyAminoJSONHandler) Modes() []types.SignMode { + return []types.SignMode{types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} +} + +func (LegacyAminoJSONHandler) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { + feeTx, ok := tx.(types.FeeTx) + if !ok { + return nil, fmt.Errorf("expected FeeTx, got %T", tx) + } + + memoTx, ok := tx.(types.TxWithMemo) + if !ok { + return nil, fmt.Errorf("expected TxWithMemo, got %T", tx) + } + + return StdSignBytes( + data.ChainID, data.AccountNumber, data.AccountSequence, StdFee{Amount: feeTx.GetFee(), Gas: feeTx.GetGas()}, tx.GetMsgs(), memoTx.GetMemo(), + ), nil +} diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 47494f45d3d6..f14236745cc5 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -3,6 +3,7 @@ package types import ( "encoding/json" "fmt" + types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" @@ -14,9 +15,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// MaxGasWanted defines the max gas allowed. -const MaxGasWanted = uint64((1 << 63) - 1) - // Deprecated: StdFee includes the amount of coins paid in fees and the maximum // gas to be used by the transaction. The ratio yields an effective "gasprice", // which must be above some miminum to be accepted into the mempool. @@ -168,10 +166,10 @@ func (tx StdTx) GetMsgs() []sdk.Msg { return tx.Msgs } func (tx StdTx) ValidateBasic() error { stdSigs := tx.GetSignatures() - if tx.Fee.Gas > MaxGasWanted { + if tx.Fee.Gas > types.MaxGasWanted { return sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, - "invalid gas supplied; %d > %d", tx.Fee.Gas, MaxGasWanted, + "invalid gas supplied; %d > %d", tx.Fee.Gas, types.MaxGasWanted, ) } if tx.Fee.Amount.IsAnyNegative() { diff --git a/x/auth/types/txbuilder.go b/x/auth/types/txbuilder.go index fd5598492a5c..03c7ac2eb978 100644 --- a/x/auth/types/txbuilder.go +++ b/x/auth/types/txbuilder.go @@ -14,7 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// TxBuilder implements a transaction context created in SDK modules. +// deprecated: TxBuilder implements a transaction context created in SDK modules. type TxBuilder struct { txEncoder sdk.TxEncoder keybase keyring.Keyring diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index d8fda5e87918..1358624fcadc 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -53,7 +53,7 @@ func QueryDepositsByTxQuery(cliCtx context.CLIContext, params types.QueryProposa var deposits []types.Deposit for _, info := range searchResult.Txs { - for _, msg := range info.Tx.GetMsgs() { + for _, msg := range info.GetTx().GetMsgs() { if msg.Type() == types.TypeMsgDeposit { depMsg := msg.(*types.MsgDeposit) @@ -94,7 +94,7 @@ func QueryVotesByTxQuery(cliCtx context.CLIContext, params types.QueryProposalVo } nextTxPage++ for _, info := range searchResult.Txs { - for _, msg := range info.Tx.GetMsgs() { + for _, msg := range info.GetTx().GetMsgs() { if msg.Type() == types.TypeMsgVote { voteMsg := msg.(*types.MsgVote) @@ -137,7 +137,7 @@ func QueryVoteByTxQuery(cliCtx context.CLIContext, params types.QueryVoteParams) return nil, err } for _, info := range searchResult.Txs { - for _, msg := range info.Tx.GetMsgs() { + for _, msg := range info.GetTx().GetMsgs() { // there should only be a single vote under the given conditions if msg.Type() == types.TypeMsgVote { voteMsg := msg.(*types.MsgVote) @@ -177,7 +177,7 @@ func QueryDepositByTxQuery(cliCtx context.CLIContext, params types.QueryDepositP } for _, info := range searchResult.Txs { - for _, msg := range info.Tx.GetMsgs() { + for _, msg := range info.GetTx().GetMsgs() { // there should only be a single deposit under the given conditions if msg.Type() == types.TypeMsgDeposit { depMsg := msg.(*types.MsgDeposit) @@ -216,7 +216,7 @@ func QueryProposerByTxQuery(cliCtx context.CLIContext, proposalID uint64) (Propo } for _, info := range searchResult.Txs { - for _, msg := range info.Tx.GetMsgs() { + for _, msg := range info.GetTx().GetMsgs() { // there should only be a single proposal under the given conditions if msg.Type() == types.TypeMsgSubmitProposal { subMsg := msg.(*types.MsgSubmitProposal) From dd682b5bfaae8c4df281c4bd3cd8e25f21ebe9b2 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 28 May 2020 15:25:14 -0400 Subject: [PATCH 43/54] Add SignatureV2 --- crypto/multisig/threshold_pubkey.go | 16 +------ crypto/types/types.go | 18 ++++++- simapp/cmd/simcli/main.go | 6 +-- types/tx/fee.go | 3 ++ types/tx/tx.go | 73 ++++++++++++++++++++++++++++- x/auth/ante/basic.go | 14 +++--- x/auth/ante/fee.go | 9 ++-- x/auth/ante/sigverify.go | 10 ++-- x/auth/ante/sigverify_proto.go | 20 +++----- x/auth/client/cli/tx_multisign.go | 40 ++++++++++------ x/auth/client/cli/tx_sign.go | 12 ++--- x/auth/client/cli/validate_sigs.go | 15 +++--- x/auth/client/tx.go | 20 +++----- x/auth/types/stdtx.go | 72 ++++++++++++++++++++++------ 14 files changed, 222 insertions(+), 106 deletions(-) diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index 55bce0c4f2a4..894870d40eaf 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -1,8 +1,6 @@ package multisig import ( - "fmt" - "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/crypto/types" @@ -72,18 +70,6 @@ func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool { return true } -func DecodeMultisignatures(bz []byte) ([][]byte, error) { - multisig := types.MultiSignature{} - err := multisig.Unmarshal(bz) - if err != nil { - return nil, err - } - if len(multisig.XXX_unrecognized) > 0 { - return nil, fmt.Errorf("rejecting unrecognized fields found in MultiSignature") - } - return multisig.Signatures, nil -} - func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool { bitarray := sig.ModeInfo.Bitarray sigs := sig.Signatures @@ -119,7 +105,7 @@ func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig Decoded if !ok { return false } - nestedSigs, err := DecodeMultisignatures(sigs[sigIndex]) + nestedSigs, err := types.DecodeMultisignatures(sigs[sigIndex]) if err != nil { return false } diff --git a/crypto/types/types.go b/crypto/types/types.go index 8361271c69ae..16cfbd36b840 100644 --- a/crypto/types/types.go +++ b/crypto/types/types.go @@ -1,6 +1,10 @@ package types -import "github.com/tendermint/tendermint/crypto" +import ( + "fmt" + + "github.com/tendermint/tendermint/crypto" +) // PublicKey specifies a public key type PublicKey struct { @@ -24,3 +28,15 @@ type PublicKey struct { func (pk PublicKey) GetCachedPubKey() crypto.PubKey { return pk.cachedValue } + +func DecodeMultisignatures(bz []byte) ([][]byte, error) { + multisig := MultiSignature{} + err := multisig.Unmarshal(bz) + if err != nil { + return nil, err + } + if len(multisig.XXX_unrecognized) > 0 { + return nil, fmt.Errorf("rejecting unrecognized fields found in MultiSignature") + } + return multisig.Signatures, nil +} diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 07b247d2b0db..539b519b530f 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -121,9 +121,9 @@ func txCmd(cdc *codec.Codec) *cobra.Command { txCmd.AddCommand( bankcmd.NewSendTxCmd(cliCtx), flags.LineBreak, - authcmd.GetSignCommand(cdc), - authcmd.GetMultiSignCommand(cdc), - authcmd.GetValidateSignaturesCommand(cdc), + authcmd.GetSignCommand(cliCtx), + authcmd.GetMultiSignCommand(cliCtx), + authcmd.GetValidateSignaturesCommand(cliCtx), flags.LineBreak, authcmd.GetBroadcastCommand(cdc), authcmd.GetEncodeCommand(cliCtx), diff --git a/types/tx/fee.go b/types/tx/fee.go index 9b6e9dca392d..6c165c7e8846 100644 --- a/types/tx/fee.go +++ b/types/tx/fee.go @@ -2,6 +2,9 @@ package types import sdk "github.com/cosmos/cosmos-sdk/types" +// MaxGasWanted defines the max gas allowed. +const MaxGasWanted = uint64((1 << 63) - 1) + func (m *Fee) GetGas() uint64 { return m.GasLimit } diff --git a/types/tx/tx.go b/types/tx/tx.go index 1494d4d32d02..b8b63af5106d 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -3,6 +3,8 @@ package types import ( "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/crypto/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -172,8 +174,75 @@ type SigTx interface { GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place + GetSignaturesV2() ([]SignatureV2, error) +} + +type SignatureV2 interface { + isSignatureV2() +} + +type SingleSignature struct { + SignMode SignMode + Signature []byte +} + +type MultiSignature struct { + BitArray *types.CompactBitArray + Signatures []SignatureV2 +} + +var _, _ SignatureV2 = SingleSignature{}, MultiSignature{} + +func (m SingleSignature) isSignatureV2() {} +func (m MultiSignature) isSignatureV2() {} + +func ModeInfoToSignatureV2(modeInfo *ModeInfo, sig []byte) (SignatureV2, error) { + switch modeInfo := modeInfo.Sum.(type) { + case *ModeInfo_Single_: + return SingleSignature{ + SignMode: modeInfo.Single.Mode, + Signature: sig, + }, nil + + case *ModeInfo_Multi_: + multi := modeInfo.Multi + + sigs, err := types.DecodeMultisignatures(sig) + if err != nil { + return nil, err + } + + sigv2s := make([]SignatureV2, len(sigs)) + for i, mi := range multi.ModeInfos { + sigv2s[i], err = ModeInfoToSignatureV2(mi, sigs[i]) + if err != nil { + return nil, err + } + } + + return MultiSignature{ + BitArray: multi.Bitarray, + Signatures: sigv2s, + }, nil + + default: + panic("unexpected case") + } } -// MaxGasWanted defines the max gas allowed. -const MaxGasWanted = uint64((1 << 63) - 1) +func (m *Tx) GetSignaturesV2() ([]SignatureV2, error) { + signerInfos := m.AuthInfo.SignerInfos + sigs := m.Signatures + n := len(signerInfos) + res := make([]SignatureV2, n) + for i, si := range signerInfos { + var err error + res[i], err = ModeInfoToSignatureV2(si.ModeInfo, sigs[i]) + if err != nil { + return nil, err + } + } + + return res, nil +} diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 44de45b07692..eefa9d33a66b 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,19 +1,19 @@ package ante import ( + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/multisig" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - types2 "github.com/cosmos/cosmos-sdk/x/auth/ante/types" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/multisig" + types3 "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/types" ) var ( - _ types2.TxWithMemo = (*types.StdTx)(nil) // assert StdTx implements TxWithMemo + _ types3.TxWithMemo = (*types.StdTx)(nil) // assert StdTx implements TxWithMemo ) // ValidateBasicDecorator will call tx.ValidateBasic and return any non-nil error. @@ -53,7 +53,7 @@ func NewValidateMemoDecorator(ak AccountKeeper) ValidateMemoDecorator { } func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - memoTx, ok := tx.(types2.TxWithMemo) + memoTx, ok := tx.(types3.TxWithMemo) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -91,7 +91,7 @@ func NewConsumeGasForTxSizeDecorator(ak AccountKeeper) ConsumeTxSizeGasDecorator } func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(types2.SigTx) + sigTx, ok := tx.(types3.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 7ad17204c218..2fc6f1317c9e 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -3,15 +3,14 @@ package ante import ( "fmt" - types2 "github.com/cosmos/cosmos-sdk/x/auth/ante/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/types" ) var ( - _ types2.FeeTx = (*types.StdTx)(nil) // assert StdTx implements FeeTx + _ txtypes.FeeTx = (*types.StdTx)(nil) // assert StdTx implements FeeTx ) // MempoolFeeDecorator will check if the transaction's fee is at least as large @@ -27,7 +26,7 @@ func NewMempoolFeeDecorator() MempoolFeeDecorator { } func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - feeTx, ok := tx.(types2.FeeTx) + feeTx, ok := tx.(txtypes.FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } @@ -76,7 +75,7 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper) DeductFeeDecor } func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - feeTx, ok := tx.(types2.FeeTx) + feeTx, ok := tx.(txtypes.FeeTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index e14fe51a4335..6e9836362ea0 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -4,6 +4,8 @@ import ( "bytes" "encoding/hex" + types3 "github.com/cosmos/cosmos-sdk/types/tx" + types2 "github.com/cosmos/cosmos-sdk/x/auth/ante/types" "github.com/tendermint/tendermint/crypto" @@ -50,7 +52,7 @@ func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { } func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(types2.SigTx) + sigTx, ok := tx.(types3.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") } @@ -107,7 +109,7 @@ func NewSigGasConsumeDecorator(ak AccountKeeper, sigGasConsumer SignatureVerific } func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - sigTx, ok := tx.(types2.SigTx) + sigTx, ok := tx.(types3.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -232,7 +234,7 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim return next(ctx, tx, simulate) } - sigTx, ok := tx.(types2.SigTx) + sigTx, ok := tx.(types3.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } @@ -265,7 +267,7 @@ func NewValidateSigCountDecorator(ak AccountKeeper) ValidateSigCountDecorator { } func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - sigTx, ok := tx.(types2.SigTx) + sigTx, ok := tx.(types3.SigTx) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a sigTx") } diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 4352a71d9bc2..8542d1ab4e5c 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -1,9 +1,8 @@ package ante import ( - "fmt" - "github.com/cosmos/cosmos-sdk/crypto/multisig" + types2 "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -16,14 +15,10 @@ type ProtoSigVerificationDecorator struct { handler types.SignModeHandler } -func NewProtoSigVerificationDecorator(ak AccountKeeper, signModeHandlers []types.SignModeHandler) ProtoSigVerificationDecorator { - handlerMap := make(map[types.SignMode]types.SignModeHandler) - for _, h := range signModeHandlers { - handlerMap[h.Modes()] = h - } +func NewProtoSigVerificationDecorator(ak AccountKeeper, signModeHandler types.SignModeHandler) ProtoSigVerificationDecorator { return ProtoSigVerificationDecorator{ - ak: ak, - signModeHandlers: handlerMap, + ak: ak, + handler: signModeHandler, } } @@ -87,7 +82,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } if !simulate { - multiSigs, err := multisig.DecodeMultisignatures(sig) + multiSigs, err := types2.DecodeMultisignatures(sig) if err != nil { return ctx, sdkerrors.Wrap(err, "cannot decode MultiSignature") } @@ -114,10 +109,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, single *types.ModeInfo_Single, signerAcc auth.AccountI, sigTx types.ProtoTx) ([]byte, error) { - verifier, found := svd.signModeHandlers[single.Mode] - if !found { - return nil, fmt.Errorf("can't verify sign mode %s", single.Mode.String()) - } + verifier := svd.handler genesis := ctx.BlockHeight() == 0 var accNum uint64 if !genesis { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index bfb128b52228..831bf6d57dc9 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -3,11 +3,14 @@ package cli import ( "bufio" "fmt" - "github.com/cosmos/cosmos-sdk/client/tx" "io/ioutil" "os" "strings" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" + types2 "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/spf13/cobra" "github.com/spf13/viper" @@ -15,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" @@ -58,9 +60,9 @@ recommended to set such parameters manually. return flags.PostCommands(cmd)[0] } -func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, args []string) error) { +func makeMultiSignCmd(cliCtx context.CLIContext) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) (err error) { - stdTx, err := client.ReadTxFromFile(cliContext, args[0]) + stdTx, err := client.ReadTxFromFile(cliCtx, args[0]) if err != nil { return } @@ -82,7 +84,7 @@ func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, a multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - cliCtx := cliContext.InitWithInput(inBuf) + cliCtx := cliCtx.InitWithInput(inBuf) txBldr := tx.NewFactoryFromCLI(inBuf) if !cliCtx.Offline { @@ -94,9 +96,17 @@ func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, a txBldr = txBldr.WithAccountNumber(accnum).WithSequence(seq) } + feeTx := stdTx.(types2.FeeTx) + fee := types.StdFee{ + Amount: feeTx.GetFee(), + Gas: feeTx.GetGas(), + } + + memoTx := stdTx.(types2.TxWithMemo) + // read each signature and add it to the multisig if valid for i := 2; i < len(args); i++ { - stdSig, err := readAndUnmarshalStdSignature(cliContext, args[i]) + stdSig, err := readAndUnmarshalStdSignature(cliCtx, args[i]) if err != nil { return err } @@ -104,7 +114,7 @@ func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, a // Validate each signature sigBytes := types.StdSignBytes( txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(), - stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), + fee, stdTx.GetMsgs(), memoTx.GetMemo(), ) if ok := stdSig.GetPubKey().VerifyBytes(sigBytes, stdSig.Signature); !ok { return fmt.Errorf("couldn't verify signature") @@ -114,20 +124,20 @@ func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, a } } - newStdSig := types.StdSignature{Signature: cliContext.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck - newTx := types.NewStdTx(stdTx.GetMsgs(), stdTx.Fee, []types.StdSignature{newStdSig}, stdTx.GetMemo()) //nolint:staticcheck + newStdSig := types.StdSignature{Signature: cliCtx.Codec.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck + newTx := types.NewStdTx(stdTx.GetMsgs(), fee, []types.StdSignature{newStdSig}, memoTx.GetMemo()) //nolint:staticcheck sigOnly := viper.GetBool(flagSigOnly) var json []byte switch { case sigOnly && cliCtx.Indent: - json, err = cliContext.MarshalJSONIndent(newTx.Signatures[0], "", " ") + json, err = codec.MarshalJSONIndent(cliCtx.JSONMarshaler, newTx.Signatures[0]) case sigOnly && !cliCtx.Indent: - json, err = cliContext.MarshalJSON(newTx.Signatures[0]) + json, err = cliCtx.JSONMarshaler.MarshalJSON(newTx.Signatures[0]) case !sigOnly && cliCtx.Indent: - json, err = cliContext.MarshalJSONIndent(newTx, "", " ") + json, err = codec.MarshalJSONIndent(cliCtx.JSONMarshaler, newTx) default: - json, err = cliContext.MarshalJSON(newTx) + json, err = cliCtx.JSONMarshaler.MarshalJSON(newTx) } if err != nil { return err @@ -152,12 +162,12 @@ func makeMultiSignCmd(cliContext context.CLIContext) (func(cmd *cobra.Command, a } } -func readAndUnmarshalStdSignature(cdc context.CLIContext, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck +func readAndUnmarshalStdSignature(cliContext context.CLIContext, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck var bytes []byte if bytes, err = ioutil.ReadFile(filename); err != nil { return } - if err = cdc.UnmarshalJSON(bytes, &stdSig); err != nil { + if err = cliContext.JSONMarshaler.UnmarshalJSON(bytes, &stdSig); err != nil { return } return diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 020df91a9494..ceae5a9db8fb 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -2,12 +2,12 @@ package cli import ( "fmt" - "github.com/cosmos/cosmos-sdk/client/context" "os" "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -72,7 +72,7 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } } -func makeSignCmd(cdc context.CLIContext) (func(cmd *cobra.Command, args []string) error) { +func makeSignCmd(cdc context.CLIContext) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) if err != nil { @@ -104,7 +104,7 @@ func makeSignCmd(cdc context.CLIContext) (func(cmd *cobra.Command, args []string return err } - json, err := getSignatureJSON(cdc, newTx, cliCtx.Indent, generateSignatureOnly) + json, err := getSignatureJSON(cliCtx.JSONMarshaler, newTx, cliCtx.Indent, generateSignatureOnly) if err != nil { return err } @@ -128,12 +128,12 @@ func makeSignCmd(cdc context.CLIContext) (func(cmd *cobra.Command, args []string } } -func getSignatureJSON(cdc *codec.Codec, newTx types.StdTx, indent, generateSignatureOnly bool) ([]byte, error) { +func getSignatureJSON(cdc codec.JSONMarshaler, newTx types.StdTx, indent, generateSignatureOnly bool) ([]byte, error) { switch generateSignatureOnly { case true: switch indent { case true: - return cdc.MarshalJSONIndent(newTx.Signatures[0], "", " ") + return codec.MarshalJSONIndent(cdc, newTx.Signatures[0]) default: return cdc.MarshalJSON(newTx.Signatures[0]) @@ -141,7 +141,7 @@ func getSignatureJSON(cdc *codec.Codec, newTx types.StdTx, indent, generateSigna default: switch indent { case true: - return cdc.MarshalJSONIndent(newTx, "", " ") + return codec.MarshalJSONIndent(cdc, newTx) default: return cdc.MarshalJSON(newTx) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 1c0cfa8a61e9..ceff68c8c4c9 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -3,17 +3,19 @@ package cli import ( "bufio" "fmt" - "github.com/cosmos/cosmos-sdk/client/tx" - multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" - txtypes "github.com/cosmos/cosmos-sdk/types/tx" "strings" + "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/spf13/cobra" "github.com/tendermint/tendermint/crypto/multisig" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/client" ) @@ -80,7 +82,7 @@ func printAndValidateSigs( for i, sig := range sigs { var ( - pubKey = pubKeys[i] + pubKey = pubKeys[i] multiSigHeader string multiSigMsg string sigAddr = sdk.AccAddress(pubKey.Address()) @@ -124,7 +126,7 @@ func printAndValidateSigs( success = false } case *txtypes.ModeInfo_Multi_: - multisigs, err := multisig2.DecodeMultisignatures(sig) + multisigs, err := types.DecodeMultisignatures(sig) if err != nil { sigSanity = "ERROR: can't decoded multisignature" success = false @@ -186,13 +188,12 @@ func printAndValidateSigs( return success } -func readTxAndInitContexts(cliCtx context.CLIContext, cmd *cobra.Command, filename string) (context.CLIContext, tx.Factory, sdk.Tx, error, ) { +func readTxAndInitContexts(cliCtx context.CLIContext, cmd *cobra.Command, filename string) (context.CLIContext, tx.Factory, sdk.Tx, error) { stdTx, err := client.ReadTxFromFile(cliCtx, filename) if err != nil { return cliCtx, tx.Factory{}, nil, err } - inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx = cliCtx.InitWithInput(inBuf) txFactory := tx.NewFactoryFromCLI(inBuf) diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index e73ff162b249..f8079fc771b8 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -8,6 +8,8 @@ import ( "os" "strings" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/gogo/protobuf/jsonpb" "github.com/pkg/errors" "github.com/spf13/viper" @@ -177,10 +179,7 @@ func PrintUnsignedStdTx(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, m // SignStdTx appends a signature to a StdTx and returns a copy of it. If appendSig // is false, it replaces the signatures already attached with the new signature. // Don't perform online validation or lookups if offline is true. -func SignStdTx( - txBldr authtypes.TxBuilder, cliCtx context.CLIContext, name string, - stdTx authtypes.StdTx, appendSig bool, offline bool, -) (authtypes.StdTx, error) { +func SignStdTx(txBldr tx.Factory, cliCtx context.CLIContext, name string, stdTx context.TxBuilder, appendSig bool, offline bool) (authtypes.StdTx, error) { var signedStdTx authtypes.StdTx @@ -203,16 +202,13 @@ func SignStdTx( } } - return txBldr.SignStdTx(name, stdTx, appendSig) + return tx.Sign(txBldr, name, "", stdTx) } // SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it. // Don't perform online validation or lookups if offline is true, else // populate account and sequence numbers from a foreign account. -func SignStdTxWithSignerAddress( - txBldr authtypes.TxBuilder, cliCtx context.CLIContext, - addr sdk.AccAddress, name string, stdTx authtypes.StdTx, offline bool, -) (signedStdTx authtypes.StdTx, err error) { +func SignStdTxWithSignerAddress(txBldr tx.Factory, cliCtx context.CLIContext, addr sdk.AccAddress, name string, stdTx sdk.Tx, offline bool) (signedStdTx authtypes.StdTx, err error) { // check whether the address is a signer if !isTxSigner(addr, stdTx.GetSigners()) { @@ -246,11 +242,9 @@ func ReadTxFromFile(ctx context.CLIContext, filename string) (tx sdk.Tx, err err return ctx.TxJSONDecoder(bytes) } -func populateAccountFromState( - txBldr authtypes.TxBuilder, cliCtx context.CLIContext, addr sdk.AccAddress, -) (authtypes.TxBuilder, error) { +func populateAccountFromState(txBldr tx.Factory, cliCtx context.CLIContext, addr sdk.AccAddress) (tx.Factory, error) { - num, seq, err := authtypes.NewAccountRetriever(Codec).GetAccountNumberSequence(cliCtx, addr) + num, seq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, addr) if err != nil { return txBldr, err } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index f14236745cc5..f0014bdb3b15 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -3,6 +3,9 @@ package types import ( "encoding/json" "fmt" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + types2 "github.com/cosmos/cosmos-sdk/crypto/types" types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" @@ -10,7 +13,6 @@ import ( yaml "gopkg.in/yaml.v2" "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" ) @@ -138,7 +140,11 @@ func CountSubKeys(pub crypto.PubKey) int { // DEPRECATED // --------------------------------------------------------------------------- -var _ sdk.Tx = (*StdTx)(nil) +var ( + _ sdk.Tx = (*StdTx)(nil) + _ types.SigTx = (*StdTx)(nil) + _ codectypes.UnpackInterfacesMessage = StdTx{} +) // StdTx is a standard way to wrap a Msg with Fee and Signatures. // NOTE: the first signature is the fee payer (Signatures must not be nil). @@ -272,6 +278,56 @@ func (tx StdTx) FeePayer() sdk.AccAddress { return sdk.AccAddress{} } +func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureV2 { + switch pk := pk.(type) { + case multisig.PubKeyMultisigThreshold: + var multisignature multisig.Multisignature + codec.Cdc.MustUnmarshalBinaryBare(sig, &multisignature) + sigs := make([]types.SignatureV2, len(multisignature.Sigs)) + size := multisignature.BitArray.Size() + sigIndex := 0 + + for i := 0; i < size; i++ { + if multisignature.BitArray.GetIndex(i) { + sigs[i] = stdSignatureToSignatureV2(pk.PubKeys[i], multisignature.Sigs[sigIndex]) + sigIndex++ + } + } + + return types.MultiSignature{ + BitArray: &types2.CompactBitArray{ + ExtraBitsStored: uint32(multisignature.BitArray.ExtraBitsStored), + Elems: multisignature.BitArray.Elems, + }, + Signatures: sigs, + } + default: + return types.SingleSignature{ + SignMode: types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + Signature: sig, + } + } +} + +func (tx StdTx) GetSignaturesV2() ([]types.SignatureV2, error) { + sigs := tx.Signatures + res := make([]types.SignatureV2, len(sigs)) + for i, sig := range sigs { + res[i] = stdSignatureToSignatureV2(sig.GetPubKey(), sig.Signature) + } + return res, nil +} + +func (tx StdTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, m := range tx.Msgs { + err := codectypes.UnpackInterfaces(m, unpacker) + if err != nil { + return err + } + } + return nil +} + // StdSignDoc is replay-prevention structure. // It includes the result of msg.GetSignBytes(), // as well as the ChainID (prevent cross chain replay) @@ -360,15 +416,3 @@ func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder { return cdc.MarshalBinaryBare(tx) } } - -var _ codectypes.UnpackInterfacesMessage = StdTx{} - -func (tx StdTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - for _, m := range tx.Msgs { - err := codectypes.UnpackInterfaces(m, unpacker) - if err != nil { - return err - } - } - return nil -} From 88e2ab23e2c83a815f9252dbcf596b864a93ea08 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 28 May 2020 17:26:12 -0400 Subject: [PATCH 44/54] Refactor signature, multisig --- client/keys/codec.go | 3 +- client/rpc/block.go | 7 +- client/rpc/status.go | 7 +- codec/amino.go | 27 ------- codec/legacy_global/amino.go | 33 +++++++++ crypto/codec/default.go | 2 +- crypto/multisig/amino.go | 29 ++++++++ crypto/multisig/codec.go | 30 -------- crypto/multisig/multisig.go | 17 ++--- crypto/multisig/multisignature.go | 38 +++++----- crypto/multisig/threshold_pubkey.go | 92 ++++++++---------------- crypto/multisig/threshold_pubkey_test.go | 65 +++++++++-------- crypto/types/codec.go | 4 +- server/tm_cmds.go | 3 +- std/codec.go | 3 +- types/rest/rest.go | 3 +- types/rest/rest_test.go | 3 +- types/result.go | 6 +- types/result_test.go | 3 +- types/tx/signature.go | 57 +++++++++++++++ types/tx/tx.go | 55 -------------- x/auth/ante/basic.go | 4 +- x/auth/ante/sigverify.go | 4 +- x/auth/client/tx_test.go | 3 +- x/auth/legacy/v0_39/migrate_test.go | 3 +- x/auth/types/codec.go | 3 +- x/auth/types/stdtx.go | 24 ++++--- x/auth/vesting/types/vesting_account.go | 18 ++--- x/bank/legacy/v0_39/migrate_test.go | 3 +- x/bank/types/codec.go | 3 +- x/crisis/types/codec.go | 3 +- x/distribution/types/codec.go | 3 +- x/evidence/types/codec.go | 3 +- x/genutil/client/cli/init_test.go | 3 +- x/genutil/legacy/v0_36/migrate.go | 5 +- x/genutil/legacy/v0_38/migrate.go | 5 +- x/genutil/legacy/v0_39/migrate.go | 5 +- x/genutil/types/codec.go | 3 +- x/gov/types/codec.go | 3 +- x/ibc/07-tendermint/tendermint_test.go | 3 +- x/mint/types/codec.go | 3 +- x/params/keeper/querier.go | 5 +- x/slashing/types/codec.go | 3 +- x/staking/legacy/v0_34/types.go | 6 +- x/staking/legacy/v0_36/types.go | 6 +- x/staking/legacy/v0_38/types.go | 6 +- x/staking/simulation/decoder_test.go | 3 +- x/staking/types/codec.go | 3 +- x/staking/types/validator_test.go | 6 +- 49 files changed, 315 insertions(+), 314 deletions(-) create mode 100644 codec/legacy_global/amino.go create mode 100644 crypto/multisig/amino.go delete mode 100644 crypto/multisig/codec.go create mode 100644 types/tx/signature.go diff --git a/client/keys/codec.go b/client/keys/codec.go index e47d3b231afc..c68f123bc6de 100644 --- a/client/keys/codec.go +++ b/client/keys/codec.go @@ -2,6 +2,7 @@ package keys import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" ) // KeysCdc defines codec to be used with key operations @@ -9,7 +10,7 @@ var KeysCdc *codec.Codec func init() { KeysCdc = codec.New() - codec.RegisterCrypto(KeysCdc) + legacy_global.RegisterCrypto(KeysCdc) KeysCdc.Seal() } diff --git a/client/rpc/block.go b/client/rpc/block.go index 6e930b641c01..81a918231e9f 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -5,13 +5,14 @@ import ( "net/http" "strconv" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" + "github.com/gorilla/mux" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/rest" tmliteProxy "github.com/tendermint/tendermint/lite/proxy" @@ -65,10 +66,10 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) { } if cliCtx.Indent { - return codec.Cdc.MarshalJSONIndent(res, "", " ") + return legacy_global.Cdc.MarshalJSONIndent(res, "", " ") } - return codec.Cdc.MarshalJSON(res) + return legacy_global.Cdc.MarshalJSON(res) } // get the current blockchain height diff --git a/client/rpc/status.go b/client/rpc/status.go index 5987930b7779..eb69a4b100e8 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -4,6 +4,8 @@ import ( "fmt" "net/http" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" + "github.com/spf13/cobra" "github.com/spf13/viper" @@ -11,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/version" @@ -55,9 +56,9 @@ func printNodeStatus(_ *cobra.Command, _ []string) error { var output []byte if cliCtx.Indent { - output, err = codec.Cdc.MarshalJSONIndent(status, "", " ") + output, err = legacy_global.Cdc.MarshalJSONIndent(status, "", " ") } else { - output, err = codec.Cdc.MarshalJSON(status) + output, err = legacy_global.Cdc.MarshalJSON(status) } if err != nil { return err diff --git a/codec/amino.go b/codec/amino.go index 53587808e65f..b21533261970 100644 --- a/codec/amino.go +++ b/codec/amino.go @@ -6,25 +6,10 @@ import ( "fmt" amino "github.com/tendermint/go-amino" - cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec/types" ) -// Cdc defines a global generic sealed Amino codec to be used throughout sdk. It -// has all Tendermint crypto and evidence types registered. -// -// TODO: Consider removing this global. -var Cdc *Codec - -func init() { - Cdc = New() - RegisterCrypto(Cdc) - RegisterEvidences(Cdc) - Cdc.Seal() -} - // deprecated: Codec defines a wrapper for an Amino codec that properly handles protobuf // types with Any's type Codec struct { @@ -41,18 +26,6 @@ func New() *Codec { return &Codec{amino.NewCodec()} } -// RegisterCrypto registers all crypto dependency types with the provided Amino -// codec. -func RegisterCrypto(cdc *Codec) { - cryptoamino.RegisterAmino(cdc.Amino) -} - -// RegisterEvidences registers Tendermint evidence types with the provided Amino -// codec. -func RegisterEvidences(cdc *Codec) { - tmtypes.RegisterEvidences(cdc.Amino) -} - // MarshalJSONIndent provides a utility for indented JSON encoding of an object // via an Amino codec. It returns an error if it cannot serialize or indent as // JSON. diff --git a/codec/legacy_global/amino.go b/codec/legacy_global/amino.go new file mode 100644 index 000000000000..6ee80edef743 --- /dev/null +++ b/codec/legacy_global/amino.go @@ -0,0 +1,33 @@ +package legacy_global + +import ( + "github.com/tendermint/tendermint/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/multisig" +) + +// Cdc defines a global generic sealed Amino codec to be used throughout sdk. It +// has all Tendermint crypto and evidence types registered. +// +// TODO: Consider removing this global. +var Cdc *codec.Codec + +func init() { + Cdc = codec.New() + RegisterCrypto(Cdc) + RegisterEvidences(Cdc) + Cdc.Seal() +} + +// RegisterCrypto registers all crypto dependency types with the provided Amino +// codec. +func RegisterCrypto(cdc *codec.Codec) { + multisig.RegisterAmino(cdc.Amino) +} + +// RegisterEvidences registers Tendermint evidence types with the provided Amino +// codec. +func RegisterEvidences(cdc *codec.Codec) { + types.RegisterEvidences(cdc.Amino) +} diff --git a/crypto/codec/default.go b/crypto/codec/default.go index eb8ed9a34f92..ffe382651b35 100644 --- a/crypto/codec/default.go +++ b/crypto/codec/default.go @@ -66,7 +66,7 @@ func (cdc DefaultPublicKeyCodec) Encode(key crypto.PubKey) (*types.PublicKey, er return &types.PublicKey{Sum: &types.PublicKey_Ed25519{Ed25519: key[:]}}, nil case sr25519.PubKeySr25519: return &types.PublicKey{Sum: &types.PublicKey_Sr25519{Sr25519: key[:]}}, nil - case multisig.PubKey: + case multisig.ThresholdMultisigPubKey: pubKeys := key.PubKeys resKeys := make([]*types.PublicKey, len(pubKeys)) for i, k := range pubKeys { diff --git a/crypto/multisig/amino.go b/crypto/multisig/amino.go new file mode 100644 index 000000000000..2e1527046d71 --- /dev/null +++ b/crypto/multisig/amino.go @@ -0,0 +1,29 @@ +package multisig + +import ( + amino "github.com/tendermint/go-amino" + "github.com/tendermint/tendermint/crypto/multisig" + + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/tendermint/tendermint/crypto/sr25519" +) + +var cdc = amino.NewCodec() + +func init() { + RegisterAmino(cdc) +} + +func RegisterAmino(amino *amino.Codec) { + amino.RegisterInterface((*crypto.PubKey)(nil), nil) + amino.RegisterConcrete(ThresholdMultisigPubKey{}, + multisig.PubKeyMultisigThresholdAminoRoute, nil) + amino.RegisterConcrete(ed25519.PubKeyEd25519{}, + ed25519.PubKeyAminoName, nil) + amino.RegisterConcrete(sr25519.PubKeySr25519{}, + sr25519.PubKeyAminoName, nil) + amino.RegisterConcrete(secp256k1.PubKeySecp256k1{}, + secp256k1.PubKeyAminoName, nil) +} diff --git a/crypto/multisig/codec.go b/crypto/multisig/codec.go deleted file mode 100644 index 3c34b6ca0162..000000000000 --- a/crypto/multisig/codec.go +++ /dev/null @@ -1,30 +0,0 @@ -package multisig - -import ( - amino "github.com/tendermint/go-amino" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/tendermint/tendermint/crypto/sr25519" -) - -// TODO: Figure out API for others to either add their own pubkey types, or -// to make verify / marshal accept a cdc. -const ( - PubKeyAminoRoute = "tendermint/PubKeyMultisigThreshold" -) - -var cdc = amino.NewCodec() - -func init() { - cdc.RegisterInterface((*crypto.PubKey)(nil), nil) - cdc.RegisterConcrete(PubKey{}, - PubKeyAminoRoute, nil) - cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, - ed25519.PubKeyAminoName, nil) - cdc.RegisterConcrete(sr25519.PubKeySr25519{}, - sr25519.PubKeyAminoName, nil) - cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{}, - secp256k1.PubKeyAminoName, nil) -} diff --git a/crypto/multisig/multisig.go b/crypto/multisig/multisig.go index 4a871ef9f6cf..2b413d126345 100644 --- a/crypto/multisig/multisig.go +++ b/crypto/multisig/multisig.go @@ -1,14 +1,15 @@ package multisig -import types "github.com/cosmos/cosmos-sdk/types/tx" +import ( + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/tendermint/tendermint/crypto" +) -type DecodedMultisignature struct { - ModeInfo *types.ModeInfo_Multi - Signatures [][]byte -} - -type GetSignBytesFunc func(single *types.ModeInfo_Single) ([]byte, error) +type GetSignBytesFunc func(mode types.SignMode) ([]byte, error) type MultisigPubKey interface { - VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool + crypto.PubKey + + VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *types.MultiSignature) bool + GetPubKeys() []crypto.PubKey } diff --git a/crypto/multisig/multisignature.go b/crypto/multisig/multisignature.go index 2e21935f26ad..87d4bf361ec1 100644 --- a/crypto/multisig/multisignature.go +++ b/crypto/multisig/multisignature.go @@ -4,23 +4,21 @@ import ( "fmt" "strings" - "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/crypto/types" + tx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/tendermint/tendermint/crypto" ) -// Multisignature is used to represent the signature object used in the multisigs. +// AminoMultisignature is used to represent the signature object used in the multisigs. // Sigs is a list of signatures, sorted by corresponding index. -type Multisignature struct { +type AminoMultisignature struct { BitArray *types.CompactBitArray Sigs [][]byte } -// NewMultisig returns a new Multisignature of size n. -func NewMultisig(n int) *Multisignature { - // Default the signature list to have a capacity of two, since we can - // expect that most multisigs will require multiple signers. - return &Multisignature{types.NewCompactBitArray(n), make([][]byte, 0, 2)} +// NewMultisig returns a new MultiSignature +func NewMultisig(n int) *tx.MultiSignature { + return &tx.MultiSignature{BitArray: types.NewCompactBitArray(n), Signatures: make([]tx.SignatureV2, n)} } // GetIndex returns the index of pk in keys. Returns -1 if not found @@ -35,29 +33,29 @@ func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int { // AddSignature adds a signature to the multisig, at the corresponding index. // If the signature already exists, replace it. -func (mSig *Multisignature) AddSignature(sig []byte, index int) { +func AddSignature(mSig *tx.MultiSignature, sig tx.SignatureV2, index int) { newSigIndex := mSig.BitArray.NumTrueBitsBefore(index) // Signature already exists, just replace the value there if mSig.BitArray.GetIndex(index) { - mSig.Sigs[newSigIndex] = sig + mSig.Signatures[newSigIndex] = sig return } mSig.BitArray.SetIndex(index, true) // Optimization if the index is the greatest index - if newSigIndex == len(mSig.Sigs) { - mSig.Sigs = append(mSig.Sigs, sig) + if newSigIndex == len(mSig.Signatures) { + mSig.Signatures = append(mSig.Signatures, sig) return } // Expand slice by one with a dummy element, move all elements after i // over by one, then place the new signature in that gap. - mSig.Sigs = append(mSig.Sigs, make([]byte, 0)) - copy(mSig.Sigs[newSigIndex+1:], mSig.Sigs[newSigIndex:]) - mSig.Sigs[newSigIndex] = sig + mSig.Signatures = append(mSig.Signatures, &tx.SingleSignature{}) + copy(mSig.Signatures[newSigIndex+1:], mSig.Signatures[newSigIndex:]) + mSig.Signatures[newSigIndex] = sig } // AddSignatureFromPubKey adds a signature to the multisig, at the index in // keys corresponding to the provided pubkey. -func (mSig *Multisignature) AddSignatureFromPubKey(sig []byte, pubkey crypto.PubKey, keys []crypto.PubKey) error { +func AddSignatureFromPubKey(mSig *tx.MultiSignature, sig tx.SignatureV2, pubkey crypto.PubKey, keys []crypto.PubKey) error { index := getIndex(pubkey, keys) if index == -1 { keysStr := make([]string, len(keys)) @@ -68,11 +66,7 @@ func (mSig *Multisignature) AddSignatureFromPubKey(sig []byte, pubkey crypto.Pub return fmt.Errorf("provided key %X doesn't exist in pubkeys: \n%s", pubkey.Bytes(), strings.Join(keysStr, "\n")) } - mSig.AddSignature(sig, index) + AddSignature(mSig, sig, index) return nil } -// Marshal the multisignature with amino -func (mSig *Multisignature) Marshal() []byte { - return cdc.MustMarshalBinaryBare(mSig) -} diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index 894870d40eaf..a28d129f5ad9 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -3,21 +3,20 @@ package multisig import ( "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/crypto/types" txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) -// PubKey implements a K of N threshold multisig. -type PubKey struct { +// ThresholdMultisigPubKey implements a K of N threshold multisig. +type ThresholdMultisigPubKey struct { K uint32 `json:"threshold"` PubKeys []crypto.PubKey `json:"pubkeys"` } -var _ crypto.PubKey = PubKey{} +var _ MultisigPubKey = ThresholdMultisigPubKey{} // NewPubKeyMultisigThreshold returns a new PubKeyMultisigThreshold. // Panics if len(pubkeys) < k or 0 >= k. -func NewPubKeyMultisigThreshold(k uint32, pubkeys []crypto.PubKey) crypto.PubKey { +func NewPubKeyMultisigThreshold(k uint32, pubkeys []crypto.PubKey) MultisigPubKey { if k <= 0 { panic("threshold k of n multisignature: k <= 0") } @@ -29,49 +28,17 @@ func NewPubKeyMultisigThreshold(k uint32, pubkeys []crypto.PubKey) crypto.PubKey panic("nil pubkey") } } - return PubKey{k, pubkeys} + return ThresholdMultisigPubKey{k, pubkeys} } -// VerifyBytes expects sig to be an amino encoded version of a MultiSignature. -// Returns true iff the multisignature contains k or more signatures -// for the correct corresponding keys, -// and all signatures are valid. (Not just k of the signatures) -// The multisig uses a bitarray, so multiple signatures for the same key is not -// a concern. -func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool { - var sig Multisignature - err := cdc.UnmarshalBinaryBare(marshalledSig, &sig) - if err != nil { - return false - } - size := sig.BitArray.Size() - // ensure bit array is the correct size - if len(pk.PubKeys) != size { - return false - } - // ensure size of signature list - if len(sig.Sigs) < int(pk.K) || len(sig.Sigs) > size { - return false - } - // ensure at least k signatures are set - if sig.BitArray.NumTrueBitsBefore(size) < int(pk.K) { - return false - } - // index in the list of signatures which we are concerned with. - sigIndex := 0 - for i := 0; i < size; i++ { - if sig.BitArray.GetIndex(i) { - if !pk.PubKeys[i].VerifyBytes(msg, sig.Sigs[sigIndex]) { - return false - } - sigIndex++ - } - } - return true +// VerifyBytes should not be used with this ThresholdMultisigPubKey, instead VerifyMultisignature +// must be used +func (pk ThresholdMultisigPubKey) VerifyBytes([]byte, []byte) bool { + return false } -func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig DecodedMultisignature) bool { - bitarray := sig.ModeInfo.Bitarray +func (pk ThresholdMultisigPubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *txtypes.MultiSignature) bool { + bitarray := sig.BitArray sigs := sig.Signatures size := bitarray.Size() // ensure bit array is the correct size @@ -90,29 +57,22 @@ func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig Decoded sigIndex := 0 for i := 0; i < size; i++ { if bitarray.GetIndex(i) { - mi := sig.ModeInfo.ModeInfos[sigIndex] - switch mi := mi.Sum.(type) { - case *txtypes.ModeInfo_Single_: - msg, err := getSignBytes(mi.Single) + si := sig.Signatures[sigIndex] + switch si := si.(type) { + case *txtypes.SingleSignature: + msg, err := getSignBytes(si.SignMode) if err != nil { return false } - if !pk.PubKeys[i].VerifyBytes(msg, sigs[sigIndex]) { + if !pk.PubKeys[i].VerifyBytes(msg, si.Signature) { return false } - case *txtypes.ModeInfo_Multi_: + case *txtypes.MultiSignature: nestedMultisigPk, ok := pk.PubKeys[i].(MultisigPubKey) if !ok { return false } - nestedSigs, err := types.DecodeMultisignatures(sigs[sigIndex]) - if err != nil { - return false - } - if !nestedMultisigPk.VerifyMultisignature(getSignBytes, DecodedMultisignature{ - ModeInfo: mi.Multi, - Signatures: nestedSigs, - }) { + if !nestedMultisigPk.VerifyMultisignature(getSignBytes, si) { return false } default: @@ -124,20 +84,24 @@ func (pk PubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig Decoded return true } -// Bytes returns the amino encoded version of the PubKey -func (pk PubKey) Bytes() []byte { +func (pk ThresholdMultisigPubKey) GetPubKeys() []crypto.PubKey { + return pk.PubKeys +} + +// Bytes returns the amino encoded version of the ThresholdMultisigPubKey +func (pk ThresholdMultisigPubKey) Bytes() []byte { return cdc.MustMarshalBinaryBare(pk) } -// Address returns tmhash(PubKey.Bytes()) -func (pk PubKey) Address() crypto.Address { +// Address returns tmhash(ThresholdMultisigPubKey.Bytes()) +func (pk ThresholdMultisigPubKey) Address() crypto.Address { return crypto.AddressHash(pk.Bytes()) } // Equals returns true iff pk and other both have the same number of keys, and // all constituent keys are the same, and in the same order. -func (pk PubKey) Equals(other crypto.PubKey) bool { - otherKey, sameType := other.(PubKey) +func (pk ThresholdMultisigPubKey) Equals(other crypto.PubKey) bool { + otherKey, sameType := other.(ThresholdMultisigPubKey) if !sameType { return false } diff --git a/crypto/multisig/threshold_pubkey_test.go b/crypto/multisig/threshold_pubkey_test.go index 2168edd71aa9..3f1e407cad6a 100644 --- a/crypto/multisig/threshold_pubkey_test.go +++ b/crypto/multisig/threshold_pubkey_test.go @@ -1,11 +1,13 @@ package multisig import ( + "github.com/tendermint/tendermint/crypto/multisig" "math/rand" "testing" "github.com/stretchr/testify/require" + types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/secp256k1" @@ -22,7 +24,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { pubkeys []crypto.PubKey signingIndices []int // signatures should be the same size as signingIndices. - signatures [][]byte + signatures []types.SignatureV2 passAfterKSignatures []bool }{ { @@ -37,48 +39,47 @@ func TestThresholdMultisigValidCases(t *testing.T) { for tcIndex, tc := range cases { multisigKey := NewPubKeyMultisigThreshold(tc.k, tc.pubkeys) multisignature := NewMultisig(len(tc.pubkeys)) + signBytesFn := func(mode types.SignMode) ([]byte, error) { return tc.msg, nil } for i := uint32(0); i < tc.k-1; i++ { signingIndex := tc.signingIndices[i] require.NoError( t, - multisignature.AddSignatureFromPubKey(tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), + AddSignatureFromPubKey(multisignature, tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), ) - bz := multisignature.Marshal() require.False( t, - multisigKey.VerifyBytes(tc.msg, bz), + multisigKey.VerifyMultisignature(signBytesFn, multisignature), "multisig passed when i < k, tc %d, i %d", tcIndex, i, ) require.NoError( t, - multisignature.AddSignatureFromPubKey(tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), + AddSignatureFromPubKey(multisignature, tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), ) require.Equal( t, int(i+1), - len(multisignature.Sigs), + len(multisignature.Signatures), "adding a signature for the same pubkey twice increased signature count by 2, tc %d", tcIndex, ) } - bz := multisignature.Marshal() require.False( t, - multisigKey.VerifyBytes(tc.msg, bz), + multisigKey.VerifyMultisignature(signBytesFn, multisignature), "multisig passed with k - 1 sigs, tc %d", tcIndex, ) require.NoError( t, - multisignature.AddSignatureFromPubKey( + AddSignatureFromPubKey( + multisignature, tc.signatures[tc.signingIndices[tc.k]], tc.pubkeys[tc.signingIndices[tc.k]], tc.pubkeys, ), ) - bz = multisignature.Marshal() require.True( t, - multisigKey.VerifyBytes(tc.msg, bz), + multisigKey.VerifyMultisignature(signBytesFn, multisignature), "multisig failed after k good signatures, tc %d", tcIndex, ) @@ -87,23 +88,24 @@ func TestThresholdMultisigValidCases(t *testing.T) { require.NoError( t, - multisignature.AddSignatureFromPubKey(tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), + AddSignatureFromPubKey(multisignature, tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), ) - bz := multisignature.Marshal() require.Equal( t, tc.passAfterKSignatures[i-int(tc.k)-1], - multisigKey.VerifyBytes(tc.msg, bz), + multisigKey.VerifyMultisignature(func(mode types.SignMode) ([]byte, error) { + return tc.msg, nil + }, multisignature), "multisig didn't verify as expected after k sigs, tc %d, i %d", tcIndex, i, ) require.NoError( t, - multisignature.AddSignatureFromPubKey(tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), + AddSignatureFromPubKey(multisignature, tc.signatures[signingIndex], tc.pubkeys[signingIndex], tc.pubkeys), ) require.Equal( t, i+1, - len(multisignature.Sigs), + len(multisignature.Signatures), "adding a signature for the same pubkey twice increased signature count by 2, tc %d", tcIndex, ) } @@ -116,21 +118,21 @@ func TestThresholdMultisigDuplicateSignatures(t *testing.T) { pubkeys, sigs := generatePubKeysAndSignatures(5, msg) multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) multisignature := NewMultisig(5) - bz := multisignature.Marshal() + signBytesFn := func(mode types.SignMode) ([]byte, error) { return msg, nil } - require.False(t, multisigKey.VerifyBytes(msg, bz)) - multisignature.AddSignatureFromPubKey(sigs[0], pubkeys[0], pubkeys) + require.False(t, multisigKey.VerifyMultisignature(signBytesFn, multisignature)) + AddSignatureFromPubKey(multisignature, sigs[0], pubkeys[0], pubkeys) // Add second signature manually - multisignature.Sigs = append(multisignature.Sigs, sigs[0]) - require.False(t, multisigKey.VerifyBytes(msg, bz)) + multisignature.Signatures = append(multisignature.Signatures, sigs[0]) + require.False(t, multisigKey.VerifyMultisignature(signBytesFn, multisignature)) } // TODO: Fully replace this test with table driven tests func TestMultiSigPubKeyEquality(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) - multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) - var unmarshalledMultisig PubKey + multisigKey := multisig.NewPubKeyMultisigThreshold(2, pubkeys) + var unmarshalledMultisig ThresholdMultisigPubKey cdc.MustUnmarshalBinaryBare(multisigKey.Bytes(), &unmarshalledMultisig) require.True(t, multisigKey.Equals(unmarshalledMultisig)) @@ -139,26 +141,26 @@ func TestMultiSigPubKeyEquality(t *testing.T) { copy(pubkeysCpy, pubkeys) pubkeysCpy[4] = pubkeys[3] pubkeysCpy[3] = pubkeys[4] - multisigKey2 := NewPubKeyMultisigThreshold(2, pubkeysCpy) + multisigKey2 := multisig.NewPubKeyMultisigThreshold(2, pubkeysCpy) require.False(t, multisigKey.Equals(multisigKey2)) } func TestAddress(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) - multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) + multisigKey := multisig.NewPubKeyMultisigThreshold(2, pubkeys) require.Len(t, multisigKey.Address().Bytes(), 20) } func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) - multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) + multisigKey := multisig.NewPubKeyMultisigThreshold(2, pubkeys) ab, err := cdc.MarshalBinaryLengthPrefixed(multisigKey) require.NoError(t, err) - // like other crypto.Pubkey implementations (e.g. ed25519.PubKey), - // PubKey should be deserializable into a crypto.PubKey: + // like other crypto.Pubkey implementations (e.g. ed25519.ThresholdMultisigPubKey), + // ThresholdMultisigPubKey should be deserializable into a crypto.ThresholdMultisigPubKey: var pubKey crypto.PubKey err = cdc.UnmarshalBinaryLengthPrefixed(ab, &pubKey) require.NoError(t, err) @@ -166,9 +168,9 @@ func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) { require.Equal(t, multisigKey, pubKey) } -func generatePubKeysAndSignatures(n int, msg []byte) (pubkeys []crypto.PubKey, signatures [][]byte) { +func generatePubKeysAndSignatures(n int, msg []byte) (pubkeys []crypto.PubKey, signatures []types.SignatureV2) { pubkeys = make([]crypto.PubKey, n) - signatures = make([][]byte, n) + signatures = make([]types.SignatureV2, n) for i := 0; i < n; i++ { var privkey crypto.PrivKey switch rand.Int63() % 3 { @@ -180,7 +182,8 @@ func generatePubKeysAndSignatures(n int, msg []byte) (pubkeys []crypto.PubKey, s privkey = sr25519.GenPrivKey() } pubkeys[i] = privkey.PubKey() - signatures[i], _ = privkey.Sign(msg) + sig, _ := privkey.Sign(msg) + signatures[i] = &types.SingleSignature{Signature: sig} } return } diff --git a/crypto/types/codec.go b/crypto/types/codec.go index 5ad14dbe278a..1230a5a02dca 100644 --- a/crypto/types/codec.go +++ b/crypto/types/codec.go @@ -1,6 +1,8 @@ package types -import "github.com/tendermint/tendermint/crypto" +import ( + "github.com/tendermint/tendermint/crypto" +) type PublicKeyCodec interface { Decode(key *PublicKey) (crypto.PubKey, error) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 2772de40ae5c..248c33370398 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -4,6 +4,7 @@ package server import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -127,7 +128,7 @@ against which this app has been compiled. func printlnJSON(v interface{}) error { cdc := codec.New() - codec.RegisterCrypto(cdc) + legacy_global.RegisterCrypto(cdc) marshalled, err := cdc.MarshalJSON(v) if err != nil { return err diff --git a/std/codec.go b/std/codec.go index 7c04eedf59e3..791919eaa436 100644 --- a/std/codec.go +++ b/std/codec.go @@ -2,6 +2,7 @@ package std import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -25,7 +26,7 @@ func MakeCodec(bm module.BasicManager) *codec.Codec { func RegisterCodec(cdc *codec.Codec) { sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) + legacy_global.RegisterCrypto(cdc) vesting.RegisterCodec(cdc) } diff --git a/types/rest/rest.go b/types/rest/rest.go index 8395c983c32e..bd2c7261896b 100644 --- a/types/rest/rest.go +++ b/types/rest/rest.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "io/ioutil" "net/http" "net/url" @@ -180,7 +181,7 @@ func CheckNotFoundError(w http.ResponseWriter, err error) bool { func WriteErrorResponse(w http.ResponseWriter, status int, err string) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) - _, _ = w.Write(codec.Cdc.MustMarshalJSON(NewErrorResponse(0, err))) + _, _ = w.Write(legacy_global.Cdc.MustMarshalJSON(NewErrorResponse(0, err))) } // WriteSimulationResponse prepares and writes an HTTP diff --git a/types/rest/rest_test.go b/types/rest/rest_test.go index 90988c4ef702..b5cd3d73b6d4 100644 --- a/types/rest/rest_test.go +++ b/types/rest/rest_test.go @@ -2,6 +2,7 @@ package rest_test import ( "errors" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "io" "io/ioutil" "net/http" @@ -199,7 +200,7 @@ func TestProcessPostResponse(t *testing.T) { acc := mockAccount{addr, coins, pubKey, accNumber, sequence} cdc := codec.New() - codec.RegisterCrypto(cdc) + legacy_global.RegisterCrypto(cdc) cdc.RegisterConcrete(&mockAccount{}, "cosmos-sdk/mockAccount", nil) ctx = ctx.WithCodec(cdc) diff --git a/types/result.go b/types/result.go index 0bb58d5af946..1708af6b0c84 100644 --- a/types/result.go +++ b/types/result.go @@ -4,17 +4,19 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/codec" "math" "strings" yaml "gopkg.in/yaml.v2" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" ctypes "github.com/tendermint/tendermint/rpc/core/types" ) +var cdc = codec.New() + func (gi GasInfo) String() string { bz, _ := yaml.Marshal(gi) return string(bz) @@ -48,7 +50,7 @@ func NewABCIMessageLog(i uint16, log string, events Events) ABCIMessageLog { // String implements the fmt.Stringer interface for the ABCIMessageLogs type. func (logs ABCIMessageLogs) String() (str string) { if logs != nil { - raw, err := codec.Cdc.MarshalJSON(logs) + raw, err := cdc.MarshalJSON(logs) if err == nil { str = string(raw) } diff --git a/types/result_test.go b/types/result_test.go index 56823eee6f91..3c5f97ff36a8 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -12,7 +12,6 @@ import ( "github.com/tendermint/tendermint/libs/bytes" ctypes "github.com/tendermint/tendermint/rpc/core/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -33,7 +32,7 @@ func TestABCIMessageLog(t *testing.T) { msgLog := sdk.NewABCIMessageLog(0, "", events) msgLogs := sdk.ABCIMessageLogs{msgLog} - bz, err := codec.Cdc.MarshalJSON(msgLogs) + bz, err := cdc.MarshalJSON(msgLogs) require.NoError(t, err) require.Equal(t, string(bz), msgLogs.String()) } diff --git a/types/tx/signature.go b/types/tx/signature.go new file mode 100644 index 000000000000..28d918ac6e66 --- /dev/null +++ b/types/tx/signature.go @@ -0,0 +1,57 @@ +package types + +import "github.com/cosmos/cosmos-sdk/crypto/types" + +type SignatureV2 interface { + isSignatureV2() +} + +type SingleSignature struct { + SignMode SignMode + Signature []byte +} + +type MultiSignature struct { + BitArray *types.CompactBitArray + Signatures []SignatureV2 +} + +var _, _ SignatureV2 = &SingleSignature{}, &MultiSignature{} + +func (m *SingleSignature) isSignatureV2() {} +func (m *MultiSignature) isSignatureV2() {} + +func ModeInfoToSignatureV2(modeInfo *ModeInfo, sig []byte) (SignatureV2, error) { + switch modeInfo := modeInfo.Sum.(type) { + case *ModeInfo_Single_: + return &SingleSignature{ + SignMode: modeInfo.Single.Mode, + Signature: sig, + }, nil + + case *ModeInfo_Multi_: + multi := modeInfo.Multi + + sigs, err := types.DecodeMultisignatures(sig) + if err != nil { + return nil, err + } + + sigv2s := make([]SignatureV2, len(sigs)) + for i, mi := range multi.ModeInfos { + sigv2s[i], err = ModeInfoToSignatureV2(mi, sigs[i]) + if err != nil { + return nil, err + } + } + + return &MultiSignature{ + BitArray: multi.Bitarray, + Signatures: sigv2s, + }, nil + + default: + panic("unexpected case") + } +} + diff --git a/types/tx/tx.go b/types/tx/tx.go index b8b63af5106d..e5e6066a89b2 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -3,8 +3,6 @@ package types import ( "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/crypto/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -177,59 +175,6 @@ type SigTx interface { GetSignaturesV2() ([]SignatureV2, error) } -type SignatureV2 interface { - isSignatureV2() -} - -type SingleSignature struct { - SignMode SignMode - Signature []byte -} - -type MultiSignature struct { - BitArray *types.CompactBitArray - Signatures []SignatureV2 -} - -var _, _ SignatureV2 = SingleSignature{}, MultiSignature{} - -func (m SingleSignature) isSignatureV2() {} -func (m MultiSignature) isSignatureV2() {} - -func ModeInfoToSignatureV2(modeInfo *ModeInfo, sig []byte) (SignatureV2, error) { - switch modeInfo := modeInfo.Sum.(type) { - case *ModeInfo_Single_: - return SingleSignature{ - SignMode: modeInfo.Single.Mode, - Signature: sig, - }, nil - - case *ModeInfo_Multi_: - multi := modeInfo.Multi - - sigs, err := types.DecodeMultisignatures(sig) - if err != nil { - return nil, err - } - - sigv2s := make([]SignatureV2, len(sigs)) - for i, mi := range multi.ModeInfos { - sigv2s[i], err = ModeInfoToSignatureV2(mi, sigs[i]) - if err != nil { - return nil, err - } - } - - return MultiSignature{ - BitArray: multi.Bitarray, - Signatures: sigv2s, - }, nil - - default: - panic("unexpected case") - } -} - func (m *Tx) GetSignaturesV2() ([]SignatureV2, error) { signerInfos := m.AuthInfo.SignerInfos sigs := m.Signatures diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index eefa9d33a66b..1ef20c3c16d6 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,10 +1,10 @@ package ante import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types3 "github.com/cosmos/cosmos-sdk/types/tx" @@ -126,7 +126,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim PubKey: pubkey.Bytes(), } - sigBz := codec.Cdc.MustMarshalBinaryBare(simSig) + sigBz := legacy_global.Cdc.MustMarshalBinaryBare(simSig) cost := sdk.Gas(len(sigBz) + 6) // If the pubkey is a multi-signature pubkey, then we estimate for the maximum diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 6e9836362ea0..d0938e455ab5 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -3,6 +3,7 @@ package ante import ( "bytes" "encoding/hex" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" types3 "github.com/cosmos/cosmos-sdk/types/tx" @@ -13,7 +14,6 @@ import ( "github.com/tendermint/tendermint/crypto/multisig" "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -305,7 +305,7 @@ func DefaultSigVerificationGasConsumer( case multisig.PubKeyMultisigThreshold: var multisignature multisig.Multisignature - codec.Cdc.MustUnmarshalBinaryBare(sig, &multisignature) + legacy_global.Cdc.MustUnmarshalBinaryBare(sig, &multisignature) ConsumeMultisignatureVerificationGas(meter, multisignature, pubkey, params) return nil diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 0c6320a8d25b..0c40522ca844 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "errors" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "io/ioutil" "os" "testing" @@ -158,7 +159,7 @@ func writeToNewTempFile(t *testing.T, data string) *os.File { func makeCodec() *codec.Codec { var cdc = codec.New() sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) + legacy_global.RegisterCrypto(cdc) authtypes.RegisterCodec(cdc) cdc.RegisterConcrete(sdk.TestMsg{}, "cosmos-sdk/Test", nil) return cdc diff --git a/x/auth/legacy/v0_39/migrate_test.go b/x/auth/legacy/v0_39/migrate_test.go index 027db2e89602..6ee6cea21b62 100644 --- a/x/auth/legacy/v0_39/migrate_test.go +++ b/x/auth/legacy/v0_39/migrate_test.go @@ -1,6 +1,7 @@ package v039_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "testing" "github.com/cosmos/cosmos-sdk/codec" @@ -14,7 +15,7 @@ import ( func TestMigrate(t *testing.T) { v039Codec := codec.New() - codec.RegisterCrypto(v039Codec) + legacy_global.RegisterCrypto(v039Codec) v038auth.RegisterCodec(v039Codec) coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 071ef3249504..48638a528123 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -41,5 +42,5 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index f0014bdb3b15..499074b58832 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -4,17 +4,18 @@ import ( "encoding/json" "fmt" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - types2 "github.com/cosmos/cosmos-sdk/crypto/types" - types "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" yaml "gopkg.in/yaml.v2" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" + types2 "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + types "github.com/cosmos/cosmos-sdk/types/tx" ) // Deprecated: StdFee includes the amount of coins paid in fees and the maximum @@ -49,7 +50,7 @@ func (fee StdFee) Bytes() []byte { fee.Amount = sdk.NewCoins() } - bz, err := codec.Cdc.MarshalJSON(fee) + bz, err := legacy_global.Cdc.MarshalJSON(fee) if err != nil { panic(err) } @@ -280,21 +281,22 @@ func (tx StdTx) FeePayer() sdk.AccAddress { func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureV2 { switch pk := pk.(type) { - case multisig.PubKeyMultisigThreshold: + case multisig2.MultisigPubKey: var multisignature multisig.Multisignature - codec.Cdc.MustUnmarshalBinaryBare(sig, &multisignature) + legacy_global.Cdc.MustUnmarshalBinaryBare(sig, &multisignature) sigs := make([]types.SignatureV2, len(multisignature.Sigs)) size := multisignature.BitArray.Size() sigIndex := 0 + pubKeys := pk.GetPubKeys() for i := 0; i < size; i++ { if multisignature.BitArray.GetIndex(i) { - sigs[i] = stdSignatureToSignatureV2(pk.PubKeys[i], multisignature.Sigs[sigIndex]) + sigs[i] = stdSignatureToSignatureV2(pubKeys[i], multisignature.Sigs[sigIndex]) sigIndex++ } } - return types.MultiSignature{ + return &types.MultiSignature{ BitArray: &types2.CompactBitArray{ ExtraBitsStored: uint32(multisignature.BitArray.ExtraBitsStored), Elems: multisignature.BitArray.Elems, @@ -302,7 +304,7 @@ func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureV2 { Signatures: sigs, } default: - return types.SingleSignature{ + return &types.SingleSignature{ SignMode: types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, Signature: sig, } @@ -349,7 +351,7 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) } - bz, err := codec.Cdc.MarshalJSON(StdSignDoc{ + bz, err := legacy_global.Cdc.MarshalJSON(StdSignDoc{ AccountNumber: accnum, ChainID: chainID, Fee: json.RawMessage(fee.Bytes()), diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index b032499b3492..3e00ab10acef 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -2,9 +2,9 @@ package types import ( "errors" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "time" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" @@ -241,13 +241,13 @@ func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { EndTime: bva.EndTime, } - return codec.Cdc.MarshalJSON(alias) + return legacy_global.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a BaseVestingAccount. func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error { var alias vestingAccountJSON - if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } @@ -398,13 +398,13 @@ func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { StartTime: cva.StartTime, } - return codec.Cdc.MarshalJSON(alias) + return legacy_global.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a ContinuousVestingAccount. func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error { var alias vestingAccountJSON - if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } @@ -589,13 +589,13 @@ func (pva PeriodicVestingAccount) MarshalJSON() ([]byte, error) { VestingPeriods: pva.VestingPeriods, } - return codec.Cdc.MarshalJSON(alias) + return legacy_global.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a PeriodicVestingAccount. func (pva *PeriodicVestingAccount) UnmarshalJSON(bz []byte) error { var alias vestingAccountJSON - if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } @@ -692,13 +692,13 @@ func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { EndTime: dva.EndTime, } - return codec.Cdc.MarshalJSON(alias) + return legacy_global.Cdc.MarshalJSON(alias) } // UnmarshalJSON unmarshals raw JSON bytes into a DelayedVestingAccount. func (dva *DelayedVestingAccount) UnmarshalJSON(bz []byte) error { var alias vestingAccountJSON - if err := codec.Cdc.UnmarshalJSON(bz, &alias); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(bz, &alias); err != nil { return err } diff --git a/x/bank/legacy/v0_39/migrate_test.go b/x/bank/legacy/v0_39/migrate_test.go index ae51134d47c1..83c82598a614 100644 --- a/x/bank/legacy/v0_39/migrate_test.go +++ b/x/bank/legacy/v0_39/migrate_test.go @@ -1,6 +1,7 @@ package v039_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "testing" "github.com/cosmos/cosmos-sdk/codec" @@ -14,7 +15,7 @@ import ( func TestMigrate(t *testing.T) { v039Codec := codec.New() - codec.RegisterCrypto(v039Codec) + legacy_global.RegisterCrypto(v039Codec) v038auth.RegisterCodec(v039Codec) coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 69a181382453..aeefb695dd95 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/exported" @@ -43,6 +44,6 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 5f319bf00b29..00c4107c4e79 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -25,6 +26,6 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index e3b2bf9e37db..97a05f36eebd 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" @@ -45,6 +46,6 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 3a23356a1f47..e2a30ec589cb 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence/exported" @@ -38,6 +39,6 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 70b20ccc4068..c3ce90d3092f 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -2,6 +2,7 @@ package cli import ( "bytes" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "io" "os" "testing" @@ -141,6 +142,6 @@ func TestInitNodeValidatorFiles(t *testing.T) { func makeCodec() *codec.Codec { var cdc = codec.New() sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) + legacy_global.RegisterCrypto(cdc) return cdc } diff --git a/x/genutil/legacy/v0_36/migrate.go b/x/genutil/legacy/v0_36/migrate.go index 59c1c4491e6f..c68be1e90037 100644 --- a/x/genutil/legacy/v0_36/migrate.go +++ b/x/genutil/legacy/v0_36/migrate.go @@ -2,6 +2,7 @@ package v036 import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34" v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36" v036bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_36" @@ -19,11 +20,11 @@ import ( // Migrate migrates exported state from v0.34 to a v0.36 genesis state. func Migrate(appState genutil.AppMap) genutil.AppMap { v034Codec := codec.New() - codec.RegisterCrypto(v034Codec) + legacy_global.RegisterCrypto(v034Codec) v034gov.RegisterCodec(v034Codec) v036Codec := codec.New() - codec.RegisterCrypto(v036Codec) + legacy_global.RegisterCrypto(v036Codec) v036gov.RegisterCodec(v036Codec) // migrate genesis accounts state diff --git a/x/genutil/legacy/v0_38/migrate.go b/x/genutil/legacy/v0_38/migrate.go index 59ba4772705f..556b7929b1a5 100644 --- a/x/genutil/legacy/v0_38/migrate.go +++ b/x/genutil/legacy/v0_38/migrate.go @@ -2,6 +2,7 @@ package v038 import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36" v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38" v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36" @@ -15,10 +16,10 @@ import ( // Migrate migrates exported state from v0.36/v0.37 to a v0.38 genesis state. func Migrate(appState genutil.AppMap) genutil.AppMap { v036Codec := codec.New() - codec.RegisterCrypto(v036Codec) + legacy_global.RegisterCrypto(v036Codec) v038Codec := codec.New() - codec.RegisterCrypto(v038Codec) + legacy_global.RegisterCrypto(v038Codec) v038auth.RegisterCodec(v038Codec) if appState[v036genaccounts.ModuleName] != nil { diff --git a/x/genutil/legacy/v0_39/migrate.go b/x/genutil/legacy/v0_39/migrate.go index aea5ccd3f91e..d0fd3b13136e 100644 --- a/x/genutil/legacy/v0_39/migrate.go +++ b/x/genutil/legacy/v0_39/migrate.go @@ -2,6 +2,7 @@ package v039 import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38" v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39" v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38" @@ -11,11 +12,11 @@ import ( func Migrate(appState genutil.AppMap) genutil.AppMap { v038Codec := codec.New() - codec.RegisterCrypto(v038Codec) + legacy_global.RegisterCrypto(v038Codec) v038auth.RegisterCodec(v038Codec) v039Codec := codec.New() - codec.RegisterCrypto(v039Codec) + legacy_global.RegisterCrypto(v039Codec) v038auth.RegisterCodec(v039Codec) // remove balances from existing accounts diff --git a/x/genutil/types/codec.go b/x/genutil/types/codec.go index 624be93d138f..4410571b1d81 100644 --- a/x/genutil/types/codec.go +++ b/x/genutil/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -17,6 +18,6 @@ func init() { stakingtypes.RegisterCodec(ModuleCdc) authtypes.RegisterCodec(ModuleCdc) sdk.RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) + legacy_global.RegisterCrypto(ModuleCdc) ModuleCdc.Seal() } diff --git a/x/gov/types/codec.go b/x/gov/types/codec.go index ee53c71c4582..12de9adc03f8 100644 --- a/x/gov/types/codec.go +++ b/x/gov/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -53,5 +54,5 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) } diff --git a/x/ibc/07-tendermint/tendermint_test.go b/x/ibc/07-tendermint/tendermint_test.go index 9792d3034bc4..55c7771f0743 100644 --- a/x/ibc/07-tendermint/tendermint_test.go +++ b/x/ibc/07-tendermint/tendermint_test.go @@ -1,6 +1,7 @@ package tendermint_test import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "testing" "time" @@ -35,7 +36,7 @@ type TendermintTestSuite struct { func (suite *TendermintTestSuite) SetupTest() { suite.cdc = codec.New() - codec.RegisterCrypto(suite.cdc) + legacy_global.RegisterCrypto(suite.cdc) ibctmtypes.RegisterCodec(suite.cdc) commitmenttypes.RegisterCodec(suite.cdc) diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go index 974091a97928..e5baba9c48c1 100644 --- a/x/mint/types/codec.go +++ b/x/mint/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" ) var ( @@ -9,6 +10,6 @@ var ( ) func init() { - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/params/keeper/querier.go b/x/params/keeper/querier.go index a898bacc6d42..1f83833c5f73 100644 --- a/x/params/keeper/querier.go +++ b/x/params/keeper/querier.go @@ -1,6 +1,7 @@ package keeper import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/codec" @@ -26,7 +27,7 @@ func NewQuerier(k Keeper) sdk.Querier { func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { var params types.QuerySubspaceParams - if err := codec.Cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -38,7 +39,7 @@ func queryParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, erro rawValue := ss.GetRaw(ctx, []byte(params.Key)) resp := types.NewSubspaceParamsResponse(params.Subspace, params.Key, string(rawValue)) - bz, err := codec.MarshalJSONIndent(codec.Cdc, resp) + bz, err := codec.MarshalJSONIndent(legacy_global.Cdc, resp) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index dae5a5ddda30..db20ed1e8feb 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -31,6 +32,6 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/staking/legacy/v0_34/types.go b/x/staking/legacy/v0_34/types.go index 013edb792d9e..ce866e4129dc 100644 --- a/x/staking/legacy/v0_34/types.go +++ b/x/staking/legacy/v0_34/types.go @@ -3,11 +3,11 @@ package v0_34 import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "time" "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -131,7 +131,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { return nil, err } - return codec.Cdc.MarshalJSON(bechValidator{ + return legacy_global.Cdc.MarshalJSON(bechValidator{ OperatorAddress: v.OperatorAddress, ConsPubKey: bechConsPubKey, Jailed: v.Jailed, @@ -149,7 +149,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the validator from JSON using Bech32 func (v *Validator) UnmarshalJSON(data []byte) error { bv := &bechValidator{} - if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(data, bv); err != nil { return err } consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey) diff --git a/x/staking/legacy/v0_36/types.go b/x/staking/legacy/v0_36/types.go index 246d6b011821..e91a7f917e16 100644 --- a/x/staking/legacy/v0_36/types.go +++ b/x/staking/legacy/v0_36/types.go @@ -3,11 +3,11 @@ package v0_36 import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "time" "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34" ) @@ -94,7 +94,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { return nil, err } - return codec.Cdc.MarshalJSON(bechValidator{ + return legacy_global.Cdc.MarshalJSON(bechValidator{ OperatorAddress: v.OperatorAddress, ConsPubKey: bechConsPubKey, Jailed: v.Jailed, @@ -111,7 +111,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { func (v *Validator) UnmarshalJSON(data []byte) error { bv := &bechValidator{} - if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(data, bv); err != nil { return err } consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey) diff --git a/x/staking/legacy/v0_38/types.go b/x/staking/legacy/v0_38/types.go index b3c27e8b47cd..05ebd0843715 100644 --- a/x/staking/legacy/v0_38/types.go +++ b/x/staking/legacy/v0_38/types.go @@ -3,11 +3,11 @@ package v0_38 import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "time" "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34" v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36" @@ -105,7 +105,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { return nil, err } - return codec.Cdc.MarshalJSON(bechValidator{ + return legacy_global.Cdc.MarshalJSON(bechValidator{ OperatorAddress: v.OperatorAddress, ConsPubKey: bechConsPubKey, Jailed: v.Jailed, @@ -123,7 +123,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals the validator from JSON using Bech32 func (v *Validator) UnmarshalJSON(data []byte) error { bv := &bechValidator{} - if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil { + if err := legacy_global.Cdc.UnmarshalJSON(data, bv); err != nil { return err } consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 593dcc243ff6..1551e1fbf22e 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -2,6 +2,7 @@ package simulation_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "testing" "time" @@ -26,7 +27,7 @@ var ( func makeTestCodec() (cdc *codec.Codec) { cdc = codec.New() sdk.RegisterCodec(cdc) - codec.RegisterCrypto(cdc) + legacy_global.RegisterCrypto(cdc) types.RegisterCodec(cdc) return } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 5d0c8a7d7219..29e576f788b8 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -40,6 +41,6 @@ var ( func init() { RegisterCodec(amino) - codec.RegisterCrypto(amino) + legacy_global.RegisterCrypto(amino) amino.Seal() } diff --git a/x/staking/types/validator_test.go b/x/staking/types/validator_test.go index 54e0c7ebb639..6982943db069 100644 --- a/x/staking/types/validator_test.go +++ b/x/staking/types/validator_test.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec/legacy_global" "math/rand" "reflect" "sort" @@ -11,7 +12,6 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" tmtypes "github.com/tendermint/tendermint/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -230,12 +230,12 @@ func TestPossibleOverflow(t *testing.T) { func TestValidatorMarshalUnmarshalJSON(t *testing.T) { validator := NewValidator(valAddr1, pk1, Description{}) - js, err := codec.Cdc.MarshalJSON(validator) + js, err := legacy_global.Cdc.MarshalJSON(validator) require.NoError(t, err) require.NotEmpty(t, js) require.Contains(t, string(js), "\"consensus_pubkey\":\"cosmosvalconspu") got := &Validator{} - err = codec.Cdc.UnmarshalJSON(js, got) + err = legacy_global.Cdc.UnmarshalJSON(js, got) assert.NoError(t, err) assert.Equal(t, validator, *got) } From da98515b8822422cde4372a0f5f9c7b4c9320957 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 28 May 2020 18:43:30 -0400 Subject: [PATCH 45/54] Fix build --- tests/cli/helpers.go | 6 +- types/tx/mode_handler.go | 2 +- types/tx/signing/handler_map.go | 4 +- x/auth/ante/ante.go | 4 +- x/auth/ante/sigverify_proto.go | 41 ++-- x/auth/client/cli/tx_sign.go | 112 +++++------ x/auth/client/cli/validate_sigs.go | 259 ++++++++++++------------ x/auth/client/tx.go | 32 +-- x/auth/module.go | 2 +- x/genutil/client/cli/gentx.go | 309 ++++++++++++++--------------- 10 files changed, 371 insertions(+), 400 deletions(-) diff --git a/tests/cli/helpers.go b/tests/cli/helpers.go index f7989a59d3e4..6e0cc03474e7 100644 --- a/tests/cli/helpers.go +++ b/tests/cli/helpers.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/cosmos/cosmos-sdk/x/auth/ante/types" + tx "github.com/cosmos/cosmos-sdk/types/tx" "github.com/stretchr/testify/require" @@ -192,9 +192,7 @@ func AddFlags(cmd string, flags []string) string { } type CLITx interface { - types.SigTx - types.FeeTx - types.TxWithMemo + tx.SigTx SetMemo(string) } diff --git a/types/tx/mode_handler.go b/types/tx/mode_handler.go index 3efef71fc8ba..d8b9342f9602 100644 --- a/types/tx/mode_handler.go +++ b/types/tx/mode_handler.go @@ -7,7 +7,7 @@ import ( ) type SigningData struct { - ModeInfo *ModeInfo_Single + Mode SignMode PublicKey crypto.PubKey ChainID string AccountNumber uint64 diff --git a/types/tx/signing/handler_map.go b/types/tx/signing/handler_map.go index 1053ce9612cb..13458dd8fd00 100644 --- a/types/tx/signing/handler_map.go +++ b/types/tx/signing/handler_map.go @@ -39,9 +39,9 @@ func (h HandlerMap) Modes() []types.SignMode { } func (h HandlerMap) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { - handler, found := h.signModeHandlers[data.ModeInfo.Mode] + handler, found := h.signModeHandlers[data.Mode] if !found { - return nil, fmt.Errorf("can't verify sign mode %s", data.ModeInfo.Mode.String()) + return nil, fmt.Errorf("can't verify sign mode %s", data.Mode.String()) } return handler.GetSignBytes(data, tx) } diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index a70c1cfb4416..956eb6d4e505 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -49,10 +49,10 @@ func NewProtoAnteHandler( NewValidateSigCountDecorator(ak), NewDeductFeeDecorator(ak, bankKeeper), NewSigGasConsumeDecorator(ak, sigGasConsumer), - NewProtoSigVerificationDecorator(ak, []types2.SignModeHandler{ + NewProtoSigVerificationDecorator(ak, signing.NewHandlerMap([]types2.SignModeHandler{ signing.DirectModeHandler{}, types.LegacyAminoJSONHandler{}, - }), + })), NewIncrementSequenceDecorator(ak), ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator ) diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 8542d1ab4e5c..d42e03b40525 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -2,8 +2,6 @@ package ante import ( "github.com/cosmos/cosmos-sdk/crypto/multisig" - types2 "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" @@ -34,7 +32,10 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. - sigs := sigTx.GetSignatures() + sigs, err := sigTx.GetSignaturesV2() + if err != nil { + return ctx, err + } // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. @@ -54,48 +55,34 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, signerAccs[i] = signerAcc - signerInfo := sigTx.GetAuthInfo().SignerInfos[i] - // retrieve pubkey pubKey := signerAccs[i].GetPubKey() if !simulate && pubKey == nil { return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") } - switch mi := signerInfo.ModeInfo.Sum.(type) { - case *types.ModeInfo_Single_: - single := mi.Single - - signBytes, err := svd.getSignBytesSingle(ctx, single, signerAcc, sigTx) + switch sig := sig.(type) { + case *types.SingleSignature: + signBytes, err := svd.getSignBytesSingle(ctx, sig.SignMode, signerAcc, sigTx) if err != nil { return ctx, err } // verify signature - if !simulate && !pubKey.VerifyBytes(signBytes, sig) { + if !simulate && !pubKey.VerifyBytes(signBytes, sig.Signature) { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") } - case *types.ModeInfo_Multi_: + case *types.MultiSignature: multisigPubKey, ok := pubKey.(multisig.MultisigPubKey) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "key is not a multisig pubkey, but ModeInfo.Multi is used") } if !simulate { - multiSigs, err := types2.DecodeMultisignatures(sig) - if err != nil { - return ctx, sdkerrors.Wrap(err, "cannot decode MultiSignature") - } - - decodedMultisig := multisig.DecodedMultisignature{ - ModeInfo: mi.Multi, - Signatures: multiSigs, - } - if !multisigPubKey.VerifyMultisignature( - func(single *types.ModeInfo_Single) ([]byte, error) { - return svd.getSignBytesSingle(ctx, single, signerAcc, sigTx) - }, decodedMultisig, + func(mode types.SignMode) ([]byte, error) { + return svd.getSignBytesSingle(ctx, mode, signerAcc, sigTx) + }, sig, ) { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") } @@ -108,7 +95,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return next(ctx, tx, simulate) } -func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, single *types.ModeInfo_Single, signerAcc auth.AccountI, sigTx types.ProtoTx) ([]byte, error) { +func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, signMode types.SignMode, signerAcc auth.AccountI, sigTx types.ProtoTx) ([]byte, error) { verifier := svd.handler genesis := ctx.BlockHeight() == 0 var accNum uint64 @@ -116,7 +103,7 @@ func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, sin accNum = signerAcc.GetAccountNumber() } data := types.SigningData{ - ModeInfo: single, + Mode: signMode, PublicKey: signerAcc.GetPubKey(), ChainID: ctx.ChainID(), AccountNumber: accNum, diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index ceae5a9db8fb..49097b10c344 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -1,17 +1,12 @@ package cli import ( - "fmt" - "os" - "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -73,59 +68,60 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } func makeSignCmd(cdc context.CLIContext) func(cmd *cobra.Command, args []string) error { - return func(cmd *cobra.Command, args []string) error { - cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) - if err != nil { - return err - } - - // if --signature-only is on, then override --append - var newTx types.StdTx - generateSignatureOnly := viper.GetBool(flagSigOnly) - multisigAddrStr := viper.GetString(flagMultisig) - - if multisigAddrStr != "" { - var multisigAddr sdk.AccAddress - - multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr) - if err != nil { - return err - } - newTx, err = client.SignStdTxWithSignerAddress( - txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, cliCtx.Offline, - ) - generateSignatureOnly = true - } else { - appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly - newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, cliCtx.Offline) - } - - if err != nil { - return err - } - - json, err := getSignatureJSON(cliCtx.JSONMarshaler, newTx, cliCtx.Indent, generateSignatureOnly) - if err != nil { - return err - } - - if viper.GetString(flagOutfile) == "" { - fmt.Printf("%s\n", json) - return nil - } - - fp, err := os.OpenFile( - viper.GetString(flagOutfile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644, - ) - if err != nil { - return err - } - - defer fp.Close() - fmt.Fprintf(fp, "%s\n", json) - - return nil - } + panic("TODO") + //return func(cmd *cobra.Command, args []string) error { + // cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) + // if err != nil { + // return err + // } + // + // // if --signature-only is on, then override --append + // var newTx types.StdTx + // generateSignatureOnly := viper.GetBool(flagSigOnly) + // multisigAddrStr := viper.GetString(flagMultisig) + // + // if multisigAddrStr != "" { + // var multisigAddr sdk.AccAddress + // + // multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr) + // if err != nil { + // return err + // } + // newTx, err = client.SignStdTxWithSignerAddress( + // txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, cliCtx.Offline, + // ) + // generateSignatureOnly = true + // } else { + // appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly + // newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, cliCtx.Offline) + // } + // + // if err != nil { + // return err + // } + // + // json, err := getSignatureJSON(cliCtx.JSONMarshaler, newTx, cliCtx.Indent, generateSignatureOnly) + // if err != nil { + // return err + // } + // + // if viper.GetString(flagOutfile) == "" { + // fmt.Printf("%s\n", json) + // return nil + // } + // + // fp, err := os.OpenFile( + // viper.GetString(flagOutfile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644, + // ) + // if err != nil { + // return err + // } + // + // defer fp.Close() + // fmt.Fprintf(fp, "%s\n", json) + // + // return nil + //} } func getSignatureJSON(cdc codec.JSONMarshaler, newTx types.StdTx, indent, generateSignatureOnly bool) ([]byte, error) { diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index ceff68c8c4c9..5d35f74eaf75 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -3,19 +3,13 @@ package cli import ( "bufio" "fmt" - "strings" - - "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/spf13/cobra" - "github.com/tendermint/tendermint/crypto/multisig" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" - txtypes "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/client" ) @@ -60,132 +54,133 @@ func makeValidateSignaturesCmd(cliCtx context.CLIContext) func(cmd *cobra.Comman func printAndValidateSigs( cmd *cobra.Command, cliCtx context.CLIContext, chainID string, tx sdk.Tx, offline bool, ) bool { - sigTx := tx.(txtypes.SigTx) - signModeHandler := cliCtx.TxGenerator.SignModeHandler() - - cmd.Println("Signers:") - signers := sigTx.GetSigners() - - for i, signer := range signers { - cmd.Printf(" %v: %v\n", i, signer.String()) - } - - success := true - sigs := sigTx.GetSignatures() - pubKeys := sigTx.GetPubKeys() - cmd.Println("") - cmd.Println("Signatures:") - - if len(sigs) != len(signers) { - success = false - } - - for i, sig := range sigs { - var ( - pubKey = pubKeys[i] - multiSigHeader string - multiSigMsg string - sigAddr = sdk.AccAddress(pubKey.Address()) - sigSanity = "OK" - ) - - if i >= len(signers) || !sigAddr.Equals(signers[i]) { - sigSanity = "ERROR: signature does not match its respective signer" - success = false - } - - // Validate the actual signature over the transaction bytes since we can - // reach out to a full node to query accounts. - if !offline && success { - accNum, accSeq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, sigAddr) - if err != nil { - cmd.Printf("failed to get account: %s\n", sigAddr) - return false - } - - signingData := txtypes.SigningData{ - PublicKey: pubKey, - ChainID: chainID, - AccountNumber: accNum, - AccountSequence: accSeq, - } - - if protoTx, ok := tx.(txtypes.ProtoTx); ok { - modeInfo := protoTx.GetAuthInfo().SignerInfos[i].ModeInfo - switch modeInfo := modeInfo.Sum.(type) { - case *txtypes.ModeInfo_Single_: - signingData.ModeInfo = modeInfo.Single - sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) - if err != nil { - sigSanity = "ERROR: can't get sign bytes" - success = false - } - - if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { - sigSanity = "ERROR: signature invalid" - success = false - } - case *txtypes.ModeInfo_Multi_: - multisigs, err := types.DecodeMultisignatures(sig) - if err != nil { - sigSanity = "ERROR: can't decoded multisignature" - success = false - } - - if multiPK, ok := pubKey.(multisig2.MultisigPubKey); ok { - multiPK.VerifyMultisignature(func(single *txtypes.ModeInfo_Single) ([]byte, error) { - signingData.ModeInfo = single - return signModeHandler.GetSignBytes(signingData, tx) - }, multisig2.DecodedMultisignature{ - ModeInfo: modeInfo.Multi, - Signatures: multisigs, - }) - } - default: - sigSanity = "ERROR: unexpected ModeInfo" - success = false - } - } else { - sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) - if err != nil { - sigSanity = "ERROR: can't get sign bytes" - success = false - } - - if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { - sigSanity = "ERROR: signature invalid" - success = false - } - } - } - - multiPK, ok := pubKey.(multisig.PubKeyMultisigThreshold) - if ok { - var multiSig multisig.Multisignature - - panic("TODO: update this:") - cliCtx.Codec.MustUnmarshalBinaryBare(sig, &multiSig) - - var b strings.Builder - b.WriteString("\n MultiSig Signatures:\n") - - for i := 0; i < multiSig.BitArray.Size(); i++ { - if multiSig.BitArray.GetIndex(i) { - addr := sdk.AccAddress(multiPK.PubKeys[i].Address().Bytes()) - b.WriteString(fmt.Sprintf(" %d: %s (weight: %d)\n", i, addr, 1)) - } - } - - multiSigHeader = fmt.Sprintf(" [multisig threshold: %d/%d]", multiPK.K, len(multiPK.PubKeys)) - multiSigMsg = b.String() - } - - cmd.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigAddr.String(), sigSanity, multiSigHeader, multiSigMsg) - } - - cmd.Println("") - - return success + //sigTx := tx.(txtypes.SigTx) + //signModeHandler := cliCtx.TxGenerator.SignModeHandler() + // + //cmd.Println("Signers:") + //signers := sigTx.GetSigners() + // + //for i, signer := range signers { + // cmd.Printf(" %v: %v\n", i, signer.String()) + //} + // + //success := true + //sigs := sigTx.GetSignatures() + //pubKeys := sigTx.GetPubKeys() + //cmd.Println("") + //cmd.Println("Signatures:") + // + //if len(sigs) != len(signers) { + // success = false + //} + // + //for i, sig := range sigs { + // var ( + // pubKey = pubKeys[i] + // multiSigHeader string + // multiSigMsg string + // sigAddr = sdk.AccAddress(pubKey.Address()) + // sigSanity = "OK" + // ) + // + // if i >= len(signers) || !sigAddr.Equals(signers[i]) { + // sigSanity = "ERROR: signature does not match its respective signer" + // success = false + // } + // + // // Validate the actual signature over the transaction bytes since we can + // // reach out to a full node to query accounts. + // if !offline && success { + // accNum, accSeq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, sigAddr) + // if err != nil { + // cmd.Printf("failed to get account: %s\n", sigAddr) + // return false + // } + // + // signingData := txtypes.SigningData{ + // PublicKey: pubKey, + // ChainID: chainID, + // AccountNumber: accNum, + // AccountSequence: accSeq, + // } + // + // if protoTx, ok := tx.(txtypes.ProtoTx); ok { + // modeInfo := protoTx.GetAuthInfo().SignerInfos[i].ModeInfo + // switch modeInfo := modeInfo.Sum.(type) { + // case *txtypes.ModeInfo_Single_: + // signingData.ModeInfo = modeInfo.Single + // sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) + // if err != nil { + // sigSanity = "ERROR: can't get sign bytes" + // success = false + // } + // + // if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { + // sigSanity = "ERROR: signature invalid" + // success = false + // } + // case *txtypes.ModeInfo_Multi_: + // multisigs, err := types.DecodeMultisignatures(sig) + // if err != nil { + // sigSanity = "ERROR: can't decoded multisignature" + // success = false + // } + // + // if multiPK, ok := pubKey.(multisig2.MultisigPubKey); ok { + // multiPK.VerifyMultisignature(func(single *txtypes.ModeInfo_Single) ([]byte, error) { + // signingData.ModeInfo = single + // return signModeHandler.GetSignBytes(signingData, tx) + // }, multisig2.DecodedMultisignature{ + // ModeInfo: modeInfo.Multi, + // Signatures: multisigs, + // }) + // } + // default: + // sigSanity = "ERROR: unexpected ModeInfo" + // success = false + // } + // } else { + // sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) + // if err != nil { + // sigSanity = "ERROR: can't get sign bytes" + // success = false + // } + // + // if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { + // sigSanity = "ERROR: signature invalid" + // success = false + // } + // } + // } + // + // multiPK, ok := pubKey.(multisig.PubKeyMultisigThreshold) + // if ok { + // var multiSig multisig.Multisignature + // + // panic("TODO: update this:") + // cliCtx.Codec.MustUnmarshalBinaryBare(sig, &multiSig) + // + // var b strings.Builder + // b.WriteString("\n MultiSig Signatures:\n") + // + // for i := 0; i < multiSig.BitArray.Size(); i++ { + // if multiSig.BitArray.GetIndex(i) { + // addr := sdk.AccAddress(multiPK.PubKeys[i].Address().Bytes()) + // b.WriteString(fmt.Sprintf(" %d: %s (weight: %d)\n", i, addr, 1)) + // } + // } + // + // multiSigHeader = fmt.Sprintf(" [multisig threshold: %d/%d]", multiPK.K, len(multiPK.PubKeys)) + // multiSigMsg = b.String() + // } + // + // cmd.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigAddr.String(), sigSanity, multiSigHeader, multiSigMsg) + //} + // + //cmd.Println("") + // + //return success + panic("TODO") } func readTxAndInitContexts(cliCtx context.CLIContext, cmd *cobra.Command, filename string) (context.CLIContext, tx.Factory, sdk.Tx, error) { diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index f8079fc771b8..330f3d52b665 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -8,6 +8,8 @@ import ( "os" "strings" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/client/tx" "github.com/gogo/protobuf/jsonpb" @@ -191,7 +193,7 @@ func SignStdTx(txBldr tx.Factory, cliCtx context.CLIContext, name string, stdTx addr := info.GetPubKey().Address() // check whether the address is a signer - if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) { + if !isTxSigner(sdk.AccAddress(addr), stdTx.GetTx().(types.SigTx).GetSigners()) { return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) } @@ -202,27 +204,29 @@ func SignStdTx(txBldr tx.Factory, cliCtx context.CLIContext, name string, stdTx } } - return tx.Sign(txBldr, name, "", stdTx) + //return tx.Sign(txBldr, name, "", stdTx) + panic("TODO") } // SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it. // Don't perform online validation or lookups if offline is true, else // populate account and sequence numbers from a foreign account. func SignStdTxWithSignerAddress(txBldr tx.Factory, cliCtx context.CLIContext, addr sdk.AccAddress, name string, stdTx sdk.Tx, offline bool) (signedStdTx authtypes.StdTx, err error) { + panic("TODO") // check whether the address is a signer - if !isTxSigner(addr, stdTx.GetSigners()) { - return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) - } - - if !offline { - txBldr, err = populateAccountFromState(txBldr, cliCtx, addr) - if err != nil { - return signedStdTx, err - } - } - - return txBldr.SignStdTx(name, stdTx, false) + //if !isTxSigner(addr, stdTx.GetSigners()) { + // return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) + //} + // + //if !offline { + // txBldr, err = populateAccountFromState(txBldr, cliCtx, addr) + // if err != nil { + // return signedStdTx, err + // } + //} + // + //return txBldr.SignStdTx(name, stdTx, false) } // Read and decode a StdTx from the given filename. Can pass "-" to read from stdin. diff --git a/x/auth/module.go b/x/auth/module.go index 4b7eac343cf4..321a89abed96 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -64,7 +64,7 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router // GetTxCmd returns the root tx command for the auth module. func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { - return cli.GetTxCmd(ctx.Codec) + return cli.GetTxCmd(ctx) } // GetQueryCmd returns the root query command for the auth module. diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 6b5a799043e9..1d1a95260e76 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -1,34 +1,24 @@ package cli import ( - "bufio" - "bytes" - "encoding/json" "fmt" "io" "io/ioutil" "os" "path/filepath" - "github.com/pkg/errors" "github.com/spf13/cobra" flag "github.com/spf13/pflag" - "github.com/spf13/viper" cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" tmos "github.com/tendermint/tendermint/libs/os" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -43,155 +33,156 @@ type StakingMsgBuildingHelpers interface { // nolint: errcheck func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, smbh StakingMsgBuildingHelpers, genBalIterator types.GenesisBalancesIterator, defaultNodeHome, defaultCLIHome string) *cobra.Command { - ipDefault, _ := server.ExternalIP() - fsCreateValidator, flagNodeID, flagPubKey, flagAmount, defaultsDesc := smbh.CreateValidatorMsgHelpers(ipDefault) - - cmd := &cobra.Command{ - Use: "gentx", - Short: "Generate a genesis tx carrying a self delegation", - Args: cobra.NoArgs, - Long: fmt.Sprintf(`This command is an alias of the 'tx create-validator' command'. - - It creates a genesis transaction to create a validator. - The following default parameters are included: - %s`, defaultsDesc), - - RunE: func(cmd *cobra.Command, args []string) error { - - config := ctx.Config - config.SetRoot(viper.GetString(flags.FlagHome)) - nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(ctx.Config) - if err != nil { - return errors.Wrap(err, "failed to initialize node validator files") - } - - // Read --nodeID, if empty take it from priv_validator.json - if nodeIDString := viper.GetString(flagNodeID); nodeIDString != "" { - nodeID = nodeIDString - } - // Read --pubkey, if empty take it from priv_validator.json - if valPubKeyString := viper.GetString(flagPubKey); valPubKeyString != "" { - valPubKey, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, valPubKeyString) - if err != nil { - return errors.Wrap(err, "failed to get consensus node public key") - } - } - - genDoc, err := tmtypes.GenesisDocFromFile(config.GenesisFile()) - if err != nil { - return errors.Wrapf(err, "failed to read genesis doc file %s", config.GenesisFile()) - } - - var genesisState map[string]json.RawMessage - if err = cdc.UnmarshalJSON(genDoc.AppState, &genesisState); err != nil { - return errors.Wrap(err, "failed to unmarshal genesis state") - } - - if err = mbm.ValidateGenesis(cdc, genesisState); err != nil { - return errors.Wrap(err, "failed to validate genesis state") - } - - inBuf := bufio.NewReader(cmd.InOrStdin()) - kb, err := keyring.New(sdk.KeyringServiceName(), - viper.GetString(flags.FlagKeyringBackend), viper.GetString(flagClientHome), inBuf) - if err != nil { - return errors.Wrap(err, "failed to initialize keybase") - } - - name := viper.GetString(flags.FlagName) - key, err := kb.Key(name) - if err != nil { - return errors.Wrap(err, "failed to read from keybase") - } - - // Set flags for creating gentx - viper.Set(flags.FlagHome, viper.GetString(flagClientHome)) - smbh.PrepareFlagsForTxCreateValidator(config, nodeID, genDoc.ChainID, valPubKey) - - // Fetch the amount of coins staked - amount := viper.GetString(flagAmount) - coins, err := sdk.ParseCoins(amount) - if err != nil { - return errors.Wrap(err, "failed to parse coins") - } - - err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, key.GetAddress(), coins, cdc) - if err != nil { - return errors.Wrap(err, "failed to validate account in genesis") - } - - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - // Set the generate-only flag here after the CLI context has - // been created. This allows the from name/key to be correctly populated. - // - // TODO: Consider removing the manual setting of generate-only in - // favor of a 'gentx' flag in the create-validator command. - viper.Set(flags.FlagGenerateOnly, true) - - // create a 'create-validator' message - txBldr, msg, err := smbh.BuildCreateValidatorMsg(cliCtx, txBldr) - if err != nil { - return errors.Wrap(err, "failed to build create-validator message") - } - - if key.GetType() == keyring.TypeOffline || key.GetType() == keyring.TypeMulti { - cmd.PrintErrln("Offline key passed in. Use `tx sign` command to sign.") - return authclient.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg}) - } - - // write the unsigned transaction to the buffer - w := bytes.NewBuffer([]byte{}) - cliCtx = cliCtx.WithOutput(w) - - if err = authclient.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg}); err != nil { - return errors.Wrap(err, "failed to print unsigned std tx") - } - - // read the transaction - stdTx, err := readUnsignedGenTxFile(cdc, w) - if err != nil { - return errors.Wrap(err, "failed to read unsigned gen tx file") - } - - // sign the transaction and write it to the output file - signedTx, err := authclient.SignStdTx(txBldr, cliCtx, name, stdTx, false, true) - if err != nil { - return errors.Wrap(err, "failed to sign std tx") - } - - // Fetch output file name - outputDocument := viper.GetString(flags.FlagOutputDocument) - if outputDocument == "" { - outputDocument, err = makeOutputFilepath(config.RootDir, nodeID) - if err != nil { - return errors.Wrap(err, "failed to create output file path") - } - } - - if err := writeSignedGenTx(cdc, outputDocument, signedTx); err != nil { - return errors.Wrap(err, "failed to write signed gen tx") - } - - cmd.PrintErrf("Genesis transaction written to %q\n", outputDocument) - return nil - - }, - } - - cmd.Flags().String(flags.FlagHome, defaultNodeHome, "node's home directory") - cmd.Flags().String(flagClientHome, defaultCLIHome, "client's home directory") - cmd.Flags().String(flags.FlagName, "", "name of private key with which to sign the gentx") - cmd.Flags().String(flags.FlagOutputDocument, "", - "write the genesis transaction JSON document to the given file instead of the default location") - cmd.Flags().AddFlagSet(fsCreateValidator) - cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") - viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend)) - - cmd.MarkFlagRequired(flags.FlagName) - - return cmd + panic("TODO") + //ipDefault, _ := server.ExternalIP() + //fsCreateValidator, flagNodeID, flagPubKey, flagAmount, defaultsDesc := smbh.CreateValidatorMsgHelpers(ipDefault) + // + //cmd := &cobra.Command{ + // Use: "gentx", + // Short: "Generate a genesis tx carrying a self delegation", + // Args: cobra.NoArgs, + // Long: fmt.Sprintf(`This command is an alias of the 'tx create-validator' command'. + // + // It creates a genesis transaction to create a validator. + // The following default parameters are included: + // %s`, defaultsDesc), + // + // RunE: func(cmd *cobra.Command, args []string) error { + // + // config := ctx.Config + // config.SetRoot(viper.GetString(flags.FlagHome)) + // nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(ctx.Config) + // if err != nil { + // return errors.Wrap(err, "failed to initialize node validator files") + // } + // + // // Read --nodeID, if empty take it from priv_validator.json + // if nodeIDString := viper.GetString(flagNodeID); nodeIDString != "" { + // nodeID = nodeIDString + // } + // // Read --pubkey, if empty take it from priv_validator.json + // if valPubKeyString := viper.GetString(flagPubKey); valPubKeyString != "" { + // valPubKey, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, valPubKeyString) + // if err != nil { + // return errors.Wrap(err, "failed to get consensus node public key") + // } + // } + // + // genDoc, err := tmtypes.GenesisDocFromFile(config.GenesisFile()) + // if err != nil { + // return errors.Wrapf(err, "failed to read genesis doc file %s", config.GenesisFile()) + // } + // + // var genesisState map[string]json.RawMessage + // if err = cdc.UnmarshalJSON(genDoc.AppState, &genesisState); err != nil { + // return errors.Wrap(err, "failed to unmarshal genesis state") + // } + // + // if err = mbm.ValidateGenesis(cdc, genesisState); err != nil { + // return errors.Wrap(err, "failed to validate genesis state") + // } + // + // inBuf := bufio.NewReader(cmd.InOrStdin()) + // kb, err := keyring.New(sdk.KeyringServiceName(), + // viper.GetString(flags.FlagKeyringBackend), viper.GetString(flagClientHome), inBuf) + // if err != nil { + // return errors.Wrap(err, "failed to initialize keybase") + // } + // + // name := viper.GetString(flags.FlagName) + // key, err := kb.Key(name) + // if err != nil { + // return errors.Wrap(err, "failed to read from keybase") + // } + // + // // Set flags for creating gentx + // viper.Set(flags.FlagHome, viper.GetString(flagClientHome)) + // smbh.PrepareFlagsForTxCreateValidator(config, nodeID, genDoc.ChainID, valPubKey) + // + // // Fetch the amount of coins staked + // amount := viper.GetString(flagAmount) + // coins, err := sdk.ParseCoins(amount) + // if err != nil { + // return errors.Wrap(err, "failed to parse coins") + // } + // + // err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, key.GetAddress(), coins, cdc) + // if err != nil { + // return errors.Wrap(err, "failed to validate account in genesis") + // } + // + // txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) + // cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) + // + // // Set the generate-only flag here after the CLI context has + // // been created. This allows the from name/key to be correctly populated. + // // + // // TODO: Consider removing the manual setting of generate-only in + // // favor of a 'gentx' flag in the create-validator command. + // viper.Set(flags.FlagGenerateOnly, true) + // + // // create a 'create-validator' message + // txBldr, msg, err := smbh.BuildCreateValidatorMsg(cliCtx, txBldr) + // if err != nil { + // return errors.Wrap(err, "failed to build create-validator message") + // } + // + // if key.GetType() == keyring.TypeOffline || key.GetType() == keyring.TypeMulti { + // cmd.PrintErrln("Offline key passed in. Use `tx sign` command to sign.") + // return authclient.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg}) + // } + // + // // write the unsigned transaction to the buffer + // w := bytes.NewBuffer([]byte{}) + // cliCtx = cliCtx.WithOutput(w) + // + // if err = authclient.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg}); err != nil { + // return errors.Wrap(err, "failed to print unsigned std tx") + // } + // + // // read the transaction + // stdTx, err := readUnsignedGenTxFile(cdc, w) + // if err != nil { + // return errors.Wrap(err, "failed to read unsigned gen tx file") + // } + // + // // sign the transaction and write it to the output file + // signedTx, err := authclient.SignStdTx(txBldr, cliCtx, name, stdTx, false, true) + // if err != nil { + // return errors.Wrap(err, "failed to sign std tx") + // } + // + // // Fetch output file name + // outputDocument := viper.GetString(flags.FlagOutputDocument) + // if outputDocument == "" { + // outputDocument, err = makeOutputFilepath(config.RootDir, nodeID) + // if err != nil { + // return errors.Wrap(err, "failed to create output file path") + // } + // } + // + // if err := writeSignedGenTx(cdc, outputDocument, signedTx); err != nil { + // return errors.Wrap(err, "failed to write signed gen tx") + // } + // + // cmd.PrintErrf("Genesis transaction written to %q\n", outputDocument) + // return nil + // + // }, + //} + // + //cmd.Flags().String(flags.FlagHome, defaultNodeHome, "node's home directory") + //cmd.Flags().String(flagClientHome, defaultCLIHome, "client's home directory") + //cmd.Flags().String(flags.FlagName, "", "name of private key with which to sign the gentx") + //cmd.Flags().String(flags.FlagOutputDocument, "", + // "write the genesis transaction JSON document to the given file instead of the default location") + //cmd.Flags().AddFlagSet(fsCreateValidator) + //cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") + //viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend)) + // + //cmd.MarkFlagRequired(flags.FlagName) + // + //return cmd } func makeOutputFilepath(rootDir, nodeID string) (string, error) { From bfb3ae65be889877d663d371014e946537d337d6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 28 May 2020 18:54:23 -0400 Subject: [PATCH 46/54] fix validate sigs --- crypto/multisig/multisig.go | 4 +- crypto/multisig/threshold_pubkey.go | 4 + x/auth/client/cli/validate_sigs.go | 236 +++++++++++++--------------- 3 files changed, 116 insertions(+), 128 deletions(-) diff --git a/crypto/multisig/multisig.go b/crypto/multisig/multisig.go index 2b413d126345..aae44faeb862 100644 --- a/crypto/multisig/multisig.go +++ b/crypto/multisig/multisig.go @@ -1,8 +1,9 @@ package multisig import ( - types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" + + types "github.com/cosmos/cosmos-sdk/types/tx" ) type GetSignBytesFunc func(mode types.SignMode) ([]byte, error) @@ -12,4 +13,5 @@ type MultisigPubKey interface { VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *types.MultiSignature) bool GetPubKeys() []crypto.PubKey + Threshold() uint32 } diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index a28d129f5ad9..3d42721b7a82 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -12,6 +12,10 @@ type ThresholdMultisigPubKey struct { PubKeys []crypto.PubKey `json:"pubkeys"` } +func (pk ThresholdMultisigPubKey) Threshold() uint32 { + return pk.K +} + var _ MultisigPubKey = ThresholdMultisigPubKey{} // NewPubKeyMultisigThreshold returns a new PubKeyMultisigThreshold. diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 5d35f74eaf75..5c92f5796192 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -3,9 +3,13 @@ package cli import ( "bufio" "fmt" + "strings" "github.com/spf13/cobra" + multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -54,133 +58,111 @@ func makeValidateSignaturesCmd(cliCtx context.CLIContext) func(cmd *cobra.Comman func printAndValidateSigs( cmd *cobra.Command, cliCtx context.CLIContext, chainID string, tx sdk.Tx, offline bool, ) bool { - //sigTx := tx.(txtypes.SigTx) - //signModeHandler := cliCtx.TxGenerator.SignModeHandler() - // - //cmd.Println("Signers:") - //signers := sigTx.GetSigners() - // - //for i, signer := range signers { - // cmd.Printf(" %v: %v\n", i, signer.String()) - //} - // - //success := true - //sigs := sigTx.GetSignatures() - //pubKeys := sigTx.GetPubKeys() - //cmd.Println("") - //cmd.Println("Signatures:") - // - //if len(sigs) != len(signers) { - // success = false - //} - // - //for i, sig := range sigs { - // var ( - // pubKey = pubKeys[i] - // multiSigHeader string - // multiSigMsg string - // sigAddr = sdk.AccAddress(pubKey.Address()) - // sigSanity = "OK" - // ) - // - // if i >= len(signers) || !sigAddr.Equals(signers[i]) { - // sigSanity = "ERROR: signature does not match its respective signer" - // success = false - // } - // - // // Validate the actual signature over the transaction bytes since we can - // // reach out to a full node to query accounts. - // if !offline && success { - // accNum, accSeq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, sigAddr) - // if err != nil { - // cmd.Printf("failed to get account: %s\n", sigAddr) - // return false - // } - // - // signingData := txtypes.SigningData{ - // PublicKey: pubKey, - // ChainID: chainID, - // AccountNumber: accNum, - // AccountSequence: accSeq, - // } - // - // if protoTx, ok := tx.(txtypes.ProtoTx); ok { - // modeInfo := protoTx.GetAuthInfo().SignerInfos[i].ModeInfo - // switch modeInfo := modeInfo.Sum.(type) { - // case *txtypes.ModeInfo_Single_: - // signingData.ModeInfo = modeInfo.Single - // sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) - // if err != nil { - // sigSanity = "ERROR: can't get sign bytes" - // success = false - // } - // - // if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { - // sigSanity = "ERROR: signature invalid" - // success = false - // } - // case *txtypes.ModeInfo_Multi_: - // multisigs, err := types.DecodeMultisignatures(sig) - // if err != nil { - // sigSanity = "ERROR: can't decoded multisignature" - // success = false - // } - // - // if multiPK, ok := pubKey.(multisig2.MultisigPubKey); ok { - // multiPK.VerifyMultisignature(func(single *txtypes.ModeInfo_Single) ([]byte, error) { - // signingData.ModeInfo = single - // return signModeHandler.GetSignBytes(signingData, tx) - // }, multisig2.DecodedMultisignature{ - // ModeInfo: modeInfo.Multi, - // Signatures: multisigs, - // }) - // } - // default: - // sigSanity = "ERROR: unexpected ModeInfo" - // success = false - // } - // } else { - // sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) - // if err != nil { - // sigSanity = "ERROR: can't get sign bytes" - // success = false - // } - // - // if ok := pubKey.VerifyBytes(sigBytes, sig); !ok { - // sigSanity = "ERROR: signature invalid" - // success = false - // } - // } - // } - // - // multiPK, ok := pubKey.(multisig.PubKeyMultisigThreshold) - // if ok { - // var multiSig multisig.Multisignature - // - // panic("TODO: update this:") - // cliCtx.Codec.MustUnmarshalBinaryBare(sig, &multiSig) - // - // var b strings.Builder - // b.WriteString("\n MultiSig Signatures:\n") - // - // for i := 0; i < multiSig.BitArray.Size(); i++ { - // if multiSig.BitArray.GetIndex(i) { - // addr := sdk.AccAddress(multiPK.PubKeys[i].Address().Bytes()) - // b.WriteString(fmt.Sprintf(" %d: %s (weight: %d)\n", i, addr, 1)) - // } - // } - // - // multiSigHeader = fmt.Sprintf(" [multisig threshold: %d/%d]", multiPK.K, len(multiPK.PubKeys)) - // multiSigMsg = b.String() - // } - // - // cmd.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigAddr.String(), sigSanity, multiSigHeader, multiSigMsg) - //} - // - //cmd.Println("") - // - //return success - panic("TODO") + sigTx := tx.(txtypes.SigTx) + signModeHandler := cliCtx.TxGenerator.SignModeHandler() + + cmd.Println("Signers:") + signers := sigTx.GetSigners() + + for i, signer := range signers { + cmd.Printf(" %v: %v\n", i, signer.String()) + } + + success := true + sigs, err := sigTx.GetSignaturesV2() + if err != nil { + panic(err) + } + pubKeys := sigTx.GetPubKeys() + cmd.Println("") + cmd.Println("Signatures:") + + if len(sigs) != len(signers) { + success = false + } + + for i, sig := range sigs { + var ( + pubKey = pubKeys[i] + multiSigHeader string + multiSigMsg string + sigAddr = sdk.AccAddress(pubKey.Address()) + sigSanity = "OK" + ) + + if i >= len(signers) || !sigAddr.Equals(signers[i]) { + sigSanity = "ERROR: signature does not match its respective signer" + success = false + } + + // Validate the actual signature over the transaction bytes since we can + // reach out to a full node to query accounts. + if !offline && success { + accNum, accSeq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, sigAddr) + if err != nil { + cmd.Printf("failed to get account: %s\n", sigAddr) + return false + } + + signingData := txtypes.SigningData{ + PublicKey: pubKey, + ChainID: chainID, + AccountNumber: accNum, + AccountSequence: accSeq, + } + + switch sig := sig.(type) { + case *txtypes.SingleSignature: + signingData.Mode = sig.SignMode + sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) + if err != nil { + sigSanity = "ERROR: can't get sign bytes" + success = false + } + + if ok := pubKey.VerifyBytes(sigBytes, sig.Signature); !ok { + sigSanity = "ERROR: signature invalid" + success = false + } + case *txtypes.MultiSignature: + multiPK, ok := pubKey.(multisig2.MultisigPubKey) + if ok { + if !multiPK.VerifyMultisignature(func(mode txtypes.SignMode) ([]byte, error) { + signingData.Mode = mode + return signModeHandler.GetSignBytes(signingData, tx) + }, sig) { + sigSanity = "ERROR: signature invalid" + success = false + } + + var b strings.Builder + b.WriteString("\n MultiSig Signatures:\n") + + pks := multiPK.GetPubKeys() + for i := 0; i < sig.BitArray.Size(); i++ { + if sig.BitArray.GetIndex(i) { + addr := sdk.AccAddress(pks[i].Address().Bytes()) + b.WriteString(fmt.Sprintf(" %d: %s (weight: %d)\n", i, addr, 1)) + } + } + + multiSigHeader = fmt.Sprintf(" [multisig threshold: %d/%d]", multiPK.Threshold(), len(pks)) + multiSigMsg = b.String() + cmd.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigAddr.String(), sigSanity, multiSigHeader, multiSigMsg) + } else { + sigSanity = "ERROR: expected multisig pub key" + success = false + } + default: + sigSanity = "ERROR: unexpected ModeInfo" + success = false + } + } + } + + cmd.Println("") + + return success } func readTxAndInitContexts(cliCtx context.CLIContext, cmd *cobra.Command, filename string) (context.CLIContext, tx.Factory, sdk.Tx, error) { From e97b368b80726ad81e3919d2325f13fa054536e5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 29 May 2020 13:58:49 -0400 Subject: [PATCH 47/54] Refactor TxBuilder --- client/context/tx_generator.go | 33 ++----- client/tx/factory.go | 3 + client/tx/tx.go | 62 +++++++++---- crypto/multisig/multisig.go | 2 +- crypto/multisig/multisignature.go | 16 ++-- crypto/multisig/threshold_pubkey.go | 6 +- crypto/multisig/threshold_pubkey_test.go | 14 +-- simapp/helpers/test_helpers.go | 50 ++++++---- simapp/params/proto.go | 2 +- tests/cli/helpers.go | 7 +- types/decimal_test.go | 4 - types/tx/mode_handler.go | 1 + types/tx/signature.go | 27 +++--- types/tx/signing/amino.go | 89 ++++++++---------- types/tx/signing/default.go | 13 +++ types/tx/signing/direct.go | 4 + types/tx/signing/handler_map.go | 8 +- types/tx/signing/signature.go | 55 ----------- types/tx/signing/tx_builder.go | 80 ++++++++++------ types/tx/signing/tx_generator.go | 25 +---- types/tx/tx.go | 15 +-- x/auth/ante/ante.go | 6 +- x/auth/ante/sigverify_proto.go | 4 +- x/auth/client/cli/tx_sign.go | 113 +++++++++++------------ x/auth/client/cli/validate_sigs.go | 4 +- x/auth/client/tx_test.go | 8 +- x/auth/types/client_tx.go | 84 +++++++---------- x/auth/types/stdtx.go | 12 +-- 28 files changed, 360 insertions(+), 387 deletions(-) create mode 100644 types/tx/signing/default.go delete mode 100644 types/tx/signing/signature.go diff --git a/client/context/tx_generator.go b/client/context/tx_generator.go index 06738390a34b..5fa8b781d539 100644 --- a/client/context/tx_generator.go +++ b/client/context/tx_generator.go @@ -14,24 +14,10 @@ type ( // implement TxBuilder. TxGenerator interface { NewTxBuilder() TxBuilder - NewFee() ClientFee - NewSignature() ClientSignature TxEncoder() sdk.TxEncoder SignModeHandler() types.SignModeHandler } - ClientFee interface { - sdk.Fee - SetGas(uint64) - SetAmount(sdk.Coins) - } - - ClientSignature interface { - sdk.Signature - SetPubKey(crypto.PubKey) error - SetSignature([]byte) - } - // TxBuilder defines an interface which an application-defined concrete transaction // type must implement. Namely, it must be able to set messages, generate // signatures, and provide canonical bytes to sign over. The transaction must @@ -39,16 +25,15 @@ type ( TxBuilder interface { GetTx() sdk.Tx - SetMsgs(...sdk.Msg) error - GetSignatures() []sdk.Signature - SetSignatures(...ClientSignature) error - GetFee() sdk.Fee - SetFee(ClientFee) error - GetMemo() string - SetMemo(string) + SetMsgs(msgs ...sdk.Msg) error + SetSignatures(signatures ...SignatureBuilder) error + SetMemo(memo string) + SetFee(amount sdk.Coins) + SetGasLimit(limit uint64) + } - // CanonicalSignBytes returns the canonical sign bytes to sign over, given a - // chain ID, along with an account and sequence number. - CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) + SignatureBuilder struct { + PubKey crypto.PubKey + Data types.SignatureData } ) diff --git a/client/tx/factory.go b/client/tx/factory.go index dc1b2c6dfcb6..49853f739d02 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -3,6 +3,8 @@ package tx import ( "io" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client/context" @@ -26,6 +28,7 @@ type Factory struct { memo string fees sdk.Coins gasPrices sdk.DecCoins + signMode types.SignMode } func NewFactoryFromCLI(input io.Reader) Factory { diff --git a/client/tx/tx.go b/client/tx/tx.go index bd8ae75baaa1..a6e9f0e69a3e 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -8,12 +8,13 @@ import ( "os" "strings" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/gogo/protobuf/jsonpb" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" - clientkeys "github.com/cosmos/cosmos-sdk/client/keys" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/rest" @@ -108,7 +109,7 @@ func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { } } - txBytes, err := Sign(txf, ctx.GetFromName(), clientkeys.DefaultKeyPass, tx) + txBytes, err := Sign(txf, ctx.GetFromName(), tx) if err != nil { return err } @@ -209,25 +210,19 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (context.TxBuilder, error) { } } - clientFee := txf.txGenerator.NewFee() - clientFee.SetAmount(fees) - clientFee.SetGas(txf.gas) - tx := txf.txGenerator.NewTxBuilder() - tx.SetMemo(txf.memo) - if err := tx.SetFee(clientFee); err != nil { + if err := tx.SetMsgs(msgs...); err != nil { return nil, err } + tx.SetMemo(txf.memo) + tx.SetFee(fees) + tx.SetGasLimit(txf.gas) if err := tx.SetSignatures(); err != nil { return nil, err } - if err := tx.SetMsgs(msgs...); err != nil { - return nil, err - } - return tx, nil } @@ -242,7 +237,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { // Create an empty signature literal as the ante handler will populate with a // sentinel pubkey. - sig := txf.txGenerator.NewSignature() + sig := context.SignatureBuilder{} if err := tx.SetSignatures(sig); err != nil { return nil, err @@ -312,28 +307,57 @@ func PrepareFactory(ctx context.CLIContext, txf Factory) (Factory, error) { // // Note, It is assumed the Factory has the necessary fields set that are required // by the CanonicalSignBytes call. -func Sign(txf Factory, name, passphrase string, tx context.TxBuilder) ([]byte, error) { +func Sign(txf Factory, name string, tx context.TxBuilder) ([]byte, error) { if txf.keybase == nil { return nil, errors.New("keybase must be set prior to signing a transaction") } - signBytes, err := tx.CanonicalSignBytes(txf.chainID, txf.accountNumber, txf.sequence) + signMode := txf.signMode + if signMode == types.SignMode_SIGN_MODE_UNSPECIFIED { + signMode = txf.txGenerator.SignModeHandler().DefaultMode() + } + + key, err := txf.keybase.Key(name) if err != nil { return nil, err } - sigBytes, pubkey, err := txf.keybase.Sign(name, signBytes) + pubKey := key.GetPubKey() + + sigData := &types.SingleSignatureData{ + SignMode: signMode, + Signature: nil, + } + sig := context.SignatureBuilder{ + PubKey: pubKey, + Data: sigData, + } + + err = tx.SetSignatures(sig) if err != nil { return nil, err } - sig := txf.txGenerator.NewSignature() - sig.SetSignature(sigBytes) + signBytes, err := txf.txGenerator.SignModeHandler().GetSignBytes( + types.SigningData{ + Mode: signMode, + PublicKey: pubKey, + ChainID: txf.chainID, + AccountNumber: txf.accountNumber, + AccountSequence: txf.sequence, + }, tx.GetTx(), + ) + if err != nil { + return nil, err + } - if err := sig.SetPubKey(pubkey); err != nil { + sigBytes, _, err := txf.keybase.Sign(name, signBytes) + if err != nil { return nil, err } + sigData.Signature = sigBytes + if err := tx.SetSignatures(sig); err != nil { return nil, err } diff --git a/crypto/multisig/multisig.go b/crypto/multisig/multisig.go index aae44faeb862..a0ffa782dd10 100644 --- a/crypto/multisig/multisig.go +++ b/crypto/multisig/multisig.go @@ -11,7 +11,7 @@ type GetSignBytesFunc func(mode types.SignMode) ([]byte, error) type MultisigPubKey interface { crypto.PubKey - VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *types.MultiSignature) bool + VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *types.MultiSignatureData) bool GetPubKeys() []crypto.PubKey Threshold() uint32 } diff --git a/crypto/multisig/multisignature.go b/crypto/multisig/multisignature.go index 87d4bf361ec1..ce730466cc03 100644 --- a/crypto/multisig/multisignature.go +++ b/crypto/multisig/multisignature.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" + "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/crypto/types" tx "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/tendermint/tendermint/crypto" ) // AminoMultisignature is used to represent the signature object used in the multisigs. @@ -16,9 +17,9 @@ type AminoMultisignature struct { Sigs [][]byte } -// NewMultisig returns a new MultiSignature -func NewMultisig(n int) *tx.MultiSignature { - return &tx.MultiSignature{BitArray: types.NewCompactBitArray(n), Signatures: make([]tx.SignatureV2, n)} +// NewMultisig returns a new MultiSignatureData +func NewMultisig(n int) *tx.MultiSignatureData { + return &tx.MultiSignatureData{BitArray: types.NewCompactBitArray(n), Signatures: make([]tx.SignatureData, n)} } // GetIndex returns the index of pk in keys. Returns -1 if not found @@ -33,7 +34,7 @@ func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int { // AddSignature adds a signature to the multisig, at the corresponding index. // If the signature already exists, replace it. -func AddSignature(mSig *tx.MultiSignature, sig tx.SignatureV2, index int) { +func AddSignature(mSig *tx.MultiSignatureData, sig tx.SignatureData, index int) { newSigIndex := mSig.BitArray.NumTrueBitsBefore(index) // Signature already exists, just replace the value there if mSig.BitArray.GetIndex(index) { @@ -48,14 +49,14 @@ func AddSignature(mSig *tx.MultiSignature, sig tx.SignatureV2, index int) { } // Expand slice by one with a dummy element, move all elements after i // over by one, then place the new signature in that gap. - mSig.Signatures = append(mSig.Signatures, &tx.SingleSignature{}) + mSig.Signatures = append(mSig.Signatures, &tx.SingleSignatureData{}) copy(mSig.Signatures[newSigIndex+1:], mSig.Signatures[newSigIndex:]) mSig.Signatures[newSigIndex] = sig } // AddSignatureFromPubKey adds a signature to the multisig, at the index in // keys corresponding to the provided pubkey. -func AddSignatureFromPubKey(mSig *tx.MultiSignature, sig tx.SignatureV2, pubkey crypto.PubKey, keys []crypto.PubKey) error { +func AddSignatureFromPubKey(mSig *tx.MultiSignatureData, sig tx.SignatureData, pubkey crypto.PubKey, keys []crypto.PubKey) error { index := getIndex(pubkey, keys) if index == -1 { keysStr := make([]string, len(keys)) @@ -69,4 +70,3 @@ func AddSignatureFromPubKey(mSig *tx.MultiSignature, sig tx.SignatureV2, pubkey AddSignature(mSig, sig, index) return nil } - diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index 3d42721b7a82..f3addf3419cb 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -41,7 +41,7 @@ func (pk ThresholdMultisigPubKey) VerifyBytes([]byte, []byte) bool { return false } -func (pk ThresholdMultisigPubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *txtypes.MultiSignature) bool { +func (pk ThresholdMultisigPubKey) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *txtypes.MultiSignatureData) bool { bitarray := sig.BitArray sigs := sig.Signatures size := bitarray.Size() @@ -63,7 +63,7 @@ func (pk ThresholdMultisigPubKey) VerifyMultisignature(getSignBytes GetSignBytes if bitarray.GetIndex(i) { si := sig.Signatures[sigIndex] switch si := si.(type) { - case *txtypes.SingleSignature: + case *txtypes.SingleSignatureData: msg, err := getSignBytes(si.SignMode) if err != nil { return false @@ -71,7 +71,7 @@ func (pk ThresholdMultisigPubKey) VerifyMultisignature(getSignBytes GetSignBytes if !pk.PubKeys[i].VerifyBytes(msg, si.Signature) { return false } - case *txtypes.MultiSignature: + case *txtypes.MultiSignatureData: nestedMultisigPk, ok := pk.PubKeys[i].(MultisigPubKey) if !ok { return false diff --git a/crypto/multisig/threshold_pubkey_test.go b/crypto/multisig/threshold_pubkey_test.go index 3f1e407cad6a..a77f575ee02e 100644 --- a/crypto/multisig/threshold_pubkey_test.go +++ b/crypto/multisig/threshold_pubkey_test.go @@ -1,17 +1,19 @@ package multisig import ( - "github.com/tendermint/tendermint/crypto/multisig" "math/rand" "testing" + "github.com/tendermint/tendermint/crypto/multisig" + "github.com/stretchr/testify/require" - types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/sr25519" + + types "github.com/cosmos/cosmos-sdk/types/tx" ) // This tests multisig functionality, but it expects the first k signatures to be valid @@ -24,7 +26,7 @@ func TestThresholdMultisigValidCases(t *testing.T) { pubkeys []crypto.PubKey signingIndices []int // signatures should be the same size as signingIndices. - signatures []types.SignatureV2 + signatures []types.SignatureData passAfterKSignatures []bool }{ { @@ -168,9 +170,9 @@ func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) { require.Equal(t, multisigKey, pubKey) } -func generatePubKeysAndSignatures(n int, msg []byte) (pubkeys []crypto.PubKey, signatures []types.SignatureV2) { +func generatePubKeysAndSignatures(n int, msg []byte) (pubkeys []crypto.PubKey, signatures []types.SignatureData) { pubkeys = make([]crypto.PubKey, n) - signatures = make([]types.SignatureV2, n) + signatures = make([]types.SignatureData, n) for i := 0; i < n; i++ { var privkey crypto.PrivKey switch rand.Int63() % 3 { @@ -183,7 +185,7 @@ func generatePubKeysAndSignatures(n int, msg []byte) (pubkeys []crypto.PubKey, s } pubkeys[i] = privkey.PubKey() sig, _ := privkey.Sign(msg) - signatures[i] = &types.SingleSignature{Signature: sig} + signatures[i] = &types.SingleSignatureData{Signature: sig} } return } diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 7cba4000dc8d..a049bebd6c80 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -4,6 +4,8 @@ import ( "math/rand" "time" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/tendermint/tendermint/crypto" @@ -20,34 +22,47 @@ const ( // GenTx generates a signed mock transaction. func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) sdk.Tx { - fee := gen.NewFee() - fee.SetAmount(feeAmt) - fee.SetGas(gas) - - sigs := make([]context.ClientSignature, len(priv)) + sigs := make([]context.SignatureBuilder, len(priv)) // create a random length memo r := rand.New(rand.NewSource(time.Now().UnixNano())) memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - for i, p := range priv { - // use a empty chainID for ease of testing - clientSig := gen.NewSignature() - clientSig.SetPubKey(p.PubKey()) + signMode := gen.SignModeHandler().DefaultMode() - sigs[i] = clientSig + for i, p := range priv { + sigs[i] = context.SignatureBuilder{ + PubKey: p.PubKey(), + Data: &types.SingleSignatureData{ + SignMode: signMode, + }, + } } tx := gen.NewTxBuilder() - tx.SetMsgs(msgs...) - tx.SetFee(fee) - tx.SetSignatures(sigs...) + err := tx.SetMsgs(msgs...) + if err != nil { + panic(err) + } + err = tx.SetSignatures(sigs...) + if err != nil { + panic(err) + } tx.SetMemo(memo) + tx.SetFee(feeAmt) + tx.SetGasLimit(gas) for i, p := range priv { // use a empty chainID for ease of testing - signBytes, err := tx.CanonicalSignBytes(chainID, accnums[i], seq[i]) + signBytes, err := gen.SignModeHandler().GetSignBytes(types.SigningData{ + Mode: 0, + PublicKey: nil, + ChainID: chainID, + AccountNumber: accnums[i], + AccountSequence: seq[i], + }, tx.GetTx()) + if err != nil { panic(err) } @@ -56,10 +71,13 @@ func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64 panic(err) } - sigs[i].SetSignature(sig) + sigs[i].Data.(*types.SingleSignatureData).Signature = sig } - tx.SetSignatures(sigs...) + err = tx.SetSignatures(sigs...) + if err != nil { + panic(err) + } return tx.GetTx() } diff --git a/simapp/params/proto.go b/simapp/params/proto.go index f98335b1e4af..56ae43862f45 100644 --- a/simapp/params/proto.go +++ b/simapp/params/proto.go @@ -14,7 +14,7 @@ func MakeEncodingConfig() EncodingConfig { interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewHybridCodec(cdc, interfaceRegistry) pubKeyCodec := cryptocodec.DefaultPublicKeyCodec{} - txGen := signing.NewTxGenerator(marshaler, pubKeyCodec) + txGen := signing.NewTxGenerator(marshaler, pubKeyCodec, signing.DefaultSignModeHandler()) return EncodingConfig{ InterfaceRegistry: interfaceRegistry, diff --git a/tests/cli/helpers.go b/tests/cli/helpers.go index 6e0cc03474e7..ccb720591e84 100644 --- a/tests/cli/helpers.go +++ b/tests/cli/helpers.go @@ -7,14 +7,13 @@ import ( "path/filepath" "strings" - tx "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/stretchr/testify/require" clientkeys "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" + txtypes "github.com/cosmos/cosmos-sdk/types/tx" ) var ( @@ -192,7 +191,9 @@ func AddFlags(cmd string, flags []string) string { } type CLITx interface { - tx.SigTx + txtypes.SigTx + txtypes.FeeTx + txtypes.TxWithMemo SetMemo(string) } diff --git a/types/decimal_test.go b/types/decimal_test.go index c58777783764..39a24703e261 100644 --- a/types/decimal_test.go +++ b/types/decimal_test.go @@ -9,8 +9,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" yaml "gopkg.in/yaml.v2" - - "github.com/cosmos/cosmos-sdk/codec" ) // create a decimal from a decimal string (ex. "1234.5678") @@ -270,8 +268,6 @@ func TestTruncate(t *testing.T) { } } -var cdc = codec.New() - func TestDecMarshalJSON(t *testing.T) { decimal := func(i int64) Dec { d := NewDec(0) diff --git a/types/tx/mode_handler.go b/types/tx/mode_handler.go index d8b9342f9602..b7c3a7524ed7 100644 --- a/types/tx/mode_handler.go +++ b/types/tx/mode_handler.go @@ -15,6 +15,7 @@ type SigningData struct { } type SignModeHandler interface { + DefaultMode() SignMode Modes() []SignMode GetSignBytes(data SigningData, tx sdk.Tx) ([]byte, error) } diff --git a/types/tx/signature.go b/types/tx/signature.go index 28d918ac6e66..ad1fc43c045b 100644 --- a/types/tx/signature.go +++ b/types/tx/signature.go @@ -2,29 +2,29 @@ package types import "github.com/cosmos/cosmos-sdk/crypto/types" -type SignatureV2 interface { - isSignatureV2() +type SignatureData interface { + isSignatureData() } -type SingleSignature struct { +type SingleSignatureData struct { SignMode SignMode Signature []byte } -type MultiSignature struct { +type MultiSignatureData struct { BitArray *types.CompactBitArray - Signatures []SignatureV2 + Signatures []SignatureData } -var _, _ SignatureV2 = &SingleSignature{}, &MultiSignature{} +var _, _ SignatureData = &SingleSignatureData{}, &MultiSignatureData{} -func (m *SingleSignature) isSignatureV2() {} -func (m *MultiSignature) isSignatureV2() {} +func (m *SingleSignatureData) isSignatureData() {} +func (m *MultiSignatureData) isSignatureData() {} -func ModeInfoToSignatureV2(modeInfo *ModeInfo, sig []byte) (SignatureV2, error) { +func ModeInfoToSignatureData(modeInfo *ModeInfo, sig []byte) (SignatureData, error) { switch modeInfo := modeInfo.Sum.(type) { case *ModeInfo_Single_: - return &SingleSignature{ + return &SingleSignatureData{ SignMode: modeInfo.Single.Mode, Signature: sig, }, nil @@ -37,15 +37,15 @@ func ModeInfoToSignatureV2(modeInfo *ModeInfo, sig []byte) (SignatureV2, error) return nil, err } - sigv2s := make([]SignatureV2, len(sigs)) + sigv2s := make([]SignatureData, len(sigs)) for i, mi := range multi.ModeInfos { - sigv2s[i], err = ModeInfoToSignatureV2(mi, sigs[i]) + sigv2s[i], err = ModeInfoToSignatureData(mi, sigs[i]) if err != nil { return nil, err } } - return &MultiSignature{ + return &MultiSignatureData{ BitArray: multi.Bitarray, Signatures: sigv2s, }, nil @@ -54,4 +54,3 @@ func ModeInfoToSignatureV2(modeInfo *ModeInfo, sig []byte) (SignatureV2, error) panic("unexpected case") } } - diff --git a/types/tx/signing/amino.go b/types/tx/signing/amino.go index 0c57551867dd..899063c7286e 100644 --- a/types/tx/signing/amino.go +++ b/types/tx/signing/amino.go @@ -1,10 +1,8 @@ package signing import ( - "fmt" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/multisig" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" + multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" @@ -30,41 +28,22 @@ func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen context.Tx } txBuilder.SetMemo(aminoTx.Memo) - - // set fee - fee := txGen.NewFee() - fee.SetGas(aminoTx.Fee.Gas) - fee.SetAmount(aminoTx.Fee.Amount) - err = txBuilder.SetFee(fee) - if err != nil { - return nil, err - } + txBuilder.SetFee(aminoTx.Fee.Amount) + txBuilder.SetGasLimit(aminoTx.Fee.Gas) n := len(aminoTx.Signatures) - clientSigs := make([]context.ClientSignature, n) - pubKeys := aminoTx.GetPubKeys() - sigs := aminoTx.GetSignatures() + clientSigs := make([]context.SignatureBuilder, n) + sigs := aminoTx.Signatures for i := 0; i < n; i++ { - csig := txGen.NewSignature() - - pubKey := pubKeys[i] - - miSig, ok := csig.(ModeInfoSignature) - if !ok { - return nil, fmt.Errorf("can't set ModeInfo") - } - miSig.SetModeInfo(makeAminoModeInfo(pubKey)) - - fmt.Printf("amino decoded pubkey: %T\n", pubKey) - err = csig.SetPubKey(pubKey) + data, err := stdSignatureToSignatureData(sigs[i]) if err != nil { return nil, err } - - csig.SetSignature(sigs[i]) - - clientSigs[i] = csig + clientSigs[i] = context.SignatureBuilder{ + PubKey: sigs[i].GetPubKey(), + Data: data, + } } err = txBuilder.SetSignatures(clientSigs...) @@ -76,24 +55,38 @@ func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen context.Tx } } -func makeAminoModeInfo(pk crypto.PubKey) *types.ModeInfo { - if multisigPk, ok := pk.(multisig.PubKeyMultisigThreshold); ok { - multi := &types.ModeInfo_Multi{} - for i, k := range multisigPk.PubKeys { - multi.ModeInfos[i] = makeAminoModeInfo(k) +func stdSignatureToSignatureData(signature auth.StdSignature) (types.SignatureData, error) { + pk := signature.GetPubKey() + if multisigPk, ok := pk.(multisig2.MultisigPubKey); ok { + pubKeys := multisigPk.GetPubKeys() + var sig multisig2.AminoMultisignature + err := legacy_global.Cdc.UnmarshalBinaryBare(signature.Signature, &sig) + if err != nil { + return nil, err } - return &types.ModeInfo{ - Sum: &types.ModeInfo_Multi_{ - Multi: multi, - }, + n := sig.BitArray.Size() + datas := make([]types.SignatureData, n) + sigIndex := 0 + for i := 0; i < n; i++ { + if sig.BitArray.GetIndex(i) { + datas[sigIndex], err = stdSignatureToSignatureData(auth.StdSignature{ + PubKey: pubKeys[i].Bytes(), + Signature: sig.Sigs[sigIndex], + }) + if err != nil { + return nil, err + } + sigIndex++ + } } + return &types.MultiSignatureData{ + BitArray: sig.BitArray, + Signatures: datas[:sigIndex], + }, nil } else { - return &types.ModeInfo{ - Sum: &types.ModeInfo_Single_{ - Single: &types.ModeInfo_Single{ - Mode: types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, - }, - }, - } + return &types.SingleSignatureData{ + SignMode: types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + Signature: signature.Signature, + }, nil } } diff --git a/types/tx/signing/default.go b/types/tx/signing/default.go new file mode 100644 index 000000000000..a898cbd83d15 --- /dev/null +++ b/types/tx/signing/default.go @@ -0,0 +1,13 @@ +package signing + +import ( + types "github.com/cosmos/cosmos-sdk/types/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func DefaultSignModeHandler() types.SignModeHandler { + return NewHandlerMap(types.SignMode_SIGN_MODE_DIRECT, []types.SignModeHandler{ + DirectModeHandler{}, + authtypes.LegacyAminoJSONHandler{}, + }) +} diff --git a/types/tx/signing/direct.go b/types/tx/signing/direct.go index 42143ab23c06..e4990f87850d 100644 --- a/types/tx/signing/direct.go +++ b/types/tx/signing/direct.go @@ -9,6 +9,10 @@ import ( type DirectModeHandler struct{} +func (h DirectModeHandler) DefaultMode() types.SignMode { + return types.SignMode_SIGN_MODE_DIRECT +} + var _ types.SignModeHandler = DirectModeHandler{} func (DirectModeHandler) Modes() []types.SignMode { diff --git a/types/tx/signing/handler_map.go b/types/tx/signing/handler_map.go index 13458dd8fd00..b08b96f5f4cf 100644 --- a/types/tx/signing/handler_map.go +++ b/types/tx/signing/handler_map.go @@ -8,13 +8,14 @@ import ( ) type HandlerMap struct { + defaultMode types.SignMode modes []types.SignMode signModeHandlers map[types.SignMode]types.SignModeHandler } var _ types.SignModeHandler = HandlerMap{} -func NewHandlerMap(handlers []types.SignModeHandler) *HandlerMap { +func NewHandlerMap(defaultMode types.SignMode, handlers []types.SignModeHandler) *HandlerMap { handlerMap := make(map[types.SignMode]types.SignModeHandler) var modes []types.SignMode @@ -29,11 +30,16 @@ func NewHandlerMap(handlers []types.SignModeHandler) *HandlerMap { } return &HandlerMap{ + defaultMode: defaultMode, modes: modes, signModeHandlers: handlerMap, } } +func (h HandlerMap) DefaultMode() types.SignMode { + return h.defaultMode +} + func (h HandlerMap) Modes() []types.SignMode { return h.modes } diff --git a/types/tx/signing/signature.go b/types/tx/signing/signature.go deleted file mode 100644 index dd0a6cb7708d..000000000000 --- a/types/tx/signing/signature.go +++ /dev/null @@ -1,55 +0,0 @@ -package signing - -import ( - "github.com/tendermint/tendermint/crypto" - - "github.com/cosmos/cosmos-sdk/client/context" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - types "github.com/cosmos/cosmos-sdk/types/tx" -) - -type ClientSignature struct { - pubKey *cryptotypes.PublicKey - signature []byte - modeInfo *types.ModeInfo - codec cryptotypes.PublicKeyCodec -} - -type ModeInfoSignature interface { - context.ClientSignature - GetModeInfo() *types.ModeInfo - SetModeInfo(modeInfo *types.ModeInfo) -} - -func (c ClientSignature) GetPubKey() crypto.PubKey { - pk, err := c.codec.Decode(c.pubKey) - if err != nil { - panic(err) - } - return pk -} - -func (c ClientSignature) GetSignature() []byte { - return c.signature -} - -func (c *ClientSignature) SetPubKey(key crypto.PubKey) error { - pk, err := c.codec.Encode(key) - if err != nil { - return err - } - c.pubKey = pk - return nil -} - -func (c *ClientSignature) SetSignature(bytes []byte) { - c.signature = bytes -} - -func (c *ClientSignature) GetModeInfo() *types.ModeInfo { - return c.modeInfo -} - -func (c *ClientSignature) SetModeInfo(modeInfo *types.ModeInfo) { - c.modeInfo = modeInfo -} diff --git a/types/tx/signing/tx_builder.go b/types/tx/signing/tx_builder.go index ca9efce75374..d84987504ce2 100644 --- a/types/tx/signing/tx_builder.go +++ b/types/tx/signing/tx_builder.go @@ -42,34 +42,62 @@ func (t TxBuilder) SetMsgs(msgs ...sdk.Msg) error { return nil } -func (t TxBuilder) GetSignatures() []sdk.Signature { - signerInfos := t.Tx.AuthInfo.SignerInfos - rawSigs := t.Tx.Signatures - n := len(signerInfos) - res := make([]sdk.Signature, n) - for i, si := range signerInfos { - res[i] = ClientSignature{ - pubKey: si.PublicKey, - signature: rawSigs[i], - modeInfo: si.ModeInfo, +func SignatureDataToSignerInfoSig(data types.SignatureData) (*types.ModeInfo, []byte) { + if data == nil { + return nil, nil + } + + switch data := data.(type) { + case *types.SingleSignatureData: + return &types.ModeInfo{ + Sum: &types.ModeInfo_Single_{ + Single: &types.ModeInfo_Single{Mode: data.SignMode}, + }, + }, data.Signature + case *types.MultiSignatureData: + n := len(data.Signatures) + modeInfos := make([]*types.ModeInfo, n) + sigs := make([][]byte, n) + + for i, d := range data.Signatures { + modeInfos[i], sigs[i] = SignatureDataToSignerInfoSig(d) + } + + multisig := cryptotypes.MultiSignature{ + Signatures: sigs, + } + sig, err := multisig.Marshal() + if err != nil { + panic(err) } + + return &types.ModeInfo{ + Sum: &types.ModeInfo_Multi_{ + Multi: &types.ModeInfo_Multi{ + Bitarray: data.BitArray, + ModeInfos: modeInfos, + }, + }, + }, sig + default: + panic("unexpected case") } - return res } -func (t TxBuilder) SetSignatures(signatures ...context.ClientSignature) error { +func (t TxBuilder) SetSignatures(signatures ...context.SignatureBuilder) error { n := len(signatures) signerInfos := make([]*types.SignerInfo, n) rawSigs := make([][]byte, n) for i, sig := range signatures { - csig, ok := sig.(*ClientSignature) - if !ok { - return fmt.Errorf("expected ClientSignature, got %T", sig) + var modeInfo *types.ModeInfo + modeInfo, rawSigs[i] = SignatureDataToSignerInfoSig(sig.Data) + pk, err := t.PubKeyCodec.Encode(sig.PubKey) + if err != nil { + return err } - rawSigs[i] = csig.signature signerInfos[i] = &types.SignerInfo{ - PublicKey: csig.pubKey, - ModeInfo: csig.modeInfo, + PublicKey: pk, + ModeInfo: modeInfo, } } t.Tx.AuthInfo.SignerInfos = signerInfos @@ -77,20 +105,12 @@ func (t TxBuilder) SetSignatures(signatures ...context.ClientSignature) error { return nil } -func (t TxBuilder) GetFee() sdk.Fee { - return t.Tx.AuthInfo.Fee -} - -func (t TxBuilder) SetFee(fee context.ClientFee) error { - t.Tx.AuthInfo.Fee = &types.Fee{ - Amount: fee.GetAmount(), - GasLimit: fee.GetGas(), - } - return nil +func (t TxBuilder) SetFee(amount sdk.Coins) { + t.Tx.AuthInfo.Fee.Amount = amount } -func (t TxBuilder) GetMemo() string { - return t.Tx.Body.Memo +func (t TxBuilder) SetGasLimit(limit uint64) { + t.Tx.AuthInfo.Fee.GasLimit = limit } func (t TxBuilder) SetMemo(s string) { diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index 0872b1f0aa57..512700b01a86 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -14,10 +14,11 @@ import ( type TxGenerator struct { Marshaler codec.Marshaler PubKeyCodec cryptotypes.PublicKeyCodec + ModeHandler types.SignModeHandler } -func NewTxGenerator(marshaler codec.Marshaler, pubKeyCodec cryptotypes.PublicKeyCodec) *TxGenerator { - return &TxGenerator{Marshaler: marshaler, PubKeyCodec: cryptotypes.CacheWrapCodec(pubKeyCodec)} +func NewTxGenerator(marshaler codec.Marshaler, pubKeyCodec cryptotypes.PublicKeyCodec, handler types.SignModeHandler) *TxGenerator { + return &TxGenerator{Marshaler: marshaler, PubKeyCodec: cryptotypes.CacheWrapCodec(pubKeyCodec), ModeHandler: handler} } var _ context.TxGenerator = TxGenerator{} @@ -30,23 +31,6 @@ func (t TxGenerator) NewTxBuilder() context.TxBuilder { } } -func (t TxGenerator) NewFee() context.ClientFee { - return &types.Fee{} -} - -func (t TxGenerator) NewSignature() context.ClientSignature { - return &ClientSignature{ - modeInfo: &types.ModeInfo{ - Sum: &types.ModeInfo_Single_{ - Single: &types.ModeInfo_Single{ - Mode: types.SignMode_SIGN_MODE_DIRECT, - }, - }, - }, - codec: t.PubKeyCodec, - } -} - func (t TxGenerator) TxEncoder() sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { ptx, ok := tx.(*types.Tx) @@ -58,6 +42,5 @@ func (t TxGenerator) TxEncoder() sdk.TxEncoder { } func (t TxGenerator) SignModeHandler() types.SignModeHandler { - panic("implement me") + return t.ModeHandler } - diff --git a/types/tx/tx.go b/types/tx/tx.go index e5e6066a89b2..a05023b7233c 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -26,8 +26,11 @@ var _ ProtoTx = &Tx{} func NewTx() *Tx { return &Tx{ - Body: &TxBody{}, - AuthInfo: &AuthInfo{}, + Body: &TxBody{}, + AuthInfo: &AuthInfo{ + SignerInfos: nil, + Fee: &Fee{}, + }, Signatures: nil, } } @@ -172,18 +175,18 @@ type SigTx interface { GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignaturesV2() ([]SignatureV2, error) + GetSignaturesV2() ([]SignatureData, error) } -func (m *Tx) GetSignaturesV2() ([]SignatureV2, error) { +func (m *Tx) GetSignaturesV2() ([]SignatureData, error) { signerInfos := m.AuthInfo.SignerInfos sigs := m.Signatures n := len(signerInfos) - res := make([]SignatureV2, n) + res := make([]SignatureData, n) for i, si := range signerInfos { var err error - res[i], err = ModeInfoToSignatureV2(si.ModeInfo, sigs[i]) + res[i], err = ModeInfoToSignatureData(si.ModeInfo, sigs[i]) if err != nil { return nil, err } diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 956eb6d4e505..30e0072178bb 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -2,7 +2,6 @@ package ante import ( sdk "github.com/cosmos/cosmos-sdk/types" - types2 "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ibcante "github.com/cosmos/cosmos-sdk/x/ibc/ante" @@ -49,10 +48,7 @@ func NewProtoAnteHandler( NewValidateSigCountDecorator(ak), NewDeductFeeDecorator(ak, bankKeeper), NewSigGasConsumeDecorator(ak, sigGasConsumer), - NewProtoSigVerificationDecorator(ak, signing.NewHandlerMap([]types2.SignModeHandler{ - signing.DirectModeHandler{}, - types.LegacyAminoJSONHandler{}, - })), + NewProtoSigVerificationDecorator(ak, signing.DefaultSignModeHandler()), NewIncrementSequenceDecorator(ak), ibcante.NewProofVerificationDecorator(ibcKeeper.ClientKeeper, ibcKeeper.ChannelKeeper), // innermost AnteDecorator ) diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index d42e03b40525..4e2893c7f345 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -62,7 +62,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } switch sig := sig.(type) { - case *types.SingleSignature: + case *types.SingleSignatureData: signBytes, err := svd.getSignBytesSingle(ctx, sig.SignMode, signerAcc, sigTx) if err != nil { return ctx, err @@ -72,7 +72,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, if !simulate && !pubKey.VerifyBytes(signBytes, sig.Signature) { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") } - case *types.MultiSignature: + case *types.MultiSignatureData: multisigPubKey, ok := pubKey.(multisig.MultisigPubKey) if !ok { return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "key is not a multisig pubkey, but ModeInfo.Multi is used") diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 49097b10c344..ee9d00048464 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -1,13 +1,12 @@ package cli import ( - "github.com/spf13/cobra" - "github.com/spf13/viper" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/spf13/cobra" + "github.com/spf13/viper" ) const ( @@ -68,60 +67,60 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } func makeSignCmd(cdc context.CLIContext) func(cmd *cobra.Command, args []string) error { - panic("TODO") - //return func(cmd *cobra.Command, args []string) error { - // cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) - // if err != nil { - // return err - // } - // - // // if --signature-only is on, then override --append - // var newTx types.StdTx - // generateSignatureOnly := viper.GetBool(flagSigOnly) - // multisigAddrStr := viper.GetString(flagMultisig) - // - // if multisigAddrStr != "" { - // var multisigAddr sdk.AccAddress - // - // multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr) - // if err != nil { - // return err - // } - // newTx, err = client.SignStdTxWithSignerAddress( - // txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, cliCtx.Offline, - // ) - // generateSignatureOnly = true - // } else { - // appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly - // newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, cliCtx.Offline) - // } - // - // if err != nil { - // return err - // } - // - // json, err := getSignatureJSON(cliCtx.JSONMarshaler, newTx, cliCtx.Indent, generateSignatureOnly) - // if err != nil { - // return err - // } - // - // if viper.GetString(flagOutfile) == "" { - // fmt.Printf("%s\n", json) - // return nil - // } - // - // fp, err := os.OpenFile( - // viper.GetString(flagOutfile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644, - // ) - // if err != nil { - // return err - // } - // - // defer fp.Close() - // fmt.Fprintf(fp, "%s\n", json) - // - // return nil - //} + return func(cmd *cobra.Command, args []string) error { + //cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) + //if err != nil { + // return err + //} + // + //// if --signature-only is on, then override --append + //var newTx types.StdTx + //generateSignatureOnly := viper.GetBool(flagSigOnly) + //multisigAddrStr := viper.GetString(flagMultisig) + // + //if multisigAddrStr != "" { + // var multisigAddr sdk.AccAddress + // + // multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr) + // if err != nil { + // return err + // } + // newTx, err = client.SignStdTxWithSignerAddress( + // txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, cliCtx.Offline, + // ) + // generateSignatureOnly = true + //} else { + // appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly + // newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, cliCtx.Offline) + //} + // + //if err != nil { + // return err + //} + // + //json, err := getSignatureJSON(cliCtx.JSONMarshaler, newTx, cliCtx.Indent, generateSignatureOnly) + //if err != nil { + // return err + //} + // + //if viper.GetString(flagOutfile) == "" { + // fmt.Printf("%s\n", json) + // return nil + //} + // + //fp, err := os.OpenFile( + // viper.GetString(flagOutfile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644, + //) + //if err != nil { + // return err + //} + // + //defer fp.Close() + //fmt.Fprintf(fp, "%s\n", json) + // + //return nil + panic("TODO: fix") + } } func getSignatureJSON(cdc codec.JSONMarshaler, newTx types.StdTx, indent, generateSignatureOnly bool) ([]byte, error) { diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 5c92f5796192..ffd872b79016 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -112,7 +112,7 @@ func printAndValidateSigs( } switch sig := sig.(type) { - case *txtypes.SingleSignature: + case *txtypes.SingleSignatureData: signingData.Mode = sig.SignMode sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) if err != nil { @@ -124,7 +124,7 @@ func printAndValidateSigs( sigSanity = "ERROR: signature invalid" success = false } - case *txtypes.MultiSignature: + case *txtypes.MultiSignatureData: multiPK, ok := pubKey.(multisig2.MultisigPubKey) if ok { if !multiPK.VerifyMultisignature(func(mode txtypes.SignMode) ([]byte, error) { diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 0c40522ca844..0c21188d5c4c 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -3,7 +3,9 @@ package client import ( "encoding/json" "errors" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec/legacy_global" + "github.com/cosmos/cosmos-sdk/types/tx" "io/ioutil" "os" "testing" @@ -130,9 +132,11 @@ func TestReadStdTxFromFile(t *testing.T) { defer os.Remove(jsonTxFile.Name()) // Read it back - decodedTx, err := ReadTxFromFile(cdc, jsonTxFile.Name()) + cliCtx := context.CLIContext{} + cliCtx = cliCtx.WithTxJSONDecoder(authtypes.DefaultJSONTxDecoder(cdc)) + decodedTx, err := ReadTxFromFile(cliCtx, jsonTxFile.Name()) require.NoError(t, err) - require.Equal(t, decodedTx.Memo, "foomemo") + require.Equal(t, decodedTx.(types.TxWithMemo).GetMemo(), "foomemo") } func compareEncoders(t *testing.T, expected sdk.TxEncoder, actual sdk.TxEncoder) { diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index c60b1fa4f48b..4b949e666a47 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -2,12 +2,13 @@ package types import ( "fmt" - types "github.com/cosmos/cosmos-sdk/types/tx" - "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" + "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" ) // StdTxBuilder wraps StdTx to implement to the context.TxBuilder interface @@ -28,42 +29,50 @@ func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { return nil } -// GetSignatures implements TxBuilder.GetSignatures -func (s StdTxBuilder) GetSignatures() []sdk.Signature { - res := make([]sdk.Signature, len(s.Signatures)) - for i, sig := range s.Signatures { - res[i] = sig +func SignatureDataToSig(data types.SignatureData) []byte { + switch data := data.(type) { + case *types.SingleSignatureData: + return data.Signature + case *types.MultiSignatureData: + n := len(data.Signatures) + sigs := make([][]byte, n) + for i, s := range data.Signatures { + sigs[i] = SignatureDataToSig(s) + } + msig := multisig.AminoMultisignature{ + BitArray: data.BitArray, + Sigs: sigs, + } + return legacy_global.Cdc.MustMarshalBinaryBare(msig) + default: + panic("unexpected case") } - return res } // SetSignatures implements TxBuilder.SetSignatures -func (s *StdTxBuilder) SetSignatures(signatures ...context.ClientSignature) error { +func (s *StdTxBuilder) SetSignatures(signatures ...context.SignatureBuilder) error { sigs := make([]StdSignature, len(signatures)) for i, sig := range signatures { - pubKey := sig.GetPubKey() + pubKey := sig.PubKey var pubKeyBz []byte if pubKey != nil { pubKeyBz = pubKey.Bytes() } sigs[i] = StdSignature{ PubKey: pubKeyBz, - Signature: sig.GetSignature(), + Signature: SignatureDataToSig(sig.Data), } } s.Signatures = sigs return nil } -// GetFee implements TxBuilder.GetFee -func (s StdTxBuilder) GetFee() sdk.Fee { - return s.Fee +func (s *StdTxBuilder) SetFee(amount sdk.Coins) { + s.Fee.Amount = amount } -// SetFee implements TxBuilder.SetFee -func (s *StdTxBuilder) SetFee(fee context.ClientFee) error { - s.Fee = StdFee{Amount: fee.GetAmount(), Gas: fee.GetGas()} - return nil +func (s *StdTxBuilder) SetGasLimit(limit uint64) { + s.Fee.Gas = limit } // SetMemo implements TxBuilder.SetMemo @@ -92,50 +101,19 @@ func (s StdTxGenerator) NewTxBuilder() context.TxBuilder { return &StdTxBuilder{} } -// NewFee implements TxGenerator.NewFee -func (s StdTxGenerator) NewFee() context.ClientFee { - return &StdFee{} -} - -// NewSignature implements TxGenerator.NewSignature -func (s StdTxGenerator) NewSignature() context.ClientSignature { - return &StdSignature{} -} - // MarshalTx implements TxGenerator.MarshalTx func (s StdTxGenerator) TxEncoder() sdk.TxEncoder { return DefaultTxEncoder(s.Cdc) } -var _ context.ClientFee = &StdFee{} - -// SetGas implements ClientFee.SetGas -func (fee *StdFee) SetGas(gas uint64) { - fee.Gas = gas -} - -// SetAmount implements ClientFee.SetAmount -func (fee *StdFee) SetAmount(coins sdk.Coins) { - fee.Amount = coins -} - -var _ context.ClientSignature = &StdSignature{} - -// SetPubKey implements ClientSignature.SetPubKey -func (ss *StdSignature) SetPubKey(key crypto.PubKey) error { - ss.PubKey = key.Bytes() - return nil -} - -// SetSignature implements ClientSignature.SetSignature -func (ss *StdSignature) SetSignature(bytes []byte) { - ss.Signature = bytes -} - type LegacyAminoJSONHandler struct{} var _ types.SignModeHandler = LegacyAminoJSONHandler{} +func (h LegacyAminoJSONHandler) DefaultMode() types.SignMode { + return types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON +} + func (LegacyAminoJSONHandler) Modes() []types.SignMode { return []types.SignMode{types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 499074b58832..1fc55ff556de 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -279,12 +279,12 @@ func (tx StdTx) FeePayer() sdk.AccAddress { return sdk.AccAddress{} } -func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureV2 { +func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureData { switch pk := pk.(type) { case multisig2.MultisigPubKey: var multisignature multisig.Multisignature legacy_global.Cdc.MustUnmarshalBinaryBare(sig, &multisignature) - sigs := make([]types.SignatureV2, len(multisignature.Sigs)) + sigs := make([]types.SignatureData, len(multisignature.Sigs)) size := multisignature.BitArray.Size() sigIndex := 0 pubKeys := pk.GetPubKeys() @@ -296,7 +296,7 @@ func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureV2 { } } - return &types.MultiSignature{ + return &types.MultiSignatureData{ BitArray: &types2.CompactBitArray{ ExtraBitsStored: uint32(multisignature.BitArray.ExtraBitsStored), Elems: multisignature.BitArray.Elems, @@ -304,16 +304,16 @@ func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureV2 { Signatures: sigs, } default: - return &types.SingleSignature{ + return &types.SingleSignatureData{ SignMode: types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, Signature: sig, } } } -func (tx StdTx) GetSignaturesV2() ([]types.SignatureV2, error) { +func (tx StdTx) GetSignaturesV2() ([]types.SignatureData, error) { sigs := tx.Signatures - res := make([]types.SignatureV2, len(sigs)) + res := make([]types.SignatureData, len(sigs)) for i, sig := range sigs { res[i] = stdSignatureToSignatureV2(sig.GetPubKey(), sig.Signature) } From b0e72fc320d61ee3b522892c455199e72eb383d9 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 29 May 2020 14:19:58 -0400 Subject: [PATCH 48/54] fixes --- simapp/helpers/test_helpers.go | 2 +- types/result_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index a049bebd6c80..e21301861d9b 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -56,7 +56,7 @@ func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64 for i, p := range priv { // use a empty chainID for ease of testing signBytes, err := gen.SignModeHandler().GetSignBytes(types.SigningData{ - Mode: 0, + Mode: signMode, PublicKey: nil, ChainID: chainID, AccountNumber: accnums[i], diff --git a/types/result_test.go b/types/result_test.go index 3c5f97ff36a8..c5be8d15a5ba 100644 --- a/types/result_test.go +++ b/types/result_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/stretchr/testify/require" @@ -28,6 +30,7 @@ func TestParseABCILog(t *testing.T) { func TestABCIMessageLog(t *testing.T) { t.Parallel() + cdc := codec.New() events := sdk.Events{sdk.NewEvent("transfer", sdk.NewAttribute("sender", "foo"))} msgLog := sdk.NewABCIMessageLog(0, "", events) From a9d954405fd1a7a607c736ff742ea4323fbb9279 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 1 Jun 2020 12:18:23 -0400 Subject: [PATCH 49/54] fix tests --- client/context/tx_generator.go | 2 +- client/tx/tx_test.go | 4 +++- crypto/multisig/multisignature.go | 2 +- types/tx/signing/tx_builder.go | 2 +- types/tx/tx.go | 4 ++-- x/auth/ante/sigverify_proto.go | 2 +- x/auth/client/cli/validate_sigs.go | 2 +- x/auth/types/client_tx.go | 6 +++++- x/auth/types/stdtx.go | 2 +- 9 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/context/tx_generator.go b/client/context/tx_generator.go index 5fa8b781d539..16fbd02345ab 100644 --- a/client/context/tx_generator.go +++ b/client/context/tx_generator.go @@ -23,7 +23,7 @@ type ( // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. TxBuilder interface { - GetTx() sdk.Tx + GetTx() types.SigTx SetMsgs(msgs ...sdk.Msg) error SetSignatures(signatures ...SignatureBuilder) error diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 2e8f9ebef4f5..d1cfb9718f79 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -105,5 +105,7 @@ func TestBuildUnsignedTx(t *testing.T) { tx, err := tx.BuildUnsignedTx(txf, msg) require.NoError(t, err) require.NotNil(t, tx) - require.Equal(t, []sdk.Signature{}, tx.GetSignatures()) + sigData, err := tx.GetTx().GetSignatureData() + require.NoError(t, err) + require.Empty(t, sigData) } diff --git a/crypto/multisig/multisignature.go b/crypto/multisig/multisignature.go index ce730466cc03..855f47c34f1a 100644 --- a/crypto/multisig/multisignature.go +++ b/crypto/multisig/multisignature.go @@ -19,7 +19,7 @@ type AminoMultisignature struct { // NewMultisig returns a new MultiSignatureData func NewMultisig(n int) *tx.MultiSignatureData { - return &tx.MultiSignatureData{BitArray: types.NewCompactBitArray(n), Signatures: make([]tx.SignatureData, n)} + return &tx.MultiSignatureData{BitArray: types.NewCompactBitArray(n), Signatures: make([]tx.SignatureData, 0, n)} } // GetIndex returns the index of pk in keys. Returns -1 if not found diff --git a/types/tx/signing/tx_builder.go b/types/tx/signing/tx_builder.go index d84987504ce2..b3fe41958f69 100644 --- a/types/tx/signing/tx_builder.go +++ b/types/tx/signing/tx_builder.go @@ -21,7 +21,7 @@ type TxBuilder struct { var _ context.TxBuilder = TxBuilder{} -func (t TxBuilder) GetTx() sdk.Tx { +func (t TxBuilder) GetTx() types.SigTx { return t.Tx } diff --git a/types/tx/tx.go b/types/tx/tx.go index a05023b7233c..82e954844541 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -175,10 +175,10 @@ type SigTx interface { GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignaturesV2() ([]SignatureData, error) + GetSignatureData() ([]SignatureData, error) } -func (m *Tx) GetSignaturesV2() ([]SignatureData, error) { +func (m *Tx) GetSignatureData() ([]SignatureData, error) { signerInfos := m.AuthInfo.SignerInfos sigs := m.Signatures n := len(signerInfos) diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 4e2893c7f345..0e14c4a64215 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -32,7 +32,7 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. - sigs, err := sigTx.GetSignaturesV2() + sigs, err := sigTx.GetSignatureData() if err != nil { return ctx, err } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index ffd872b79016..34d8780a9c90 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -69,7 +69,7 @@ func printAndValidateSigs( } success := true - sigs, err := sigTx.GetSignaturesV2() + sigs, err := sigTx.GetSignatureData() if err != nil { panic(err) } diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 4b949e666a47..fadc02857390 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -19,7 +19,7 @@ type StdTxBuilder struct { var _ context.TxBuilder = &StdTxBuilder{} // GetTx implements TxBuilder.GetTx -func (s *StdTxBuilder) GetTx() sdk.Tx { +func (s *StdTxBuilder) GetTx() types.SigTx { return s.StdTx } @@ -30,6 +30,10 @@ func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { } func SignatureDataToSig(data types.SignatureData) []byte { + if data == nil { + return nil + } + switch data := data.(type) { case *types.SingleSignatureData: return data.Signature diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 1fc55ff556de..8fb76ee717ab 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -311,7 +311,7 @@ func stdSignatureToSignatureV2(pk crypto.PubKey, sig []byte) types.SignatureData } } -func (tx StdTx) GetSignaturesV2() ([]types.SignatureData, error) { +func (tx StdTx) GetSignatureData() ([]types.SignatureData, error) { sigs := tx.Signatures res := make([]types.SignatureData, len(sigs)) for i, sig := range sigs { From a71dcc6324f59b38e7ca217cbc2d9198eddd6d99 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 1 Jun 2020 12:44:04 -0400 Subject: [PATCH 50/54] fixes --- client/context.go | 2 +- client/rpc/block.go | 3 +-- client/tx/tx.go | 4 ++-- simapp/cmd/simcli/proto.go | 6 +++--- simapp/helpers/test_helpers.go | 10 +++++----- simapp/params/encoding.go | 4 ++-- simapp/test_helpers.go | 6 +++--- types/tx/signing/amino.go | 8 ++++---- types/tx/signing/tx_builder.go | 6 +++--- types/tx/signing/tx_generator.go | 7 ++++--- x/auth/client/cli/broadcast.go | 5 +++-- x/auth/client/cli/encode.go | 8 ++++---- x/auth/client/cli/tx.go | 3 +-- x/auth/client/cli/tx_multisign.go | 20 ++++++++++---------- x/auth/client/cli/tx_sign.go | 11 ++++++----- x/auth/client/cli/validate_sigs.go | 20 ++++++++++---------- x/auth/client/tx.go | 6 +++--- x/genutil/client/cli/gentx.go | 1 - 18 files changed, 65 insertions(+), 65 deletions(-) diff --git a/client/context.go b/client/context.go index 65ebab70b66c..7356de4c7bf1 100644 --- a/client/context.go +++ b/client/context.go @@ -201,7 +201,7 @@ func (ctx Context) WithJSONMarshaler(m codec.JSONMarshaler) Context { } // WithTxJSONDecoder returns a copy of the CLIContext with an updated JSONMarshaler. -func (ctx CLIContext) WithTxJSONDecoder(dec sdk.TxDecoder) CLIContext { +func (ctx Context) WithTxJSONDecoder(dec sdk.TxDecoder) Context { ctx.TxJSONDecoder = dec return ctx } diff --git a/client/rpc/block.go b/client/rpc/block.go index f94059795546..e6dd71e701c4 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -2,11 +2,10 @@ package rpc import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "net/http" "strconv" - "github.com/cosmos/cosmos-sdk/codec/legacy_global" + "github.com/cosmos/cosmos-sdk/codec" "github.com/gorilla/mux" "github.com/spf13/cobra" diff --git a/client/tx/tx.go b/client/tx/tx.go index 7275f06d6930..523f8ba9c85e 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -237,7 +237,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { // Create an empty signature literal as the ante handler will populate with a // sentinel pubkey. - sig := context.SignatureBuilder{} + sig := client.SignatureBuilder{} if err := tx.SetSignatures(sig); err != nil { return nil, err @@ -328,7 +328,7 @@ func Sign(txf Factory, name string, tx client.TxBuilder) ([]byte, error) { SignMode: signMode, Signature: nil, } - sig := context.SignatureBuilder{ + sig := client.SignatureBuilder{ PubKey: pubKey, Data: sigData, } diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index aeacfd4515a6..fbea003b986e 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -3,13 +3,13 @@ package main import ( - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func MakeTxCLIContext() context.CLIContext { - cliCtx := context.CLIContext{} +func MakeTxCLIContext() client.Context { + cliCtx := client.Context{} protoCdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) return cliCtx. WithJSONMarshaler(protoCdc). diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index e21301861d9b..7ab9ffdc06aa 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -4,9 +4,9 @@ import ( "math/rand" "time" - types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/context" + types "github.com/cosmos/cosmos-sdk/types/tx" "github.com/tendermint/tendermint/crypto" @@ -21,8 +21,8 @@ const ( ) // GenTx generates a signed mock transaction. -func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) sdk.Tx { - sigs := make([]context.SignatureBuilder, len(priv)) +func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) sdk.Tx { + sigs := make([]client.SignatureBuilder, len(priv)) // create a random length memo r := rand.New(rand.NewSource(time.Now().UnixNano())) @@ -32,7 +32,7 @@ func GenTx(gen context.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64 signMode := gen.SignModeHandler().DefaultMode() for i, p := range priv { - sigs[i] = context.SignatureBuilder{ + sigs[i] = client.SignatureBuilder{ PubKey: p.PubKey(), Data: &types.SingleSignatureData{ SignMode: signMode, diff --git a/simapp/params/encoding.go b/simapp/params/encoding.go index 5f2f5d04a778..c5fa2b8ce89a 100644 --- a/simapp/params/encoding.go +++ b/simapp/params/encoding.go @@ -1,7 +1,7 @@ package params import ( - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,6 +12,6 @@ type EncodingConfig struct { Marshaler codec.Marshaler TxDecoder sdk.TxDecoder TxJSONDecoder sdk.TxDecoder - TxGenerator context.TxGenerator + TxGenerator client.TxGenerator Amino *codec.Codec } diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 22e8df873524..841efac11e32 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -7,7 +7,7 @@ import ( "strconv" "testing" - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -241,7 +241,7 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.C // the parameter 'expPass' against the result. A corresponding result is // returned. func SignCheckDeliver( - t *testing.T, txGen context.TxGenerator, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg, + t *testing.T, txGen client.TxGenerator, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg, accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { tx := helpers.GenTx( @@ -290,7 +290,7 @@ func SignCheckDeliver( // GenSequenceOfTxs generates a set of signed transactions of messages, such // that they differ only by having the sequence numbers incremented between // every transaction. -func GenSequenceOfTxs(txGen context.TxGenerator, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []sdk.Tx { +func GenSequenceOfTxs(txGen client.TxGenerator, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []sdk.Tx { txs := make([]sdk.Tx, numToGenerate) for i := 0; i < numToGenerate; i++ { txs[i] = helpers.GenTx(txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, "", accNums, initSeqNums, priv...) diff --git a/types/tx/signing/amino.go b/types/tx/signing/amino.go index 899063c7286e..92d017867464 100644 --- a/types/tx/signing/amino.go +++ b/types/tx/signing/amino.go @@ -1,17 +1,17 @@ package signing import ( + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/legacy_global" multisig2 "github.com/cosmos/cosmos-sdk/crypto/multisig" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types/tx" auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen context.TxGenerator) sdk.TxDecoder { +func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen client.TxGenerator) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { var aminoTx auth.StdTx err := aminoJsonMarshaler.UnmarshalJSON(txBytes, &aminoTx) @@ -32,7 +32,7 @@ func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen context.Tx txBuilder.SetGasLimit(aminoTx.Fee.Gas) n := len(aminoTx.Signatures) - clientSigs := make([]context.SignatureBuilder, n) + clientSigs := make([]client.SignatureBuilder, n) sigs := aminoTx.Signatures for i := 0; i < n; i++ { @@ -40,7 +40,7 @@ func AminoJSONTxDecoder(aminoJsonMarshaler codec.JSONMarshaler, txGen context.Tx if err != nil { return nil, err } - clientSigs[i] = context.SignatureBuilder{ + clientSigs[i] = client.SignatureBuilder{ PubKey: sigs[i].GetPubKey(), Data: data, } diff --git a/types/tx/signing/tx_builder.go b/types/tx/signing/tx_builder.go index b3fe41958f69..3a431533e955 100644 --- a/types/tx/signing/tx_builder.go +++ b/types/tx/signing/tx_builder.go @@ -5,7 +5,7 @@ import ( "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -19,7 +19,7 @@ type TxBuilder struct { PubKeyCodec cryptotypes.PublicKeyCodec } -var _ context.TxBuilder = TxBuilder{} +var _ client.TxBuilder = TxBuilder{} func (t TxBuilder) GetTx() types.SigTx { return t.Tx @@ -84,7 +84,7 @@ func SignatureDataToSignerInfoSig(data types.SignatureData) (*types.ModeInfo, [] } } -func (t TxBuilder) SetSignatures(signatures ...context.SignatureBuilder) error { +func (t TxBuilder) SetSignatures(signatures ...client.SignatureBuilder) error { n := len(signatures) signerInfos := make([]*types.SignerInfo, n) rawSigs := make([][]byte, n) diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index 512700b01a86..3ba28c90a01b 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -3,9 +3,10 @@ package signing import ( "fmt" + "github.com/cosmos/cosmos-sdk/client" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types/tx" @@ -21,9 +22,9 @@ func NewTxGenerator(marshaler codec.Marshaler, pubKeyCodec cryptotypes.PublicKey return &TxGenerator{Marshaler: marshaler, PubKeyCodec: cryptotypes.CacheWrapCodec(pubKeyCodec), ModeHandler: handler} } -var _ context.TxGenerator = TxGenerator{} +var _ client.TxGenerator = TxGenerator{} -func (t TxGenerator) NewTxBuilder() context.TxBuilder { +func (t TxGenerator) NewTxBuilder() client.TxBuilder { return TxBuilder{ Tx: types.NewTx(), Marshaler: t.Marshaler, diff --git a/x/auth/client/cli/broadcast.go b/x/auth/client/cli/broadcast.go index 72b29addf5b6..0437dd196eb1 100644 --- a/x/auth/client/cli/broadcast.go +++ b/x/auth/client/cli/broadcast.go @@ -4,12 +4,13 @@ import ( "errors" "strings" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" ) // GetBroadcastCommand returns the tx broadcast command. @@ -32,7 +33,7 @@ $ tx broadcast ./mytxn.json return errors.New("cannot broadcast tx during offline mode") } - stdTx, err := client.ReadTxFromFile(clientCtx, args[0]) + stdTx, err := authclient.ReadTxFromFile(clientCtx, args[0]) if err != nil { return err } diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index 4b511225b690..653f8b389a1a 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/x/auth/client" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" ) // txEncodeRespStr implements a simple Stringer wrapper for a encoded tx. @@ -19,7 +19,7 @@ func (txr txEncodeRespStr) String() string { // GetEncodeCommand returns the encode command to take a JSONified transaction and turn it into // Amino-serialized bytes -func GetEncodeCommand(cliCtx client.Context) *cobra.Command { +func GetEncodeCommand(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "encode [file]", Short: "Encode transactions generated offline", @@ -28,9 +28,9 @@ Read a transaction from , serialize it to the Amino wire protocol, and out If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { - cliCtx := cliCtx.Init() + cliCtx := clientCtx.Init() - tx, err := client.ReadTxFromFile(cliCtx, args[0]) + tx, err := authclient.ReadTxFromFile(cliCtx, args[0]) if err != nil { return } diff --git a/x/auth/client/cli/tx.go b/x/auth/client/cli/tx.go index 01a1827d3b0c..a065c8d9ba74 100644 --- a/x/auth/client/cli/tx.go +++ b/x/auth/client/cli/tx.go @@ -1,7 +1,6 @@ package cli import ( - "github.com/cosmos/cosmos-sdk/client/context" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" @@ -9,7 +8,7 @@ import ( ) // GetTxCmd returns the transaction commands for this module -func GetTxCmd(ctx context.CLIContext) *cobra.Command { +func GetTxCmd(ctx client.Context) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Auth transaction subcommands", diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 943ace93970f..45fa61c1fa07 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -26,7 +26,7 @@ import ( ) // GetSignCommand returns the sign command -func GetMultiSignCommand(ctx context.CLIContext) *cobra.Command { +func GetMultiSignCommand(ctx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "multisign [file] [name] [[signature]...]", Short: "Generate multisig signatures for transactions generated offline", @@ -106,7 +106,7 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] // read each signature and add it to the multisig if valid for i := 2; i < len(args); i++ { - stdSig, err := readAndUnmarshalStdSignature(cliCtx, args[i]) + stdSig, err := readAndUnmarshalStdSignature(clientCtx, args[i]) if err != nil { return err } @@ -124,20 +124,20 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] } } - newStdSig := types.StdSignature{Signature: cliCtx.Codec.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck - newTx := types.NewStdTx(stdTx.GetMsgs(), fee, []types.StdSignature{newStdSig}, memoTx.GetMemo()) //nolint:staticcheck + newStdSig := types.StdSignature{Signature: clientCtx.Codec.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck + newTx := types.NewStdTx(stdTx.GetMsgs(), fee, []types.StdSignature{newStdSig}, memoTx.GetMemo()) //nolint:staticcheck sigOnly := viper.GetBool(flagSigOnly) var json []byte switch { case sigOnly && clientCtx.Indent: - json, err = codec.MarshalJSONIndent(cliCtx.JSONMarshaler, newTx.Signatures[0]) + json, err = codec.MarshalJSONIndent(clientCtx.JSONMarshaler, newTx.Signatures[0]) case sigOnly && !clientCtx.Indent: - json, err = cliCtx.JSONMarshaler.MarshalJSON(newTx.Signatures[0]) + json, err = clientCtx.JSONMarshaler.MarshalJSON(newTx.Signatures[0]) case !sigOnly && clientCtx.Indent: - json, err = codec.MarshalJSONIndent(cliCtx.JSONMarshaler, newTx) + json, err = codec.MarshalJSONIndent(clientCtx.JSONMarshaler, newTx) default: - json, err = cliCtx.JSONMarshaler.MarshalJSON(newTx) + json, err = clientCtx.JSONMarshaler.MarshalJSON(newTx) } if err != nil { return err @@ -162,12 +162,12 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] } } -func readAndUnmarshalStdSignature(cliContext context.CLIContext, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck +func readAndUnmarshalStdSignature(clientCtx client.Context, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck var bytes []byte if bytes, err = ioutil.ReadFile(filename); err != nil { return } - if err = cliContext.JSONMarshaler.UnmarshalJSON(bytes, &stdSig); err != nil { + if err = clientCtx.JSONMarshaler.UnmarshalJSON(bytes, &stdSig); err != nil { return } return diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index ee9d00048464..bcb1df11d3dc 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -1,12 +1,13 @@ package cli import ( - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/spf13/cobra" - "github.com/spf13/viper" ) const ( @@ -17,7 +18,7 @@ const ( ) // GetSignCommand returns the transaction sign command. -func GetSignCommand(ctx context.CLIContext) *cobra.Command { +func GetSignCommand(ctx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "sign [file]", Short: "Sign transactions generated offline", @@ -66,7 +67,7 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } } -func makeSignCmd(cdc context.CLIContext) func(cmd *cobra.Command, args []string) error { +func makeSignCmd(cdc client.Context) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { //cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) //if err != nil { diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 48c46eed3c64..52240c4b0e5f 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -17,7 +17,7 @@ import ( authclient "github.com/cosmos/cosmos-sdk/x/auth/client" ) -func GetValidateSignaturesCommand(cliCtx context.CLIContext) *cobra.Command { +func GetValidateSignaturesCommand(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "validate-signatures [file]", Short: "Validate transactions signatures", @@ -30,16 +30,16 @@ given transaction. If the --offline flag is also set, signature validation over transaction will be not be performed as that will require RPC communication with a full node. `, PreRun: preSignCmd, - RunE: makeValidateSignaturesCmd(cliCtx), + RunE: makeValidateSignaturesCmd(clientCtx), Args: cobra.ExactArgs(1), } return flags.PostCommands(cmd)[0] } -func makeValidateSignaturesCmd(cliCtx context.CLIContext) func(cmd *cobra.Command, args []string) error { +func makeValidateSignaturesCmd(clientCtx client.Context) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - clientCtx, txBldr, stdTx, err := readTxAndInitContexts(cliCtx, cmd, args[0]) + clientCtx, txBldr, stdTx, err := readTxAndInitContexts(clientCtx, cmd, args[0]) if err != nil { return err } @@ -59,7 +59,7 @@ func printAndValidateSigs( cmd *cobra.Command, clientCtx client.Context, chainID string, tx sdk.Tx, offline bool, ) bool { sigTx := tx.(txtypes.SigTx) - signModeHandler := cliCtx.TxGenerator.SignModeHandler() + signModeHandler := clientCtx.TxGenerator.SignModeHandler() cmd.Println("Signers:") signers := sigTx.GetSigners() @@ -98,7 +98,7 @@ func printAndValidateSigs( // Validate the actual signature over the transaction bytes since we can // reach out to a full node to query accounts. if !offline && success { - accNum, accSeq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(cliCtx, sigAddr) + accNum, accSeq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, sigAddr) if err != nil { cmd.Printf("failed to get account: %s\n", sigAddr) return false @@ -165,14 +165,14 @@ func printAndValidateSigs( return success } -func readTxAndInitContexts(cliCtx context.CLIContext, cmd *cobra.Command, filename string) (client.Context, tx.Factory, sdk.Tx, error) { - stdTx, err := authclient.ReadTxFromFile(cliCtx, filename) +func readTxAndInitContexts(clientCtx client.Context, cmd *cobra.Command, filename string) (client.Context, tx.Factory, sdk.Tx, error) { + stdTx, err := authclient.ReadTxFromFile(clientCtx, filename) if err != nil { - return cliCtx, tx.Factory{}, nil, err + return clientCtx, tx.Factory{}, nil, err } inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx = cliCtx.InitWithInput(inBuf) + clientCtx = clientCtx.InitWithInput(inBuf) txFactory := tx.NewFactoryFromCLI(inBuf) return clientCtx, txFactory, stdTx, nil diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 1eebb0931b8e..889bade9b62b 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -181,7 +181,7 @@ func PrintUnsignedStdTx(txBldr authtypes.TxBuilder, clientCtx client.Context, ms // SignStdTx appends a signature to a StdTx and returns a copy of it. If appendSig // is false, it replaces the signatures already attached with the new signature. // Don't perform online validation or lookups if offline is true. -func SignStdTx(txBldr tx.Factory, clientCtx client.Context, name string, stdTx context.TxBuilder, appendSig bool, offline bool) (authtypes.StdTx, error) { +func SignStdTx(txBldr tx.Factory, clientCtx client.Context, name string, stdTx client.TxBuilder, appendSig bool, offline bool) (authtypes.StdTx, error) { var signedStdTx authtypes.StdTx @@ -230,7 +230,7 @@ func SignStdTxWithSignerAddress(txBldr tx.Factory, clientCtx client.Context, add } // Read and decode a StdTx from the given filename. Can pass "-" to read from stdin. -func ReadTxFromFile(ctx context.CLIContext, filename string) (tx sdk.Tx, err error) { +func ReadTxFromFile(ctx client.Context, filename string) (tx sdk.Tx, err error) { var bytes []byte if filename == "-" { @@ -248,7 +248,7 @@ func ReadTxFromFile(ctx context.CLIContext, filename string) (tx sdk.Tx, err err func populateAccountFromState(txBldr tx.Factory, clientCtx client.Context, addr sdk.AccAddress) (tx.Factory, error) { - num, seq, err := cliCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, addr) + num, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, addr) if err != nil { return txBldr, err } diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index c7da615c06a4..3afbba045fa7 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -14,7 +14,6 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" From e0cb2039014a60b525d542381d8ae31b9dabd4ab Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 1 Jun 2020 15:30:42 -0400 Subject: [PATCH 51/54] fix tests --- simapp/cmd/simcli/main.go | 2 +- types/tx/signing/json.go | 12 +++++++----- types/tx/tx.go | 5 ++++- x/auth/client/cli/broadcast.go | 7 +++---- x/auth/client/cli/broadcast_test.go | 17 ++++++++++++----- x/auth/client/tx_test.go | 13 +++++++------ 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 2cff129a3c25..853f1ef0cbb9 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -125,7 +125,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { authcmd.GetMultiSignCommand(clientCtx), authcmd.GetValidateSignaturesCommand(clientCtx), flags.LineBreak, - authcmd.GetBroadcastCommand(cdc), + authcmd.GetBroadcastCommand(clientCtx), authcmd.GetEncodeCommand(clientCtx), authcmd.GetDecodeCommand(cdc), flags.LineBreak, diff --git a/types/tx/signing/json.go b/types/tx/signing/json.go index af03cee6c17c..a6df0f311f7a 100644 --- a/types/tx/signing/json.go +++ b/types/tx/signing/json.go @@ -18,11 +18,13 @@ func DefaultJSONTxDecoder(cdc codec.Marshaler, keyCodec cryptotypes.PublicKeyCod } // this decodes pubkeys and makes sure they are cached - signerInfos := tx.AuthInfo.SignerInfos - for _, si := range signerInfos { - _, err := keyCodec.Decode(si.PublicKey) - if err != nil { - return nil, err + if tx.AuthInfo != nil { + signerInfos := tx.AuthInfo.SignerInfos + for _, si := range signerInfos { + _, err := keyCodec.Decode(si.PublicKey) + if err != nil { + return nil, err + } } } diff --git a/types/tx/tx.go b/types/tx/tx.go index 82e954844541..9e1c75c7aca4 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -138,7 +138,10 @@ var _ codectypes.UnpackInterfacesMessage = &TxBody{} var _ codectypes.UnpackInterfacesMessage = &SignDoc{} func (m *Tx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { - return m.Body.UnpackInterfaces(unpacker) + if m.Body != nil { + return m.Body.UnpackInterfaces(unpacker) + } + return nil } func (m *SignDoc) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { diff --git a/x/auth/client/cli/broadcast.go b/x/auth/client/cli/broadcast.go index 0437dd196eb1..7f6ff6b8914c 100644 --- a/x/auth/client/cli/broadcast.go +++ b/x/auth/client/cli/broadcast.go @@ -10,11 +10,10 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" ) // GetBroadcastCommand returns the tx broadcast command. -func GetBroadcastCommand(cdc *codec.Codec) *cobra.Command { +func GetBroadcastCommand(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "broadcast [file_path]", Short: "Broadcast transactions generated offline", @@ -27,7 +26,7 @@ $ tx broadcast ./mytxn.json `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx = clientCtx.Init() if clientCtx.Offline { return errors.New("cannot broadcast tx during offline mode") @@ -38,7 +37,7 @@ $ tx broadcast ./mytxn.json return err } - txBytes, err := clientCtx.Codec.MarshalBinaryBare(stdTx) + txBytes, err := clientCtx.TxGenerator.TxEncoder()(stdTx) if err != nil { return err } diff --git a/x/auth/client/cli/broadcast_test.go b/x/auth/client/cli/broadcast_test.go index 11d41df89e51..6cd1b1806b1e 100644 --- a/x/auth/client/cli/broadcast_test.go +++ b/x/auth/client/cli/broadcast_test.go @@ -5,17 +5,20 @@ import ( "path/filepath" "testing" + "github.com/cosmos/cosmos-sdk/client" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/spf13/viper" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/tests" ) func TestGetBroadcastCommand_OfflineFlag(t *testing.T) { - cdc := codec.New() - cmd := GetBroadcastCommand(cdc) + clientCtx := client.Context{} + clientCtx = clientCtx.WithTxJSONDecoder(simappparams.MakeEncodingConfig().TxJSONDecoder) + cmd := GetBroadcastCommand(clientCtx) viper.Set(flags.FlagOffline, true) @@ -24,8 +27,12 @@ func TestGetBroadcastCommand_OfflineFlag(t *testing.T) { } func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) { - cdc := codec.New() - cmd := GetBroadcastCommand(cdc) + clientCtx := client.Context{} + encodingConfig := simappparams.MakeEncodingConfig() + clientCtx = clientCtx. + WithTxJSONDecoder(encodingConfig.TxJSONDecoder). + WithTxGenerator(encodingConfig.TxGenerator) + cmd := GetBroadcastCommand(clientCtx) viper.Set(flags.FlagOffline, false) diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 0c21188d5c4c..5a955b6bfc56 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -3,13 +3,14 @@ package client import ( "encoding/json" "errors" - "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec/legacy_global" - "github.com/cosmos/cosmos-sdk/types/tx" "io/ioutil" "os" "testing" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec/legacy_global" + types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" @@ -132,9 +133,9 @@ func TestReadStdTxFromFile(t *testing.T) { defer os.Remove(jsonTxFile.Name()) // Read it back - cliCtx := context.CLIContext{} - cliCtx = cliCtx.WithTxJSONDecoder(authtypes.DefaultJSONTxDecoder(cdc)) - decodedTx, err := ReadTxFromFile(cliCtx, jsonTxFile.Name()) + clientCtx := client.Context{} + clientCtx = clientCtx.WithTxJSONDecoder(authtypes.DefaultJSONTxDecoder(cdc)) + decodedTx, err := ReadTxFromFile(clientCtx, jsonTxFile.Name()) require.NoError(t, err) require.Equal(t, decodedTx.(types.TxWithMemo).GetMemo(), "foomemo") } From bfc7e699514dfe3312fccc5999c8183128431273 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 1 Jun 2020 15:32:47 -0400 Subject: [PATCH 52/54] fix amino build --- simapp/cmd/simcli/amino.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/cmd/simcli/amino.go b/simapp/cmd/simcli/amino.go index 0659ba8c94ea..4e1dffa90d7d 100644 --- a/simapp/cmd/simcli/amino.go +++ b/simapp/cmd/simcli/amino.go @@ -3,13 +3,13 @@ package main import ( - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func MakeTxCLIContext() context.CLIContext { - cliCtx := context.CLIContext{} +func MakeTxCLIContext() client.Context { + cliCtx := client.Context{} aminoCdc := codec.NewAminoCodec(encodingConfig.Amino) return cliCtx. WithJSONMarshaler(aminoCdc). From 8598372d3993ececcd97df461515707e4a005da8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 1 Jun 2020 15:54:17 -0400 Subject: [PATCH 53/54] fix tests --- client/context.go | 7 ------- client/tx_generator.go | 5 ++++- crypto/multisig/threshold_pubkey_test.go | 10 ++++------ simapp/app.go | 2 +- simapp/cmd/simcli/amino.go | 1 - simapp/cmd/simcli/main.go | 6 +++--- simapp/cmd/simcli/proto.go | 1 - simapp/params/amino.go | 2 -- simapp/params/encoding.go | 3 --- simapp/params/proto.go | 2 -- tests/cli/helpers.go | 2 +- types/tx/signing/tx_generator.go | 14 ++++++++++++++ types/tx/tx.go | 3 +++ x/auth/client/cli/broadcast_test.go | 7 ++----- x/auth/client/cli/decode.go | 19 ++++++++----------- x/auth/client/tx.go | 2 +- x/auth/client/tx_test.go | 17 +++++++++++------ x/auth/types/client_tx.go | 14 ++++++++++++++ 18 files changed, 66 insertions(+), 51 deletions(-) diff --git a/client/context.go b/client/context.go index 7356de4c7bf1..88a96014b83e 100644 --- a/client/context.go +++ b/client/context.go @@ -28,7 +28,6 @@ type Context struct { Client rpcclient.Client ChainID string JSONMarshaler codec.JSONMarshaler - TxJSONDecoder sdk.TxDecoder Input io.Reader Keyring keyring.Keyring Output io.Writer @@ -200,12 +199,6 @@ func (ctx Context) WithJSONMarshaler(m codec.JSONMarshaler) Context { return ctx } -// WithTxJSONDecoder returns a copy of the CLIContext with an updated JSONMarshaler. -func (ctx Context) WithTxJSONDecoder(dec sdk.TxDecoder) Context { - ctx.TxJSONDecoder = dec - return ctx -} - // WithCodec returns a copy of the context with an updated codec. // TODO: Deprecated (remove). func (ctx Context) WithCodec(cdc *codec.Codec) Context { diff --git a/client/tx_generator.go b/client/tx_generator.go index 8eab501a86dd..93e443a3ec23 100644 --- a/client/tx_generator.go +++ b/client/tx_generator.go @@ -3,8 +3,8 @@ package client import ( "github.com/tendermint/tendermint/crypto" - types "github.com/cosmos/cosmos-sdk/types/tx" sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" ) type ( @@ -14,6 +14,9 @@ type ( TxGenerator interface { NewTxBuilder() TxBuilder TxEncoder() sdk.TxEncoder + TxDecoder() sdk.TxDecoder + TxJSONEncoder() sdk.TxEncoder + TxJSONDecoder() sdk.TxDecoder SignModeHandler() types.SignModeHandler } diff --git a/crypto/multisig/threshold_pubkey_test.go b/crypto/multisig/threshold_pubkey_test.go index a77f575ee02e..deb31fe72821 100644 --- a/crypto/multisig/threshold_pubkey_test.go +++ b/crypto/multisig/threshold_pubkey_test.go @@ -4,8 +4,6 @@ import ( "math/rand" "testing" - "github.com/tendermint/tendermint/crypto/multisig" - "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" @@ -133,7 +131,7 @@ func TestThresholdMultisigDuplicateSignatures(t *testing.T) { func TestMultiSigPubKeyEquality(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) - multisigKey := multisig.NewPubKeyMultisigThreshold(2, pubkeys) + multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) var unmarshalledMultisig ThresholdMultisigPubKey cdc.MustUnmarshalBinaryBare(multisigKey.Bytes(), &unmarshalledMultisig) require.True(t, multisigKey.Equals(unmarshalledMultisig)) @@ -143,21 +141,21 @@ func TestMultiSigPubKeyEquality(t *testing.T) { copy(pubkeysCpy, pubkeys) pubkeysCpy[4] = pubkeys[3] pubkeysCpy[3] = pubkeys[4] - multisigKey2 := multisig.NewPubKeyMultisigThreshold(2, pubkeysCpy) + multisigKey2 := NewPubKeyMultisigThreshold(2, pubkeysCpy) require.False(t, multisigKey.Equals(multisigKey2)) } func TestAddress(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) - multisigKey := multisig.NewPubKeyMultisigThreshold(2, pubkeys) + multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) require.Len(t, multisigKey.Address().Bytes(), 20) } func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) - multisigKey := multisig.NewPubKeyMultisigThreshold(2, pubkeys) + multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) ab, err := cdc.MarshalBinaryLengthPrefixed(multisigKey) require.NoError(t, err) diff --git a/simapp/app.go b/simapp/app.go index a64ab6797443..b05d73e62a7a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -146,7 +146,7 @@ func NewSimApp( encodingConfig := MakeEncodingConfig() marshaler := encodingConfig.Marshaler - bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxDecoder, baseAppOptions...) + bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxGenerator.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) diff --git a/simapp/cmd/simcli/amino.go b/simapp/cmd/simcli/amino.go index 4e1dffa90d7d..c04ac9e1d985 100644 --- a/simapp/cmd/simcli/amino.go +++ b/simapp/cmd/simcli/amino.go @@ -14,7 +14,6 @@ func MakeTxCLIContext() client.Context { return cliCtx. WithJSONMarshaler(aminoCdc). WithTxGenerator(encodingConfig.TxGenerator). - WithTxJSONDecoder(encodingConfig.TxJSONDecoder). WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). WithCodec(encodingConfig.Amino) } diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 853f1ef0cbb9..d51ff3585d5c 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -62,7 +62,7 @@ func main() { rpc.StatusCommand(), client.ConfigCmd(simapp.DefaultCLIHome), queryCmd(encodingConfig.Amino), - txCmd(encodingConfig.Amino), + txCmd(), flags.LineBreak, lcd.ServeCommand(encodingConfig.Amino, registerRoutes), flags.LineBreak, @@ -107,7 +107,7 @@ func queryCmd(cdc *codec.Codec) *cobra.Command { return queryCmd } -func txCmd(cdc *codec.Codec) *cobra.Command { +func txCmd() *cobra.Command { txCmd := &cobra.Command{ Use: "tx", Short: "Transactions subcommands", @@ -127,7 +127,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { flags.LineBreak, authcmd.GetBroadcastCommand(clientCtx), authcmd.GetEncodeCommand(clientCtx), - authcmd.GetDecodeCommand(cdc), + authcmd.GetDecodeCommand(clientCtx), flags.LineBreak, ) diff --git a/simapp/cmd/simcli/proto.go b/simapp/cmd/simcli/proto.go index fbea003b986e..6754542a28c7 100644 --- a/simapp/cmd/simcli/proto.go +++ b/simapp/cmd/simcli/proto.go @@ -14,7 +14,6 @@ func MakeTxCLIContext() client.Context { return cliCtx. WithJSONMarshaler(protoCdc). WithTxGenerator(encodingConfig.TxGenerator). - WithTxJSONDecoder(encodingConfig.TxJSONDecoder). WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)). WithCodec(encodingConfig.Amino) } diff --git a/simapp/params/amino.go b/simapp/params/amino.go index e34cdb6118a9..10c91b1ac769 100644 --- a/simapp/params/amino.go +++ b/simapp/params/amino.go @@ -16,8 +16,6 @@ func MakeEncodingConfig() EncodingConfig { return EncodingConfig{ InterfaceRegistry: interfaceRegistry, Marshaler: marshaler, - TxDecoder: authtypes.DefaultTxDecoder(cdc), - TxJSONDecoder: authtypes.DefaultJSONTxDecoder(cdc), TxGenerator: authtypes.StdTxGenerator{Cdc: cdc}, Amino: cdc, } diff --git a/simapp/params/encoding.go b/simapp/params/encoding.go index c5fa2b8ce89a..040e06ddb247 100644 --- a/simapp/params/encoding.go +++ b/simapp/params/encoding.go @@ -4,14 +4,11 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) type EncodingConfig struct { InterfaceRegistry types.InterfaceRegistry Marshaler codec.Marshaler - TxDecoder sdk.TxDecoder - TxJSONDecoder sdk.TxDecoder TxGenerator client.TxGenerator Amino *codec.Codec } diff --git a/simapp/params/proto.go b/simapp/params/proto.go index 56ae43862f45..d02c9a1e38ee 100644 --- a/simapp/params/proto.go +++ b/simapp/params/proto.go @@ -19,8 +19,6 @@ func MakeEncodingConfig() EncodingConfig { return EncodingConfig{ InterfaceRegistry: interfaceRegistry, Marshaler: marshaler, - TxDecoder: signing.DefaultTxDecoder(marshaler, pubKeyCodec), - TxJSONDecoder: signing.DefaultJSONTxDecoder(marshaler, pubKeyCodec), TxGenerator: txGen, Amino: cdc, } diff --git a/tests/cli/helpers.go b/tests/cli/helpers.go index ccb720591e84..87bd2537f395 100644 --- a/tests/cli/helpers.go +++ b/tests/cli/helpers.go @@ -199,7 +199,7 @@ type CLITx interface { } func (f Fixtures) UnmarshalTxJSON(s string) CLITx { - tx, err := f.EncodingConfig.TxJSONDecoder([]byte(s)) + tx, err := f.EncodingConfig.TxGenerator.TxJSONDecoder()([]byte(s)) require.Nil(f.T, err) sigTx, ok := tx.(CLITx) require.True(f.T, ok, "couldn't decode tx") diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index 3ba28c90a01b..78492559a88c 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -42,6 +42,20 @@ func (t TxGenerator) TxEncoder() sdk.TxEncoder { } } +func (t TxGenerator) TxDecoder() sdk.TxDecoder { + return DefaultTxDecoder(t.Marshaler, t.PubKeyCodec) +} + +func (t TxGenerator) TxJSONEncoder() sdk.TxEncoder { + return func(tx sdk.Tx) ([]byte, error) { + return t.Marshaler.MarshalJSON(tx) + } +} + +func (t TxGenerator) TxJSONDecoder() sdk.TxDecoder { + return DefaultJSONTxDecoder(t.Marshaler, t.PubKeyCodec) +} + func (t TxGenerator) SignModeHandler() types.SignModeHandler { return t.ModeHandler } diff --git a/types/tx/tx.go b/types/tx/tx.go index 9e1c75c7aca4..f0c5cba0ea9f 100644 --- a/types/tx/tx.go +++ b/types/tx/tx.go @@ -90,6 +90,9 @@ func (m *Tx) FeePayer() sdk.AccAddress { } func (m *Tx) GetMemo() string { + if m.Body == nil { + return "" + } return m.Body.Memo } diff --git a/x/auth/client/cli/broadcast_test.go b/x/auth/client/cli/broadcast_test.go index 6cd1b1806b1e..2aa881bb0bcc 100644 --- a/x/auth/client/cli/broadcast_test.go +++ b/x/auth/client/cli/broadcast_test.go @@ -17,7 +17,7 @@ import ( func TestGetBroadcastCommand_OfflineFlag(t *testing.T) { clientCtx := client.Context{} - clientCtx = clientCtx.WithTxJSONDecoder(simappparams.MakeEncodingConfig().TxJSONDecoder) + clientCtx = clientCtx.WithTxGenerator(simappparams.MakeEncodingConfig().TxGenerator) cmd := GetBroadcastCommand(clientCtx) viper.Set(flags.FlagOffline, true) @@ -28,10 +28,7 @@ func TestGetBroadcastCommand_OfflineFlag(t *testing.T) { func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) { clientCtx := client.Context{} - encodingConfig := simappparams.MakeEncodingConfig() - clientCtx = clientCtx. - WithTxJSONDecoder(encodingConfig.TxJSONDecoder). - WithTxGenerator(encodingConfig.TxGenerator) + clientCtx = clientCtx.WithTxGenerator(simappparams.MakeEncodingConfig().TxGenerator) cmd := GetBroadcastCommand(clientCtx) viper.Set(flags.FlagOffline, false) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index efd124921b52..2fde4790a39c 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -9,29 +9,27 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) const flagHex = "hex" -// GetDecodeCommand returns the decode command to take Amino-serialized bytes +// GetDecodeCommand returns the decode command to take serialized bytes // and turn it into a JSONified transaction. -func GetDecodeCommand(codec *codec.Codec) *cobra.Command { +func GetDecodeCommand(clientCtx client.Context) *cobra.Command { cmd := &cobra.Command{ Use: "decode [amino-byte-string]", - Short: "Decode an amino-encoded transaction string.", + Short: "Decode an binary encoded transaction string.", Args: cobra.ExactArgs(1), - RunE: runDecodeTxString(codec), + RunE: runDecodeTxString(clientCtx), } cmd.Flags().BoolP(flagHex, "x", false, "Treat input as hexadecimal instead of base64") return flags.PostCommands(cmd)[0] } -func runDecodeTxString(codec *codec.Codec) func(cmd *cobra.Command, args []string) (err error) { +func runDecodeTxString(clientCtx client.Context) func(cmd *cobra.Command, args []string) (err error) { return func(cmd *cobra.Command, args []string) (err error) { - clientCtx := client.NewContext().WithCodec(codec).WithOutput(cmd.OutOrStdout()) + clientCtx = clientCtx.Init().WithOutput(cmd.OutOrStdout()) var txBytes []byte if viper.GetBool(flagHex) { @@ -43,12 +41,11 @@ func runDecodeTxString(codec *codec.Codec) func(cmd *cobra.Command, args []strin return err } - var stdTx authtypes.StdTx - err = clientCtx.Codec.UnmarshalBinaryBare(txBytes, &stdTx) + tx, err := clientCtx.TxGenerator.TxDecoder()(txBytes) if err != nil { return err } - return clientCtx.PrintOutput(stdTx) + return clientCtx.PrintOutput(tx) } } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index 889bade9b62b..bf9f093885b1 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -243,7 +243,7 @@ func ReadTxFromFile(ctx client.Context, filename string) (tx sdk.Tx, err error) return } - return ctx.TxJSONDecoder(bytes) + return ctx.TxGenerator.TxJSONDecoder()(bytes) } func populateAccountFromState(txBldr tx.Factory, clientCtx client.Context, addr sdk.AccAddress) (tx.Factory, error) { diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 5a955b6bfc56..82723282b6d4 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -7,6 +7,8 @@ import ( "os" "testing" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/legacy_global" types "github.com/cosmos/cosmos-sdk/types/tx" @@ -119,22 +121,25 @@ func TestConfiguredTxEncoder(t *testing.T) { compareEncoders(t, customEncoder, encoder) } -func TestReadStdTxFromFile(t *testing.T) { +func TestReadTxFromFile(t *testing.T) { cdc := codec.New() sdk.RegisterCodec(cdc) + txGen := simappparams.MakeEncodingConfig().TxGenerator + clientCtx := client.Context{} + clientCtx = clientCtx.WithTxGenerator(txGen) // Build a test transaction - fee := authtypes.NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)}) - stdTx := authtypes.NewStdTx([]sdk.Msg{}, fee, []authtypes.StdSignature{}, "foomemo") + txBuilder := txGen.NewTxBuilder() + txBuilder.SetGasLimit(50000) + txBuilder.SetFee(sdk.Coins{sdk.NewInt64Coin("atom", 150)}) + txBuilder.SetMemo("foomemo") // Write it to the file - encodedTx, _ := cdc.MarshalJSON(stdTx) + encodedTx, _ := txGen.TxJSONEncoder()(txBuilder.GetTx()) jsonTxFile := writeToNewTempFile(t, string(encodedTx)) defer os.Remove(jsonTxFile.Name()) // Read it back - clientCtx := client.Context{} - clientCtx = clientCtx.WithTxJSONDecoder(authtypes.DefaultJSONTxDecoder(cdc)) decodedTx, err := ReadTxFromFile(clientCtx, jsonTxFile.Name()) require.NoError(t, err) require.Equal(t, decodedTx.(types.TxWithMemo).GetMemo(), "foomemo") diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 48c9c4477317..39d580c32392 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -110,6 +110,20 @@ func (s StdTxGenerator) TxEncoder() sdk.TxEncoder { return DefaultTxEncoder(s.Cdc) } +func (s StdTxGenerator) TxDecoder() sdk.TxDecoder { + return DefaultTxDecoder(s.Cdc) +} + +func (s StdTxGenerator) TxJSONEncoder() sdk.TxEncoder { + return func(tx sdk.Tx) ([]byte, error) { + return s.Cdc.MarshalJSON(tx) + } +} + +func (s StdTxGenerator) TxJSONDecoder() sdk.TxDecoder { + return DefaultJSONTxDecoder(s.Cdc) +} + type LegacyAminoJSONHandler struct{} var _ types.SignModeHandler = LegacyAminoJSONHandler{} From 7241768cd2837a1772f037fe66783d01ae71da30 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 2 Jun 2020 13:15:19 -0400 Subject: [PATCH 54/54] WIP on implementing sign and multisign cmd's --- client/flags/flags.go | 2 + client/tx/factory.go | 10 ++ client/tx/tx.go | 25 +++-- client/tx_generator.go | 2 + simapp/helpers/test_helpers.go | 3 +- types/tx/mode_handler.go | 2 +- types/tx/signature.go | 4 +- types/tx/signing/direct.go | 2 +- types/tx/signing/handler_map.go | 6 +- types/tx/signing/tx_generator.go | 12 +++ types/tx/signing/verify.go | 27 +++++ types/tx/types.proto | 3 + x/auth/ante/sigverify_proto.go | 62 +++--------- x/auth/client/cli/tx_multisign.go | 68 ++++++++----- x/auth/client/cli/tx_sign.go | 154 ++++++++++++++++------------- x/auth/client/cli/validate_sigs.go | 5 +- x/auth/client/tx.go | 43 ++++---- x/auth/types/client_tx.go | 10 +- 18 files changed, 255 insertions(+), 185 deletions(-) create mode 100644 types/tx/signing/verify.go diff --git a/client/flags/flags.go b/client/flags/flags.go index fb4438da722b..78e50c0447dd 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -70,6 +70,7 @@ const ( FlagPage = "page" FlagLimit = "limit" FlagUnsafeCORS = "unsafe-cors" + FlagSignMode = "sign-mode" ) // LineBreak can be included in a command list to provide a blank line @@ -122,6 +123,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command { c.Flags().Bool(FlagOffline, false, "Offline mode (does not allow any online functionality") c.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation") c.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") + c.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature") // --gas can accept integers and "simulate" c.Flags().Var(&GasFlagVar, "gas", fmt.Sprintf( diff --git a/client/tx/factory.go b/client/tx/factory.go index 31fba01d2e30..1568e60f62e9 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -42,6 +42,15 @@ func NewFactoryFromCLI(input io.Reader) Factory { panic(err) } + signModeStr := viper.GetString(flags.FlagSignMode) + signMode := types.SignMode_SIGN_MODE_UNSPECIFIED + switch signModeStr { + case "direct": + signMode = types.SignMode_SIGN_MODE_DIRECT + case "amino-json": + signMode = types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON + } + f := Factory{ keybase: kb, accountNumber: viper.GetUint64(flags.FlagAccountNumber), @@ -51,6 +60,7 @@ func NewFactoryFromCLI(input io.Reader) Factory { simulateAndExecute: flags.GasFlagVar.Simulate, chainID: viper.GetString(flags.FlagChainID), memo: viper.GetString(flags.FlagMemo), + signMode: signMode, } f = f.WithFees(viper.GetString(flags.FlagFees)) diff --git a/client/tx/tx.go b/client/tx/tx.go index 523f8ba9c85e..112318d43739 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -109,7 +109,12 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error { } } - txBytes, err := Sign(txf, clientCtx.GetFromName(), tx) + err = Sign(txf, clientCtx.GetFromName(), tx) + if err != nil { + return err + } + + txBytes, err := clientCtx.TxGenerator.TxEncoder()(tx.GetTx()) if err != nil { return err } @@ -307,9 +312,9 @@ func PrepareFactory(clientCtx client.Context, txf Factory) (Factory, error) { // // Note, It is assumed the Factory has the necessary fields set that are required // by the CanonicalSignBytes call. -func Sign(txf Factory, name string, tx client.TxBuilder) ([]byte, error) { +func Sign(txf Factory, name string, tx client.TxBuilder) error { if txf.keybase == nil { - return nil, errors.New("keybase must be set prior to signing a transaction") + return errors.New("keybase must be set prior to signing a transaction") } signMode := txf.signMode @@ -319,7 +324,7 @@ func Sign(txf Factory, name string, tx client.TxBuilder) ([]byte, error) { key, err := txf.keybase.Key(name) if err != nil { - return nil, err + return err } pubKey := key.GetPubKey() @@ -335,12 +340,12 @@ func Sign(txf Factory, name string, tx client.TxBuilder) ([]byte, error) { err = tx.SetSignatures(sig) if err != nil { - return nil, err + return err } signBytes, err := txf.txGenerator.SignModeHandler().GetSignBytes( + signMode, types.SigningData{ - Mode: signMode, PublicKey: pubKey, ChainID: txf.chainID, AccountNumber: txf.accountNumber, @@ -348,21 +353,21 @@ func Sign(txf Factory, name string, tx client.TxBuilder) ([]byte, error) { }, tx.GetTx(), ) if err != nil { - return nil, err + return err } sigBytes, _, err := txf.keybase.Sign(name, signBytes) if err != nil { - return nil, err + return err } sigData.Signature = sigBytes if err := tx.SetSignatures(sig); err != nil { - return nil, err + return err } - return txf.txGenerator.TxEncoder()(tx.GetTx()) + return nil } // GasEstimateResponse defines a response definition for tx gas estimation. diff --git a/client/tx_generator.go b/client/tx_generator.go index 93e443a3ec23..0e50ca083be2 100644 --- a/client/tx_generator.go +++ b/client/tx_generator.go @@ -13,6 +13,8 @@ type ( // implement TxBuilder. TxGenerator interface { NewTxBuilder() TxBuilder + // WrapTxBuilder wraps an existing tx in a TxBuilder or returns an error + WrapTxBuilder(tx sdk.Tx) (TxBuilder, error) TxEncoder() sdk.TxEncoder TxDecoder() sdk.TxDecoder TxJSONEncoder() sdk.TxEncoder diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 7ab9ffdc06aa..11d558352c07 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -55,8 +55,7 @@ func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, for i, p := range priv { // use a empty chainID for ease of testing - signBytes, err := gen.SignModeHandler().GetSignBytes(types.SigningData{ - Mode: signMode, + signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, types.SigningData{ PublicKey: nil, ChainID: chainID, AccountNumber: accnums[i], diff --git a/types/tx/mode_handler.go b/types/tx/mode_handler.go index b7c3a7524ed7..bfe9223b638e 100644 --- a/types/tx/mode_handler.go +++ b/types/tx/mode_handler.go @@ -17,5 +17,5 @@ type SigningData struct { type SignModeHandler interface { DefaultMode() SignMode Modes() []SignMode - GetSignBytes(data SigningData, tx sdk.Tx) ([]byte, error) + GetSignBytes(mode SignMode, data SigningData, tx sdk.Tx) ([]byte, error) } diff --git a/types/tx/signature.go b/types/tx/signature.go index ad1fc43c045b..7b45c6c72265 100644 --- a/types/tx/signature.go +++ b/types/tx/signature.go @@ -1,6 +1,8 @@ package types -import "github.com/cosmos/cosmos-sdk/crypto/types" +import ( + "github.com/cosmos/cosmos-sdk/crypto/types" +) type SignatureData interface { isSignatureData() diff --git a/types/tx/signing/direct.go b/types/tx/signing/direct.go index e4990f87850d..9db445cc4208 100644 --- a/types/tx/signing/direct.go +++ b/types/tx/signing/direct.go @@ -19,7 +19,7 @@ func (DirectModeHandler) Modes() []types.SignMode { return []types.SignMode{types.SignMode_SIGN_MODE_DIRECT} } -func (DirectModeHandler) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { +func (DirectModeHandler) GetSignBytes(mode types.SignMode, data types.SigningData, tx sdk.Tx) ([]byte, error) { protoTx, ok := tx.(types.ProtoTx) if !ok { return nil, fmt.Errorf("can only get direct sign bytes for a ProtoTx, got %T", tx) diff --git a/types/tx/signing/handler_map.go b/types/tx/signing/handler_map.go index b08b96f5f4cf..043486271a4c 100644 --- a/types/tx/signing/handler_map.go +++ b/types/tx/signing/handler_map.go @@ -44,10 +44,10 @@ func (h HandlerMap) Modes() []types.SignMode { return h.modes } -func (h HandlerMap) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { - handler, found := h.signModeHandlers[data.Mode] +func (h HandlerMap) GetSignBytes(mode types.SignMode, data types.SigningData, tx sdk.Tx) ([]byte, error) { + handler, found := h.signModeHandlers[mode] if !found { return nil, fmt.Errorf("can't verify sign mode %s", data.Mode.String()) } - return handler.GetSignBytes(data, tx) + return handler.GetSignBytes(mode, data, tx) } diff --git a/types/tx/signing/tx_generator.go b/types/tx/signing/tx_generator.go index 78492559a88c..ae467ba18472 100644 --- a/types/tx/signing/tx_generator.go +++ b/types/tx/signing/tx_generator.go @@ -32,6 +32,18 @@ func (t TxGenerator) NewTxBuilder() client.TxBuilder { } } +func (t TxGenerator) WrapTxBuilder(tx sdk.Tx) (client.TxBuilder, error) { + stdTx, ok := tx.(*types.Tx) + if !ok { + return nil, fmt.Errorf("expected %T, got %T", &types.Tx{}, tx) + } + return TxBuilder{ + Tx: stdTx, + Marshaler: t.Marshaler, + PubKeyCodec: t.PubKeyCodec, + }, nil +} + func (t TxGenerator) TxEncoder() sdk.TxEncoder { return func(tx sdk.Tx) ([]byte, error) { ptx, ok := tx.(*types.Tx) diff --git a/types/tx/signing/verify.go b/types/tx/signing/verify.go new file mode 100644 index 000000000000..97566353c940 --- /dev/null +++ b/types/tx/signing/verify.go @@ -0,0 +1,27 @@ +package signing + +import ( + "github.com/cosmos/cosmos-sdk/crypto/multisig" + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types/tx" +) + +func VerifySignature(signingData types.SigningData, sigData types.SignatureData, tx sdk.Tx, handler types.SignModeHandler) bool { + switch data := sigData.(type) { + case *types.SingleSignatureData: + signBytes, err := handler.GetSignBytes(data.SignMode, signingData, tx) + if err != nil { + return false + } + return signingData.PublicKey.VerifyBytes(signBytes, data.Signature) + case *types.MultiSignatureData: + multiPK, ok := signingData.PublicKey.(multisig.MultisigPubKey) + if !ok { + return false + } + return multiPK.VerifyMultisignature(func(mode types.SignMode) ([]byte, error) { + return handler.GetSignBytes(mode, signingData, tx) + }, data) + } + return false +} diff --git a/types/tx/types.proto b/types/tx/types.proto index 44314140a5c6..f6b4c8569d1a 100644 --- a/types/tx/types.proto +++ b/types/tx/types.proto @@ -105,6 +105,8 @@ message ModeInfo { message Single { // mode is the signing mode of the single signer SignMode mode = 1; + + bytes signature = 2; } // Multi is the mode info for a multisig public key @@ -148,3 +150,4 @@ message Fee { // before an out of gas error occurs uint64 gas_limit = 2; } + diff --git a/x/auth/ante/sigverify_proto.go b/x/auth/ante/sigverify_proto.go index 0e14c4a64215..e3dd7b2a3b13 100644 --- a/x/auth/ante/sigverify_proto.go +++ b/x/auth/ante/sigverify_proto.go @@ -1,10 +1,10 @@ package ante import ( - "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" types "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/types/tx/signing" auth "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -61,57 +61,23 @@ func (svd ProtoSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") } - switch sig := sig.(type) { - case *types.SingleSignatureData: - signBytes, err := svd.getSignBytesSingle(ctx, sig.SignMode, signerAcc, sigTx) - if err != nil { - return ctx, err - } + genesis := ctx.BlockHeight() == 0 + var accNum uint64 + if !genesis { + accNum = signerAcc.GetAccountNumber() + } - // verify signature - if !simulate && !pubKey.VerifyBytes(signBytes, sig.Signature) { - return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") - } - case *types.MultiSignatureData: - multisigPubKey, ok := pubKey.(multisig.MultisigPubKey) - if !ok { - return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "key is not a multisig pubkey, but ModeInfo.Multi is used") - } + data := types.SigningData{ + PublicKey: signerAcc.GetPubKey(), + ChainID: ctx.ChainID(), + AccountNumber: accNum, + AccountSequence: signerAcc.GetSequence(), + } - if !simulate { - if !multisigPubKey.VerifyMultisignature( - func(mode types.SignMode) ([]byte, error) { - return svd.getSignBytesSingle(ctx, mode, signerAcc, sigTx) - }, sig, - ) { - return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") - } - } - default: - panic("unexpected ModeInfo type") + if !signing.VerifySignature(data, sig, tx, svd.handler) { + return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "signature verification failed; verify correct account sequence and chain-id") } } return next(ctx, tx, simulate) } - -func (svd ProtoSigVerificationDecorator) getSignBytesSingle(ctx sdk.Context, signMode types.SignMode, signerAcc auth.AccountI, sigTx types.ProtoTx) ([]byte, error) { - verifier := svd.handler - genesis := ctx.BlockHeight() == 0 - var accNum uint64 - if !genesis { - accNum = signerAcc.GetAccountNumber() - } - data := types.SigningData{ - Mode: signMode, - PublicKey: signerAcc.GetPubKey(), - ChainID: ctx.ChainID(), - AccountNumber: accNum, - AccountSequence: signerAcc.GetSequence(), - } - signBytes, err := verifier.GetSignBytes(data, sigTx) - if err != nil { - return nil, err - } - return signBytes, nil -} diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 45fa61c1fa07..7c4cc625d3c1 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -3,10 +3,11 @@ package cli import ( "bufio" "fmt" - "io/ioutil" "os" "strings" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" types2 "github.com/cosmos/cosmos-sdk/types/tx" @@ -14,11 +15,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/tendermint/crypto/multisig" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/multisig" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -82,10 +82,10 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType()) } - multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold) - multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) + multisigPub := multisigInfo.GetPubKey().(multisig.MultisigPubKey) + multisigSig := multisig.NewMultisig(len(multisigPub.GetPubKeys())) clientCtx := clientCtx.InitWithInput(inBuf) - txBldr := tx.NewFactoryFromCLI(inBuf) + txFactory := tx.NewFactoryFromCLI(inBuf) if !clientCtx.Offline { accnum, seq, err := types.NewAccountRetriever(authclient.Codec).GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) @@ -93,7 +93,7 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] return err } - txBldr = txBldr.WithAccountNumber(accnum).WithSequence(seq) + txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq) } feeTx := stdTx.(types2.FeeTx) @@ -111,15 +111,18 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] return err } + signingData := types2.SigningData{ + PublicKey: stdSig.PubKey, + ChainID: txFactory.ChainID(), + AccountNumber: txFactory.AccountNumber(), + AccountSequence: txFactory.Sequence(), + } + // Validate each signature - sigBytes := types.StdSignBytes( - txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(), - fee, stdTx.GetMsgs(), memoTx.GetMemo(), - ) - if ok := stdSig.GetPubKey().VerifyBytes(sigBytes, stdSig.Signature); !ok { + if ok := signing.VerifySignature(signingData, stdSig.Data, stdTx, clientCtx.TxGenerator.SignModeHandler()); !ok { return fmt.Errorf("couldn't verify signature") } - if err := multisigSig.AddSignatureFromPubKey(stdSig.Signature, stdSig.GetPubKey(), multisigPub.PubKeys); err != nil { + if err := multisig.AddSignatureFromPubKey(multisigSig, stdSig.Data, stdSig.PubKey, multisigPub.GetPubKeys()); err != nil { return err } } @@ -127,13 +130,29 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] newStdSig := types.StdSignature{Signature: clientCtx.Codec.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub.Bytes()} //nolint:staticcheck newTx := types.NewStdTx(stdTx.GetMsgs(), fee, []types.StdSignature{newStdSig}, memoTx.GetMemo()) //nolint:staticcheck + txBldr, err := clientCtx.TxGenerator.WrapTxBuilder(stdTx) + if err != nil { + return err + } + + sigBldr := client.SignatureBuilder{ + PubKey: multisigPub, + Data: multisigSig, + } + + err = txBldr.SetSignatures(sigBldr) + + if err != nil { + return err + } + sigOnly := viper.GetBool(flagSigOnly) var json []byte switch { case sigOnly && clientCtx.Indent: - json, err = codec.MarshalJSONIndent(clientCtx.JSONMarshaler, newTx.Signatures[0]) + json, err = getSignatureBuilderJSON(clientCtx.JSONMarshaler, sigBldr, true) case sigOnly && !clientCtx.Indent: - json, err = clientCtx.JSONMarshaler.MarshalJSON(newTx.Signatures[0]) + json, err = getSignatureBuilderJSON(clientCtx.JSONMarshaler, sigBldr, false) case !sigOnly && clientCtx.Indent: json, err = codec.MarshalJSONIndent(clientCtx.JSONMarshaler, newTx) default: @@ -162,13 +181,14 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] } } -func readAndUnmarshalStdSignature(clientCtx client.Context, filename string) (stdSig types.StdSignature, err error) { //nolint:staticcheck - var bytes []byte - if bytes, err = ioutil.ReadFile(filename); err != nil { - return - } - if err = clientCtx.JSONMarshaler.UnmarshalJSON(bytes, &stdSig); err != nil { - return - } - return +func readAndUnmarshalStdSignature(clientCtx client.Context, filename string) (stdSig client.SignatureBuilder, err error) { //nolint:staticcheck + //var bytes []byte + //if bytes, err = ioutil.ReadFile(filename); err != nil { + // return + //} + //if err = clientCtx.JSONMarshaler.UnmarshalJSON(bytes, &stdSig); err != nil { + // return + //} + //return + panic("TODO: json signatures") } diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index bcb1df11d3dc..c1a3d06884de 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -1,13 +1,19 @@ package cli import ( + "fmt" + "os" + "github.com/spf13/cobra" "github.com/spf13/viper" + sdk "github.com/cosmos/cosmos-sdk/types" + types2 "github.com/cosmos/cosmos-sdk/types/tx" + client2 "github.com/cosmos/cosmos-sdk/x/auth/client" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/auth/types" ) const ( @@ -67,80 +73,94 @@ func preSignCmd(cmd *cobra.Command, _ []string) { } } -func makeSignCmd(cdc client.Context) func(cmd *cobra.Command, args []string) error { +func makeSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - //cliCtx, txBldr, stdTx, err := readTxAndInitContexts(cdc, cmd, args[0]) - //if err != nil { - // return err - //} - // - //// if --signature-only is on, then override --append - //var newTx types.StdTx - //generateSignatureOnly := viper.GetBool(flagSigOnly) - //multisigAddrStr := viper.GetString(flagMultisig) - // - //if multisigAddrStr != "" { - // var multisigAddr sdk.AccAddress - // - // multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr) - // if err != nil { - // return err - // } - // newTx, err = client.SignStdTxWithSignerAddress( - // txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, cliCtx.Offline, - // ) - // generateSignatureOnly = true - //} else { - // appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly - // newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, cliCtx.Offline) - //} - // - //if err != nil { - // return err - //} - // - //json, err := getSignatureJSON(cliCtx.JSONMarshaler, newTx, cliCtx.Indent, generateSignatureOnly) - //if err != nil { - // return err - //} - // - //if viper.GetString(flagOutfile) == "" { - // fmt.Printf("%s\n", json) - // return nil - //} - // - //fp, err := os.OpenFile( - // viper.GetString(flagOutfile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644, - //) - //if err != nil { - // return err - //} - // - //defer fp.Close() - //fmt.Fprintf(fp, "%s\n", json) + clientCtx, txFactory, tx, err := readTxAndInitContexts(clientCtx, cmd, args[0]) + if err != nil { + return err + } // - //return nil - panic("TODO: fix") + // if --signature-only is on, then override --append + generateSignatureOnly := viper.GetBool(flagSigOnly) + multisigAddrStr := viper.GetString(flagMultisig) + + txBldr, err := clientCtx.TxGenerator.WrapTxBuilder(tx) + if err != nil { + return err + } + + if multisigAddrStr != "" { + var multisigAddr sdk.AccAddress + + multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr) + if err != nil { + return err + } + + err = client2.SignStdTxWithSignerAddress( + txFactory, clientCtx, multisigAddr, clientCtx.GetFromName(), txBldr, clientCtx.Offline, + ) + + generateSignatureOnly = true + } else { + appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly + err = client2.SignStdTx(txFactory, clientCtx, clientCtx.GetFromName(), txBldr, appendSig, clientCtx.Offline) + } + + if err != nil { + return err + } + + json, err := getSignatureJSON(clientCtx.JSONMarshaler, txBldr.GetTx(), clientCtx.Indent, generateSignatureOnly) + if err != nil { + return err + } + + if viper.GetString(flagOutfile) == "" { + fmt.Printf("%s\n", json) + return nil + } + + fp, err := os.OpenFile( + viper.GetString(flagOutfile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644, + ) + if err != nil { + return err + } + + defer fp.Close() + fmt.Fprintf(fp, "%s\n", json) + + return nil } } -func getSignatureJSON(cdc codec.JSONMarshaler, newTx types.StdTx, indent, generateSignatureOnly bool) ([]byte, error) { +func getSignatureJSON(cdc codec.JSONMarshaler, newTx types2.SigTx, indent, generateSignatureOnly bool) ([]byte, error) { switch generateSignatureOnly { case true: - switch indent { - case true: - return codec.MarshalJSONIndent(cdc, newTx.Signatures[0]) - - default: - return cdc.MarshalJSON(newTx.Signatures[0]) + sigData, err := newTx.GetSignatureData() + pubKeys := newTx.GetPubKeys() + if err != nil { + return nil, err } - default: - switch indent { - case true: - return codec.MarshalJSONIndent(cdc, newTx) - default: - return cdc.MarshalJSON(newTx) - } + return getSignatureBuilderJSON(cdc, client.SignatureBuilder{ + PubKey: pubKeys[0], + Data: sigData[0], + }, indent) + + default: + panic("TODO") + //switch indent { + //case true: + // return codec.MarshalJSONIndent(cdc, newTx) + // + //default: + // return cdc.MarshalJSON(newTx) + //} } } + +func getSignatureBuilderJSON(cdc codec.JSONMarshaler, sigBuilder client.SignatureBuilder, indent bool) ([]byte, error) { + panic("TODO: getSignatureBuilderJSON") +} diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 52240c4b0e5f..a42f7dbf5b86 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -113,8 +113,7 @@ func printAndValidateSigs( switch sig := sig.(type) { case *txtypes.SingleSignatureData: - signingData.Mode = sig.SignMode - sigBytes, err := signModeHandler.GetSignBytes(signingData, tx) + sigBytes, err := signModeHandler.GetSignBytes(sig.SignMode, signingData, tx) if err != nil { sigSanity = "ERROR: can't get sign bytes" success = false @@ -129,7 +128,7 @@ func printAndValidateSigs( if ok { if !multiPK.VerifyMultisignature(func(mode txtypes.SignMode) ([]byte, error) { signingData.Mode = mode - return signModeHandler.GetSignBytes(signingData, tx) + return signModeHandler.GetSignBytes(mode, signingData, tx) }, sig) { sigSanity = "ERROR: signature invalid" success = false diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index bf9f093885b1..efa1bbc262b4 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -181,52 +181,47 @@ func PrintUnsignedStdTx(txBldr authtypes.TxBuilder, clientCtx client.Context, ms // SignStdTx appends a signature to a StdTx and returns a copy of it. If appendSig // is false, it replaces the signatures already attached with the new signature. // Don't perform online validation or lookups if offline is true. -func SignStdTx(txBldr tx.Factory, clientCtx client.Context, name string, stdTx client.TxBuilder, appendSig bool, offline bool) (authtypes.StdTx, error) { - - var signedStdTx authtypes.StdTx - +func SignStdTx(txBldr tx.Factory, clientCtx client.Context, name string, stdTx client.TxBuilder, appendSig bool, offline bool) error { info, err := txBldr.Keybase().Key(name) if err != nil { - return signedStdTx, err + return err } addr := info.GetPubKey().Address() // check whether the address is a signer if !isTxSigner(sdk.AccAddress(addr), stdTx.GetTx().(types.SigTx).GetSigners()) { - return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) + return fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) } if !offline { txBldr, err = populateAccountFromState(txBldr, clientCtx, sdk.AccAddress(addr)) if err != nil { - return signedStdTx, err + return err } } - //return tx.Sign(txBldr, name, "", stdTx) - panic("TODO") + return tx.Sign(txBldr, name, stdTx) } // SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it. // Don't perform online validation or lookups if offline is true, else // populate account and sequence numbers from a foreign account. -func SignStdTxWithSignerAddress(txBldr tx.Factory, clientCtx client.Context, addr sdk.AccAddress, name string, stdTx sdk.Tx, offline bool) (signedStdTx authtypes.StdTx, err error) { - panic("TODO") +func SignStdTxWithSignerAddress(txFactory tx.Factory, clientCtx client.Context, addr sdk.AccAddress, name string, txBuilder client.TxBuilder, offline bool) error { + //check whether the address is a signer + if !isTxSigner(addr, txBuilder.GetTx().GetSigners()) { + return fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) + } - // check whether the address is a signer - //if !isTxSigner(addr, stdTx.GetSigners()) { - // return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name) - //} - // - //if !offline { - // txBldr, err = populateAccountFromState(txBldr, clientCtx, addr) - // if err != nil { - // return signedStdTx, err - // } - //} - // - //return txBldr.SignStdTx(name, stdTx, false) + var err error + if !offline { + txFactory, err = populateAccountFromState(txFactory, clientCtx, addr) + if err != nil { + return err + } + } + + return tx.Sign(txFactory, name, txBuilder) } // Read and decode a StdTx from the given filename. Can pass "-" to read from stdin. diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 39d580c32392..75779feb8e0c 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -105,6 +105,14 @@ func (s StdTxGenerator) NewTxBuilder() client.TxBuilder { return &StdTxBuilder{} } +func (s StdTxGenerator) WrapTxBuilder(tx sdk.Tx) (client.TxBuilder, error) { + stdTx, ok := tx.(StdTx) + if !ok { + return nil, fmt.Errorf("expected %T, got %T", StdTx{}, tx) + } + return &StdTxBuilder{StdTx: stdTx}, nil +} + // MarshalTx implements TxGenerator.MarshalTx func (s StdTxGenerator) TxEncoder() sdk.TxEncoder { return DefaultTxEncoder(s.Cdc) @@ -136,7 +144,7 @@ func (LegacyAminoJSONHandler) Modes() []types.SignMode { return []types.SignMode{types.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} } -func (LegacyAminoJSONHandler) GetSignBytes(data types.SigningData, tx sdk.Tx) ([]byte, error) { +func (LegacyAminoJSONHandler) GetSignBytes(_ types.SignMode, data types.SigningData, tx sdk.Tx) ([]byte, error) { feeTx, ok := tx.(types.FeeTx) if !ok { return nil, fmt.Errorf("expected FeeTx, got %T", tx)