From 5e61a31b2ac6a71baa68c2268fa11f92215e33c1 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 2 Jan 2024 17:10:58 +0800 Subject: [PATCH 1/3] Fix: ban notify from contract developer (#845) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ban notify from contract developer * fix ut * Update src/Neo.SmartContract.Framework/Services/Runtime.cs --------- Co-authored-by: Vitor Nazário Coelho Co-authored-by: Shargon --- src/Neo.SmartContract.Framework/Services/Runtime.cs | 5 +++-- tests/Neo.SmartContract.Framework.UnitTests/SyscallTest.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Neo.SmartContract.Framework/Services/Runtime.cs b/src/Neo.SmartContract.Framework/Services/Runtime.cs index d8c5e96b7..18338c3c7 100644 --- a/src/Neo.SmartContract.Framework/Services/Runtime.cs +++ b/src/Neo.SmartContract.Framework/Services/Runtime.cs @@ -95,8 +95,9 @@ public static extern byte AddressVersion [Syscall("System.Runtime.Log")] public static extern void Log(string message); - [Syscall("System.Runtime.Notify")] - public static extern void Notify(string eventName, object[] state); + // Events not present in the ABI were disabled in HF_Basilisk + // [Syscall("System.Runtime.Notify")] + // public static extern void Notify(string eventName, object[] state); [Syscall("System.Runtime.BurnGas")] public static extern void BurnGas(long gas); diff --git a/tests/Neo.SmartContract.Framework.UnitTests/SyscallTest.cs b/tests/Neo.SmartContract.Framework.UnitTests/SyscallTest.cs index 6c49dc079..981989e92 100644 --- a/tests/Neo.SmartContract.Framework.UnitTests/SyscallTest.cs +++ b/tests/Neo.SmartContract.Framework.UnitTests/SyscallTest.cs @@ -81,7 +81,7 @@ public void TestAllSyscalls() HashSet fwSyscalls = visitor.Visit(compilation.GlobalNamespace).ToHashSet(); fwSyscalls.SymmetricExceptWith(neoSyscalls); - if (fwSyscalls.Count > 0) + if (fwSyscalls.Count > 0 && fwSyscalls.All(p => !p.Equals("System.Runtime.Notify"))) { Assert.Fail($"Unknown or unimplemented syscalls: {string.Join("\n", fwSyscalls)}"); } From 065f04d26962fb8338f12ebf28140131dbda64a5 Mon Sep 17 00:00:00 2001 From: Christopher Schuchardt Date: Thu, 4 Jan 2024 04:56:42 -0500 Subject: [PATCH 2/3] Updated Templates (#853) * Updated Templates * Fixed neo.smartcontract.template csproj * Update src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json Co-authored-by: Shargon --------- Co-authored-by: Shargon --- src/Directory.Build.props | 7 + .../Neo.Compiler.CSharp.csproj | 6 +- .../Neo.SmartContract.Framework.csproj | 7 +- .../Neo.SmartContract.Template.csproj | 4 - .../neocontract/.config/dotnet-tools.json | 12 ++ .../neocontract/.template.config/icon.png | Bin 0 -> 1419 bytes .../.template.config/template.json | 24 ++- .../templates/neocontract/Contract1.cs | 25 ++- .../templates/neocontract/ProjectName.csproj | 6 +- .../.config/dotnet-tools.json | 12 ++ .../.template.config/icon.png | Bin 0 -> 1419 bytes .../.template.config/template.json | 30 ++++ .../templates/neocontractnep17/Contract1.cs | 156 ++++++++++++++++++ .../neocontractnep17/ProjectName.csproj | 25 +++ .../.config/dotnet-tools.json | 12 ++ .../.template.config/icon.png | Bin 0 -> 1419 bytes .../.template.config/template.json | 30 ++++ .../templates/neocontractoracle/Contract1.cs | 109 ++++++++++++ .../neocontractoracle/ProjectName.csproj | 25 +++ .../.config/dotnet-tools.json | 12 ++ .../.template.config/icon.png | Bin 0 -> 1419 bytes .../.template.config/template.json | 30 ++++ .../templates/neocontractowner/Contract1.cs | 94 +++++++++++ .../neocontractowner/ProjectName.csproj | 25 +++ src/neo.png | Bin 0 -> 1419 bytes 25 files changed, 622 insertions(+), 29 deletions(-) create mode 100644 src/Neo.SmartContract.Template/templates/neocontract/.config/dotnet-tools.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontract/.template.config/icon.png create mode 100644 src/Neo.SmartContract.Template/templates/neocontractnep17/.config/dotnet-tools.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/icon.png create mode 100644 src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontractnep17/Contract1.cs create mode 100644 src/Neo.SmartContract.Template/templates/neocontractnep17/ProjectName.csproj create mode 100644 src/Neo.SmartContract.Template/templates/neocontractoracle/.config/dotnet-tools.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/icon.png create mode 100644 src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontractoracle/Contract1.cs create mode 100644 src/Neo.SmartContract.Template/templates/neocontractoracle/ProjectName.csproj create mode 100644 src/Neo.SmartContract.Template/templates/neocontractowner/.config/dotnet-tools.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/icon.png create mode 100644 src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json create mode 100644 src/Neo.SmartContract.Template/templates/neocontractowner/Contract1.cs create mode 100644 src/Neo.SmartContract.Template/templates/neocontractowner/ProjectName.csproj create mode 100644 src/neo.png diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 528909c21..d534bfadd 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -6,6 +6,13 @@ 3.6.2 net7.0 The Neo Project + https://github.com/neo-project/neo-devpack-dotnet + MIT + git + https://github.com/neo-project/neo-devpack-dotnet.git + + + diff --git a/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj b/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj index 46025e759..700882cb5 100644 --- a/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj +++ b/src/Neo.Compiler.CSharp/Neo.Compiler.CSharp.csproj @@ -9,13 +9,11 @@ Neo.Compiler enable NEO;Blockchain;Smart Contract;Compiler - https://github.com/neo-project/neo-devpack-dotnet - MIT - git - https://github.com/neo-project/neo-devpack-dotnet.git The Neo Project Neo.Compiler.CSharp Neo.Compiler.CSharp + true + snupkg diff --git a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj index 58d6f1691..b05baa37e 100644 --- a/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj +++ b/src/Neo.SmartContract.Framework/Neo.SmartContract.Framework.csproj @@ -4,14 +4,9 @@ Neo.SmartContract.Framework Neo.SmartContract.Framework Neo.SmartContract.Framework - NEO;Blockchain - https://github.com/neo-project/neo-devpack-dotnet - MIT - git - https://github.com/neo-project/neo-devpack-dotnet.git + Neo.SmartContract.Framework true snupkg - Neo.SmartContract.Framework diff --git a/src/Neo.SmartContract.Template/Neo.SmartContract.Template.csproj b/src/Neo.SmartContract.Template/Neo.SmartContract.Template.csproj index 378937f38..6ce59054b 100644 --- a/src/Neo.SmartContract.Template/Neo.SmartContract.Template.csproj +++ b/src/Neo.SmartContract.Template/Neo.SmartContract.Template.csproj @@ -5,10 +5,6 @@ Template Neo.SmartContract.Template NEO;Blockchain;Smart Contract - https://github.com/neo-project/neo-devpack-dotnet - MIT - git - https://github.com/neo-project/neo-devpack-dotnet.git Templates to use when creating a smart contract for NEO. true false diff --git a/src/Neo.SmartContract.Template/templates/neocontract/.config/dotnet-tools.json b/src/Neo.SmartContract.Template/templates/neocontract/.config/dotnet-tools.json new file mode 100644 index 000000000..33d1b0eb0 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontract/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "neo.compiler.csharp": { + "version": "TemplateNeoVersion", + "commands": [ + "nccs" + ] + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontract/.template.config/icon.png b/src/Neo.SmartContract.Template/templates/neocontract/.template.config/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1a71de07eb55e4630535a8bd211257d0a4dbfb1c GIT binary patch literal 1419 zcma)6Su`666pbZ_E!HYZLyL6md#g%wmPXQY0#v0 z)u5Jf1l6gf)-g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++{0CRWjIP%*rstUBzpShPhwz0@`(?PD4f@30>rhsthyd5egCPi)F?Ed6G0a>7L(r1z7} Q(E|mb5N=LY4nax(0@8w_9{>OV literal 0 HcmV?d00001 diff --git a/src/Neo.SmartContract.Template/templates/neocontract/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontract/.template.config/template.json index 83f27eb57..9f8b9dec8 100644 --- a/src/Neo.SmartContract.Template/templates/neocontract/.template.config/template.json +++ b/src/Neo.SmartContract.Template/templates/neocontract/.template.config/template.json @@ -1,14 +1,30 @@ { "$schema": "http://json.schemastore.org/template", "author": "The Neo Project", - "classifications": [ "NEO", "Blockchain", "Smart Contract" ], - "identity": "Neo.SmartContract.Template", - "name": "Neo.SmartContract.Template", + "classifications": [ "NEO", "Blockchain", "Smart Contract", "Basic" ], + "identity": "Neo.SmartContract.Template.Basic", + "name": "Neo Smart Contract - Basic", "shortName": "neocontract", "preferNameDirectory": true, "tags": { "language": "C#", "type": "project" }, - "sourceName": "ProjectName" + "sourceName": "ProjectName", + "symbols": { + "NeoVersion": { + "type": "parameter", + "datatype": "choice", + "choices": [ + { + "choice": "3.6.0" + }, + { + "choice": "3.6.2" + } + ], + "defaultValue": "3.6.2", + "replaces": "TemplateNeoVersion" + } + } } diff --git a/src/Neo.SmartContract.Template/templates/neocontract/Contract1.cs b/src/Neo.SmartContract.Template/templates/neocontract/Contract1.cs index 5c56370a1..a76f89e64 100644 --- a/src/Neo.SmartContract.Template/templates/neocontract/Contract1.cs +++ b/src/Neo.SmartContract.Template/templates/neocontract/Contract1.cs @@ -4,19 +4,23 @@ using Neo.SmartContract.Framework.Attributes; using Neo.SmartContract.Framework.Native; using Neo.SmartContract.Framework.Services; + using System; -using System.Numerics; +using System.ComponentModel; namespace ProjectName { - [ManifestExtra("Author", "Neo")] - [ManifestExtra("Email", "dev@neo.org")] - [ManifestExtra("Description", "This is a contract example")] + [DisplayName(nameof(Contract1))] + [ManifestExtra("Author", "")] + [ManifestExtra("Description", "")] + [ManifestExtra("Email", "")] + [ManifestExtra("Version", "")] [ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template")] + [ContractPermission("*", "*")] public class Contract1 : SmartContract { - //TODO: Replace it with your own address. - [InitialValue("NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB", ContractParameterType.Hash160)] + // TODO: Replace it with your own address. + [InitialValue("", ContractParameterType.Hash160)] static readonly UInt160 Owner = default; private static bool IsOwner() => Runtime.CheckWitness(Owner); @@ -24,6 +28,7 @@ public class Contract1 : SmartContract // When this contract address is included in the transaction signature, // this method will be triggered as a VerificationTrigger to verify that the signature is correct. // For example, this method needs to be called when withdrawing token from the contract. + [Safe] public static bool Verify() => IsOwner(); // TODO: Replace it with your methods. @@ -34,9 +39,13 @@ public static string MyMethod() public static void _deploy(object data, bool update) { - if (update) return; + if (update) + { + // This will be executed during update + return; + } - // It will be executed during deploy + // This will be executed during deploy Storage.Put(Storage.CurrentContext, "Hello", "World"); } diff --git a/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj b/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj index 173ddef51..05f237f84 100644 --- a/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj +++ b/src/Neo.SmartContract.Template/templates/neocontract/ProjectName.csproj @@ -5,7 +5,7 @@ - + @@ -17,9 +17,9 @@ - + - + diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/.config/dotnet-tools.json b/src/Neo.SmartContract.Template/templates/neocontractnep17/.config/dotnet-tools.json new file mode 100644 index 000000000..33d1b0eb0 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractnep17/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "neo.compiler.csharp": { + "version": "TemplateNeoVersion", + "commands": [ + "nccs" + ] + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/icon.png b/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1a71de07eb55e4630535a8bd211257d0a4dbfb1c GIT binary patch literal 1419 zcma)6Su`666pbZ_E!HYZLyL6md#g%wmPXQY0#v0 z)u5Jf1l6gf)-gg!f(BDt)i$=_Z$9Uod*40xeY|_l{di=I8&XD6O%ebA$e>)Da7XHL zObM~0>9JIYJQAU39MS<$)qiT?$cPf)Kf(ckT8h+OF!0EOqFj8U0RRKkF@-oC9uNQk z2thf)@ua||0-v-~h*PQE9_05Tk%R4znP>A!UAqn#40&)9-9pEDe+$y*Cxest$q;SV zZgD@LappU;ILZWk)55^HvxQ29s43NoCLFA<3k^N7g@eJ<1NA zP~LCw!3v^Sc1d-mb7EB#y*s@pVh<1Ss0QDw+FXAmJ1%;SeJ0ehy0_hYbX3P;_9@qI zTOJpXei|MV0nIH;dv_M-gc+g>7*%xH*7~qoua&2c_BOcb0-h5VBfdv=}zzNIO z4?4k^$Gf;m&aK;#8aW_k_FZNyLb>Ycq8Ytr3K0M*n>_SngjV>5pw9z~crQNg=P~se z6+DSK8jm4GU#7oqOG1;Zm-f#Cw{TwM9q}>#W#&-OmAbqtQ<{)(-obTekFDoSN&it& z78Da^R>j}3@6u>?hfQGg$JDn?+vlUvO3>tCYy+%pyGWNNAZe8J3hk%l+p}B^wVwQg z)Wy1Rfd)&Xw*PHX$y{al8Pcx!4A zKbaYvr;d;b)&3KFSOER@gQtW)?8JYOu9kBz#P4`JDObl8e)Io<8A;Uawq)+Z-r;%^ z`F$cB@7K`~3QvW4*}F^QYGIp5Tc_TtMXXV`%D_CO8L`p}FKm+(th(u)Wbh`uCsqpN zTdh%X2Uh;s)@uviBNte6%!I+$!*N17YkNgl0iM;qh>t%RqghcooYFVHl=zS=D9>Ul zx^nV=QLszl?2Ql324*Kd8ezviaOV(+s{M!vtJCIlQc$uWvRml;4pDpYY`rXNB+@1l z9s+yz>tp!Oq=S`h*_-C`rc90bf66j)j}C`QyAV{D9U{8=TGRWaKTRhY^OfU=;w}9% zmz~xV5_R!y*;3~sQeLg&eZHdH%o=b@W0()A+mlpJwq4S0d=2=ky3S198sTL6r5FzxCo>BAv_bc7yuBP-ySc(KY86pPJ+* zcH*Q|F*Y$6)--p$rTJuxpi*!_y++{0CRWjIP%*rstUBzpShPhwz0@`(?PD4f@30>rhsthyd5egCPi)F?Ed6G0a>7L(r1z7} Q(E|mb5N=LY4nax(0@8w_9{>OV literal 0 HcmV?d00001 diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json new file mode 100644 index 000000000..7a2a47621 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/template.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "The Neo Project", + "classifications": [ "NEO", "Blockchain", "Smart Contract", "NEP-17" ], + "identity": "Neo.SmartContract.Template.Nep17", + "name": "Neo Smart Contract - NEP-17", + "shortName": "neocontractnep17", + "preferNameDirectory": true, + "tags": { + "language": "C#", + "type": "project" + }, + "sourceName": "ProjectName", + "symbols": { + "NeoVersion": { + "type": "parameter", + "datatype": "choice", + "choices": [ + { + "choice": "3.6.0" + }, + { + "choice": "3.6.2" + } + ], + "defaultValue": "3.6.2", + "replaces": "TemplateNeoVersion" + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/Contract1.cs b/src/Neo.SmartContract.Template/templates/neocontractnep17/Contract1.cs new file mode 100644 index 000000000..c05084d54 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractnep17/Contract1.cs @@ -0,0 +1,156 @@ +using Neo; +using Neo.SmartContract; +using Neo.SmartContract.Framework; +using Neo.SmartContract.Framework.Attributes; +using Neo.SmartContract.Framework.Native; +using Neo.SmartContract.Framework.Services; + +using System; +using System.ComponentModel; +using System.Numerics; + +namespace ProjectName +{ + [DisplayName(nameof(Contract1))] + [ManifestExtra("Author", "")] + [ManifestExtra("Description", "")] + [ManifestExtra("Email", "")] + [ManifestExtra("Version", "")] + [ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template")] + [ContractPermission("*", "*")] + [SupportedStandards("NEP-17")] + public class Contract1 : Nep17Token + { + #region Owner + + private const byte Prefix_Owner = 0xff; + + // TODO: Replace it with your own address. + [InitialValue("", Neo.SmartContract.ContractParameterType.Hash160)] + private static readonly UInt160 InitialOwner = default; + + [Safe] + public static UInt160 GetOwner() + { + var currentOwner = Storage.Get(new[] { Prefix_Owner }); + + if (currentOwner == null) + return InitialOwner; + + return (UInt160)currentOwner; + } + + private static bool IsOwner() => + Runtime.CheckWitness(GetOwner()); + + public delegate void OnSetOwnerDelegate(UInt160 newOwner); + + [DisplayName("SetOwner")] + public static event OnSetOwnerDelegate OnSetOwner; + + public static void SetOwner(UInt160 newOwner) + { + if (IsOwner() == false) + throw new InvalidOperationException("No Authorization!"); + if (newOwner != null && newOwner.IsValid) + { + Storage.Put(new[] { Prefix_Owner }, newOwner); + OnSetOwner(newOwner); + } + } + + #endregion + + #region NEP17 + + // NOTE: Valid Range 0-31 + [Safe] + public override byte Decimals() => 8; + + // TODO: Replace "EXAMPLE" with a short name all UPPERCASE 3-8 characters + [Safe] + public override string Symbol() => "EXAMPLE"; + + public static new void Burn(UInt160 account, BigInteger amount) + { + if (IsOwner() == false) + throw new InvalidOperationException("No Authorization!"); + Nep17Token.Burn(account, amount); + } + + public static new void Mint(UInt160 to, BigInteger amount) + { + if (IsOwner() == false) + throw new InvalidOperationException("No Authorization!"); + Nep17Token.Mint(to, amount); + } + + #endregion + + #region Payment + + public static bool Withdraw(UInt160 token, UInt160 to, BigInteger amount) + { + if (IsOwner() == false) + throw new InvalidOperationException("No Authorization!"); + if (amount <= 0) + throw new ArgumentOutOfRangeException(nameof(amount)); + if (to == null || to.IsValid == false) + throw new ArgumentException("Invalid Address!"); + if (token == null || token.IsValid == false) + throw new ArgumentException("Invalid Token Address!"); + if (ContractManagement.GetContract(token) == null) + throw new ArgumentException("Token Not A Contract!"); + // TODO: Add logic + return true; + } + + // NOTE: Allows ALL NEP-17 tokens to be received for this contract + public static void OnNEP17Payment(UInt160 from, BigInteger amount, object data) + { + // TODO: Add logic for specific NEP-17 contract tokens + if (Runtime.CallingScriptHash == NEO.Hash) + { + // TODO: Add logic (Burn, Mint, Transfer, Etc) + } + if (Runtime.CallingScriptHash == GAS.Hash) + { + // TODO: Add logic (Burn, Mint, Transfer, Etc) + } + } + + #endregion + + // When this contract address is included in the transaction signature, + // this method will be triggered as a VerificationTrigger to verify that the signature is correct. + // For example, this method needs to be called when withdrawing token from the contract. + [Safe] + public static bool Verify() => IsOwner(); + + // TODO: Replace it with your methods. + public static string MyMethod() + { + return Storage.Get(Storage.CurrentContext, "Hello"); + } + + public static void _deploy(object data, bool update) + { + if (update) + { + // This will be executed during update + return; + } + + // This will be executed during deploy + Storage.Put(Storage.CurrentContext, "Hello", "World"); + } + + public static void Update(ByteString nefFile, string manifest) + { + if (!IsOwner()) throw new Exception("No authorization."); + ContractManagement.Update(nefFile, manifest, null); + } + + // NOTE: NEP-17 contracts "SHOULD NOT" have "Destroy" method + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractnep17/ProjectName.csproj b/src/Neo.SmartContract.Template/templates/neocontractnep17/ProjectName.csproj new file mode 100644 index 000000000..05f237f84 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractnep17/ProjectName.csproj @@ -0,0 +1,25 @@ + + + + net7.0 + + + + + + + + --base-name $(AssemblyName) + --base-name $(MSBuildProjectName) + --nullable $(Nullable) + --checked + -d + + + + + + + + + diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/.config/dotnet-tools.json b/src/Neo.SmartContract.Template/templates/neocontractoracle/.config/dotnet-tools.json new file mode 100644 index 000000000..33d1b0eb0 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractoracle/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "neo.compiler.csharp": { + "version": "TemplateNeoVersion", + "commands": [ + "nccs" + ] + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/icon.png b/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1a71de07eb55e4630535a8bd211257d0a4dbfb1c GIT binary patch literal 1419 zcma)6Su`666pbZ_E!HYZLyL6md#g%wmPXQY0#v0 z)u5Jf1l6gf)-gg!f(BDt)i$=_Z$9Uod*40xeY|_l{di=I8&XD6O%ebA$e>)Da7XHL zObM~0>9JIYJQAU39MS<$)qiT?$cPf)Kf(ckT8h+OF!0EOqFj8U0RRKkF@-oC9uNQk z2thf)@ua||0-v-~h*PQE9_05Tk%R4znP>A!UAqn#40&)9-9pEDe+$y*Cxest$q;SV zZgD@LappU;ILZWk)55^HvxQ29s43NoCLFA<3k^N7g@eJ<1NA zP~LCw!3v^Sc1d-mb7EB#y*s@pVh<1Ss0QDw+FXAmJ1%;SeJ0ehy0_hYbX3P;_9@qI zTOJpXei|MV0nIH;dv_M-gc+g>7*%xH*7~qoua&2c_BOcb0-h5VBfdv=}zzNIO z4?4k^$Gf;m&aK;#8aW_k_FZNyLb>Ycq8Ytr3K0M*n>_SngjV>5pw9z~crQNg=P~se z6+DSK8jm4GU#7oqOG1;Zm-f#Cw{TwM9q}>#W#&-OmAbqtQ<{)(-obTekFDoSN&it& z78Da^R>j}3@6u>?hfQGg$JDn?+vlUvO3>tCYy+%pyGWNNAZe8J3hk%l+p}B^wVwQg z)Wy1Rfd)&Xw*PHX$y{al8Pcx!4A zKbaYvr;d;b)&3KFSOER@gQtW)?8JYOu9kBz#P4`JDObl8e)Io<8A;Uawq)+Z-r;%^ z`F$cB@7K`~3QvW4*}F^QYGIp5Tc_TtMXXV`%D_CO8L`p}FKm+(th(u)Wbh`uCsqpN zTdh%X2Uh;s)@uviBNte6%!I+$!*N17YkNgl0iM;qh>t%RqghcooYFVHl=zS=D9>Ul zx^nV=QLszl?2Ql324*Kd8ezviaOV(+s{M!vtJCIlQc$uWvRml;4pDpYY`rXNB+@1l z9s+yz>tp!Oq=S`h*_-C`rc90bf66j)j}C`QyAV{D9U{8=TGRWaKTRhY^OfU=;w}9% zmz~xV5_R!y*;3~sQeLg&eZHdH%o=b@W0()A+mlpJwq4S0d=2=ky3S198sTL6r5FzxCo>BAv_bc7yuBP-ySc(KY86pPJ+* zcH*Q|F*Y$6)--p$rTJuxpi*!_y++{0CRWjIP%*rstUBzpShPhwz0@`(?PD4f@30>rhsthyd5egCPi)F?Ed6G0a>7L(r1z7} Q(E|mb5N=LY4nax(0@8w_9{>OV literal 0 HcmV?d00001 diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json new file mode 100644 index 000000000..c94fcd257 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/template.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "The Neo Project", + "classifications": [ "NEO", "Blockchain", "Smart Contract", "Oracle" ], + "identity": "Neo.SmartContract.Template.Oracle", + "name": "Neo Smart Contract - Oracle", + "shortName": "neocontractoracle", + "preferNameDirectory": true, + "tags": { + "language": "C#", + "type": "project" + }, + "sourceName": "ProjectName", + "symbols": { + "NeoVersion": { + "type": "parameter", + "datatype": "choice", + "choices": [ + { + "choice": "3.6.0" + }, + { + "choice": "3.6.2" + } + ], + "defaultValue": "3.6.2", + "replaces": "TemplateNeoVersion" + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/Contract1.cs b/src/Neo.SmartContract.Template/templates/neocontractoracle/Contract1.cs new file mode 100644 index 000000000..4d74615bc --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractoracle/Contract1.cs @@ -0,0 +1,109 @@ +using Neo; +using Neo.SmartContract; +using Neo.SmartContract.Framework; +using Neo.SmartContract.Framework.Attributes; +using Neo.SmartContract.Framework.Native; +using Neo.SmartContract.Framework.Services; + +using System; +using System.ComponentModel; + +namespace ProjectName +{ + [DisplayName(nameof(Contract1))] + [ManifestExtra("Author", "")] + [ManifestExtra("Description", "")] + [ManifestExtra("Email", "")] + [ManifestExtra("Version", "")] + [ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template")] + [ContractPermission("*", "*")] + public class Contract1 : SmartContract + { + public delegate void OnRequestSuccessfulDelegate(string requestedUrl, object jsonValue); + + [DisplayName("RequestSuccessful")] + public static event OnRequestSuccessfulDelegate OnRequestSuccessful; + + // TODO: Replace it with your own address. + [InitialValue("", ContractParameterType.Hash160)] + static readonly UInt160 Owner = default; + + private static bool IsOwner() => Runtime.CheckWitness(Owner); + + // When this contract address is included in the transaction signature, + // this method will be triggered as a VerificationTrigger to verify that the signature is correct. + // For example, this method needs to be called when withdrawing token from the contract. + [Safe] + public static bool Verify() => IsOwner(); + + // TODO: Replace it with your methods. + public static string MyMethod() + { + return Storage.Get(Storage.CurrentContext, "Hello"); + } + + public static void _deploy(object data, bool update) + { + if (update) + { + // This will be executed during update + return; + } + + // This will be executed during deploy + Storage.Put(Storage.CurrentContext, "Hello", "World"); + } + + public static void Update(ByteString nefFile, string manifest) + { + if (!IsOwner()) throw new Exception("No authorization."); + ContractManagement.Update(nefFile, manifest, null); + } + + public static void Destroy() + { + if (!IsOwner()) throw new Exception("No authorization."); + ContractManagement.Destroy(); + } + + // TODO: Add your own logic + public static void DoRequest() + { + /* + JSON DATA EXAMPLE + { + "id": "6520ad3c12a5d3765988542a", + "record": { + "propertyName": "Hello World!" + }, + "metadata": { + "name": "HelloWorld", + "readCountRemaining": 98, + "timeToExpire": 86379, + "createdAt": "2023-10-07T00:58:36.746Z" + } + } + See JSONPath format at https://github.com/atifaziz/JSONPath + JSONPath = "$.record.propertyName" + ReturnValue = ["Hello World!"] + ReturnValueType = string array + */ + var requestUrl = "https://api.jsonbin.io/v3/qs/6520ad3c12a5d3765988542a"; + Oracle.Request(requestUrl, "$.record.propertyName", "onOracleResponse", null, Oracle.MinimumResponseFee); + } + + // This method is called after the Oracle receives response from requested URL + public static void OnOracleResponse(string requestedUrl, object userData, OracleResponseCode oracleResponse, string jsonString) + { + if (Runtime.CallingScriptHash != Oracle.Hash) + throw new InvalidOperationException("No Authorization!"); + if (oracleResponse != OracleResponseCode.Success) + throw new Exception("Oracle response failure with code " + (byte)oracleResponse); + + var jsonArrayValues = (object[])StdLib.JsonDeserialize(jsonString); + var jsonFirstValue = (string)jsonArrayValues[0]; + + OnRequestSuccessful(requestedUrl, jsonFirstValue); + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractoracle/ProjectName.csproj b/src/Neo.SmartContract.Template/templates/neocontractoracle/ProjectName.csproj new file mode 100644 index 000000000..05f237f84 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractoracle/ProjectName.csproj @@ -0,0 +1,25 @@ + + + + net7.0 + + + + + + + + --base-name $(AssemblyName) + --base-name $(MSBuildProjectName) + --nullable $(Nullable) + --checked + -d + + + + + + + + + diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/.config/dotnet-tools.json b/src/Neo.SmartContract.Template/templates/neocontractowner/.config/dotnet-tools.json new file mode 100644 index 000000000..33d1b0eb0 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractowner/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "neo.compiler.csharp": { + "version": "TemplateNeoVersion", + "commands": [ + "nccs" + ] + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/icon.png b/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1a71de07eb55e4630535a8bd211257d0a4dbfb1c GIT binary patch literal 1419 zcma)6Su`666pbZ_E!HYZLyL6md#g%wmPXQY0#v0 z)u5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TJuxpi*!_y++{0CRWjIP%*rstUBzpShPhwz0@`(?PD4f@30>rhsthyd5egCPi)F?Ed6G0a>7L(r1z7} Q(E|mb5N=LY4nax(0@8w_9{>OV literal 0 HcmV?d00001 diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json b/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json new file mode 100644 index 000000000..55a8ef12c --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/template.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "The Neo Project", + "classifications": [ "NEO", "Blockchain", "Smart Contract", "Owner" ], + "identity": "Neo.SmartContract.Template.Owner", + "name": "Neo Smart Contract - Advanced Owner", + "shortName": "neocontractowner", + "preferNameDirectory": true, + "tags": { + "language": "C#", + "type": "project" + }, + "sourceName": "ProjectName", + "symbols": { + "NeoVersion": { + "type": "parameter", + "datatype": "choice", + "choices": [ + { + "choice": "3.6.0" + }, + { + "choice": "3.6.2" + } + ], + "defaultValue": "3.6.2", + "replaces": "TemplateNeoVersion" + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/Contract1.cs b/src/Neo.SmartContract.Template/templates/neocontractowner/Contract1.cs new file mode 100644 index 000000000..b6089817e --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractowner/Contract1.cs @@ -0,0 +1,94 @@ +using Neo; +using Neo.SmartContract; +using Neo.SmartContract.Framework; +using Neo.SmartContract.Framework.Attributes; +using Neo.SmartContract.Framework.Native; +using Neo.SmartContract.Framework.Services; + +using System; +using System.ComponentModel; + +namespace ProjectName +{ + [DisplayName(nameof(Contract1))] + [ManifestExtra("Author", "")] + [ManifestExtra("Description", "")] + [ManifestExtra("Email", "")] + [ManifestExtra("Version", "")] + [ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/src/Neo.SmartContract.Template")] + [ContractPermission("*", "*")] + public class Contract1 : SmartContract + { + private const byte Prefix_Owner = 0xff; + + public delegate void OnSetOwnerDelegate(UInt160 newOwner); + + [DisplayName("SetOwner")] + public static event OnSetOwnerDelegate OnSetOwner; + + // TODO: Replace it with your own address. + [InitialValue("", ContractParameterType.Hash160)] + private static readonly UInt160 InitialOwner = default; + + private static bool IsOwner() => Runtime.CheckWitness(GetOwner()); + + // When this contract address is included in the transaction signature, + // this method will be triggered as a VerificationTrigger to verify that the signature is correct. + // For example, this method needs to be called when withdrawing token from the contract. + [Safe] + public static bool Verify() => IsOwner(); + + // TODO: Replace it with your methods. + public static string MyMethod() + { + return Storage.Get(Storage.CurrentContext, "Hello"); + } + + public static void _deploy(object data, bool update) + { + if (update) + { + // This will be executed during update + return; + } + + // This will be executed during deploy + Storage.Put(Storage.CurrentContext, "Hello", "World"); + } + + public static void Update(ByteString nefFile, string manifest) + { + if (!IsOwner()) throw new Exception("No authorization."); + ContractManagement.Update(nefFile, manifest, null); + } + + public static void Destroy() + { + if (!IsOwner()) throw new Exception("No authorization."); + ContractManagement.Destroy(); + } + + // Safe is for read operations Or Safe to call by everyone + [Safe] + public static UInt160 GetOwner() + { + var currentOwner = Storage.Get(new[] { Prefix_Owner }); + + if (currentOwner == null) + return InitialOwner; + + return (UInt160)currentOwner; + } + + public static void SetOwner(UInt160 newOwner) + { + if (IsOwner() == false) + throw new InvalidOperationException("No Authorization!"); + if (newOwner != null && newOwner.IsValid) + { + Storage.Put(new[] { Prefix_Owner }, newOwner); + OnSetOwner(newOwner); + } + } + } +} diff --git a/src/Neo.SmartContract.Template/templates/neocontractowner/ProjectName.csproj b/src/Neo.SmartContract.Template/templates/neocontractowner/ProjectName.csproj new file mode 100644 index 000000000..05f237f84 --- /dev/null +++ b/src/Neo.SmartContract.Template/templates/neocontractowner/ProjectName.csproj @@ -0,0 +1,25 @@ + + + + net7.0 + + + + + + + + --base-name $(AssemblyName) + --base-name $(MSBuildProjectName) + --nullable $(Nullable) + --checked + -d + + + + + + + + + diff --git a/src/neo.png b/src/neo.png new file mode 100644 index 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y*;3~sQeLg&eZHdH%o=b@W0()A+mlpJwq4S0d=2=ky3S198sTL6r5FzxCo>BAv_bc7yuBP-ySc(KY86pPJ+* zcH*Q|F*Y$6)--p$rTJuxpi*!_y++{0CRWjIP%*rstUBzpShPhwz0@`(?PD4f@30>rhsthyd5egCPi)F?Ed6G0a>7L(r1z7} Q(E|mb5N=LY4nax(0@8w_9{>OV literal 0 HcmV?d00001 From 8fdc94de70c03429fc8f67dd005de74e354ec31b Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 5 Jan 2024 02:30:20 +0800 Subject: [PATCH 3/3] fix error message (#854) --- src/Neo.Compiler.CSharp/DiagnosticId.cs | 1 + src/Neo.Compiler.CSharp/MethodConvert.cs | 37 ++++++++++++++---------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Neo.Compiler.CSharp/DiagnosticId.cs b/src/Neo.Compiler.CSharp/DiagnosticId.cs index 2d57f420a..beb604bd6 100644 --- a/src/Neo.Compiler.CSharp/DiagnosticId.cs +++ b/src/Neo.Compiler.CSharp/DiagnosticId.cs @@ -33,5 +33,6 @@ static class DiagnosticId public const string InvalidMethodName = "NC3002"; public const string MethodNameConflict = "NC3003"; public const string EventNameConflict = "NC3004"; + public const string InvalidInitialValue = "NC3005"; } } diff --git a/src/Neo.Compiler.CSharp/MethodConvert.cs b/src/Neo.Compiler.CSharp/MethodConvert.cs index 9910f0122..ee3d39fd1 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert.cs @@ -339,22 +339,29 @@ private void ProcessFieldInitializer(SemanticModel model, IFieldSymbol field, Ac preInitialize?.Invoke(); string value = (string)initialValue.ConstructorArguments[0].Value!; ContractParameterType type = (ContractParameterType)initialValue.ConstructorArguments[1].Value!; - switch (type) + try { - case ContractParameterType.String: - Push(value); - break; - case ContractParameterType.ByteArray: - Push(value.HexToBytes(true)); - break; - case ContractParameterType.Hash160: - Push((UInt160.TryParse(value, out var hash) ? hash : value.ToScriptHash(context.Options.AddressVersion)).ToArray()); - break; - case ContractParameterType.PublicKey: - Push(ECPoint.Parse(value, ECCurve.Secp256r1).EncodePoint(true)); - break; - default: - throw new CompilationException(field, DiagnosticId.InvalidInitialValueType, $"Unsupported initial value type: {type}"); + switch (type) + { + case ContractParameterType.String: + Push(value); + break; + case ContractParameterType.ByteArray: + Push(value.HexToBytes(true)); + break; + case ContractParameterType.Hash160: + Push((UInt160.TryParse(value, out var hash) ? hash : value.ToScriptHash(context.Options.AddressVersion)).ToArray()); + break; + case ContractParameterType.PublicKey: + Push(ECPoint.Parse(value, ECCurve.Secp256r1).EncodePoint(true)); + break; + default: + throw new CompilationException(field, DiagnosticId.InvalidInitialValueType, $"Unsupported initial value type: {type}"); + } + } + catch (Exception ex) when (ex is not CompilationException) + { + throw new CompilationException(field, DiagnosticId.InvalidInitialValue, $"Invalid initial value: {value} of type: {type}"); } postInitialize?.Invoke(); }