contract BTCPayment is Ownable, PresaleFallbackReceiver {
  using SafeMath for uint256;

  PaymentFallbackReceiver public presale;
  PaymentFallbackReceiver public mainsale;

  event NewPayment(address _beneficiary, uint256 _tokens);

  function addPayment(address _beneficiary, uint256 _tokens)
    public
    onlyOwner
  {
    if (!presaleFallBackCalled) {
      presale.paymentFallBack(_beneficiary, _tokens);
    } else {
      mainsale.paymentFallBack(_beneficiary, _tokens);
    }

    NewPayment(_beneficiary, _tokens);
  }

  function setPresale(address _presale) external onlyOwner {
    require(presale == address(0));
    presale = PaymentFallbackReceiver(_presale); // datatype conversion `address` to `PaymentFallbackReceiver`. not calling constructor `PaymentFallbackReceiver`
  }

  function setMainsale(address _mainsale) external onlyOwner {
    require(mainsale == address(0));
    mainsale = PaymentFallbackReceiver(_mainsale); // datatype conversion `address` to `PaymentFallbackReceiver`. not calling constructor `PaymentFallbackReceiver`
  }

  /**
   * @dev Presale should notify that presale is finalized and mainsale
   * is going to start.
   */
  function presaleFallBack(uint256) public returns (bool) {
    require(msg.sender == address(presale));
    if (presaleFallBackCalled) return false;
    presaleFallBackCalled = true;
    return true;
  }
}
function presaleFallBack(uint256) public returns (bool) {
  require(msg.sender == address(presale));
  if (presaleFallBackCalled) return false;
  presaleFallBackCalled = true;
  return true;
}

/**
 * @dev Presale should notify that presale is finalized and mainsale
 * is going to start.
 */