@@ -911,11 +911,10 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
911
911
* @param _to address The address which you want to transfer to
912
912
* @param _value uint256 the amount of tokens to be transferred
913
913
* @param _data The `bytes _data` allows arbitrary data to be submitted alongside the transfer.
914
- * @return bool It signifies whether the transaction will be executed or not.
915
914
* @return byte Ethereum status code (ESC)
916
915
* @return bytes32 Application specific reason code
917
916
*/
918
- function canTransfer (address _to , uint256 _value , bytes calldata _data ) external view returns (bool , byte , bytes32 ) {
917
+ function canTransfer (address _to , uint256 _value , bytes calldata _data ) external view returns (byte , bytes32 ) {
919
918
return _canTransfer (msg .sender , _to, _value, _data);
920
919
}
921
920
@@ -927,22 +926,21 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
927
926
* @param _to address The address which you want to transfer to
928
927
* @param _value uint256 the amount of tokens to be transferred
929
928
* @param _data The `bytes _data` allows arbitrary data to be submitted alongside the transfer.
930
- * @return bool It signifies whether the transaction will be executed or not.
931
929
* @return byte Ethereum status code (ESC)
932
930
* @return bytes32 Application specific reason code
933
931
*/
934
- function canTransferFrom (address _from , address _to , uint256 _value , bytes calldata _data ) external view returns (bool success , byte reasonCode , bytes32 appCode ) {
935
- (success, reasonCode, appCode) = _canTransfer (_from, _to, _value, _data);
936
- if (success && _value > allowance (_from, msg .sender )) {
937
- return (false , StatusCodes.code (StatusCodes.Status.InsufficientAllowance), bytes32 (0 ));
932
+ function canTransferFrom (address _from , address _to , uint256 _value , bytes calldata _data ) external view returns (byte reasonCode , bytes32 appCode ) {
933
+ (reasonCode, appCode) = _canTransfer (_from, _to, _value, _data);
934
+ if (isSuccess (reasonCode) && _value > allowance (_from, msg .sender )) {
935
+ return (StatusCodes.code (StatusCodes.Status.InsufficientAllowance), bytes32 (0 ));
938
936
}
939
937
}
940
938
941
- function _canTransfer (address _from , address _to , uint256 _value , bytes memory _data ) internal view returns (bool , byte , bytes32 ) {
939
+ function _canTransfer (address _from , address _to , uint256 _value , bytes memory _data ) internal view returns (byte , bytes32 ) {
942
940
bytes32 appCode;
943
941
bool success;
944
942
if (_value % granularity != 0 ) {
945
- return (false , StatusCodes.code (StatusCodes.Status.TransferFailure), bytes32 (0 ));
943
+ return (StatusCodes.code (StatusCodes.Status.TransferFailure), bytes32 (0 ));
946
944
}
947
945
(success, appCode) = TokenLib.verifyTransfer (modules[TRANSFER_KEY], modulesToData, _from, _to, _value, _data, transfersFrozen);
948
946
return TokenLib.canTransfer (success, appCode, _to, _value, balanceOf (_from));
@@ -969,17 +967,16 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
969
967
)
970
968
external
971
969
view
972
- returns (byte esc , bytes32 appStatusCode , bytes32 toPartition )
970
+ returns (byte reasonCode , bytes32 appStatusCode , bytes32 toPartition )
973
971
{
974
972
if (_partition == UNLOCKED) {
975
- bool success;
976
- (success, esc, appStatusCode) = _canTransfer (_from, _to, _value, _data);
977
- if (success) {
973
+ (reasonCode, appStatusCode) = _canTransfer (_from, _to, _value, _data);
974
+ if (isSuccess (reasonCode)) {
978
975
uint256 beforeBalance = _balanceOfByPartition (LOCKED, _to, 0 );
979
976
uint256 afterbalance = _balanceOfByPartition (LOCKED, _to, _value);
980
977
toPartition = _returnPartition (beforeBalance, afterbalance, _value);
981
978
}
982
- return (esc , appStatusCode, toPartition);
979
+ return (reasonCode , appStatusCode, toPartition);
983
980
}
984
981
return (StatusCodes.code (StatusCodes.Status.TransferFailure), bytes32 (0 ), bytes32 (0 ));
985
982
}
@@ -1100,4 +1097,13 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
1100
1097
emit OwnershipTransferred (_owner, newOwner);
1101
1098
_owner = newOwner;
1102
1099
}
1100
+
1101
+ /**
1102
+ * @dev Check if a status code represents success (ie: 0x*1)
1103
+ * @param status Binary ERC-1066 status code
1104
+ * @return successful A boolean representing if the status code represents success
1105
+ */
1106
+ function isSuccess (byte status ) public pure returns (bool successful ) {
1107
+ return (status & 0x0F ) == 0x01 ;
1108
+ }
1103
1109
}
0 commit comments