Skip to content

Commit

Permalink
fix(records): lower string in handler instead of in method
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Oct 1, 2024
1 parent 4e9518b commit 5870c0e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
68 changes: 37 additions & 31 deletions src/common/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function ant.init()
end
local tags = msg.Tags
local name, transactionId, ttlSeconds =
tags["Sub-Domain"], tags["Transaction-Id"], tonumber(tags["TTL-Seconds"])
string.lower(tags["Sub-Domain"]), tags["Transaction-Id"], tonumber(tags["TTL-Seconds"])

local setRecordStatus, setRecordResult = pcall(records.setRecord, name, transactionId, ttlSeconds)
if not setRecordStatus then
Expand All @@ -269,7 +269,8 @@ function ant.init()
if assertHasPermission == false then
return ao.send({ Target = msg.From, Action = "Invalid-Remove-Record-Notice", Data = permissionErr })
end
local removeRecordStatus, removeRecordResult = pcall(records.removeRecord, msg.Tags["Sub-Domain"])
local name = string.lower(msg.Tags["Sub-Domain"])
local removeRecordStatus, removeRecordResult = pcall(records.removeRecord, name)
if not removeRecordStatus then
ao.send({
Target = msg.From,
Expand All @@ -284,7 +285,8 @@ function ant.init()
end)

Handlers.add(camel(ActionMap.Record), utils.hasMatchingTag("Action", ActionMap.Record), function(msg)
local nameStatus, nameRes = pcall(records.getRecord, msg.Tags["Sub-Domain"])
local name = string.lower(msg.Tags["Sub-Domain"])
local nameStatus, nameRes = pcall(records.getRecord, name)
if not nameStatus then
ao.send({
Target = msg.From,
Expand All @@ -299,7 +301,7 @@ function ant.init()
local recordNotice = {
Target = msg.From,
Action = "Record-Notice",
Name = msg.Tags["Sub-Domain"],
Name = name,
Data = nameRes,
}

Expand Down Expand Up @@ -414,36 +416,40 @@ function ant.init()
utils.notices.notifyState(msg, msg.From)
end)

Handlers.prepend(camel(ActionMap.Evolve),Handlers.utils.continue(utils.hasMatchingTag("Action", "Eval")), function(msg)
local srcCodeTxId = msg.Tags["Source-Code-TX-ID"]
if not srcCodeTxId then
return
end
Handlers.prepend(
camel(ActionMap.Evolve),
Handlers.utils.continue(utils.hasMatchingTag("Action", "Eval")),
function(msg)
local srcCodeTxId = msg.Tags["Source-Code-TX-ID"]
if not srcCodeTxId then
return
end

if Owner ~= msg.From then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Error = "Evolve-Error",
["Message-Id"] = msg.Id,
Data = "Only the Owner [" .. Owner or "no owner set" .. "] can call Evolve",
})
return
end
if Owner ~= msg.From then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Error = "Evolve-Error",
["Message-Id"] = msg.Id,
Data = "Only the Owner [" .. Owner or "no owner set" .. "] can call Evolve",
})
return
end

local srcCodeTxIdStatus, srcCodeTxIdResult = pcall(utils.validateArweaveId, srcCodeTxId)
if srcCodeTxIdStatus and not srcCodeTxIdStatus then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Error = "Evolve-Error",
["Message-Id"] = msg.Id,
Data = "Source-Code-TX-ID is required",
})
return
local srcCodeTxIdStatus, srcCodeTxIdResult = pcall(utils.validateArweaveId, srcCodeTxId)
if srcCodeTxIdStatus and not srcCodeTxIdStatus then
ao.send({
Target = msg.From,
Action = "Invalid-Evolve-Notice",
Error = "Evolve-Error",
["Message-Id"] = msg.Id,
Data = "Source-Code-TX-ID is required",
})
return
end
SourceCodeTxId = srcCodeTxId
end
SourceCodeTxId = srcCodeTxId
end)
)
end

return ant
6 changes: 3 additions & 3 deletions src/common/records.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function records.setRecord(name, transactionId, ttlSeconds)
error("Max records limit of 10,000 reached, please delete some records to make space")
end

Records[string.lower(name)] = {
Records[name] = {
transactionId = transactionId,
ttlSeconds = ttlSeconds,
}
Expand All @@ -32,15 +32,15 @@ end
function records.removeRecord(name)
local nameValidity, nameValidityError = pcall(utils.validateUndername, name)
assert(nameValidity ~= false, nameValidityError)
Records[string.lower(name)] = nil
Records[name] = nil
return json.encode({ message = "Record deleted" })
end

function records.getRecord(name)
utils.validateUndername(name)
assert(Records[name] ~= nil, "Record does not exist")

return json.encode(Records[string.lower(name)])
return json.encode(Records[name])
end

function records.getRecords()
Expand Down

0 comments on commit 5870c0e

Please sign in to comment.