-
Notifications
You must be signed in to change notification settings - Fork 1
/
HelloWorldContract.cs
57 lines (50 loc) · 1.87 KB
/
HelloWorldContract.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.ComponentModel;
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
namespace DevHawk.SampleContracts
{
[DisplayName("HelloWorld")]
[ManifestExtra("Author", "Harry Pierson")]
[ManifestExtra("Email", "[email protected]")]
[ManifestExtra("Description", "This is an example contract")]
public class HelloWorldContract : SmartContract
{
// using strings for keys to avoid insertion of CONVERT instruction
// https://github.com/neo-project/neo-devpack-dotnet/issues/777
const string Prefix_SampleValue = "S";
const string Prefix_ContractOwner = "O";
[Safe]
public static ByteString Get()
{
return Storage.Get(Storage.CurrentContext, Prefix_SampleValue);
}
public static void Put(ByteString value)
{
Storage.Put(Storage.CurrentContext, Prefix_SampleValue, value);
}
public static void Delete()
{
Storage.Delete(Storage.CurrentContext, Prefix_SampleValue);
}
[DisplayName("_deploy")]
public static void Deploy(object _, bool update)
{
if (update) return;
var tx = (Transaction)Runtime.ScriptContainer;
Storage.Put(Storage.CurrentContext, Prefix_ContractOwner, tx.Sender);
}
public static void Update(ByteString nefFile, string manifest)
{
var contractOwner = (UInt160)Storage.Get(Storage.CurrentContext, Prefix_ContractOwner);
if (!Runtime.CheckWitness(contractOwner))
{
throw new Exception("Only the contract owner can update the contract");
}
ContractManagement.Update(nefFile, manifest, null);
}
}
}