From f31ce9289db5ac526b351ed85141bf883b0a3a0f Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 16 Jul 2020 12:13:55 +0300 Subject: [PATCH] core: add System.Contract.GetCallFlags interop Part of #1055. It returns calling flags of the current context. --- pkg/compiler/syscall.go | 1 + pkg/core/interop_system.go | 6 ++++++ pkg/core/interop_system_test.go | 9 +++++++++ pkg/core/interops.go | 1 + pkg/interop/contract/contract.go | 6 ++++++ 5 files changed, 23 insertions(+) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index cc2668c43..c88a0d928 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -25,6 +25,7 @@ var syscalls = map[string]map[string]Syscall{ "CreateStandardAccount": {"System.Contract.CreateStandardAccount", false}, "Destroy": {"System.Contract.Destroy", false}, "IsStandard": {"System.Contract.IsStandard", false}, + "GetCallFlags": {"System.Contract.GetCallFlags", false}, "Update": {"System.Contract.Update", false}, }, "crypto": { diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 65f99db65..54c77a315 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -530,3 +530,9 @@ func contractCreateStandardAccount(ic *interop.Context, v *vm.VM) error { v.Estack().PushVal(p.GetScriptHash().BytesBE()) return nil } + +// contractGetCallFlags returns current context calling flags. +func contractGetCallFlags(_ *interop.Context, v *vm.VM) error { + v.Estack().PushVal(v.Context().GetCallFlags()) + return nil +} diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index 37f8fd462..b115b8f68 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -582,3 +582,12 @@ func TestContractUpdate(t *testing.T) { require.Error(t, err) }) } + +func TestContractGetCallFlags(t *testing.T) { + v, ic, bc := createVM(t) + defer bc.Close() + + v.LoadScriptWithHash([]byte{byte(opcode.RET)}, util.Uint160{1, 2, 3}, smartcontract.All) + require.NoError(t, contractGetCallFlags(ic, v)) + require.Equal(t, int64(smartcontract.All), v.Estack().Pop().Value().(*big.Int).Int64()) +} diff --git a/pkg/core/interops.go b/pkg/core/interops.go index e9a6da597..d2dcd6958 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -93,6 +93,7 @@ var systemInterops = []interop.Function{ {Name: "System.Contract.Destroy", Func: contractDestroy, Price: 1000000, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates}, {Name: "System.Contract.IsStandard", Func: contractIsStandard, Price: 30000}, + {Name: "System.Contract.GetCallFlags", Func: contractGetCallFlags, Price: 30000}, {Name: "System.Contract.Update", Func: contractUpdate, Price: 0, AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates}, {Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 400}, diff --git a/pkg/interop/contract/contract.go b/pkg/interop/contract/contract.go index c6ce760aa..4e237f6d9 100644 --- a/pkg/interop/contract/contract.go +++ b/pkg/interop/contract/contract.go @@ -49,3 +49,9 @@ func IsStandard(h []byte) bool { func CreateStandardAccount(pub []byte) []byte { return nil } + +// GetCallFlags returns calling flags which execution context was created with. +// This function uses `System.Contract.GetCallFlags` syscall. +func GetCallFlags() int64 { + return 0 +}