Skip to content

Commit

Permalink
fix(tags): stringify numbers in tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Jun 25, 2024
1 parent 480ea3b commit cce07aa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/common/controllers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function controllers.removeController(controller)
end

assert(controllerExists ~= nil, "Controller does not exist")
return json.encode(Controllers)
end

function controllers.getControllers()
Expand Down
56 changes: 41 additions & 15 deletions src/common/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function ant.init()
ao.send({
Target = msg.From,
Action = "Balance-Notice",
Balance = balRes,
Balance = tostring(balRes),
Ticker = Ticker,
Address = msg.Tags.Recipient or msg.From,
Data = balRes,
Expand Down Expand Up @@ -151,9 +151,9 @@ function ant.init()
local info = {
Name = Name,
Ticker = Ticker,
["Total-Supply"] = TotalSupply,
["Total-Supply"] = tostring(TotalSupply),
Logo = Logo,
Denomination = Denomination,
Denomination = tostring(Denomination),
Owner = Owner,
}
ao.send({
Expand Down Expand Up @@ -221,13 +221,9 @@ function ant.init()
end
)

Handlers.add(
camel(ActionMap.Controllers),
utils.hasMatchingTag("Action", ActionMap.Controllers),
function(msg)
ao.send({ Target = msg.From, Action = "Controllers-Notice", Data = controllers.getControllers() })
end
)
Handlers.add(camel(ActionMap.Controllers), utils.hasMatchingTag("Action", ActionMap.Controllers), function(msg)
ao.send({ Target = msg.From, Action = "Controllers-Notice", Data = controllers.getControllers() })
end)

Handlers.add(camel(ActionMap.SetRecord), utils.hasMatchingTag("Action", ActionMap.SetRecord), function(msg)
local assertHasPermission, permissionErr = pcall(utils.assertHasPermission, msg.From)
Expand All @@ -246,7 +242,13 @@ function ant.init()

local setRecordStatus, setRecordResult = pcall(records.setRecord, name, transactionId, ttlSeconds)
if not setRecordStatus then
ao.send({ Target = msg.From, Action = "Invalid-Set-Record-Notice", Data = setRecordResult, Error = "Set-Record-Error", ["Message-Id"] = msg.Id })
ao.send({
Target = msg.From,
Action = "Invalid-Set-Record-Notice",
Data = setRecordResult,
Error = "Set-Record-Error",
["Message-Id"] = msg.Id,
})
return
end

Expand Down Expand Up @@ -275,7 +277,13 @@ function ant.init()
Handlers.add(camel(ActionMap.Record), utils.hasMatchingTag("Action", ActionMap.Record), function(msg)
local nameStatus, nameRes = pcall(records.getRecord, msg.Tags["Sub-Domain"])
if not nameStatus then
ao.send({ Target = msg.From, Action = "Invalid-Record-Notice", Data = nameRes, Error = "Record-Error", ["Message-Id"] = msg.Id })
ao.send({
Target = msg.From,
Action = "Invalid-Record-Notice",
Data = nameRes,
Error = "Record-Error",
["Message-Id"] = msg.Id,
})
return
end

Expand Down Expand Up @@ -333,7 +341,13 @@ function ant.init()
end
local nameStatus, nameRes = pcall(balances.setName, msg.Tags.Name)
if not nameStatus then
ao.send({ Target = msg.From, Action = "Invalid-Set-Name-Notice", Data = nameRes, Error = "Set-Name-Error", ["Message-Id"] = msg.Id })
ao.send({
Target = msg.From,
Action = "Invalid-Set-Name-Notice",
Data = nameRes,
Error = "Set-Name-Error",
["Message-Id"] = msg.Id,
})
return
end
ao.send({ Target = msg.From, Action = "Set-Name-Notice", Data = nameRes })
Expand All @@ -352,7 +366,13 @@ function ant.init()
end
local tickerStatus, tickerRes = pcall(balances.setTicker, msg.Tags.Ticker)
if not tickerStatus then
ao.send({ Target = msg.From, Action = "Invalid-Set-Ticker-Notice", Data = tickerRes, Error = "Set-Ticker-Error", ["Message-Id"] = msg.Id })
ao.send({
Target = msg.From,
Action = "Invalid-Set-Ticker-Notice",
Data = tickerRes,
Error = "Set-Ticker-Error",
["Message-Id"] = msg.Id,
})
return
end

Expand All @@ -367,7 +387,13 @@ function ant.init()
local initStatus, result = pcall(initialize.initializeANTState, msg.Data)

if not initStatus then
ao.send({ Target = msg.From, Action = "Invalid-Initialize-State-Notice", Data = result, Error = "Initialize-State-Error", ["Message-Id"] = msg.Id })
ao.send({
Target = msg.From,
Action = "Invalid-Initialize-State-Notice",
Data = result,
Error = "Initialize-State-Error",
["Message-Id"] = msg.Id,
})
return
else
ao.send({ Target = msg.From, Action = "Initialize-State-Notice", Data = result })
Expand Down
6 changes: 4 additions & 2 deletions src/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ function utils.notices.credit(msg)
local notice = {
Target = msg.From,
Action = "Credit-Notice",
Sender = msg.From,
Recipient = msg.Recipient,
Quantity = tostring(1),
}
for tagName, tagValue in pairs(msg) do
-- Tags beginning with "X-" are forwarded
Expand All @@ -273,7 +274,8 @@ function utils.notices.debit(msg)
local notice = {
Target = msg.From,
Action = "Debit-Notice",
Sender = msg.From,
Recipient = msg.Recipient,
Quantity = tostring(1),
}
-- Add forwarded tags to the credit and debit notice messages
for tagName, tagValue in pairs(msg) do
Expand Down
30 changes: 1 addition & 29 deletions tools/spawn-aos.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const arweave = Arweave.init({
const ao = connect({
GATEWAY_URL: 'https://arweave.net',
});
const moduleId = '9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4';
const moduleId = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
const scheduler = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';

async function main() {
Expand Down Expand Up @@ -52,34 +52,6 @@ async function main() {

const testCases = [
['Eval', {}, luaCode],
['Info', {}],
['Set-Controller', { Controller: ''.padEnd(43, '1') }],
['Remove-Controller', { Controller: ''.padEnd(43, '1') }],
['Set-Name', { Name: 'Test Name' }],
['Set-Ticker', { Ticker: 'TEST' }],
[
'Set-Record',
{
'Transaction-Id': ''.padEnd(43, '1'),
'TTL-Seconds': '1000',
'Sub-Domain': '@',
},
],
[
'Set-Record',
{
'Transaction-Id': ''.padEnd(43, '1'),
'TTL-Seconds': '1000',
'Sub-Domain': 'bob',
},
],
['Remove-Record', { 'Sub-Domain': 'bob' }],
['Balance', {}],
['Balance', { Recipient: address }],
['Balances', {}],
['Get-Controllers', {}],
['Get-Records', {}],
['Get-Record', { 'Sub-Domain': '@' }],
['Initialize-State', {}, initState],
['Transfer', { Recipient: 'N4h8M9A9hasa3tF47qQyNvcKjm4APBKuFs7vqUVm-SI' }],
];
Expand Down

0 comments on commit cce07aa

Please sign in to comment.