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 000000000..1a71de07e Binary files /dev/null and b/src/Neo.SmartContract.Template/templates/neocontract/.template.config/icon.png differ 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 000000000..1a71de07e Binary files /dev/null and b/src/Neo.SmartContract.Template/templates/neocontractnep17/.template.config/icon.png differ 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 000000000..1a71de07e Binary files /dev/null and b/src/Neo.SmartContract.Template/templates/neocontractoracle/.template.config/icon.png differ 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 000000000..1a71de07e Binary files /dev/null and b/src/Neo.SmartContract.Template/templates/neocontractowner/.template.config/icon.png differ 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 000000000..1a71de07e Binary files /dev/null and b/src/neo.png differ