Skip to content

Commit 909e4c4

Browse files
Jim8ycschuchardt88
authored andcommitted
[Framework] add interfaces (neo-project#952)
1 parent bbe2a8f commit 909e4c4

5 files changed

Lines changed: 57 additions & 3 deletions

File tree

src/Neo.Compiler.CSharp/CompilationEngine.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,17 @@ private List<CompilationContext> CompileProjectContracts(Compilation compilation
116116
return Contexts.Select(p => p.Value).ToList();
117117
}
118118

119+
/// <summary>
120+
/// Sort the classes based on their topological dependencies
121+
/// </summary>
122+
/// <param name="dependencies">Contract dependencies map</param>
123+
/// <returns>List of sorted contracts</returns>
124+
/// <exception cref="InvalidOperationException"></exception>
119125
private static List<INamedTypeSymbol> TopologicalSort(Dictionary<INamedTypeSymbol, List<INamedTypeSymbol>> dependencies)
120126
{
121127
var sorted = new List<INamedTypeSymbol>();
122128
var visited = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
123-
var visiting = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default); // 添加中间状态以检测循环依赖
129+
var visiting = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default); // for detecting cycles
124130

125131
void Visit(INamedTypeSymbol classSymbol)
126132
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Numerics;
2+
3+
namespace Neo.SmartContract.Framework.Interfaces;
4+
5+
/// <summary>
6+
/// Interface of method that indicate a contract receive NEP-11 Payment
7+
/// </summary>
8+
public interface INep11Payment
9+
{
10+
/// <summary>
11+
/// NonFungibleToken contracts should implement the <see cref="OnNEP11Payment"/> method
12+
/// to receive assets and modify the Manifest file to trust the received asset contract.
13+
/// </summary>
14+
/// <param name="from">The address of the payer</param>
15+
/// <param name="amount">The amount of token to be transferred</param>
16+
/// <param name="data">Additional payment description data</param>
17+
public void OnNEP11Payment(UInt160 from, BigInteger amount, object? data = null);
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Numerics;
2+
3+
namespace Neo.SmartContract.Framework.Interfaces;
4+
5+
/// <summary>
6+
/// Interface of method that indicate a contract receive NEP-17 Payment
7+
/// </summary>
8+
public interface INep17Payment
9+
{
10+
/// <summary>
11+
/// The Token contract should implement the <see cref="OnNEP17Payment"/> method
12+
/// to receive assets and modify the Manifest file to trust the received asset contract.
13+
/// </summary>
14+
/// <param name="from">The address of the payer</param>
15+
/// <param name="amount">The amount of token to be transferred</param>
16+
/// <param name="data">Additional payment description data</param>
17+
public void OnNEP17Payment(UInt160 from, BigInteger amount, object? data = null);
18+
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
using System.Numerics;
12
using Neo.SmartContract.Framework.Attributes;
3+
using Neo.SmartContract.Framework.Interfaces;
24

35
namespace Neo.SmartContract.Framework.UnitTests.TestClasses
46
{
57
[SupportedStandards(NEPStandard.NEP11)]
6-
public class Contract_SupportedStandard11Enum : Nep11Token<Nep11TokenState>
8+
public class Contract_SupportedStandard11Enum : Nep11Token<Nep11TokenState>, INep11Payment
79
{
810
public static bool TestStandard()
911
{
1012
return true;
1113
}
1214

1315
public override string Symbol { [Safe] get; }
16+
17+
public void OnNEP11Payment(UInt160 from, BigInteger amount, object? data = null)
18+
{
19+
}
1420
}
1521
}

tests/Neo.SmartContract.Framework.TestContracts/Contract_SupportedStandard17Enum.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Neo.SmartContract.Framework.Attributes;
22
using System.ComponentModel;
3+
using System.Numerics;
4+
using Neo.SmartContract.Framework.Interfaces;
35

46
namespace Neo.SmartContract.Framework.UnitTests.TestClasses
57
{
@@ -11,9 +13,13 @@ namespace Neo.SmartContract.Framework.UnitTests.TestClasses
1113
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template")]
1214
[ContractPermission("*", "*")]
1315
[SupportedStandards(NEPStandard.NEP17)]
14-
public class Contract_SupportedStandard17Enum : Nep17Token
16+
public class Contract_SupportedStandard17Enum : Nep17Token, INep17Payment
1517
{
1618
public override string Symbol { [Safe] get; }
1719
public override byte Decimals { [Safe] get; }
20+
21+
public void OnNEP17Payment(UInt160 from, BigInteger amount, object? data = null)
22+
{
23+
}
1824
}
1925
}

0 commit comments

Comments
 (0)