Skip to content

Commit

Permalink
Merge pull request #4 from sei-protocol/tony-chen-remove-legacytm
Browse files Browse the repository at this point in the history
Remove legacytm definitions
  • Loading branch information
codchen authored Aug 23, 2022
2 parents 9d6b9a8 + 960e23e commit a0f3bb7
Show file tree
Hide file tree
Showing 57 changed files with 303 additions and 14,803 deletions.
13 changes: 5 additions & 8 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/legacytm"
"github.com/cosmos/cosmos-sdk/utils"
)

// InitChain implements the ABCI interface. It runs the initialization logic
Expand Down Expand Up @@ -142,7 +141,7 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
}

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req legacytm.RequestBeginBlock) (res legacytm.ResponseBeginBlock) {
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")

if err := app.validateHeight(req); err != nil {
Expand All @@ -157,7 +156,7 @@ func (app *BaseApp) BeginBlock(req legacytm.RequestBeginBlock) (res legacytm.Res
}

// EndBlock implements the ABCI interface.
func (app *BaseApp) EndBlock(req legacytm.RequestEndBlock) (res legacytm.ResponseEndBlock) {
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "end_block")

if app.deliverState.ms.TracingEnabled() {
Expand Down Expand Up @@ -215,7 +214,7 @@ func (app *BaseApp) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abc
// Otherwise, the ResponseDeliverTx will contain releveant error information.
// Regardless of tx execution outcome, the ResponseDeliverTx will contain relevant
// gas execution context.
func (app *BaseApp) DeliverTx(req legacytm.RequestDeliverTx) abci.ResponseDeliverTx {
func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx")

gInfo := sdk.GasInfo{}
Expand All @@ -239,8 +238,7 @@ func (app *BaseApp) DeliverTx(req legacytm.RequestDeliverTx) abci.ResponseDelive
GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints?
Log: result.Log,
Data: result.Data,
Events: utils.Map(sdk.MarkEventsToIndex(
utils.Map(result.Events, sdk.ABCIToLegacyEvent), app.indexEvents), sdk.LegacyToABCIEvent),
Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents),
}
}

Expand Down Expand Up @@ -973,8 +971,7 @@ func (app *BaseApp) FinalizeBlock(ctx context.Context, req *abci.RequestFinalize
if err != nil {
return nil, err
}
res.Events = utils.Map(sdk.MarkEventsToIndex(
utils.Map(res.Events, sdk.ABCIToLegacyEvent), app.indexEvents), sdk.LegacyToABCIEvent)
res.Events = sdk.MarkEventsToIndex(res.Events, app.indexEvents)
// set the signed validators for addition to context in deliverTx
app.voteInfos = req.DecidedLastCommit.GetVotes()
return res, nil
Expand Down
8 changes: 3 additions & 5 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/legacytm"
"github.com/cosmos/cosmos-sdk/utils"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)

Expand Down Expand Up @@ -547,7 +545,7 @@ func (app *BaseApp) getMaximumBlockGas(ctx sdk.Context) uint64 {
}
}

func (app *BaseApp) validateHeight(req legacytm.RequestBeginBlock) error {
func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error {
if req.Header.Height < 1 {
return fmt.Errorf("invalid height: %d", req.Header.Height)
}
Expand Down Expand Up @@ -736,7 +734,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
}

msCache.Write()
anteEvents = utils.Map(events.ToABCIEvents(), sdk.LegacyToABCIEvent)
anteEvents = events.ToABCIEvents()
}

// Create a new Context based off of the existing Context with a MultiStore branch
Expand Down Expand Up @@ -844,6 +842,6 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
return &sdk.Result{
Data: data,
Log: strings.TrimSpace(msgLogs.String()),
Events: utils.Map(events.ToABCIEvents(), sdk.LegacyToABCIEvent),
Events: events.ToABCIEvents(),
}, nil
}
41 changes: 20 additions & 21 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/legacytm"
"github.com/cosmos/cosmos-sdk/utils"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)
Expand Down Expand Up @@ -170,7 +169,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
}
txBytes, err := codec.Marshal(tx)
require.NoError(t, err)
resp := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
resp := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, resp.IsOK(), "%v", resp.String())
}
app.Commit(context.Background())
Expand Down Expand Up @@ -658,7 +657,7 @@ func TestBeginBlock_WithInitialHeight(t *testing.T) {
)

require.PanicsWithError(t, "invalid height: 4; expected: 3", func() {
app.BeginBlock(legacytm.RequestBeginBlock{
app.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
Height: 4,
},
Expand Down Expand Up @@ -864,7 +863,7 @@ func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk
return nil, err
}

res.Events = utils.Map(ctx.EventManager().Events().ToABCIEvents(), sdk.LegacyToABCIEvent)
res.Events = ctx.EventManager().Events().ToABCIEvents()
return res, nil
}
}
Expand Down Expand Up @@ -988,12 +987,12 @@ func TestDeliverTx(t *testing.T) {
txBytes, err := codec.Marshal(tx)
require.NoError(t, err)

res := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))
events := res.GetEvents()
require.Len(t, events, 3, "should contain ante handler, message type and counter events respectively")
require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], sdk.ABCIToLegacyEvent(events[0]), "ante handler event")
require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0], sdk.ABCIToLegacyEvent(events[2]), "msg handler update counter event")
require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], events[0], "ante handler event")
require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0], events[2], "msg handler update counter event")
}

app.Commit(context.Background())
Expand Down Expand Up @@ -1035,7 +1034,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
tx := newTxCounter(0, 0, 1, 2)
txBytes, err := codec.Marshal(tx)
require.NoError(t, err)
res := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))

store := app.deliverState.ctx.KVStore(capKey1)
Expand All @@ -1055,7 +1054,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
tx.Msgs = append(tx.Msgs, msgCounter2{1})
txBytes, err = codec.Marshal(tx)
require.NoError(t, err)
res = app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))

store = app.deliverState.ctx.KVStore(capKey1)
Expand Down Expand Up @@ -1244,7 +1243,7 @@ func TestRunInvalidTransaction(t *testing.T) {
txBytes, err := newCdc.Marshal(tx)
require.NoError(t, err)

res := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.EqualValues(t, sdkerrors.ErrTxDecode.ABCICode(), res.Code)
require.EqualValues(t, sdkerrors.ErrTxDecode.Codespace(), res.Codespace)
}
Expand Down Expand Up @@ -1507,7 +1506,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
tx.setFailOnAnte(true)
txBytes, err := cdc.Marshal(tx)
require.NoError(t, err)
res := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.Empty(t, res.Events)
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))

Expand All @@ -1523,7 +1522,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
txBytes, err = cdc.Marshal(tx)
require.NoError(t, err)

res = app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
// should emit ante event
require.NotEmpty(t, res.Events)
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))
Expand All @@ -1540,7 +1539,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
txBytes, err = cdc.Marshal(tx)
require.NoError(t, err)

res = app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.NotEmpty(t, res.Events)
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))

Expand Down Expand Up @@ -1611,15 +1610,15 @@ func TestGasConsumptionBadTx(t *testing.T) {
txBytes, err := cdc.Marshal(tx)
require.NoError(t, err)

res := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))

// require next tx to fail due to black gas limit
tx = newTxCounter(5, 0)
txBytes, err = cdc.Marshal(tx)
require.NoError(t, err)

res = app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))
}

Expand Down Expand Up @@ -1976,7 +1975,7 @@ func TestWithRouter(t *testing.T) {
txBytes, err := codec.Marshal(tx)
require.NoError(t, err)

res := app.DeliverTx(legacytm.RequestDeliverTx{Tx: txBytes})
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))
}

Expand All @@ -2001,11 +2000,11 @@ func TestBaseApp_EndBlock(t *testing.T) {
ConsensusParams: cp,
})
app.SetFinalizeBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
endBlockResp := app.EndBlock(legacytm.RequestEndBlock{
endBlockResp := app.EndBlock(abci.RequestEndBlock{
Height: req.Height,
})
return &abci.ResponseFinalizeBlock{
ValidatorUpdates: utils.Map(endBlockResp.ValidatorUpdates, func(v legacytm.ValidatorUpdate) abci.ValidatorUpdate {
ValidatorUpdates: utils.Map(endBlockResp.ValidatorUpdates, func(v abci.ValidatorUpdate) abci.ValidatorUpdate {
return abci.ValidatorUpdate{
PubKey: v.PubKey,
Power: v.Power,
Expand All @@ -2030,9 +2029,9 @@ func TestBaseApp_EndBlock(t *testing.T) {
},
}, nil
})
app.SetEndBlocker(func(ctx sdk.Context, req legacytm.RequestEndBlock) legacytm.ResponseEndBlock {
return legacytm.ResponseEndBlock{
ValidatorUpdates: []legacytm.ValidatorUpdate{
app.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return abci.ResponseEndBlock{
ValidatorUpdates: []abci.ValidatorUpdate{
{Power: 100},
},
}
Expand Down
3 changes: 1 addition & 2 deletions baseapp/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/legacytm"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
)
Expand Down Expand Up @@ -82,7 +81,7 @@ func TestMsgService(t *testing.T) {
app.SetFinalizeBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
txResults := []*abci.ExecTxResult{}
for _, tx := range req.Txs {
deliverTxResp := app.DeliverTx(legacytm.RequestDeliverTx{
deliverTxResp := app.DeliverTx(abci.RequestDeliverTx{
Tx: tx,
})
txResults = append(txResults, &abci.ExecTxResult{
Expand Down
3 changes: 1 addition & 2 deletions server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/legacytm"
)

// NewApp creates a simple mock kvstore app for testing. It should work
Expand All @@ -39,7 +38,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
baseApp.SetFinalizeBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
txResults := []*abci.ExecTxResult{}
for _, tx := range req.Txs {
deliverTxResp := baseApp.DeliverTx(legacytm.RequestDeliverTx{
deliverTxResp := baseApp.DeliverTx(abci.RequestDeliverTx{
Tx: tx,
})
txResults = append(txResults, &abci.ExecTxResult{
Expand Down
5 changes: 2 additions & 3 deletions server/rosetta/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/types/legacytm"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -316,8 +315,8 @@ func (s *ConverterTestSuite) TestBalanceOps() {
sdk.NewCoins(sdk.NewInt64Coin("test", 10), sdk.NewInt64Coin("utxo", 10)),
)

abciSubBalanceOp := sdk.LegacyToABCIEvent((legacytm.Event)(subBalanceOp))
abciAddBalanceOp := sdk.LegacyToABCIEvent((legacytm.Event)(addBalanceOp))
abciSubBalanceOp := (abci.Event)(subBalanceOp)
abciAddBalanceOp := (abci.Event)(addBalanceOp)

ops := s.c.ToRosetta().BalanceOps("", []abci.Event{abciSubBalanceOp, abciAddBalanceOp})
s.Len(ops, 4)
Expand Down
33 changes: 16 additions & 17 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/legacytm"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/utils"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -451,22 +450,22 @@ func (app *SimApp) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProc

func (app *SimApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
events := []abci.Event{}
beginBlockResp := app.BeginBlock(legacytm.RequestBeginBlock{
beginBlockResp := app.BeginBlock(abci.RequestBeginBlock{
Hash: req.Hash,
ByzantineValidators: utils.Map(req.ByzantineValidators, func(mis abci.Misbehavior) legacytm.Evidence {
return legacytm.Evidence{
Type: legacytm.EvidenceType(mis.Type),
Validator: legacytm.Validator(mis.Validator),
ByzantineValidators: utils.Map(req.ByzantineValidators, func(mis abci.Misbehavior) abci.Evidence {
return abci.Evidence{
Type: abci.MisbehaviorType(mis.Type),
Validator: abci.Validator(mis.Validator),
Height: mis.Height,
Time: mis.Time,
TotalVotingPower: mis.TotalVotingPower,
}
}),
LastCommitInfo: legacytm.LastCommitInfo{
LastCommitInfo: abci.LastCommitInfo{
Round: req.DecidedLastCommit.Round,
Votes: utils.Map(req.DecidedLastCommit.Votes, func(vote abci.VoteInfo) legacytm.VoteInfo {
return legacytm.VoteInfo{
Validator: legacytm.Validator(vote.Validator),
Votes: utils.Map(req.DecidedLastCommit.Votes, func(vote abci.VoteInfo) abci.VoteInfo {
return abci.VoteInfo{
Validator: abci.Validator(vote.Validator),
SignedLastBlock: vote.SignedLastBlock,
}
}),
Expand All @@ -478,10 +477,10 @@ func (app *SimApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlo
ProposerAddress: ctx.BlockHeader().ProposerAddress,
},
})
events = append(events, utils.Map(beginBlockResp.Events, sdk.LegacyToABCIEvent)...)
events = append(events, beginBlockResp.Events...)
txResults := []*abci.ExecTxResult{}
for _, tx := range req.Txs {
deliverTxResp := app.DeliverTx(legacytm.RequestDeliverTx{
deliverTxResp := app.DeliverTx(abci.RequestDeliverTx{
Tx: tx,
})
txResults = append(txResults, &abci.ExecTxResult{
Expand All @@ -495,16 +494,16 @@ func (app *SimApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlo
Codespace: deliverTxResp.Codespace,
})
}
endBlockResp := app.EndBlock(legacytm.RequestEndBlock{
endBlockResp := app.EndBlock(abci.RequestEndBlock{
Height: req.Height,
})
events = append(events, utils.Map(endBlockResp.Events, sdk.LegacyToABCIEvent)...)
events = append(events, endBlockResp.Events...)

appHash := app.WriteDeliverStateAndGetWorkingHash()
return &abci.ResponseFinalizeBlock{
Events: events,
TxResults: txResults,
ValidatorUpdates: utils.Map(endBlockResp.ValidatorUpdates, func(v legacytm.ValidatorUpdate) abci.ValidatorUpdate {
ValidatorUpdates: utils.Map(endBlockResp.ValidatorUpdates, func(v abci.ValidatorUpdate) abci.ValidatorUpdate {
return abci.ValidatorUpdate{
PubKey: v.PubKey,
Power: v.Power,
Expand Down Expand Up @@ -532,12 +531,12 @@ func (app *SimApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlo
}

// BeginBlocker application updates every begin block
func (app *SimApp) BeginBlocker(ctx sdk.Context, req legacytm.RequestBeginBlock) legacytm.ResponseBeginBlock {
func (app *SimApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}

// EndBlocker application updates every end block
func (app *SimApp) EndBlocker(ctx sdk.Context, req legacytm.RequestEndBlock) legacytm.ResponseEndBlock {
func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}

Expand Down
Loading

0 comments on commit a0f3bb7

Please sign in to comment.