When using contract calls with an ERC-20 token things get messy. Let me explain:
There are 3 scenarios for token transfers:
1.- User A sends tokens to User B
2.- An ICO contract sends tokens to a buyer
3.- An asset contract sends buyer's tokens to an asset seller
By using the ERC-20 token transfer() method cases 1 and 2 are covered.
function transfer(address _to, uint256 _amount) public returns (bool success) {
...
balances[msg.sender] -= _amount;
balances[_to] += _amount;
...
}
Being msg.sender, User A (case #1) and ICO contract (case #2) the tokens are transferred successfully.
But transfer() method cannot solve case #3, because msg.sender is not the user (having tokens) that sends the transaction, but the asset contract (having no tokens) acting as middle-man.
This third case requires the use of tx.origin instead of msg.sender, so the tokens would came from the user that originates the transaction.
Any idea how to solve the 3 cases preserving the ERC-20 transfer method as unique? Thx!
Refs.: