From e43ac33c73606f8ad4e180e7449d6917f34a9459 Mon Sep 17 00:00:00 2001 From: Philip Mataras Date: Mon, 14 Oct 2024 22:56:27 -0400 Subject: [PATCH 1/8] feat: allow description and keywords --- README.md | 18 ++++++++++ spec/ant_spec.lua | 73 +++++++++++++++++++++++++++++++++++++ src/common/balances.lua | 28 +++++++++++++++ src/common/initialize.lua | 21 +++++++++++ src/common/main.lua | 75 +++++++++++++++++++++++++++++++++++++++ src/common/utils.lua | 2 ++ test/info.test.mjs | 51 ++++++++++++++++++++++++++ test/initialize.test.mjs | 23 +++++++++--- tools/constants.mjs | 2 ++ tools/load-module.mjs | 13 +++++++ tools/spawn-aos.mjs | 2 ++ tools/spawn-module.mjs | 13 +++++++ 12 files changed, 316 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 683b7a5..8d11538 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,24 @@ Sets the ticker symbol for the ANT. | Action | string | "Set-Ticker" | true | Action tag for triggering handler | | Ticker | string | N/A | true | New ticker symbol for ANT. | +#### `Set-Description` + +Sets the description for the ANT. + +| Tag Name | Type | Pattern | Required | Description | +| ----------- | ------ | ----------------- | -------- | --------------------------------- | +| Action | string | "Set-Description" | true | Action tag for triggering handler | +| Description | string | N/A | true | New description for ANT. | + +#### `Set-Keywords` + +Sets the keywords for the ANT. + +| Tag Name | Type | Pattern | Required | Description | +| -------- | ------ | -------------- | -------- | --------------------------------- | +| Action | string | "Set-Keywords" | true | Action tag for triggering handler | +| Keywords | table | "^[%w-_]+$" | true | New keywords for ANT. | + #### `Set-Controller` Adds a new controller to the ANT. diff --git a/spec/ant_spec.lua b/spec/ant_spec.lua index 425141e..d05923e 100644 --- a/spec/ant_spec.lua +++ b/spec/ant_spec.lua @@ -17,6 +17,8 @@ _G.Records = {} _G.Controllers = { fake_address } _G.Name = "Arweave Name Token" _G.Ticker = "ANT" +_G.Description = "ANT's Description" +_G.Keywords = { "KEYWORD-1", "KEYWORD-2", "KEYWORD-3" } _G.Logo = "LOGO" _G.Denomination = 1 @@ -27,6 +29,8 @@ end local originalState = { name = "Arweave Name Token", ticker = "ANT", + description = "ANT's description", + keywords = { "KEYWORD-1", "KEYWORD-2", "KEYWORD-3" }, controllers = { fake_address }, records = { ["@"] = { transactionId = "test", ttlSeconds = 900 } }, balances = { [fake_address] = 1 }, @@ -40,6 +44,8 @@ describe("Arweave Name Token", function() _G.Controllers = { fake_address } _G.Name = "Arweave Name Token" _G.Ticker = "ANT" + _G.Description = "ANT's description" + _G.Keywords = { "KEYWORD-1", "KEYWORD-2", "KEYWORD-3" } end) setup(function() end) @@ -54,6 +60,8 @@ describe("Arweave Name Token", function() assert.are.same(_G.Controllers, originalState.controllers) assert.are.same(_G.Name, originalState.name) assert.are.same(_G.Ticker, originalState.ticker) + assert.are.same(_G.Description, originalState.description) + assert.are.same(_G.Keywords, originalState.keywords) end) it("Transfers tokens between accounts", function() @@ -117,4 +125,69 @@ describe("Arweave Name Token", function() assert.are.same(_G.Ticker, newTicker) end) + + it("sets the description", function() + local newDescription = "NEW DESCRIPTION" + balances.setDescription(newDescription) -- happy path + + assert.are.same(_G.Description, newDescription) + end) + + it("sets the keywords", function() + local newKeywords = { "NEW-KEYWORD-1", "NEW-KEYWORD-2", "NEW-KEYWORD-3" } + balances.setKeywords(newKeywords) -- setKeywords now handles JSON string + + assert.are.same(_G.Keywords, newKeywords) + end) + + -- Test when too many keywords are provided + it("throws an error if keywords exceed 16 elements", function() + local tooManyKeywords = {} + for i = 1, 17 do -- 17 keywords, exceeds limit + table.insert(tooManyKeywords, "keyword" .. i) + end + assert.has_error(function() + balances.setKeywords(tooManyKeywords) + end, "There must not be more than 16 keywords") + end) + + -- Test when any keyword is too long + it("throws an error if any keyword is too long", function() + local keywordsWithLongEntry = { "valid", string.rep("a", 33) } -- Second keyword is 33 characters long + assert.has_error(function() + balances.setKeywords(keywordsWithLongEntry) + end, "Each keyword must not be longer than 32 characters") + end) + + -- Test when any keyword contains spaces + it("throws an error if any keyword contains spaces", function() + local keywordsWithSpace = { "valid", "invalid keyword" } -- Contains a space + assert.has_error(function() + balances.setKeywords(keywordsWithSpace) + end, "Keywords must not contain spaces") + end) + + -- Test when keywords contain invalid characters + it("throws an error if keywords contain invalid characters", function() + local keywordsWithSpecialChars = { "valid", "inva@lid" } -- Contains special character '@' + assert.has_error(function() + balances.setKeywords(keywordsWithSpecialChars) + end, "Keywords must only contain alphanumeric characters, dashes, or underscores") + end) + + -- Test when any keyword is duplicated + it("throws an error if any keyword is duplicated", function() + local keywordsWithDuplicates = { "keyword", "keyword" } -- Duplicate keyword + assert.has_error(function() + balances.setKeywords(keywordsWithDuplicates) + end, "Duplicate keyword detected: keyword") + end) + + -- Test when the keywords array is not actually an array + it("throws an error if the keywords array is not actually an array", function() + local notAnArray = "not-an-array" + assert.has_error(function() + balances.setKeywords(notAnArray) + end, "Keywords must be an array") + end) end) diff --git a/src/common/balances.lua b/src/common/balances.lua index 2ffbc37..01797df 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -37,4 +37,32 @@ function balances.setTicker(ticker) return json.encode({ ticker = Ticker }) end +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 }) +end + +function balances.setKeywords(keywords) + assert(type(keywords) == "table", "Keywords must be an array") + assert(#keywords <= 16, "There must not be more than 16 keywords") + + local seenKeywords = {} -- Table to track seen keywords + + for _, keyword in ipairs(keywords) do + assert(type(keyword) == "string", "Each keyword must be a string") + assert(#keyword <= 32, "Each keyword must not be longer than 32 characters") + assert(not keyword:find("%s"), "Keywords must not contain spaces") + assert(keyword:match("^[%w-_]+$"), "Keywords must only contain alphanumeric characters, dashes, or underscores") + + -- Check for duplicates + assert(not seenKeywords[keyword], "Duplicate keyword detected: " .. keyword) + seenKeywords[keyword] = true + end + + Keywords = keywords + return json.encode({ keywords = Keywords }) +end + return balances diff --git a/src/common/initialize.lua b/src/common/initialize.lua index 5e80468..91d3dcb 100644 --- a/src/common/initialize.lua +++ b/src/common/initialize.lua @@ -9,9 +9,13 @@ function initialize.initializeANTState(state) local records = encoded.records local name = encoded.name local ticker = encoded.ticker + local description = encoded.description + local keywords = encoded.keywords local owner = encoded.owner assert(type(name) == "string", "name must be a string") assert(type(ticker) == "string", "ticker must be a string") + assert(type(description) == "string", "description must be a string") + assert(#description <= 512, "Description must not be longer than 512 characters") assert(type(balances) == "table", "balances must be a table") for k, v in pairs(balances) do balances[k] = tonumber(v) @@ -26,8 +30,23 @@ function initialize.initializeANTState(state) utils.validateTTLSeconds(v.ttlSeconds) end + assert(type(keywords) == "table", "Keywords must be an array") + assert(#keywords <= 16, "There must not be more than 16 keywords") + + local seenKeywords = {} + for _, keyword in ipairs(keywords) do + assert(type(keyword) == "string", "Each keyword must be a string") + assert(#keyword <= 32, "Each keyword must not be longer than 32 characters") + assert(not keyword:find("%s"), "Keywords must not contain spaces") + assert(keyword:match("^[%w-_]+$"), "Keywords must only contain alphanumeric characters, dashes, or underscores") + assert(not seenKeywords[keyword], "Duplicate keyword detected: " .. keyword) + seenKeywords[keyword] = true + end + Name = name Ticker = ticker + Description = description + Keywords = keywords Balances = balances Controllers = controllers Records = records @@ -37,6 +56,8 @@ function initialize.initializeANTState(state) return json.encode({ name = Name, ticker = Ticker, + description = Description, + keywords = Keywords, balances = Balances, controllers = Controllers, records = Records, diff --git a/src/common/main.lua b/src/common/main.lua index 38a30bd..e1c7b28 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -19,6 +19,8 @@ function ant.init() Name = Name or "Arweave Name Token" Ticker = Ticker or "ANT" Logo = Logo or "Sie_26dvgyok0PZD_-iQAFOhOd5YxDTkczOLoqTTL_A" + Description = Description or "A brief description of this ANT." + Keywords = Keywords or {} Denomination = Denomination or 0 TotalSupply = TotalSupply or 1 Initialized = Initialized or false @@ -34,6 +36,8 @@ function ant.init() RemoveRecord = "Remove-Record", SetName = "Set-Name", SetTicker = "Set-Ticker", + SetDescription = "Set-Description", + SetKeywords = "Set-Keywords", --- initialization method for bootstrapping the contract from other platforms --- InitializeState = "Initialize-State", -- read @@ -158,6 +162,8 @@ function ant.init() Ticker = Ticker, ["Total-Supply"] = tostring(TotalSupply), Logo = Logo, + Description = Description, + Keywords = Keywords, Denomination = tostring(Denomination), Owner = Owner, Handlers = utils.getHandlerNames(Handlers), @@ -390,6 +396,75 @@ function ant.init() ao.send({ Target = msg.From, Action = "Set-Ticker-Notice", Data = tickerRes }) end) + Handlers.add( + camel(ActionMap.SetDescription), + utils.hasMatchingTag("Action", ActionMap.SetDescription), + function(msg) + local assertHasPermission, permissionErr = pcall(utils.assertHasPermission, msg.From) + if assertHasPermission == false then + return ao.send({ + Target = msg.From, + Action = "Invalid-Set-Description-Notice", + Data = permissionErr, + Error = "Set-Description-Error", + ["Message-Id"] = msg.Id, + }) + end + local descriptionStatus, descriptionRes = pcall(balances.setDescription, msg.Tags.Description) + if not descriptionStatus then + ao.send({ + Target = msg.From, + Action = "Invalid-Set-Description-Notice", + Data = descriptionRes, + Error = "Set-Description-Error", + ["Message-Id"] = msg.Id, + }) + return + end + + ao.send({ Target = msg.From, Action = "Set-Description-Notice", Data = descriptionRes }) + end + ) + + Handlers.add(camel(ActionMap.SetKeywords), utils.hasMatchingTag("Action", ActionMap.SetKeywords), function(msg) + local assertHasPermission, permissionErr = pcall(utils.assertHasPermission, msg.From) + if assertHasPermission == false then + return ao.send({ + Target = msg.From, + Action = "Invalid-Set-Keywords-Notice", + Data = permissionErr, + Error = "Set-Keywords-Error", + ["Message-Id"] = msg.Id, + }) + end + + -- Decode JSON from the tag + local success, keywords = pcall(json.decode, msg.Tags.Keywords) + if not success or type(keywords) ~= "table" then + return ao.send({ + Target = msg.From, + Action = "Invalid-Set-Keywords-Notice", + Data = "Invalid JSON format for keywords", + Error = "Set-Keywords-Error", + ["Message-Id"] = msg.Id, + }) + end + + local keywordsStatus, keywordsRes = pcall(balances.setKeywords, keywords) + if not keywordsStatus then + ao.send({ + Target = msg.From, + Action = "Invalid-Set-Keywords-Notice", + Data = keywordsRes, + Error = "Set-Keywords-Error", + ["Message-Id"] = msg.Id, + }) + return + end + + ao.send({ Target = msg.From, Action = "Set-Keywords-Notice", Data = keywordsRes }) + end) + Handlers.add( camel(ActionMap.InitializeState), utils.hasMatchingTag("Action", ActionMap.InitializeState), diff --git a/src/common/utils.lua b/src/common/utils.lua index 846c10a..92e574a 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -309,6 +309,8 @@ function utils.notices.notifyState(msg, target) Name = Name, Ticker = Ticker, Logo = Logo, + Description = Description, + Keywords = Keywords, Denomination = Denomination, TotalSupply = TotalSupply, Initialized = Initialized, diff --git a/test/info.test.mjs b/test/info.test.mjs index 678b8a8..56d720e 100644 --- a/test/info.test.mjs +++ b/test/info.test.mjs @@ -29,6 +29,8 @@ describe('aos Info', async () => { const processInfo = JSON.parse(result.Messages[0].Data); assert(processInfo.Name); assert(processInfo.Ticker); + assert(processInfo.Description); + assert(processInfo.Keywords); assert(processInfo['Total-Supply']); assert(processInfo.Denomination !== undefined); assert(processInfo.Logo); @@ -52,6 +54,8 @@ describe('aos Info', async () => { 'records', 'setName', 'setTicker', + 'setDescription', + 'setKeywords', 'initializeState', 'state', ]); @@ -93,6 +97,51 @@ describe('aos Info', async () => { assert(info.Ticker === 'TEST'); }); + it('should set the description of the process', async () => { + const setDescriptionResult = await handle({ + Tags: [ + { name: 'Action', value: 'Set-Description' }, + { name: 'Description', value: 'NEW DESCRIPTION' }, + ], + }); + + const infoResult = await handle( + { + Tags: [{ name: 'Action', value: 'Info' }], + }, + setDescriptionResult.Memory, + ); + const info = JSON.parse(infoResult.Messages[0].Data); + assert(info.Description === 'NEW DESCRIPTION'); + }); + + it('should set the keywords of the process', async () => { + const setKeywordsResult = await handle({ + Tags: [ + { name: 'Action', value: 'Set-Keywords' }, + { + name: 'Keywords', + value: JSON.stringify(['keyword1', 'keyword2', 'keyword3']), + }, + ], + }); + + // Assuming an 'Info' action retrieves the current state of the process + const infoResult = await handle( + { + Tags: [{ name: 'Action', value: 'Info' }], + }, + setKeywordsResult.Memory, // Use the updated memory from the setKeywordsResult + ); + + const info = JSON.parse(infoResult.Messages[0].Data); + assert.deepEqual( + info.Keywords, + ['keyword1', 'keyword2', 'keyword3'], + 'Keywords do not match expected values', + ); + }); + it('should get state', async () => { const result = await handle({ Tags: [{ name: 'Action', value: 'State' }], @@ -105,6 +154,8 @@ describe('aos Info', async () => { assert(state.Controllers); assert(state.Owner); assert(state.Ticker); + assert(state.Description); + assert(state.Keywords); assert(state.Name); }); }); diff --git a/test/initialize.test.mjs b/test/initialize.test.mjs index f4e403e..7a1cf1d 100644 --- a/test/initialize.test.mjs +++ b/test/initialize.test.mjs @@ -26,6 +26,8 @@ describe('aos Initialization', async () => { const antState = { name: 'Test Process', ticker: 'TEST', + description: 'TEST DESCRIPTION', + keywords: ['KEYWORD-1', 'KEYWORD-2', 'KEYWORD-3'], owner: STUB_ADDRESS, controllers: [STUB_ADDRESS], balances: { [STUB_ADDRESS]: 1 }, @@ -36,15 +38,26 @@ describe('aos Initialization', async () => { }, }, }; + const result = await handle({ Tags: [{ name: 'Action', value: 'Initialize-State' }], Data: JSON.stringify(antState), }); - const { name, ticker, balances, controllers, records } = JSON.parse( - result.Messages[0].Data, - ); - assert(name === antState.name); - assert(ticker === antState.ticker); + + const { + name, + ticker, + description, + keywords, + balances, + controllers, + records, + } = JSON.parse(result.Messages[0].Data); + + assert.strictEqual(name, antState.name); + assert.strictEqual(ticker, antState.ticker); + assert.strictEqual(description, antState.description); + assert.deepStrictEqual(keywords, antState.keywords); assert.deepEqual(balances, antState.balances); assert.deepEqual(controllers, antState.controllers); assert.deepEqual(records, antState.records); diff --git a/tools/constants.mjs b/tools/constants.mjs index 3388084..0e856e4 100644 --- a/tools/constants.mjs +++ b/tools/constants.mjs @@ -55,6 +55,8 @@ const DEFAULT_ANT_STATE = JSON.stringify({ }, }, ticker: 'ANT', + description: "ANT's description", + keywords: ['KEYWORD-1', 'KEYWORD-2', 'KEYWORD-3'], }); const DEFAULT_HANDLE_OPTIONS = { diff --git a/tools/load-module.mjs b/tools/load-module.mjs index cd4fe96..adbf49d 100644 --- a/tools/load-module.mjs +++ b/tools/load-module.mjs @@ -35,6 +35,17 @@ async function main() { ['Remove-Controller', { Controller: ''.padEnd(43, '1') }], ['Set-Name', { Name: 'Test Name' }], ['Set-Ticker', { Ticker: 'TEST' }], + ['Set-Description', { Description: 'TEST DESCRIPTION' }], + [ + 'Set-Keywords', + { + Keywords: JSON.stringify([ + 'TEST-KEYWORD-1', + 'TEST-KEYWORD-2', + 'TEST-KEYWORD-3', + ]), + }, + ], // Test for Set-Keywords [ 'Set-Record', { @@ -90,6 +101,8 @@ async function main() { }, }, ticker: 'ANT', + description: 'Description of this ANT.', + keywords: ['KEYWORD-1', 'KEYWORD-2', 'KEYWORD-3'], }), }, env, diff --git a/tools/spawn-aos.mjs b/tools/spawn-aos.mjs index 15bafbb..700c3d1 100644 --- a/tools/spawn-aos.mjs +++ b/tools/spawn-aos.mjs @@ -37,6 +37,8 @@ async function main() { }, }, ticker: 'ANT', + description: 'Description for this ANT.', + keywords: ['KEYWORD-1', 'KEYWORD-2', 'KEYWORD-3'], }); const processId = await ao.spawn({ diff --git a/tools/spawn-module.mjs b/tools/spawn-module.mjs index 8341c5e..6e355ae 100644 --- a/tools/spawn-module.mjs +++ b/tools/spawn-module.mjs @@ -41,6 +41,17 @@ async function main() { ['Remove-Controller', { Controller: ''.padEnd(43, '1') }], ['Set-Name', { Name: 'Test Name' }], ['Set-Ticker', { Ticker: 'TEST' }], + ['Set-Description', { Description: 'TEST DESCRIPTION' }], + [ + 'Set-Keywords', + { + Keywords: JSON.stringify([ + 'TEST-KEYWORD-1', + 'TEST-KEYWORD-2', + 'TEST-KEYWORD-3', + ]), + }, + ], // Test for Set-Keywords [ 'Set-Record', { @@ -87,6 +98,8 @@ async function main() { }, }, ticker: 'ANT', + description: 'Description for this ANT.', + keywords: ['KEYWORD-1', 'KEYWORD-2', 'KEYWORD-3'], }), signer, }); From 66fc768d708cf0b9a3e235892519de7ce12a0904 Mon Sep 17 00:00:00 2001 From: Philip Mataras Date: Wed, 16 Oct 2024 18:48:43 -0400 Subject: [PATCH 2/8] updates pattern on description --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8d11538..70d16e8 100644 --- a/README.md +++ b/README.md @@ -205,10 +205,10 @@ Sets the ticker symbol for the ANT. Sets the description for the ANT. -| Tag Name | Type | Pattern | Required | Description | -| ----------- | ------ | ----------------- | -------- | --------------------------------- | -| Action | string | "Set-Description" | true | Action tag for triggering handler | -| Description | string | N/A | true | New description for ANT. | +| Tag Name | Type | Pattern | Required | Description | +| ----------- | ------ | ------------------ | -------- | --------------------------------- | +| Action | string | "Set-Description" | true | Action tag for triggering handler | +| Description | string | Max 512 characters | true | New description for ANT. | #### `Set-Keywords` From 9884702e9144fe14c2b1899b5fef58deb4ffa2ad Mon Sep 17 00:00:00 2001 From: Philip Mataras Date: Wed, 16 Oct 2024 19:04:00 -0400 Subject: [PATCH 3/8] adds # and @ to allowable keyword characters --- spec/ant_spec.lua | 4 ++-- src/common/balances.lua | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/ant_spec.lua b/spec/ant_spec.lua index 6d8acb5..d2fb754 100644 --- a/spec/ant_spec.lua +++ b/spec/ant_spec.lua @@ -146,10 +146,10 @@ describe("Arweave Name Token", function() -- Test when keywords contain invalid characters it("throws an error if keywords contain invalid characters", function() - local keywordsWithSpecialChars = { "valid", "inva@lid" } -- Contains special character '@' + local keywordsWithSpecialChars = { "valid", "inva!lid" } -- Contains special character '!' assert.has_error(function() balances.setKeywords(keywordsWithSpecialChars) - end, "Keywords must only contain alphanumeric characters, dashes, or underscores") + end, "Keywords must only contain alphanumeric characters, dashes, underscores, #, or @") end) -- Test when any keyword is duplicated diff --git a/src/common/balances.lua b/src/common/balances.lua index 01797df..5420ecb 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -54,8 +54,10 @@ function balances.setKeywords(keywords) assert(type(keyword) == "string", "Each keyword must be a string") assert(#keyword <= 32, "Each keyword must not be longer than 32 characters") assert(not keyword:find("%s"), "Keywords must not contain spaces") - assert(keyword:match("^[%w-_]+$"), "Keywords must only contain alphanumeric characters, dashes, or underscores") - + assert( + keyword:match("^[%w-_#@]+$"), + "Keywords must only contain alphanumeric characters, dashes, underscores, #, or @" + ) -- Check for duplicates assert(not seenKeywords[keyword], "Duplicate keyword detected: " .. keyword) seenKeywords[keyword] = true From 15f997f701d2f714a7aeaa60f488a87cdf62695d Mon Sep 17 00:00:00 2001 From: Philip Mataras Date: Wed, 16 Oct 2024 19:07:27 -0400 Subject: [PATCH 4/8] adds correct pattern for keywords --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 70d16e8..2eaf278 100644 --- a/README.md +++ b/README.md @@ -214,10 +214,10 @@ Sets the description for the ANT. Sets the keywords for the ANT. -| Tag Name | Type | Pattern | Required | Description | -| -------- | ------ | -------------- | -------- | --------------------------------- | -| Action | string | "Set-Keywords" | true | Action tag for triggering handler | -| Keywords | table | "^[%w-_]+$" | true | New keywords for ANT. | +| Tag Name | Type | Pattern | Required | Description | +| -------- | ------ | ---------------------------------------------------------------- | -------- | --------------------------------- | +| Action | string | "Set-Keywords" | true | Action tag for triggering handler | +| Keywords | table | "^[%w-_#@]+$", max 32 characters, max 16 keywords, min 1 keyword | true | New keywords for ANT. | #### `Set-Controller` From db004725da70b8c02341adb202edab3dd08012db Mon Sep 17 00:00:00 2001 From: Philip Mataras Date: Wed, 16 Oct 2024 19:17:57 -0400 Subject: [PATCH 5/8] adds util to validate keywords --- src/common/balances.lua | 18 +----------------- src/common/initialize.lua | 13 +------------ src/common/utils.lua | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/common/balances.lua b/src/common/balances.lua index 5420ecb..5047cbb 100644 --- a/src/common/balances.lua +++ b/src/common/balances.lua @@ -45,23 +45,7 @@ function balances.setDescription(description) end function balances.setKeywords(keywords) - assert(type(keywords) == "table", "Keywords must be an array") - assert(#keywords <= 16, "There must not be more than 16 keywords") - - local seenKeywords = {} -- Table to track seen keywords - - for _, keyword in ipairs(keywords) do - assert(type(keyword) == "string", "Each keyword must be a string") - assert(#keyword <= 32, "Each keyword must not be longer than 32 characters") - assert(not keyword:find("%s"), "Keywords must not contain spaces") - assert( - keyword:match("^[%w-_#@]+$"), - "Keywords must only contain alphanumeric characters, dashes, underscores, #, or @" - ) - -- Check for duplicates - assert(not seenKeywords[keyword], "Duplicate keyword detected: " .. keyword) - seenKeywords[keyword] = true - end + utils.validateKeywords(keywords) Keywords = keywords return json.encode({ keywords = Keywords }) diff --git a/src/common/initialize.lua b/src/common/initialize.lua index 91d3dcb..f4f3b9e 100644 --- a/src/common/initialize.lua +++ b/src/common/initialize.lua @@ -30,18 +30,7 @@ function initialize.initializeANTState(state) utils.validateTTLSeconds(v.ttlSeconds) end - assert(type(keywords) == "table", "Keywords must be an array") - assert(#keywords <= 16, "There must not be more than 16 keywords") - - local seenKeywords = {} - for _, keyword in ipairs(keywords) do - assert(type(keyword) == "string", "Each keyword must be a string") - assert(#keyword <= 32, "Each keyword must not be longer than 32 characters") - assert(not keyword:find("%s"), "Keywords must not contain spaces") - assert(keyword:match("^[%w-_]+$"), "Keywords must only contain alphanumeric characters, dashes, or underscores") - assert(not seenKeywords[keyword], "Duplicate keyword detected: " .. keyword) - seenKeywords[keyword] = true - end + utils.validateKeywords(keywords) Name = name Ticker = ticker diff --git a/src/common/utils.lua b/src/common/utils.lua index 50f458c..4f3b56b 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -342,4 +342,24 @@ function utils.getHandlerNames(handlers) return names end +function utils.validateKeywords(keywords) + assert(type(keywords) == "table", "Keywords must be an array") + assert(#keywords <= 16, "There must not be more than 16 keywords") + + local seenKeywords = {} -- Table to track seen keywords + + for _, keyword in ipairs(keywords) do + assert(type(keyword) == "string", "Each keyword must be a string") + assert(#keyword <= 32, "Each keyword must not be longer than 32 characters") + assert(not keyword:find("%s"), "Keywords must not contain spaces") + assert( + keyword:match("^[%w-_#@]+$"), + "Keywords must only contain alphanumeric characters, dashes, underscores, #, or @" + ) + -- Check for duplicates + assert(not seenKeywords[keyword], "Duplicate keyword detected: " .. keyword) + seenKeywords[keyword] = true + end +end + return utils From be0b48f08477d424a6251c021bf7f3f1ce6128b1 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 21 Oct 2024 10:39:26 -0600 Subject: [PATCH 6/8] fix(action): set version of ubuntu to use for glibc --- .github/workflows/ant.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ant.yaml b/.github/workflows/ant.yaml index 9feb2e3..161813b 100644 --- a/.github/workflows/ant.yaml +++ b/.github/workflows/ant.yaml @@ -4,7 +4,7 @@ on: [push, workflow_dispatch] jobs: unit: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 name: Check out repository code From 49e91c354a4cd80a64dca9e2888bf93969870af9 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 21 Oct 2024 11:47:12 -0600 Subject: [PATCH 7/8] fix(action): bump to 23.10 ubuntu --- .github/workflows/ant.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ant.yaml b/.github/workflows/ant.yaml index 161813b..8a8da66 100644 --- a/.github/workflows/ant.yaml +++ b/.github/workflows/ant.yaml @@ -4,7 +4,7 @@ on: [push, workflow_dispatch] jobs: unit: - runs-on: ubuntu-22.04 + runs-on: ubuntu-23.10 steps: - uses: actions/checkout@v4 name: Check out repository code From 81d21bc4fc13f87cc2892a77b9bec0aa4f057c83 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 22 Oct 2024 06:26:22 -0500 Subject: [PATCH 8/8] chore(git): try ubuntu-24.04 in runner --- .github/workflows/ant.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ant.yaml b/.github/workflows/ant.yaml index 8a8da66..38bafe1 100644 --- a/.github/workflows/ant.yaml +++ b/.github/workflows/ant.yaml @@ -4,7 +4,7 @@ on: [push, workflow_dispatch] jobs: unit: - runs-on: ubuntu-23.10 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 name: Check out repository code