From cce07aabe28abf50be0e933b3f06dac69eda2794 Mon Sep 17 00:00:00 2001 From: Atticus Date: Mon, 24 Jun 2024 18:00:11 -0600 Subject: [PATCH] fix(tags): stringify numbers in tags --- src/common/controllers.lua | 1 + src/common/main.lua | 56 ++++++++++++++++++++++++++++---------- src/common/utils.lua | 6 ++-- tools/spawn-aos.js | 30 +------------------- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/common/controllers.lua b/src/common/controllers.lua index 432d4f8..51da100 100644 --- a/src/common/controllers.lua +++ b/src/common/controllers.lua @@ -27,6 +27,7 @@ function controllers.removeController(controller) end assert(controllerExists ~= nil, "Controller does not exist") + return json.encode(Controllers) end function controllers.getControllers() diff --git a/src/common/main.lua b/src/common/main.lua index 1e84e49..d8a905d 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -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, @@ -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({ @@ -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) @@ -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 @@ -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 @@ -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 }) @@ -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 @@ -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 }) diff --git a/src/common/utils.lua b/src/common/utils.lua index 318852a..994091d 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -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 @@ -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 diff --git a/tools/spawn-aos.js b/tools/spawn-aos.js index b45c35b..69d23c2 100644 --- a/tools/spawn-aos.js +++ b/tools/spawn-aos.js @@ -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() { @@ -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' }], ];