This repository was archived by the owner on Apr 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleCoin.cs
More file actions
164 lines (126 loc) · 4.47 KB
/
ExampleCoin.cs
File metadata and controls
164 lines (126 loc) · 4.47 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright (C) 2023 Christopher R Schuchardt
//
// The neo-examples-csharp is free software distributed under the
// MIT software license, see the accompanying file LICENSE in
// the main directory of the project for more details.
using Neo;
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 ExampleCoin;
[DisplayName("ExampleCoin")]
[ManifestExtra("Author", "neo.events")]
[ManifestExtra("Description", "Simple Smart Contract Example")]
[ManifestExtra("Email", "examples@neo.events")]
[ManifestExtra("Website", "https://www.neo.events/")]
[ManifestExtra("Version", "1.0.0")]
[ContractSourceCode("https://github.com/cschuchardt88/neo-examples-csharp")]
[SupportedStandards("NEP-17")]
[ContractPermission("*", "*")]
public class ExampleCoin : Nep17Token
{
#region Owner
private const byte Prefix_Owner = 0x02;
[InitialValue("NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP", 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 Minter
private const byte Prefix_Minter = 0x03;
[InitialValue("NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP", Neo.SmartContract.ContractParameterType.Hash160)]
private static readonly UInt160 InitialMinter = default;
[Safe]
public static UInt160 GetMinter()
{
var currentMinter = Storage.Get(new[] { Prefix_Minter });
if (currentMinter == null)
return InitialMinter;
return (UInt160)currentMinter;
}
private static bool IsMinter() =>
Runtime.CheckWitness(GetMinter());
public delegate void OnSetMinterDelegate(UInt160 newMinter);
[DisplayName("SetMinter")]
public static event OnSetMinterDelegate OnSetMinter;
public static void SetMinter(UInt160 newMinter)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
if (newMinter != null && newMinter.IsValid)
{
Storage.Put(new[] { Prefix_Minter }, newMinter);
OnSetMinter(newMinter);
}
}
public static new void Mint(UInt160 to, BigInteger amount)
{
if (IsOwner() == false && IsMinter() == false)
throw new InvalidOperationException("No Authorization!");
Nep17Token.Mint(to, amount);
}
#endregion
#region NEP17
[Safe]
public override byte Decimals() => 8;
[Safe]
public override string Symbol() => "EXAMPLE";
public static new void Burn(UInt160 account, BigInteger amount)
{
if (IsOwner() == false && IsMinter() == false)
throw new InvalidOperationException("No Authorization!");
Nep17Token.Burn(account, amount);
}
#endregion
#region Payment
public static bool Withdraw(UInt160 to, BigInteger amount)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
if (amount <= 0)
return false;
return GAS.Transfer(Runtime.ExecutingScriptHash, to, amount);
}
public static void OnNEP17Payment(UInt160 from, BigInteger amount, object data)
{
if (Runtime.CallingScriptHash == GAS.Hash && amount > 0)
Nep17Token.Mint(from, amount);
}
#endregion
#region Basic
[Safe]
public static bool Verify() => IsOwner();
public static bool Update(ByteString nefFile, string manifest)
{
if (IsOwner() == false)
throw new InvalidOperationException("No Authorization!");
ContractManagement.Update(nefFile, manifest);
return true;
}
#endregion
}