interop: add System.Runtime.BurnGas

This commit is contained in:
Evgeniy Stratonikov 2021-04-29 11:33:21 +03:00
parent 5924123927
commit 0114f9a912
6 changed files with 74 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package runtime
import (
"errors"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
@ -99,3 +100,21 @@ func GetTime(ic *interop.Context) error {
ic.VM.Estack().PushVal(ic.Block.Timestamp)
return nil
}
// BurnGas burns GAS to benefit NEO ecosystem.
func BurnGas(ic *interop.Context) error {
gas := ic.VM.Estack().Pop().BigInt()
if !gas.IsInt64() {
return errors.New("invalid GAS value")
}
g := gas.Int64()
if g <= 0 {
return errors.New("GAS must be positive")
}
if !ic.VM.AddGas(g) {
return errors.New("GAS limit exceeded")
}
return nil
}