Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token standard: 0x address and fix token.lua code #941

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lua-examples/ao-standard-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ If there is an insufficient balance, then you will receive a `Transfer-Error` Me
}
```

If the Transfer's Recipient is a 0x address, it must be an [EIP55](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md) standard address, since 0x addresses on ao only support the EIP55 address format.
You can use the methods in the [APM](https://apm.betteridea.dev/pkg?id=6CodALD5aCaSByXrEqw2RcmkFWUQ8B9ZuN6VU-4IJtI) library.
such as:
```lua
local utils = require(".utils")
handlers.add('transfer', ...)
assert(utils.verifyEccAddress(msg.Tags.Recipient) == true, 'Ecc recipient must be EIP55')

```

### Mint

The Process itself can `mint` more `Points Coin`!
Expand Down
11 changes: 6 additions & 5 deletions lua-examples/ao-standard-token/token.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
them the Processes' balance
]] --
local json = require('json')
local ao = require('.ao')

--[[
Initialize State
Expand All @@ -44,15 +45,15 @@ if not Logo then Logo = 'SBCCXwwecBlDqRLUjb8dYABExTJXLieawf7m2aBJ-KY' end
--[[
Info
]] --
handlers.add('info', handlers.utils.hasMatchingTag('Action', 'Info'), function(msg)
Handlers.add('info', Handlers.utils.hasMatchingTag('Action', 'Info'), function(msg)
ao.send(
{ Target = msg.From, Tags = { Name = Name, Ticker = Ticker, Logo = Logo, Denomination = tostring(Denomination) } })
end)

--[[
Balance
]] --
handlers.add('balance', handlers.utils.hasMatchingTag('Action', 'Balance'), function(msg)
Handlers.add('balance', Handlers.utils.hasMatchingTag('Action', 'Balance'), function(msg)
local bal = '0'

-- If not Target is provided, then return the Senders balance
Expand All @@ -71,13 +72,13 @@ end)
--[[
Balances
]] --
handlers.add('balances', handlers.utils.hasMatchingTag('Action', 'Balances'),
Handlers.add('balances', Handlers.utils.hasMatchingTag('Action', 'Balances'),
function(msg) ao.send({ Target = msg.From, Data = json.encode(Balances) }) end)

--[[
Transfer
]] --
handlers.add('transfer', handlers.utils.hasMatchingTag('Action', 'Transfer'), function(msg)
Handlers.add('transfer', Handlers.utils.hasMatchingTag('Action', 'Transfer'), function(msg)
assert(type(msg.Tags.Recipient) == 'string', 'Recipient is required!')
assert(type(msg.Tags.Quantity) == 'string', 'Quantity is required!')

Expand Down Expand Up @@ -119,7 +120,7 @@ end)
--[[
Mint
]] --
handlers.add('mint', handlers.utils.hasMatchingTag('Action', 'Mint'), function(msg, env)
Handlers.add('mint', Handlers.utils.hasMatchingTag('Action', 'Mint'), function(msg, env)
assert(type(msg.Tags.Quantity) == 'string', 'Quantity is required!')

if msg.From == env.Process.Id then
Expand Down