Skip to content

Commit

Permalink
Updated spec names
Browse files Browse the repository at this point in the history
  • Loading branch information
vilenarios committed Aug 6, 2024
1 parent d98c3ee commit e2401a3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 25 deletions.
36 changes: 20 additions & 16 deletions scripts/anp-01.lua → scripts/anp-control-01.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
local json = require("json")
local ao = require('ao')

-- ANP-BASE-01 Constants and Objects
-- ANP-RESOLVE-01 Constants and Objects
local constants = {}


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

local ANPBaseSpecActionMap = {
local ANPResolveSpecActionMap = {
-- read actions
Record = "Record",
Records = "Records",
Expand Down Expand Up @@ -56,13 +55,13 @@ function records.getRecords()
return json.encode(Records)
end

-- ANP-01 Constants and Objects
-- ANP-CONTROL-01 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 ANPSpecActionMap = {
local ANPControlSpecActionMap = {
-- read actions
Controllers = "Controllers",
-- write actions
Expand Down Expand Up @@ -155,8 +154,8 @@ function controllers.getControllers()
return json.encode(Controllers)
end

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

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

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

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

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

-- ANP-01 Handlers
Handlers.add(ANPSpecActionMap.Controllers, Handlers.utils.hasMatchingTag("Action", ANPSpecActionMap.Controllers),
-- ANP-CONTROL-01 Handlers
Handlers.add(ANPControlSpecActionMap.Controllers,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.Controllers),
function(msg)
local controllersNotice = {
Target = msg.From,
Expand All @@ -259,7 +259,8 @@ Handlers.add(ANPSpecActionMap.Controllers, Handlers.utils.hasMatchingTag("Action
ao.send(controllersNotice)
end)

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

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

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

Handlers.add(ANPSpecActionMap.RemoveRecord, Handlers.utils.hasMatchingTag("Action", ANPSpecActionMap.RemoveRecord),
Handlers.add(ANPControlSpecActionMap.RemoveRecord,
Handlers.utils.hasMatchingTag("Action", ANPControlSpecActionMap.RemoveRecord),
function(msg)
local assertHasPermission, permissionErr = pcall(assertHasPermission, msg.From)
if assertHasPermission == false then
Expand All @@ -408,6 +411,7 @@ Handlers.add(ANPSpecActionMap.RemoveRecord, Handlers.utils.hasMatchingTag("Actio
else
local removeRecordNotice = {
Target = msg.From,
Action = 'Remove-Record-Notice',
Data = removeRecordResult
}

Expand Down
10 changes: 5 additions & 5 deletions scripts/anp-base-01.lua → scripts/anp-resolve-01.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local json = require("json")
local ao = require('ao')

-- ANP-BASE-01 Constants and Objects
-- ANP-RESOLVE-01 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 ANPBaseSpecActionMap = {
local ANPResolveSpecActionMap = {
-- read actions
Record = "Record",
Records = "Records",
Expand All @@ -43,7 +43,7 @@ function records.getRecords()
end

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

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

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

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

Handlers.add(ANPBaseSpecActionMap.State, Handlers.utils.hasMatchingTag("Action", ANPBaseSpecActionMap.State),
Handlers.add(ANPResolveSpecActionMap.State, Handlers.utils.hasMatchingTag("Action", ANPResolveSpecActionMap.State),
function(msg)
local state = {
Records = Records,
Expand Down
109 changes: 105 additions & 4 deletions scripts/ant-base.lua → scripts/anp.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
local json = require("json")
local bint = require('.bint')(256)
local ao = require('ao')

-- Update the below as needed
Name = Name or "ANT-Base"
Ticker = Ticker or "ANT-Base"
Denomination = Denomination or 1
Name = Name or "ANT-Base-Spec"
Ticker = Ticker or "ANT-Base-Spec"
Denomination = Denomination or 0
TotalSupply = TotalSupply or 1
Logo = Logo or "Sie_26dvgyok0PZD_-iQAFOhOd5YxDTkczOLoqTTL_A"

-- Setup balances as needed
Owner = Owner or ao.env.Process.Owner
Balances = Balances or { [Owner] = 1 }

-- Setup the default record pointing to the ArNS landing page
if not Records then
Records = {}
Expand All @@ -15,11 +22,41 @@ if not Records then
}
end

-- Set empty controllers
-- Set empty controllers if needed
if not Controllers then
Controllers = {}
end

local ANTSpecActionMap = {
-- write
AddController = "Add-Controller",
RemoveController = "Remove-Controller",
SetRecord = "Set-Record",
RemoveRecord = "Remove-Record",
SetName = "Set-Name",
SetTicker = "Set-Ticker",
--- initialization method for bootstrapping the contract from other platforms ---
InitializeState = "Initialize-State",
-- read
Controllers = "Controllers",
Record = "Record",
Records = "Records",
State = "State",
Evolve = "Evolve",
}

local TokenSpecActionMap = {
Info = "Info",
Balances = "Balances",
Balance = "Balance",
Transfer = "Transfer",
TotalSupply = "Total-Supply",
CreditNotice = "Credit-Notice",
-- not implemented
Mint = "Mint",
Burn = "Burn",
}

-- Custom validateSetRecord function in Lua
function validateSetRecord(msg)
-- Check for required fields
Expand Down Expand Up @@ -100,6 +137,70 @@ function validArweaveId(inputString)
return string.match(inputString, pattern) ~= nil
end

-- caller must own the process or be the process itself
function validateOwner(caller)
local isOwner = false
if Owner == caller or ao.env.Process.Id == caller then
isOwner = true
end
assert(isOwner, "Sender is not the owner.")
end

Handlers.add(
TokenSpecActionMap.Transfer,
Handlers.utils.hasMatchingTag("Action", TokenSpecActionMap.Transfer),
function(msg)
local recipient = msg.Tags.Recipient
local function checkAssertions()
validArweaveId(recipient)
validateOwner(msg.From)
end

local inputStatus, inputResult = pcall(checkAssertions)

if not inputStatus then
ao.send({
Target = msg.From,
Tags = { Action = "Invalid-Transfer-Notice", Error = "Transfer-Error" },
Data = tostring(inputResult),
["Message-Id"] = msg.Id,
})
return
end
local transferStatus, transferResult = pcall(balances.transfer, recipient)

if not transferStatus then
ao.send({
Target = msg.From,
Tags = { Action = "Invalid-Transfer-Notice", Error = "Transfer-Error" },
["Message-Id"] = msg.Id,
Data = tostring(transferResult),
})
return
elseif not msg.Cast then
ao.send(utils.notices.debit(msg))
ao.send(utils.notices.credit(msg))
return
end
ao.send({
Target = msg.From,
Data = transferResult,
})
end
)













Handlers.add("info", Handlers.utils.hasMatchingTag("Action", "Info"), function(msg, env)
local info = {
name = Name,
Expand Down

0 comments on commit e2401a3

Please # to comment.