diff --git a/x/evm/handler.go b/x/evm/handler.go index a1fb634dc..5782afcb6 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -68,8 +68,8 @@ func handleETHTxMsg(ctx sdk.Context, keeper Keeper, msg types.EthereumTxMsg) sdk txHash := tm.Tx(txBytes).Hash() // Prepare db for logs - keeper.csdb.Prepare(common.BytesToHash(txHash), common.Hash{}, *keeper.txCount) - *keeper.txCount = *keeper.txCount + 1 + keeper.csdb.Prepare(common.BytesToHash(txHash), common.Hash{}, keeper.txCount.get()) + keeper.txCount.increment() return st.TransitionCSDB(ctx) } @@ -102,8 +102,8 @@ func handleEmintMsg(ctx sdk.Context, keeper Keeper, msg types.EmintMsg) sdk.Resu } // Prepare db for logs - keeper.csdb.Prepare(common.Hash{}, common.Hash{}, *keeper.txCount) // Cannot provide tx hash - *keeper.txCount = *keeper.txCount + 1 + keeper.csdb.Prepare(common.Hash{}, common.Hash{}, keeper.txCount.get()) // Cannot provide tx hash + keeper.txCount.increment() return st.TransitionCSDB(ctx) } diff --git a/x/evm/keeper.go b/x/evm/keeper.go index 0e1f1564a..fe31c1e5e 100644 --- a/x/evm/keeper.go +++ b/x/evm/keeper.go @@ -23,7 +23,21 @@ type Keeper struct { csdb *types.CommitStateDB cdc *codec.Codec blockKey sdk.StoreKey - txCount *int + txCount *count +} + +type count int + +func (c *count) get() int { + return (int)(*c) +} + +func (c *count) increment() { + *c = *c + 1 +} + +func (c *count) reset() { + *c = 0 } // NewKeeper generates new evm module keeper @@ -33,7 +47,7 @@ func NewKeeper(ak auth.AccountKeeper, storageKey, codeKey sdk.StoreKey, csdb: types.NewCommitStateDB(sdk.Context{}, ak, storageKey, codeKey), cdc: cdc, blockKey: blockKey, - txCount: new(int), + txCount: new(count), } } diff --git a/x/evm/module.go b/x/evm/module.go index dae2447c2..7d3033578 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -107,7 +107,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { func (am AppModule) BeginBlock(ctx sdk.Context, bl abci.RequestBeginBlock) { // Consider removing this when using evm as module without web3 API am.keeper.SetBlockHashMapping(ctx, bl.Header.LastBlockId.GetHash(), bl.Header.GetHeight()-1) - *am.keeper.txCount = 0 + am.keeper.txCount.reset() } // EndBlock function for module at end of block