From 9c8b2e9726f925eb3fffdedf89d0a2e423f1412e Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Tue, 12 Nov 2024 15:48:33 -0600 Subject: [PATCH 1/9] fix(apis): do not encode on return in apis --- package.json | 3 ++- src/common/balances.lua | 31 +++++++++++++++---------------- src/common/controllers.lua | 13 ++++++------- src/common/records.lua | 19 +++++++++---------- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 43d5f1e..73dd92a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "aos:load": "node tools/bundle-aos.mjs && node tools/load-aos.mjs", "aos:spawn": "node tools/spawn-aos.mjs", "test": "yarn aos:build && node --test --test-concurrency 1 --experimental-wasm-memory64 **/*.test.mjs", - "prepare": "husky" + "prepare": "husky", + "install-lua-deps": "sh tools/install-lua-deps.sh" }, "devDependencies": { "@ardrive/turbo-sdk": "^1.19.0", diff --git a/src/common/balances.lua b/src/common/balances.lua index 1c4f69d..8b6ab95 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -2,7 +2,6 @@ -- @module balances local utils = require(".common.utils") -local json = require(".common.json") local balances = {} @@ -15,19 +14,19 @@ end --- Transfers the ANT to a specified wallet. ---@param to string - The wallet address to transfer the balance to. ----@return string - Returns the encoded JSON representation of the transferred balance. +---@return table function balances.transfer(to) utils.validateArweaveId(to) Balances = { [to] = 1 } --luacheck: ignore Owner Controllers Owner = to Controllers = {} - return json.encode({ [to] = 1 }) + return { [to] = 1 } end --- Retrieves the balance of a specified wallet. ---@param address string - The wallet address to retrieve the balance from. ----@return number - Returns the balance of the specified wallet. +---@return integer - Returns the balance of the specified wallet. function balances.balance(address) utils.validateArweaveId(address) local balance = Balances[address] or 0 @@ -35,55 +34,55 @@ function balances.balance(address) end --- Retrieves all balances. ----@return string - Returns the encoded JSON representation of all balances. +---@return table - Returns the encoded JSON representation of all balances. function balances.balances() - return json.encode(Balances) + return Balances end --- Sets the name of the ANT. ---@param name string - The name to set. ----@return string - Returns the encoded JSON representation of the updated name. +---@return table function balances.setName(name) assert(type(name) == "string", "Name must be a string") Name = name - return json.encode({ name = Name }) + return { name = Name } end --- Sets the ticker of the ANT. ---@param ticker string - The ticker to set. ----@return string - Returns the encoded JSON representation of the updated ticker. +---@return table function balances.setTicker(ticker) assert(type(ticker) == "string", "Ticker must be a string") Ticker = ticker - return json.encode({ ticker = Ticker }) + return { ticker = Ticker } end --- Sets the description of the ANT. ---@param description string - The description to set. ----@return string - Returns the encoded JSON representation of the updated description. +---@return table function balances.setDescription(description) assert(type(description) == "string", "Description must be a string") assert(#description <= 512, "Description must not be longer than 512 characters") Description = description - return json.encode({ description = Description }) + return { description = Description } end --- Sets the keywords of the ANT. ---@param keywords table - The keywords to set. ----@return string - Returns the encoded JSON representation of the updated keywords. +---@return table function balances.setKeywords(keywords) utils.validateKeywords(keywords) Keywords = keywords - return json.encode({ keywords = Keywords }) + return { keywords = Keywords } end --- Sets the logo of the ANT. ---@param logo string - The Arweave transaction ID that represents the logo. ----@return string - Returns the encoded JSON representation of the updated logo. +---@return table function balances.setLogo(logo) Logo = logo - return json.encode({ logo = Logo }) + return { logo = Logo } end return balances diff --git a/src/common/controllers.lua b/src/common/controllers.lua index a7bc84d..5cb0b2e 100644 --- a/src/common/controllers.lua +++ b/src/common/controllers.lua @@ -1,11 +1,10 @@ -local json = require(".common.json") local utils = require(".common.utils") local controllers = {} --- Set a controller. ---@param controller string The controller to set. ----@return string The encoded JSON representation of the updated controllers. +---@return table function controllers.setController(controller) utils.validateArweaveId(controller) @@ -14,12 +13,12 @@ function controllers.setController(controller) end table.insert(Controllers, controller) - return json.encode(Controllers) + return Controllers end --- Remove a controller. ---@param controller string The controller to remove. ----@return string The encoded JSON representation of the updated controllers. +---@return table function controllers.removeController(controller) utils.validateArweaveId(controller) local controllerExists = false @@ -33,13 +32,13 @@ function controllers.removeController(controller) end assert(controllerExists ~= nil, "Controller does not exist") - return json.encode(Controllers) + return Controllers end --- Get all controllers. ----@return string The encoded JSON representation of the controllers. +---@return table function controllers.getControllers() - return json.encode(Controllers) + return Controllers end return controllers diff --git a/src/common/records.lua b/src/common/records.lua index 9237e7c..1c9b81f 100644 --- a/src/common/records.lua +++ b/src/common/records.lua @@ -1,5 +1,4 @@ local utils = require(".common.utils") -local json = require(".common.json") local records = {} -- defaults to landing page txid Records = Records or { ["@"] = { transactionId = "-k7t8xMoB8hW482609Z9F4bTFMC3MnuW8bTvTyT8pFI", ttlSeconds = 3600 } } @@ -8,7 +7,7 @@ Records = Records or { ["@"] = { transactionId = "-k7t8xMoB8hW482609Z9F4bTFMC3Mn ---@param name string The name of the record. ---@param transactionId string The transaction ID of the record. ---@param ttlSeconds number The time-to-live in seconds for the record. ----@return string The encoded JSON representation of the record. +---@return Record function records.setRecord(name, transactionId, ttlSeconds) utils.validateUndername(name) utils.validateArweaveId(transactionId) @@ -25,35 +24,35 @@ function records.setRecord(name, transactionId, ttlSeconds) ttlSeconds = ttlSeconds, } - return json.encode({ + return { transactionId = transactionId, ttlSeconds = ttlSeconds, - }) + } end --- Remove a record from the ANT. ---@param name string The name of the record to remove. ----@return string The encoded JSON representation of the deletion message. +---@return table<'message', string> function records.removeRecord(name) utils.validateUndername(name) Records[name] = nil - return json.encode({ message = "Record deleted" }) + return { message = "Record deleted" } end --- Get a record from the ANT. ---@param name string The name of the record to retrieve. ----@return string The encoded JSON representation of the record. +---@return Record function records.getRecord(name) utils.validateUndername(name) assert(Records[name] ~= nil, "Record does not exist") - return json.encode(Records[name]) + return Records[name] end --- Get all records from the ANT ----@return string The encoded JSON representation of all records. +---@return table function records.getRecords() - return json.encode(Records) + return Records end return records From 467fb1c2ee2836af9a2cadbdd241551c9a020bef Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Tue, 12 Nov 2024 16:08:30 -0600 Subject: [PATCH 2/9] fix(spec): update apis to return according to spec --- src/common/balances.lua | 20 ++++++-------------- src/common/records.lua | 4 ++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/common/balances.lua b/src/common/balances.lua index 8b6ab95..97e4f01 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -5,23 +5,15 @@ local utils = require(".common.utils") local balances = {} ---- Checks if a wallet has sufficient balance. ----@param wallet string - The wallet address to check. ----@return boolean - Returns true if the wallet has a balance greater than 0, otherwise false. -function balances.walletHasSufficientBalance(wallet) - return Balances[wallet] ~= nil and Balances[wallet] > 0 -end - --- Transfers the ANT to a specified wallet. ---@param to string - The wallet address to transfer the balance to. ----@return table +---@return nil function balances.transfer(to) utils.validateArweaveId(to) Balances = { [to] = 1 } --luacheck: ignore Owner Controllers Owner = to Controllers = {} - return { [to] = 1 } end --- Retrieves the balance of a specified wallet. @@ -45,7 +37,7 @@ end function balances.setName(name) assert(type(name) == "string", "Name must be a string") Name = name - return { name = Name } + return { Name = Name } end --- Sets the ticker of the ANT. @@ -54,7 +46,7 @@ end function balances.setTicker(ticker) assert(type(ticker) == "string", "Ticker must be a string") Ticker = ticker - return { ticker = Ticker } + return { Ticker = Ticker } end --- Sets the description of the ANT. @@ -64,7 +56,7 @@ function balances.setDescription(description) assert(type(description) == "string", "Description must be a string") assert(#description <= 512, "Description must not be longer than 512 characters") Description = description - return { description = Description } + return { Description = Description } end --- Sets the keywords of the ANT. @@ -74,7 +66,7 @@ function balances.setKeywords(keywords) utils.validateKeywords(keywords) Keywords = keywords - return { keywords = Keywords } + return { Keywords = Keywords } end --- Sets the logo of the ANT. @@ -82,7 +74,7 @@ end ---@return table function balances.setLogo(logo) Logo = logo - return { logo = Logo } + return { Logo = Logo } end return balances diff --git a/src/common/records.lua b/src/common/records.lua index 1c9b81f..ae325de 100644 --- a/src/common/records.lua +++ b/src/common/records.lua @@ -32,11 +32,11 @@ end --- Remove a record from the ANT. ---@param name string The name of the record to remove. ----@return table<'message', string> +---@return table Returns the records of the ANT function records.removeRecord(name) utils.validateUndername(name) Records[name] = nil - return { message = "Record deleted" } + return Records end --- Get a record from the ANT. From b40e51e003c990984e1154d42f77b0e70c6ece4e Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Tue, 12 Nov 2024 16:13:43 -0600 Subject: [PATCH 3/9] fix(tests): add test for setLogo --- spec/ant_spec.lua | 13 +++++++++++++ src/common/balances.lua | 1 + src/common/main.lua | 1 - 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/ant_spec.lua b/spec/ant_spec.lua index d2fb754..6d1f368 100644 --- a/spec/ant_spec.lua +++ b/spec/ant_spec.lua @@ -27,6 +27,7 @@ describe("Arweave Name Token", function() _G.Description = "ANT's description" _G.Keywords = { "KEYWORD-1", "KEYWORD-2", "KEYWORD-3" } _G.Denomination = 1 + _G.Logo = "" end) it("Initializes the state of the process", function() @@ -167,4 +168,16 @@ describe("Arweave Name Token", function() balances.setKeywords(notAnArray) end, "Keywords must be an array") end) + + it("should set the logo", function() + local logo = string.rep("1", 43) + balances.setLogo(logo) + assert.are.same(logo, _G.Logo) + end) + it("should not set the logo with invalid id", function() + local logo = string.rep("1", 42) + assert.has_error(function() + balances.setLogo(logo) + end) + end) end) diff --git a/src/common/balances.lua b/src/common/balances.lua index 97e4f01..5c5f730 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -73,6 +73,7 @@ end ---@param logo string - The Arweave transaction ID that represents the logo. ---@return table function balances.setLogo(logo) + utils.validateArweaveId(logo) Logo = logo return { Logo = Logo } end diff --git a/src/common/main.lua b/src/common/main.lua index 6ec0b60..c6bcb64 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -213,7 +213,6 @@ function ant.init() createActionHandler(ActionMap.SetLogo, function(msg) utils.assertHasPermission(msg.From) - utils.validateArweaveId(msg.Logo) return balances.setLogo(msg.Logo) end) From 34316ae44c426e93e4a7addd48652025a0750696 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 13 Nov 2024 07:23:14 -0600 Subject: [PATCH 4/9] fix(utils): remove unused utils --- src/common/controllers.lua | 6 +- src/common/main.lua | 2 +- src/common/types.lua | 2 +- src/common/utils.lua | 186 +------------------------------------ 4 files changed, 7 insertions(+), 189 deletions(-) diff --git a/src/common/controllers.lua b/src/common/controllers.lua index 5cb0b2e..d37759c 100644 --- a/src/common/controllers.lua +++ b/src/common/controllers.lua @@ -4,7 +4,7 @@ local controllers = {} --- Set a controller. ---@param controller string The controller to set. ----@return table +---@return string[] function controllers.setController(controller) utils.validateArweaveId(controller) @@ -18,7 +18,7 @@ end --- Remove a controller. ---@param controller string The controller to remove. ----@return table +---@return string[] function controllers.removeController(controller) utils.validateArweaveId(controller) local controllerExists = false @@ -36,7 +36,7 @@ function controllers.removeController(controller) end --- Get all controllers. ----@return table +---@return string[] function controllers.getControllers() return Controllers end diff --git a/src/common/main.lua b/src/common/main.lua index c6bcb64..a925805 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -36,7 +36,7 @@ function ant.init() ---@alias Description string ---@description A brief description of this ANT up to 255 characters Description = Description or "A brief description of this ANT." - ---@alias Keywords table + ---@alias Keywords string[] ---@description A list of keywords that describe this ANT. Each keyword must be a string, unique, and less than 32 characters. There can be up to 16 keywords Keywords = Keywords or {} ---@alias Denomination integer diff --git a/src/common/types.lua b/src/common/types.lua index 548d320..5ab943b 100644 --- a/src/common/types.lua +++ b/src/common/types.lua @@ -40,7 +40,7 @@ --- Logo: string, --- Balances: table, --- Owner: string, ---- Controllers: table, +--- Controllers: string[], --- Denomination: integer, --- TotalSupply: integer, --- Initialized: boolean, diff --git a/src/common/utils.lua b/src/common/utils.lua index 044e6dd..58c791f 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -3,172 +3,6 @@ local constants = require(".common.constants") local json = require(".common.json") local utils = { _version = "0.0.1" } -local function isArray(table) - if type(table) == "table" then - local maxIndex = 0 - for k, _ in pairs(table) do - if type(k) ~= "number" or k < 1 or math.floor(k) ~= k then - return false -- If there's a non-integer key, it's not an array - end - maxIndex = math.max(maxIndex, k) - end - -- If the highest numeric index is equal to the number of elements, it's an array - return maxIndex == #table - end - return false -end - ---- @param fn function ---- @param arity number -utils.curry = function(fn, arity) - assert(type(fn) == "function", "function is required as first argument") - arity = arity or debug.getinfo(fn, "u").nparams - if arity < 2 then - return fn - end - - return function(...) - local args = { ... } - - if #args >= arity then - return fn(table.unpack(args)) - else - return utils.curry(function(...) - return fn(table.unpack(args), ...) - end, arity - #args) - end - end -end - ---- Concat two Array Tables. ---- @param a table ---- @param b table -utils.concat = utils.curry(function(a, b) - assert(type(a) == "table", "first argument should be a table that is an array") - assert(type(b) == "table", "second argument should be a table that is an array") - assert(isArray(a), "first argument should be a table") - assert(isArray(b), "second argument should be a table") - - local result = {} - for i = 1, #a do - result[#result + 1] = a[i] - end - for i = 1, #b do - result[#result + 1] = b[i] - end - return result -end, 2) - ---- reduce applies a function to a table ---- @param fn function ---- @param initial any ---- @param t table -utils.reduce = utils.curry(function(fn, initial, t) - assert(type(fn) == "function", "first argument should be a function that accepts (result, value, key)") - assert(type(t) == "table" and isArray(t), "third argument should be a table that is an array") - local result = initial - for k, v in pairs(t) do - if result == nil then - result = v - else - result = fn(result, v, k) - end - end - return result -end, 3) - ---- @param fn function ---- @param data table -utils.map = utils.curry(function(fn, data) - assert(type(fn) == "function", "first argument should be a unary function") - assert(type(data) == "table" and isArray(data), "second argument should be an Array") - - local function map(result, v, k) - result[k] = fn(v, k) - return result - end - - return utils.reduce(map, {}, data) -end, 2) - ---- @param fn function ---- @param data table -utils.filter = utils.curry(function(fn, data) - assert(type(fn) == "function", "first argument should be a unary function") - assert(type(data) == "table" and isArray(data), "second argument should be an Array") - - local function filter(result, v) - if fn(v) then - table.insert(result, v) - end - return result - end - - return utils.reduce(filter, {}, data) -end, 2) - ---- @param fn function ---- @param t table -utils.find = utils.curry(function(fn, t) - assert(type(fn) == "function", "first argument should be a unary function") - assert(type(t) == "table", "second argument should be a table that is an array") - for _, v in pairs(t) do - if fn(v) then - return v - end - end -end, 2) - ---- @param propName string ---- @param value string ---- @param object table -utils.propEq = utils.curry(function(propName, value, object) - assert(type(propName) == "string", "first argument should be a string") - -- assert(type(value) == "string", "second argument should be a string") - assert(type(object) == "table", "third argument should be a table") - - return object[propName] == value -end, 3) - ---- @param data table -utils.reverse = function(data) - assert(type(data) == "table", "argument needs to be a table that is an array") - return utils.reduce(function(result, v, i) - result[#data - i + 1] = v - return result - end, {}, data) -end - ---- @param ... function -utils.compose = utils.curry(function(...) - local mutations = utils.reverse({ ... }) - - return function(v) - local result = v - ---@diagnostic disable-next-line - for _, fn in pairs(mutations) do - assert(type(fn) == "function", "each argument needs to be a function") - result = fn(result) - end - return result - end -end, 2) - ---- @param propName string ---- @param object table -utils.prop = utils.curry(function(propName, object) - return object[propName] -end, 2) - ---- @param val any ---- @param t table -utils.includes = utils.curry(function(val, t) - assert(type(t) == "table", "argument needs to be a table") - return utils.find(function(v) - return v == val - end, t) ~= nil -end, 2) - --- @param t table utils.keys = function(t) assert(type(t) == "table", "argument needs to be a table") @@ -179,26 +13,10 @@ utils.keys = function(t) return keys end ---- @param t table -utils.values = function(t) - assert(type(t) == "table", "argument needs to be a table") - local values = {} - for _, value in pairs(t) do - table.insert(values, value) - end - return values -end - function utils.hasMatchingTag(tag, value) return Handlers.utils.hasMatchingTag(tag, value) end ----@param msg AoMessage -function utils.reply(msg) - ---@diagnostic disable-next-line - Handlers.utils.reply(msg) -end - --- Deep copies a table --- @param original table The table to copy --- @return table|nil The deep copy of the table or nil if the original is nil @@ -399,7 +217,7 @@ end --- @param handlers Handlers --- @description Get the names of all handlers ---- @return table +--- @return string[] function utils.getHandlerNames(handlers) local names = {} for _, handler in ipairs(handlers.list) do @@ -485,7 +303,7 @@ function utils.createActionHandler(action, msgHandler, position) return utils.createHandler("Action", action, msgHandler, position) end ----@param keywords table +---@param keywords string[] ---@description Validates the keywords ---Amount of keywords must be less than or equal to 16 ---Each keyword must be a unique string of 32 characters or less From abad18f533d8b15693814d61f948dabcc1b9f240 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 13 Nov 2024 07:31:21 -0600 Subject: [PATCH 5/9] fix(notices): move notification methods to notices file --- src/common/main.lua | 7 +++-- src/common/notices.lua | 65 ++++++++++++++++++++++++++++++++++++++ src/common/utils.lua | 71 +++--------------------------------------- 3 files changed, 73 insertions(+), 70 deletions(-) create mode 100644 src/common/notices.lua diff --git a/src/common/main.lua b/src/common/main.lua index a925805..b3271f5 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -5,6 +5,7 @@ function ant.init() -- utils local json = require(".common.json") local utils = require(".common.utils") + local notices = require(".common.notices") local camel = utils.camelCase local createActionHandler = utils.createActionHandler @@ -96,8 +97,8 @@ function ant.init() utils.validateOwner(msg.From) balances.transfer(recipient) if not msg.Cast then - ao.send(utils.notices.debit(msg)) - ao.send(utils.notices.credit(msg)) + ao.send(notices.debit(msg)) + ao.send(notices.credit(msg)) end end) @@ -221,7 +222,7 @@ function ant.init() end) createActionHandler(ActionMap.State, function(msg) - utils.notices.notifyState(msg, msg.From) + notices.notifyState(msg, msg.From) end) -- IO Network Contract Handlers diff --git a/src/common/notices.lua b/src/common/notices.lua new file mode 100644 index 0000000..d6ce298 --- /dev/null +++ b/src/common/notices.lua @@ -0,0 +1,65 @@ +local notices = {} + +--- @param oldMsg AoMessage +--- @param newMsg AoMessage +--- @description Add forwarded tags to the new message +--- @return AoMessage +function notices.addForwardedTags(oldMsg, newMsg) + for tagName, tagValue in pairs(oldMsg) do + -- Tags beginning with "X-" are forwarded + if string.sub(tagName, 1, 2) == "X-" then + newMsg[tagName] = tagValue + end + end + return newMsg +end + +--- @param msg AoMessage +--- @description Create a credit notice message +--- @return AoMessage +function notices.credit(msg) + return notices.addForwardedTags(msg, { + Target = msg.Recipient, + Action = "Credit-Notice", + Sender = msg.From, + Quantity = tostring(1), + }) +end + +--- @param msg AoMessage +--- @description Create a debit notice message +--- @return AoMessage +function notices.debit(msg) + return notices.addForwardedTags(msg, { + Target = msg.From, + Action = "Debit-Notice", + Recipient = msg.Recipient, + Quantity = tostring(1), + }) +end + +--- @param notices table +function notices.sendNotices(notices) + for _, notice in ipairs(notices) do + ao.send(notice) + end +end + +--- @param msg AoMessage +--- @param target string +--- @description Notify the target of the current state +--- @return nil +function notices.notifyState(msg, target) + if not target then + print("No target specified for state notice") + return + end + + ao.send(notices.addForwardedTags(msg, { + Target = target, + Action = "State-Notice", + Data = json.encode(utils.getState()), + })) +end + +return notices diff --git a/src/common/utils.lua b/src/common/utils.lua index 58c791f..7bc1211 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -1,6 +1,7 @@ -- the majority of this file came from https://github.com/permaweb/aos/blob/main/process/utils.lua local constants = require(".common.constants") local json = require(".common.json") +local notices = require(".common.notices") local utils = { _version = "0.0.1" } --- @param t table @@ -151,70 +152,6 @@ function utils.getState() } end -utils.notices = {} - ---- @param oldMsg AoMessage ---- @param newMsg AoMessage ---- @description Add forwarded tags to the new message ---- @return AoMessage -function utils.notices.addForwardedTags(oldMsg, newMsg) - for tagName, tagValue in pairs(oldMsg) do - -- Tags beginning with "X-" are forwarded - if string.sub(tagName, 1, 2) == "X-" then - newMsg[tagName] = tagValue - end - end - return newMsg -end - ---- @param msg AoMessage ---- @description Create a credit notice message ---- @return AoMessage -function utils.notices.credit(msg) - return utils.notices.addForwardedTags(msg, { - Target = msg.Recipient, - Action = "Credit-Notice", - Sender = msg.From, - Quantity = tostring(1), - }) -end - ---- @param msg AoMessage ---- @description Create a debit notice message ---- @return AoMessage -function utils.notices.debit(msg) - return utils.notices.addForwardedTags(msg, { - Target = msg.From, - Action = "Debit-Notice", - Recipient = msg.Recipient, - Quantity = tostring(1), - }) -end - ---- @param notices table -function utils.notices.sendNotices(notices) - for _, notice in ipairs(notices) do - ao.send(notice) - end -end - ---- @param msg AoMessage ---- @param target string ---- @description Notify the target of the current state ---- @return nil -function utils.notices.notifyState(msg, target) - if not target then - print("No target specified for state notice") - return - end - - ao.send(utils.notices.addForwardedTags(msg, { - Target = target, - Action = "State-Notice", - Data = json.encode(utils.getState()), - })) -end - --- @param handlers Handlers --- @description Get the names of all handlers --- @return string[] @@ -270,7 +207,7 @@ function utils.createHandler(tagName, tagValue, handler, position) end, utils.errorHandler) if not handlerStatus then - ao.send(utils.notices.addForwardedTags(msg, { + ao.send(notices.addForwardedTags(msg, { Target = msg.From, Action = "Invalid-" .. tagValue .. "-Notice", Error = tagValue .. "-Error", @@ -278,7 +215,7 @@ function utils.createHandler(tagName, tagValue, handler, position) Data = handlerRes, })) elseif handlerRes then - ao.send(utils.notices.addForwardedTags(msg, { + ao.send(notices.addForwardedTags(msg, { Target = msg.From, Action = tagValue .. "-Notice", Data = type(handlerRes) == "string" and handlerRes or json.encode(handlerRes), @@ -288,7 +225,7 @@ function utils.createHandler(tagName, tagValue, handler, position) local hasNewOwner = Owner ~= prevOwner local hasDifferentControllers = #utils.keys(Controllers) ~= #utils.keys(prevControllers) if (hasNewOwner or hasDifferentControllers) and tagValue ~= "State" then - utils.notices.notifyState(msg, msg.From) + notices.notifyState(msg, msg.From) end return handlerRes From 81da676a2e3ac2bbdd7bb9e24fc774aae8c39e6b Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 13 Nov 2024 07:32:26 -0600 Subject: [PATCH 6/9] fix(scripts): remove script from package json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 73dd92a..43d5f1e 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "aos:load": "node tools/bundle-aos.mjs && node tools/load-aos.mjs", "aos:spawn": "node tools/spawn-aos.mjs", "test": "yarn aos:build && node --test --test-concurrency 1 --experimental-wasm-memory64 **/*.test.mjs", - "prepare": "husky", - "install-lua-deps": "sh tools/install-lua-deps.sh" + "prepare": "husky" }, "devDependencies": { "@ardrive/turbo-sdk": "^1.19.0", From ec0d7566e03836a7823dc1da34c28439722455ce Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 13 Nov 2024 07:34:43 -0600 Subject: [PATCH 7/9] fix(lint): fix linting on notices --- src/common/notices.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/notices.lua b/src/common/notices.lua index d6ce298..1c24c70 100644 --- a/src/common/notices.lua +++ b/src/common/notices.lua @@ -1,3 +1,5 @@ +local json = require("json") +local utils = require(".common.utils") local notices = {} --- @param oldMsg AoMessage From 9d514a31d5b973b5918b287e64ae8da2909ce93e Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 13 Nov 2024 07:37:59 -0600 Subject: [PATCH 8/9] fix(transfer): update transfer method to return the changed balances of the ant --- src/common/balances.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/balances.lua b/src/common/balances.lua index 5c5f730..256211d 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -14,6 +14,8 @@ function balances.transfer(to) --luacheck: ignore Owner Controllers Owner = to Controllers = {} + + return { [to] = 1 } end --- Retrieves the balance of a specified wallet. From e9c857133f4825bb4954cddd2f1ceb9ef7c433e6 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Wed, 13 Nov 2024 07:47:54 -0600 Subject: [PATCH 9/9] fix(circular import): remove utils from notices file since it causes a circular reference --- src/common/balances.lua | 2 +- src/common/notices.lua | 26 +++++++++++++++++++++----- src/common/types.lua | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/common/balances.lua b/src/common/balances.lua index 256211d..6c7fad7 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -7,7 +7,7 @@ local balances = {} --- Transfers the ANT to a specified wallet. ---@param to string - The wallet address to transfer the balance to. ----@return nil +---@return table function balances.transfer(to) utils.validateArweaveId(to) Balances = { [to] = 1 } diff --git a/src/common/notices.lua b/src/common/notices.lua index 1c24c70..189a39d 100644 --- a/src/common/notices.lua +++ b/src/common/notices.lua @@ -1,5 +1,4 @@ local json = require("json") -local utils = require(".common.utils") local notices = {} --- @param oldMsg AoMessage @@ -40,9 +39,9 @@ function notices.debit(msg) }) end ---- @param notices table -function notices.sendNotices(notices) - for _, notice in ipairs(notices) do +--- @param noticesToSend table +function notices.sendNotices(noticesToSend) + for _, notice in ipairs(noticesToSend) do ao.send(notice) end end @@ -57,10 +56,27 @@ function notices.notifyState(msg, target) return end + ---@type AntState + local state = { + Records = Records, + Controllers = Controllers, + Balances = Balances, + Owner = Owner, + Name = Name, + Ticker = Ticker, + Logo = Logo, + Description = Description, + Keywords = Keywords, + Denomination = Denomination, + TotalSupply = TotalSupply, + Initialized = Initialized, + ["Source-Code-TX-ID"] = SourceCodeTxId, + } + ao.send(notices.addForwardedTags(msg, { Target = target, Action = "State-Notice", - Data = json.encode(utils.getState()), + Data = json.encode(state), })) end diff --git a/src/common/types.lua b/src/common/types.lua index 5ab943b..7dd6845 100644 --- a/src/common/types.lua +++ b/src/common/types.lua @@ -36,7 +36,7 @@ --- Name: string, --- Ticker: string, --- Description: string, ---- Keywords: string, +--- Keywords: table, --- Logo: string, --- Balances: table, --- Owner: string,