Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
CryptoSagaArenaRecord
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++; } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"constant":true,"inputs":[],"name":"getRecentPlayersCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"numberOfRecentPlayers","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getEloRating","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"leaderBoardPlayers","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"claimOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"grantAccessDeploy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"addressToElo","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"recentPlayers","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getRecentPlayers","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getLeaderboardPlayers","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getLeaderboardLength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recentPlayersBack","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_myAddress","type":"address"},{"name":"_enemyAddress","type":"address"},{"name":"_didWin","type":"bool"}],"name":"updateRecord","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"recentPlayersFront","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"addressToIsInLeaderboard","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"numberOfLeaderboardPlayers","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"revokeAccessDeploy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"pendingOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_firstPlayerAddress","type":"address"},{"name":"_firstPlayerElo","type":"uint32"},{"name":"_numberOfLeaderboardPlayers","type":"uint8"},{"name":"_numberOfRecentPlayers","type":"uint8"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_by","type":"address"},{"indexed":false,"name":"_dateTime","type":"uint256"}],"name":"UpdateLeaderboard","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"}]
Contract Creation Code
60606040526000805460a060020a60ff02191690556003805460ff1990811660191790915560068054909116603217905534156200003c57600080fd5b604051608080620013358339810160405280805191906020018051919060200180519190602001805160008054600160a060020a033316600160a060020a03199091161790556003805460ff80871660ff1992831617909255600680549284169290911691909117905560048054919350915060018101620000bf83826200019a565b5060009182526020808320919091018054600160a060020a031916600160a060020a03881690811790915582526005905260409020805460ff19166001179055620001188464010000000062000151810262000e2e1704565b5050600160a060020a03919091166000908152600a60205260409020805463ffffffff191663ffffffff909216919091179055620001ea565b60078054600181016200016583826200019a565b5060009182526020909120018054600160a060020a031916600160a060020a0392909216919091179055600980546001019055565b815481835581811511620001c157600083815260209020620001c1918101908301620001c6565b505050565b620001e791905b80821115620001e35760008155600101620001cd565b5090565b90565b61113b80620001fa6000396000f3006060604052600436106101325763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632732938081146101375780633bce14c81461015c5780633c8a0b13146101855780633f4ba83a146101bd5780634794997f146101d25780634e71e0c814610204578063584283221461021757806358e3f1bc146102365780635c975abb146102555780636be20d4a1461027c5780638456cb591461029257806388508a18146102a55780638da5cb5b1461030b5780638e98c6b91461031e578063ab48660714610331578063b1ecb34314610344578063b52db3b914610357578063b87aedcc14610381578063bbeeca4814610394578063d47ee6c1146103b3578063de852afe146103c6578063e30c3978146103e5578063f2fde38b146103f8575b600080fd5b341561014257600080fd5b61014a610417565b60405190815260200160405180910390f35b341561016757600080fd5b61016f610422565b60405160ff909116815260200160405180910390f35b341561019057600080fd5b6101a4600160a060020a036004351661042b565b60405163ffffffff909116815260200160405180910390f35b34156101c857600080fd5b6101d061047e565b005b34156101dd57600080fd5b6101e86004356104fd565b604051600160a060020a03909116815260200160405180910390f35b341561020f57600080fd5b6101d0610525565b341561022257600080fd5b6101d0600160a060020a03600435166105a6565b341561024157600080fd5b6101a4600160a060020a03600435166105e5565b341561026057600080fd5b6102686105fd565b604051901515815260200160405180910390f35b341561028757600080fd5b6101e860043561060d565b341561029d57600080fd5b6101d061061b565b34156102b057600080fd5b6102b861069f565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156102f75780820151838201526020016102df565b505050509050019250505060405180910390f35b341561031657600080fd5b6101e8610707565b341561032957600080fd5b6102b8610716565b341561033c57600080fd5b61014a61077c565b341561034f57600080fd5b61014a610782565b341561036257600080fd5b6101d0600160a060020a03600435811690602435166044351515610788565b341561038c57600080fd5b61014a610cbc565b341561039f57600080fd5b610268600160a060020a0360043516610cc2565b34156103be57600080fd5b61016f610cd7565b34156103d157600080fd5b6101d0600160a060020a0360043516610ce0565b34156103f057600080fd5b6101e8610d1c565b341561040357600080fd5b6101d0600160a060020a0360043516610d2b565b600854600954035b90565b60065460ff1681565b600160a060020a0381166000908152600a602052604081205463ffffffff16156104745750600160a060020a0381166000908152600a602052604090205463ffffffff16610479565b506105dc5b919050565b60005433600160a060020a0390811691161461049957600080fd5b60005460a060020a900460ff1615156104b157600080fd5b6000805474ff0000000000000000000000000000000000000000191690557f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600480548290811061050b57fe5b600091825260209091200154600160a060020a0316905081565b60015433600160a060020a0390811691161461054057600080fd5b600154600054600160a060020a0391821691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36001805460008054600160a060020a0319908116600160a060020a03841617909155169055565b60005433600160a060020a039081169116146105c157600080fd5b600160a060020a03166000908152600260205260409020805460ff19166001179055565b600a6020526000908152604090205463ffffffff1681565b60005460a060020a900460ff1681565b600780548290811061050b57fe5b60005433600160a060020a0390811691161461063657600080fd5b60005460a060020a900460ff161561064d57600080fd5b6000805474ff0000000000000000000000000000000000000000191660a060020a1790557f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b6106a76110b6565b60078054806020026020016040519081016040528092919081815260200182805480156106fd57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116106df575b5050505050905090565b600054600160a060020a031681565b61071e6110b6565b60048054806020026020016040519081016040528092919081815260200182805480156106fd57602002820191906000526020600020908154600160a060020a031681526001909101906020018083116106df575050505050905090565b60045490565b60095481565b6000805481908190819060a060020a900460ff16156107a657600080fd5b60005433600160a060020a03908116911614806107e05750600160a060020a03331660009081526002602052604090205460ff1615156001145b15156107eb57600080fd5b846107f657856107f8565b865b9350846108055786610807565b855b600160a060020a0385166000908152600a602052604090205490935063ffffffff169150811515610838576105dc91505b50600160a060020a0382166000908152600a602052604090205463ffffffff1680151561086457506105dc5b63ffffffff80821690831610610a4e57603281830363ffffffff1610156108d657600160a060020a038085166000908152600a6020526040808220805463ffffffff60058801811663ffffffff1992831617909255938716835291208054600419850190921691909216179055610a49565b605081830363ffffffff16101561093857600160a060020a038085166000908152600a6020526040808220805463ffffffff60048801811663ffffffff1992831617909255938716835291208054600319850190921691909216179055610a49565b609681830363ffffffff16101561099a57600160a060020a038085166000908152600a6020526040808220805463ffffffff60038801811663ffffffff1992831617909255938716835291208054600219850190921691909216179055610a49565b60fa81830363ffffffff1610156109fc57600160a060020a038085166000908152600a6020526040808220805463ffffffff60028801811663ffffffff1992831617909255938716835291208054600119850190921691909216179055610a49565b600160a060020a038085166000908152600a6020526040808220805463ffffffff60018801811663ffffffff19928316179092559387168352912080546000198501909216919092161790555b610c23565b603282820363ffffffff161015610ab057600160a060020a038085166000908152600a6020526040808220805463ffffffff60058801811663ffffffff1992831617909255938716835291208054600419850190921691909216179055610c23565b605082820363ffffffff161015610b1257600160a060020a038085166000908152600a6020526040808220805463ffffffff60068801811663ffffffff1992831617909255938716835291208054600519850190921691909216179055610c23565b609682820363ffffffff161015610b7457600160a060020a038085166000908152600a6020526040808220805463ffffffff60078801811663ffffffff1992831617909255938716835291208054600619850190921691909216179055610c23565b60fa82820363ffffffff161015610bd657600160a060020a038085166000908152600a6020526040808220805463ffffffff60088801811663ffffffff1992831617909255938716835291208054600719850190921691909216179055610c23565b600160a060020a038085166000908152600a6020526040808220805463ffffffff60098801811663ffffffff19928316179092559387168352912080546008198501909216919092161790555b610c2c87610d68565b1515610c585760065460ff16610c40610417565b10610c4f57610c4d610db9565b505b610c5887610e2e565b610c6186610e75565b80610c705750610c7087610e75565b15610cb35786600160a060020a03167f2c0fc499426d009673f35a90921a0b51c0faf04f3f9155528a785157c3c82f514260405190815260200160405180910390a25b50505050505050565b60085481565b60056020526000908152604090205460ff1681565b60035460ff1681565b60005433600160a060020a03908116911614610cfb57600080fd5b600160a060020a03166000908152600260205260409020805460ff19169055565b600154600160a060020a031681565b60005433600160a060020a03908116911614610d4657600080fd5b60018054600160a060020a031916600160a060020a0392909216919091179055565b6008546000905b600954811015610db3576007805482908110610d8757fe5b600091825260209091200154600160a060020a0384811691161415610dab57600191505b600101610d6f565b50919050565b60006008546009541415610dcf5750600061041f565b6007600854815481101515610de057fe5b60009182526020909120015460085460078054600160a060020a039093169350918110610e0957fe5b60009182526020909120018054600160a060020a031916905560088054600101905590565b6007805460018101610e4083826110c8565b5060009182526020909120018054600160a060020a031916600160a060020a0392909216919091179055600980546001019055565b6000805481908190819060a060020a900460ff1615610e9357600080fd5b600160a060020a03851660009081526005602052604090205460ff1615610eb9576110ae565b60035460045460ff90911690106110565750506003546201869f915060ff1660005b60045460ff82161015610f8357600a600060048360ff16815481101515610efe57fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205463ffffffff9081169084161115610f7b57600a600060048360ff16815481101515610f4a57fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205463ffffffff1692509050805b600101610edb565b600160a060020a0385166000908152600a602052604090205463ffffffff90811690841611611051578460048360ff16815481101515610fbf57fe5b60009182526020808320919091018054600160a060020a031916600160a060020a03948516179055918716815260059182905260408120805460ff191660011790556004805491929183919060ff871690811061101857fe5b600091825260208083209190910154600160a060020a031683528201929092526040019020805460ff1916911515919091179055600193505b6110ae565b600480546001810161106883826110c8565b5060009182526020808320919091018054600160a060020a031916600160a060020a03891690811790915582526005905260409020805460ff1916600190811790915593505b505050919050565b60206040519081016040526000815290565b8154818355818115116110ec576000838152602090206110ec9181019083016110f1565b505050565b61041f91905b8082111561110b57600081556001016110f7565b50905600a165627a7a7230582015080735f66e4e1ca33b47fe3fcee22b34067f4fdbb60fc6acd41721fe06709600290000000000000000000000006589adf7720a5b5f80bd391c0bbf2148d00be5ae00000000000000000000000000000000000000000000000000000000000005dc00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000032
Deployed Bytecode
0x6060604052600436106101325763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632732938081146101375780633bce14c81461015c5780633c8a0b13146101855780633f4ba83a146101bd5780634794997f146101d25780634e71e0c814610204578063584283221461021757806358e3f1bc146102365780635c975abb146102555780636be20d4a1461027c5780638456cb591461029257806388508a18146102a55780638da5cb5b1461030b5780638e98c6b91461031e578063ab48660714610331578063b1ecb34314610344578063b52db3b914610357578063b87aedcc14610381578063bbeeca4814610394578063d47ee6c1146103b3578063de852afe146103c6578063e30c3978146103e5578063f2fde38b146103f8575b600080fd5b341561014257600080fd5b61014a610417565b60405190815260200160405180910390f35b341561016757600080fd5b61016f610422565b60405160ff909116815260200160405180910390f35b341561019057600080fd5b6101a4600160a060020a036004351661042b565b60405163ffffffff909116815260200160405180910390f35b34156101c857600080fd5b6101d061047e565b005b34156101dd57600080fd5b6101e86004356104fd565b604051600160a060020a03909116815260200160405180910390f35b341561020f57600080fd5b6101d0610525565b341561022257600080fd5b6101d0600160a060020a03600435166105a6565b341561024157600080fd5b6101a4600160a060020a03600435166105e5565b341561026057600080fd5b6102686105fd565b604051901515815260200160405180910390f35b341561028757600080fd5b6101e860043561060d565b341561029d57600080fd5b6101d061061b565b34156102b057600080fd5b6102b861069f565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156102f75780820151838201526020016102df565b505050509050019250505060405180910390f35b341561031657600080fd5b6101e8610707565b341561032957600080fd5b6102b8610716565b341561033c57600080fd5b61014a61077c565b341561034f57600080fd5b61014a610782565b341561036257600080fd5b6101d0600160a060020a03600435811690602435166044351515610788565b341561038c57600080fd5b61014a610cbc565b341561039f57600080fd5b610268600160a060020a0360043516610cc2565b34156103be57600080fd5b61016f610cd7565b34156103d157600080fd5b6101d0600160a060020a0360043516610ce0565b34156103f057600080fd5b6101e8610d1c565b341561040357600080fd5b6101d0600160a060020a0360043516610d2b565b600854600954035b90565b60065460ff1681565b600160a060020a0381166000908152600a602052604081205463ffffffff16156104745750600160a060020a0381166000908152600a602052604090205463ffffffff16610479565b506105dc5b919050565b60005433600160a060020a0390811691161461049957600080fd5b60005460a060020a900460ff1615156104b157600080fd5b6000805474ff0000000000000000000000000000000000000000191690557f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600480548290811061050b57fe5b600091825260209091200154600160a060020a0316905081565b60015433600160a060020a0390811691161461054057600080fd5b600154600054600160a060020a0391821691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36001805460008054600160a060020a0319908116600160a060020a03841617909155169055565b60005433600160a060020a039081169116146105c157600080fd5b600160a060020a03166000908152600260205260409020805460ff19166001179055565b600a6020526000908152604090205463ffffffff1681565b60005460a060020a900460ff1681565b600780548290811061050b57fe5b60005433600160a060020a0390811691161461063657600080fd5b60005460a060020a900460ff161561064d57600080fd5b6000805474ff0000000000000000000000000000000000000000191660a060020a1790557f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b6106a76110b6565b60078054806020026020016040519081016040528092919081815260200182805480156106fd57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116106df575b5050505050905090565b600054600160a060020a031681565b61071e6110b6565b60048054806020026020016040519081016040528092919081815260200182805480156106fd57602002820191906000526020600020908154600160a060020a031681526001909101906020018083116106df575050505050905090565b60045490565b60095481565b6000805481908190819060a060020a900460ff16156107a657600080fd5b60005433600160a060020a03908116911614806107e05750600160a060020a03331660009081526002602052604090205460ff1615156001145b15156107eb57600080fd5b846107f657856107f8565b865b9350846108055786610807565b855b600160a060020a0385166000908152600a602052604090205490935063ffffffff169150811515610838576105dc91505b50600160a060020a0382166000908152600a602052604090205463ffffffff1680151561086457506105dc5b63ffffffff80821690831610610a4e57603281830363ffffffff1610156108d657600160a060020a038085166000908152600a6020526040808220805463ffffffff60058801811663ffffffff1992831617909255938716835291208054600419850190921691909216179055610a49565b605081830363ffffffff16101561093857600160a060020a038085166000908152600a6020526040808220805463ffffffff60048801811663ffffffff1992831617909255938716835291208054600319850190921691909216179055610a49565b609681830363ffffffff16101561099a57600160a060020a038085166000908152600a6020526040808220805463ffffffff60038801811663ffffffff1992831617909255938716835291208054600219850190921691909216179055610a49565b60fa81830363ffffffff1610156109fc57600160a060020a038085166000908152600a6020526040808220805463ffffffff60028801811663ffffffff1992831617909255938716835291208054600119850190921691909216179055610a49565b600160a060020a038085166000908152600a6020526040808220805463ffffffff60018801811663ffffffff19928316179092559387168352912080546000198501909216919092161790555b610c23565b603282820363ffffffff161015610ab057600160a060020a038085166000908152600a6020526040808220805463ffffffff60058801811663ffffffff1992831617909255938716835291208054600419850190921691909216179055610c23565b605082820363ffffffff161015610b1257600160a060020a038085166000908152600a6020526040808220805463ffffffff60068801811663ffffffff1992831617909255938716835291208054600519850190921691909216179055610c23565b609682820363ffffffff161015610b7457600160a060020a038085166000908152600a6020526040808220805463ffffffff60078801811663ffffffff1992831617909255938716835291208054600619850190921691909216179055610c23565b60fa82820363ffffffff161015610bd657600160a060020a038085166000908152600a6020526040808220805463ffffffff60088801811663ffffffff1992831617909255938716835291208054600719850190921691909216179055610c23565b600160a060020a038085166000908152600a6020526040808220805463ffffffff60098801811663ffffffff19928316179092559387168352912080546008198501909216919092161790555b610c2c87610d68565b1515610c585760065460ff16610c40610417565b10610c4f57610c4d610db9565b505b610c5887610e2e565b610c6186610e75565b80610c705750610c7087610e75565b15610cb35786600160a060020a03167f2c0fc499426d009673f35a90921a0b51c0faf04f3f9155528a785157c3c82f514260405190815260200160405180910390a25b50505050505050565b60085481565b60056020526000908152604090205460ff1681565b60035460ff1681565b60005433600160a060020a03908116911614610cfb57600080fd5b600160a060020a03166000908152600260205260409020805460ff19169055565b600154600160a060020a031681565b60005433600160a060020a03908116911614610d4657600080fd5b60018054600160a060020a031916600160a060020a0392909216919091179055565b6008546000905b600954811015610db3576007805482908110610d8757fe5b600091825260209091200154600160a060020a0384811691161415610dab57600191505b600101610d6f565b50919050565b60006008546009541415610dcf5750600061041f565b6007600854815481101515610de057fe5b60009182526020909120015460085460078054600160a060020a039093169350918110610e0957fe5b60009182526020909120018054600160a060020a031916905560088054600101905590565b6007805460018101610e4083826110c8565b5060009182526020909120018054600160a060020a031916600160a060020a0392909216919091179055600980546001019055565b6000805481908190819060a060020a900460ff1615610e9357600080fd5b600160a060020a03851660009081526005602052604090205460ff1615610eb9576110ae565b60035460045460ff90911690106110565750506003546201869f915060ff1660005b60045460ff82161015610f8357600a600060048360ff16815481101515610efe57fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205463ffffffff9081169084161115610f7b57600a600060048360ff16815481101515610f4a57fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205463ffffffff1692509050805b600101610edb565b600160a060020a0385166000908152600a602052604090205463ffffffff90811690841611611051578460048360ff16815481101515610fbf57fe5b60009182526020808320919091018054600160a060020a031916600160a060020a03948516179055918716815260059182905260408120805460ff191660011790556004805491929183919060ff871690811061101857fe5b600091825260208083209190910154600160a060020a031683528201929092526040019020805460ff1916911515919091179055600193505b6110ae565b600480546001810161106883826110c8565b5060009182526020808320919091018054600160a060020a031916600160a060020a03891690811790915582526005905260409020805460ff1916600190811790915593505b505050919050565b60206040519081016040526000815290565b8154818355818115116110ec576000838152602090206110ec9181019083016110f1565b505050565b61041f91905b8082111561110b57600081556001016110f7565b50905600a165627a7a7230582015080735f66e4e1ca33b47fe3fcee22b34067f4fdbb60fc6acd41721fe0670960029
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000006589adf7720a5b5f80bd391c0bbf2148d00be5ae00000000000000000000000000000000000000000000000000000000000005dc00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000032
-----Decoded View---------------
Arg [0] : _firstPlayerAddress (address): 0x6589AdF7720a5B5f80Bd391C0BBF2148d00bE5ae
Arg [1] : _firstPlayerElo (uint32): 1500
Arg [2] : _numberOfLeaderboardPlayers (uint8): 20
Arg [3] : _numberOfRecentPlayers (uint8): 50
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000006589adf7720a5b5f80bd391c0bbf2148d00be5ae
Arg [1] : 00000000000000000000000000000000000000000000000000000000000005dc
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000014
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000032
Swarm Source
bzzr://15080735f66e4e1ca33b47fe3fcee22b34067f4fdbb60fc6acd41721fe067096
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 25 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
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.