Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetTransaction signers #2685

Merged
merged 4 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 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 : ISerializable, IInteroperable
{
// This limits maximum number of AllowedContracts or AllowedGroups here
private const int MaxSubitems = 16;
Expand Down Expand Up @@ -176,5 +178,27 @@ public JObject ToJson()
json["rules"] = Rules.Select(p => p.ToJson()).ToArray();
return json;
}

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

public VM.Types.StackItem ToStackItem(ReferenceCounter referenceCounter)
{
return new VM.Types.Array(referenceCounter, new VM.Types.StackItem[]
{
Account.ToArray(),
(int)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 =>
new VM.Types.Array(new VM.Types.StackItem []{
new VM.Types.Integer((byte)u.Action),
new VM.Types.ByteString(u.Condition.ToArray())
}))),
this.ToArray(),
});
}
}
}
11 changes: 11 additions & 0 deletions src/neo/SmartContract/Native/LedgerContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ public Transaction GetTransaction(DataCache snapshot, UInt256 hash)
return GetTransactionState(snapshot, hash)?.Transaction;
}

/// <summary>
/// Gets a transaction signers with the specified hash.
/// </summary>
/// <param name="snapshot">The snapshot used to read data.</param>
/// <param name="hash">The hash of the transaction.</param>
/// <returns>The transaction signers with the specified hash.</returns>
public Signer[] GetTransactionSigners(DataCache snapshot, UInt256 hash)
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
return GetTransactionState(snapshot, hash)?.Transaction?.Signers;
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.ReadStates, Name = "getTransaction")]
private Transaction GetTransactionForContract(ApplicationEngine engine, UInt256 hash)
{
Expand Down