core: move System.ExecutionEngine.* interops to System.Runtime.*

This commit is contained in:
Evgenii Stratonikov 2020-06-16 11:54:48 +03:00
parent 901181a392
commit ad2a75a500
10 changed files with 58 additions and 61 deletions

View file

@ -1,22 +1,21 @@
package enginecontract package enginecontract
import ( import (
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
) )
// Main is that famous Main() function, you know. // Main is that famous Main() function, you know.
func Main() bool { func Main() bool {
tx := engine.GetScriptContainer() tx := runtime.GetScriptContainer()
runtime.Notify(tx) runtime.Notify(tx)
callingScriptHash := engine.GetCallingScriptHash() callingScriptHash := runtime.GetCallingScriptHash()
runtime.Notify(callingScriptHash) runtime.Notify(callingScriptHash)
execScriptHash := engine.GetExecutingScriptHash() execScriptHash := runtime.GetExecutingScriptHash()
runtime.Notify(execScriptHash) runtime.Notify(execScriptHash)
entryScriptHash := engine.GetEntryScriptHash() entryScriptHash := runtime.GetEntryScriptHash()
runtime.Notify(entryScriptHash) runtime.Notify(entryScriptHash)
return true return true

View file

@ -1,7 +1,6 @@
package nep5 package nep5
import ( import (
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage" "github.com/nspcc-dev/neo-go/pkg/interop/storage"
"github.com/nspcc-dev/neo-go/pkg/interop/util" "github.com/nspcc-dev/neo-go/pkg/interop/util"
@ -85,7 +84,7 @@ func IsUsableAddress(addr []byte) bool {
} }
// Check if a smart contract is calling scripthash // Check if a smart contract is calling scripthash
callingScriptHash := engine.GetCallingScriptHash() callingScriptHash := runtime.GetCallingScriptHash()
if util.Equals(callingScriptHash, addr) { if util.Equals(callingScriptHash, addr) {
return true return true
} }

View file

@ -24,6 +24,11 @@ var syscalls = map[string]map[string]string{
"Put": "System.Storage.Put", "Put": "System.Storage.Put",
}, },
"runtime": { "runtime": {
"GetScriptContainer": "System.Runtime.GetScriptContainer",
"GetCallingScriptHash": "System.Runtime.GetCallingScriptHash",
"GetEntryScriptHash": "System.Runtime.GetEntryScriptHash",
"GetExecutingScriptHash": "System.Runtime.GetExecutingScriptHash",
"GetTrigger": "System.Runtime.GetTrigger", "GetTrigger": "System.Runtime.GetTrigger",
"CheckWitness": "System.Runtime.CheckWitness", "CheckWitness": "System.Runtime.CheckWitness",
"Notify": "System.Runtime.Notify", "Notify": "System.Runtime.Notify",
@ -45,12 +50,6 @@ var syscalls = map[string]map[string]string{
"Destroy": "System.Contract.Destroy", "Destroy": "System.Contract.Destroy",
"Update": "System.Contract.Update", "Update": "System.Contract.Update",
}, },
"engine": {
"GetScriptContainer": "System.ExecutionEngine.GetScriptContainer",
"GetCallingScriptHash": "System.ExecutionEngine.GetCallingScriptHash",
"GetEntryScriptHash": "System.ExecutionEngine.GetEntryScriptHash",
"GetExecutingScriptHash": "System.ExecutionEngine.GetExecutingScriptHash",
},
"iterator": { "iterator": {
"Concat": "System.Iterator.Concat", "Concat": "System.Iterator.Concat",
"Create": "System.Iterator.Create", "Create": "System.Iterator.Create",

View file

@ -99,10 +99,6 @@ var systemInterops = []interop.Function{
{Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 400}, {Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 400},
{Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1000000}, {Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1000000},
{Name: "System.Enumerator.Value", Func: enumerator.Value, Price: 400}, {Name: "System.Enumerator.Value", Func: enumerator.Value, Price: 400},
{Name: "System.ExecutionEngine.GetCallingScriptHash", Func: engineGetCallingScriptHash, Price: 1},
{Name: "System.ExecutionEngine.GetEntryScriptHash", Func: engineGetEntryScriptHash, Price: 1},
{Name: "System.ExecutionEngine.GetExecutingScriptHash", Func: engineGetExecutingScriptHash, Price: 1},
{Name: "System.ExecutionEngine.GetScriptContainer", Func: engineGetScriptContainer, Price: 1},
{Name: "System.Iterator.Concat", Func: iterator.Concat, Price: 400}, {Name: "System.Iterator.Concat", Func: iterator.Concat, Price: 400},
{Name: "System.Iterator.Create", Func: iterator.Create, Price: 400}, {Name: "System.Iterator.Create", Func: iterator.Create, Price: 400},
{Name: "System.Iterator.Key", Func: iterator.Key, Price: 400}, {Name: "System.Iterator.Key", Func: iterator.Key, Price: 400},
@ -111,6 +107,10 @@ var systemInterops = []interop.Function{
{Name: "System.Json.Deserialize", Func: json.Deserialize, Price: 500000}, {Name: "System.Json.Deserialize", Func: json.Deserialize, Price: 500000},
{Name: "System.Json.Serialize", Func: json.Serialize, Price: 100000}, {Name: "System.Json.Serialize", Func: json.Serialize, Price: 100000},
{Name: "System.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 200, RequiredFlags: smartcontract.AllowStates}, {Name: "System.Runtime.CheckWitness", Func: runtime.CheckWitness, Price: 200, RequiredFlags: smartcontract.AllowStates},
{Name: "System.Runtime.GetCallingScriptHash", Func: engineGetCallingScriptHash, Price: 400},
{Name: "System.Runtime.GetEntryScriptHash", Func: engineGetEntryScriptHash, Price: 400},
{Name: "System.Runtime.GetExecutingScriptHash", Func: engineGetExecutingScriptHash, Price: 400},
{Name: "System.Runtime.GetScriptContainer", Func: engineGetScriptContainer, Price: 250},
{Name: "System.Runtime.GetTime", Func: runtimeGetTime, Price: 1, {Name: "System.Runtime.GetTime", Func: runtimeGetTime, Price: 1,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowStates}, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowStates},
{Name: "System.Runtime.GetTrigger", Func: runtimeGetTrigger, Price: 1}, {Name: "System.Runtime.GetTrigger", Func: runtimeGetTrigger, Price: 1},

View file

@ -1,47 +1,10 @@
/* /*
Package engine provides access to VM execution metadata and allows to make contract calls. Package engine allows to make contract calls.
It's roughly similar in function to ExecutionEngine class in the Neo .net It's roughly similar in function to ExecutionEngine class in the Neo .net
framework. framework.
*/ */
package engine package engine
import "github.com/nspcc-dev/neo-go/pkg/interop/blockchain"
// GetScriptContainer returns the transaction that initially triggered current
// execution context. It never changes in a single execution, no matter how deep
// this execution goes. This function uses
// `System.ExecutionEngine.GetScriptContainer` syscall.
func GetScriptContainer() blockchain.Transaction {
return blockchain.Transaction{}
}
// GetExecutingScriptHash returns script hash (160 bit in BE form represented
// as 20-byte slice) of the contract that is currently being executed. Any
// AppCall can change the value returned by this function if it calls a
// different contract. This function uses
// `System.ExecutionEngine.GetExecutingScriptHash` syscall.
func GetExecutingScriptHash() []byte {
return nil
}
// GetCallingScriptHash returns script hash (160 bit in BE form represented
// as 20-byte slice) of the contract that started the execution of the currently
// running context (caller of current contract or function), so it's one level
// above the GetExecutingScriptHash in the call stack. It uses
// `System.ExecutionEngine.GetCallingScriptHash` syscall.
func GetCallingScriptHash() []byte {
return nil
}
// GetEntryScriptHash returns script hash (160 bit in BE form represented
// as 20-byte slice) of the contract that initially started current execution
// (this is a script that is contained in a transaction returned by
// GetScriptContainer) execution from the start. This function uses
// `System.ExecutionEngine.GetEntryScriptHash` syscall.
func GetEntryScriptHash() []byte {
return nil
}
// AppCall executes previously deployed blockchain contract with specified hash // AppCall executes previously deployed blockchain contract with specified hash
// (160 bit in BE form represented as 20-byte slice) using provided arguments. // (160 bit in BE form represented as 20-byte slice) using provided arguments.
// It returns whatever this contract returns. Even though this function accepts // It returns whatever this contract returns. Even though this function accepts

View file

@ -0,0 +1,38 @@
package runtime
import "github.com/nspcc-dev/neo-go/pkg/interop/blockchain"
// GetScriptContainer returns the transaction that initially triggered current
// execution context. It never changes in a single execution, no matter how deep
// this execution goes. This function uses
// `System.Runtime.GetScriptContainer` syscall.
func GetScriptContainer() blockchain.Transaction {
return blockchain.Transaction{}
}
// GetExecutingScriptHash returns script hash (160 bit in BE form represented
// as 20-byte slice) of the contract that is currently being executed. Any
// AppCall can change the value returned by this function if it calls a
// different contract. This function uses
// `System.Runtime.GetExecutingScriptHash` syscall.
func GetExecutingScriptHash() []byte {
return nil
}
// GetCallingScriptHash returns script hash (160 bit in BE form represented
// as 20-byte slice) of the contract that started the execution of the currently
// running context (caller of current contract or function), so it's one level
// above the GetExecutingScriptHash in the call stack. It uses
// `System.Runtime.GetCallingScriptHash` syscall.
func GetCallingScriptHash() []byte {
return nil
}
// GetEntryScriptHash returns script hash (160 bit in BE form represented
// as 20-byte slice) of the contract that initially started current execution
// (this is a script that is contained in a transaction returned by
// GetScriptContainer) execution from the start. This function uses
// `System.Runtime.GetEntryScriptHash` syscall.
func GetEntryScriptHash() []byte {
return nil
}

View file

@ -50,18 +50,18 @@ type rpcTestCase struct {
check func(t *testing.T, e *executor, result interface{}) check func(t *testing.T, e *executor, result interface{})
} }
const testContractHash = "279c86355b30d452386c1717e2ffa01c9dac31f3" const testContractHash = "e65ff7b3a02d207b584a5c27057d4e9862ef01da"
var rpcTestCases = map[string][]rpcTestCase{ var rpcTestCases = map[string][]rpcTestCase{
"getapplicationlog": { "getapplicationlog": {
{ {
name: "positive", name: "positive",
params: `["136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20"]`, params: `["9352fa8d351635bb151e7e5a3a923bfe4d8fb90f05b605ec00af95c2410b594d"]`,
result: func(e *executor) interface{} { return &result.ApplicationLog{} }, result: func(e *executor) interface{} { return &result.ApplicationLog{} },
check: func(t *testing.T, e *executor, acc interface{}) { check: func(t *testing.T, e *executor, acc interface{}) {
res, ok := acc.(*result.ApplicationLog) res, ok := acc.(*result.ApplicationLog)
require.True(t, ok) require.True(t, ok)
expectedTxHash, err := util.Uint256DecodeStringLE("136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20") expectedTxHash, err := util.Uint256DecodeStringLE("9352fa8d351635bb151e7e5a3a923bfe4d8fb90f05b605ec00af95c2410b594d")
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, expectedTxHash, res.TxHash)
assert.Equal(t, 1, len(res.Executions)) assert.Equal(t, 1, len(res.Executions))
@ -483,7 +483,7 @@ var rpcTestCases = map[string][]rpcTestCase{
"gettransactionheight": { "gettransactionheight": {
{ {
name: "positive", name: "positive",
params: `["136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20"]`, params: `["9352fa8d351635bb151e7e5a3a923bfe4d8fb90f05b605ec00af95c2410b594d"]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
h := 0 h := 0
return &h return &h

Binary file not shown.

View file

@ -1,7 +1,6 @@
package testdata package testdata
import ( import (
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage" "github.com/nspcc-dev/neo-go/pkg/interop/storage"
) )
@ -71,7 +70,7 @@ func Main(operation string, args []interface{}) interface{} {
return true return true
case "init": case "init":
ctx := storage.GetContext() ctx := storage.GetContext()
h := engine.GetExecutingScriptHash() h := runtime.GetExecutingScriptHash()
amount := totalSupply amount := totalSupply
storage.Put(ctx, h, amount) storage.Put(ctx, h, amount)
runtime.Notify("transfer", []byte{}, h, amount) runtime.Notify("transfer", []byte{}, h, amount)

Binary file not shown.