-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from ar-io/PE-6979-set-logo-api
fix(PE-6979): set logo api
- Loading branch information
Showing
10 changed files
with
315 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,89 @@ | ||
--- Module for managing balances and transactions. | ||
-- @module balances | ||
|
||
local utils = require(".common.utils") | ||
local json = require(".common.json") | ||
|
||
local balances = {} | ||
|
||
--- Checks if a wallet has sufficient balance. | ||
---@param wallet string - The wallet address to check. | ||
---@return boolean - Returns true if the wallet has a balance greater than 0, otherwise false. | ||
function balances.walletHasSufficientBalance(wallet) | ||
return Balances[wallet] ~= nil and Balances[wallet] > 0 | ||
end | ||
|
||
--- Transfers the ANT to a specified wallet. | ||
---@param to string - The wallet address to transfer the balance to. | ||
---@return string - Returns the encoded JSON representation of the transferred balance. | ||
function balances.transfer(to) | ||
utils.validateArweaveId(to) | ||
Balances = { [to] = 1 } | ||
--luacheck: ignore Owner Controllers | ||
Owner = to | ||
Controllers = {} | ||
return json.encode({ [to] = 1 }) | ||
end | ||
|
||
--- Retrieves the balance of a specified wallet. | ||
---@param address string - The wallet address to retrieve the balance from. | ||
---@return number - Returns the balance of the specified wallet. | ||
function balances.balance(address) | ||
utils.validateArweaveId(address) | ||
local balance = Balances[address] or 0 | ||
return balance | ||
end | ||
|
||
--- Retrieves all balances. | ||
---@return string - Returns the encoded JSON representation of all balances. | ||
function balances.balances() | ||
return json.encode(Balances) | ||
end | ||
|
||
--- Sets the name of the ANT. | ||
---@param name string - The name to set. | ||
---@return string - Returns the encoded JSON representation of the updated name. | ||
function balances.setName(name) | ||
assert(type(name) == "string", "Name must be a string") | ||
Name = name | ||
return json.encode({ name = Name }) | ||
end | ||
|
||
--- Sets the ticker of the ANT. | ||
---@param ticker string - The ticker to set. | ||
---@return string - Returns the encoded JSON representation of the updated ticker. | ||
function balances.setTicker(ticker) | ||
assert(type(ticker) == "string", "Ticker must be a string") | ||
Ticker = ticker | ||
return json.encode({ ticker = Ticker }) | ||
end | ||
|
||
--- Sets the description of the ANT. | ||
---@param description string - The description to set. | ||
---@return string - Returns the encoded JSON representation of the updated description. | ||
function balances.setDescription(description) | ||
assert(type(description) == "string", "Description must be a string") | ||
assert(#description <= 512, "Description must not be longer than 512 characters") | ||
Description = description | ||
return json.encode({ description = Description }) | ||
end | ||
|
||
--- Sets the keywords of the ANT. | ||
---@param keywords table - The keywords to set. | ||
---@return string - Returns the encoded JSON representation of the updated keywords. | ||
function balances.setKeywords(keywords) | ||
utils.validateKeywords(keywords) | ||
|
||
Keywords = keywords | ||
return json.encode({ keywords = Keywords }) | ||
end | ||
|
||
--- Sets the logo of the ANT. | ||
---@param logo string - The Arweave transaction ID that represents the logo. | ||
---@return string - Returns the encoded JSON representation of the updated logo. | ||
function balances.setLogo(logo) | ||
Logo = logo | ||
return json.encode({ logo = Logo }) | ||
end | ||
|
||
return balances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
-- need to specify this as a module so it can be imported | ||
---@alias AoMessage { | ||
--- Id: string, | ||
--- From: string, | ||
--- Target: string, | ||
--- Tags: table<string, string | number>, | ||
--- Owner: string, | ||
--- Data: string | number | nil, | ||
--- [string]: string | number, | ||
---} | ||
|
||
---@alias Handler { | ||
--- name: string, | ||
--- pattern: function|table<string, string|nil>, | ||
--- handle: function, | ||
---} | ||
---@alias HandlersList table<string, Handler> | ||
|
||
---@alias Handlers { | ||
--- list: HandlersList, | ||
--- add: function, | ||
--- before: function, | ||
--- after: function, | ||
--- remove: function, | ||
--- prepend: function, | ||
--- append: function, | ||
--- evaluate: function, | ||
---} | ||
|
||
---@alias Record { | ||
--- transactionId: string, | ||
--- ttlSeconds: integer, | ||
---} | ||
|
||
---@alias AntState { | ||
--- Name: string, | ||
--- Ticker: string, | ||
--- Description: string, | ||
--- Keywords: string, | ||
--- Logo: string, | ||
--- Balances: table<string, integer>, | ||
--- Owner: string, | ||
--- Controllers: table<string>, | ||
--- Denomination: integer, | ||
--- TotalSupply: integer, | ||
--- Initialized: boolean, | ||
--- ["Source-Code-TX-ID"|SourceCodeTxId]: string, | ||
--- Records: table<string, Record>, | ||
---} |
Oops, something went wrong.