-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
202 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
using Neo.VM.Types; | ||
using Neo.Persistence; | ||
using System; | ||
using VMArray = Neo.VM.Types.Array; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Neo.SmartContract.Native | ||
{ | ||
internal class ContractMethodMetadata | ||
{ | ||
public Func<ApplicationEngine, VMArray, StackItem> Delegate; | ||
public long Price; | ||
public CallFlags RequiredCallFlags; | ||
public string Name { get; } | ||
public MethodInfo Handler { get; } | ||
public InteropParameterDescriptor[] Parameters { get; } | ||
public bool NeedApplicationEngine { get; } | ||
public bool NeedSnapshot { get; } | ||
public long Price { get; } | ||
public CallFlags RequiredCallFlags { get; } | ||
|
||
public ContractMethodMetadata(MemberInfo member, ContractMethodAttribute attribute) | ||
{ | ||
this.Name = attribute.Name ?? member.Name.ToLower()[0] + member.Name[1..]; | ||
this.Handler = member switch | ||
{ | ||
MethodInfo m => m, | ||
PropertyInfo p => p.GetMethod, | ||
_ => throw new ArgumentException(nameof(member)) | ||
}; | ||
ParameterInfo[] parameterInfos = this.Handler.GetParameters(); | ||
if (parameterInfos.Length > 0) | ||
{ | ||
NeedApplicationEngine = parameterInfos[0].ParameterType.IsAssignableFrom(typeof(ApplicationEngine)); | ||
NeedSnapshot = parameterInfos[0].ParameterType.IsAssignableFrom(typeof(StoreView)); | ||
} | ||
if (NeedApplicationEngine || NeedSnapshot) | ||
this.Parameters = parameterInfos.Skip(1).Select(p => new InteropParameterDescriptor(p)).ToArray(); | ||
else | ||
this.Parameters = parameterInfos.Select(p => new InteropParameterDescriptor(p)).ToArray(); | ||
this.Price = attribute.Price; | ||
this.RequiredCallFlags = attribute.RequiredCallFlags; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.