CURRENTLY IN TESTNET — Should be updated when in mainnet
A transfer mechanism needs to be both secure, efficient, and transparent. Let’s take a closer look at the various process in transfer.lua
which is responsible for transferring.
Target
We identify first the target:
-- transfer target
local target = message.Tags.Recipient or message.Target
Target Address
Check whether it is a valid Arweave address:
-- validate target address
arweave.Address:assert(target)
Validation of Target & Target Address
Conduct simple use of error handling:
-- check if the target and the sender are the same
assert(target ~= message.From, "Target cannot be the sender")
Validation of Token Quantity & User’s Reserve Quantity
The quantity to be transferred should be valid and the user initiating the transfer should have a sufficient balance:
-- validate quantity
arweave.TokenQuantity:assert(quantity)
-- validate if the user has enough tokens
assert(Balances[message.From] ~= nil, "No balance for this user")
assert(Balances[message.From] >= quantity, "Not enought tokens for this transfer")