Skip to content

Commit

Permalink
add string method to gas meter (#6137)
Browse files Browse the repository at this point in the history
* add string method to gas meter

* update changelog

* Update store/types/gas.go

Co-authored-by: Alexander Bezobchuk <[email protected]>

Co-authored-by: Alexander Bezobchuk <[email protected]>
  • Loading branch information
Sladuca and alexanderbez authored May 4, 2020
1 parent 687d424 commit 18890a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion store/types/gas.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package types

import "math"
import (
"fmt"
"math"
)

// Gas consumption descriptors.
const (
Expand Down Expand Up @@ -36,6 +39,7 @@ type GasMeter interface {
ConsumeGas(amount Gas, descriptor string)
IsPastLimit() bool
IsOutOfGas() bool
String() string
}

type basicGasMeter struct {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 18890a2

Please sign in to comment.