-
Notifications
You must be signed in to change notification settings - Fork 3
/
SMC.glua
101 lines (82 loc) · 2.75 KB
/
SMC.glua
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
type Storage = {
name:string,
balance:Map<int>,
transfer_version:int
}
var M = Contract<Storage>()
function M:init()
print("³õʼ»¯")
self.storage.name = "SMC"
self.storage.transfer_version = 0
self.storage.balance = {}
self.storage.balance['ACTBvVxAdDsVBW81gyyWsCBtEcn63pw7wS23'] = 100000000000000
end
function M:transfer_to(arg:string)
arg=string.gsub(arg, "%s","")
local items:Array<string>
items = []
items = string.split(arg, '|')
local to_address = items[1]
local size = string.len(to_address)
if size < 35 then
emit transfer_to_fail('Transfer address is invalid')
return
end
if size > 50 then
to_address = string.sub(to_address, 1, size-32)
end
if string.sub(to_address, 1,3) ~= "ACT" then
emit transfer_to_fail('Transfer address is invalid')
return
end
if caller_address == to_address then
emit transfer_to_fail("Transfer address is invalid")
return
end
local transfer_balance = tonumber(items[2])
if transfer_balance == nil then
emit transfer_to_fail("Transfer balance is invalid")
return
end
local transfer_balance_number1 = (transfer_balance+0.0000001) * 100000
local transfer_balance_number = tointeger(transfer_balance_number1)
if transfer_balance_number <= 0 then
--add error massage
emit transfer_to_fail('Transfer balance is invalid')
return
end
local balance = self.storage.balance[caller_address]
if balance == nil then
emit transfer_to_fail('Transfer Account is invalid')
return
end
if balance < transfer_balance_number then
--add error massage
emit transfer_to_fail('Balance is insufficient')
return
end
balance = balance - transfer_balance_number
self.storage.balance[caller_address] = balance
local to_balance = self.storage.balance[to_address]
if to_balance == nil then
to_balance = 0
end
to_balance = to_balance + transfer_balance_number
self.storage.balance[to_address] = to_balance
local version = self.storage.transfer_version
version = tointeger((version+1)%1000000 )
self.storage.transfer_version = version
local temp_transfer_log = caller_address..":"..tostring(balance)..","..to_address..":"..tostring(to_balance)..","..tostring(version)..","..tostring(get_chain_now())
emit transfer_to_success(temp_transfer_log)
end
function M:query_balance()
if self.storage.balance[caller_address] == nil then
print("TOKEN:SMC:BLC:"..caller_address..":0:END")
return
end
local balance = self.storage.balance[caller_address]
print("TOKEN:SMC:BLC:"..caller_address..":"..tostring(balance)..":END")
end
function M:COIN_SMC()
end
return M