add string method to gas meter (#6137)

* add string method to gas meter

* update changelog

* Update store/types/gas.go

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Sebastien La Duca 2020-05-04 15:23:44 -04:00 committed by GitHub
parent 687d4246e5
commit 18890a225b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -230,6 +230,7 @@ functionality that requires an online connection.
* (simulation) [\#6002](https://github.com/cosmos/cosmos-sdk/pull/6002) Add randomized consensus params into simulation.
* (x/staking) [\#6059](https://github.com/cosmos/cosmos-sdk/pull/6059) Updated `HistoricalEntries` parameter default to 100.
* (x/ibc) [\#5948](https://github.com/cosmos/cosmos-sdk/issues/5948) Add `InitGenesis` and `ExportGenesis` functions for `ibc` module.
* (types) [\#6128](https://github.com/cosmos/cosmos-sdk/pull/6137) Add String() method to GasMeter
## [v0.38.3] - 2020-04-09

View File

@ -1,6 +1,9 @@
package types
import "math"
import (
"fmt"
"math"
)
// Gas consumption descriptors.
const (
@ -36,6 +39,7 @@ type GasMeter interface {
ConsumeGas(amount Gas, descriptor string)
IsPastLimit() bool
IsOutOfGas() bool
String() string
}
type basicGasMeter struct {
@ -98,6 +102,10 @@ func (g *basicGasMeter) IsOutOfGas() bool {
return g.consumed >= g.limit
}
func (g *basicGasMeter) String() string {
return fmt.Sprintf("BasicGasMeter:\n limit: %d\n consumed: %d", g.limit, g.consumed)
}
type infiniteGasMeter struct {
consumed Gas
}
@ -138,6 +146,10 @@ func (g *infiniteGasMeter) IsOutOfGas() bool {
return false
}
func (g *infiniteGasMeter) String() string {
return fmt.Sprintf("InfiniteGasMeter:\n consumed: %d", g.consumed)
}
// GasConfig defines gas cost for each operation on KVStores
type GasConfig struct {
HasCost Gas