Skip to content

Commit

Permalink
Use sdkmath.Int instead
Browse files Browse the repository at this point in the history
  • Loading branch information
phamminh0811 committed Jul 27, 2024
1 parent 2a2fcf7 commit e1d17ec
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions store/types/tax_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
)

// Gas measured by the SDK
type TaxGas = sdkmath.Uint
type TaxGas = sdkmath.Int

type ErrorGasInputNegative struct {
Descriptor string
}

// GasMeter interface to track gas consumption
type TaxGasMeter interface {
Expand All @@ -24,7 +28,7 @@ type basicTaxGasMeter struct {
// NewGasMeter returns a reference to a new basicGasMeter.
func NewTaxGasMeter() TaxGasMeter {
return &basicTaxGasMeter{
consumed: sdkmath.ZeroUint(),
consumed: sdkmath.ZeroInt(),
}
}

Expand All @@ -34,7 +38,11 @@ func (g *basicTaxGasMeter) GasConsumed() TaxGas {
}

// ConsumeGas adds the given amount of gas to the gas consumed and panics if it overflows the limit or out of gas.
func (g *basicTaxGasMeter) ConsumeGas(amount TaxGas, _descriptor string) {
func (g *basicTaxGasMeter) ConsumeGas(amount TaxGas, descriptor string) {
if amount.IsNegative() {
panic(ErrorGasInputNegative{Descriptor: descriptor})
}

g.consumed = g.consumed.Add(amount)
}

Expand All @@ -45,6 +53,10 @@ func (g *basicTaxGasMeter) ConsumeGas(amount TaxGas, _descriptor string) {
// EVM-compatible chains can fully support the go-ethereum StateDb interface.
// See https://github.com/cosmos/cosmos-sdk/pull/9403 for reference.
func (g *basicTaxGasMeter) RefundGas(amount TaxGas, descriptor string) {
if amount.IsNegative() {
panic(ErrorGasInputNegative{Descriptor: descriptor})
}

if g.consumed.LTE(amount) {
panic(ErrorNegativeGasConsumed{Descriptor: descriptor})
}
Expand Down

0 comments on commit e1d17ec

Please sign in to comment.