diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 36843b7762..aeb534d43c 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -322,6 +322,7 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) { Data: result.Data, Log: result.Log, GasWanted: result.GasWanted, + GasUsed: result.GasUsed, Fee: cmn.KI64Pair{ []byte(result.FeeDenom), result.FeeAmount, @@ -433,6 +434,9 @@ func (app *BaseApp) runTx(isCheckTx bool, txBytes []byte, tx sdk.Tx) (result sdk result = handler(ctx, msg) + // Set gas utilized + result.GasUsed = ctx.GasMeter().GasConsumed() + // If result was successful, write to app.checkState.ms or app.deliverState.ms if result.IsOK() { msCache.Write() diff --git a/types/gas.go b/types/gas.go index 63aa71c1b0..d4b63597c9 100644 --- a/types/gas.go +++ b/types/gas.go @@ -2,10 +2,11 @@ package types import () -type Gas uint64 +type Gas = int64 type GasMeter interface { GasExceeded() bool + GasConsumed() Gas ConsumeGas(amount Gas) ConsumeGasOrFail(amount Gas) bool } @@ -26,6 +27,10 @@ func (g *basicGasMeter) GasExceeded() bool { return g.consumed > g.limit } +func (g *basicGasMeter) GasConsumed() Gas { + return g.consumed +} + func (g *basicGasMeter) ConsumeGas(amount Gas) { g.consumed += amount }