From ddb3b36b7b2c513c284267845d2cdadba1327306 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Mon, 7 May 2018 20:49:34 +0200 Subject: [PATCH] Pass gas consumed back in result struct --- baseapp/baseapp.go | 4 ++++ types/gas.go | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 36843b776..aeb534d43 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 63aa71c1b..d4b63597c 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 }