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