Skip to content

Commit

Permalink
FeaturesAttribute instead of individual feature attributes to match 3…
Browse files Browse the repository at this point in the history
….x (#162)

* FeaturesAttribute instead of individual feature attributes to match 3.x

* fix formatting
  • Loading branch information
devhawk committed Dec 12, 2019
1 parent b396bf3 commit 8ff122a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
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)]
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

0 comments on commit 8ff122a

Please sign in to comment.