Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Alternative count type
Browse files Browse the repository at this point in the history
  • Loading branch information
austinabell committed Oct 2, 2019
1 parent f5c78ed commit 6396abb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
18 changes: 16 additions & 2 deletions x/evm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6396abb

Please sign in to comment.