@@ -71,7 +71,7 @@ Logo = Logo or 'SBCCXwwecBlDqRLUjb8dYABExTJXLieawf7m2aBJ-KY'
71
71
Info
72
72
]]
73
73
--
74
- Handlers .add (' info' , " Info" , function (msg )
74
+ Handlers .add (' info' , Handlers . utils . hasMatchingTag ( " Action " , " Info" ) , function (msg )
75
75
msg .reply ({
76
76
Name = Name ,
77
77
Ticker = Ticker ,
84
84
Balance
85
85
]]
86
86
--
87
- Handlers .add (' balance' , " Balance" , function (msg )
87
+ Handlers .add (' balance' , Handlers . utils . hasMatchingTag ( " Action " , " Balance" ) , function (msg )
88
88
local bal = ' 0'
89
89
90
90
-- If not Recipient is provided, then return the Senders balance
@@ -97,27 +97,42 @@ Handlers.add('balance', "Balance", function(msg)
97
97
elseif Balances [msg .From ] then
98
98
bal = Balances [msg .From ]
99
99
end
100
-
101
- msg .reply ({
102
- Balance = bal ,
103
- Ticker = Ticker ,
104
- Account = msg .Tags .Recipient or msg .From ,
105
- Data = bal
106
- })
100
+ if msg .reply then
101
+ msg .reply ({
102
+ Balance = bal ,
103
+ Ticker = Ticker ,
104
+ Account = msg .Tags .Recipient or msg .From ,
105
+ Data = bal
106
+ })
107
+ else
108
+ Send ({
109
+ Target = msg .From ,
110
+ Balance = bal ,
111
+ Ticker = Ticker ,
112
+ Account = msg .Tags .Recipient or msg .From ,
113
+ Data = bal
114
+ })
115
+ end
107
116
end )
108
117
109
118
--[[
110
119
Balances
111
120
]]
112
121
--
113
- Handlers .add (' balances' , " Balances" ,
114
- function (msg ) msg .reply ({ Data = json .encode (Balances ) }) end )
122
+ Handlers .add (' balances' , Handlers .utils .hasMatchingTag (" Action" , " Balances" ),
123
+ function (msg )
124
+ if msg .reply then
125
+ msg .reply ({ Data = json .encode (Balances ) })
126
+ else
127
+ Send ({Target = msg .From , Data = json .encode (Balances ) })
128
+ end
129
+ end )
115
130
116
131
--[[
117
132
Transfer
118
133
]]
119
134
--
120
- Handlers .add (' transfer' , " Transfer" , function (msg )
135
+ Handlers .add (' transfer' , Handlers . utils . hasMatchingTag ( " Action " , " Transfer" ) , function (msg )
121
136
assert (type (msg .Recipient ) == ' string' , ' Recipient is required!' )
122
137
assert (type (msg .Quantity ) == ' string' , ' Quantity is required!' )
123
138
assert (bint .__lt (0 , bint (msg .Quantity )), ' Quantity must be greater than 0' )
@@ -165,23 +180,36 @@ Handlers.add('transfer', "Transfer", function(msg)
165
180
end
166
181
167
182
-- Send Debit-Notice and Credit-Notice
168
- msg .reply (debitNotice )
183
+ if msg .reply then
184
+ msg .reply (debitNotice )
185
+ else
186
+ Send (debitNotice )
187
+ end
169
188
Send (creditNotice )
170
189
end
171
190
else
172
- msg .reply ({
173
- Action = ' Transfer-Error' ,
174
- [' Message-Id' ] = msg .Id ,
175
- Error = ' Insufficient Balance!'
176
- })
191
+ if msg .reply then
192
+ msg .reply ({
193
+ Action = ' Transfer-Error' ,
194
+ [' Message-Id' ] = msg .Id ,
195
+ Error = ' Insufficient Balance!'
196
+ })
197
+ else
198
+ Send ({
199
+ Target = msg .From ,
200
+ Action = ' Transfer-Error' ,
201
+ [' Message-Id' ] = msg .Id ,
202
+ Error = ' Insufficient Balance!'
203
+ })
204
+ end
177
205
end
178
206
end )
179
207
180
208
--[[
181
209
Mint
182
210
]]
183
211
--
184
- Handlers .add (' mint' , " Mint" , function (msg )
212
+ Handlers .add (' mint' , Handlers . utils . hasMatchingTag ( " Action " , " Mint" ) , function (msg )
185
213
assert (type (msg .Quantity ) == ' string' , ' Quantity is required!' )
186
214
assert (bint (0 ) < bint (msg .Quantity ), ' Quantity must be greater than zero!' )
187
215
@@ -191,43 +219,70 @@ Handlers.add('mint', "Mint", function(msg)
191
219
-- Add tokens to the token pool, according to Quantity
192
220
Balances [msg .From ] = utils .add (Balances [msg .From ], msg .Quantity )
193
221
TotalSupply = utils .add (TotalSupply , msg .Quantity )
194
- msg .reply ({
195
- Data = Colors .gray .. " Successfully minted " .. Colors .blue .. msg .Quantity .. Colors .reset
196
- })
222
+ if msg .reply then
223
+ msg .reply ({
224
+ Data = Colors .gray .. " Successfully minted " .. Colors .blue .. msg .Quantity .. Colors .reset
225
+ })
226
+ else
227
+ Send ({
228
+ Target = msg .From ,
229
+ Data = Colors .gray .. " Successfully minted " .. Colors .blue .. msg .Quantity .. Colors .reset
230
+ })
231
+ end
197
232
else
198
- msg .reply ({
199
- Action = ' Mint-Error' ,
200
- [' Message-Id' ] = msg .Id ,
201
- Error = ' Only the Process Id can mint new ' .. Ticker .. ' tokens!'
202
- })
233
+ if msg .reply then
234
+ msg .reply ({
235
+ Action = ' Mint-Error' ,
236
+ [' Message-Id' ] = msg .Id ,
237
+ Error = ' Only the Process Id can mint new ' .. Ticker .. ' tokens!'
238
+ })
239
+ else
240
+ Send ({
241
+ Target = msg .From ,
242
+ Action = ' Mint-Error' ,
243
+ [' Message-Id' ] = msg .Id ,
244
+ Error = ' Only the Process Id can mint new ' .. Ticker .. ' tokens!'
245
+ })
246
+ end
203
247
end
204
248
end )
205
249
206
250
--[[
207
251
Total Supply
208
252
]]
209
253
--
210
- Handlers .add (' totalSupply' , " Total-Supply" , function (msg )
254
+ Handlers .add (' totalSupply' , Handlers . utils . hasMatchingTag ( " Action " , " Total-Supply" ) , function (msg )
211
255
assert (msg .From ~= ao .id , ' Cannot call Total-Supply from the same process!' )
212
-
213
- msg .reply ({
214
- Action = ' Total-Supply' ,
215
- Data = TotalSupply ,
216
- Ticker = Ticker
217
- })
256
+ if msg .reply then
257
+ msg .reply ({
258
+ Action = ' Total-Supply' ,
259
+ Data = TotalSupply ,
260
+ Ticker = Ticker
261
+ })
262
+ else
263
+ Send ({
264
+ Target = msg .From ,
265
+ Action = ' Total-Supply' ,
266
+ Data = TotalSupply ,
267
+ Ticker = Ticker
268
+ })
269
+ end
218
270
end )
219
271
220
272
--[[
221
273
Burn
222
274
]] --
223
- Handlers .add (' burn' , ' Burn' , function (msg )
224
- assert (type (msg .Quantity ) == ' string' , ' Quantity is required!' )
225
- assert (bint (msg .Quantity ) <= bint (Balances [msg .From ]), ' Quantity must be less than or equal to the current balance!' )
226
-
227
- Balances [msg .From ] = utils .subtract (Balances [msg .From ], msg .Quantity )
228
- TotalSupply = utils .subtract (TotalSupply , msg .Quantity )
275
+ Handlers .add (' burn' , Handlers .utils .hasMatchingTag (" Action" ,' Burn' ), function (msg )
276
+ assert (type (msg .Tags .Quantity ) == ' string' , ' Quantity is required!' )
277
+ assert (bint (msg .Tags .Quantity ) <= bint (Balances [msg .From ]), ' Quantity must be less than or equal to the current balance!' )
229
278
230
- msg .reply ({
231
- Data = Colors .gray .. " Successfully burned " .. Colors .blue .. msg .Quantity .. Colors .reset
232
- })
279
+ Balances [msg .From ] = utils .subtract (Balances [msg .From ], msg .Tags .Quantity )
280
+ TotalSupply = utils .subtract (TotalSupply , msg .Tags .Quantity )
281
+ if msg .reply then
282
+ msg .reply ({
283
+ Data = Colors .gray .. " Successfully burned " .. Colors .blue .. msg .Tags .Quantity .. Colors .reset
284
+ })
285
+ else
286
+ Send ({Target = msg .From , Data = Colors .gray .. " Successfully burned " .. Colors .blue .. msg .Tags .Quantity .. Colors .reset })
287
+ end
233
288
end )
0 commit comments