I have a problem
I have two contracts at the moment
One contract is an AEX9 token contract
A contract is a contract that I write my own logic
The requirement is that the user replaces the AEX 9 token with AE, or can replace the AEX 9 token with AE
Now I realize that the AEX9 token can be replaced by AE, but when I change back to AE from the AEX9 token, I find there will be problems, because what the user calls is the contract for writing logic, and the contract for writing logic calls the CONTRACT for AEX9. In this way, the default transfer is to operate the AEX9 token in the contract instead of the user’s token.
contract FungibleTokenInterface =
record meta_info =
{ name : string
, symbol : string
, decimals : int }
datatype event =
Transfer(address, address, int)
entrypoint aex9_extensions : () => list(string)
entrypoint meta_info : () => meta_info
entrypoint total_supply : () => int
entrypoint owner : () => address
entrypoint balances : () => map(address, int)
entrypoint balance : (address) => option(int)
entrypoint transfer : (address, int) => unit
payable contract BoxContract =
record state = {
token_address : address,
map_hamsters : map(string, string),
testvalue: int}
stateful entrypoint init(token : FungibleTokenInterface) = {
token_address = token.address,
map_hamsters = {},
testvalue = 42 }
entrypoint getTokenBalance(token : FungibleTokenInterface) =
token.balance(Call.caller)
entrypoint getCallCaller() =
Call.caller
entrypoint getContractBalance() =
Contract.balance
entrypoint getContractAddress() =
Contract.address
payable stateful entrypoint buy(token : FungibleTokenInterface) =
Chain.spend(Contract.address, Call.value)
token.transfer(Call.caller , Call.value)
stateful entrypoint sell(token : FungibleTokenInterface , number : int) =
switch(token.balance(Call.caller))
Some(balance) =>
require(balance > number, "BOX_INSUFFICIENT_BALANCE")
None => abort("BALANCE_ACCOUNT_NOT_EXISTENT")
//The problem code is here, I want to deduct the user AEX9 token
token.transfer(Contract.address , number)
Chain.spend(Call.caller, number)
entrypoint getBalances(token : FungibleTokenInterface) =
token.balances()