Pass gas consumed back in result struct

This commit is contained in:
Christopher Goes 2018-05-07 20:49:34 +02:00
parent f0e4d24ea3
commit ddb3b36b7b
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
2 changed files with 10 additions and 1 deletions

View File

@ -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()

View File

@ -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
}