Skip to content

Commit

Permalink
Add TransactionInvocation.GetScript to StateReader (#170)
Browse files Browse the repository at this point in the history
This allows smart contracts to check that the transaction is
an invocation to the same contract during verification phase.

Example use case: neo-project/proposals#18 (comment)
  • Loading branch information
RavenXce authored and erikzhang committed Feb 8, 2018
1 parent 456ae69 commit f49f266
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions neo/SmartContract/StateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<InvocationTransaction>();
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)
Expand Down

0 comments on commit f49f266

Please sign in to comment.