Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tx, SignDoc, etc. proto types from 6111 #6214

Merged
merged 19 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions baseapp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type (
}

ClientFee interface {
sdk.Fee
sdk.FeeI
SetGas(uint64)
SetAmount(sdk.Coins)
}
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions server/mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions std/tx.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,7 +11,7 @@ import (
)

var (
_ sdk.Tx = (*Transaction)(nil)
_ sdk.TxI = (*Transaction)(nil)
_ clientx.ClientTx = (*Transaction)(nil)
_ clientx.Generator = TxGenerator{}
_ clientx.ClientFee = &StdFee{}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/types_handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions types/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:]...))
}
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion types/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
8 changes: 4 additions & 4 deletions types/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())

Expand Down
10 changes: 5 additions & 5 deletions types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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

Expand All @@ -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)

//__________________________________________________________

Expand Down
Loading