Skip to content

Commit

Permalink
GetTransaction signers (#2685)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Apr 14, 2022
1 parent da5decb commit 64bdd57
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/neo/Network/P2P/Payloads/Conditions/AndCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -58,5 +60,12 @@ public override JObject ToJson()
json["expressions"] = Expressions.Select(p => p.ToJson()).ToArray();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (VM.Types.Array)base.ToStackItem(referenceCounter);
result.Add(new VM.Types.Array(referenceCounter, Expressions.Select(p => p.ToStackItem(referenceCounter))));
return result;
}
}
}
9 changes: 9 additions & 0 deletions src/neo/Network/P2P/Payloads/Conditions/BooleanCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System.IO;

namespace Neo.Network.P2P.Payloads.Conditions
Expand Down Expand Up @@ -50,5 +52,12 @@ public override JObject ToJson()
json["expression"] = Expression;
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (Array)base.ToStackItem(referenceCounter);
result.Add(Expression);
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System.IO;

namespace Neo.Network.P2P.Payloads.Conditions
Expand Down Expand Up @@ -51,5 +53,12 @@ public override JObject ToJson()
json["hash"] = Hash.ToString();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (Array)base.ToStackItem(referenceCounter);
result.Add(Hash.ToArray());
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -56,5 +58,12 @@ public override JObject ToJson()
json["group"] = Group.ToString();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (Array)base.ToStackItem(referenceCounter);
result.Add(Group.ToArray());
return result;
}
}
}
9 changes: 9 additions & 0 deletions src/neo/Network/P2P/Payloads/Conditions/GroupCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -56,5 +58,12 @@ public override JObject ToJson()
json["group"] = Group.ToString();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (Array)base.ToStackItem(referenceCounter);
result.Add(Group.ToArray());
return result;
}
}
}
9 changes: 9 additions & 0 deletions src/neo/Network/P2P/Payloads/Conditions/NotCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.IO;

Expand Down Expand Up @@ -56,5 +58,12 @@ public override JObject ToJson()
json["expression"] = Expression.ToJson();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (VM.Types.Array)base.ToStackItem(referenceCounter);
result.Add(Expression.ToStackItem(referenceCounter));
return result;
}
}
}
9 changes: 9 additions & 0 deletions src/neo/Network/P2P/Payloads/Conditions/OrCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -58,5 +60,12 @@ public override JObject ToJson()
json["expressions"] = Expressions.Select(p => p.ToJson()).ToArray();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (VM.Types.Array)base.ToStackItem(referenceCounter);
result.Add(new VM.Types.Array(referenceCounter, Expressions.Select(p => p.ToStackItem(referenceCounter))));
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System.IO;

namespace Neo.Network.P2P.Payloads.Conditions
Expand Down Expand Up @@ -51,5 +53,12 @@ public override JObject ToJson()
json["hash"] = Hash.ToString();
return json;
}

public override StackItem ToStackItem(ReferenceCounter referenceCounter)
{
var result = (Array)base.ToStackItem(referenceCounter);
result.Add(Hash.ToArray());
return result;
}
}
}
14 changes: 13 additions & 1 deletion src/neo/Network/P2P/Payloads/Conditions/WitnessCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
using Neo.IO.Caching;
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.IO;

namespace Neo.Network.P2P.Payloads.Conditions
{
public abstract class WitnessCondition : ISerializable
public abstract class WitnessCondition : IInteroperable, ISerializable
{
private const int MaxSubitems = 16;
internal const int MaxNestingDepth = 2;
Expand Down Expand Up @@ -119,5 +121,15 @@ public virtual JObject ToJson()
["type"] = Type
};
}

void IInteroperable.FromStackItem(StackItem stackItem)
{
throw new NotSupportedException();
}

public virtual StackItem ToStackItem(ReferenceCounter referenceCounter)
{
return new VM.Types.Array(referenceCounter, new StackItem[] { (byte)Type });
}
}
}
22 changes: 21 additions & 1 deletion src/neo/Network/P2P/Payloads/Signer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.Network.P2P.Payloads.Conditions;
using Neo.SmartContract;
using Neo.VM;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -22,7 +24,7 @@ namespace Neo.Network.P2P.Payloads
/// <summary>
/// Represents a signer of a <see cref="Transaction"/>.
/// </summary>
public class Signer : ISerializable
public class Signer : IInteroperable, ISerializable
{
// This limits maximum number of AllowedContracts or AllowedGroups here
private const int MaxSubitems = 16;
Expand Down Expand Up @@ -176,5 +178,23 @@ public JObject ToJson()
json["rules"] = Rules.Select(p => p.ToJson()).ToArray();
return json;
}

void IInteroperable.FromStackItem(VM.Types.StackItem stackItem)
{
throw new NotSupportedException();
}

VM.Types.StackItem IInteroperable.ToStackItem(ReferenceCounter referenceCounter)
{
return new VM.Types.Array(referenceCounter, new VM.Types.StackItem[]
{
this.ToArray(),
Account.ToArray(),
(byte)Scopes,
new VM.Types.Array(AllowedContracts.Select(u => new VM.Types.ByteString(u.ToArray()))),
new VM.Types.Array(AllowedGroups.Select(u => new VM.Types.ByteString(u.ToArray()))),
new VM.Types.Array(Rules.Select(u => u.ToStackItem(referenceCounter)))
});
}
}
}
19 changes: 18 additions & 1 deletion src/neo/Network/P2P/Payloads/WitnessRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using Neo.IO;
using Neo.IO.Json;
using Neo.Network.P2P.Payloads.Conditions;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System;
using System.IO;

Expand All @@ -19,7 +22,7 @@ namespace Neo.Network.P2P.Payloads
/// <summary>
/// The rule used to describe the scope of the witness.
/// </summary>
public class WitnessRule : ISerializable
public class WitnessRule : IInteroperable, ISerializable
{
/// <summary>
/// Indicates the action to be taken if the current context meets with the rule.
Expand Down Expand Up @@ -73,5 +76,19 @@ public JObject ToJson()
["condition"] = Condition.ToJson()
};
}

void IInteroperable.FromStackItem(StackItem stackItem)
{
throw new NotSupportedException();
}

public StackItem ToStackItem(ReferenceCounter referenceCounter)
{
return new VM.Types.Array(referenceCounter, new StackItem[]
{
(byte)Action,
Condition.ToStackItem(referenceCounter)
});
}
}
}
6 changes: 6 additions & 0 deletions src/neo/SmartContract/Native/LedgerContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ private Transaction GetTransactionForContract(ApplicationEngine engine, UInt256
return state.Transaction;
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.ReadStates)]
private Signer[] GetTransactionSigners(DataCache snapshot, UInt256 hash)
{
return GetTransactionState(snapshot, hash)?.Transaction.Signers;
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.ReadStates)]
private VMState GetTransactionVMState(ApplicationEngine engine, UInt256 hash)
{
Expand Down

0 comments on commit 64bdd57

Please sign in to comment.