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

FeaturesAttribute instead of individual feature attributes to match 3.x #162

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions Neo.Compiler.MSIL.UnitTests/TestClasses/Contract_metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
[assembly: Neo.SmartContract.Framework.ContractVersion("contract version")]
[assembly: Neo.SmartContract.Framework.ContractAuthor("contract author")]
[assembly: Neo.SmartContract.Framework.ContractEmail("contract email")]
[assembly: Neo.SmartContract.Framework.ContractHasDynamicInvoke]
[assembly: Neo.SmartContract.Framework.ContractHasStorage]
[assembly: Neo.SmartContract.Framework.ContractIsPayable]
[assembly: Neo.SmartContract.Framework.Features(
Neo.SmartContract.Framework.Services.Neo.ContractPropertyState.HasStorage |
Neo.SmartContract.Framework.Services.Neo.ContractPropertyState.HasDynamicInvoke |
Neo.SmartContract.Framework.Services.Neo.ContractPropertyState.Payable)]

namespace Neo.Compiler.MSIL.TestClasses
{
Expand Down
20 changes: 12 additions & 8 deletions Neo.Compiler.MSIL/MSIL/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,18 @@ private static void ParseMetadata(ILModule inModule, NeoModule outModule)
case "Neo.SmartContract.Framework.ContractEmail":
outModule.Email = attrib.ConstructorArguments[0].Value.ToString();
break;
case "Neo.SmartContract.Framework.ContractHasDynamicInvoke":
outModule.HasDynamicInvoke = true;
break;
case "Neo.SmartContract.Framework.ContractHasStorage":
outModule.HasStorage = true;
break;
case "Neo.SmartContract.Framework.ContractIsPayable":
outModule.IsPayable = true;
case "Neo.SmartContract.Framework.FeaturesAttribute":
{
// define constants to mirror ContractPropertyState values
const byte HAS_STORAGE = 1 << 0;
const byte HAS_DYNAMIC_INVOKE = 1 << 1;
const byte PAYABLE = 1 << 2;

var features = (byte)attrib.ConstructorArguments[0].Value;
outModule.HasDynamicInvoke = (features & HAS_DYNAMIC_INVOKE) != 0;
outModule.HasStorage = (features & HAS_STORAGE) != 0;
outModule.IsPayable = (features & PAYABLE) != 0;
}
break;
case "Neo.SmartContract.Framework.ContractTitle":
outModule.Title = attrib.ConstructorArguments[0].Value.ToString();
Expand Down
34 changes: 19 additions & 15 deletions Neo.SmartContract.Framework/ContractMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
using Neo.SmartContract.Framework.Services.Neo;
using Neo.VM;
using System;

namespace Neo.SmartContract.Framework
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
devhawk marked this conversation as resolved.
Show resolved Hide resolved
public class FeaturesAttribute : Attribute
{
/// <summary>
/// Smart contract features
/// </summary>
public ContractPropertyState Features { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="features">Specify the smart contract features</param>
public FeaturesAttribute(ContractPropertyState features)
{
Features = features;
}
}

[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class ContractAuthor : Attribute
{
Expand Down Expand Up @@ -36,21 +55,6 @@ public ContractEmail(string email)
public string Email { get; }
}

[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class ContractHasDynamicInvoke : Attribute
{
}

[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class ContractHasStorage : Attribute
{
}

[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class ContractIsPayable : Attribute
{
}

[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class ContractTitle : Attribute
{
Expand Down