Skip to content

Commit f204897

Browse files
authored
Merge pull request #326 from permaweb/twilson63/bump-2-0-0
chore: bump aos to 2.0
2 parents feaf86d + 36f652c commit f204897

16 files changed

+361
-122
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
<img alt="logo">
55
</picture>
66

7-
Status: Preview rc2
8-
Version: 2.0.0-rc2
9-
Module: `PSPMkkFrJzYI2bQbkmeEQ5ONmeR-FJZu0fNQoSCU1-I`
107

11-
Sqlite-Module: `C4bxMlK8d_wQ-QpXIIZLU8UWXu6Sd8PDJw7HN3nNE2I`
8+
Version: 2.0.0
9+
Module: `bkjb55i07GUCUSWROtKK4HU1mBS_X0TyH3M5jMV6aPg`
1210

11+
Sqlite-Module: `aGVVWHldKA7GBlI_w7Qp_agO6aKjCoOTPA1G2OlluXE`
1312

1413
## Requirements
1514

blueprints/staking.lua

+19-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ Handlers.stake = function(msg)
2929
Stakers[msg.From].amount = utils.add(Stakers[msg.From].amount, msg.Tags.Quantity)
3030
Stakers[msg.From].unstake_at = height + delay
3131
print("Successfully Staked " .. msg.Tags.Quantity)
32-
msg.reply({ Data = "Successfully Staked " .. msg.Tags.Quantity})
32+
if msg.reply then
33+
msg.reply({ Data = "Successfully Staked " .. msg.Tags.Quantity})
34+
else
35+
Send({Target = msg.From, Data = "Successfully Staked " .. msg.Tags.Quantity })
36+
end
3337
end
3438

3539
-- Unstake Action Handler
@@ -38,10 +42,14 @@ Handlers.unstake = function(msg)
3842
assert(stakerInfo and bint(stakerInfo.amount) >= bint(msg.Tags.Quantity), "Insufficient staked amount")
3943
stakerInfo.amount = utils.subtract(stakerInfo.amount, msg.Tags.Quantity)
4044
Unstaking[msg.From] = {
41-
amount = msg.Quantity,
45+
amount = msg.Tags.Quantity,
4246
release_at = stakerInfo.unstake_at
4347
}
44-
msg.reply({ Data = "Successfully unstaked " .. msg.Tags.Quantity})
48+
if msg.reply then
49+
msg.reply({ Data = "Successfully unstaked " .. msg.Tags.Quantity})
50+
else
51+
Send({Target = msg.From, Data = "Successfully unstaked " .. msg.Tags.Quantity })
52+
end
4553
end
4654

4755
-- Finalization Handler
@@ -68,8 +76,14 @@ local function continue(fn)
6876
end
6977
end
7078

71-
Handlers.add('staking.balances', 'Stakers',
72-
function(msg) msg.reply({ Data = require('json').encode(Stakers) }) end)
79+
Handlers.add('staking.balances', Handlers.utils.hasMatchingTag("Action", 'Stakers'),
80+
function(msg)
81+
if msg.reply then
82+
msg.reply({ Data = require('json').encode(Stakers) })
83+
else
84+
Send({Target = msg.From, Data = require('json').encode(Stakers) })
85+
end
86+
end)
7387
-- Registering Handlers
7488
Handlers.add("staking.stake",
7589
continue(Handlers.utils.hasMatchingTag("Action", "Stake")), Handlers.stake)

blueprints/token.lua

+98-43
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Logo = Logo or 'SBCCXwwecBlDqRLUjb8dYABExTJXLieawf7m2aBJ-KY'
7171
Info
7272
]]
7373
--
74-
Handlers.add('info', "Info", function(msg)
74+
Handlers.add('info', Handlers.utils.hasMatchingTag("Action", "Info"), function(msg)
7575
msg.reply({
7676
Name = Name,
7777
Ticker = Ticker,
@@ -84,7 +84,7 @@ end)
8484
Balance
8585
]]
8686
--
87-
Handlers.add('balance', "Balance", function(msg)
87+
Handlers.add('balance', Handlers.utils.hasMatchingTag("Action", "Balance"), function(msg)
8888
local bal = '0'
8989

9090
-- If not Recipient is provided, then return the Senders balance
@@ -97,27 +97,42 @@ Handlers.add('balance', "Balance", function(msg)
9797
elseif Balances[msg.From] then
9898
bal = Balances[msg.From]
9999
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
107116
end)
108117

109118
--[[
110119
Balances
111120
]]
112121
--
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)
115130

116131
--[[
117132
Transfer
118133
]]
119134
--
120-
Handlers.add('transfer', "Transfer", function(msg)
135+
Handlers.add('transfer', Handlers.utils.hasMatchingTag("Action", "Transfer"), function(msg)
121136
assert(type(msg.Recipient) == 'string', 'Recipient is required!')
122137
assert(type(msg.Quantity) == 'string', 'Quantity is required!')
123138
assert(bint.__lt(0, bint(msg.Quantity)), 'Quantity must be greater than 0')
@@ -165,23 +180,36 @@ Handlers.add('transfer', "Transfer", function(msg)
165180
end
166181

167182
-- 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
169188
Send(creditNotice)
170189
end
171190
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
177205
end
178206
end)
179207

180208
--[[
181209
Mint
182210
]]
183211
--
184-
Handlers.add('mint', "Mint", function(msg)
212+
Handlers.add('mint', Handlers.utils.hasMatchingTag("Action","Mint"), function(msg)
185213
assert(type(msg.Quantity) == 'string', 'Quantity is required!')
186214
assert(bint(0) < bint(msg.Quantity), 'Quantity must be greater than zero!')
187215

@@ -191,43 +219,70 @@ Handlers.add('mint', "Mint", function(msg)
191219
-- Add tokens to the token pool, according to Quantity
192220
Balances[msg.From] = utils.add(Balances[msg.From], msg.Quantity)
193221
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
197232
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
203247
end
204248
end)
205249

206250
--[[
207251
Total Supply
208252
]]
209253
--
210-
Handlers.add('totalSupply', "Total-Supply", function(msg)
254+
Handlers.add('totalSupply', Handlers.utils.hasMatchingTag("Action","Total-Supply"), function(msg)
211255
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
218270
end)
219271

220272
--[[
221273
Burn
222274
]] --
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!')
229278

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
233288
end)

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
"yargs": "^17.7.2"
3030
},
3131
"aos": {
32-
"module": "zx6_08gJzKNXxLCplINj6TPv9-ElRgeRqr9F6riRBK8",
33-
"sqlite": "CJ-iZL7RKNA43UZr3l6J5M8JegMP9RldoCoVge_vRuI",
32+
"module": "bkjb55i07GUCUSWROtKK4HU1mBS_X0TyH3M5jMV6aPg",
33+
"sqlite": "aGVVWHldKA7GBlI_w7Qp_agO6aKjCoOTPA1G2OlluXE",
34+
"llama": "oamLI-KZ1Q9MxNxWwLcqXYavpwKYf1EX1BpEofb6418",
3435
"version": "2.0.0"
3536
},
3637
"devDependencies": {

process/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"main": "index.js",
66
"license": "MIT",
77
"dependencies": {
8-
"@permaweb/ao-loader": "^0.0.35"
8+
"@permaweb/ao-loader": "^0.0.36"
99
},
1010
"scripts": {
1111
"build": "ao build",
1212
"test": "node --test --experimental-wasm-memory64",
13-
"deploy": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.0 -t Name -v aos-xl",
14-
"deploy-sqlite": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.0 -t Name -v sqlite-xl"
13+
"deploy": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.0 -t Name -v xl",
14+
"deploy-sqlite": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 1-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.0 -t Name -v sqlite-xl",
15+
"deploy-llama": "ao publish -w ~/.wallet.json process.wasm -t Memory-Limit -v 16-gb -t Compute-Limit -v 9000000000000 -t Module-Format -v wasm64-unknown-emscripten-draft_2024_02_15 -t AOS-Version -v 2.0.0 -t Name -v llama-xxl -t Extension -v WeaveDrive"
1516
}
16-
}
17+
}

process/process.lua

+22-5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ function print(a)
106106
if type(a) == "table" then
107107
a = stringify.format(a)
108108
end
109+
--[[
110+
In order to print non string types we need to convert to string
111+
]]
112+
if type(a) == "boolean" then
113+
a = Colors.blue .. tostring(a) .. Colors.reset
114+
end
115+
if type(a) == "nil" then
116+
a = Colors.red .. tostring(a) .. Colors.reset
117+
end
118+
if type(a) == "number" then
119+
a = Colors.green .. tostring(a) .. Colors.reset
120+
end
109121

110122
local data = a
111123
if ao.outbox.Output.data then
@@ -266,13 +278,17 @@ function process.handle(msg, _)
266278

267279
-- Only trust messages from a signed owner or an Authority
268280
if msg.From ~= msg.Owner and not ao.isTrusted(msg) then
269-
Send({Target = msg.From, Data = "Message is not trusted by this process!"})
281+
if msg.From ~= ao.id then
282+
Send({Target = msg.From, Data = "Message is not trusted by this process!"})
283+
end
270284
print('Message is not trusted! From: ' .. msg.From .. ' - Owner: ' .. msg.Owner)
271285
return ao.result({ })
272286
end
273287

274288
if ao.isAssignment(msg) and not ao.isAssignable(msg) then
275-
Send({Target = msg.From, Data = "Assignment is not trusted by this process!"})
289+
if msg.From ~= ao.id then
290+
Send({Target = msg.From, Data = "Assignment is not trusted by this process!"})
291+
end
276292
print('Assignment is not trusted! From: ' .. msg.From .. ' - Owner: ' .. msg.Owner)
277293
return ao.result({ })
278294
end
@@ -337,7 +353,7 @@ function process.handle(msg, _)
337353
if (msg.Action == "Eval") then
338354
table.insert(Errors, result)
339355
local printData = table.concat(HANDLER_PRINT_LOGS, "\n")
340-
return { Error = printData .. '\n\n' .. result }
356+
return { Error = printData .. '\n\n' .. Colors.red .. 'error:\n' .. Colors.reset .. result }
341357
end
342358
--table.insert(Errors, result)
343359
--ao.outbox.Output.data = ""
@@ -348,9 +364,10 @@ function process.handle(msg, _)
348364
end
349365
print(Colors.green .. result .. Colors.reset)
350366
print("\n" .. Colors.gray .. removeLastThreeLines(debug.traceback()) .. Colors.reset)
351-
return ao.result({ Messages = {}, Spawns = {}, Assignments = {} })
367+
local printData = table.concat(HANDLER_PRINT_LOGS, "\n")
368+
return ao.result({Error = printData .. '\n\n' .. Colors.red .. 'error:\n' .. Colors.reset .. result, Messages = {}, Spawns = {}, Assignments = {} })
352369
end
353-
370+
354371
if msg.Action == "Eval" then
355372
local response = ao.result({
356373
Output = {

process/stringify.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function stringify.isSimpleArray(tbl)
1919
return true
2020
end
2121

22-
function stringify.format(tbl, indent)
22+
function stringify.format(tbl, indent, visited)
2323
indent = indent or 0
2424
local toIndent = string.rep(" ", indent)
2525
local toIndentChild = string.rep(" ", indent + 2)
@@ -59,7 +59,13 @@ function stringify.format(tbl, indent)
5959
end
6060
if not isArray then
6161
if type(v) == "table" then
62-
v = stringify.format(v, indent + 2)
62+
visited = visited or {}
63+
if visited[v] then
64+
return "<circular reference>"
65+
end
66+
visited[v] = true
67+
68+
v = stringify.format(v, indent + 2, visited)
6369
elseif type(v) == "string" then
6470
v = colors.green .. '"' .. v .. '"' .. colors.reset
6571
else

process/test/handlers.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Handlers.add("timestamp",
305305
Timestamp: currentTimestamp
306306
}
307307
const result = await handle(Memory, timestamp, env)
308-
assert.equal(result.Output.data, currentTimestamp)
308+
assert.equal(result.Output.data, "\x1B[32m" + currentTimestamp + "\x1B[0m")
309309
assert.ok(true)
310310
})
311311

0 commit comments

Comments
 (0)