From 1f1a9dbb8f25094b40919e1e899d3d8eb13d2e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 10:22:40 +0800 Subject: [PATCH 1/8] Add Verify --- templates/Template.CSharp/Contract1.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index 51ffa80d5..5cf312b1d 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -16,5 +16,10 @@ public static bool Main() Storage.Put("Hello", "World"); return true; } + + // 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. + public static bool Verify() => true; } } From fc1ebef871c6da5aa112d031dd41077c6b117ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 10:39:56 +0800 Subject: [PATCH 2/8] add update and destroy --- templates/Template.CSharp/Contract1.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index 5cf312b1d..79f25073b 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -1,6 +1,7 @@ using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Services.Neo; using System; +using System.Diagnostics.Contracts; using System.Numerics; namespace $safeprojectname$ @@ -11,15 +12,35 @@ namespace $safeprojectname$ [Features(ContractFeatures.HasStorage)] public class Contract1 : SmartContract { + static readonly byte[] Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash(); + public static bool Main() { Storage.Put("Hello", "World"); return true; } - + + public static bool Destroy() + { + if (!IsOwner()) throw new Exception("No authorization."); + Contract.Destroy(); + return true; + } + + private static bool IsOwner() => Runtime.CheckWitness(Owner); + + public static bool Update(byte[] script, string manifest) + { + if (!IsOwner()) throw new Exception("No authorization."); + // Check empty + if (script.Length == 0 && manifest.Length == 0) return false; + Contract.Update(script, manifest); + return true; + } + // 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. - public static bool Verify() => true; + public static bool Verify() => IsOwner(); } } From f8b287dcd67fbab5a38029b00b4d5b977c580394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 10:40:53 +0800 Subject: [PATCH 3/8] update --- templates/Template.CSharp/Contract1.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index 79f25073b..c8faa54b5 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -1,7 +1,6 @@ using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Services.Neo; using System; -using System.Diagnostics.Contracts; using System.Numerics; namespace $safeprojectname$ From d7b0a0e340cc45c1f58d251e4e6e91f939ce52b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 10:46:31 +0800 Subject: [PATCH 4/8] update --- templates/Template.CSharp/Contract1.cs | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index c8faa54b5..203cdfa2d 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -11,23 +11,22 @@ namespace $safeprojectname$ [Features(ContractFeatures.HasStorage)] public class Contract1 : SmartContract { + //Replace it with your own address. static readonly byte[] Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash(); + 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. + public static bool Verify() => IsOwner(); + public static bool Main() { Storage.Put("Hello", "World"); return true; } - public static bool Destroy() - { - if (!IsOwner()) throw new Exception("No authorization."); - Contract.Destroy(); - return true; - } - - private static bool IsOwner() => Runtime.CheckWitness(Owner); - public static bool Update(byte[] script, string manifest) { if (!IsOwner()) throw new Exception("No authorization."); @@ -37,9 +36,11 @@ public static bool Update(byte[] script, string manifest) return true; } - // 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. - public static bool Verify() => IsOwner(); + public static bool Destroy() + { + if (!IsOwner()) throw new Exception("No authorization."); + Contract.Destroy(); + return true; + } } } From b2649d434a6705bb41725e65ea37e14750aaa57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 04:43:38 -0500 Subject: [PATCH 5/8] Update templates/Template.CSharp/Contract1.cs Co-authored-by: Erik Zhang --- templates/Template.CSharp/Contract1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index 203cdfa2d..9294d0f58 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -11,7 +11,7 @@ namespace $safeprojectname$ [Features(ContractFeatures.HasStorage)] public class Contract1 : SmartContract { - //Replace it with your own address. + //TODO: Replace it with your own address. static readonly byte[] Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB".ToScriptHash(); private static bool IsOwner() => Runtime.CheckWitness(Owner); From 41f41bd144e1552f6b52248f4e96bf0b512f46d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 04:43:50 -0500 Subject: [PATCH 6/8] Update templates/Template.CSharp/Contract1.cs Co-authored-by: Erik Zhang --- templates/Template.CSharp/Contract1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index 9294d0f58..11cdd4a8c 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -21,7 +21,7 @@ public class Contract1 : SmartContract // For example, this method needs to be called when withdrawing token from the contract. public static bool Verify() => IsOwner(); - public static bool Main() + public static bool MyMethod() { Storage.Put("Hello", "World"); return true; From f5266d5a4dc7528c3464152e9b95f5d2db9b0bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Fri, 11 Sep 2020 17:46:06 +0800 Subject: [PATCH 7/8] update --- templates/Template.CSharp/Contract1.cs | 8 ++------ templates/Template.NEP5.CSharp/NEP5.Owner.cs | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index 203cdfa2d..bcfe566a3 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -27,20 +27,16 @@ public static bool Main() return true; } - public static bool Update(byte[] script, string manifest) + public static void Update(byte[] script, string manifest) { if (!IsOwner()) throw new Exception("No authorization."); - // Check empty - if (script.Length == 0 && manifest.Length == 0) return false; Contract.Update(script, manifest); - return true; } - public static bool Destroy() + public static void Destroy() { if (!IsOwner()) throw new Exception("No authorization."); Contract.Destroy(); - return true; } } } diff --git a/templates/Template.NEP5.CSharp/NEP5.Owner.cs b/templates/Template.NEP5.CSharp/NEP5.Owner.cs index 03fe9af32..94bd8f545 100644 --- a/templates/Template.NEP5.CSharp/NEP5.Owner.cs +++ b/templates/Template.NEP5.CSharp/NEP5.Owner.cs @@ -19,20 +19,16 @@ public static bool Deploy() return true; } - public static bool Update(byte[] script, string manifest) + public static void Update(byte[] script, string manifest) { if (!IsOwner()) throw new Exception("No authorization."); - // Check empty - if (script.Length == 0 && manifest.Length == 0) return false; Contract.Update(script, manifest); - return true; } - public static bool Destroy() + public static void Destroy() { if (!IsOwner()) throw new Exception("No authorization."); Contract.Destroy(); - return true; } private static bool IsOwner() => Runtime.CheckWitness(Owner); From c0fab3cb3bc8c071e56dca2cd995e4857154e771 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Tue, 15 Sep 2020 11:10:27 +0800 Subject: [PATCH 8/8] Update templates/Template.CSharp/Contract1.cs Co-authored-by: Luchuan --- templates/Template.CSharp/Contract1.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/Template.CSharp/Contract1.cs b/templates/Template.CSharp/Contract1.cs index f4ae78fba..6bf538336 100644 --- a/templates/Template.CSharp/Contract1.cs +++ b/templates/Template.CSharp/Contract1.cs @@ -21,6 +21,7 @@ public class Contract1 : SmartContract // For example, this method needs to be called when withdrawing token from the contract. public static bool Verify() => IsOwner(); + // TODO: Replace it with your methods. public static bool MyMethod() { Storage.Put("Hello", "World");