Skip to content

Commit

Permalink
fix 3195
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y committed May 15, 2024
1 parent a88ebe4 commit c1af443
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/Native/ContractEventAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class ContractEventAttribute : Attribute
{
public int Order { get; init; }
public ContractEventDescriptor Descriptor { get; set; }
public Hardfork? ActiveIn { get; init; } = null;
public Hardfork? ActiveIn { get; internal set; } = null;

public ContractEventAttribute(Hardfork activeIn, int order, string name,
string arg1Name, ContractParameterType arg1Value) : this(order, name, arg1Name, arg1Value)
Expand Down
30 changes: 23 additions & 7 deletions src/Neo/SmartContract/Native/NativeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,36 @@ protected NativeContract()
List<ContractMethodMetadata> listMethods = new();
foreach (MemberInfo member in GetType().GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
{
ContractMethodAttribute attribute = member.GetCustomAttribute<ContractMethodAttribute>();
var attribute = member.GetCustomAttribute<ContractMethodAttribute>();
if (attribute is null) continue;
listMethods.Add(new ContractMethodMetadata(member, attribute));
}
methodDescriptors = listMethods.OrderBy(p => p.Name, StringComparer.Ordinal).ThenBy(p => p.Parameters.Length).ToList().AsReadOnly();

// fix the hardfork issue in https://github.com/neo-project/neo/pull/3195
var contractEventAttributes = GetType()
.BaseType?
.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty<Type>(), null)?
.GetCustomAttributes<ContractEventAttribute>()
.ToList();
if (contractEventAttributes != null)
{
foreach (var attribute in contractEventAttributes)
{
attribute.ActiveIn = Hardfork.HF_Cockatrice;
}
}

// Reflection to get the events
eventsDescriptors =
GetType().GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty<Type>(), null)?.
GetCustomAttributes<ContractEventAttribute>().
// Take into account not only the contract constructor, but also the base type constructor for proper FungibleToken events handling.
Concat(GetType().BaseType?.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty<Type>(), null)?.
GetCustomAttributes<ContractEventAttribute>()).
OrderBy(p => p.Order).ToList().AsReadOnly();
GetType().
GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty<Type>(), null)?.
GetCustomAttributes<ContractEventAttribute>().
// Take into account not only the contract constructor, but also the base type constructor for proper FungibleToken events handling.
Concat(contractEventAttributes).
OrderBy(p => p.Order).
ToList().
AsReadOnly();

// Calculate the initializations forks
usedHardforks =
Expand Down

0 comments on commit c1af443

Please sign in to comment.