mirror of https://github.com/embarklabs/embark.git
48 lines
1.1 KiB
Solidity
48 lines
1.1 KiB
Solidity
pragma solidity ^0.5.7;
|
|
|
|
import "../token/ERC20Token.sol";
|
|
|
|
|
|
contract SafeTransfer {
|
|
function _safeTransfer(ERC20Token _token, address _to, uint256 _value) internal returns (bool result) {
|
|
_token.transfer(_to, _value);
|
|
assembly {
|
|
switch returndatasize()
|
|
case 0 {
|
|
result := not(0)
|
|
}
|
|
case 32 {
|
|
returndatacopy(0, 0, 32)
|
|
result := mload(0)
|
|
}
|
|
default {
|
|
revert(0, 0)
|
|
}
|
|
}
|
|
require(result, "Unsuccessful token transfer");
|
|
}
|
|
|
|
function _safeTransferFrom(
|
|
ERC20Token _token,
|
|
address _from,
|
|
address _to,
|
|
uint256 _value
|
|
) internal returns (bool result)
|
|
{
|
|
_token.transferFrom(_from, _to, _value);
|
|
assembly {
|
|
switch returndatasize()
|
|
case 0 {
|
|
result := not(0)
|
|
}
|
|
case 32 {
|
|
returndatacopy(0, 0, 32)
|
|
result := mload(0)
|
|
}
|
|
default {
|
|
revert(0, 0)
|
|
}
|
|
}
|
|
require(result, "Unsuccessful token transfer");
|
|
}
|
|
} |