From b807fd9e7fae65a4904e86cebc2d49a7b29a77a2 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 8 Dec 2020 14:11:06 +0300 Subject: [PATCH] compiler: rename `engine.AppCall()` to `contract.Call()` --- examples/timer/timer.go | 3 +-- pkg/compiler/interop_test.go | 20 ++++++++++---------- pkg/compiler/syscall.go | 4 +--- pkg/interop/contract/contract.go | 8 ++++++++ pkg/interop/engine/engine.go | 16 ---------------- 5 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 pkg/interop/engine/engine.go diff --git a/examples/timer/timer.go b/examples/timer/timer.go index 169506fa0..0b0839df2 100644 --- a/examples/timer/timer.go +++ b/examples/timer/timer.go @@ -3,7 +3,6 @@ package timer import ( "github.com/nspcc-dev/neo-go/pkg/interop/binary" "github.com/nspcc-dev/neo-go/pkg/interop/contract" - "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" @@ -54,7 +53,7 @@ func Tick() bool { ticksLeft = ticksLeft.(int) - 1 if ticksLeft == 0 { runtime.Log("Fired!") - return engine.AppCall(runtime.GetExecutingScriptHash(), "selfDestroy").(bool) + return contract.Call(runtime.GetExecutingScriptHash(), "selfDestroy").(bool) } storage.Put(ctx, ticksKey, ticksLeft) i := binary.Itoa(ticksLeft.(int), 10) diff --git a/pkg/compiler/interop_test.go b/pkg/compiler/interop_test.go index a87bcbfbe..91a5dbb39 100644 --- a/pkg/compiler/interop_test.go +++ b/pkg/compiler/interop_test.go @@ -132,12 +132,12 @@ func TestAppCall(t *testing.T) { t.Run("convert from string constant", func(t *testing.T) { src := ` package foo - import "github.com/nspcc-dev/neo-go/pkg/interop/engine" + import "github.com/nspcc-dev/neo-go/pkg/interop/contract" const scriptHash = ` + fmt.Sprintf("%#v", string(ih.BytesBE())) + ` func Main() []byte { x := []byte{1, 2} y := []byte{3, 4} - result := engine.AppCall([]byte(scriptHash), "append", x, y) + result := contract.Call([]byte(scriptHash), "append", x, y) return result.([]byte) } ` @@ -151,12 +151,12 @@ func TestAppCall(t *testing.T) { t.Run("convert from var", func(t *testing.T) { src := ` package foo - import "github.com/nspcc-dev/neo-go/pkg/interop/engine" + import "github.com/nspcc-dev/neo-go/pkg/interop/contract" func Main() []byte { x := []byte{1, 2} y := []byte{3, 4} var addr = []byte(` + fmt.Sprintf("%#v", string(ih.BytesBE())) + `) - result := engine.AppCall(addr, "append", x, y) + result := contract.Call(addr, "append", x, y) return result.([]byte) } ` @@ -169,10 +169,10 @@ func TestAppCall(t *testing.T) { t.Run("InitializedGlobals", func(t *testing.T) { src := `package foo - import "github.com/nspcc-dev/neo-go/pkg/interop/engine" + import "github.com/nspcc-dev/neo-go/pkg/interop/contract" func Main() int { var addr = []byte(` + fmt.Sprintf("%#v", string(ih.BytesBE())) + `) - result := engine.AppCall(addr, "add3", 39) + result := contract.Call(addr, "add3", 39) return result.(int) }` @@ -184,10 +184,10 @@ func TestAppCall(t *testing.T) { t.Run("AliasPackage", func(t *testing.T) { src := `package foo - import ee "github.com/nspcc-dev/neo-go/pkg/interop/engine" + import ee "github.com/nspcc-dev/neo-go/pkg/interop/contract" func Main() int { var addr = []byte(` + fmt.Sprintf("%#v", string(ih.BytesBE())) + `) - result := ee.AppCall(addr, "add3", 39) + result := ee.Call(addr, "add3", 39) return result.(int) }` v := spawnVM(t, ic, src) @@ -199,11 +199,11 @@ func TestAppCall(t *testing.T) { func getAppCallScript(h string) string { return ` package foo - import "github.com/nspcc-dev/neo-go/pkg/interop/engine" + import "github.com/nspcc-dev/neo-go/pkg/interop/contract" func Main() []byte { x := []byte{1, 2} y := []byte{3, 4} - result := engine.AppCall(` + h + `, "append", x, y) + result := contract.Call(` + h + `, "append", x, y) return result.([]byte) } ` diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 3ad960b4b..37626157f 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -23,6 +23,7 @@ var syscalls = map[string]map[string]string{ "GetTransactionHeight": interopnames.SystemBlockchainGetTransactionHeight, }, "contract": { + "Call": interopnames.SystemContractCall, "Create": interopnames.SystemContractCreate, "CreateStandardAccount": interopnames.SystemContractCreateStandardAccount, "Destroy": interopnames.SystemContractDestroy, @@ -44,9 +45,6 @@ var syscalls = map[string]map[string]string{ "Next": interopnames.SystemEnumeratorNext, "Value": interopnames.SystemEnumeratorValue, }, - "engine": { - "AppCall": interopnames.SystemContractCall, - }, "iterator": { "Concat": interopnames.SystemIteratorConcat, "Create": interopnames.SystemIteratorCreate, diff --git a/pkg/interop/contract/contract.go b/pkg/interop/contract/contract.go index 89862018a..8a6f15639 100644 --- a/pkg/interop/contract/contract.go +++ b/pkg/interop/contract/contract.go @@ -55,3 +55,11 @@ func CreateStandardAccount(pub interop.PublicKey) []byte { func GetCallFlags() int64 { return 0 } + +// Call executes previously deployed blockchain contract with specified hash +// (20 bytes in BE form) using provided arguments. +// It returns whatever this contract returns. This function uses +// `System.Contract.Call` syscall. +func Call(scriptHash interop.Hash160, method string, args ...interface{}) interface{} { + return nil +} diff --git a/pkg/interop/engine/engine.go b/pkg/interop/engine/engine.go deleted file mode 100644 index 353044c15..000000000 --- a/pkg/interop/engine/engine.go +++ /dev/null @@ -1,16 +0,0 @@ -/* -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" - -// 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. This function uses -// `System.Contract.Call` syscall. -func AppCall(scriptHash interop.Hash160, method string, args ...interface{}) interface{} { - return nil -}