From f49f26604717579455691396adc301778c02d865 Mon Sep 17 00:00:00 2001 From: Ivan Poon Date: Thu, 8 Feb 2018 14:06:50 +0800 Subject: [PATCH] Add TransactionInvocation.GetScript to StateReader (#170) This allows smart contracts to check that the transaction is an invocation to the same contract during verification phase. Example use case: https://github.com/neo-project/proposals/pull/18#issuecomment-353839621 --- neo/SmartContract/StateReader.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/neo/SmartContract/StateReader.cs b/neo/SmartContract/StateReader.cs index f10aca0c53..5ae79fc227 100644 --- a/neo/SmartContract/StateReader.cs +++ b/neo/SmartContract/StateReader.cs @@ -104,6 +104,7 @@ public StateReader() Register("Neo.Transaction.GetOutputs", Transaction_GetOutputs); Register("Neo.Transaction.GetReferences", Transaction_GetReferences); Register("Neo.Transaction.GetUnspentCoins", Transaction_GetUnspentCoins); + Register("Neo.InvocationTransaction.GetScript", InvocationTransaction_GetScript); Register("Neo.Attribute.GetUsage", Attribute_GetUsage); Register("Neo.Attribute.GetData", Attribute_GetData); Register("Neo.Input.GetHash", Input_GetHash); @@ -671,6 +672,18 @@ protected virtual bool Transaction_GetUnspentCoins(ExecutionEngine engine) return false; } + protected virtual bool InvocationTransaction_GetScript(ExecutionEngine engine) + { + if (engine.EvaluationStack.Pop() is InteropInterface _interface) + { + InvocationTransaction tx = _interface.GetInterface(); + if (tx == null) return false; + engine.EvaluationStack.Push(tx.Script); + return true; + } + return false; + } + protected virtual bool Attribute_GetUsage(ExecutionEngine engine) { if (engine.EvaluationStack.Pop() is InteropInterface _interface)