Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 在智能合约上检索卡住的以太_Ethereum_Smartcontracts - Fatal编程技术网

Ethereum 在智能合约上检索卡住的以太

Ethereum 在智能合约上检索卡住的以太,ethereum,smartcontracts,Ethereum,Smartcontracts,有没有办法回收智能合约中卡住的乙醚? returnMoney()方法应该在所有事情都完成后才调用,但因为有人从交换钱包中转移了一些金额,所以我们必须退款。现在,weiRaised变量显示出比智能合约当前更大的价值 下面是使用源代码部署的live合约 pragma-solidity^0.4.19; 合同所有权{ 向公众所有人致辞; 事件所有者已转移(地址索引为previousOwner,地址索引为newOwner); 构造函数()公共{owner=msg.sender;} 仅修饰符所有者(){

有没有办法回收智能合约中卡住的乙醚? returnMoney()方法应该在所有事情都完成后才调用,但因为有人从交换钱包中转移了一些金额,所以我们必须退款。现在,weiRaised变量显示出比智能合约当前更大的价值

下面是使用源代码部署的live合约

pragma-solidity^0.4.19;
合同所有权{
向公众所有人致辞;
事件所有者已转移(地址索引为previousOwner,地址索引为newOwner);
构造函数()公共{owner=msg.sender;}
仅修饰符所有者(){
地址发送者=msg.sender;
地址_owner=所有者;
需要(msg.sender==\u所有者);
_;  
}
函数TransferOwner(地址newOwner)仅所有者公共{
require(newOwner!=地址(0));
排放所有权转移(所有者、新所有者);
所有者=新所有者;
}
}
图书馆安全数学{
函数mul(uint256 a,uint256 b)内部纯返回(uint256){
uint256 c=a*b;
断言(a==0 | | c/a==b);
返回c;
}
函数div(uint256 a,uint256 b)内部纯返回(uint256){
uint256 c=a/b;
//assert(a==b*c+a%b);//在任何情况下都是这样
返回c;
}
函数子(uint256 a,uint256 b)内部纯返回(uint256){
断言(b=a);
返回c;
}
}
合同ERC20Basic{
uint256公共总供给;
(地址)公共固定收益的功能平衡(uint256);
函数传输(地址到,uint256值)公共返回(bool);
事件传输(地址索引自,地址索引至,uint256值);
}
/**
*@title ERC20接口
*@dev-seehttps://github.com/ethereum/EIPs/issues/20
*/
合同ERC20是ERC20Basic{
功能津贴(地址所有者、地址使用者)公共固定收益(uint256);
函数transferFrom(地址from,地址to,uint256值)公共返回(bool);
功能批准(地址支出者,uint256值)公共退货(bool);
事件批准(地址索引所有者、地址索引支出者、uint256值);
}
合同基本条款是ERC20Basic{
对uint256使用SafeMath;
映射(地址=>uint256)余额;
/**
*@dev指定地址的传输令牌
*@param_到要传输到的地址。
*@param\u表示要转移的金额。
*/
函数传输(地址到,uint256值)公共返回(bool){
要求(_to!=地址(0));
//如果没有足够的平衡,SafeMath.sub将抛出。
余额[msg.sender]=余额[msg.sender].sub(_值);
余额[\u to]=余额[\u to]。添加(\u值);
发送传输(msg.sender,_-to,_-value);
返回true;
}
/**
*@dev获取指定地址的余额。
*@param_owner查询余额的地址。
*@返回一个uint256,表示传递的地址所拥有的金额。
*/
(地址所有者)公共常量返回的函数余额(uint256余额){
返还余额[_所有者];
}
}
/**
*@title标准ERC20令牌
*
*@dev基本标准令牌的实现。
*@devhttps://github.com/ethereum/EIPs/issues/20
*@dev基于FirstBlood的代码:https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
合同标准令牌是ERC20,BasicToken{
允许映射(地址=>mapping(地址=>uint256));
/**
*@dev将令牌从一个地址转移到另一个地址
*@param\u from address您要从中发送令牌的地址
*@param\u以寻址您要传送到的地址
*@param_value uint256要传输的令牌数量
*/
函数transferFrom(地址from,地址to,uint256 value)公共返回(bool){
要求(_to!=地址(0));
uint256 _余量=允许[_from][msg.sender];
余额[_-from]=余额[_-from].sub(_值);
余额[\u to]=余额[\u to]。添加(\u值);
允许的[\u from][msg.sender]=\u余量.sub(\u值);
发射传输(_从,_到,_值);
返回true;
}
/**
*@dev批准传递的地址以代表msg.sender使用指定数量的令牌。
*
*请注意,使用这种方法更改津贴会带来风险,即有人可能同时使用旧津贴和旧津贴
*以及通过不幸的事务排序获得的新津贴。缓解这一问题的一个可能的解决方案
*竞态条件是首先将挥霍者的津贴降低到0,然后设置所需的值:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*@param_将花费资金的地址挥霍掉。
*@param\u表示要花费的代币数量。
*/
职能部门批准(地址、支出者、uint256值)公共回报(bool){
允许的[msg.sender][\u spender]=\u值;
发出批准(msg.sender、\u spender、\u value);
返回true;
}
/**
*@dev函数检查所有者允许挥霍者使用的代币数量。
*@param_owner address拥有资金的地址。
*@param_spender地址将花费资金的地址。
*@返回一个uint256,指定仍可供挥霍者使用的代币数量。
*/
功能津贴(地址所有者、地址支出者)公共固定收益(uint256剩余){
允许退货[\u所有者][\u消费者];
}
/**
*允许时应调用approve[\u spender]==0。以增加
*允许值最好使用此函数来避免2次调用(并等待
*第一个事务被挖掘)
*来自MonolithDAO Token.sol
*/
功能增加批准(地址_spender,uint _addedValue)公共回报(bool success){
允许的[msg.sender][\u spender]=允许的[msg.sender][\u spender].add(\u addedValue);
发出批准(msg.sender,_spender,allowed[msg.sender][_spender]);
返回true;
}
函数decreaseApproval(地址_spender,uint _减去值)公共返回(bool such
pragma solidity ^0.4.19;

contract Ownable {
  address public owner;
  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  constructor() public { owner = msg.sender;  }

  modifier onlyOwner() {     
      address sender =  msg.sender;
      address _owner = owner;
      require(msg.sender == _owner);    
      _;  
  }

  function transferOwnership(address newOwner) onlyOwner public { 
    require(newOwner != address(0));
    emit OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }
}

library SafeMath {
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a * b;
    assert(a == 0 || c / a == b);
    return c;
  }

  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }
}

contract ERC20Basic {
  uint256 public totalSupply;
  function balanceOf(address who) public constant returns (uint256);
  function transfer(address to, uint256 value) public returns (bool);
  event Transfer(address indexed from, address indexed to, uint256 value);
}

/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
contract ERC20 is ERC20Basic {
  function allowance(address owner, address spender) public constant returns (uint256);
  function transferFrom(address from, address to, uint256 value) public returns (bool);
  function approve(address spender, uint256 value) public returns (bool);
  event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract BasicToken is ERC20Basic {
  using SafeMath for uint256;
  mapping(address => uint256) balances;

  /**
  * @dev transfer token for a specified address
  * @param _to The address to transfer to.
  * @param _value The amount to be transferred.
  */
  function transfer(address _to, uint256 _value) public returns (bool) {
    require(_to != address(0));

    // SafeMath.sub will throw if there is not enough balance.
    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    emit Transfer(msg.sender, _to, _value);
    return true;
  }

  /**
  * @dev Gets the balance of the specified address.
  * @param _owner The address to query the the balance of.
  * @return An uint256 representing the amount owned by the passed address.
  */
  function balanceOf(address _owner) public constant returns (uint256 balance) {
    return balances[_owner];
  }

}

/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * @dev https://github.com/ethereum/EIPs/issues/20
 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 */
contract StandardToken is ERC20, BasicToken {

  mapping (address => mapping (address => uint256)) allowed;

  /**
   * @dev Transfer tokens from one address to another
   * @param _from address The address which you want to send tokens from
   * @param _to address The address which you want to transfer to
   * @param _value uint256 the amount of tokens to be transferred
   */
  function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
    require(_to != address(0));
    uint256 _allowance = allowed[_from][msg.sender];
    balances[_from] = balances[_from].sub(_value);
    balances[_to] = balances[_to].add(_value);
    allowed[_from][msg.sender] = _allowance.sub(_value);
    emit Transfer(_from, _to, _value);
    return true;
  }

  /**
   * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
   *
   * Beware that changing an allowance with this method brings the risk that someone may use both the old
   * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
   * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
   * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
   * @param _spender The address which will spend the funds.
   * @param _value The amount of tokens to be spent.
   */
  function approve(address _spender, uint256 _value) public returns (bool) {
    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);
    return true;
  }

  /**
   * @dev Function to check the amount of tokens that an owner allowed to a spender.
   * @param _owner address The address which owns the funds.
   * @param _spender address The address which will spend the funds.
   * @return A uint256 specifying the amount of tokens still available for the spender.
   */
  function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
    return allowed[_owner][_spender];
  }

  /**
   * approve should be called when allowed[_spender] == 0. To increment
   * allowed value is better to use this function to avoid 2 calls (and wait until
   * the first transaction is mined)
   * From MonolithDAO Token.sol
   */
  function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
    allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
    emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    return true;
  }

  function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
    uint oldValue = allowed[msg.sender][_spender];
    if (_subtractedValue > oldValue) {
      allowed[msg.sender][_spender] = 0;
    } else {
      allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
    }
    emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    return true;
  }

}

contract MintableToken is StandardToken, Ownable {
  event Mint(address indexed to, uint256 amount);
  event MintFinished();

  bool public mintingFinished = false;

  modifier canMint() {
    require(!mintingFinished);
    _;
  }

  /**
   * @dev Function to mint tokens
   * @param _to The address that will receive the minted tokens.
   * @param _amount The amount of tokens to mint.
   * @return A boolean that indicates if the operation was successful.
   */
  function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
    totalSupply = totalSupply.add(_amount);
    balances[_to] = balances[_to].add(_amount);
    emit Mint(_to, _amount);
    emit Transfer(0x0, _to, _amount);
    return true;
  }

  /**
   * @dev Function to mint tokens
   * @param _to The address that will receive the minted tokens.
   * @param _amount The amount of tokens to mint.
   * @return A boolean that indicates if the operation was successful.
   */
  function mintFinalize(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
    totalSupply = totalSupply.add(_amount);
    balances[_to] = balances[_to].add(_amount);
    emit Mint(_to, _amount);
    emit Transfer(0x0, _to, _amount);
    return true;
  }

  /**
   * @dev Function to stop minting new tokens.
   * @return True if the operation was successful.
   */
  function finishMinting() onlyOwner public returns (bool) {
    mintingFinished = true;
    emit MintFinished();
    return true;
  }
}

/**
 * @title SwordToken
 * @dev Sword ERC20 Token that can be minted.
 * It is meant to be used in Sword crowdsale contract.
 */
contract SwordToken is MintableToken {

    string public constant name = "Sword Coin"; 
    string public constant symbol = "SWDC";
    uint8 public constant decimals = 18;

    function getTotalSupply() view public returns (uint256) {
        return totalSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool) {
        super.transfer(_to, _value);
    }

}

contract KycContractInterface {
    function isAddressVerified(address _address) public view returns (bool);
}

contract KycContract is Ownable {

    mapping (address => bool) verifiedAddresses;

    function isAddressVerified(address _address) public view returns (bool) {
        return verifiedAddresses[_address];
    }

    function addAddress(address _newAddress) public onlyOwner {
        require(!verifiedAddresses[_newAddress]);

        verifiedAddresses[_newAddress] = true;
    }

    function removeAddress(address _oldAddress) public onlyOwner {
        require(verifiedAddresses[_oldAddress]);

        verifiedAddresses[_oldAddress] = false;
    }

    function batchAddAddresses(address[] _addresses) public onlyOwner {
        for (uint cnt = 0; cnt < _addresses.length; cnt++) {
            assert(!verifiedAddresses[_addresses[cnt]]);
            verifiedAddresses[_addresses[cnt]] = true;
        }
    }
}


/**
 * @title SwordCrowdsale
 * @dev This is Sword's crowdsale contract.
 */
contract SwordCrowdsale is Ownable {
    using SafeMath for uint256;

    // start and end timestamps where investments are allowed (both inclusive)
    uint256 public startTime;
    uint256 public endTime;
    // amount of raised money in wei
    uint256 public weiRaised;
    uint256 public limitDateSale; // end date in units

    bool public isSoftCapHit = false;
    bool public isStarted = false;
    bool public isFinalized = false;

   struct ContributorData {
        uint256 contributionAmount;
        uint256 tokensIssued;
    }

   address[] public tokenSendFailures;

    mapping(address => ContributorData) public contributorList;
    mapping(uint => address) contributorIndexes;
    uint nextContributorIndex;

    constructor() public {}

   function init(uint256 _totalTokens, uint256 _tokensForCrowdsale, address _wallet, 
        uint256 _etherInUSD, address _tokenAddress, uint256 _softCapInEthers, uint256 _hardCapInEthers, 
        uint _saleDurationInDays, address _kycAddress, uint bonus) onlyOwner public {

        setTotalTokens(_totalTokens);
        setTokensForCrowdSale(_tokensForCrowdsale);
        setWallet(_wallet);
        setRate(_etherInUSD);
        setTokenAddress(_tokenAddress);
        setSoftCap(_softCapInEthers);
        setHardCap(_hardCapInEthers);
        setSaleDuration(_saleDurationInDays);
        setKycAddress(_kycAddress);
        setSaleBonus(bonus);
        kyc = KycContract(_kycAddress);
        start(); // starting the crowdsale
   }

    /**
    * @dev Must be called to start the crowdsale
    */
    function start() onlyOwner public {
        require(!isStarted);
        require(!hasStarted());
        require(wallet != address(0));
        require(tokenAddress != address(0));
        require(kycAddress != address(0));
        require(rate != 0);
        require(saleDuration != 0);
        require(totalTokens != 0);
        require(tokensForCrowdSale != 0);
        require(softCap != 0);
        require(hardCap != 0);

        starting();
        emit SwordStarted();

        isStarted = true;
    }


   uint256 public totalTokens = 0;
   function setTotalTokens(uint256 _totalTokens) onlyOwner public {
       totalTokens = _totalTokens * (10 ** 18); // Total 1 billion tokens, 75 percent will be sold
   }

   uint256 public tokensForCrowdSale = 0;
   function setTokensForCrowdSale(uint256 _tokensForCrowdsale) onlyOwner public {
       tokensForCrowdSale = _tokensForCrowdsale * (10 ** 18); // Total 1 billion tokens, 75 percent will be sold 
   }

    // address where funds are collected
    address public wallet = 0x0;
    function setWallet(address _wallet) onlyOwner public {
        wallet = _wallet;
    } 

    uint256 public rate = 0;
    function setRate(uint256 _etherInUSD) public onlyOwner{
         rate = (5 * (10**18) / 100) / _etherInUSD;
    }

    // The token being sold
    SwordToken public token;
    address tokenAddress = 0x0; 
    function setTokenAddress(address _tokenAddress) public onlyOwner {
        tokenAddress = _tokenAddress; // to check if token address is provided at start
        token = SwordToken(_tokenAddress);
    }

   uint256 public softCap = 0;
   function setSoftCap(uint256 _softCap) onlyOwner public {
       softCap = _softCap * (10 ** 18); 
    }

   uint256 public hardCap = 0; 
   function setHardCap(uint256 _hardCap) onlyOwner public {
       hardCap = _hardCap * (10 ** 18); 
   }

    // sale period (includes holidays)
    uint public saleDuration = 0; // in days ex: 60.
    function setSaleDuration(uint _saleDurationInDays) onlyOwner public {
        saleDuration = _saleDurationInDays;
        limitDateSale = startTime + (saleDuration * 1 days);
        endTime = limitDateSale;
    }

    address kycAddress = 0x0;
    function setKycAddress(address _kycAddress) onlyOwner public {
        kycAddress = _kycAddress;
    }

    uint public saleBonus = 0; // ex. 10
    function setSaleBonus(uint bonus) public onlyOwner{
        saleBonus = bonus;
    }

   bool public isKYCRequiredToReceiveFunds = true; // whether Kyc is required to receive funds.
    function setKYCRequiredToReceiveFunds(bool IS_KYCRequiredToReceiveFunds) public onlyOwner{
        isKYCRequiredToReceiveFunds = IS_KYCRequiredToReceiveFunds;
    }

    bool public isKYCRequiredToSendTokens = true; // whether Kyc is required to send tokens.
      function setKYCRequiredToSendTokens(bool IS_KYCRequiredToSendTokens) public onlyOwner{
        isKYCRequiredToSendTokens = IS_KYCRequiredToSendTokens;
    }


    // fallback function can be used to buy tokens
    function () public payable {
        buyTokens(msg.sender);
    }

   KycContract public kyc;
   function transferKycOwnerShip(address _address) onlyOwner public {
       kyc.transferOwnership(_address);
   }

   function transferTokenOwnership(address _address) onlyOwner public {
       token.transferOwnership(_address);
   }

    /**
     * release Tokens
     */
    function releaseAllTokens() onlyOwner public {
        for(uint i=0; i < nextContributorIndex; i++) {
            address addressToSendTo = contributorIndexes[i]; // address of user
            releaseTokens(addressToSendTo);
        }
    }

    /**
     * release Tokens of an individual address
     */
    function releaseTokens(address _contributerAddress) onlyOwner public {
        if(isKYCRequiredToSendTokens){
             if(KycContractInterface(kycAddress).isAddressVerified(_contributerAddress)){ // if kyc needs to be checked at release time
                release(_contributerAddress);
             }
        } else {
            release(_contributerAddress);
        }
    }

    function release(address _contributerAddress) internal {
        if(contributorList[_contributerAddress].tokensIssued > 0) { 
            if(token.mint(_contributerAddress, contributorList[_contributerAddress].tokensIssued)) { // tokens sent successfully
                contributorList[_contributerAddress].tokensIssued = 0;
                contributorList[_contributerAddress].contributionAmount = 0;
            } else { // token sending failed, has to be processed manually
                tokenSendFailures.push(_contributerAddress);
            }
        }
    }

    function tokenSendFailuresCount() public view returns (uint) {
        return tokenSendFailures.length;
    }

    function buyTokens(address beneficiary) public payable {
        require(beneficiary != address(0));
        require(validPurchase());
        if(isKYCRequiredToReceiveFunds){
            require(KycContractInterface(kycAddress).isAddressVerified(msg.sender));
        }

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 tokens = computeTokens(weiAmount);

        require(isWithinTokenAllocLimit(tokens));

        // update state - Add to eth raised
        weiRaised = weiRaised.add(weiAmount);

        if (contributorList[beneficiary].contributionAmount == 0) { // if its a new contributor, add him and increase index
            contributorIndexes[nextContributorIndex] = beneficiary;
            nextContributorIndex += 1;
        }
        contributorList[beneficiary].contributionAmount += weiAmount;
        contributorList[beneficiary].tokensIssued += tokens;

        emit SwordTokenPurchase(msg.sender, beneficiary, weiAmount, tokens);
        handleFunds();
    }

      /**
    * event for token purchase logging
    * @param purchaser who paid for the tokens
    * @param beneficiary who got the tokens
    * @param value weis paid for purchase
    * @param amount amount of tokens purchased
    */
    event SwordTokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

    function investorCount() constant public returns(uint) {
        return nextContributorIndex;
    }

    // @return true if crowdsale event has started
    function hasStarted() public constant returns (bool) {
        return (startTime != 0 && now > startTime);
    }

    // send ether to the fund collection wallet
    function forwardFunds() internal {
        wallet.transfer(msg.value);
    }

     // send ether to the fund collection wallet
    function forwardAllRaisedFunds() internal {
        wallet.transfer(weiRaised);
    }

    function isWithinSaleTimeLimit() internal view returns (bool) {
        return now <= limitDateSale;
    }

    function isWithinSaleLimit(uint256 _tokens) internal view returns (bool) {
        return token.getTotalSupply().add(_tokens) <= tokensForCrowdSale;
    }

    function computeTokens(uint256 weiAmount) view internal returns (uint256) {
        uint256 appliedBonus = 0;
        if (isWithinSaleTimeLimit()) {
            appliedBonus = saleBonus;
        } 
        return (weiAmount.div(rate) + (weiAmount.div(rate).mul(appliedBonus).div(100))) * (10 ** 18);
    }

    function isWithinTokenAllocLimit(uint256 _tokens) view internal returns (bool) {
        return (isWithinSaleTimeLimit() && isWithinSaleLimit(_tokens));
    }

    function didSoftCapReached() internal returns (bool) {
        if(weiRaised >= softCap){
            isSoftCapHit = true; // setting the flag that soft cap is hit and all funds should be sent directly to wallet from now on.
        } else {
            isSoftCapHit = false;
        }
        return isSoftCapHit;
    }

    // overriding SwordBaseCrowdsale#validPurchase to add extra cap logic
    // @return true if investors can buy at the moment
    function validPurchase() internal constant returns (bool) {
        bool withinCap = weiRaised.add(msg.value) <= hardCap;
        bool withinPeriod = now >= startTime && now <= endTime; 
        bool nonZeroPurchase = msg.value != 0; 
        return (withinPeriod && nonZeroPurchase) && withinCap && isWithinSaleTimeLimit();
    }

    // overriding Crowdsale#hasEnded to add cap logic
    // @return true if crowdsale event has ended
    function hasEnded() public constant returns (bool) {
        bool capReached = weiRaised >= hardCap;
        return (endTime != 0 && now > endTime) || capReached;
    }



  event SwordStarted();
  event SwordFinalized();

  /**
   * @dev Must be called after crowdsale ends, to do some extra finalization
   * work. Calls the contract's finalization function.
   */
  function finalize() onlyOwner public {
    require(!isFinalized);
   // require(hasEnded());

    finalization();
    emit SwordFinalized();

    isFinalized = true;
  }

    function starting() internal {
        startTime = now;
        limitDateSale = startTime + (saleDuration * 1 days);
        endTime = limitDateSale;
    }

    function finalization() internal {
        uint256 remainingTokens = totalTokens.sub(token.getTotalSupply());
        token.mintFinalize(wallet, remainingTokens);
        forwardAllRaisedFunds(); 
    }

    // overridden
    function handleFunds() internal {
        if(isSoftCapHit){ // if soft cap is reached, start transferring funds immediately to wallet
            forwardFunds();  
        } else {
            if(didSoftCapReached()){    
                forwardAllRaisedFunds();            
            }
        }
    }

     modifier afterDeadline() { if (hasEnded() || isFinalized) _; } // a modifier to tell token sale ended 

  /**
     * auto refund Tokens
     */
    function refundAllMoney() onlyOwner public {
        for(uint i=0; i < nextContributorIndex; i++) {
            address addressToSendTo = contributorIndexes[i];
            refundMoney(addressToSendTo); 
        }
    }

    /**
     * refund Tokens of a single address
     */
    function refundMoney(address _address) onlyOwner public {
        uint amount = contributorList[_address].contributionAmount;
        if (amount > 0 && _address.send(amount)) { // user got money back
            contributorList[_address].contributionAmount =  0;
            contributorList[_address].tokensIssued =  0;
        } 
    }
}