diff --git a/examples/engine/engine.go b/examples/engine/engine.go index d5a914c68..e747863d1 100644 --- a/examples/engine/engine.go +++ b/examples/engine/engine.go @@ -1,22 +1,21 @@ package enginecontract import ( - "github.com/nspcc-dev/neo-go/pkg/interop/engine" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" ) // Main is that famous Main() function, you know. func Main() bool { - tx := engine.GetScriptContainer() + tx := runtime.GetScriptContainer() runtime.Notify(tx) - callingScriptHash := engine.GetCallingScriptHash() + callingScriptHash := runtime.GetCallingScriptHash() runtime.Notify(callingScriptHash) - execScriptHash := engine.GetExecutingScriptHash() + execScriptHash := runtime.GetExecutingScriptHash() runtime.Notify(execScriptHash) - entryScriptHash := engine.GetEntryScriptHash() + entryScriptHash := runtime.GetEntryScriptHash() runtime.Notify(entryScriptHash) return true diff --git a/examples/token/nep5/nep5.go b/examples/token/nep5/nep5.go index 742e0e3df..7082ad65b 100644 --- a/examples/token/nep5/nep5.go +++ b/examples/token/nep5/nep5.go @@ -1,7 +1,6 @@ package nep5 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/storage" "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 - callingScriptHash := engine.GetCallingScriptHash() + callingScriptHash := runtime.GetCallingScriptHash() if util.Equals(callingScriptHash, addr) { return true } diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 2a4b12fa9..d5c7c5908 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -24,6 +24,11 @@ var syscalls = map[string]map[string]string{ "Put": "System.Storage.Put", }, "runtime": { + "GetScriptContainer": "System.Runtime.GetScriptContainer", + "GetCallingScriptHash": "System.Runtime.GetCallingScriptHash", + "GetEntryScriptHash": "System.Runtime.GetEntryScriptHash", + "GetExecutingScriptHash": "System.Runtime.GetExecutingScriptHash", + "GetTrigger": "System.Runtime.GetTrigger", "CheckWitness": "System.Runtime.CheckWitness", "Notify": "System.Runtime.Notify", @@ -45,12 +50,6 @@ var syscalls = map[string]map[string]string{ "Destroy": "System.Contract.Destroy", "Update": "System.Contract.Update", }, - "engine": { - "GetScriptContainer": "System.ExecutionEngine.GetScriptContainer", - "GetCallingScriptHash": "System.ExecutionEngine.GetCallingScriptHash", - "GetEntryScriptHash": "System.ExecutionEngine.GetEntryScriptHash", - "GetExecutingScriptHash": "System.ExecutionEngine.GetExecutingScriptHash", - }, "iterator": { "Concat": "System.Iterator.Concat", "Create": "System.Iterator.Create", diff --git a/pkg/core/interops.go b/pkg/core/interops.go index e3af4d4ec..aa64a714c 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -99,10 +99,6 @@ var systemInterops = []interop.Function{ {Name: "System.Enumerator.Create", Func: enumerator.Create, Price: 400}, {Name: "System.Enumerator.Next", Func: enumerator.Next, Price: 1000000}, {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.Create", Func: iterator.Create, 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.Serialize", Func: json.Serialize, Price: 100000}, {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, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowStates}, {Name: "System.Runtime.GetTrigger", Func: runtimeGetTrigger, Price: 1}, diff --git a/pkg/interop/engine/engine.go b/pkg/interop/engine/engine.go index ace2ceff3..d126a5b99 100644 --- a/pkg/interop/engine/engine.go +++ b/pkg/interop/engine/engine.go @@ -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 framework. */ 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 // (160 bit in BE form represented as 20-byte slice) using provided arguments. // It returns whatever this contract returns. Even though this function accepts diff --git a/pkg/interop/runtime/engine.go b/pkg/interop/runtime/engine.go new file mode 100644 index 000000000..c71173c1b --- /dev/null +++ b/pkg/interop/runtime/engine.go @@ -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 +} diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 60437d2b1..e206b6b03 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -50,18 +50,18 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "279c86355b30d452386c1717e2ffa01c9dac31f3" +const testContractHash = "e65ff7b3a02d207b584a5c27057d4e9862ef01da" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { { name: "positive", - params: `["136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20"]`, + params: `["9352fa8d351635bb151e7e5a3a923bfe4d8fb90f05b605ec00af95c2410b594d"]`, result: func(e *executor) interface{} { return &result.ApplicationLog{} }, check: func(t *testing.T, e *executor, acc interface{}) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) - expectedTxHash, err := util.Uint256DecodeStringLE("136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20") + expectedTxHash, err := util.Uint256DecodeStringLE("9352fa8d351635bb151e7e5a3a923bfe4d8fb90f05b605ec00af95c2410b594d") require.NoError(t, err) assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, 1, len(res.Executions)) @@ -483,7 +483,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "gettransactionheight": { { name: "positive", - params: `["136ef2ba8259d121a173da2588ae0fbb735f0f740820fded9cd8da8fee109b20"]`, + params: `["9352fa8d351635bb151e7e5a3a923bfe4d8fb90f05b605ec00af95c2410b594d"]`, result: func(e *executor) interface{} { h := 0 return &h diff --git a/pkg/rpc/server/testdata/test_contract.avm b/pkg/rpc/server/testdata/test_contract.avm index 459d4e221..eec2f3ea4 100755 Binary files a/pkg/rpc/server/testdata/test_contract.avm and b/pkg/rpc/server/testdata/test_contract.avm differ diff --git a/pkg/rpc/server/testdata/test_contract.go b/pkg/rpc/server/testdata/test_contract.go index 9eb87fe4e..c8d7609d0 100644 --- a/pkg/rpc/server/testdata/test_contract.go +++ b/pkg/rpc/server/testdata/test_contract.go @@ -1,7 +1,6 @@ package testdata 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/storage" ) @@ -71,7 +70,7 @@ func Main(operation string, args []interface{}) interface{} { return true case "init": ctx := storage.GetContext() - h := engine.GetExecutingScriptHash() + h := runtime.GetExecutingScriptHash() amount := totalSupply storage.Put(ctx, h, amount) runtime.Notify("transfer", []byte{}, h, amount) diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 482613445..e175a3066 100644 Binary files a/pkg/rpc/server/testdata/testblocks.acc and b/pkg/rpc/server/testdata/testblocks.acc differ