The ABI is for external calls only therefore you cannot define a method in the ABI and call it in the same contract. If you want to define a function for a contract, but keep it private so that only your contract can call it, you can define it outside of the impl
and call it inside the contract, similar to the return_45()
function above.
If functions outside of the implementation block are private. What’s the point of having a public function that is outside of ABI block?
#[storage(read, write)]
pub fn _mint(recipient: Identity, amount: u64) {
use std::asset::mint_to;
let supply = storage.total_supply.read();
storage.total_supply.write(supply + amount);
mint_to(recipient, PRE_CALCULATED_SHARE_VAULT_SUB_ID, amount);
}
#[storage(read, write)]
pub fn _burn(asset_id: AssetId, amount: u64) {
use std::{asset::burn, context::this_balance};
require(
this_balance(asset_id) >= amount,
"BurnError::NotEnoughCoins",
);
// If we pass the check above, we can assume it is safe to unwrap.
let supply = storage.total_supply.read();
storage.total_supply.write(supply - amount);
burn(PRE_CALCULATED_SHARE_VAULT_SUB_ID, amount);
}