Skip to content

Commit

Permalink
Merge pull request #32 from ar-io/PE-7013-remove-record-fixes
Browse files Browse the repository at this point in the history
fix(PE-7013): "Remove-Record" API fixes by way of codification of patterns
  • Loading branch information
atticusofsparta authored Nov 13, 2024
2 parents 410163a + b5fb446 commit 2377eab
Show file tree
Hide file tree
Showing 21 changed files with 993 additions and 789 deletions.
11 changes: 5 additions & 6 deletions .busted
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
print("Loading .busted configuration...")

return {
_all = {
default = {
root = "src",
pattern = "**/*_spec.lua$",
helper = "spec/setup.lua",
verbose = true,
coverage = true,
output = "utfTerminal",
jobs = 4,
},
default = {
ROOT = {"ant"},
pattern = "**/*_spec.lua$",
helper = "spec/setup.lua",
}
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ node_modules
wallet.json
.DS_Store
luacov-html
.luacov
*.gz
luacov.stats.out
process.wasm
dist
publish-output.json
publish-output.json
luarocks-3.9.1
15 changes: 15 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@ exclude_files = {
globals = {
"Handlers",
"ao",
"Owner",
"Balances",
"Records",
"Controllers",
"Name",
"Ticker",
"TotalSupply",
"Logo",
"Description",
"Keywords",
"Denomination",
"SourceCodeTxId",
"Initialized"


}
max_line_length = 185
5 changes: 5 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
statsfile = 'coverage/luacov.stats.out';
reportfile = 'coverage/luacov.report.out';
deleteStatsFile = false;
include = { "src/" }
exclude = { "crypto", "json", "base64", "ao" }
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Allows for setting the description of the ANT
- Set-Keywords Handler
- Allows for setting keywords on the ANT
- Set-Logo Handler
- Allows for setting the logo of the ANT

### Changed

- Refactored handlers to use a util that codifies responses on calls.
- Added documentation with luadoc types for improved linting.
- Records are now returned as an alphabetically sorted array of [{name, transactionId, ttlSeconds}] with the '@' record being the first.

### Fixed

- Fixed the Remove-Record api to return appropriate notices on calls.

<!-- eslint-disable-next-line -->

Expand Down
163 changes: 114 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,50 @@ This repository contains the source code used for Arweave Name Tokens used to re

This repository provides two flavours of ANT process module, AOS and a custom module.

<!-- toc -->

- [Setup](#setup)
- [Install](#install)
- [Testing](#testing)
- [Building the AOS code](#building-the-aos-code)
- [Build](#build)
- [Publish](#publish)
- [Load](#load)
- [Spawn](#spawn)
- [Handler Methods](#handler-methods)
- [Read Methods](#read-methods)
- [`Info`](#info)
- [`Total-Supply`](#total-supply)
- [`State`](#state)
- [`Records`](#records)
- [`Record`](#record)
- [`Controllers`](#controllers)
- [`Balance`](#balance)
- [`Balances`](#balances)
- [Write methods](#write-methods)
- [`Transfer`](#transfer)
- [`Set-Record`](#set-record)
- [`Set-Name`](#set-name)
- [`Set-Ticker`](#set-ticker)
- [`Set-Description`](#set-description)
- [`Set-Logo`](#set-logo)
- [`Set-Keywords`](#set-keywords)
- [`Add-Controller`](#add-controller)
- [`Remove-Controller`](#remove-controller)
- [`Remove-Record`](#remove-record)
- [`Release-Name`](#release-name)
- [`Reassign-Name`](#reassign-name)
- [Developers](#developers)
- [Requirements](#requirements)
- [Lua Setup (MacOS)](#lua-setup-macos)
- [LuaRocks Setup](#luarocks-setup)
- [aos](#aos)
- [Code Formatting](#code-formatting)
- [Testing](#testing-1)
- [Dependencies](#dependencies)

<!-- tocstop -->

## Setup

### Install
Expand Down Expand Up @@ -67,82 +111,74 @@ yarn aos:spawn

This will deploy the bundled lua file to arweave as an L1 transaction, so your wallet will need AR to pay the gas.

### Building the custom module

Using the ao-dev-cli.

#### Build

This will compile the standalone ANT module to wasm, as a file named `process.wasm` and loads the module in [AO Loader](https://github.com/permaweb/ao/tree/main/loader) to validate the WASM program is valid.

```bash
yarn module:build
```

#### Publish

Publishes the custom ANT module to arweave - requires you placed your JWK in the `tools` directory. May require AR in the wallet to pay gas.

```sh
yarn module:publish
```

#### Load
## Handler Methods

Loads the module in [AO Loader](https://github.com/permaweb/ao/tree/main/loader) to validate the WASM program is valid.
For interacting with handlers please refer to the [AO Cookbook]

```bash
yarn module:load
```
### Read Methods

Requires `module:build` to have been called so that `process.wasm` exists.
#### `Info`

#### Spawn
Retrieves the Name, Ticker, Total supply, Logo, Denomination, and Owner of the ANT.

Spawns a process with the `process.wasm` file.
| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ------- | -------- | --------------------------------- |
| Action | string | "Info" | true | Action tag for triggering handler |

```bash
yarn module:spawn
```
#### `Total-Supply`

## Handler Methods
Retrieves total supply of the ANT.

For interacting with handlers please refer to the [AO Cookbook]
| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | -------------- | -------- | --------------------------------- |
| Action | string | "Total-Supply" | true | Action tag for triggering handler |

### Read Methods
#### `State`

#### `Info`
Retrieves the entire state of the ANT, which includes:

Retrieves the Name, Ticker, Total supply, Logo, Denomination, and Owner of the ANT.
- Records
- Controllers
- Balances
- Owner
- Name
- Ticker
- Logo
- Description
- Keywords
- Denomination
- TotalSupply
- Initialized
- Source-Code-TX-ID

| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ------- | -------- | --------------------------------- |
| Action | string | "Info" | true | Action tag for triggering handler |
| Action | string | "State" | true | Action tag for triggering handler |

#### `Get-Records`
#### `Records`

Retrieves all the records configured on the ANT

| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ------------- | -------- | --------------------------------- |
| Action | string | "Get-Records" | true | Action tag for triggering handler |
| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | --------- | -------- | --------------------------------- |
| Action | string | "Records" | true | Action tag for triggering handler |

#### `Get-Record`
#### `Record`

Retrieves and individual record by name.

| Tag Name | Type | Pattern | Required | Description |
| ---------- | ------ | ------------------------- | -------- | --------------------------------- |
| Action | string | "Get-Record" | true | Action tag for triggering handler |
| Action | string | "Record" | true | Action tag for triggering handler |
| Sub-Domain | string | "^(?:[a-zA-Z0-9_-]+\|@)$" | true | Subdomain you which to read |

#### `Get-Controllers`
#### `Controllers`

Retrieves all the controllers on the ANT.

| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ----------------- | -------- | --------------------------------- |
| Action | string | "Get-Controllers" | true | Action tag for triggering handler |
| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ------------- | -------- | --------------------------------- |
| Action | string | "Controllers" | true | Action tag for triggering handler |

#### `Balance`

Expand Down Expand Up @@ -210,6 +246,15 @@ Sets the description for the ANT.
| Action | string | "Set-Description" | true | Action tag for triggering handler |
| Description | string | Max 512 characters | true | New description for ANT. |

#### `Set-Logo`

Sets the logo for the ANT.

| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | --------------------- | -------- | --------------------------------- |
| Action | string | "Set-Logo" | true | Action tag for triggering handler |
| Logo | string | "^[a-zA-Z0-9_-]{43}$" | true | ID of new logo for ANT. |

#### `Set-Keywords`

Sets the keywords for the ANT.
Expand All @@ -219,13 +264,13 @@ Sets the keywords for the ANT.
| Action | string | "Set-Keywords" | true | Action tag for triggering handler |
| Keywords | table | "^[%w-_#@]+$", max 32 characters, max 16 keywords, min 1 keyword | true | New keywords for ANT. |

#### `Set-Controller`
#### `Add-Controller`

Adds a new controller to the ANT.

| Tag Name | Type | Pattern | Required | Description |
| ---------- | ------ | --------------------- | -------- | --------------------------------- |
| Action | string | "Set-Controller" | true | Action tag for triggering handler |
| Action | string | "Add-Controller" | true | Action tag for triggering handler |
| Controller | string | "^[a-zA-Z0-9_-]{43}$" | true | Address of the new controller. |

#### `Remove-Controller`
Expand All @@ -246,6 +291,26 @@ Removes a record from the ANT.
| Action | string | "Remove-Record" | true | Action tag for triggering handler |
| Sub-Domain | string | "^(?:[a-zA-Z0-9_-]+\|@)$" | true | Subdomain of the record to remove. |

#### `Release-Name`

Calls the IO Network process to release the given ArNS name if that name is associated with the ANT.

| Tag Name | Type | Pattern | Required | Description |
| -------- | ------ | ------------------- | -------- | --------------------------------- |
| Action | string | "Release-Name" | true | Action tag for triggering handler |
| Name | string | "^([a-zA-Z0-9_-])$" | true | ArNS name to release |

#### `Reassign-Name`

Calls the IO Network process to reassign the given ArNS name to a new ANT ID if that name is associated with the ANT.

| Tag Name | Type | Pattern | Required | Description |
| ------------- | ------ | --------------------- | -------- | ---------------------------------------------------- |
| Action | string | "Reassign-Name" | true | Action tag for triggering handler |
| IO-Process-Id | string | "^[a-zA-Z0-9_-]{43}$" | true | ID of the IO Network Process to reassign the name on |
| Process-Id | string | "^[a-zA-Z0-9_-]{43}$" | true | ID of the new ANT to assign to the ArNS name |
| Name | string | "^([a-zA-Z0-9_-])$" | true | Subdomain of the record to remove. |

## Developers

### Requirements
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"arweave": "^1.15.1",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"markdown-toc-gen": "^1.1.0",
"prettier": "^3.3.2"
},
"lint-staged": {
Expand All @@ -29,6 +30,9 @@
],
"*.{js,mjs}": [
"prettier --write"
],
"**/README.md": [
"markdown-toc-gen insert"
]
}
}
28 changes: 28 additions & 0 deletions spec/ant_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("Arweave Name Token", function()
_G.Description = "ANT's description"
_G.Keywords = { "KEYWORD-1", "KEYWORD-2", "KEYWORD-3" }
_G.Denomination = 1
_G.Logo = ""
end)

it("Initializes the state of the process", function()
Expand Down Expand Up @@ -82,6 +83,21 @@ describe("Arweave Name Token", function()
assert.are.same(_G.Records["@"].ttlSeconds, 900)
end)

it("gets all records", function()
_G.Records["zed"] = {
transactionId = string.rep("1", 43),
ttlSeconds = 3600,
}
_G.Records["@"] = {
transactionId = string.rep("1", 43),
ttlSeconds = 3600,
}
local recordEntries = records.getRecords()

assert.are.same(recordEntries[1].name, "@")
assert.are.same(recordEntries[#recordEntries].name, "zed")
end)

it("removes a record", function()
local name = "@"
records.removeRecord(name) -- happy path
Expand Down Expand Up @@ -167,4 +183,16 @@ describe("Arweave Name Token", function()
balances.setKeywords(notAnArray)
end, "Keywords must be an array")
end)

it("should set the logo", function()
local logo = string.rep("1", 43)
balances.setLogo(logo)
assert.are.same(logo, _G.Logo)
end)
it("should not set the logo with invalid id", function()
local logo = string.rep("1", 42)
assert.has_error(function()
balances.setLogo(logo)
end)
end)
end)
Loading

0 comments on commit 2377eab

Please sign in to comment.