From 6d93baddea60eee8b341407e3c432a74daec6f76 Mon Sep 17 00:00:00 2001 From: Shargon Date: Sun, 19 Apr 2020 09:02:24 +0200 Subject: [PATCH] Add GetCallFlags --- src/neo/SmartContract/InteropService.Contract.cs | 9 +++++++++ tests/neo.UnitTests/SmartContract/UT_InteropService.cs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/neo/SmartContract/InteropService.Contract.cs b/src/neo/SmartContract/InteropService.Contract.cs index 88260a0407..d66fd27d7b 100644 --- a/src/neo/SmartContract/InteropService.Contract.cs +++ b/src/neo/SmartContract/InteropService.Contract.cs @@ -24,6 +24,8 @@ public static class Contract public static readonly InteropDescriptor Call = Register("System.Contract.Call", Contract_Call, 0_01000000, TriggerType.System | TriggerType.Application, CallFlags.AllowCall); public static readonly InteropDescriptor CallEx = Register("System.Contract.CallEx", Contract_CallEx, 0_01000000, TriggerType.System | TriggerType.Application, CallFlags.AllowCall); public static readonly InteropDescriptor IsStandard = Register("System.Contract.IsStandard", Contract_IsStandard, 0_00030000, TriggerType.All, CallFlags.None); + public static readonly InteropDescriptor GetCallFlags = Register("System.Contract.GetCallFlags", Contract_GetCallFlags, 0_00030000, TriggerType.All, CallFlags.None); + /// /// Calculate corresponding account scripthash for given public key /// Warning: check first that input public key is valid, before creating the script. @@ -36,6 +38,13 @@ private static long GetDeploymentPrice(EvaluationStack stack, StoreView snapshot return Storage.GasPerByte * size; } + private static bool Contract_GetCallFlags(ApplicationEngine engine) + { + var state = engine.CurrentContext.GetState(); + engine.Push((int)state.CallFlags); + return true; + } + private static bool Contract_Create(ApplicationEngine engine) { if (!engine.TryPop(out ReadOnlySpan script)) return false; diff --git a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs index 0db5358f7c..5fb8cc4220 100644 --- a/tests/neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/neo.UnitTests/SmartContract/UT_InteropService.cs @@ -261,6 +261,15 @@ public void TestExecutionEngine_GetEntryScriptHash() .Should().Be(engine.EntryScriptHash.ToArray().ToHexString()); } + [TestMethod] + public void TestContract_GetCallFlags() + { + var engine = GetEngine(); + InteropService.Invoke(engine, InteropService.Contract.GetCallFlags).Should().BeTrue(); + engine.CurrentContext.EvaluationStack.Pop().GetBigInteger() + .Should().Be(((int)CallFlags.All)); + } + [TestMethod] public void TestRuntime_Platform() {