pragma solidity ^0.4.25; // Standard ERC721 functions import contract ERC721 { // Required methods function approve(address _to, uint256 _tokenId) public; function balanceOf(address _owner) public view returns (uint256 balance); function implementsERC721() public pure returns (bool); function ownerOf(uint256 _tokenId) public view returns (address addr); function takeOwnership(uint256 _tokenId) public; function totalSupply() public view returns (uint256 total); function transferFrom(address _from, address _to, uint256 _tokenId) public; function transfer(address _to, uint256 _tokenId) public; event Transfer(address indexed from, address indexed to, uint256 tokenId); event Approval(address indexed owner, address indexed approved, uint256 tokenId); } contract PalettenToken is ERC721 { /**************************************/ /****************** EVENTS ************/ /*************************************/ ///@dev New User has been registered event NewPaletteHasBeenRequistered(uint256 _id, address _owner, address _issuer); /**************************************/ /*************** CONSTANTS ************/ /*************************************/ /// @notice Name and symbol of the non fungible token, as defined in ERC721. string public constant NAME = "PalettenToken"; string public constant SYMBOL = "PAT"; // zu ersetzen durch eine Whitelist address ceoAddress; /**************************************/ /*************** Mappings ************/ /*************************************/ /// @dev A mapping from Player IDs to the address that owns them. All Players have /// some valid owner address. mapping (uint256 => address) public OwnerByPalettenID; // @dev A mapping from owner address to count of tokens that address owns. // Used internally inside balanceOf() to resolve ownership count. mapping (address => Palette[]) public PalettenOfOwner; //mapping for different qualities mapping (uint256 => uint8) public APlettes; mapping (uint256 => uint8) public BPlettes; mapping (uint256 => uint8) public CPlettes; mapping (uint256 => uint8) public DPlettes; /**************************************/ /*************** DATATYPES ************/ /*************************************/ struct Palette { uint256 id; uint8 palettenType; // quality from A to D; 0to 3 uint8 quality; string place; address owner; } Palette[] private paletten; /**************************************/ /*************** MODIFIERS ************/ /*************************************/ modifier onlyExecutableByOwner() { require(msg.sender == ceoAddress); _; } modifier secureHandOver(address _newOwner){ require(msg.sender == _newOwner); _; } /**************************************/ /************ CONSTRUCTOR ************/ /*************************************/ constructor() public { ceoAddress = msg.sender; } /**************************************/ /*************** FUNCTIONS ************/ /*************************************/ function generateNewPalette(uint8 _palettenType, uint8 _quality, string _place, address _owner) public onlyExecutableByOwner { Palette memory _palette = Palette({ id: paletten.length, palettenType: _palettenType, quality: _quality, place: _place, owner: _owner }); paletten.push(_palette); } function adjustQualityOfPalette(uint256 _id, uint8 _newQuality) public { paletten[_id].quality = _newQuality; } function changeOwernshipOfPalette(uint256 _id, address _newOwner) public { // makes sure, that the new owner accepted the quality of the palette require (msg.sender == _newOwner); paletten[_id].owner = _newOwner; } /**************************************/ /*************** GETTERS ************/ /*************************************/ function getPalettenInfo(uint256 _id) public view returns (uint8 _palettenType, uint8 _quality, string _place, address _owner){ _palettenType = paletten[_id].palettenType; _quality = paletten[_id].quality; _place = paletten[_id].place; _owner = paletten[_id].owner; return (_palettenType, _quality, _place, _owner); } } 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; } }
0.4.25