interop: add System.Runtime.BurnGas
This commit is contained in:
parent
5924123927
commit
0114f9a912
6 changed files with 74 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue