Skip to content

Commit

Permalink
Change to a new syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Feb 2, 2020
1 parent 8985184 commit 36b3221
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/neo/SmartContract/InteropService.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class Blockchain
public static readonly InteropDescriptor GetHeight = Register("System.Blockchain.GetHeight", Blockchain_GetHeight, 0_00000400, TriggerType.Application, CallFlags.None);
public static readonly InteropDescriptor GetBlock = Register("System.Blockchain.GetBlock", Blockchain_GetBlock, 0_02500000, TriggerType.Application, CallFlags.None);
public static readonly InteropDescriptor GetTransaction = Register("System.Blockchain.GetTransaction", Blockchain_GetTransaction, 0_01000000, TriggerType.Application, CallFlags.None);
public static readonly InteropDescriptor GetCurrentTransaction = Register("System.Blockchain.GetCurrentTransaction", Blockchain_GetCurrentTransaction, 0_01000000, TriggerType.Application, CallFlags.None);
public static readonly InteropDescriptor GetTransactionHeight = Register("System.Blockchain.GetTransactionHeight", Blockchain_GetTransactionHeight, 0_01000000, TriggerType.Application, CallFlags.None);
public static readonly InteropDescriptor GetTransactionFromBlock = Register("System.Blockchain.GetTransactionFromBlock", Blockchain_GetTransactionFromBlock, 0_01000000, TriggerType.Application, CallFlags.None);
public static readonly InteropDescriptor GetContract = Register("System.Blockchain.GetContract", Blockchain_GetContract, 0_01000000, TriggerType.Application, CallFlags.None);
Expand Down Expand Up @@ -43,27 +44,21 @@ private static bool Blockchain_GetBlock(ApplicationEngine engine)
return true;
}

private static bool Blockchain_GetTransaction(ApplicationEngine engine)
private static bool Blockchain_GetCurrentTransaction(ApplicationEngine engine)
{
Transaction tx;
StackItem item = engine.CurrentContext.EvaluationStack.Pop();
Transaction tx = !(engine.ScriptContainer is Transaction) ? null : (Transaction)engine.ScriptContainer;

if (item.IsNull)
{
if (engine.ScriptContainer is Transaction senderTx)
{
tx = senderTx;
}
else
{
return false;
}
}
if (tx == null)
engine.CurrentContext.EvaluationStack.Push(StackItem.Null);
else
{
tx = engine.Snapshot.GetTransaction(new UInt256(item.GetSpan()));
}
engine.CurrentContext.EvaluationStack.Push(tx.ToStackItem(engine.ReferenceCounter));
return true;
}

private static bool Blockchain_GetTransaction(ApplicationEngine engine)
{
ReadOnlySpan<byte> hash = engine.CurrentContext.EvaluationStack.Pop().GetSpan();
Transaction tx = engine.Snapshot.GetTransaction(new UInt256(hash));
if (tx == null)
engine.CurrentContext.EvaluationStack.Push(StackItem.Null);
else
Expand Down

0 comments on commit 36b3221

Please sign in to comment.