Skip to content

Commit

Permalink
Merge pull request #326 from permaweb/twilson63/bump-2-0-0
Browse files Browse the repository at this point in the history
chore: bump aos to 2.0
  • Loading branch information
twilson63 authored Sep 19, 2024
2 parents feaf86d + 36f652c commit f204897
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 122 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
<img alt="logo">
</picture>

Status: Preview rc2
Version: 2.0.0-rc2
Module: `PSPMkkFrJzYI2bQbkmeEQ5ONmeR-FJZu0fNQoSCU1-I`

Sqlite-Module: `C4bxMlK8d_wQ-QpXIIZLU8UWXu6Sd8PDJw7HN3nNE2I`
Version: 2.0.0
Module: `bkjb55i07GUCUSWROtKK4HU1mBS_X0TyH3M5jMV6aPg`

Sqlite-Module: `aGVVWHldKA7GBlI_w7Qp_agO6aKjCoOTPA1G2OlluXE`

## Requirements

Expand Down
24 changes: 19 additions & 5 deletions blueprints/staking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ Handlers.stake = function(msg)
Stakers[msg.From].amount = utils.add(Stakers[msg.From].amount, msg.Tags.Quantity)
Stakers[msg.From].unstake_at = height + delay
print("Successfully Staked " .. msg.Tags.Quantity)
msg.reply({ Data = "Successfully Staked " .. msg.Tags.Quantity})
if msg.reply then
msg.reply({ Data = "Successfully Staked " .. msg.Tags.Quantity})
else
Send({Target = msg.From, Data = "Successfully Staked " .. msg.Tags.Quantity })
end
end

-- Unstake Action Handler
Expand All @@ -38,10 +42,14 @@ Handlers.unstake = function(msg)
assert(stakerInfo and bint(stakerInfo.amount) >= bint(msg.Tags.Quantity), "Insufficient staked amount")
stakerInfo.amount = utils.subtract(stakerInfo.amount, msg.Tags.Quantity)
Unstaking[msg.From] = {
amount = msg.Quantity,
amount = msg.Tags.Quantity,
release_at = stakerInfo.unstake_at
}
msg.reply({ Data = "Successfully unstaked " .. msg.Tags.Quantity})
if msg.reply then
msg.reply({ Data = "Successfully unstaked " .. msg.Tags.Quantity})
else
Send({Target = msg.From, Data = "Successfully unstaked " .. msg.Tags.Quantity })
end
end

-- Finalization Handler
Expand All @@ -68,8 +76,14 @@ local function continue(fn)
end
end

Handlers.add('staking.balances', 'Stakers',
function(msg) msg.reply({ Data = require('json').encode(Stakers) }) end)
Handlers.add('staking.balances', Handlers.utils.hasMatchingTag("Action", 'Stakers'),
function(msg)
if msg.reply then
msg.reply({ Data = require('json').encode(Stakers) })
else
Send({Target = msg.From, Data = require('json').encode(Stakers) })
end
end)
-- Registering Handlers
Handlers.add("staking.stake",
continue(Handlers.utils.hasMatchingTag("Action", "Stake")), Handlers.stake)
Expand Down
141 changes: 98 additions & 43 deletions blueprints/token.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Logo = Logo or 'SBCCXwwecBlDqRLUjb8dYABExTJXLieawf7m2aBJ-KY'
Info
]]
--
Handlers.add('info', "Info", function(msg)
Handlers.add('info', Handlers.utils.hasMatchingTag("Action", "Info"), function(msg)
msg.reply({
Name = Name,
Ticker = Ticker,
Expand All @@ -84,7 +84,7 @@ end)
Balance
]]
--
Handlers.add('balance', "Balance", function(msg)
Handlers.add('balance', Handlers.utils.hasMatchingTag("Action", "Balance"), function(msg)
local bal = '0'

-- If not Recipient is provided, then return the Senders balance
Expand All @@ -97,27 +97,42 @@ Handlers.add('balance', "Balance", function(msg)
elseif Balances[msg.From] then
bal = Balances[msg.From]
end

msg.reply({
Balance = bal,
Ticker = Ticker,
Account = msg.Tags.Recipient or msg.From,
Data = bal
})
if msg.reply then
msg.reply({
Balance = bal,
Ticker = Ticker,
Account = msg.Tags.Recipient or msg.From,
Data = bal
})
else
Send({
Target = msg.From,
Balance = bal,
Ticker = Ticker,
Account = msg.Tags.Recipient or msg.From,
Data = bal
})
end
end)

--[[
Balances
]]
--
Handlers.add('balances', "Balances",
function(msg) msg.reply({ Data = json.encode(Balances) }) end)
Handlers.add('balances', Handlers.utils.hasMatchingTag("Action", "Balances"),
function(msg)
if msg.reply then
msg.reply({ Data = json.encode(Balances) })
else
Send({Target = msg.From, Data = json.encode(Balances) })
end
end)

--[[
Transfer
]]
--
Handlers.add('transfer', "Transfer", function(msg)
Handlers.add('transfer', Handlers.utils.hasMatchingTag("Action", "Transfer"), function(msg)
assert(type(msg.Recipient) == 'string', 'Recipient is required!')
assert(type(msg.Quantity) == 'string', 'Quantity is required!')
assert(bint.__lt(0, bint(msg.Quantity)), 'Quantity must be greater than 0')
Expand Down Expand Up @@ -165,23 +180,36 @@ Handlers.add('transfer', "Transfer", function(msg)
end

-- Send Debit-Notice and Credit-Notice
msg.reply(debitNotice)
if msg.reply then
msg.reply(debitNotice)
else
Send(debitNotice)
end
Send(creditNotice)
end
else
msg.reply({
Action = 'Transfer-Error',
['Message-Id'] = msg.Id,
Error = 'Insufficient Balance!'
})
if msg.reply then
msg.reply({
Action = 'Transfer-Error',
['Message-Id'] = msg.Id,
Error = 'Insufficient Balance!'
})
else
Send({
Target = msg.From,
Action = 'Transfer-Error',
['Message-Id'] = msg.Id,
Error = 'Insufficient Balance!'
})
end
end
end)

--[[
Mint
]]
--
Handlers.add('mint', "Mint", function(msg)
Handlers.add('mint', Handlers.utils.hasMatchingTag("Action","Mint"), function(msg)
assert(type(msg.Quantity) == 'string', 'Quantity is required!')
assert(bint(0) < bint(msg.Quantity), 'Quantity must be greater than zero!')

Expand All @@ -191,43 +219,70 @@ Handlers.add('mint', "Mint", function(msg)
-- Add tokens to the token pool, according to Quantity
Balances[msg.From] = utils.add(Balances[msg.From], msg.Quantity)
TotalSupply = utils.add(TotalSupply, msg.Quantity)
msg.reply({
Data = Colors.gray .. "Successfully minted " .. Colors.blue .. msg.Quantity .. Colors.reset
})
if msg.reply then
msg.reply({
Data = Colors.gray .. "Successfully minted " .. Colors.blue .. msg.Quantity .. Colors.reset
})
else
Send({
Target = msg.From,
Data = Colors.gray .. "Successfully minted " .. Colors.blue .. msg.Quantity .. Colors.reset
})
end
else
msg.reply({
Action = 'Mint-Error',
['Message-Id'] = msg.Id,
Error = 'Only the Process Id can mint new ' .. Ticker .. ' tokens!'
})
if msg.reply then
msg.reply({
Action = 'Mint-Error',
['Message-Id'] = msg.Id,
Error = 'Only the Process Id can mint new ' .. Ticker .. ' tokens!'
})
else
Send({
Target = msg.From,
Action = 'Mint-Error',
['Message-Id'] = msg.Id,
Error = 'Only the Process Id can mint new ' .. Ticker .. ' tokens!'
})
end
end
end)

--[[
Total Supply
]]
--
Handlers.add('totalSupply', "Total-Supply", function(msg)
Handlers.add('totalSupply', Handlers.utils.hasMatchingTag("Action","Total-Supply"), function(msg)
assert(msg.From ~= ao.id, 'Cannot call Total-Supply from the same process!')

msg.reply({
Action = 'Total-Supply',
Data = TotalSupply,
Ticker = Ticker
})
if msg.reply then
msg.reply({
Action = 'Total-Supply',
Data = TotalSupply,
Ticker = Ticker
})
else
Send({
Target = msg.From,
Action = 'Total-Supply',
Data = TotalSupply,
Ticker = Ticker
})
end
end)

--[[
Burn
]] --
Handlers.add('burn', 'Burn', function(msg)
assert(type(msg.Quantity) == 'string', 'Quantity is required!')
assert(bint(msg.Quantity) <= bint(Balances[msg.From]), 'Quantity must be less than or equal to the current balance!')

Balances[msg.From] = utils.subtract(Balances[msg.From], msg.Quantity)
TotalSupply = utils.subtract(TotalSupply, msg.Quantity)
Handlers.add('burn', Handlers.utils.hasMatchingTag("Action",'Burn'), function(msg)
assert(type(msg.Tags.Quantity) == 'string', 'Quantity is required!')
assert(bint(msg.Tags.Quantity) <= bint(Balances[msg.From]), 'Quantity must be less than or equal to the current balance!')

msg.reply({
Data = Colors.gray .. "Successfully burned " .. Colors.blue .. msg.Quantity .. Colors.reset
})
Balances[msg.From] = utils.subtract(Balances[msg.From], msg.Tags.Quantity)
TotalSupply = utils.subtract(TotalSupply, msg.Tags.Quantity)
if msg.reply then
msg.reply({
Data = Colors.gray .. "Successfully burned " .. Colors.blue .. msg.Tags.Quantity .. Colors.reset
})
else
Send({Target = msg.From, Data = Colors.gray .. "Successfully burned " .. Colors.blue .. msg.Tags.Quantity .. Colors.reset })
end
end)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"yargs": "^17.7.2"
},
"aos": {
"module": "zx6_08gJzKNXxLCplINj6TPv9-ElRgeRqr9F6riRBK8",
"sqlite": "CJ-iZL7RKNA43UZr3l6J5M8JegMP9RldoCoVge_vRuI",
"module": "bkjb55i07GUCUSWROtKK4HU1mBS_X0TyH3M5jMV6aPg",
"sqlite": "aGVVWHldKA7GBlI_w7Qp_agO6aKjCoOTPA1G2OlluXE",
"llama": "oamLI-KZ1Q9MxNxWwLcqXYavpwKYf1EX1BpEofb6418",
"version": "2.0.0"
},
"devDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions process/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@permaweb/ao-loader": "^0.0.35"
"@permaweb/ao-loader": "^0.0.36"
},
"scripts": {
"build": "ao build",
"test": "node --test --experimental-wasm-memory64",
"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",
"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"
"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",
"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",
"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"
}
}
}
27 changes: 22 additions & 5 deletions process/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ function print(a)
if type(a) == "table" then
a = stringify.format(a)
end
--[[
In order to print non string types we need to convert to string
]]
if type(a) == "boolean" then
a = Colors.blue .. tostring(a) .. Colors.reset
end
if type(a) == "nil" then
a = Colors.red .. tostring(a) .. Colors.reset
end
if type(a) == "number" then
a = Colors.green .. tostring(a) .. Colors.reset
end

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

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

if ao.isAssignment(msg) and not ao.isAssignable(msg) then
Send({Target = msg.From, Data = "Assignment is not trusted by this process!"})
if msg.From ~= ao.id then
Send({Target = msg.From, Data = "Assignment is not trusted by this process!"})
end
print('Assignment is not trusted! From: ' .. msg.From .. ' - Owner: ' .. msg.Owner)
return ao.result({ })
end
Expand Down Expand Up @@ -337,7 +353,7 @@ function process.handle(msg, _)
if (msg.Action == "Eval") then
table.insert(Errors, result)
local printData = table.concat(HANDLER_PRINT_LOGS, "\n")
return { Error = printData .. '\n\n' .. result }
return { Error = printData .. '\n\n' .. Colors.red .. 'error:\n' .. Colors.reset .. result }
end
--table.insert(Errors, result)
--ao.outbox.Output.data = ""
Expand All @@ -348,9 +364,10 @@ function process.handle(msg, _)
end
print(Colors.green .. result .. Colors.reset)
print("\n" .. Colors.gray .. removeLastThreeLines(debug.traceback()) .. Colors.reset)
return ao.result({ Messages = {}, Spawns = {}, Assignments = {} })
local printData = table.concat(HANDLER_PRINT_LOGS, "\n")
return ao.result({Error = printData .. '\n\n' .. Colors.red .. 'error:\n' .. Colors.reset .. result, Messages = {}, Spawns = {}, Assignments = {} })
end

if msg.Action == "Eval" then
local response = ao.result({
Output = {
Expand Down
10 changes: 8 additions & 2 deletions process/stringify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function stringify.isSimpleArray(tbl)
return true
end

function stringify.format(tbl, indent)
function stringify.format(tbl, indent, visited)
indent = indent or 0
local toIndent = string.rep(" ", indent)
local toIndentChild = string.rep(" ", indent + 2)
Expand Down Expand Up @@ -59,7 +59,13 @@ function stringify.format(tbl, indent)
end
if not isArray then
if type(v) == "table" then
v = stringify.format(v, indent + 2)
visited = visited or {}
if visited[v] then
return "<circular reference>"
end
visited[v] = true

v = stringify.format(v, indent + 2, visited)
elseif type(v) == "string" then
v = colors.green .. '"' .. v .. '"' .. colors.reset
else
Expand Down
2 changes: 1 addition & 1 deletion process/test/handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Handlers.add("timestamp",
Timestamp: currentTimestamp
}
const result = await handle(Memory, timestamp, env)
assert.equal(result.Output.data, currentTimestamp)
assert.equal(result.Output.data, "\x1B[32m" + currentTimestamp + "\x1B[0m")
assert.ok(true)
})

Expand Down
Loading

0 comments on commit f204897

Please sign in to comment.