forked from neo-project/neo-devpack-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleNep17Token.cs
More file actions
140 lines (108 loc) · 4.23 KB
/
Copy pathSampleNep17Token.cs
File metadata and controls
140 lines (108 loc) · 4.23 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
// Copyright (C) 2015-2025 The Neo Project.
//
// Nep17Token.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
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 NEP17
{
/// <inheritdoc />
[DisplayName("SampleNep17Token")]
[ContractAuthor("core-dev", "dev@neo.org")]
[ContractVersion("0.0.1")]
[ContractDescription("A sample NEP-17 token")]
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples/")]
[ContractPermission(Permission.Any, Method.Any)]
[SupportedStandards(NepStandard.Nep17)]
public class SampleNep17Token : Nep17Token
{
#region Owner
private const byte PrefixOwner = 0xff;
private static readonly UInt160 InitialOwner = "NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP";
[Safe]
public static UInt160 GetOwner()
{
var currentOwner = Storage.Get(new[] { PrefixOwner });
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[] { PrefixOwner }, newOwner);
OnSetOwner(newOwner);
}
}
#endregion
#region Minter
private const byte PrefixMinter = 0xfd;
private static readonly UInt160 InitialMinter = "NUuJw4C4XJFzxAvSZnFTfsNoWZytmQKXQP";
[Safe]
public static UInt160 GetMinter()
{
var currentMinter = Storage.Get(new[] { PrefixMinter });
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.IsValid) return;
Storage.Put(new[] { PrefixMinter }, newMinter);
OnSetMinter(newMinter);
}
public new static void Mint(UInt160 to, BigInteger amount)
{
if (IsOwner() == false && IsMinter() == false)
throw new InvalidOperationException("No Authorization!");
Nep17Token.Mint(to, amount);
}
#endregion
#region Example.SmartContract.NEP17
public override string Symbol { [Safe] get => "SampleNep17Token"; }
public override byte Decimals { [Safe] get => 8; }
public new static void Burn(UInt160 account, BigInteger amount)
{
if (IsOwner() == false && IsMinter() == false)
throw new InvalidOperationException("No Authorization!");
Nep17Token.Burn(account, 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
}
}