Hi community,
I deployed this contract:
pragma solidity ^0.5.5;
import "../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol";
contract TokenExchange {
using SafeMath for uint256;
address private _owner;
// Contract constructor: set owner
constructor() public {
_owner = msg.sender;
}
// Access control modifier
modifier ownerOnly {
require(msg.sender == _owner,
"Only the contract owner can call this function");
_;
}
function swapTokens(
address sourceTokenCA,
address sourceEOA,
uint256 sourceTokenValue,
uint sourceTokenType,
address targetTokenCA,
address targetEOA,
uint256 targetTokenValue,
uint targetTokenType,
address exchangeCA
) public ownerOnly returns (bool) {
bool success = false;
if (_transferFrom(sourceTokenCA, sourceEOA, exchangeCA, sourceTokenValue, sourceTokenType) &&
_transferFrom(targetTokenCA, targetEOA, exchangeCA, targetTokenValue, targetTokenType) &&
_transfer(sourceTokenCA, targetEOA, sourceTokenValue, sourceTokenType) &&
_transfer(targetTokenCA, sourceEOA, targetTokenValue, targetTokenType)
) {
success = true;
}
return success;
}
function _transferFrom(
address tokenCA,
address EOA,
address exchangeCA,
uint256 value,
uint tokenType
) internal returns (bool) {
bool rtnVal = false;
if(tokenType == 20 || tokenType == 721) {
(bool success, bytes memory result) = address(tokenCA).call(
abi.encodeWithSignature("transferFrom(address,address,uint256)", EOA, exchangeCA, value)
);
rtnVal = success;
}
if(!rtnVal) {
revert();
}
return rtnVal;
}
function _transfer(
address tokenCA,
address EOA,
uint256 value,
uint tokenType
) internal returns (bool) {
bool rtnVal = false;
if(tokenType == 20 || tokenType == 721) {
(bool success, bytes memory result) = address(tokenCA).call(
abi.encodeWithSignature("transfer(address,uint256)", EOA, value)
);
rtnVal = success;
}
if(!rtnVal) {
revert();
}
return rtnVal;
}
}
Deployment goes fine, I use remix on a Quorum private blockchain.
The issue after, when trying to interact with this contract:
- If try to execute a transaction on this contract, for instance calling swapTokens() function to start swapping erc20 tokens…I get this error:
status false Transaction mined but execution failed transaction hash 0x7356c4820605b0c15f13525028c5a27b9c1bac56657db7dff18ee2aebbc0f837 from 0x079d713C8490e468Cc2680D7430e301782d597e8 to TokenExchange.swapTokens(address,address,uint256,uint256,address,address,uint256,uint256,address) 0x0B052dE6ce9066e19826383cdEEeDE4788f3c3E6 gas 3000000 gas transaction cost 3000000 gas hash 0x7356c4820605b0c15f13525028c5a27b9c1bac56657db7dff18ee2aebbc0f837 input 0x90a...3c3e6 decoded input { "address sourceTokenCA": "0x804B4D280C0b34d2CD110af154De289F14ba1B02", "address sourceEOA": "0x079d713C8490e468Cc2680D7430e301782d597e8", "uint256 sourceTokenValue": { "_hex": "0x01" }, "uint256 sourceTokenType": { "_hex": "0x14" }, "address targetTokenCA": "0xC81D113776ecbfd52c7c9de46c6ee848637DE99D", "address targetEOA": "0xcc83Fd1b198EBc44D947608283Dd3834fC746a87", "uint256 targetTokenValue": { "_hex": "0x02" }, "uint256 targetTokenType": { "_hex": "0x14" }, "address exchangeCA": "0x0B052dE6ce9066e19826383cdEEeDE4788f3c3E6" } decoded output - logs [] value 0 wei