ETH Price: $2,644.49 (+8.24%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Enter Arena58637332018-06-27 14:28:582323 days ago1530109738IN
0x6403670a...5313A2EC4
0 ETH0.000098481
Enter Arena58637252018-06-27 14:26:462323 days ago1530109606IN
0x6403670a...5313A2EC4
0 ETH0.00068947
Enter Arena58637252018-06-27 14:26:462323 days ago1530109606IN
0x6403670a...5313A2EC4
0 ETH0.0010833511
Enter Arena58637252018-06-27 14:26:462323 days ago1530109606IN
0x6403670a...5313A2EC4
0 ETH0.000590926
Enter Arena58095482018-06-18 7:05:292333 days ago1529305529IN
0x6403670a...5313A2EC4
0 ETH0.000650031
Enter Arena58095062018-06-18 6:56:222333 days ago1529304982IN
0x6403670a...5313A2EC4
0 ETH0.0008281
Enter Arena58094702018-06-18 6:48:512333 days ago1529304531IN
0x6403670a...5313A2EC4
0 ETH0.000649161
Enter Arena58094442018-06-18 6:43:212333 days ago1529304201IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58094182018-06-18 6:37:322333 days ago1529303852IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58093602018-06-18 6:20:012333 days ago1529302801IN
0x6403670a...5313A2EC4
0 ETH0.000865661
Enter Arena58093112018-06-18 6:05:192333 days ago1529301919IN
0x6403670a...5313A2EC4
0 ETH0.000944171.1
Enter Arena58090262018-06-18 4:57:032333 days ago1529297823IN
0x6403670a...5313A2EC4
0 ETH0.000649161
Enter Arena58089952018-06-18 4:50:432333 days ago1529297443IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58089052018-06-18 4:29:592333 days ago1529296199IN
0x6403670a...5313A2EC4
0 ETH0.000649161
Enter Arena58088692018-06-18 4:21:332333 days ago1529295693IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58088252018-06-18 4:10:042333 days ago1529295004IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58087672018-06-18 3:56:252333 days ago1529294185IN
0x6403670a...5313A2EC4
0 ETH0.000098481
Enter Arena58087612018-06-18 3:55:322333 days ago1529294132IN
0x6403670a...5313A2EC4
0 ETH0.000649161
Enter Arena58087212018-06-18 3:43:512333 days ago1529293431IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58086792018-06-18 3:33:582333 days ago1529292838IN
0x6403670a...5313A2EC4
0 ETH0.000649161
Enter Arena58086552018-06-18 3:28:062333 days ago1529292486IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58086162018-06-18 3:18:192333 days ago1529291899IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58085452018-06-18 2:59:182333 days ago1529290758IN
0x6403670a...5313A2EC4
0 ETH0.000649191
Enter Arena58085112018-06-18 2:50:552333 days ago1529290255IN
0x6403670a...5313A2EC4
0 ETH0.000832821
Enter Arena58084382018-06-18 2:34:202333 days ago1529289260IN
0x6403670a...5313A2EC4
0 ETH0.000649191
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CryptoSagaArenaVer1

Compiler Version
v0.4.18+commit.9cf6e910

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2018-06-07
*/

pragma solidity ^0.4.18;


/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {

  /**
  * @dev Multiplies two numbers, throws on overflow.
  */
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    assert(c / a == b);
    return c;
  }

  /**
  * @dev Integer division of two numbers, truncating the quotient.
  */
  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

  /**
  * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  */
  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  /**
  * @dev Adds two numbers, throws on overflow.
  */
  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }
}

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
  address public owner;


  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);


  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() public {
    owner = msg.sender;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }

  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) public onlyOwner {
    require(newOwner != address(0));
    OwnershipTransferred(owner, newOwner);
    owner = newOwner;
  }

}


/**
 * @title Claimable
 * @dev Extension for the Ownable contract, where the ownership needs to be claimed.
 * This allows the new owner to accept the transfer.
 */
contract Claimable is Ownable {
  address public pendingOwner;

  /**
   * @dev Modifier throws if called by any account other than the pendingOwner.
   */
  modifier onlyPendingOwner() {
    require(msg.sender == pendingOwner);
    _;
  }

  /**
   * @dev Allows the current owner to set the pendingOwner address.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner public {
    pendingOwner = newOwner;
  }

  /**
   * @dev Allows the pendingOwner address to finalize the transfer.
   */
  function claimOwnership() onlyPendingOwner public {
    OwnershipTransferred(owner, pendingOwner);
    owner = pendingOwner;
    pendingOwner = address(0);
  }
}


/**
 * @title Pausable
 * @dev Base contract which allows children to implement an emergency stop mechanism.
 */
contract Pausable is Ownable {
  event Pause();
  event Unpause();

  bool public paused = false;


  /**
   * @dev Modifier to make a function callable only when the contract is not paused.
   */
  modifier whenNotPaused() {
    require(!paused);
    _;
  }

  /**
   * @dev Modifier to make a function callable only when the contract is paused.
   */
  modifier whenPaused() {
    require(paused);
    _;
  }

  /**
   * @dev called by the owner to pause, triggers stopped state
   */
  function pause() onlyOwner whenNotPaused public {
    paused = true;
    Pause();
  }

  /**
   * @dev called by the owner to unpause, returns to normal state
   */
  function unpause() onlyOwner whenPaused public {
    paused = false;
    Unpause();
  }
}


/**
 * @title ERC721 interface
 * @dev see https://github.com/ethereum/eips/issues/721
 */
contract ERC721 {
  event Transfer(address indexed _from, address indexed _to, uint256 _tokenId);
  event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);

  function balanceOf(address _owner) public view returns (uint256 _balance);
  function ownerOf(uint256 _tokenId) public view returns (address _owner);
  function transfer(address _to, uint256 _tokenId) public;
  function approve(address _to, uint256 _tokenId) public;
  function takeOwnership(uint256 _tokenId) public;
}


/**
 * @title ERC721Token
 * Generic implementation for the required functionality of the ERC721 standard
 */
contract ERC721Token is ERC721 {
  using SafeMath for uint256;

  // Total amount of tokens
  uint256 private totalTokens;

  // Mapping from token ID to owner
  mapping (uint256 => address) private tokenOwner;

  // Mapping from token ID to approved address
  mapping (uint256 => address) private tokenApprovals;

  // Mapping from owner to list of owned token IDs
  mapping (address => uint256[]) private ownedTokens;

  // Mapping from token ID to index of the owner tokens list
  mapping(uint256 => uint256) private ownedTokensIndex;

  /**
  * @dev Guarantees msg.sender is owner of the given token
  * @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender
  */
  modifier onlyOwnerOf(uint256 _tokenId) {
    require(ownerOf(_tokenId) == msg.sender);
    _;
  }

  /**
  * @dev Gets the total amount of tokens stored by the contract
  * @return uint256 representing the total amount of tokens
  */
  function totalSupply() public view returns (uint256) {
    return totalTokens;
  }

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

  /**
  * @dev Gets the list of tokens owned by a given address
  * @param _owner address to query the tokens of
  * @return uint256[] representing the list of tokens owned by the passed address
  */
  function tokensOf(address _owner) public view returns (uint256[]) {
    return ownedTokens[_owner];
  }

  /**
  * @dev Gets the owner of the specified token ID
  * @param _tokenId uint256 ID of the token to query the owner of
  * @return owner address currently marked as the owner of the given token ID
  */
  function ownerOf(uint256 _tokenId) public view returns (address) {
    address owner = tokenOwner[_tokenId];
    require(owner != address(0));
    return owner;
  }

  /**
   * @dev Gets the approved address to take ownership of a given token ID
   * @param _tokenId uint256 ID of the token to query the approval of
   * @return address currently approved to take ownership of the given token ID
   */
  function approvedFor(uint256 _tokenId) public view returns (address) {
    return tokenApprovals[_tokenId];
  }

  /**
  * @dev Transfers the ownership of a given token ID to another address
  * @param _to address to receive the ownership of the given token ID
  * @param _tokenId uint256 ID of the token to be transferred
  */
  function transfer(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
    clearApprovalAndTransfer(msg.sender, _to, _tokenId);
  }

  /**
  * @dev Approves another address to claim for the ownership of the given token ID
  * @param _to address to be approved for the given token ID
  * @param _tokenId uint256 ID of the token to be approved
  */
  function approve(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
    address owner = ownerOf(_tokenId);
    require(_to != owner);
    if (approvedFor(_tokenId) != 0 || _to != 0) {
      tokenApprovals[_tokenId] = _to;
      Approval(owner, _to, _tokenId);
    }
  }

  /**
  * @dev Claims the ownership of a given token ID
  * @param _tokenId uint256 ID of the token being claimed by the msg.sender
  */
  function takeOwnership(uint256 _tokenId) public {
    require(isApprovedFor(msg.sender, _tokenId));
    clearApprovalAndTransfer(ownerOf(_tokenId), msg.sender, _tokenId);
  }

  /**
  * @dev Mint token function
  * @param _to The address that will own the minted token
  * @param _tokenId uint256 ID of the token to be minted by the msg.sender
  */
  function _mint(address _to, uint256 _tokenId) internal {
    require(_to != address(0));
    addToken(_to, _tokenId);
    Transfer(0x0, _to, _tokenId);
  }

  /**
  * @dev Burns a specific token
  * @param _tokenId uint256 ID of the token being burned by the msg.sender
  */
  function _burn(uint256 _tokenId) onlyOwnerOf(_tokenId) internal {
    if (approvedFor(_tokenId) != 0) {
      clearApproval(msg.sender, _tokenId);
    }
    removeToken(msg.sender, _tokenId);
    Transfer(msg.sender, 0x0, _tokenId);
  }

  /**
   * @dev Tells whether the msg.sender is approved for the given token ID or not
   * This function is not private so it can be extended in further implementations like the operatable ERC721
   * @param _owner address of the owner to query the approval of
   * @param _tokenId uint256 ID of the token to query the approval of
   * @return bool whether the msg.sender is approved for the given token ID or not
   */
  function isApprovedFor(address _owner, uint256 _tokenId) internal view returns (bool) {
    return approvedFor(_tokenId) == _owner;
  }

  /**
  * @dev Internal function to clear current approval and transfer the ownership of a given token ID
  * @param _from address which you want to send tokens from
  * @param _to address which you want to transfer the token to
  * @param _tokenId uint256 ID of the token to be transferred
  */
  function clearApprovalAndTransfer(address _from, address _to, uint256 _tokenId) internal {
    require(_to != address(0));
    require(_to != ownerOf(_tokenId));
    require(ownerOf(_tokenId) == _from);

    clearApproval(_from, _tokenId);
    removeToken(_from, _tokenId);
    addToken(_to, _tokenId);
    Transfer(_from, _to, _tokenId);
  }

  /**
  * @dev Internal function to clear current approval of a given token ID
  * @param _tokenId uint256 ID of the token to be transferred
  */
  function clearApproval(address _owner, uint256 _tokenId) private {
    require(ownerOf(_tokenId) == _owner);
    tokenApprovals[_tokenId] = 0;
    Approval(_owner, 0, _tokenId);
  }

  /**
  * @dev Internal function to add a token ID to the list of a given address
  * @param _to address representing the new owner of the given token ID
  * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
  */
  function addToken(address _to, uint256 _tokenId) private {
    require(tokenOwner[_tokenId] == address(0));
    tokenOwner[_tokenId] = _to;
    uint256 length = balanceOf(_to);
    ownedTokens[_to].push(_tokenId);
    ownedTokensIndex[_tokenId] = length;
    totalTokens = totalTokens.add(1);
  }

  /**
  * @dev Internal function to remove a token ID from the list of a given address
  * @param _from address representing the previous owner of the given token ID
  * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
  */
  function removeToken(address _from, uint256 _tokenId) private {
    require(ownerOf(_tokenId) == _from);

    uint256 tokenIndex = ownedTokensIndex[_tokenId];
    uint256 lastTokenIndex = balanceOf(_from).sub(1);
    uint256 lastToken = ownedTokens[_from][lastTokenIndex];

    tokenOwner[_tokenId] = 0;
    ownedTokens[_from][tokenIndex] = lastToken;
    ownedTokens[_from][lastTokenIndex] = 0;
    // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
    // be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
    // the lastToken to the first position, and then dropping the element placed in the last position of the list

    ownedTokens[_from].length--;
    ownedTokensIndex[_tokenId] = 0;
    ownedTokensIndex[lastToken] = tokenIndex;
    totalTokens = totalTokens.sub(1);
  }
}


/**
 * @title ERC20Basic
 * @dev Simpler version of ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/179
 */
contract ERC20Basic {
  function totalSupply() public view returns (uint256);
  function balanceOf(address who) public view 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 view 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);
}


/**
 * @title Basic token
 * @dev Basic version of StandardToken, with no allowances.
 */
contract BasicToken is ERC20Basic {
  using SafeMath for uint256;

  mapping(address => uint256) balances;

  uint256 totalSupply_;

  /**
  * @dev total number of tokens in existence
  */
  function totalSupply() public view returns (uint256) {
    return totalSupply_;
  }

  /**
  * @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));
    require(_value <= balances[msg.sender]);

    // SafeMath.sub will throw if there is not enough balance.
    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    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 view 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)) internal 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));
    require(_value <= balances[_from]);
    require(_value <= allowed[_from][msg.sender]);

    balances[_from] = balances[_from].sub(_value);
    balances[_to] = balances[_to].add(_value);
    allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
    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;
    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 view returns (uint256) {
    return allowed[_owner][_spender];
  }

  /**
   * @dev Increase the amount of tokens that an owner allowed to a 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
   * @param _spender The address which will spend the funds.
   * @param _addedValue The amount of tokens to increase the allowance by.
   */
  function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
    allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
    Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    return true;
  }

  /**
   * @dev Decrease the amount of tokens that an owner allowed to a spender.
   *
   * approve should be called when allowed[_spender] == 0. To decrement
   * allowed value is better to use this function to avoid 2 calls (and wait until
   * the first transaction is mined)
   * From MonolithDAO Token.sol
   * @param _spender The address which will spend the funds.
   * @param _subtractedValue The amount of tokens to decrease the allowance by.
   */
  function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
    uint oldValue = allowed[msg.sender][_spender];
    if (_subtractedValue > oldValue) {
      allowed[msg.sender][_spender] = 0;
    } else {
      allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
    }
    Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    return true;
  }

}


/**
 * @title AccessDeposit
 * @dev Adds grant/revoke functions to the contract.
 */
contract AccessDeposit is Claimable {

  // Access for adding deposit.
  mapping(address => bool) private depositAccess;

  // Modifier for accessibility to add deposit.
  modifier onlyAccessDeposit {
    require(msg.sender == owner || depositAccess[msg.sender] == true);
    _;
  }

  // @dev Grant acess to deposit heroes.
  function grantAccessDeposit(address _address)
    onlyOwner
    public
  {
    depositAccess[_address] = true;
  }

  // @dev Revoke acess to deposit heroes.
  function revokeAccessDeposit(address _address)
    onlyOwner
    public
  {
    depositAccess[_address] = false;
  }

}


/**
 * @title AccessDeploy
 * @dev Adds grant/revoke functions to the contract.
 */
contract AccessDeploy is Claimable {

  // Access for deploying heroes.
  mapping(address => bool) private deployAccess;

  // Modifier for accessibility to deploy a hero on a location.
  modifier onlyAccessDeploy {
    require(msg.sender == owner || deployAccess[msg.sender] == true);
    _;
  }

  // @dev Grant acess to deploy heroes.
  function grantAccessDeploy(address _address)
    onlyOwner
    public
  {
    deployAccess[_address] = true;
  }

  // @dev Revoke acess to deploy heroes.
  function revokeAccessDeploy(address _address)
    onlyOwner
    public
  {
    deployAccess[_address] = false;
  }

}

/**
 * @title AccessMint
 * @dev Adds grant/revoke functions to the contract.
 */
contract AccessMint is Claimable {

  // Access for minting new tokens.
  mapping(address => bool) private mintAccess;

  // Modifier for accessibility to define new hero types.
  modifier onlyAccessMint {
    require(msg.sender == owner || mintAccess[msg.sender] == true);
    _;
  }

  // @dev Grant acess to mint heroes.
  function grantAccessMint(address _address)
    onlyOwner
    public
  {
    mintAccess[_address] = true;
  }

  // @dev Revoke acess to mint heroes.
  function revokeAccessMint(address _address)
    onlyOwner
    public
  {
    mintAccess[_address] = false;
  }

}


/**
 * @title Gold
 * @dev ERC20 Token that can be minted.
 */
contract Gold is StandardToken, Claimable, AccessMint {

  string public constant name = "Gold";
  string public constant symbol = "G";
  uint8 public constant decimals = 18;

  // Event that is fired when minted.
  event Mint(
    address indexed _to,
    uint256 indexed _tokenId
  );

  // @dev Mint tokens with _amount to the address.
  function mint(address _to, uint256 _amount) 
    onlyAccessMint
    public 
    returns (bool) 
  {
    totalSupply_ = totalSupply_.add(_amount);
    balances[_to] = balances[_to].add(_amount);
    Mint(_to, _amount);
    Transfer(address(0), _to, _amount);
    return true;
  }

}


/**
 * @title CryptoSaga Card
 * @dev ERC721 Token that repesents CryptoSaga's cards.
 *  Buy consuming a card, players of CryptoSaga can get a heroe.
 */
contract CryptoSagaCard is ERC721Token, Claimable, AccessMint {

  string public constant name = "CryptoSaga Card";
  string public constant symbol = "CARD";

  // Rank of the token.
  mapping(uint256 => uint8) public tokenIdToRank;

  // The number of tokens ever minted.
  uint256 public numberOfTokenId;

  // The converter contract.
  CryptoSagaCardSwap private swapContract;

  // Event that should be fired when card is converted.
  event CardSwap(address indexed _by, uint256 _tokenId, uint256 _rewardId);

  // @dev Set the address of the contract that represents CryptoSaga Cards.
  function setCryptoSagaCardSwapContract(address _contractAddress)
    public
    onlyOwner
  {
    swapContract = CryptoSagaCardSwap(_contractAddress);
  }

  function rankOf(uint256 _tokenId) 
    public view
    returns (uint8)
  {
    return tokenIdToRank[_tokenId];
  }

  // @dev Mint a new card.
  function mint(address _beneficiary, uint256 _amount, uint8 _rank)
    onlyAccessMint
    public
  {
    for (uint256 i = 0; i < _amount; i++) {
      _mint(_beneficiary, numberOfTokenId);
      tokenIdToRank[numberOfTokenId] = _rank;
      numberOfTokenId ++;
    }
  }

  // @dev Swap this card for reward.
  //  The card will be burnt.
  function swap(uint256 _tokenId)
    onlyOwnerOf(_tokenId)
    public
    returns (uint256)
  {
    require(address(swapContract) != address(0));

    var _rank = tokenIdToRank[_tokenId];
    var _rewardId = swapContract.swapCardForReward(this, _rank);
    CardSwap(ownerOf(_tokenId), _tokenId, _rewardId);
    _burn(_tokenId);
    return _rewardId;
  }

}


/**
 * @title The interface contract for Card-For-Hero swap functionality.
 * @dev With this contract, a card holder can swap his/her CryptoSagaCard for reward.
 *  This contract is intended to be inherited by CryptoSagaCardSwap implementation contracts.
 */
contract CryptoSagaCardSwap is Ownable {

  // Card contract.
  address internal cardAddess;

  // Modifier for accessibility to define new hero types.
  modifier onlyCard {
    require(msg.sender == cardAddess);
    _;
  }
  
  // @dev Set the address of the contract that represents ERC721 Card.
  function setCardContract(address _contractAddress)
    public
    onlyOwner
  {
    cardAddess = _contractAddress;
  }

  // @dev Convert card into reward.
  //  This should be implemented by CryptoSagaCore later.
  function swapCardForReward(address _by, uint8 _rank)
    onlyCard
    public 
    returns (uint256);

}


/**
 * @title CryptoSagaHero
 * @dev The token contract for the hero.
 *  Also a superset of the ERC721 standard that allows for the minting
 *  of the non-fungible tokens.
 */
contract CryptoSagaHero is ERC721Token, Claimable, Pausable, AccessMint, AccessDeploy, AccessDeposit {

  string public constant name = "CryptoSaga Hero";
  string public constant symbol = "HERO";
  
  struct HeroClass {
    // ex) Soldier, Knight, Fighter...
    string className;
    // 0: Common, 1: Uncommon, 2: Rare, 3: Heroic, 4: Legendary.
    uint8 classRank;
    // 0: Human, 1: Celestial, 2: Demon, 3: Elf, 4: Dark Elf, 5: Yogoe, 6: Furry, 7: Dragonborn, 8: Undead, 9: Goblin, 10: Troll, 11: Slime, and more to come.
    uint8 classRace;
    // How old is this hero class? 
    uint32 classAge;
    // 0: Fighter, 1: Rogue, 2: Mage.
    uint8 classType;

    // Possible max level of this class.
    uint32 maxLevel; 
    // 0: Water, 1: Fire, 2: Nature, 3: Light, 4: Darkness.
    uint8 aura; 

    // Base stats of this hero type. 
    // 0: ATK	1: DEF 2: AGL	3: LUK 4: HP.
    uint32[5] baseStats;
    // Minimum IVs for stats. 
    // 0: ATK	1: DEF 2: AGL	3: LUK 4: HP.
    uint32[5] minIVForStats;
    // Maximum IVs for stats.
    // 0: ATK	1: DEF 2: AGL	3: LUK 4: HP.
    uint32[5] maxIVForStats;
    
    // Number of currently instanced heroes.
    uint32 currentNumberOfInstancedHeroes;
  }
    
  struct HeroInstance {
    // What is this hero's type? ex) John, Sally, Mark...
    uint32 heroClassId;
    
    // Individual hero's name.
    string heroName;
    
    // Current level of this hero.
    uint32 currentLevel;
    // Current exp of this hero.
    uint32 currentExp;

    // Where has this hero been deployed? (0: Never depolyed ever.) ex) Dungeon Floor #1, Arena #5...
    uint32 lastLocationId;
    // When a hero is deployed, it takes time for the hero to return to the base. This is in Unix epoch.
    uint256 availableAt;

    // Current stats of this hero. 
    // 0: ATK	1: DEF 2: AGL	3: LUK 4: HP.
    uint32[5] currentStats;
    // The individual value for this hero's stats. 
    // This will affect the current stats of heroes.
    // 0: ATK	1: DEF 2: AGL	3: LUK 4: HP.
    uint32[5] ivForStats;
  }

  // Required exp for level up will increase when heroes level up.
  // This defines how the value will increase.
  uint32 public requiredExpIncreaseFactor = 100;

  // Required Gold for level up will increase when heroes level up.
  // This defines how the value will increase.
  uint256 public requiredGoldIncreaseFactor = 1000000000000000000;

  // Existing hero classes.
  mapping(uint32 => HeroClass) public heroClasses;
  // The number of hero classes ever defined.
  uint32 public numberOfHeroClasses;

  // Existing hero instances.
  // The key is _tokenId.
  mapping(uint256 => HeroInstance) public tokenIdToHeroInstance;
  // The number of tokens ever minted. This works as the serial number.
  uint256 public numberOfTokenIds;

  // Gold contract.
  Gold public goldContract;

  // Deposit of players (in Gold).
  mapping(address => uint256) public addressToGoldDeposit;

  // Random seed.
  uint32 private seed = 0;

  // Event that is fired when a hero type defined.
  event DefineType(
    address indexed _by,
    uint32 indexed _typeId,
    string _className
  );

  // Event that is fired when a hero is upgraded.
  event LevelUp(
    address indexed _by,
    uint256 indexed _tokenId,
    uint32 _newLevel
  );

  // Event that is fired when a hero is deployed.
  event Deploy(
    address indexed _by,
    uint256 indexed _tokenId,
    uint32 _locationId,
    uint256 _duration
  );

  // @dev Get the class's entire infomation.
  function getClassInfo(uint32 _classId)
    external view
    returns (string className, uint8 classRank, uint8 classRace, uint32 classAge, uint8 classType, uint32 maxLevel, uint8 aura, uint32[5] baseStats, uint32[5] minIVs, uint32[5] maxIVs) 
  {
    var _cl = heroClasses[_classId];
    return (_cl.className, _cl.classRank, _cl.classRace, _cl.classAge, _cl.classType, _cl.maxLevel, _cl.aura, _cl.baseStats, _cl.minIVForStats, _cl.maxIVForStats);
  }

  // @dev Get the class's name.
  function getClassName(uint32 _classId)
    external view
    returns (string)
  {
    return heroClasses[_classId].className;
  }

  // @dev Get the class's rank.
  function getClassRank(uint32 _classId)
    external view
    returns (uint8)
  {
    return heroClasses[_classId].classRank;
  }

  // @dev Get the heroes ever minted for the class.
  function getClassMintCount(uint32 _classId)
    external view
    returns (uint32)
  {
    return heroClasses[_classId].currentNumberOfInstancedHeroes;
  }

  // @dev Get the hero's entire infomation.
  function getHeroInfo(uint256 _tokenId)
    external view
    returns (uint32 classId, string heroName, uint32 currentLevel, uint32 currentExp, uint32 lastLocationId, uint256 availableAt, uint32[5] currentStats, uint32[5] ivs, uint32 bp)
  {
    HeroInstance memory _h = tokenIdToHeroInstance[_tokenId];
    var _bp = _h.currentStats[0] + _h.currentStats[1] + _h.currentStats[2] + _h.currentStats[3] + _h.currentStats[4];
    return (_h.heroClassId, _h.heroName, _h.currentLevel, _h.currentExp, _h.lastLocationId, _h.availableAt, _h.currentStats, _h.ivForStats, _bp);
  }

  // @dev Get the hero's class id.
  function getHeroClassId(uint256 _tokenId)
    external view
    returns (uint32)
  {
    return tokenIdToHeroInstance[_tokenId].heroClassId;
  }

  // @dev Get the hero's name.
  function getHeroName(uint256 _tokenId)
    external view
    returns (string)
  {
    return tokenIdToHeroInstance[_tokenId].heroName;
  }

  // @dev Get the hero's level.
  function getHeroLevel(uint256 _tokenId)
    external view
    returns (uint32)
  {
    return tokenIdToHeroInstance[_tokenId].currentLevel;
  }
  
  // @dev Get the hero's location.
  function getHeroLocation(uint256 _tokenId)
    external view
    returns (uint32)
  {
    return tokenIdToHeroInstance[_tokenId].lastLocationId;
  }

  // @dev Get the time when the hero become available.
  function getHeroAvailableAt(uint256 _tokenId)
    external view
    returns (uint256)
  {
    return tokenIdToHeroInstance[_tokenId].availableAt;
  }

  // @dev Get the hero's BP.
  function getHeroBP(uint256 _tokenId)
    public view
    returns (uint32)
  {
    var _tmp = tokenIdToHeroInstance[_tokenId].currentStats;
    return (_tmp[0] + _tmp[1] + _tmp[2] + _tmp[3] + _tmp[4]);
  }

  // @dev Get the hero's required gold for level up.
  function getHeroRequiredGoldForLevelUp(uint256 _tokenId)
    public view
    returns (uint256)
  {
    return (uint256(2) ** (tokenIdToHeroInstance[_tokenId].currentLevel / 10)) * requiredGoldIncreaseFactor;
  }

  // @dev Get the hero's required exp for level up.
  function getHeroRequiredExpForLevelUp(uint256 _tokenId)
    public view
    returns (uint32)
  {
    return ((tokenIdToHeroInstance[_tokenId].currentLevel + 2) * requiredExpIncreaseFactor);
  }

  // @dev Get the deposit of gold of the player.
  function getGoldDepositOfAddress(address _address)
    external view
    returns (uint256)
  {
    return addressToGoldDeposit[_address];
  }

  // @dev Get the token id of the player's #th token.
  function getTokenIdOfAddressAndIndex(address _address, uint256 _index)
    external view
    returns (uint256)
  {
    return tokensOf(_address)[_index];
  }

  // @dev Get the total BP of the player.
  function getTotalBPOfAddress(address _address)
    external view
    returns (uint32)
  {
    var _tokens = tokensOf(_address);
    uint32 _totalBP = 0;
    for (uint256 i = 0; i < _tokens.length; i ++) {
      _totalBP += getHeroBP(_tokens[i]);
    }
    return _totalBP;
  }

  // @dev Set the hero's name.
  function setHeroName(uint256 _tokenId, string _name)
    onlyOwnerOf(_tokenId)
    public
  {
    tokenIdToHeroInstance[_tokenId].heroName = _name;
  }

  // @dev Set the address of the contract that represents ERC20 Gold.
  function setGoldContract(address _contractAddress)
    onlyOwner
    public
  {
    goldContract = Gold(_contractAddress);
  }

  // @dev Set the required golds to level up a hero.
  function setRequiredExpIncreaseFactor(uint32 _value)
    onlyOwner
    public
  {
    requiredExpIncreaseFactor = _value;
  }

  // @dev Set the required golds to level up a hero.
  function setRequiredGoldIncreaseFactor(uint256 _value)
    onlyOwner
    public
  {
    requiredGoldIncreaseFactor = _value;
  }

  // @dev Contructor.
  function CryptoSagaHero(address _goldAddress)
    public
  {
    require(_goldAddress != address(0));

    // Assign Gold contract.
    setGoldContract(_goldAddress);

    // Initial heroes.
    // Name, Rank, Race, Age, Type, Max Level, Aura, Stats.
    defineType("Archangel", 4, 1, 13540, 0, 99, 3, [uint32(74), 75, 57, 99, 95], [uint32(8), 6, 8, 5, 5], [uint32(8), 10, 10, 6, 6]);
    defineType("Shadowalker", 3, 4, 134, 1, 75, 4, [uint32(45), 35, 60, 80, 40], [uint32(3), 2, 10, 4, 5], [uint32(5), 5, 10, 7, 5]);
    defineType("Pyromancer", 2, 0, 14, 2, 50, 1, [uint32(50), 28, 17, 40, 35], [uint32(5), 3, 2, 3, 3], [uint32(8), 4, 3, 4, 5]);
    defineType("Magician", 1, 3, 224, 2, 30, 0, [uint32(35), 15, 25, 25, 30], [uint32(3), 1, 2, 2, 2], [uint32(5), 2, 3, 3, 3]);
    defineType("Farmer", 0, 0, 59, 0, 15, 2, [uint32(10), 22, 8, 15, 25], [uint32(1), 2, 1, 1, 2], [uint32(1), 3, 1, 2, 3]);
  }

  // @dev Define a new hero type (class).
  function defineType(string _className, uint8 _classRank, uint8 _classRace, uint32 _classAge, uint8 _classType, uint32 _maxLevel, uint8 _aura, uint32[5] _baseStats, uint32[5] _minIVForStats, uint32[5] _maxIVForStats)
    onlyOwner
    public
  {
    require(_classRank < 5);
    require(_classType < 3);
    require(_aura < 5);
    require(_minIVForStats[0] <= _maxIVForStats[0] && _minIVForStats[1] <= _maxIVForStats[1] && _minIVForStats[2] <= _maxIVForStats[2] && _minIVForStats[3] <= _maxIVForStats[3] && _minIVForStats[4] <= _maxIVForStats[4]);

    HeroClass memory _heroType = HeroClass({
      className: _className,
      classRank: _classRank,
      classRace: _classRace,
      classAge: _classAge,
      classType: _classType,
      maxLevel: _maxLevel,
      aura: _aura,
      baseStats: _baseStats,
      minIVForStats: _minIVForStats,
      maxIVForStats: _maxIVForStats,
      currentNumberOfInstancedHeroes: 0
    });

    // Save the hero class.
    heroClasses[numberOfHeroClasses] = _heroType;

    // Fire event.
    DefineType(msg.sender, numberOfHeroClasses, _heroType.className);

    // Increment number of hero classes.
    numberOfHeroClasses ++;

  }

  // @dev Mint a new hero, with _heroClassId.
  function mint(address _owner, uint32 _heroClassId)
    onlyAccessMint
    public
    returns (uint256)
  {
    require(_owner != address(0));
    require(_heroClassId < numberOfHeroClasses);

    // The information of the hero's class.
    var _heroClassInfo = heroClasses[_heroClassId];

    // Mint ERC721 token.
    _mint(_owner, numberOfTokenIds);

    // Build random IVs for this hero instance.
    uint32[5] memory _ivForStats;
    uint32[5] memory _initialStats;
    for (uint8 i = 0; i < 5; i++) {
      _ivForStats[i] = (random(_heroClassInfo.maxIVForStats[i] + 1, _heroClassInfo.minIVForStats[i]));
      _initialStats[i] = _heroClassInfo.baseStats[i] + _ivForStats[i];
    }

    // Temporary hero instance.
    HeroInstance memory _heroInstance = HeroInstance({
      heroClassId: _heroClassId,
      heroName: "",
      currentLevel: 1,
      currentExp: 0,
      lastLocationId: 0,
      availableAt: now,
      currentStats: _initialStats,
      ivForStats: _ivForStats
    });

    // Save the hero instance.
    tokenIdToHeroInstance[numberOfTokenIds] = _heroInstance;

    // Increment number of token ids.
    // This will only increment when new token is minted, and will never be decemented when the token is burned.
    numberOfTokenIds ++;

     // Increment instanced number of heroes.
    _heroClassInfo.currentNumberOfInstancedHeroes ++;

    return numberOfTokenIds - 1;
  }

  // @dev Set where the heroes are deployed, and when they will return.
  //  This is intended to be called by Dungeon, Arena, Guild contracts.
  function deploy(uint256 _tokenId, uint32 _locationId, uint256 _duration)
    onlyAccessDeploy
    public
    returns (bool)
  {
    // The hero should be possessed by anybody.
    require(ownerOf(_tokenId) != address(0));

    var _heroInstance = tokenIdToHeroInstance[_tokenId];

    // The character should be avaiable. 
    require(_heroInstance.availableAt <= now);

    _heroInstance.lastLocationId = _locationId;
    _heroInstance.availableAt = now + _duration;

    // As the hero has been deployed to another place, fire event.
    Deploy(msg.sender, _tokenId, _locationId, _duration);
  }

  // @dev Add exp.
  //  This is intended to be called by Dungeon, Arena, Guild contracts.
  function addExp(uint256 _tokenId, uint32 _exp)
    onlyAccessDeploy
    public
    returns (bool)
  {
    // The hero should be possessed by anybody.
    require(ownerOf(_tokenId) != address(0));

    var _heroInstance = tokenIdToHeroInstance[_tokenId];

    var _newExp = _heroInstance.currentExp + _exp;

    // Sanity check to ensure we don't overflow.
    require(_newExp == uint256(uint128(_newExp)));

    _heroInstance.currentExp += _newExp;

  }

  // @dev Add deposit.
  //  This is intended to be called by Dungeon, Arena, Guild contracts.
  function addDeposit(address _to, uint256 _amount)
    onlyAccessDeposit
    public
  {
    // Increment deposit.
    addressToGoldDeposit[_to] += _amount;
  }

  // @dev Level up the hero with _tokenId.
  //  This function is called by the owner of the hero.
  function levelUp(uint256 _tokenId)
    onlyOwnerOf(_tokenId) whenNotPaused
    public
  {

    // Hero instance.
    var _heroInstance = tokenIdToHeroInstance[_tokenId];

    // The character should be avaiable. (Should have already returned from the dungeons, arenas, etc.)
    require(_heroInstance.availableAt <= now);

    // The information of the hero's class.
    var _heroClassInfo = heroClasses[_heroInstance.heroClassId];

    // Hero shouldn't level up exceed its max level.
    require(_heroInstance.currentLevel < _heroClassInfo.maxLevel);

    // Required Exp.
    var requiredExp = getHeroRequiredExpForLevelUp(_tokenId);

    // Need to have enough exp.
    require(_heroInstance.currentExp >= requiredExp);

    // Required Gold.
    var requiredGold = getHeroRequiredGoldForLevelUp(_tokenId);

    // Owner of token.
    var _ownerOfToken = ownerOf(_tokenId);

    // Need to have enough Gold balance.
    require(addressToGoldDeposit[_ownerOfToken] >= requiredGold);

    // Increase Level.
    _heroInstance.currentLevel += 1;

    // Increase Stats.
    for (uint8 i = 0; i < 5; i++) {
      _heroInstance.currentStats[i] = _heroClassInfo.baseStats[i] + (_heroInstance.currentLevel - 1) * _heroInstance.ivForStats[i];
    }
    
    // Deduct exp.
    _heroInstance.currentExp -= requiredExp;

    // Deduct gold.
    addressToGoldDeposit[_ownerOfToken] -= requiredGold;

    // Fire event.
    LevelUp(msg.sender, _tokenId, _heroInstance.currentLevel);
  }

  // @dev Transfer deposit (with the allowance pattern.)
  function transferDeposit(uint256 _amount)
    whenNotPaused
    public
  {
    require(goldContract.allowance(msg.sender, this) >= _amount);

    // Send msg.sender's Gold to this contract.
    if (goldContract.transferFrom(msg.sender, this, _amount)) {
       // Increment deposit.
      addressToGoldDeposit[msg.sender] += _amount;
    }
  }

  // @dev Withdraw deposit.
  function withdrawDeposit(uint256 _amount)
    public
  {
    require(addressToGoldDeposit[msg.sender] >= _amount);

    // Send deposit of Golds to msg.sender. (Rather minting...)
    if (goldContract.transfer(msg.sender, _amount)) {
      // Decrement deposit.
      addressToGoldDeposit[msg.sender] -= _amount;
    }
  }

  // @dev return a pseudo random number between lower and upper bounds
  function random(uint32 _upper, uint32 _lower)
    private
    returns (uint32)
  {
    require(_upper > _lower);

    seed = uint32(keccak256(keccak256(block.blockhash(block.number), seed), now));
    return seed % (_upper - _lower) + _lower;
  }

}


/**
 * @title CryptoSagaCorrectedHeroStats
 * @dev Corrected hero stats is needed to fix the bug in hero stats.
 */
contract CryptoSagaCorrectedHeroStats {

  // The hero contract.
  CryptoSagaHero private heroContract;

  // @dev Constructor.
  function CryptoSagaCorrectedHeroStats(address _heroContractAddress)
    public
  {
    heroContract = CryptoSagaHero(_heroContractAddress);
  }

  // @dev Get the hero's stats and some other infomation.
  function getCorrectedStats(uint256 _tokenId)
    external view
    returns (uint32 currentLevel, uint32 currentExp, uint32[5] currentStats, uint32[5] ivs, uint32 bp)
  {
    var (, , _currentLevel, _currentExp, , , _currentStats, _ivs, ) = heroContract.getHeroInfo(_tokenId);
    
    if (_currentLevel != 1) {
      for (uint8 i = 0; i < 5; i ++) {
        _currentStats[i] += _ivs[i];
      }
    }

    var _bp = _currentStats[0] + _currentStats[1] + _currentStats[2] + _currentStats[3] + _currentStats[4];
    return (_currentLevel, _currentExp, _currentStats, _ivs, _bp);
  }

  // @dev Get corrected total BP of the address.
  function getCorrectedTotalBPOfAddress(address _address)
    external view
    returns (uint32)
  {
    var _balance = heroContract.balanceOf(_address);

    uint32 _totalBP = 0;

    for (uint256 i = 0; i < _balance; i ++) {
      var (, , _currentLevel, , , , _currentStats, _ivs, ) = heroContract.getHeroInfo(heroContract.getTokenIdOfAddressAndIndex(_address, i));
      if (_currentLevel != 1) {
        for (uint8 j = 0; j < 5; j ++) {
          _currentStats[j] += _ivs[j];
        }
      }
      _totalBP += (_currentStats[0] + _currentStats[1] + _currentStats[2] + _currentStats[3] + _currentStats[4]);
    }

    return _totalBP;
  }

  // @dev Get corrected total BP of the address.
  function getCorrectedTotalBPOfTokens(uint256[] _tokens)
    external view
    returns (uint32)
  {
    uint32 _totalBP = 0;

    for (uint256 i = 0; i < _tokens.length; i ++) {
      var (, , _currentLevel, , , , _currentStats, _ivs, ) = heroContract.getHeroInfo(_tokens[i]);
      if (_currentLevel != 1) {
        for (uint8 j = 0; j < 5; j ++) {
          _currentStats[j] += _ivs[j];
        }
      }
      _totalBP += (_currentStats[0] + _currentStats[1] + _currentStats[2] + _currentStats[3] + _currentStats[4]);
    }

    return _totalBP;
  }
}


/**
 * @title CryptoSagaArenaRecord
 * @dev The record of battles in the Arena.
 */
contract CryptoSagaArenaRecord is Pausable, AccessDeploy {

  // Number of players for the leaderboard.
  uint8 public numberOfLeaderboardPlayers = 25;

  // Top players in the leaderboard.
  address[] public leaderBoardPlayers;

  // For checking whether the player is in the leaderboard.
  mapping(address => bool) public addressToIsInLeaderboard;

  // Number of recent player recorded for matchmaking.
  uint8 public numberOfRecentPlayers = 50;

  // List of recent players.
  address[] public recentPlayers;

  // Front of recent players.
  uint256 public recentPlayersFront;

  // Back of recent players.
  uint256 public recentPlayersBack;

  // Record of each player.
  mapping(address => uint32) public addressToElo;

  // Event that is fired when a new change has been made to the leaderboard.
  event UpdateLeaderboard(
    address indexed _by,
    uint256 _dateTime
  );

  // @dev Get elo rating of a player.
  function getEloRating(address _address)
    external view
    returns (uint32)
  {
    if (addressToElo[_address] != 0)
      return addressToElo[_address];
    else
      return 1500;
  }

  // @dev Get players in the leaderboard.
  function getLeaderboardPlayers()
    external view
    returns (address[])
  {
    return leaderBoardPlayers;
  }

  // @dev Get current length of the leaderboard.
  function getLeaderboardLength()
    external view
    returns (uint256)
  {
    return leaderBoardPlayers.length;
  }

  // @dev Get recently played players.
  function getRecentPlayers()
    external view
    returns (address[])
  {
    return recentPlayers;
  }

  // @dev Get current number of players in the recently played players queue.
  function getRecentPlayersCount()
    public view
    returns (uint256) 
  {
    return recentPlayersBack - recentPlayersFront;
  }

  // @dev Constructor.
  function CryptoSagaArenaRecord(
    address _firstPlayerAddress,
    uint32 _firstPlayerElo, 
    uint8 _numberOfLeaderboardPlayers, 
    uint8 _numberOfRecentPlayers)
    public
  {

    numberOfLeaderboardPlayers = _numberOfLeaderboardPlayers;
    numberOfRecentPlayers = _numberOfRecentPlayers;

    // The initial player gets into leaderboard.
    leaderBoardPlayers.push(_firstPlayerAddress);
    addressToIsInLeaderboard[_firstPlayerAddress] = true;

    // The initial player pushed into the recent players queue. 
    pushPlayer(_firstPlayerAddress);
    
    // The initial player's Elo.
    addressToElo[_firstPlayerAddress] = _firstPlayerElo;
  }

  // @dev Update record.
  function updateRecord(address _myAddress, address _enemyAddress, bool _didWin)
    whenNotPaused onlyAccessDeploy
    public
  {
    address _winnerAddress = _didWin? _myAddress: _enemyAddress;
    address _loserAddress = _didWin? _enemyAddress: _myAddress;
    
    // Initial value of Elo.
    uint32 _winnerElo = addressToElo[_winnerAddress];
    if (_winnerElo == 0)
      _winnerElo = 1500;
    uint32 _loserElo = addressToElo[_loserAddress];
    if (_loserElo == 0)
      _loserElo = 1500;

    // Adjust Elo.
    if (_winnerElo >= _loserElo) {
      if (_winnerElo - _loserElo < 50) {
        addressToElo[_winnerAddress] = _winnerElo + 5;
        addressToElo[_loserAddress] = _loserElo - 5;
      } else if (_winnerElo - _loserElo < 80) {
        addressToElo[_winnerAddress] = _winnerElo + 4;
        addressToElo[_loserAddress] = _loserElo - 4;
      } else if (_winnerElo - _loserElo < 150) {
        addressToElo[_winnerAddress] = _winnerElo + 3;
        addressToElo[_loserAddress] = _loserElo - 3;
      } else if (_winnerElo - _loserElo < 250) {
        addressToElo[_winnerAddress] = _winnerElo + 2;
        addressToElo[_loserAddress] = _loserElo - 2;
      } else {
        addressToElo[_winnerAddress] = _winnerElo + 1;
        addressToElo[_loserAddress] = _loserElo - 1;
      }
    } else {
      if (_loserElo - _winnerElo < 50) {
        addressToElo[_winnerAddress] = _winnerElo + 5;
        addressToElo[_loserAddress] = _loserElo - 5;
      } else if (_loserElo - _winnerElo < 80) {
        addressToElo[_winnerAddress] = _winnerElo + 6;
        addressToElo[_loserAddress] = _loserElo - 6;
      } else if (_loserElo - _winnerElo < 150) {
        addressToElo[_winnerAddress] = _winnerElo + 7;
        addressToElo[_loserAddress] = _loserElo - 7;
      } else if (_loserElo - _winnerElo < 250) {
        addressToElo[_winnerAddress] = _winnerElo + 8;
        addressToElo[_loserAddress] = _loserElo - 8;
      } else {
        addressToElo[_winnerAddress] = _winnerElo + 9;
        addressToElo[_loserAddress] = _loserElo - 9;
      }
    }

    // Update recent players list.
    if (!isPlayerInQueue(_myAddress)) {
      
      // If the queue is full, pop a player.
      if (getRecentPlayersCount() >= numberOfRecentPlayers)
        popPlayer();
      
      // Push _myAddress to the queue.
      pushPlayer(_myAddress);
    }

    // Update leaderboards.
    if(updateLeaderboard(_enemyAddress) || updateLeaderboard(_myAddress))
    {
      UpdateLeaderboard(_myAddress, now);
    }

  }

  // @dev Update leaderboard.
  function updateLeaderboard(address _addressToUpdate)
    whenNotPaused
    private
    returns (bool isChanged)
  {

    // If this players is already in the leaderboard, there's no need for replace the minimum recorded player.
    if (addressToIsInLeaderboard[_addressToUpdate]) {
      // Do nothing.
    } else {
      if (leaderBoardPlayers.length >= numberOfLeaderboardPlayers) {
        
        // Need to replace existing player.
        // First, we need to find the player with miminum Elo value.
        uint32 _minimumElo = 99999;
        uint8 _minimumEloPlayerIndex = numberOfLeaderboardPlayers;
        for (uint8 i = 0; i < leaderBoardPlayers.length; i ++) {
          if (_minimumElo > addressToElo[leaderBoardPlayers[i]]) {
            _minimumElo = addressToElo[leaderBoardPlayers[i]];
            _minimumEloPlayerIndex = i;
          }
        }

        // Second, if the minimum elo value is smaller than the player's elo value, then replace the entity.
        if (_minimumElo <= addressToElo[_addressToUpdate]) {
          leaderBoardPlayers[_minimumEloPlayerIndex] = _addressToUpdate;
          addressToIsInLeaderboard[_addressToUpdate] = true;
          addressToIsInLeaderboard[leaderBoardPlayers[_minimumEloPlayerIndex]] = false;
          isChanged = true;
        }
      } else {
        // The list is not full yet. 
        // Just add the player to the list.
        leaderBoardPlayers.push(_addressToUpdate);
        addressToIsInLeaderboard[_addressToUpdate] = true;
        isChanged = true;
      }
    }
  }

  // #dev Check whether contain the element or not.
  function isPlayerInQueue(address _player)
    view private
    returns (bool isContain)
  {
    isContain = false;
    for (uint256 i = recentPlayersFront; i < recentPlayersBack; i++) {
      if (_player == recentPlayers[i]) {
        isContain = true;
      }
    }
  }
    
  // @dev Push a new player into the queue.
  function pushPlayer(address _player)
    private
  {
    recentPlayers.push(_player);
    recentPlayersBack++;
  }
    
  // @dev Pop the oldest player in this queue.
  function popPlayer() 
    private
    returns (address player)
  {
    if (recentPlayersBack == recentPlayersFront)
      return address(0);
    player = recentPlayers[recentPlayersFront];
    delete recentPlayers[recentPlayersFront];
    recentPlayersFront++;
  }

}


/**
 * @title CryptoSagaArenaVer1
 * @dev The actual gameplay is done by this contract. Version 1.0.0.
 */
contract CryptoSagaArenaVer1 is Claimable, Pausable {

  struct PlayRecord {
    // This is needed for reconstructing the record.
    uint32 initialSeed;
    // The address of the enemy player.
    address enemyAddress;
    // Hero's token ids.
    uint256[4] tokenIds;
    // Unit's class ids. 0 ~ 3: Heroes. 4 ~ 7: Mobs.
    uint32[8] unitClassIds;
    // Unit's levels. 0 ~ 3: Heroes. 4 ~ 7: Mobs.
    uint32[8] unitLevels;
    // Exp reward given.
    uint32 expReward;
    // Gold Reward given.
    uint256 goldReward;
  }

  // This information can be reconstructed with seed and dateTime.
  // For the optimization this won't be really used.
  struct TurnInfo {
    // Number of turns before a team was vanquished.
    uint8 turnLength;
    // Turn order of units.
    uint8[8] turnOrder;
    // Defender list. (The unit that is attacked.)
    uint8[24] defenderList;
    // Damage list. (The damage given to the defender.)
    uint32[24] damageList;
    // Heroes' original Exps.
    uint32[4] originalExps;
  }

  // Progress contract.
  CryptoSagaArenaRecord private recordContract;

  // The hero contract.
  CryptoSagaHero private heroContract;

  // Corrected hero stats contract.
  CryptoSagaCorrectedHeroStats private correctedHeroContract;

  // Gold contract.
  Gold public goldContract;

  // Card contract.
  CryptoSagaCard public cardContract;

  // The location Id of this contract.
  // Will be used when calling deploy function of hero contract.
  uint32 public locationId = 100;

  // Hero cooldown time. (Default value: 60 mins.)
  uint256 public coolHero = 3600;

  // The exp reward for fighting in this arena.
  uint32 public expReward = 100;

  // The Gold reward when fighting in this arena.
  uint256 public goldReward = 1000000000000000000;

  // Should this contract save the turn data?
  bool public isTurnDataSaved = true;

  // Last game's record of the player.
  mapping(address => PlayRecord) public addressToPlayRecord;

  // Additional information on last game's record of the player.
  mapping(address => TurnInfo) public addressToTurnInfo;

  // Random seed.
  uint32 private seed = 0;

  // Event that is fired when a player fights in this arena.
  event TryArena(
    address indexed _by,
    address indexed _against,
    bool _didWin
  );

  // @dev Get previous game record.
  function getPlayRecord(address _address)
    external view
    returns (uint32, address, uint256[4], uint32[8], uint32[8], uint32, uint256, uint8, uint8[8], uint8[24], uint32[24])
  {
    PlayRecord memory _p = addressToPlayRecord[_address];
    TurnInfo memory _t = addressToTurnInfo[_address];
    return (
      _p.initialSeed,
      _p.enemyAddress,
      _p.tokenIds,
      _p.unitClassIds,
      _p.unitLevels,
      _p.expReward,
      _p.goldReward,
      _t.turnLength,
      _t.turnOrder,
      _t.defenderList,
      _t.damageList
    );
  }

  // @dev Get previous game record.
  function getPlayRecordNoTurnData(address _address)
    external view
    returns (uint32, address, uint256[4], uint32[8], uint32[8], uint32, uint256)
  {
    PlayRecord memory _p = addressToPlayRecord[_address];
    return (
      _p.initialSeed,
      _p.enemyAddress,
      _p.tokenIds,
      _p.unitClassIds,
      _p.unitLevels,
      _p.expReward,
      _p.goldReward
      );
  }

  // @dev Set location id.
  function setLocationId(uint32 _value)
    onlyOwner
    public
  {
    locationId = _value;
  }

  // @dev Set cooldown of heroes entered this arena.
  function setCoolHero(uint32 _value)
    onlyOwner
    public
  {
    coolHero = _value;
  }

  // @dev Set the Exp given to the player for fighting in this arena.
  function setExpReward(uint32 _value)
    onlyOwner
    public
  {
    expReward = _value;
  }

  // @dev Set the Golds given to the player for fighting in this arena.
  function setGoldReward(uint256 _value)
    onlyOwner
    public
  {
    goldReward = _value;
  }

  // @dev Set wether the turn data saved or not.
  function setIsTurnDataSaved(bool _value)
    onlyOwner
    public
  {
    isTurnDataSaved = _value;
  }

  // @dev Constructor.
  function CryptoSagaArenaVer1(
    address _recordContractAddress,
    address _heroContractAddress,
    address _correctedHeroContractAddress,
    address _cardContractAddress,
    address _goldContractAddress,
    address _firstPlayerAddress,
    uint32 _locationId,
    uint256 _coolHero,
    uint32 _expReward,
    uint256 _goldReward,
    bool _isTurnDataSaved)
    public
  {
    recordContract = CryptoSagaArenaRecord(_recordContractAddress);
    heroContract = CryptoSagaHero(_heroContractAddress);
    correctedHeroContract = CryptoSagaCorrectedHeroStats(_correctedHeroContractAddress);
    cardContract = CryptoSagaCard(_cardContractAddress);
    goldContract = Gold(_goldContractAddress);

    // Save first player's record.
    // This is for preventing errors.
    PlayRecord memory _playRecord;
    _playRecord.initialSeed = seed;
    _playRecord.enemyAddress = _firstPlayerAddress;
    _playRecord.tokenIds[0] = 1;
    _playRecord.tokenIds[1] = 2;
    _playRecord.tokenIds[2] = 3;
    _playRecord.tokenIds[3] = 4;
    addressToPlayRecord[_firstPlayerAddress] = _playRecord;
    
    locationId = _locationId;
    coolHero = _coolHero;
    expReward = _expReward;
    goldReward = _goldReward;
    
    isTurnDataSaved = _isTurnDataSaved;
  }
  
  // @dev Enter this arena.
  function enterArena(uint256[4] _tokenIds, address _enemyAddress)
    whenNotPaused
    public
  {

    // Shouldn't fight against self.
    require(msg.sender != _enemyAddress);

    // Each hero should be with different ids.
    require(_tokenIds[0] == 0 || (_tokenIds[0] != _tokenIds[1] && _tokenIds[0] != _tokenIds[2] && _tokenIds[0] != _tokenIds[3]));
    require(_tokenIds[1] == 0 || (_tokenIds[1] != _tokenIds[0] && _tokenIds[1] != _tokenIds[2] && _tokenIds[1] != _tokenIds[3]));
    require(_tokenIds[2] == 0 || (_tokenIds[2] != _tokenIds[0] && _tokenIds[2] != _tokenIds[1] && _tokenIds[2] != _tokenIds[3]));
    require(_tokenIds[3] == 0 || (_tokenIds[3] != _tokenIds[0] && _tokenIds[3] != _tokenIds[1] && _tokenIds[3] != _tokenIds[2]));

    // Check ownership and availability of the heroes.
    require(checkOwnershipAndAvailability(msg.sender, _tokenIds));

    // The play record of the enemy should exist.
    // The check is done with the enemy's enemy address, because the default value of it will be address(0).
    require(addressToPlayRecord[_enemyAddress].enemyAddress != address(0));

    // Set seed.
    seed += uint32(now);

    // Define play record here.
    PlayRecord memory _playRecord;
    _playRecord.initialSeed = seed;
    _playRecord.enemyAddress = _enemyAddress;
    _playRecord.tokenIds[0] = _tokenIds[0];
    _playRecord.tokenIds[1] = _tokenIds[1];
    _playRecord.tokenIds[2] = _tokenIds[2];
    _playRecord.tokenIds[3] = _tokenIds[3];

    // The information that can give additional information.
    TurnInfo memory _turnInfo;

    // Step 1: Retrieve Hero information (0 ~ 3) & Enemy information (4 ~ 7).

    uint32[5][8] memory _unitStats; // Stats of units for given levels and class ids.
    uint8[2][8] memory _unitTypesAuras; // 0: Types of units for given levels and class ids. 1: Auras of units for given levels and class ids.

    // Retrieve deployed hero information.
    if (_tokenIds[0] != 0) {
      _playRecord.unitClassIds[0] = heroContract.getHeroClassId(_tokenIds[0]);
      (_playRecord.unitLevels[0], _turnInfo.originalExps[0], _unitStats[0], , ) = correctedHeroContract.getCorrectedStats(_tokenIds[0]);
      (, , , , _unitTypesAuras[0][0], , _unitTypesAuras[0][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[0]);
    }
    if (_tokenIds[1] != 0) {
      _playRecord.unitClassIds[1] = heroContract.getHeroClassId(_tokenIds[1]);
      (_playRecord.unitLevels[1], _turnInfo.originalExps[1], _unitStats[1], , ) = correctedHeroContract.getCorrectedStats(_tokenIds[1]);
      (, , , , _unitTypesAuras[1][0], , _unitTypesAuras[1][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[1]);
    }
    if (_tokenIds[2] != 0) {
      _playRecord.unitClassIds[2] = heroContract.getHeroClassId(_tokenIds[2]);
      (_playRecord.unitLevels[2], _turnInfo.originalExps[2], _unitStats[2], , ) = correctedHeroContract.getCorrectedStats(_tokenIds[2]);
      (, , , , _unitTypesAuras[2][0], , _unitTypesAuras[2][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[2]);
    }
    if (_tokenIds[3] != 0) {
      _playRecord.unitClassIds[3] = heroContract.getHeroClassId(_tokenIds[3]);
      (_playRecord.unitLevels[3], _turnInfo.originalExps[3], _unitStats[3], , ) = correctedHeroContract.getCorrectedStats(_tokenIds[3]);
      (, , , , _unitTypesAuras[3][0], , _unitTypesAuras[3][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[3]);
    }

    // Retrieve enemy information.
    PlayRecord memory _enemyPlayRecord = addressToPlayRecord[_enemyAddress];
    if (_enemyPlayRecord.tokenIds[0] != 0) {
      _playRecord.unitClassIds[4] = heroContract.getHeroClassId(_enemyPlayRecord.tokenIds[0]);
      (_playRecord.unitLevels[4], , _unitStats[4], , ) = correctedHeroContract.getCorrectedStats(_enemyPlayRecord.tokenIds[0]);
      (, , , , _unitTypesAuras[4][0], , _unitTypesAuras[4][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[4]);
    }
    if (_enemyPlayRecord.tokenIds[1] != 0) {
      _playRecord.unitClassIds[5] = heroContract.getHeroClassId(_enemyPlayRecord.tokenIds[1]);
      (_playRecord.unitLevels[5], , _unitStats[5], , ) = correctedHeroContract.getCorrectedStats(_enemyPlayRecord.tokenIds[1]);
      (, , , , _unitTypesAuras[5][0], , _unitTypesAuras[5][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[5]);
    }
    if (_enemyPlayRecord.tokenIds[2] != 0) {
      _playRecord.unitClassIds[6] = heroContract.getHeroClassId(_enemyPlayRecord.tokenIds[2]);
      (_playRecord.unitLevels[6], , _unitStats[6], , ) = correctedHeroContract.getCorrectedStats(_enemyPlayRecord.tokenIds[2]);
      (, , , , _unitTypesAuras[6][0], , _unitTypesAuras[6][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[6]);
    }
    if (_enemyPlayRecord.tokenIds[3] != 0) {
      _playRecord.unitClassIds[7] = heroContract.getHeroClassId(_enemyPlayRecord.tokenIds[3]);
      (_playRecord.unitLevels[7], , _unitStats[7], , ) = correctedHeroContract.getCorrectedStats(_enemyPlayRecord.tokenIds[3]);
      (, , , , _unitTypesAuras[7][0], , _unitTypesAuras[7][1], , , ) = heroContract.getClassInfo(_playRecord.unitClassIds[7]);
    }

    // Step 2. Run the battle logic.
    
    // Firstly, we need to assign the unit's turn order with AGLs of the units.
    uint32[8] memory _unitAGLs;
    for (uint8 i = 0; i < 8; i ++) {
      _unitAGLs[i] = _unitStats[i][2];
    }
    _turnInfo.turnOrder = getOrder(_unitAGLs);
    
    // Fight for 24 turns. (8 units x 3 rounds.)
    _turnInfo.turnLength = 24;
    for (i = 0; i < 24; i ++) {
      if (_unitStats[4][4] == 0 && _unitStats[5][4] == 0 && _unitStats[6][4] == 0 && _unitStats[7][4] == 0) {
        _turnInfo.turnLength = i;
        break;
      } else if (_unitStats[0][4] == 0 && _unitStats[1][4] == 0 && _unitStats[2][4] == 0 && _unitStats[3][4] == 0) {
        _turnInfo.turnLength = i;
        break;
      }
      
      var _slotId = _turnInfo.turnOrder[(i % 8)];
      if (_slotId < 4 && _tokenIds[_slotId] == 0) {
        // This means the slot is empty.
        // Defender should be default value.
        _turnInfo.defenderList[i] = 127;
      } else if (_unitStats[_slotId][4] == 0) {
        // This means the unit on this slot is dead.
        // Defender should be default value.
        _turnInfo.defenderList[i] = 128;
      } else {
        // 1) Check number of attack targets that are alive.
        uint8 _targetSlotId = 255;
        if (_slotId < 4) {
          if (_unitStats[4][4] > 0)
            _targetSlotId = 4;
          else if (_unitStats[5][4] > 0)
            _targetSlotId = 5;
          else if (_unitStats[6][4] > 0)
            _targetSlotId = 6;
          else if (_unitStats[7][4] > 0)
            _targetSlotId = 7;
        } else {
          if (_unitStats[0][4] > 0)
            _targetSlotId = 0;
          else if (_unitStats[1][4] > 0)
            _targetSlotId = 1;
          else if (_unitStats[2][4] > 0)
            _targetSlotId = 2;
          else if (_unitStats[3][4] > 0)
            _targetSlotId = 3;
        }
        
        // Target is the defender.
        _turnInfo.defenderList[i] = _targetSlotId;
        
        // Base damage. (Attacker's ATK * 1.5 - Defender's DEF).
        uint32 _damage = 10;
        if ((_unitStats[_slotId][0] * 150 / 100) > _unitStats[_targetSlotId][1])
          _damage = max((_unitStats[_slotId][0] * 150 / 100) - _unitStats[_targetSlotId][1], 10);
        else
          _damage = 10;

        // Check miss / success.
        if ((_unitStats[_slotId][3] * 150 / 100) > _unitStats[_targetSlotId][2]) {
          if (min(max(((_unitStats[_slotId][3] * 150 / 100) - _unitStats[_targetSlotId][2]), 75), 99) <= random(100, 0))
            _damage = _damage * 0;
        }
        else {
          if (75 <= random(100, 0))
            _damage = _damage * 0;
        }

        // Is the attack critical?
        if (_unitStats[_slotId][3] > _unitStats[_targetSlotId][3]) {
          if (min(max((_unitStats[_slotId][3] - _unitStats[_targetSlotId][3]), 5), 75) > random(100, 0))
            _damage = _damage * 150 / 100;
        }
        else {
          if (5 > random(100, 0))
            _damage = _damage * 150 / 100;
        }

        // Is attacker has the advantageous Type?
        if (_unitTypesAuras[_slotId][0] == 0 && _unitTypesAuras[_targetSlotId][0] == 1) // Fighter > Rogue
          _damage = _damage * 125 / 100;
        else if (_unitTypesAuras[_slotId][0] == 1 && _unitTypesAuras[_targetSlotId][0] == 2) // Rogue > Mage
          _damage = _damage * 125 / 100;
        else if (_unitTypesAuras[_slotId][0] == 2 && _unitTypesAuras[_targetSlotId][0] == 0) // Mage > Fighter
          _damage = _damage * 125 / 100;

        // Is attacker has the advantageous Aura?
        if (_unitTypesAuras[_slotId][1] == 0 && _unitTypesAuras[_targetSlotId][1] == 1) // Water > Fire
          _damage = _damage * 150 / 100;
        else if (_unitTypesAuras[_slotId][1] == 1 && _unitTypesAuras[_targetSlotId][1] == 2) // Fire > Nature
          _damage = _damage * 150 / 100;
        else if (_unitTypesAuras[_slotId][1] == 2 && _unitTypesAuras[_targetSlotId][1] == 0) // Nature > Water
          _damage = _damage * 150 / 100;
        else if (_unitTypesAuras[_slotId][1] == 3 && _unitTypesAuras[_targetSlotId][1] == 4) // Light > Darkness
          _damage = _damage * 150 / 100;
        else if (_unitTypesAuras[_slotId][1] == 4 && _unitTypesAuras[_targetSlotId][1] == 3) // Darkness > Light
          _damage = _damage * 150 / 100;
        
        // Apply damage so that reduce hp of defender.
        if(_unitStats[_targetSlotId][4] > _damage)
          _unitStats[_targetSlotId][4] -= _damage;
        else
          _unitStats[_targetSlotId][4] = 0;

        // Save damage to play record.
        _turnInfo.damageList[i] = _damage;
      }
    }
    
    // Step 3. Apply the result of this battle.

    // Set heroes deployed.
    if (_tokenIds[0] != 0)
      heroContract.deploy(_tokenIds[0], locationId, coolHero);
    if (_tokenIds[1] != 0)
      heroContract.deploy(_tokenIds[1], locationId, coolHero);
    if (_tokenIds[2] != 0)
      heroContract.deploy(_tokenIds[2], locationId, coolHero);
    if (_tokenIds[3] != 0)
      heroContract.deploy(_tokenIds[3], locationId, coolHero);

    uint8 _deadHeroes = 0;
    uint8 _deadEnemies = 0;

    // Check result.
    if (_unitStats[0][4] == 0)
      _deadHeroes ++;
    if (_unitStats[1][4] == 0)
      _deadHeroes ++;
    if (_unitStats[2][4] == 0)
      _deadHeroes ++;
    if (_unitStats[3][4] == 0)
      _deadHeroes ++;
    if (_unitStats[4][4] == 0)
      _deadEnemies ++;
    if (_unitStats[5][4] == 0)
      _deadEnemies ++;
    if (_unitStats[6][4] == 0)
      _deadEnemies ++;
    if (_unitStats[7][4] == 0)
      _deadEnemies ++;
      
    if (_deadEnemies > _deadHeroes) { // Win
      // Fire TryArena event.
      TryArena(msg.sender, _enemyAddress, true);
      
      // Give reward.
      (_playRecord.expReward, _playRecord.goldReward) = giveReward(_tokenIds, true, _turnInfo.originalExps);

      // Save the record.
      recordContract.updateRecord(msg.sender, _enemyAddress, true);
    }
    else if (_deadEnemies < _deadHeroes) { // Lose
      // Fire TryArena event.
      TryArena(msg.sender, _enemyAddress, false);

      // Rewards.
      (_playRecord.expReward, _playRecord.goldReward) = giveReward(_tokenIds, false, _turnInfo.originalExps);

      // Save the record.
      recordContract.updateRecord(msg.sender, _enemyAddress, false);
    }
    else { // Draw
      // Fire TryArena event.
      TryArena(msg.sender, _enemyAddress, false);

      // Rewards.
      (_playRecord.expReward, _playRecord.goldReward) = giveReward(_tokenIds, false, _turnInfo.originalExps);
    }

    // Save the result of this gameplay.
    addressToPlayRecord[msg.sender] = _playRecord;

    // Save the turn data.
    // This is commented as this information can be reconstructed with intitial seed and date time.
    // By commenting this, we can reduce about 400k gas.
    if (isTurnDataSaved) {
      addressToTurnInfo[msg.sender] = _turnInfo;
    }
  }

  // @dev Check ownership.
  function checkOwnershipAndAvailability(address _playerAddress, uint256[4] _tokenIds)
    private view
    returns(bool)
  {
    if ((_tokenIds[0] == 0 || heroContract.ownerOf(_tokenIds[0]) == _playerAddress) && (_tokenIds[1] == 0 || heroContract.ownerOf(_tokenIds[1]) == _playerAddress) && (_tokenIds[2] == 0 || heroContract.ownerOf(_tokenIds[2]) == _playerAddress) && (_tokenIds[3] == 0 || heroContract.ownerOf(_tokenIds[3]) == _playerAddress)) {
      
      // Retrieve avail time of heroes.
      uint256[4] memory _heroAvailAts;
      if (_tokenIds[0] != 0)
        ( , , , , , _heroAvailAts[0], , , ) = heroContract.getHeroInfo(_tokenIds[0]);
      if (_tokenIds[1] != 0)
        ( , , , , , _heroAvailAts[1], , , ) = heroContract.getHeroInfo(_tokenIds[1]);
      if (_tokenIds[2] != 0)
        ( , , , , , _heroAvailAts[2], , , ) = heroContract.getHeroInfo(_tokenIds[2]);
      if (_tokenIds[3] != 0)
        ( , , , , , _heroAvailAts[3], , , ) = heroContract.getHeroInfo(_tokenIds[3]);

      if (_heroAvailAts[0] <= now && _heroAvailAts[1] <= now && _heroAvailAts[2] <= now && _heroAvailAts[3] <= now) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }

  // @dev Give rewards.
  function giveReward(uint256[4] _heroes, bool _didWin, uint32[4] _originalExps)
    private
    returns (uint32 expRewardGiven, uint256 goldRewardGiven)
  {
    if (!_didWin) {
      // In case lost.
      // Give baseline gold reward.
      goldRewardGiven = goldReward / 10;
      expRewardGiven = expReward / 5;
    } else {
      // In case win.
      goldRewardGiven = goldReward;
      expRewardGiven = expReward;
    }

    // Give reward Gold.
    goldContract.mint(msg.sender, goldRewardGiven);
    
    // Give reward EXP.
    if(_heroes[0] != 0)
      heroContract.addExp(_heroes[0], uint32(2)**32 - _originalExps[0] + expRewardGiven);
    if(_heroes[1] != 0)
      heroContract.addExp(_heroes[1], uint32(2)**32 - _originalExps[1] + expRewardGiven);
    if(_heroes[2] != 0)
      heroContract.addExp(_heroes[2], uint32(2)**32 - _originalExps[2] + expRewardGiven);
    if(_heroes[3] != 0)
      heroContract.addExp(_heroes[3], uint32(2)**32 - _originalExps[3] + expRewardGiven);
  }

  // @dev Return a pseudo random number between lower and upper bounds
  function random(uint32 _upper, uint32 _lower)
    private
    returns (uint32)
  {
    require(_upper > _lower);

    seed = seed % uint32(1103515245) + 12345;
    return seed % (_upper - _lower) + _lower;
  }

  // @dev Retreive order based on given array _by.
  function getOrder(uint32[8] _by)
    private pure
    returns (uint8[8])
  {
    uint8[8] memory _order = [uint8(0), 1, 2, 3, 4, 5, 6, 7];
    for (uint8 i = 0; i < 8; i ++) {
      for (uint8 j = i + 1; j < 8; j++) {
        if (_by[i] < _by[j]) {
          uint32 tmp1 = _by[i];
          _by[i] = _by[j];
          _by[j] = tmp1;
          uint8 tmp2 = _order[i];
          _order[i] = _order[j];
          _order[j] = tmp2;
        }
      }
    }
    return _order;
  }

  // @return Bigger value of two uint32s.
  function max(uint32 _value1, uint32 _value2)
    private pure
    returns (uint32)
  {
    if(_value1 >= _value2)
      return _value1;
    else
      return _value2;
  }

  // @return Bigger value of two uint32s.
  function min(uint32 _value1, uint32 _value2)
    private pure
    returns (uint32)
  {
    if(_value2 >= _value1)
      return _value1;
    else
      return _value2;
  }

  // @return Square root of the given value.
  function sqrt(uint32 _value) 
    private pure
    returns (uint32) 
  {
    uint32 z = (_value + 1) / 2;
    uint32 y = _value;
    while (z < y) {
      y = z;
      z = (_value / z + z) / 2;
    }
    return y;
  }

}

Contract Security Audit

Contract ABI

[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"addressToPlayRecord","outputs":[{"name":"initialSeed","type":"uint32"},{"name":"enemyAddress","type":"address"},{"name":"expReward","type":"uint32"},{"name":"goldReward","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"bool"}],"name":"setIsTurnDataSaved","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"addressToTurnInfo","outputs":[{"name":"turnLength","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"isTurnDataSaved","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint32"}],"name":"setExpReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"claimOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"goldReward","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cardContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"setGoldReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getPlayRecord","outputs":[{"name":"","type":"uint32"},{"name":"","type":"address"},{"name":"","type":"uint256[4]"},{"name":"","type":"uint32[8]"},{"name":"","type":"uint32[8]"},{"name":"","type":"uint32"},{"name":"","type":"uint256"},{"name":"","type":"uint8"},{"name":"","type":"uint8[8]"},{"name":"","type":"uint8[24]"},{"name":"","type":"uint32[24]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint32"}],"name":"setLocationId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"coolHero","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pendingOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[4]"},{"name":"_enemyAddress","type":"address"}],"name":"enterArena","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"locationId","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getPlayRecordNoTurnData","outputs":[{"name":"","type":"uint32"},{"name":"","type":"address"},{"name":"","type":"uint256[4]"},{"name":"","type":"uint32[8]"},{"name":"","type":"uint32[8]"},{"name":"","type":"uint32"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"expReward","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint32"}],"name":"setCoolHero","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"goldContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_recordContractAddress","type":"address"},{"name":"_heroContractAddress","type":"address"},{"name":"_correctedHeroContractAddress","type":"address"},{"name":"_cardContractAddress","type":"address"},{"name":"_goldContractAddress","type":"address"},{"name":"_firstPlayerAddress","type":"address"},{"name":"_locationId","type":"uint32"},{"name":"_coolHero","type":"uint256"},{"name":"_expReward","type":"uint32"},{"name":"_goldReward","type":"uint256"},{"name":"_isTurnDataSaved","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_by","type":"address"},{"indexed":true,"name":"_against","type":"address"},{"indexed":false,"name":"_didWin","type":"bool"}],"name":"TryArena","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]

60606040526001805460a060020a60ff02191681556006805460a060020a63ffffffff02191674640000000000000000000000000000000000000000179055610e1060075560088054606463ffffffff1991821617909155670de0b6b3a7640000600955600a805460ff1916909217909155600d8054909116905534156200008657600080fd5b60405161016080620047fd83398101604052808051919060200180519190602001805191906020018051919060200180519190602001805191906020018051919060200180519190602001805191906020018051919060200180519150620000ef9050620002ce565b60008054600160a060020a031990811633600160a060020a03908116919091179092556002805482168f84161790556003805482168e84161790556004805482168d84161790556006805482168c8416179055600580549091168a8316179055600d5463ffffffff168252871660208201526001604082015152600260408201516020015260036040820151600260200201526004604082015160600152600160a060020a0387166000908152600b6020526040902081908151815463ffffffff191663ffffffff9190911617815560208201518154600160a060020a039190911664010000000002602060020a60c060020a0319909116178155604082015162000201906001830190600462000324565b50606082015162000219906005830190600862000367565b50608082015162000231906006830190600862000367565b5060a082015160078201805463ffffffff191663ffffffff9290921691909117905560c08201516008918201556006805460a060020a63ffffffff0219167401000000000000000000000000000000000000000063ffffffff9a8b16021790556007969096555050835463ffffffff19169290941691909117909155600955600a805460ff1916911515919091179055506200049c945050505050565b6103006040519081016040908152600080835260208301528101620002f262000406565b8152602001620003016200042e565b8152602001620003106200042e565b815260006020820181905260409091015290565b826004810192821562000355579160200282015b828111156200035557825182559160200191906001019062000338565b506200036392915062000458565b5090565b600183019183908215620003f85791602002820160005b83821115620003c457835183826101000a81548163ffffffff021916908363ffffffff16021790555092602001926004016020816003010492830192600103026200037e565b8015620003f65782816101000a81549063ffffffff0219169055600401602081600301049283019260010302620003c4565b505b506200036392915062000478565b60806040519081016040526004815b6000815260200190600190039081620004155790505090565b6101006040519081016040526008815b6000815260001990910190602001816200043e5790505090565b6200047591905b808211156200036357600081556001016200045f565b90565b6200047591905b808211156200036357805463ffffffff191681556001016200047f565b61435180620004ac6000396000f3006060604052600436106101245763ffffffff60e060020a6000350416630faac0e281146101295780632b99f3e1146101835780633789ddd21461019d5780633f4ba83a146101d257806345fd3666146101e55780634a5e4fa81461020c5780634e71e0c8146102285780635c975abb1461023b57806360e587f91461024e578063693bd2d0146102735780638456cb59146102a2578063862eb9c0146102b55780638da5cb5b146102cb5780639686898a146102de578063c4e6aaa61461044c578063d9c76d6114610468578063e30c39781461047b578063e712bbad1461048e578063e8aadc3f146104d1578063eeb84910146104fd578063f019c5da146105e3578063f2fde38b146105f6578063fc36cc9d14610615578063fc99655714610631575b600080fd5b341561013457600080fd5b610148600160a060020a0360043516610644565b60405163ffffffff9485168152600160a060020a03909316602084015292166040808301919091526060820192909252608001905180910390f35b341561018e57600080fd5b61019b6004351515610680565b005b34156101a857600080fd5b6101bc600160a060020a03600435166106ae565b60405160ff909116815260200160405180910390f35b34156101dd57600080fd5b61019b6106c3565b34156101f057600080fd5b6101f8610742565b604051901515815260200160405180910390f35b341561021757600080fd5b61019b63ffffffff6004351661074b565b341561023357600080fd5b61019b610782565b341561024657600080fd5b6101f8610810565b341561025957600080fd5b610261610820565b60405190815260200160405180910390f35b341561027e57600080fd5b610286610826565b604051600160a060020a03909116815260200160405180910390f35b34156102ad57600080fd5b61019b610835565b34156102c057600080fd5b61019b6004356108b9565b34156102d657600080fd5b6102866108d9565b34156102e957600080fd5b6102fd600160a060020a03600435166108e8565b60405163ffffffff8c168152600160a060020a038b166020820152604081018a608080838360005b8381101561033d578082015183820152602001610325565b5050505090500189600860200280838360005b83811015610368578082015183820152602001610350565b5050505090500188600860200280838360005b8381101561039357808201518382015260200161037b565b5050505063ffffffff8a169201918252506020810187905260ff861660408201526060018461010080838360005b838110156103d95780820151838201526020016103c1565b5050505090500183601860200280838360005b838110156104045780820151838201526020016103ec565b5050505090500182601860200280838360005b8381101561042f578082015183820152602001610417565b505050509050019b50505050505050505050505060405180910390f35b341561045757600080fd5b61019b63ffffffff60043516610cd7565b341561047357600080fd5b610261610d29565b341561048657600080fd5b610286610d2f565b341561049957600080fd5b61019b6004608481806080604051908101604052919082826080808284375093955050509135600160a060020a03169150610d3e9050565b34156104dc57600080fd5b6104e4613208565b60405163ffffffff909116815260200160405180910390f35b341561050857600080fd5b61051c600160a060020a036004351661321b565b60405163ffffffff88168152600160a060020a03871660208201526040810186608080838360005b8381101561055c578082015183820152602001610544565b5050505090500185600860200280838360005b8381101561058757808201518382015260200161056f565b5050505090500184600860200280838360005b838110156105b257808201518382015260200161059a565b505050509050018363ffffffff1663ffffffff16815260200182815260200197505050505050505060405180910390f35b34156105ee57600080fd5b6104e46133e5565b341561060157600080fd5b61019b600160a060020a03600435166133f1565b341561062057600080fd5b61019b63ffffffff6004351661343b565b341561063c57600080fd5b610286613461565b600b6020526000908152604090208054600782015460089092015463ffffffff80831693640100000000909304600160a060020a031692169084565b60005433600160a060020a0390811691161461069b57600080fd5b600a805460ff1916911515919091179055565b600c6020526000908152604090205460ff1681565b60005433600160a060020a039081169116146106de57600080fd5b60015460a060020a900460ff1615156106f657600080fd5b6001805474ff0000000000000000000000000000000000000000191690557f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600a5460ff1681565b60005433600160a060020a0390811691161461076657600080fd5b6008805463ffffffff191663ffffffff92909216919091179055565b60015433600160a060020a0390811691161461079d57600080fd5b600154600054600160a060020a0391821691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600180546000805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a03841617909155169055565b60015460a060020a900460ff1681565b60095481565b600654600160a060020a031681565b60005433600160a060020a0390811691161461085057600080fd5b60015460a060020a900460ff161561086757600080fd5b6001805474ff0000000000000000000000000000000000000000191660a060020a1790557f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b60005433600160a060020a039081169116146108d457600080fd5b600955565b600054600160a060020a031681565b6000806108f3613f5f565b6108fb613f86565b610903613f86565b6000806000610910613f86565b610918613faf565b610920613faf565b610928613fca565b61093061401a565b600160a060020a038e166000908152600b6020526040908190209060e090519081016040908152825463ffffffff811683526401000000009004600160a060020a031660208301529091908083019060018301906004906080905190810160405291906080830182845b81548152602001906001019080831161099a57505050918352505060200160058201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116109d6579050505050918352505060200160068201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff1681526020019060040190602082600301049283019260010382029150808411610a3b579050505050505081526020016007820160009054906101000a900463ffffffff1663ffffffff1663ffffffff1681526020016008820154815250509150600c60008f600160a060020a0316600160a060020a0316815260200190815260200160002060a06040519081016040908152825460ff16825290919060208301906001830190600890610100905190810160405291906101008301826000855b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411610b12579050505050918352505060200160028201601861030060405190810160405291906103008301826000855b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411610b69579050505050918352505060200160038201601861030060405190810160405291906103008301826000855b82829054906101000a900463ffffffff1663ffffffff1681526020019060040190602082600301049283019260010382029150808411610bc057905050505091835250506020016006820160046080604051908101604052919060808301826000855b82829054906101000a900463ffffffff1663ffffffff1681526020019060040190602082600301049283019260010382029150808411610c235790505050505050815250509050816000015182602001518360400151846060015185608001518660a001518760c001518751886020015189604001518a606001518898508797508696508292508191508090509c509c509c509c509c509c509c509c509c509c509c50505091939597999b90929496989a50565b60005433600160a060020a03908116911614610cf257600080fd5b6006805463ffffffff90921660a060020a0277ffffffff000000000000000000000000000000000000000019909216919091179055565b60075481565b600154600160a060020a031681565b610d46613fca565b610d4e61401a565b610d56614062565b610d5e614090565b610d66613fca565b610d6e613f86565b600080600080600080600160149054906101000a900460ff16151515610d9357600080fd5b8c600160a060020a031633600160a060020a031614151515610db457600080fd5b8d511580610de8575060208e01518e5114158015610dd7575060408e01518e5114155b8015610de8575060608e01518e5114155b1515610df357600080fd5b60208e01511580610e3057508d5160208f015114158015610e1c575060408e015160208f015114155b8015610e30575060608e015160208f015114155b1515610e3b57600080fd5b60408e01511580610e7857508d5160408f015114158015610e64575060208e015160408f015114155b8015610e78575060608e015160408f015114155b1515610e8357600080fd5b60608e01511580610ec057508d5160608f015114158015610eac575060208e015160608f015114155b8015610ec0575060408e015160608f015114155b1515610ecb57600080fd5b610ed5338f613470565b1515610ee057600080fd5b600160a060020a038d81166000908152600b60205260409020546401000000009004161515610f0e57600080fd5b600d805463ffffffff1981164263ffffffff9283160182161791829055168c52600160a060020a038d1660208d01528d600060200201518c604001515260208e01518c604001516020015260408e01518c604001516040015260608e01518c60400151606001528d511561116a57600354600160a060020a031663d1f699028f5160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515610fce57600080fd5b6102c65a03f11515610fdf57600080fd5b505050604051805190508c6060015163ffffffff919091169052600454600160a060020a031663763901448f5160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561104d57600080fd5b6102c65a03f1151561105e57600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160808f0151918e5263ffffffff92831690915291169052600354600160a060020a0316636ccd5cbe60608e01515160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b15156110f857600080fd5b6102c65a03f1151561110957600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d9250600091506111529050565b60200201518b5160ff92831660209190910152911690525b60208e01511561138757600354600160a060020a031663d1f699028f6001602002015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156111cc57600080fd5b6102c65a03f115156111dd57600080fd5b505050604051805190508c60600151600163ffffffff9092166020929092020152600454600160a060020a031663763901448f6001602002015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561125857600080fd5b6102c65a03f1151561126957600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160200160808f015160208f81019390935263ffffffff93841692019190915291169052600354600160a060020a0316636ccd5cbe60608e01516020015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561131257600080fd5b6102c65a03f1151561132357600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d92506001915061136c9050565b602002015160208c015160ff92831660209190910152911690525b60408e0151156115a457600354600160a060020a031663d1f699028f6002602002015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156113e957600080fd5b6102c65a03f115156113fa57600080fd5b505050604051805190508c60600151600263ffffffff9092166020929092020152600454600160a060020a031663763901448f6002602002015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561147557600080fd5b6102c65a03f1151561148657600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160400160808f015160408f81019390935263ffffffff93841692019190915291169052600354600160a060020a0316636ccd5cbe60608e01516040015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561152f57600080fd5b6102c65a03f1151561154057600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d9250600291506115899050565b602002015160408c015160ff92831660209190910152911690525b60608e0151156117e557600360009054906101000a9004600160a060020a0316600160a060020a031663d1f699028f60036004811015156115e157fe5b602002015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561162557600080fd5b6102c65a03f1151561163657600080fd5b505050604051805190508c60600151600363ffffffff9092166020929092020152600454600160a060020a031663763901448f6003602002015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b15156116b157600080fd5b6102c65a03f115156116c257600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160600160808f01516003602002018e6003602002019290925263ffffffff92831690915291169052600354600160a060020a0316636ccd5cbe60608e01516060015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561177057600080fd5b6102c65a03f1151561178157600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d9250600391506117ca9050565b602002015160608c015160ff92831660209190910152911690525b600160a060020a038d166000908152600b6020526040908190209060e090519081016040908152825463ffffffff811683526401000000009004600160a060020a031660208301529091908083019060018301906004906080905190810160405291906080830182845b81548152602001906001019080831161184f57505050918352505060200160058201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161188b579050505050918352505060200160068201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116118f057505050928452505050600782015463ffffffff1660208201526008909101546040918201529098508801515115611b5b57600354600160a060020a031663d1f6990260408a01515160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156119b157600080fd5b6102c65a03f115156119c257600080fd5b505050604051805190508c6060015163ffffffff91909116608090910152600454600160a060020a0316637639014460408a01515160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b1515611a3857600080fd5b6102c65a03f11515611a4957600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160808d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e01516080015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b1515611ae657600080fd5b6102c65a03f11515611af757600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d925060049150611b409050565b602002015160808c015160ff92831660209190910152911690525b87604001516020015115611d6f57600354600160a060020a031663d1f6990260408a01516020015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515611bc257600080fd5b6102c65a03f11515611bd357600080fd5b505050604051805190508c6060015163ffffffff9190911660a090910152600454600160a060020a0316637639014460408a01516020015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b1515611c4c57600080fd5b6102c65a03f11515611c5d57600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160a08d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e015160a0015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b1515611cfa57600080fd5b6102c65a03f11515611d0b57600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d925060059150611d549050565b602002015160a08c015160ff92831660209190910152911690525b87604001516040015115611f8357600354600160a060020a031663d1f6990260408a01516040015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515611dd657600080fd5b6102c65a03f11515611de757600080fd5b505050604051805190508c6060015163ffffffff9190911660c090910152600454600160a060020a0316637639014460408a01516040015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b1515611e6057600080fd5b6102c65a03f11515611e7157600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160c08d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e015160c0015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b1515611f0e57600080fd5b6102c65a03f11515611f1f57600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d925060069150611f689050565b602002015160c08c015160ff92831660209190910152911690525b8760400151606001511561219757600354600160a060020a031663d1f6990260408a01516060015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515611fea57600080fd5b6102c65a03f11515611ffb57600080fd5b505050604051805190508c6060015163ffffffff9190911660e090910152600454600160a060020a0316637639014460408a01516060015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561207457600080fd5b6102c65a03f1151561208557600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160e08d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e015160e0015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561212257600080fd5b6102c65a03f1151561213357600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d92506007915061217c9050565b602002015160e08c015160ff92831660209190910152911690525b600095505b60088660ff1610156121ea578960ff8716600881106121b757fe5b6020020151604001518760ff8816600881106121cf57fe5b63ffffffff909216602092909202015260019095019461219c565b6121f387613a1f565b60208c015260188b52600095505b60188660ff161015612aa45760808a01516080015163ffffffff16158015612235575060a08a01516080015163ffffffff16155b801561224d575060c08a01516080015163ffffffff16155b8015612265575060e08a01516080015163ffffffff16155b156122755760ff86168b52612aa4565b89516080015163ffffffff1615801561229a575060208a01516080015163ffffffff16155b80156122b2575060408a01516080015163ffffffff16155b80156122ca575060608a01516080015163ffffffff16155b156122da5760ff86168b52612aa4565b8a60200151600860ff88160660ff166008811015156122f557fe5b6020020151945060048560ff1610801561232057508d60ff86166004811061231957fe5b6020020151155b1561234c57607f8b6040015160ff88166018811061233a57fe5b60ff9092166020929092020152612a99565b8960ff86166008811061235b57fe5b60200201516080015163ffffffff1615156123855760808b6040015160ff88166018811061233a57fe5b60ff935060048560ff16101561241657600060808b01516080015163ffffffff1611156123b55760049350612411565b600060a08b01516080015163ffffffff1611156123d55760059350612411565b600060c08b01516080015163ffffffff1611156123f55760069350612411565b600060e08b01516080015163ffffffff16111561241157600793505b61248f565b60008a516080015163ffffffff161115612433576000935061248f565b600060208b01516080015163ffffffff161115612453576001935061248f565b600060408b01516080015163ffffffff161115612473576002935061248f565b600060608b01516080015163ffffffff16111561248f57600393505b838b6040015160ff8816601881106124a357fe5b60ff9283166020919091029190910152600a93508a908516600881106124c557fe5b60200201516020015163ffffffff1660648b60ff8816600881106124e557fe5b60200201515160960263ffffffff168115156124fd57fe5b0463ffffffff16111561255e576125578a60ff86166008811061251c57fe5b60200201516020015160648c60ff89166008811061253657fe5b60200201515160960263ffffffff1681151561254e57fe5b0403600a613bcb565b9250612563565b600a92505b8960ff85166008811061257257fe5b60200201516040015163ffffffff1660648b60ff88166008811061259257fe5b60200201516060015160960263ffffffff168115156125ad57fe5b0463ffffffff16111561263b576125c660646000613bed565b63ffffffff1661262661261f8c60ff8816600881106125e157fe5b60200201516040015160648e60ff8b16600881106125fb57fe5b60200201516060015160960263ffffffff1681151561261657fe5b0403604b613bcb565b6063613c51565b63ffffffff161161263657600092505b612659565b61264760646000613bed565b63ffffffff16604b1161265957600092505b8960ff85166008811061266857fe5b60200201516060015163ffffffff168a60ff87166008811061268657fe5b60200201516060015163ffffffff161115612713576126a760646000613bed565b63ffffffff166126f26126eb8c60ff8816600881106126c257fe5b6020020151606001518d60ff8a16600881106126da57fe5b602002015160600151036005613bcb565b604b613c51565b63ffffffff16111561270e57606463ffffffff60968502160492505b61273d565b61271f60646000613bed565b63ffffffff166005111561273d57606463ffffffff60968502160492505b8860ff86166008811061274c57fe5b60200201515160ff1615801561277957508860ff85166008811061276c57fe5b60200201515160ff166001145b1561279357606463ffffffff607d8502165b049250612838565b8860ff8616600881106127a257fe5b60200201515160ff1660011480156127d157508860ff8516600881106127c457fe5b60200201515160ff166002145b156127e757606463ffffffff607d85021661278b565b8860ff8616600881106127f657fe5b60200201515160ff16600214801561282357508860ff85166008811061281857fe5b60200201515160ff16155b1561283857606463ffffffff607d8502160492505b8860ff86166008811061284757fe5b60200201516020015160ff1615801561287a57508860ff85166008811061286a57fe5b60200201516020015160ff166001145b1561289457606463ffffffff60968502165b0492506129f9565b8860ff8616600881106128a357fe5b60200201516020015160ff1660011480156128d857508860ff8516600881106128c857fe5b60200201516020015160ff166002145b156128ee57606463ffffffff609685021661288c565b8860ff8616600881106128fd57fe5b60200201516020015160ff16600214801561293057508860ff85166008811061292257fe5b60200201516020015160ff16155b1561294657606463ffffffff609685021661288c565b8860ff86166008811061295557fe5b60200201516020015160ff16600314801561298a57508860ff85166008811061297a57fe5b60200201516020015160ff166004145b156129a057606463ffffffff609685021661288c565b8860ff8616600881106129af57fe5b60200201516020015160ff1660041480156129e457508860ff8516600881106129d457fe5b60200201516020015160ff166003145b156129f957606463ffffffff60968502160492505b63ffffffff83168a60ff861660088110612a0f57fe5b60200201516080015163ffffffff161115612a4e57828a60ff861660088110612a3457fe5b60200201516080018181510363ffffffff16905250612a74565b60008a60ff861660088110612a5f57fe5b602002015163ffffffff919091166080909101525b828b6060015160ff881660188110612a8857fe5b63ffffffff90921660209290920201525b600190950194612201565b8d5115612b4b57600354600160a060020a031663284fb3638f51600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612b2f57600080fd5b6102c65a03f11515612b4057600080fd5b505050604051805150505b60208e015115612bfb57600354600160a060020a031663284fb3638f60016020020151600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612bdf57600080fd5b6102c65a03f11515612bf057600080fd5b505050604051805150505b60408e015115612cab57600354600160a060020a031663284fb3638f60026020020151600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612c8f57600080fd5b6102c65a03f11515612ca057600080fd5b505050604051805150505b60608e015115612d7a57600360009054906101000a9004600160a060020a0316600160a060020a031663284fb3638f6003600481101515612ce857fe5b6020020151600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612d5e57600080fd5b6102c65a03f11515612d6f57600080fd5b505050604051805150505b50600090508089516080015163ffffffff161515612d99576001909101905b60208a01516080015163ffffffff161515612db5576001909101905b60408a01516080015163ffffffff161515612dd1576001909101905b60608a01516080015163ffffffff161515612ded576001909101905b60808a01516080015163ffffffff161515612e06576001015b60a08a01516080015163ffffffff161515612e1f576001015b60c08a01516080015163ffffffff161515612e38576001015b60e08a01516080015163ffffffff161515612e51576001015b8160ff168160ff161115612f46578c600160a060020a031633600160a060020a03167ffa17b61080902731a2720bfa418fcae6de065aa77e52ffc41759dd96a761a2e46001604051901515815260200160405180910390a3612eb98e60018d60800151613c6a565b60c08e015263ffffffff1660a08d0152600254600160a060020a031663b52db3b9338f600160405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201529015156044820152606401600060405180830381600087803b1515612f2d57600080fd5b6102c65a03f11515612f3e57600080fd5b50505061308d565b8160ff168160ff161015613022578c600160a060020a031633600160a060020a03167ffa17b61080902731a2720bfa418fcae6de065aa77e52ffc41759dd96a761a2e46000604051901515815260200160405180910390a3612fae8e60008d60800151613c6a565b60c08e015263ffffffff1660a08d0152600254600160a060020a031663b52db3b9338f600060405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201529015156044820152606401600060405180830381600087803b1515612f2d57600080fd5b8c600160a060020a031633600160a060020a03167ffa17b61080902731a2720bfa418fcae6de065aa77e52ffc41759dd96a761a2e46000604051901515815260200160405180910390a361307c8e60008d60800151613c6a565b60c08e015263ffffffff1660a08d01525b600160a060020a0333166000908152600b602052604090208c908151815463ffffffff191663ffffffff9190911617815560208201518154600160a060020a03919091166401000000000277ffffffffffffffffffffffffffffffffffffffff0000000019909116178155604082015161310d90600183019060046140be565b50606082015161312390600583019060086140fc565b50608082015161313990600683019060086140fc565b5060a082015160078201805463ffffffff191663ffffffff9290921691909117905560c082015160089091015550600a5460ff16156131f857600160a060020a0333166000908152600c602052604090208b908151815460ff191660ff9190911617815560208201516131b29060018301906008614194565b5060408201516131c89060028301906018614194565b5060608201516131de9060038301906018614223565b5060808201516131f490600683019060046140fc565b5050505b5050505050505050505050505050565b60065460a060020a900463ffffffff1681565b600080613226613f5f565b61322e613f86565b613236613f86565b600080613241613fca565b600160a060020a0389166000908152600b6020526040908190209060e090519081016040908152825463ffffffff811683526401000000009004600160a060020a031660208301529091908083019060018301906004906080905190810160405291906080830182845b8154815260200190600101908083116132ab57505050918352505060200160058201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116132e7579050505050918352505060200160068201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161334c57505050928452505050600782015463ffffffff1660208201526008909101546040909101529050805181602001518260400151836060015184608001518560a001518660c00151959f949e50929c50909a509850965090945092505050565b60085463ffffffff1681565b60005433600160a060020a0390811691161461340c57600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461345657600080fd5b63ffffffff16600755565b600554600160a060020a031681565b600061347a613f5f565b825115806134ff5750600354600160a060020a038581169116636352211e855160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156134d957600080fd5b6102c65a03f115156134ea57600080fd5b50505060405180519050600160a060020a0316145b80156135915750602083015115806135915750600354600160a060020a038581169116636352211e602086015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561356b57600080fd5b6102c65a03f1151561357c57600080fd5b50505060405180519050600160a060020a0316145b80156136235750604083015115806136235750600354600160a060020a038581169116636352211e604086015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156135fd57600080fd5b6102c65a03f1151561360e57600080fd5b50505060405180519050600160a060020a0316145b80156136b55750606083015115806136b55750600354600160a060020a038581169116636352211e606086015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561368f57600080fd5b6102c65a03f115156136a057600080fd5b50505060405180519050600160a060020a0316145b15613a135782511561377b57600354600160a060020a03166375e39f2684516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b151561371557600080fd5b6102c65a03f1151561372657600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a001805150602001604052509095508694506000935061377592505050565b60200201525b60208301511561384257600354600160a060020a03166375e39f2660208501516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b15156137dc57600080fd5b6102c65a03f115156137ed57600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a001805150602001604052509095508694506001935061383c92505050565b60200201525b60408301511561390957600354600160a060020a03166375e39f2660408501516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b15156138a357600080fd5b6102c65a03f115156138b457600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a001805150602001604052509095508694506002935061390392505050565b60200201525b6060830151156139d057600354600160a060020a03166375e39f2660608501516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b151561396a57600080fd5b6102c65a03f1151561397b57600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a00180515060200160405250909550869450600393506139ca92505050565b60200201525b428151111580156139e5575042602082015111155b80156139f5575042604082015111155b8015613a05575042606082015111155b15613a135760019150613a18565b600091505b5092915050565b613a27613f86565b613a2f613f86565b60008060008061010060405190810160409081526000808352600160208401526002918301919091526003606083015260046080830152600560a0830152600660c0830152600760e083015290955093505b60088460ff161015613bc0578360010192505b60088360ff161015613bb5578660ff841660088110613aaf57fe5b602002015163ffffffff168760ff861660088110613ac957fe5b602002015163ffffffff161015613baa578660ff851660088110613ae957fe5b602002015191508660ff841660088110613aff57fe5b60200201518760ff861660088110613b1357fe5b63ffffffff9092166020929092020152818760ff851660088110613b3357fe5b63ffffffff90921660209290920201528460ff851660088110613b5257fe5b602002015190508460ff841660088110613b6857fe5b60200201518560ff861660088110613b7c57fe5b60ff928316602091909102919091015281908690851660088110613b9c57fe5b60ff90921660209290920201525b600190920191613a94565b600190930192613a81565b509295945050505050565b600063ffffffff80831690841610613be4575081613be7565b50805b92915050565b600063ffffffff80831690841611613c0457600080fd5b600d546341c64e6d9063ffffffff16600d805463ffffffff1916929091066130390163ffffffff9081169290921790819055839182860381169116811515613c4857fe5b06019392505050565b600063ffffffff80841690831610613be4575081613be7565b600080831515613c91575050600954600854600563ffffffff9091160490600a9004613ca1565b505060095460085463ffffffff16905b600554600160a060020a03166340c10f19338360006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515613d0057600080fd5b6102c65a03f11515613d1157600080fd5b5050506040518051508590505115613da457600354600160a060020a0316631debbe2f8651848651640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613d8857600080fd5b6102c65a03f11515613d9957600080fd5b505050604051805150505b602085015115613e3557600354600160a060020a0316631debbe2f6020870151846020870151640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613e1957600080fd5b6102c65a03f11515613e2a57600080fd5b505050604051805150505b604085015115613ec657600354600160a060020a0316631debbe2f6040870151846040870151640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613eaa57600080fd5b6102c65a03f11515613ebb57600080fd5b505050604051805150505b606085015115613f5757600354600160a060020a0316631debbe2f6060870151846060870151640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613f3b57600080fd5b6102c65a03f11515613f4c57600080fd5b505050604051805150505b935093915050565b60806040519081016040526004815b6000815260200190600190039081613f6e5790505090565b6101006040519081016040526008815b600081526000199091019060200181613f965790505090565b61030060405190810160405260008152601760208201613f96565b6103006040519081016040908152600080835260208301528101613fec613f5f565b8152602001613ff9613f86565b8152602001614006613f86565b815260006020820181905260409091015290565b6107a06040519081016040526000815260208101614036613f86565b8152602001614043613faf565b8152602001614050613faf565b815260200161405d61427c565b905290565b6105006040519081016040526008815b61407a614296565b8152602001906001900390816140725790505090565b6102006040519081016040526008815b6140a86142b0565b8152602001906001900390816140a05790505090565b82600481019282156140ec579160200282015b828111156140ec5782518255916020019190600101906140d1565b506140f89291506142c9565b5090565b6001830191839082156141885791602002820160005b8382111561415657835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302614112565b80156141865782816101000a81549063ffffffff0219169055600401602081600301049283019260010302614156565b505b506140f89291506142e6565b6001830191839082156142175791602002820160005b838211156141e857835183826101000a81548160ff021916908360ff16021790555092602001926001016020816000010492830192600103026141aa565b80156142155782816101000a81549060ff02191690556001016020816000010492830192600103026141e8565b505b506140f8929150614307565b6003830191839082156141885791602002820160008382111561415657835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302614112565b608060405190810160405260008152600360208201613f96565b60a060405190810160405260008152600460208201613f96565b6040805190810160405260008152600160208201613f96565b6142e391905b808211156140f857600081556001016142cf565b90565b6142e391905b808211156140f857805463ffffffff191681556001016142ec565b6142e391905b808211156140f857805460ff1916815560010161430d5600a165627a7a723058202a355c55f26faec8f18bd73a5baee224b5dde97477be66c5df3892b2fba94b7e002900000000000000000000000067e72299beaf3f59f365bb4a43e8d02bff61e176000000000000000000000000abc7e6c01237e8eef355bba2bf925a730b714d5f0000000000000000000000001f6f71e1e6a56dc348f1ec9a22b200ac44459fe40000000000000000000000001b5242794288b45831ce069c9934a29b89af019700000000000000000000000059bcded9c87ce46ec97c13640bfc0390ceb00e990000000000000000000000006589adf7720a5b5f80bd391c0bbf2148d00be5ae0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000012c00000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000000000000000000000000002b5e3af16b18800000000000000000000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x6060604052600436106101245763ffffffff60e060020a6000350416630faac0e281146101295780632b99f3e1146101835780633789ddd21461019d5780633f4ba83a146101d257806345fd3666146101e55780634a5e4fa81461020c5780634e71e0c8146102285780635c975abb1461023b57806360e587f91461024e578063693bd2d0146102735780638456cb59146102a2578063862eb9c0146102b55780638da5cb5b146102cb5780639686898a146102de578063c4e6aaa61461044c578063d9c76d6114610468578063e30c39781461047b578063e712bbad1461048e578063e8aadc3f146104d1578063eeb84910146104fd578063f019c5da146105e3578063f2fde38b146105f6578063fc36cc9d14610615578063fc99655714610631575b600080fd5b341561013457600080fd5b610148600160a060020a0360043516610644565b60405163ffffffff9485168152600160a060020a03909316602084015292166040808301919091526060820192909252608001905180910390f35b341561018e57600080fd5b61019b6004351515610680565b005b34156101a857600080fd5b6101bc600160a060020a03600435166106ae565b60405160ff909116815260200160405180910390f35b34156101dd57600080fd5b61019b6106c3565b34156101f057600080fd5b6101f8610742565b604051901515815260200160405180910390f35b341561021757600080fd5b61019b63ffffffff6004351661074b565b341561023357600080fd5b61019b610782565b341561024657600080fd5b6101f8610810565b341561025957600080fd5b610261610820565b60405190815260200160405180910390f35b341561027e57600080fd5b610286610826565b604051600160a060020a03909116815260200160405180910390f35b34156102ad57600080fd5b61019b610835565b34156102c057600080fd5b61019b6004356108b9565b34156102d657600080fd5b6102866108d9565b34156102e957600080fd5b6102fd600160a060020a03600435166108e8565b60405163ffffffff8c168152600160a060020a038b166020820152604081018a608080838360005b8381101561033d578082015183820152602001610325565b5050505090500189600860200280838360005b83811015610368578082015183820152602001610350565b5050505090500188600860200280838360005b8381101561039357808201518382015260200161037b565b5050505063ffffffff8a169201918252506020810187905260ff861660408201526060018461010080838360005b838110156103d95780820151838201526020016103c1565b5050505090500183601860200280838360005b838110156104045780820151838201526020016103ec565b5050505090500182601860200280838360005b8381101561042f578082015183820152602001610417565b505050509050019b50505050505050505050505060405180910390f35b341561045757600080fd5b61019b63ffffffff60043516610cd7565b341561047357600080fd5b610261610d29565b341561048657600080fd5b610286610d2f565b341561049957600080fd5b61019b6004608481806080604051908101604052919082826080808284375093955050509135600160a060020a03169150610d3e9050565b34156104dc57600080fd5b6104e4613208565b60405163ffffffff909116815260200160405180910390f35b341561050857600080fd5b61051c600160a060020a036004351661321b565b60405163ffffffff88168152600160a060020a03871660208201526040810186608080838360005b8381101561055c578082015183820152602001610544565b5050505090500185600860200280838360005b8381101561058757808201518382015260200161056f565b5050505090500184600860200280838360005b838110156105b257808201518382015260200161059a565b505050509050018363ffffffff1663ffffffff16815260200182815260200197505050505050505060405180910390f35b34156105ee57600080fd5b6104e46133e5565b341561060157600080fd5b61019b600160a060020a03600435166133f1565b341561062057600080fd5b61019b63ffffffff6004351661343b565b341561063c57600080fd5b610286613461565b600b6020526000908152604090208054600782015460089092015463ffffffff80831693640100000000909304600160a060020a031692169084565b60005433600160a060020a0390811691161461069b57600080fd5b600a805460ff1916911515919091179055565b600c6020526000908152604090205460ff1681565b60005433600160a060020a039081169116146106de57600080fd5b60015460a060020a900460ff1615156106f657600080fd5b6001805474ff0000000000000000000000000000000000000000191690557f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600a5460ff1681565b60005433600160a060020a0390811691161461076657600080fd5b6008805463ffffffff191663ffffffff92909216919091179055565b60015433600160a060020a0390811691161461079d57600080fd5b600154600054600160a060020a0391821691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600180546000805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a03841617909155169055565b60015460a060020a900460ff1681565b60095481565b600654600160a060020a031681565b60005433600160a060020a0390811691161461085057600080fd5b60015460a060020a900460ff161561086757600080fd5b6001805474ff0000000000000000000000000000000000000000191660a060020a1790557f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b60005433600160a060020a039081169116146108d457600080fd5b600955565b600054600160a060020a031681565b6000806108f3613f5f565b6108fb613f86565b610903613f86565b6000806000610910613f86565b610918613faf565b610920613faf565b610928613fca565b61093061401a565b600160a060020a038e166000908152600b6020526040908190209060e090519081016040908152825463ffffffff811683526401000000009004600160a060020a031660208301529091908083019060018301906004906080905190810160405291906080830182845b81548152602001906001019080831161099a57505050918352505060200160058201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116109d6579050505050918352505060200160068201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff1681526020019060040190602082600301049283019260010382029150808411610a3b579050505050505081526020016007820160009054906101000a900463ffffffff1663ffffffff1663ffffffff1681526020016008820154815250509150600c60008f600160a060020a0316600160a060020a0316815260200190815260200160002060a06040519081016040908152825460ff16825290919060208301906001830190600890610100905190810160405291906101008301826000855b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411610b12579050505050918352505060200160028201601861030060405190810160405291906103008301826000855b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411610b69579050505050918352505060200160038201601861030060405190810160405291906103008301826000855b82829054906101000a900463ffffffff1663ffffffff1681526020019060040190602082600301049283019260010382029150808411610bc057905050505091835250506020016006820160046080604051908101604052919060808301826000855b82829054906101000a900463ffffffff1663ffffffff1681526020019060040190602082600301049283019260010382029150808411610c235790505050505050815250509050816000015182602001518360400151846060015185608001518660a001518760c001518751886020015189604001518a606001518898508797508696508292508191508090509c509c509c509c509c509c509c509c509c509c509c50505091939597999b90929496989a50565b60005433600160a060020a03908116911614610cf257600080fd5b6006805463ffffffff90921660a060020a0277ffffffff000000000000000000000000000000000000000019909216919091179055565b60075481565b600154600160a060020a031681565b610d46613fca565b610d4e61401a565b610d56614062565b610d5e614090565b610d66613fca565b610d6e613f86565b600080600080600080600160149054906101000a900460ff16151515610d9357600080fd5b8c600160a060020a031633600160a060020a031614151515610db457600080fd5b8d511580610de8575060208e01518e5114158015610dd7575060408e01518e5114155b8015610de8575060608e01518e5114155b1515610df357600080fd5b60208e01511580610e3057508d5160208f015114158015610e1c575060408e015160208f015114155b8015610e30575060608e015160208f015114155b1515610e3b57600080fd5b60408e01511580610e7857508d5160408f015114158015610e64575060208e015160408f015114155b8015610e78575060608e015160408f015114155b1515610e8357600080fd5b60608e01511580610ec057508d5160608f015114158015610eac575060208e015160608f015114155b8015610ec0575060408e015160608f015114155b1515610ecb57600080fd5b610ed5338f613470565b1515610ee057600080fd5b600160a060020a038d81166000908152600b60205260409020546401000000009004161515610f0e57600080fd5b600d805463ffffffff1981164263ffffffff9283160182161791829055168c52600160a060020a038d1660208d01528d600060200201518c604001515260208e01518c604001516020015260408e01518c604001516040015260608e01518c60400151606001528d511561116a57600354600160a060020a031663d1f699028f5160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515610fce57600080fd5b6102c65a03f11515610fdf57600080fd5b505050604051805190508c6060015163ffffffff919091169052600454600160a060020a031663763901448f5160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561104d57600080fd5b6102c65a03f1151561105e57600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160808f0151918e5263ffffffff92831690915291169052600354600160a060020a0316636ccd5cbe60608e01515160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b15156110f857600080fd5b6102c65a03f1151561110957600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d9250600091506111529050565b60200201518b5160ff92831660209190910152911690525b60208e01511561138757600354600160a060020a031663d1f699028f6001602002015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156111cc57600080fd5b6102c65a03f115156111dd57600080fd5b505050604051805190508c60600151600163ffffffff9092166020929092020152600454600160a060020a031663763901448f6001602002015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561125857600080fd5b6102c65a03f1151561126957600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160200160808f015160208f81019390935263ffffffff93841692019190915291169052600354600160a060020a0316636ccd5cbe60608e01516020015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561131257600080fd5b6102c65a03f1151561132357600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d92506001915061136c9050565b602002015160208c015160ff92831660209190910152911690525b60408e0151156115a457600354600160a060020a031663d1f699028f6002602002015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156113e957600080fd5b6102c65a03f115156113fa57600080fd5b505050604051805190508c60600151600263ffffffff9092166020929092020152600454600160a060020a031663763901448f6002602002015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561147557600080fd5b6102c65a03f1151561148657600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160400160808f015160408f81019390935263ffffffff93841692019190915291169052600354600160a060020a0316636ccd5cbe60608e01516040015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561152f57600080fd5b6102c65a03f1151561154057600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d9250600291506115899050565b602002015160408c015160ff92831660209190910152911690525b60608e0151156117e557600360009054906101000a9004600160a060020a0316600160a060020a031663d1f699028f60036004811015156115e157fe5b602002015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561162557600080fd5b6102c65a03f1151561163657600080fd5b505050604051805190508c60600151600363ffffffff9092166020929092020152600454600160a060020a031663763901448f6003602002015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b15156116b157600080fd5b6102c65a03f115156116c257600080fd5b5050506040518051906020018051906020018060a0018060a0018051506020016040525060808f015160600160808f01516003602002018e6003602002019290925263ffffffff92831690915291169052600354600160a060020a0316636ccd5cbe60608e01516060015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561177057600080fd5b6102c65a03f1151561178157600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d9250600391506117ca9050565b602002015160608c015160ff92831660209190910152911690525b600160a060020a038d166000908152600b6020526040908190209060e090519081016040908152825463ffffffff811683526401000000009004600160a060020a031660208301529091908083019060018301906004906080905190810160405291906080830182845b81548152602001906001019080831161184f57505050918352505060200160058201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161188b579050505050918352505060200160068201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116118f057505050928452505050600782015463ffffffff1660208201526008909101546040918201529098508801515115611b5b57600354600160a060020a031663d1f6990260408a01515160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156119b157600080fd5b6102c65a03f115156119c257600080fd5b505050604051805190508c6060015163ffffffff91909116608090910152600454600160a060020a0316637639014460408a01515160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b1515611a3857600080fd5b6102c65a03f11515611a4957600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160808d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e01516080015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b1515611ae657600080fd5b6102c65a03f11515611af757600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d925060049150611b409050565b602002015160808c015160ff92831660209190910152911690525b87604001516020015115611d6f57600354600160a060020a031663d1f6990260408a01516020015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515611bc257600080fd5b6102c65a03f11515611bd357600080fd5b505050604051805190508c6060015163ffffffff9190911660a090910152600454600160a060020a0316637639014460408a01516020015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b1515611c4c57600080fd5b6102c65a03f11515611c5d57600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160a08d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e015160a0015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b1515611cfa57600080fd5b6102c65a03f11515611d0b57600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d925060059150611d549050565b602002015160a08c015160ff92831660209190910152911690525b87604001516040015115611f8357600354600160a060020a031663d1f6990260408a01516040015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515611dd657600080fd5b6102c65a03f11515611de757600080fd5b505050604051805190508c6060015163ffffffff9190911660c090910152600454600160a060020a0316637639014460408a01516040015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b1515611e6057600080fd5b6102c65a03f11515611e7157600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160c08d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e015160c0015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b1515611f0e57600080fd5b6102c65a03f11515611f1f57600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d925060069150611f689050565b602002015160c08c015160ff92831660209190910152911690525b8760400151606001511561219757600354600160a060020a031663d1f6990260408a01516060015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b1515611fea57600080fd5b6102c65a03f11515611ffb57600080fd5b505050604051805190508c6060015163ffffffff9190911660e090910152600454600160a060020a0316637639014460408a01516060015160006040516101a0015260405160e060020a63ffffffff841602815260048101919091526024016101a060405180830381600087803b151561207457600080fd5b6102c65a03f1151561208557600080fd5b5050506040518051906020018051906020018060a0018060a00180515060200160405250905060808e015160e08d81019290925263ffffffff92909216910152600354600160a060020a0316636ccd5cbe60608e015160e0015160006040516102c0015260405163ffffffff83811660e060020a0282529190911660048201526024016102c060405180830381600087803b151561212257600080fd5b6102c65a03f1151561213357600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180516102009091016040529195509093508d92506007915061217c9050565b602002015160e08c015160ff92831660209190910152911690525b600095505b60088660ff1610156121ea578960ff8716600881106121b757fe5b6020020151604001518760ff8816600881106121cf57fe5b63ffffffff909216602092909202015260019095019461219c565b6121f387613a1f565b60208c015260188b52600095505b60188660ff161015612aa45760808a01516080015163ffffffff16158015612235575060a08a01516080015163ffffffff16155b801561224d575060c08a01516080015163ffffffff16155b8015612265575060e08a01516080015163ffffffff16155b156122755760ff86168b52612aa4565b89516080015163ffffffff1615801561229a575060208a01516080015163ffffffff16155b80156122b2575060408a01516080015163ffffffff16155b80156122ca575060608a01516080015163ffffffff16155b156122da5760ff86168b52612aa4565b8a60200151600860ff88160660ff166008811015156122f557fe5b6020020151945060048560ff1610801561232057508d60ff86166004811061231957fe5b6020020151155b1561234c57607f8b6040015160ff88166018811061233a57fe5b60ff9092166020929092020152612a99565b8960ff86166008811061235b57fe5b60200201516080015163ffffffff1615156123855760808b6040015160ff88166018811061233a57fe5b60ff935060048560ff16101561241657600060808b01516080015163ffffffff1611156123b55760049350612411565b600060a08b01516080015163ffffffff1611156123d55760059350612411565b600060c08b01516080015163ffffffff1611156123f55760069350612411565b600060e08b01516080015163ffffffff16111561241157600793505b61248f565b60008a516080015163ffffffff161115612433576000935061248f565b600060208b01516080015163ffffffff161115612453576001935061248f565b600060408b01516080015163ffffffff161115612473576002935061248f565b600060608b01516080015163ffffffff16111561248f57600393505b838b6040015160ff8816601881106124a357fe5b60ff9283166020919091029190910152600a93508a908516600881106124c557fe5b60200201516020015163ffffffff1660648b60ff8816600881106124e557fe5b60200201515160960263ffffffff168115156124fd57fe5b0463ffffffff16111561255e576125578a60ff86166008811061251c57fe5b60200201516020015160648c60ff89166008811061253657fe5b60200201515160960263ffffffff1681151561254e57fe5b0403600a613bcb565b9250612563565b600a92505b8960ff85166008811061257257fe5b60200201516040015163ffffffff1660648b60ff88166008811061259257fe5b60200201516060015160960263ffffffff168115156125ad57fe5b0463ffffffff16111561263b576125c660646000613bed565b63ffffffff1661262661261f8c60ff8816600881106125e157fe5b60200201516040015160648e60ff8b16600881106125fb57fe5b60200201516060015160960263ffffffff1681151561261657fe5b0403604b613bcb565b6063613c51565b63ffffffff161161263657600092505b612659565b61264760646000613bed565b63ffffffff16604b1161265957600092505b8960ff85166008811061266857fe5b60200201516060015163ffffffff168a60ff87166008811061268657fe5b60200201516060015163ffffffff161115612713576126a760646000613bed565b63ffffffff166126f26126eb8c60ff8816600881106126c257fe5b6020020151606001518d60ff8a16600881106126da57fe5b602002015160600151036005613bcb565b604b613c51565b63ffffffff16111561270e57606463ffffffff60968502160492505b61273d565b61271f60646000613bed565b63ffffffff166005111561273d57606463ffffffff60968502160492505b8860ff86166008811061274c57fe5b60200201515160ff1615801561277957508860ff85166008811061276c57fe5b60200201515160ff166001145b1561279357606463ffffffff607d8502165b049250612838565b8860ff8616600881106127a257fe5b60200201515160ff1660011480156127d157508860ff8516600881106127c457fe5b60200201515160ff166002145b156127e757606463ffffffff607d85021661278b565b8860ff8616600881106127f657fe5b60200201515160ff16600214801561282357508860ff85166008811061281857fe5b60200201515160ff16155b1561283857606463ffffffff607d8502160492505b8860ff86166008811061284757fe5b60200201516020015160ff1615801561287a57508860ff85166008811061286a57fe5b60200201516020015160ff166001145b1561289457606463ffffffff60968502165b0492506129f9565b8860ff8616600881106128a357fe5b60200201516020015160ff1660011480156128d857508860ff8516600881106128c857fe5b60200201516020015160ff166002145b156128ee57606463ffffffff609685021661288c565b8860ff8616600881106128fd57fe5b60200201516020015160ff16600214801561293057508860ff85166008811061292257fe5b60200201516020015160ff16155b1561294657606463ffffffff609685021661288c565b8860ff86166008811061295557fe5b60200201516020015160ff16600314801561298a57508860ff85166008811061297a57fe5b60200201516020015160ff166004145b156129a057606463ffffffff609685021661288c565b8860ff8616600881106129af57fe5b60200201516020015160ff1660041480156129e457508860ff8516600881106129d457fe5b60200201516020015160ff166003145b156129f957606463ffffffff60968502160492505b63ffffffff83168a60ff861660088110612a0f57fe5b60200201516080015163ffffffff161115612a4e57828a60ff861660088110612a3457fe5b60200201516080018181510363ffffffff16905250612a74565b60008a60ff861660088110612a5f57fe5b602002015163ffffffff919091166080909101525b828b6060015160ff881660188110612a8857fe5b63ffffffff90921660209290920201525b600190950194612201565b8d5115612b4b57600354600160a060020a031663284fb3638f51600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612b2f57600080fd5b6102c65a03f11515612b4057600080fd5b505050604051805150505b60208e015115612bfb57600354600160a060020a031663284fb3638f60016020020151600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612bdf57600080fd5b6102c65a03f11515612bf057600080fd5b505050604051805150505b60408e015115612cab57600354600160a060020a031663284fb3638f60026020020151600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612c8f57600080fd5b6102c65a03f11515612ca057600080fd5b505050604051805150505b60608e015115612d7a57600360009054906101000a9004600160a060020a0316600160a060020a031663284fb3638f6003600481101515612ce857fe5b6020020151600660149054906101000a900463ffffffff166007546000604051602001526040518463ffffffff1660e060020a028152600401808481526020018363ffffffff1663ffffffff1681526020018281526020019350505050602060405180830381600087803b1515612d5e57600080fd5b6102c65a03f11515612d6f57600080fd5b505050604051805150505b50600090508089516080015163ffffffff161515612d99576001909101905b60208a01516080015163ffffffff161515612db5576001909101905b60408a01516080015163ffffffff161515612dd1576001909101905b60608a01516080015163ffffffff161515612ded576001909101905b60808a01516080015163ffffffff161515612e06576001015b60a08a01516080015163ffffffff161515612e1f576001015b60c08a01516080015163ffffffff161515612e38576001015b60e08a01516080015163ffffffff161515612e51576001015b8160ff168160ff161115612f46578c600160a060020a031633600160a060020a03167ffa17b61080902731a2720bfa418fcae6de065aa77e52ffc41759dd96a761a2e46001604051901515815260200160405180910390a3612eb98e60018d60800151613c6a565b60c08e015263ffffffff1660a08d0152600254600160a060020a031663b52db3b9338f600160405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201529015156044820152606401600060405180830381600087803b1515612f2d57600080fd5b6102c65a03f11515612f3e57600080fd5b50505061308d565b8160ff168160ff161015613022578c600160a060020a031633600160a060020a03167ffa17b61080902731a2720bfa418fcae6de065aa77e52ffc41759dd96a761a2e46000604051901515815260200160405180910390a3612fae8e60008d60800151613c6a565b60c08e015263ffffffff1660a08d0152600254600160a060020a031663b52db3b9338f600060405160e060020a63ffffffff8616028152600160a060020a0393841660048201529190921660248201529015156044820152606401600060405180830381600087803b1515612f2d57600080fd5b8c600160a060020a031633600160a060020a03167ffa17b61080902731a2720bfa418fcae6de065aa77e52ffc41759dd96a761a2e46000604051901515815260200160405180910390a361307c8e60008d60800151613c6a565b60c08e015263ffffffff1660a08d01525b600160a060020a0333166000908152600b602052604090208c908151815463ffffffff191663ffffffff9190911617815560208201518154600160a060020a03919091166401000000000277ffffffffffffffffffffffffffffffffffffffff0000000019909116178155604082015161310d90600183019060046140be565b50606082015161312390600583019060086140fc565b50608082015161313990600683019060086140fc565b5060a082015160078201805463ffffffff191663ffffffff9290921691909117905560c082015160089091015550600a5460ff16156131f857600160a060020a0333166000908152600c602052604090208b908151815460ff191660ff9190911617815560208201516131b29060018301906008614194565b5060408201516131c89060028301906018614194565b5060608201516131de9060038301906018614223565b5060808201516131f490600683019060046140fc565b5050505b5050505050505050505050505050565b60065460a060020a900463ffffffff1681565b600080613226613f5f565b61322e613f86565b613236613f86565b600080613241613fca565b600160a060020a0389166000908152600b6020526040908190209060e090519081016040908152825463ffffffff811683526401000000009004600160a060020a031660208301529091908083019060018301906004906080905190810160405291906080830182845b8154815260200190600101908083116132ab57505050918352505060200160058201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116132e7579050505050918352505060200160068201600861010060405190810160405291906101008301826000855b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161334c57505050928452505050600782015463ffffffff1660208201526008909101546040909101529050805181602001518260400151836060015184608001518560a001518660c00151959f949e50929c50909a509850965090945092505050565b60085463ffffffff1681565b60005433600160a060020a0390811691161461340c57600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461345657600080fd5b63ffffffff16600755565b600554600160a060020a031681565b600061347a613f5f565b825115806134ff5750600354600160a060020a038581169116636352211e855160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156134d957600080fd5b6102c65a03f115156134ea57600080fd5b50505060405180519050600160a060020a0316145b80156135915750602083015115806135915750600354600160a060020a038581169116636352211e602086015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561356b57600080fd5b6102c65a03f1151561357c57600080fd5b50505060405180519050600160a060020a0316145b80156136235750604083015115806136235750600354600160a060020a038581169116636352211e604086015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b15156135fd57600080fd5b6102c65a03f1151561360e57600080fd5b50505060405180519050600160a060020a0316145b80156136b55750606083015115806136b55750600354600160a060020a038581169116636352211e606086015160006040516020015260405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561368f57600080fd5b6102c65a03f115156136a057600080fd5b50505060405180519050600160a060020a0316145b15613a135782511561377b57600354600160a060020a03166375e39f2684516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b151561371557600080fd5b6102c65a03f1151561372657600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a001805150602001604052509095508694506000935061377592505050565b60200201525b60208301511561384257600354600160a060020a03166375e39f2660208501516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b15156137dc57600080fd5b6102c65a03f115156137ed57600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a001805150602001604052509095508694506001935061383c92505050565b60200201525b60408301511561390957600354600160a060020a03166375e39f2660408501516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b15156138a357600080fd5b6102c65a03f115156138b457600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a001805150602001604052509095508694506002935061390392505050565b60200201525b6060830151156139d057600354600160a060020a03166375e39f2660608501516000604051610220015260405160e060020a63ffffffff8416028152600481019190915260240161022060405180830381600087803b151561396a57600080fd5b6102c65a03f1151561397b57600080fd5b5050506040518051906020018051906020018051906020018051906020018051906020018051906020018060a0018060a00180515060200160405250909550869450600393506139ca92505050565b60200201525b428151111580156139e5575042602082015111155b80156139f5575042604082015111155b8015613a05575042606082015111155b15613a135760019150613a18565b600091505b5092915050565b613a27613f86565b613a2f613f86565b60008060008061010060405190810160409081526000808352600160208401526002918301919091526003606083015260046080830152600560a0830152600660c0830152600760e083015290955093505b60088460ff161015613bc0578360010192505b60088360ff161015613bb5578660ff841660088110613aaf57fe5b602002015163ffffffff168760ff861660088110613ac957fe5b602002015163ffffffff161015613baa578660ff851660088110613ae957fe5b602002015191508660ff841660088110613aff57fe5b60200201518760ff861660088110613b1357fe5b63ffffffff9092166020929092020152818760ff851660088110613b3357fe5b63ffffffff90921660209290920201528460ff851660088110613b5257fe5b602002015190508460ff841660088110613b6857fe5b60200201518560ff861660088110613b7c57fe5b60ff928316602091909102919091015281908690851660088110613b9c57fe5b60ff90921660209290920201525b600190920191613a94565b600190930192613a81565b509295945050505050565b600063ffffffff80831690841610613be4575081613be7565b50805b92915050565b600063ffffffff80831690841611613c0457600080fd5b600d546341c64e6d9063ffffffff16600d805463ffffffff1916929091066130390163ffffffff9081169290921790819055839182860381169116811515613c4857fe5b06019392505050565b600063ffffffff80841690831610613be4575081613be7565b600080831515613c91575050600954600854600563ffffffff9091160490600a9004613ca1565b505060095460085463ffffffff16905b600554600160a060020a03166340c10f19338360006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515613d0057600080fd5b6102c65a03f11515613d1157600080fd5b5050506040518051508590505115613da457600354600160a060020a0316631debbe2f8651848651640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613d8857600080fd5b6102c65a03f11515613d9957600080fd5b505050604051805150505b602085015115613e3557600354600160a060020a0316631debbe2f6020870151846020870151640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613e1957600080fd5b6102c65a03f11515613e2a57600080fd5b505050604051805150505b604085015115613ec657600354600160a060020a0316631debbe2f6040870151846040870151640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613eaa57600080fd5b6102c65a03f11515613ebb57600080fd5b505050604051805150505b606085015115613f5757600354600160a060020a0316631debbe2f6060870151846060870151640100000000030160006040516020015260405163ffffffff84811660e060020a028252600482019390935291166024820152604401602060405180830381600087803b1515613f3b57600080fd5b6102c65a03f11515613f4c57600080fd5b505050604051805150505b935093915050565b60806040519081016040526004815b6000815260200190600190039081613f6e5790505090565b6101006040519081016040526008815b600081526000199091019060200181613f965790505090565b61030060405190810160405260008152601760208201613f96565b6103006040519081016040908152600080835260208301528101613fec613f5f565b8152602001613ff9613f86565b8152602001614006613f86565b815260006020820181905260409091015290565b6107a06040519081016040526000815260208101614036613f86565b8152602001614043613faf565b8152602001614050613faf565b815260200161405d61427c565b905290565b6105006040519081016040526008815b61407a614296565b8152602001906001900390816140725790505090565b6102006040519081016040526008815b6140a86142b0565b8152602001906001900390816140a05790505090565b82600481019282156140ec579160200282015b828111156140ec5782518255916020019190600101906140d1565b506140f89291506142c9565b5090565b6001830191839082156141885791602002820160005b8382111561415657835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302614112565b80156141865782816101000a81549063ffffffff0219169055600401602081600301049283019260010302614156565b505b506140f89291506142e6565b6001830191839082156142175791602002820160005b838211156141e857835183826101000a81548160ff021916908360ff16021790555092602001926001016020816000010492830192600103026141aa565b80156142155782816101000a81549060ff02191690556001016020816000010492830192600103026141e8565b505b506140f8929150614307565b6003830191839082156141885791602002820160008382111561415657835183826101000a81548163ffffffff021916908363ffffffff1602179055509260200192600401602081600301049283019260010302614112565b608060405190810160405260008152600360208201613f96565b60a060405190810160405260008152600460208201613f96565b6040805190810160405260008152600160208201613f96565b6142e391905b808211156140f857600081556001016142cf565b90565b6142e391905b808211156140f857805463ffffffff191681556001016142ec565b6142e391905b808211156140f857805460ff1916815560010161430d5600a165627a7a723058202a355c55f26faec8f18bd73a5baee224b5dde97477be66c5df3892b2fba94b7e0029

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000067e72299beaf3f59f365bb4a43e8d02bff61e176000000000000000000000000abc7e6c01237e8eef355bba2bf925a730b714d5f0000000000000000000000001f6f71e1e6a56dc348f1ec9a22b200ac44459fe40000000000000000000000001b5242794288b45831ce069c9934a29b89af019700000000000000000000000059bcded9c87ce46ec97c13640bfc0390ceb00e990000000000000000000000006589adf7720a5b5f80bd391c0bbf2148d00be5ae0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000012c00000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000000000000000000000000002b5e3af16b18800000000000000000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _recordContractAddress (address): 0x67E72299bEaF3F59f365Bb4a43e8D02bfF61E176
Arg [1] : _heroContractAddress (address): 0xabC7e6c01237e8EeF355Bba2bF925A730b714d5f
Arg [2] : _correctedHeroContractAddress (address): 0x1f6F71E1E6A56Dc348f1Ec9a22B200ac44459fe4
Arg [3] : _cardContractAddress (address): 0x1b5242794288B45831cE069C9934a29B89aF0197
Arg [4] : _goldContractAddress (address): 0x59bCDeD9C87cE46eC97C13640BFC0390CEB00E99
Arg [5] : _firstPlayerAddress (address): 0x6589AdF7720a5B5f80Bd391C0BBF2148d00bE5ae
Arg [6] : _locationId (uint32): 100
Arg [7] : _coolHero (uint256): 300
Arg [8] : _expReward (uint32): 500
Arg [9] : _goldReward (uint256): 50000000000000000000
Arg [10] : _isTurnDataSaved (bool): False

-----Encoded View---------------
11 Constructor Arguments found :
Arg [0] : 00000000000000000000000067e72299beaf3f59f365bb4a43e8d02bff61e176
Arg [1] : 000000000000000000000000abc7e6c01237e8eef355bba2bf925a730b714d5f
Arg [2] : 0000000000000000000000001f6f71e1e6a56dc348f1ec9a22b200ac44459fe4
Arg [3] : 0000000000000000000000001b5242794288b45831ce069c9934a29b89af0197
Arg [4] : 00000000000000000000000059bcded9c87ce46ec97c13640bfc0390ceb00e99
Arg [5] : 0000000000000000000000006589adf7720a5b5f80bd391c0bbf2148d00be5ae
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000064
Arg [7] : 000000000000000000000000000000000000000000000000000000000000012c
Arg [8] : 00000000000000000000000000000000000000000000000000000000000001f4
Arg [9] : 000000000000000000000000000000000000000000000002b5e3af16b1880000
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000000


Swarm Source

bzzr://2a355c55f26faec8f18bd73a5baee224b5dde97477be66c5df3892b2fba94b7e

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.