-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathContract1.cs
104 lines (96 loc) · 3.86 KB
/
Contract1.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
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
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using System;
using System.ComponentModel;
using System.Numerics;
namespace Nep5_Contract
{
public class ContractNep5 : SmartContract
{
//nep5 notify
public delegate void deleTransfer(byte[] from, byte[] to, BigInteger value);
[DisplayName("transfer")]
public static event deleTransfer Transferred;
public static readonly byte[] SuperAdmin = Helper.ToScriptHash("AYYiDtPGaxt7rVtEEp9tiw4wgtg8jVEnSP");
//nep5 func
public static BigInteger TotalSupply()
{
return Storage.Get(Storage.CurrentContext, "totalSupply").AsBigInteger();
}
public static string Name()
{
return "Trinity Network Credit";
}
public static string Symbol()
{
return "TNC";
}
private const ulong factor = 100000000;
private const ulong totalCoin = 1000000000 * factor;
public static byte Decimals()
{
return 8;
}
public static BigInteger BalanceOf(byte[] address)
{
return Storage.Get(Storage.CurrentContext, address).AsBigInteger();
}
public static bool Transfer(byte[] from, byte[] to, BigInteger value)
{
if (value <= 0) return false;
if (!Runtime.CheckWitness(from)) return false;
if (from == to) return true;
BigInteger from_value = Storage.Get(Storage.CurrentContext, from).AsBigInteger();
if (from_value < value) return false;
if (from_value == value)
Storage.Delete(Storage.CurrentContext, from);
else
Storage.Put(Storage.CurrentContext, from, from_value - value);
BigInteger to_value = Storage.Get(Storage.CurrentContext, to).AsBigInteger();
Storage.Put(Storage.CurrentContext, to, to_value + value);
Transferred(from, to, value);
return true;
}
public static object Main(string method, object[] args)
{
var magicstr = "2018-01-11";
if (Runtime.Trigger == TriggerType.Verification)//
{
return Runtime.CheckWitness(SuperAdmin);
}
else if (Runtime.Trigger == TriggerType.Application)
{
//this is in nep5
if (method == "totalSupply") return TotalSupply();
if (method == "name") return Name();
if (method == "symbol") return Symbol();
if (method == "decimals") return Decimals();
if (method == "balanceOf")
{
if (args.Length != 1) return 0;
byte[] account = (byte[])args[0];
return BalanceOf(account);
}
if (method == "transfer")
{
if (args.Length != 3) return false;
byte[] from = (byte[])args[0];
byte[] to = (byte[])args[1];
BigInteger value = (BigInteger)args[2];
return Transfer(from, to, value);
}
if (method == "deploy")//fix count
{
if (args.Length != 1) return false;
if (!Runtime.CheckWitness(SuperAdmin)) return false;
byte[] total_supply = Storage.Get(Storage.CurrentContext, "totalSupply");
if (total_supply.Length != 0) return false;
Storage.Put(Storage.CurrentContext, SuperAdmin, totalCoin);
Storage.Put(Storage.CurrentContext, "totalSupply", totalCoin);
Transferred(null, SuperAdmin, totalCoin);
}
}
return false;
}
}
}