Skip to content
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

Update demo contract #353

Merged
merged 11 commits into from
Sep 15, 2020
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()
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
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