From e2401a349bca8862db1802bf7d9a39ef18bee517 Mon Sep 17 00:00:00 2001 From: vilenarios Date: Tue, 6 Aug 2024 15:15:30 -0400 Subject: [PATCH] Updated spec names --- scripts/{anp-01.lua => anp-control-01.lua} | 36 +++--- .../{anp-base-01.lua => anp-resolve-01.lua} | 10 +- scripts/{ant-base.lua => anp.lua} | 109 +++++++++++++++++- 3 files changed, 130 insertions(+), 25 deletions(-) rename scripts/{anp-01.lua => anp-control-01.lua} (89%) rename scripts/{anp-base-01.lua => anp-resolve-01.lua} (86%) rename scripts/{ant-base.lua => anp.lua} (78%) diff --git a/scripts/anp-01.lua b/scripts/anp-control-01.lua similarity index 89% rename from scripts/anp-01.lua rename to scripts/anp-control-01.lua index cf7aa3fc..df8bf09c 100644 --- a/scripts/anp-01.lua +++ b/scripts/anp-control-01.lua @@ -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 @@ -27,7 +26,7 @@ if not Records then } end -local ANPBaseSpecActionMap = { +local ANPResolveSpecActionMap = { -- read actions Record = "Record", Records = "Records", @@ -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 @@ -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"]) @@ -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() @@ -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, @@ -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, @@ -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 @@ -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 @@ -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 @@ -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 @@ -408,6 +411,7 @@ Handlers.add(ANPSpecActionMap.RemoveRecord, Handlers.utils.hasMatchingTag("Actio else local removeRecordNotice = { Target = msg.From, + Action = 'Remove-Record-Notice', Data = removeRecordResult } diff --git a/scripts/anp-base-01.lua b/scripts/anp-resolve-01.lua similarity index 86% rename from scripts/anp-base-01.lua rename to scripts/anp-resolve-01.lua index 92979be2..3849fa5d 100644 --- a/scripts/anp-base-01.lua +++ b/scripts/anp-resolve-01.lua @@ -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!" @@ -18,7 +18,7 @@ if not Records then } end -local ANPBaseSpecActionMap = { +local ANPResolveSpecActionMap = { -- read actions Record = "Record", Records = "Records", @@ -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"]) @@ -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() @@ -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, diff --git a/scripts/ant-base.lua b/scripts/anp.lua similarity index 78% rename from scripts/ant-base.lua rename to scripts/anp.lua index 6ff0abf3..039e2f4b 100644 --- a/scripts/ant-base.lua +++ b/scripts/anp.lua @@ -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 = {} @@ -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 @@ -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,