Skip to content

Commit

Permalink
chore(ant): add error tags in token spec format
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Jun 13, 2024
1 parent e3d2843 commit 5b0209a
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 264 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [],
"semi": true,
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion ant/spec/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- spec/utils_spec.lua
local utils = require("src.ant-utils")
local utils = require("src.utils")

describe("utils.camelCase", function()
it("should convert snake_case to camelCase", function()
Expand Down
105 changes: 0 additions & 105 deletions ant/src/ant-utils.lua

This file was deleted.

12 changes: 2 additions & 10 deletions ant/src/balances.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local utils = require(".ant-utils")
local utils = require(".utils")
local json = require(".json")

Balances = Balances or {}

local balances = {}

function balances.walletHasSufficientBalance(wallet)
Expand Down Expand Up @@ -31,13 +29,7 @@ end
function balances.balance(address)
utils.validateArweaveId(address)
local balance = Balances[address] or 0
return {
Target = address,
Balance = balance,
Ticker = Ticker,
Account = address,
Data = balance,
}
return balance
end

function balances.balances()
Expand Down
4 changes: 1 addition & 3 deletions ant/src/controllers.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
local json = require(".json")
local utils = require(".ant-utils")

Controllers = Controllers or { Owner }
local utils = require(".utils")

local controllers = {}

Expand Down
37 changes: 19 additions & 18 deletions ant/src/initialize.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
local utils = require(".ant-utils")
local utils = require(".utils")
local json = require("json")
local initialize = {}

function initialize.initializeANTState(state)
local name, ticker, balances, controllers, records =
state.name, state.ticker, state.balances, state.controllers, state.records

local encoded = json.decode(state)
local balances = encoded.balances
local controllers = encoded.controllers
local records = encoded.records
local name = encoded.name
local ticker = encoded.ticker
assert(type(name) == "string", "name must be a string")
assert(type(ticker) == "string", "ticker must be a string")
assert(type(balances) == "table", "balances must be a table")
for k, v in pairs(balances) do
local idValidity, idRes = pcall(utils.validateArweaveId, k)
assert(idValidity ~= false, idRes)
assert(type(v) == "number", "balances values must be numbers")
balances[k] = tonumber(v)
end
assert(type(controllers) == "table", "controllers must be a table")
for _, v in ipairs(controllers) do
local controllerValidity, _ = pcall(utils.validateArweaveId, v)
assert(controllerValidity ~= false, "controllers must be a list of arweave id's")
end
assert(type(records) == "table", "records must be a table")
for k, v in pairs(records) do
local nameValidity, _ = pcall(utils.validateUndername, k)
assert(nameValidity ~= false, "records keys must be strings")
utils.validateUndername(k)
assert(type(v) == "table", "records values must be tables")
local idValidity, _ = pcall(utils.validateArweaveId, k)
assert(idValidity ~= false, "records transactionId must be a string")
local ttlValidity, _ = pcall(utils.validateTTLSeconds, v.ttlSeconds)
assert(ttlValidity ~= false, "Invalid ttlSeconds on records")
utils.validateArweaveId(v.transactionId)
utils.validateTTLSeconds(v.ttlSeconds)
end

Name = name
Expand All @@ -36,7 +31,13 @@ function initialize.initializeANTState(state)
Records = records
Initialized = true

return "State initialized"
return {
name = Name,
ticker = Ticker,
balances = Balances,
controllers = Controllers,
records = Records,
}
end

local function findObject(array, key, value)
Expand Down
Loading

0 comments on commit 5b0209a

Please sign in to comment.