Do anyone mind explaining the approve
and allowance
functions in this token smart contract:
export function approve(spender: string, tokens: u64): boolean {
logging.log("approve: " + spender + " tokens: " + tokens.toString());
approves.set(context.sender + ":" + spender, tokens);
return true;
}
and
export function allowance(tokenOwner: string, spender: string): u64 {
const key = tokenOwner + ":" + spender;
if (!approves.contains(key)) {
return 0;
}
return approves.getSome(key);
}
I'm trying to make sense of what them are doing against the blog post I read about the ERC-20's approve
and allowance
functions from Cointelegraph
Not really, because [approve] checks a transaction against the total supply of tokens. It makes sure that there are none missing or extra. Another way to safeguard the integrity of our hypothetical poker game is to make sure no one brought extra BLU to the table. So, [approve] allows the exchange by checking that the total number of BLU on the table equals 10.
Like I said earlier, it won't hurt to include a little documentation in the token smart contract existing in this repo. Please!