/** * Copyright 2017–2019, LaborX PTY * Licensed under the AGPL Version 3 license. */ pragma solidity ^0.4.25; import "@laborx/solidity-shared-contracts/contracts/ERC223ReceivingInterface.sol"; import "./erc20/ERC20Manager.sol"; import "./EscrowBaseInterface.sol"; import "./Disputed.sol"; import "./EscrowEmitter.sol"; import "../common/Signatures.sol"; import "../common/FeeConstants.sol"; import "../libs/SafeMath.sol"; import "../libs/PercentCalculator.sol"; /// @title ERC20_Draft_v_0_1 is a cut version of full ERC-20 standard that /// includes only transfer methods and return no result after their completion /// (no return value, so we need to handle this). /// @dev USDT (Tether) implementation uses such technique (without return value) so this is /// a workaround that supports token from Tether. contract ERC20_Draft_v_0_1 { event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed from, address indexed spender, uint256 value); string public symbol; function decimals() public view returns (uint8); function totalSupply() public view returns (uint256 supply); function balanceOf(address _owner) public view returns (uint256 balance); function approve(address _spender, uint256 _value) public returns (bool success); function allowance(address owner, address spender) public view returns (uint); function transferFrom(address from, address to, uint value) public; function transfer(address to, uint value) public; } contract EscrowERC20 is EscrowBaseInterface, Disputed, EscrowEmitter, FeeConstants, ERC223ReceivingInterface { using SafeMath for uint; ERC20Manager public erc20Manager; mapping(bytes32 => Escrow) private escrows; mapping(address => uint) private token2accumulatedFeeMapping; struct Escrow { bool exists; bool disputed; bytes32 symbol; uint value; address arbiter; uint16 sellerFee; uint16 buyerFee; } constructor(address _erc20Manager, address _escrowFeeManager) public { erc20Manager = ERC20Manager(_erc20Manager); require(_escrowFeeManager != 0x0, "ESCROW_ERC20_INVALID_FEE_MANAGER"); _feeManager = EscrowFeeManagerInterface(_escrowFeeManager); } function() external payable { revert("ESCROW_ERC20_DOES_NOT_SUPPORT_ETH"); } /// @dev Standard ERC223 function that will handle incoming token transfers. function tokenFallback(address /* _from */, uint /* _value */, bytes /* _data */) external { require(erc20Manager.isTokenExists(msg.sender), "ESCROW_ERC20_CURRENCY_SHOULD_BE_SUPPORTED"); } function setFeeManager(address _escrowFeeManager) external onlyContractOwner returns (uint) { require(_escrowFeeManager != 0x0, "ESCROW_ERC20_INVALID_FEE_MANAGER"); require(_escrowFeeManager != address(_feeManager), "ESCROW_ERC20_INVALID_FEE_MANAGER"); _feeManager = EscrowFeeManagerInterface(_escrowFeeManager); return OK; } function getFeeBalance(address[] _tokens) public view returns (uint[] _balances) { _balances = new uint[](_tokens.length); for (uint _tokenIdx = 0; _tokenIdx < _tokens.length; _tokenIdx++) { _balances[_tokenIdx] = token2accumulatedFeeMapping[_tokens[_tokenIdx]]; } } /// @notice Creates an escrow record for provided symbol "`_symbol`" /// @dev Escrow is reusable so the same tradeRecordId could be reused after an escrow /// with the same identifier is resolved. /// @dev Escrow is identified by a message = keccak256(_tradeRecordId, _seller, _buyer) /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment /// @param _symbol symbol of payment currency /// @param _value amount to initially deposit to escrow; could be 0 /// @param _transferImmediatelyToBuyerAmount amount to transfer immediately to a buyer /// @param _feeStatus fee condition (1st bit - seller, 2nd - buyer) /// @return result code of an operation function createEscrow( bytes32 _tradeRecordId, address _seller, address _buyer, bytes32 _symbol, uint _value, uint _transferImmediatelyToBuyerAmount, uint8 _feeStatus ) external payable onlyRelay returns (uint) { require(msg.value == 0, "ESCROW_ERC20_DOES_NOT_SUPPORT_ETH"); bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; require(!_escrow.exists, "ESCROW_ERC20_ESCROW_SHOULD_NOT_EXIST"); require(hasCurrencySupport(_symbol), "ESCROW_ERC20_CURRENCY_SHOULD_BE_SUPPORTED"); _escrow.exists = true; (_escrow.sellerFee,) = _feeManager.getSellerFee(_seller); (_escrow.buyerFee,) = _feeManager.getBuyerFee(_buyer); uint _valueWithoutFee = _value; if (_value > 0) { ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_symbol)); require(_token.allowance(_seller, address(this)) >= _value && _value >= _transferImmediatelyToBuyerAmount, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); _token.transferFrom(_seller, address(this), _value); _valueWithoutFee = _takeDepositFee(_escrow, _token, _value, _feeStatus); if (_transferImmediatelyToBuyerAmount > 0) { //send upfront to buyer _valueWithoutFee = _valueWithoutFee.sub(_transferImmediatelyToBuyerAmount); uint _transferImmediatelyToBuyerAmountWithoutFee = _takeWithdrawalFee(_escrow, _token, _transferImmediatelyToBuyerAmount, _feeStatus); _token.transfer(_buyer, _transferImmediatelyToBuyerAmountWithoutFee); } } _escrow.symbol = _symbol; _escrow.value = _valueWithoutFee; _emitCreated(_escrowHash, _symbol, _valueWithoutFee); return OK; } /// @notice Deposits to an escrow provided amount `_value` /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment /// @param _value amount to deposit /// @param _transferImmediatelyToBuyerAmount amount to transfer immediately to a buyer /// @param _feeStatus fee condition (1st bit - seller, 2nd - buyer) /// @return result code of an operation function deposit( bytes32 _tradeRecordId, address _seller, address _buyer, uint _value, uint _transferImmediatelyToBuyerAmount, // transfers _transferImmediatelyToBuyerAmount directly to _buyer. uint8 _feeStatus ) external payable onlyRelay returns (uint) { require(msg.value == 0, "ESCROW_ERC20_DOES_NOT_SUPPORT_ETH"); bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; require(_escrow.exists, "ESCROW_ERC20_ESCROW_SHOULD_EXIST"); require(!_escrow.disputed, "ESCROW_ERC20_ESCROW_SHOULD_NOT_BE_DISPUTED"); ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_escrow.symbol)); address _investor = _getDepositInitiator(_seller, _buyer, _feeStatus); require(_value > 0 && _token.allowance(_investor, address(this)) >= _value && _value >= _transferImmediatelyToBuyerAmount, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); _token.transferFrom(_investor, address(this), _value); uint _valueWithoutFee = _takeDepositFee(_escrow, _token, _value, _feeStatus); if (_transferImmediatelyToBuyerAmount > 0) { //send upfront to buyer _valueWithoutFee = _valueWithoutFee.sub(_transferImmediatelyToBuyerAmount); uint _transferImmediatelyToBuyerAmountWithoutFee = _takeWithdrawalFee(_escrow, _token, _transferImmediatelyToBuyerAmount, _feeStatus); _token.transfer(_buyer, _transferImmediatelyToBuyerAmountWithoutFee); } _escrow.value = _escrow.value.add(_valueWithoutFee); _emitDeposited(_escrowHash, _escrow.symbol, _valueWithoutFee); return OK; } /// @notice Transfers `_value` from escrow to buyer `_buyer` /// @dev Escrow is identified by a message = keccak256(_tradeRecordId, _seller, _buyer) /// @dev Seller shoud sign hash of (message, escrow address, msg.sig, _value, _expireAtBlock, _salt) data /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment /// @param _value amount to withdraw from escrow /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _salt random bytes to identify signed data /// @param _sellerSignature signature produced by seller /// @param _feeStatus fee condition (1st bit - seller, 2nd - buyer) /// @return result code of an operation function releaseBuyerPayment( bytes32 _tradeRecordId, address _seller, address _buyer, uint _value, uint _expireAtBlock, uint _salt, bytes _sellerSignature, uint8 _feeStatus ) external onlyRelay returns (uint) { bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; bytes32 _encodedSaltWithEscrow = _getEncodedSaltWithEscrowHash(_salt, _escrowHash); require(_escrow.exists, "ESCROW_ERC20_ESCROW_SHOULD_EXIST"); require(!_escrow.disputed, "ESCROW_ERC20_ESCROW_SHOULD_NOT_BE_DISPUTED"); require(!_saltWithEscrow2flagMapping[_encodedSaltWithEscrow], "ESCROW_ERC20_SUCH_SALT_SHOULD_NOT_EXIST"); _assertSeller(_escrowHash, _seller, _value, _expireAtBlock, _salt, _sellerSignature); require(block.number < _expireAtBlock, "ESCROW_ERC20_TX_SHOULD_NOT_BE_EXPIRED"); require(_escrow.value >= _value && _value > 0, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); _saltWithEscrow2flagMapping[_encodedSaltWithEscrow] = true; _escrow.value = _escrow.value.sub(_value); ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_escrow.symbol)); uint _valueWithoutFee = _takeWithdrawalFee(_escrow, _token, _value, _feeStatus); _token.transfer(_buyer, _valueWithoutFee); _emitReleasedPayment(_escrowHash, _escrow.symbol, _valueWithoutFee); return OK; } function _assertSeller( bytes32 _escrowHash, address _seller, uint _value, uint _expireAtBlock, uint _salt, bytes _sellerSignature ) private view { bytes memory _message = abi.encodePacked( _escrowHash, address(this), msg.sig, _value, _expireAtBlock, _salt ); address _signer = Signatures.getSignerFromSignature(keccak256(_message), _sellerSignature); require(_signer == _seller, "ESCROW_ERC20_SIGNER_SHOULD_BE_SELLER"); } /// @notice Transfers `_value` from escrow to seller `_seller` /// @dev Escrow is identified by a message = keccak256(_tradeRecordId, _seller, _buyer) /// @dev Buyer shoud sign hash of (message, escrow address, msg.sig, _value, _expireAtBlock, _salt) data /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment /// @param _value amount to withdraw from escrow /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _salt random bytes to identify signed data /// @param _buyerSignature signature produced by buyer /// @return result code of an operation function sendSellerPayback( bytes32 _tradeRecordId, address _seller, address _buyer, uint _value, uint _expireAtBlock, uint _salt, bytes _buyerSignature ) external onlyRelay returns (uint) { bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; bytes32 _encodedSaltWithEscrow = _getEncodedSaltWithEscrowHash(_salt, _escrowHash); require(_escrow.exists, "ESCROW_ERC20_ESCROW_SHOULD_EXIST"); require(!_escrow.disputed, "ESCROW_ERC20_ESCROW_SHOULD_NOT_BE_DISPUTED"); require(!_saltWithEscrow2flagMapping[_encodedSaltWithEscrow], "ESCROW_ERC20_SUCH_SALT_SHOULD_NOT_EXIST"); bytes memory _message = abi.encodePacked( _escrowHash, address(this), msg.sig, _value, _expireAtBlock, _salt ); address _signer = Signatures.getSignerFromSignature(keccak256(_message), _buyerSignature); require(_signer == _buyer, "ESCROW_ERC20_SIGNER_SHOULD_BE_BUYER"); require(block.number < _expireAtBlock, "ESCROW_ERC20_TX_SHOULD_NOT_BE_EXPIRED"); require(_escrow.value >= _value && _value > 0, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); _saltWithEscrow2flagMapping[_encodedSaltWithEscrow] = true; _escrow.value = _escrow.value.sub(_value); ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_escrow.symbol)); _token.transfer(_seller, _value); _emitPayback(_escrowHash, _escrow.symbol, _value); return OK; } /// @notice Transfers `_value` from escrow to seller `_seller` and buyer `_buyer` /// @dev Escrow is identified by a message = keccak256(_tradeRecordId, _seller, _buyer) /// @dev Seller and buyer shoud sign hash of (message, escrow address, msg.sig, _sellerValue, _buyerValue, _expireAtBlock, _salt) data /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment /// @param _sellerValue amount to withdraw from escrow to the seller /// @param _buyerValue amount to withdraw from escrow to the buyer /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _salt random bytes to identify signed data /// @param _signatures concatenated signatures produced by seller and buyer /// @param _feeStatus fee condition (1st bit - seller, 2nd - buyer) /// @return result code of an operation function releaseNegotiatedPayment( bytes32 _tradeRecordId, address _seller, address _buyer, uint _sellerValue, uint _buyerValue, uint _expireAtBlock, uint _salt, bytes _signatures, uint8 _feeStatus ) external onlyRelay returns (uint) { bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; require(_escrow.exists, "ESCROW_ERC20_ESCROW_SHOULD_EXIST"); require(!_escrow.disputed, "ESCROW_ERC20_ESCROW_SHOULD_NOT_BE_DISPUTED"); require(!_saltWithEscrow2flagMapping[_getEncodedSaltWithEscrowHash(_salt, _escrowHash)], "ESCROW_ERC20_SUCH_SALT_SHOULD_NOT_EXIST"); _assertSellerAndBuyer(_escrowHash, _seller, _buyer, _sellerValue, _buyerValue, _expireAtBlock, _salt, _signatures); require(block.number < _expireAtBlock, "ESCROW_ERC20_TX_SHOULD_NOT_BE_EXPIRED"); require(_escrow.value >= _sellerValue.add(_buyerValue) && _sellerValue.add(_buyerValue) > 0, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); _saltWithEscrow2flagMapping[_getEncodedSaltWithEscrowHash(_salt, _escrowHash)] = true; _escrow.value = _escrow.value.sub(_sellerValue.add(_buyerValue)); ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_escrow.symbol)); _token.transfer(_seller, _sellerValue); uint _buyerValueWithoutFee = _takeWithdrawalFee(_escrow, _token, _buyerValue, _feeStatus); _token.transfer(_buyer, _buyerValueWithoutFee); _emitPayback(_escrowHash, _escrow.symbol, _sellerValue); _emitReleasedPayment(_escrowHash, _escrow.symbol, _buyerValueWithoutFee); return OK; } function _assertSellerAndBuyer( bytes32 _escrowHash, address _seller, address _buyer, uint _sellerValue, uint _buyerValue, uint _expireAtBlock, uint _salt, bytes _signatures ) private view { bytes memory _message = abi.encodePacked( _escrowHash, address(this), msg.sig, _sellerValue, _buyerValue, _expireAtBlock, _salt ); address[] memory _signers = Signatures.getSignersFromSignatures(keccak256(_message), _signatures); require(_signers.length == 2 && ((_signers[0] == _seller && _signers[1] == _buyer) || (_signers[0] == _buyer && _signers[1] == _seller)), "ESCROW_ERC20_SIGNERS_SHOULD_BE_BUYER_AND_SELLER"); } /// @notice Transfers disputed value from escrow to the seller `_seller` and the buyer `_buyer` according /// to provided buyer value `_buyerValue`. The value of escrow - _buyerValue will be transferred to the seller. /// @dev Escrow is identified by a message = keccak256(_tradeRecordId, _seller, _buyer) /// @dev Arbiter should sign hash of (message, escrow address, msg.sig, _buyerValue, _expireAtBlock) data /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment /// @param _buyerValue value that will be transferred to the buyer /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _arbiterSignature signature of an arbiter /// @return result code of an operation function releaseDisputedPayment( bytes32 _tradeRecordId, address _seller, address _buyer, uint _buyerValue, uint _expireAtBlock, bytes _arbiterSignature ) external onlyRelay returns (uint) { bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; require(_escrow.exists, "ESCROW_ERC20_ESCROW_SHOULD_EXIST"); require(_escrow.disputed, "ESCROW_ERC20_ESCROW_SHOULD_BE_DISPUTED"); bytes memory _message = abi.encodePacked( _escrowHash, address(this), msg.sig, _buyerValue, _expireAtBlock ); address _signer = Signatures.getSignerFromSignature(keccak256(_message), _arbiterSignature); require(_signer == _escrow.arbiter, "ESCROW_ERC20_SIGNER_SHOULD_BE_ARBITER"); require(block.number < _expireAtBlock, "ESCROW_ERC20_TX_SHOULD_NOT_BE_EXPIRED"); require(_buyerValue <= _escrow.value, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_escrow.symbol)); if (_buyerValue < _escrow.value) { uint _sellerValue = _escrow.value.sub(_buyerValue); _token.transfer(_seller, _sellerValue); _emitPayback(_escrowHash, _escrow.symbol, _sellerValue); } uint _buyerValueWithoutFee = _takeAnyWithdrawalFee(_escrow, _token, _buyerValue, _getBuyerFeeFlag()); _token.transfer(_buyer, _buyerValueWithoutFee); _deleteEscrow(_escrowHash); delete _disputeInitiators[_escrowHash]; _emitReleasedPayment(_escrowHash, _escrow.symbol, _buyerValueWithoutFee); _emitDisputeCanceled(_escrowHash); return OK; } /// @notice Deletes escrow record when it is no more needed. /// Escrow should be empty to be deleted. /// @param _tradeRecordId identifier of escrow record /// @param _seller who will mainly deposit to escrow /// @param _buyer who will eventually is going to receive payment function deleteEscrow( bytes32 _tradeRecordId, address _seller, address _buyer ) external returns (uint) { bytes32 _escrowHash = _getEscrowHash(_tradeRecordId, _seller, _buyer); Escrow storage _escrow = escrows[_escrowHash]; if (_escrow.exists && _escrow.value == 0) { _deleteEscrow(_escrowHash); } return OK; } function _deleteEscrow(bytes32 _escrowHash) private { delete escrows[_escrowHash]; } /// @notice Charges a service fee for deposits to escrow contract. /// @param _value value from which the commission is taken /// @param _feeStatus activate state fee: 1 - active, 0 - not active. 1st bit - seller, 2nd bit - buyer /// @return result value without service fee function _takeDepositFee( Escrow storage _escrow, address _token, uint _value, uint8 _feeStatus ) private returns (uint _valueToDeposit) { _valueToDeposit = _value; bool _isActivatedRelay = isActivatedRelay(); if (_escrow.sellerFee > 0 && (!_isActivatedRelay || (_isActivatedRelay && _isFeeFlagAppliedFor(_feeStatus, SELLER_FLAG_BIT_IDX)))) { uint _feePrecision = _feeManager.getServiceFeePrecision(); _valueToDeposit = PercentCalculator.getFullValueFromPercentedValue(_value, _feePrecision.add(_escrow.sellerFee), _feePrecision); uint _feeValue = _value.sub(_valueToDeposit); token2accumulatedFeeMapping[_token] = token2accumulatedFeeMapping[_token].add(_feeValue); } } /// @notice Charges a service fee for withdrawal payments from escrow contract. /// @param _token erc20 token address /// @param _value value from which the commission is taken /// @param _feeStatus activate state fee: 1 - active, 0 - not active. 1st bit - seller, 2nd bit - buyer /// @return result value without service fee function _takeWithdrawalFee( Escrow storage _escrow, address _token, uint _value, uint8 _feeStatus ) private returns (uint) { bool _isActivatedRelay = isActivatedRelay(); if (!_isActivatedRelay || (_isActivatedRelay && _isFeeFlagAppliedFor(_feeStatus, BUYER_FLAG_BIT_IDX))) { return _takeAnyWithdrawalFee(_escrow, _token, _value, _feeStatus); } return _value; } function _takeAnyWithdrawalFee( Escrow storage _escrow, address _token, uint _value, uint8 _feeStatus ) private returns (uint) { uint16 _serviceFee; if (_isFeeFlagAppliedFor(_feeStatus, BUYER_FLAG_BIT_IDX)) { _serviceFee = _escrow.buyerFee; } if (_serviceFee > 0) { uint _feePrecision = _feeManager.getServiceFeePrecision(); uint _feeValue = PercentCalculator.getPercent(_value, _serviceFee, _feePrecision); _value = _value.sub(_feeValue); token2accumulatedFeeMapping[_token] = token2accumulatedFeeMapping[_token].add(_feeValue); } return _value; } function withdrawFeeForTokens(address[] _tokens) public onlyContractOwner { address _feeDestinationAddress = _feeManager.getServiceFeeAddress(); require(_feeDestinationAddress != address(0), "ESCROW_ERC20_INVALID_SERVICE_FEE_ADDRESS"); for (uint _tokenIdx = 0; _tokenIdx < _tokens.length; _tokenIdx++) { address _token = _tokens[_tokenIdx]; uint _accumulatedFee = token2accumulatedFeeMapping[_token]; token2accumulatedFeeMapping[_token] = 0; if (_accumulatedFee > 0) { ERC20_Draft_v_0_1(_token).transfer(_feeDestinationAddress, _accumulatedFee); } } } function retranslateToFeeRecipient(bytes32 _symbol, address _from, uint _amount) external payable returns (uint) { require(hasCurrencySupport(_symbol), "ESCROW_ERC20_CURRENCY_SHOULD_BE_SUPPORTED"); ERC20_Draft_v_0_1 _token = ERC20_Draft_v_0_1(erc20Manager.getTokenAddressBySymbol(_symbol)); require(_amount > 0 && _token.allowance(_from, address(this)) >= _amount, "ESCROW_ERC20_VALUE_SHOULD_BE_CORRECT"); _token.transferFrom(_from, address(this), _amount); token2accumulatedFeeMapping[_token] = token2accumulatedFeeMapping[_token].add(_amount); return OK; } /// @notice Transfer accumulated service fee to the serviceFeeAddress function withdrawFee(address _token) public onlyContractOwner { address[] memory _tokens = new address[](1); _tokens[0] = _token; withdrawFeeForTokens(_tokens); } function hasCurrencySupport(bytes32 _symbol) public view returns (bool) { return erc20Manager.isTokenSymbolExists(_symbol); } function _getEscrowExists(bytes32 _escrowHash) internal view returns (bool) { Escrow storage _escrow = escrows[_escrowHash]; return _escrow.exists; } function _getEscrowDisputed(bytes32 _escrowHash) internal view returns (bool) { Escrow storage _escrow = escrows[_escrowHash]; return _escrow.disputed; } function _getEscrowSymbol(bytes32 _escrowHash) internal view returns (bytes32) { Escrow storage _escrow = escrows[_escrowHash]; return _escrow.symbol; } function _getEscrowValue(bytes32 _escrowHash) internal view returns (uint) { Escrow storage _escrow = escrows[_escrowHash]; return _escrow.value; } function _getEscrowArbiter(bytes32 _escrowHash) internal view returns (address) { Escrow storage _escrow = escrows[_escrowHash]; return _escrow.arbiter; } function _getEscrowFees(bytes32 _escrowHash) internal view returns (uint16, uint16) { Escrow storage _escrow = escrows[_escrowHash]; return (_escrow.sellerFee, _escrow.buyerFee); } function _setEscrowDisputed(bytes32 _escrowHash, bool _disputeStatus) internal { Escrow storage _escrow = escrows[_escrowHash]; _escrow.disputed = _disputeStatus; } function _setEscrowArbiter(bytes32 _escrowHash, address _arbiter) internal { Escrow storage _escrow = escrows[_escrowHash]; _escrow.arbiter = _arbiter; } function _getDepositInitiator(address _seller, address _buyer, uint8 _status) private pure returns (address) { if (_isFeeFlagAppliedFor(_status, BUYER_DEPOSIT_INITIATOR_IDX)) { return _buyer; } return _seller; } }