Installed: eosio: 1.7.3; eosio.cdt: 1.6.1
Implemented and locally deployed: sample market
contract and eosio.token
contract. In order to make an inline transfer from market
contract in behalf of a user, I am using the following logic:
transfer_tokens(buyer, seller, asset(tokensToTransfer, symbol("ABC", 4)), "transfer tokens to seller");
void market::transfer_tokens(name from, name to, asset quantity, string memo)
{
token::transfer_action transfer("eosio.token"_n, {from, "active"_n});
transfer.send(from, to, quantity, memo);
}
This way market
contract will spend buyer's tokens, since it has been already authorized to do that.
Accounts/Permissions configuration:
buyer
"account_name": "buyer",
"permissions": [{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "buyer public key",
"weight": 1
}
],
"accounts": [{
"permission": {
"actor": "market",
"permission": "eosio.code"
},
"weight": 1
}
],
"waits": []
}
}
market
"account_name": "market",
"permissions": [{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "market public key",
"weight": 1
}
],
"accounts": [{
"permission": {
"actor": "market",
"permission": "eosio.code"
},
"weight": 1
}
],
"waits": []
}
}
eosio.token
"account_name": "eosio.token",
"permissions": [{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "eosio.token public key",
"weight": 1
}
],
"accounts": [{
"permission": {
"actor": "eosio.token",
"permission": "eosio.code"
},
"weight": 1
}
],
"waits": []
}
}