Skip to content

Commit

Permalink
fix contract trust FromStackItem `ContractPermissionDescriptor.Create…
Browse files Browse the repository at this point in the history
…(StackItem item)` (#2901)

* ContractPermissionDescriptor.Create(StackItem item)

* Update src/Neo/SmartContract/Manifest/ContractPermissionDescriptor.cs

Co-authored-by: Jimmy <jinghui@wayne.edu>

---------

Co-authored-by: Jimmy <jinghui@wayne.edu>
Co-authored-by: Shargon <shargon@gmail.com>
  • Loading branch information
3 people committed Sep 25, 2023
1 parent bfe6d13 commit f6d578b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/Manifest/ContractManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void IInteroperable.FromStackItem(StackItem stackItem)
{
Null _ => WildcardContainer<ContractPermissionDescriptor>.CreateWildcard(),
// Array array when array.Any(p => ((ByteString)p).Size == 0) => WildcardContainer<ContractPermissionDescriptor>.CreateWildcard(),
Array array => WildcardContainer<ContractPermissionDescriptor>.Create(array.Select(p => new ContractPermissionDescriptor(p.GetSpan())).ToArray()),
Array array => WildcardContainer<ContractPermissionDescriptor>.Create(array.Select(ContractPermissionDescriptor.Create).ToArray()),
_ => throw new ArgumentException(null, nameof(stackItem))
};
Extra = (JObject)JToken.Parse(@struct[7].GetSpan());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Json;
using Neo.VM.Types;
using System;

namespace Neo.SmartContract.Manifest
Expand Down Expand Up @@ -66,6 +67,11 @@ internal ContractPermissionDescriptor(ReadOnlySpan<byte> span)
}
}

public static ContractPermissionDescriptor Create(StackItem item)
{
return item.Equals(StackItem.Null) ? CreateWildcard() : new ContractPermissionDescriptor(item.GetSpan());
}

/// <summary>
/// Creates a new instance of the <see cref="ContractPermissionDescriptor"/> class with the specified contract hash.
/// </summary>
Expand Down

0 comments on commit f6d578b

Please sign in to comment.