Skip to content

Commit

Permalink
Update demo contract (#353)
Browse files Browse the repository at this point in the history
* Add Verify

* add update and destroy

* update

* update

* Update templates/Template.CSharp/Contract1.cs

Co-authored-by: Erik Zhang <[email protected]>

* Update templates/Template.CSharp/Contract1.cs

Co-authored-by: Erik Zhang <[email protected]>

* update

* Update templates/Template.CSharp/Contract1.cs

Co-authored-by: Luchuan <[email protected]>

Co-authored-by: Erik Zhang <[email protected]>
Co-authored-by: Luchuan <[email protected]>
  • Loading branch information
3 people authored Sep 15, 2020
1 parent eea7a9d commit 2ebb098
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 24 additions & 1 deletion templates/Template.CSharp/Contract1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,33 @@ namespace $safeprojectname$
[Features(ContractFeatures.HasStorage)]
public class Contract1 : SmartContract
{
public static bool Main()
//TODO: 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();

// TODO: Replace it with your methods.
public static bool MyMethod()
{
Storage.Put("Hello", "World");
return true;
}

public static void Update(byte[] script, string manifest)
{
if (!IsOwner()) throw new Exception("No authorization.");
Contract.Update(script, manifest);
}

public static void Destroy()
{
if (!IsOwner()) throw new Exception("No authorization.");
Contract.Destroy();
}
}
}
8 changes: 2 additions & 6 deletions templates/Template.NEP5.CSharp/NEP5.Owner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2ebb098

Please sign in to comment.