Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add string method to gas meter #6137

Merged
merged 5 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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