-
Notifications
You must be signed in to change notification settings - Fork 106
[Framework Add] implement payable #990
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
Changes from 1 commit
cb0e876
729414c
a83423a
5534919
a1a950a
8795eeb
c8273ea
f37b86d
8670f71
9148455
8767b34
213e3b1
049ba8a
bcf35f0
b96f968
027d399
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,44 @@ private static void CheckNep17Compliant(this ContractManifest manifest) | |
} | ||
} | ||
|
||
private static void CheckNep11PayableCompliant(this ContractManifest manifest) | ||
{ | ||
try | ||
{ | ||
var onNEP11PaymentMethod = manifest.Abi.GetMethod("onNEP11Payment", 3); | ||
shargon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
var onNEP11PaymentValid = onNEP11PaymentMethod is { Safe: false, ReturnType: ContractParameterType.Void } && | ||
shargon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
onNEP11PaymentMethod.Parameters[0].Type == ContractParameterType.Hash160 && | ||
onNEP11PaymentMethod.Parameters[1].Type == ContractParameterType.Integer && | ||
onNEP11PaymentMethod.Parameters[2].Type == ContractParameterType.Any; | ||
|
||
|
||
if (!onNEP11PaymentValid) throw new CompilationException(DiagnosticId.IncorrectNEPStandard, | ||
$"Incomplete NEP standard {NepStandard.Nep11Payable.ToStandard()} implementation: onNEP11Payment"); | ||
} | ||
catch (Exception ex) when (ex is not CompilationException) | ||
{ | ||
throw new CompilationException(DiagnosticId.IncorrectNEPStandard, $"Incomplete NEP standard {NepStandard.Nep11Payable.ToStandard()} implementation: Unidentified issue."); | ||
} | ||
} | ||
|
||
private static void CheckNep17PayableCompliant(this ContractManifest manifest) | ||
shargon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
try | ||
{ | ||
var onNEP17PaymentMethod = manifest.Abi.GetMethod("onNEP17Payment", 3); | ||
var onNEP17PaymentValid = onNEP17PaymentMethod is { Safe: false, ReturnType: ContractParameterType.Void } && | ||
onNEP17PaymentMethod.Parameters[0].Type == ContractParameterType.Hash160 && | ||
onNEP17PaymentMethod.Parameters[1].Type == ContractParameterType.Integer && | ||
onNEP17PaymentMethod.Parameters[2].Type == ContractParameterType.Any; | ||
|
||
if (!onNEP17PaymentValid) throw new CompilationException(DiagnosticId.IncorrectNEPStandard, | ||
$"Incomplete NEP standard {NepStandard.Nep17Payable.ToStandard()} implementation: onNEP17Payment"); | ||
} | ||
catch (Exception ex) when (ex is not CompilationException) | ||
{ | ||
throw new CompilationException(DiagnosticId.IncorrectNEPStandard, $"Incomplete NEP standard {NepStandard.Nep17Payable.ToStandard()} implementation: Unidentified issue."); | ||
} | ||
} | ||
|
||
internal static ContractManifest CheckStandards(this ContractManifest manifest) | ||
{ | ||
if (manifest.SupportedStandards.Contains(NepStandard.Nep11.ToStandard())) | ||
|
@@ -175,6 +213,16 @@ internal static ContractManifest CheckStandards(this ContractManifest manifest) | |
manifest.CheckNep17Compliant(); | ||
} | ||
|
||
if (manifest.SupportedStandards.Contains(NepStandard.Nep11Payable.ToStandard())) | ||
{ | ||
manifest.CheckNep11PayableCompliant(); | ||
} | ||
|
||
if (manifest.SupportedStandards.Contains(NepStandard.Nep17Payable.ToStandard())) | ||
{ | ||
manifest.CheckNep17PayableCompliant(); | ||
} | ||
|
||
return manifest; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Neo.SmartContract.Framework.Attributes; | ||
using System.ComponentModel; | ||
using System.Numerics; | ||
using Neo.SmartContract.Framework.Interfaces; | ||
|
||
namespace Neo.SmartContract.Framework.TestContracts | ||
{ | ||
[DisplayName(nameof(Contract_SupportedStandard11Payable))] | ||
[ContractDescription("<Description Here>")] | ||
[ContractAuthor("<Your Name Or Company Here>", "<Your Public Email Here>")] | ||
[ContractVersion("<Version String Here>")] | ||
[ContractPermission(Permission.WildCard, Method.WildCard)] | ||
shargon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[SupportedStandards(NepStandard.Nep11Payable)] | ||
public class Contract_SupportedStandard11Payable : SmartContract, INep11Payable | ||
{ | ||
public void OnNEP11Payment(UInt160 from, BigInteger amount, object? data = null) | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Neo.SmartContract.Framework.Attributes; | ||
using System.ComponentModel; | ||
using System.Numerics; | ||
using Neo.SmartContract.Framework.Interfaces; | ||
|
||
namespace Neo.SmartContract.Framework.TestContracts | ||
{ | ||
[DisplayName(nameof(Contract_SupportedStandard17Payable))] | ||
[ContractDescription("<Description Here>")] | ||
[ContractAuthor("<Your Name Or Company Here>", "<Your Public Email Here>")] | ||
[ContractVersion("<Version String Here>")] | ||
[ContractPermission(Permission.WildCard, Method.WildCard)] | ||
shargon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
[SupportedStandards(NepStandard.Nep17Payable)] | ||
public class Contract_SupportedStandard17Payable : SmartContract, INep17Payable | ||
{ | ||
public void OnNEP17Payment(UInt160 from, BigInteger amount, object? data = null) | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Neo.Cryptography.ECC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Numerics; | ||
|
||
namespace Neo.SmartContract.Testing; | ||
|
||
public abstract class Contract_SupportedStandard11Payable : Neo.SmartContract.Testing.SmartContract | ||
{ | ||
#region Compiled data | ||
|
||
public static readonly Neo.SmartContract.Manifest.ContractManifest Manifest = Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Contract_SupportedStandard11Payable"",""groups"":[],""features"":{},""supportedstandards"":[""NEP-11-Y""],""abi"":{""methods"":[{""name"":""onNEP11Payment"",""parameters"":[{""name"":""from"",""type"":""Hash160""},{""name"":""amount"",""type"":""Integer""},{""name"":""data"",""type"":""Any""}],""returntype"":""Void"",""offset"":15,""safe"":false}],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""extra"":{""Description"":""\u003CDescription Here\u003E"",""Author"":""\u003CYour Name Or Company Here\u003E"",""Version"":""\u003CVersion String Here\u003E""}}"); | ||
|
||
public static readonly Neo.SmartContract.NefFile Nef = Neo.IO.Helper.AsSerializable<Neo.SmartContract.NefFile>(Convert.FromBase64String(@"TkVGM1Rlc3RpbmdFbmdpbmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVXAARAVwABeDQDQFcAAUDCSjTzIu3rbva0")); | ||
|
||
#endregion | ||
|
||
#region Unsafe methods | ||
|
||
/// <summary> | ||
/// Unsafe method | ||
/// </summary> | ||
[DisplayName("onNEP11Payment")] | ||
public abstract void OnNEP11Payment(UInt160? from, BigInteger? amount, object? data = null); | ||
shargon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#endregion | ||
|
||
#region Constructor for internal use only | ||
|
||
protected Contract_SupportedStandard11Payable(Neo.SmartContract.Testing.SmartContractInitialize initialize) : base(initialize) { } | ||
|
||
#endregion | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Neo.Cryptography.ECC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Numerics; | ||
|
||
namespace Neo.SmartContract.Testing; | ||
|
||
public abstract class Contract_SupportedStandard17Payable : Neo.SmartContract.Testing.SmartContract | ||
{ | ||
#region Compiled data | ||
|
||
public static readonly Neo.SmartContract.Manifest.ContractManifest Manifest = Neo.SmartContract.Manifest.ContractManifest.Parse(@"{""name"":""Contract_SupportedStandard17Payable"",""groups"":[],""features"":{},""supportedstandards"":[""NEP-17-Z""],""abi"":{""methods"":[{""name"":""onNEP17Payment"",""parameters"":[{""name"":""from"",""type"":""Hash160""},{""name"":""amount"",""type"":""Integer""},{""name"":""data"",""type"":""Any""}],""returntype"":""Void"",""offset"":15,""safe"":false}],""events"":[]},""permissions"":[{""contract"":""*"",""methods"":""*""}],""trusts"":[],""extra"":{""Description"":""\u003CDescription Here\u003E"",""Author"":""\u003CYour Name Or Company Here\u003E"",""Version"":""\u003CVersion String Here\u003E""}}"); | ||
|
||
public static readonly Neo.SmartContract.NefFile Nef = Neo.IO.Helper.AsSerializable<Neo.SmartContract.NefFile>(Convert.FromBase64String(@"TkVGM1Rlc3RpbmdFbmdpbmUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVXAARAVwABeDQDQFcAAUDCSjTzIu3rbva0")); | ||
|
||
#endregion | ||
|
||
#region Unsafe methods | ||
|
||
/// <summary> | ||
/// Unsafe method | ||
/// </summary> | ||
[DisplayName("onNEP17Payment")] | ||
public abstract void OnNEP17Payment(UInt160? from, BigInteger? amount, object? data = null); | ||
|
||
#endregion | ||
|
||
#region Constructor for internal use only | ||
|
||
protected Contract_SupportedStandard17Payable(Neo.SmartContract.Testing.SmartContractInitialize initialize) : base(initialize) { } | ||
|
||
#endregion | ||
} |
Uh oh!
There was an error while loading. Please reload this page.