core,vm: implement System.Runtime.GasLeft syscall
This commit is contained in:
parent
a7d4fff897
commit
a4e4439967
5 changed files with 31 additions and 0 deletions
|
@ -29,6 +29,7 @@ var syscalls = map[string]map[string]string{
|
|||
"GetEntryScriptHash": "System.Runtime.GetEntryScriptHash",
|
||||
"GetExecutingScriptHash": "System.Runtime.GetExecutingScriptHash",
|
||||
|
||||
"GasLeft": "System.Runtime.GasLeft",
|
||||
"GetTrigger": "System.Runtime.GetTrigger",
|
||||
"CheckWitness": "System.Runtime.CheckWitness",
|
||||
"Notify": "System.Runtime.Notify",
|
||||
|
|
12
pkg/core/interop/runtime/util.go
Normal file
12
pkg/core/interop/runtime/util.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package runtime
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
)
|
||||
|
||||
// GasLeft returns remaining amount of GAS.
|
||||
func GasLeft(_ *interop.Context, v *vm.VM) error {
|
||||
v.Estack().PushVal(int64(v.GasLimit - v.GasConsumed()))
|
||||
return nil
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/dbft/crypto"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -197,3 +198,13 @@ func TestContractCreateAccount(t *testing.T) {
|
|||
require.Error(t, contractCreateStandardAccount(ic, v))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRuntimeGasLeft(t *testing.T) {
|
||||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
|
||||
v.GasLimit = 100
|
||||
v.AddGas(58)
|
||||
require.NoError(t, runtime.GasLeft(ic, v))
|
||||
require.EqualValues(t, 42, v.Estack().Pop().BigInt().Int64())
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ var systemInterops = []interop.Function{
|
|||
{Name: "System.Json.Deserialize", Func: json.Deserialize, Price: 500000},
|
||||
{Name: "System.Json.Serialize", Func: json.Serialize, Price: 100000},
|
||||
{Name: "System.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 30000},
|
||||
{Name: "System.Runtime.GasLeft", Func: runtime.GasLeft, Price: 400},
|
||||
{Name: "System.Runtime.GetCallingScriptHash", Func: engineGetCallingScriptHash, Price: 400},
|
||||
{Name: "System.Runtime.GetEntryScriptHash", Func: engineGetEntryScriptHash, Price: 400},
|
||||
{Name: "System.Runtime.GetExecutingScriptHash", Func: engineGetExecutingScriptHash, Price: 400},
|
||||
|
|
|
@ -54,3 +54,9 @@ func Application() byte {
|
|||
func Verification() byte {
|
||||
return 0x00
|
||||
}
|
||||
|
||||
// GasLeft returns the amount of gas available for the current execution.
|
||||
// This function uses `System.Runtime.GasLeft` syscall.
|
||||
func GasLeft() int64 {
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue