Skip to content

Commit

Permalink
updates to match specs
Browse files Browse the repository at this point in the history
  • Loading branch information
vilenarios committed Sep 6, 2024
1 parent 4533807 commit 206e028
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
12 changes: 6 additions & 6 deletions scripts/anp-resolve-01.lua → scripts/arns-core-1.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local json = require("json")
local ao = require('ao')

-- ANP-RESOLVE-01 Constants and Objects
-- ARNS-CORE-1 Constants and Objects
local constants = {}

constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE = "Record does not exist!"
Expand All @@ -18,7 +18,7 @@ if not Records then
}
end

local ANPResolveSpecActionMap = {
local ARNSCoreSpecActionMap = {
-- read actions
Record = "Record",
Records = "Records",
Expand All @@ -42,8 +42,8 @@ function records.getRecords()
return json.encode(Records)
end

-- ANP-Base-01 Handlers
Handlers.add(ANPResolveSpecActionMap.Record, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.Record),
-- ARNS-CORE-1 Handlers
Handlers.add(ARNSCoreSpecActionMap.Record, Handlers.utils.hasMatchingTag("Action", ARNSCoreSpecActionMap.Record),
function(msg)
local nameStatus, nameRes = pcall(records.getRecord, msg.Tags["Sub-Domain"])

Expand Down Expand Up @@ -77,7 +77,7 @@ Handlers.add(ANPResolveSpecActionMap.Record, Handlers.utils.hasMatchingTag("Acti
ao.send(recordNotice)
end)

Handlers.add(ANPResolveSpecActionMap.Records, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.Records),
Handlers.add(ARNSCoreSpecActionMap.Records, Handlers.utils.hasMatchingTag("Action", ARNSCoreSpecActionMap.Records),
function(msg)
local records = records.getRecords()

Expand All @@ -100,7 +100,7 @@ Handlers.add(ANPResolveSpecActionMap.Records, Handlers.utils.hasMatchingTag("Act
ao.send(recordsNotice)
end)

Handlers.add(ANPResolveSpecActionMap.State, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.State),
Handlers.add(ARNSCoreSpecActionMap.State, Handlers.utils.hasMatchingTag("Action", ARNSCoreSpecActionMap.State),
function(msg)
local state = {
Records = Records,
Expand Down
41 changes: 21 additions & 20 deletions scripts/anp-control-01.lua → scripts/arns-manage-1.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local json = require("json")
local ao = require('ao')

-- ANP-RESOLVE-01 Constants and Objects
-- ARNS-CORE-1 Constants and Objects
local constants = {}

constants.UNDERNAME_DOES_NOT_EXIST_MESSAGE = "Record does not exist!"
Expand All @@ -26,7 +26,7 @@ if not Records then
}
end

local ANPResolveSpecActionMap = {
local ARNSCoreSpecActionMap = {
-- read actions
Record = "Record",
Records = "Records",
Expand All @@ -40,7 +40,8 @@ function records.validateUndername(name)
end

function records.validateTTLSeconds(ttl)
local valid = type(ttl) == "number" and ttl >= constants.MIN_TTL_SECONDS and ttl <= constants.MAX_TTL_SECONDS
local valid = type(ttl) == "number" and ttl >= constants.MIN_TTL_SECONDS and ttl <= constants
.MAX_TTL_SECONDS
return assert(valid ~= false, constants.INVALID_TTL_MESSAGE)
end

Expand All @@ -55,13 +56,13 @@ function records.getRecords()
return json.encode(Records)
end

-- ANP-CONTROL-01 Constants and Objects
-- ARNS-MANAGE-1 Constants and Objects
constants.ARWEAVE_ID_REGEXP = "^[a-zA-Z0-9-_]{43}$"
constants.INVALID_ARWEAVE_ID_MESSAGE = "Invalid Arweave ID"

Controllers = Controllers or { Owner }

local ANPControlSpecActionMap = {
local ARNSManageSpecActionMap = {
-- read actions
Controllers = "Controllers",
-- write actions
Expand Down Expand Up @@ -154,8 +155,8 @@ function controllers.getControllers()
return json.encode(Controllers)
end

-- ANP-RESOLVE-01 Handlers
Handlers.add(ANPResolveSpecActionMap.Record, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.Record),
-- ARNS-CORE-1 Handlers
Handlers.add(ARNSCoreSpecActionMap.Record, Handlers.utils.hasMatchingTag("Action", ARNSCoreSpecActionMap.Record),
function(msg)
local nameStatus, nameRes = pcall(records.getRecord, msg.Tags["Sub-Domain"])

Expand Down Expand Up @@ -189,7 +190,7 @@ Handlers.add(ANPResolveSpecActionMap.Record, Handlers.utils.hasMatchingTag("Acti
ao.send(recordNotice)
end)

Handlers.add(ANPResolveSpecActionMap.Records, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.Records),
Handlers.add(ARNSCoreSpecActionMap.Records, Handlers.utils.hasMatchingTag("Action", ARNSCoreSpecActionMap.Records),
function(msg)
local records = records.getRecords()

Expand All @@ -212,7 +213,7 @@ Handlers.add(ANPResolveSpecActionMap.Records, Handlers.utils.hasMatchingTag("Act
ao.send(recordsNotice)
end)

Handlers.add(ANPResolveSpecActionMap.State, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.State),
Handlers.add(ARNSCoreSpecActionMap.State, Handlers.utils.hasMatchingTag("Action", ARNSCoreSpecActionMap.State),
function(msg)
local state = {
Records = Records,
Expand All @@ -238,9 +239,9 @@ Handlers.add(ANPResolveSpecActionMap.State, Handlers.utils.hasMatchingTag("Actio
ao.send(stateNotice)
end)

-- ANP-CONTROL-01 Handlers
Handlers.add(ANPControlSpecActionMap.Controllers,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.Controllers),
-- ARNS-MANAGE-1 Handlers
Handlers.add(ARNSManageSpecActionMap.Controllers,
Handlers.utils.hasMatchingTag("Action", ARNSManageSpecActionMap.Controllers),
function(msg)
local controllersNotice = {
Target = msg.From,
Expand All @@ -260,8 +261,8 @@ Handlers.add(ANPControlSpecActionMap.Controllers,
ao.send(controllersNotice)
end)

Handlers.add(ANPControlSpecActionMap.AddController,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.AddController),
Handlers.add(ARNSManageSpecActionMap.AddController,
Handlers.utils.hasMatchingTag("Action", ARNSManageSpecActionMap.AddController),
function(msg)
local assertHasPermission, permissionErr = pcall(assertHasPermission, msg.From)
if assertHasPermission == false then
Expand Down Expand Up @@ -303,8 +304,8 @@ Handlers.add(ANPControlSpecActionMap.AddController,
ao.send(addControllerNotice)
end)

Handlers.add(ANPControlSpecActionMap.RemoveController,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.RemoveController),
Handlers.add(ARNSManageSpecActionMap.RemoveController,
Handlers.utils.hasMatchingTag("Action", ARNSManageSpecActionMap.RemoveController),
function(msg)
local assertHasPermission, permissionErr = pcall(assertHasPermission, msg.From)
if assertHasPermission == false then
Expand Down Expand Up @@ -346,8 +347,8 @@ Handlers.add(ANPControlSpecActionMap.RemoveController,
ao.send(removeControllerNotice)
end)

Handlers.add(ANPControlSpecActionMap.SetRecord,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.SetRecord),
Handlers.add(ARNSManageSpecActionMap.SetRecord,
Handlers.utils.hasMatchingTag("Action", ARNSManageSpecActionMap.SetRecord),
function(msg)
local assertHasPermission, permissionErr = pcall(assertHasPermission, msg.From)
if assertHasPermission == false then
Expand Down Expand Up @@ -393,8 +394,8 @@ Handlers.add(ANPControlSpecActionMap.SetRecord,
ao.send(setRecordNotice)
end)

Handlers.add(ANPControlSpecActionMap.RemoveRecord,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.RemoveRecord),
Handlers.add(ARNSManageSpecActionMap.RemoveRecord,
Handlers.utils.hasMatchingTag("Action", ARNSManageSpecActionMap.RemoveRecord),
function(msg)
local assertHasPermission, permissionErr = pcall(assertHasPermission, msg.From)
if assertHasPermission == false then
Expand Down

0 comments on commit 206e028

Please sign in to comment.