Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
//Ownable ¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? contract Ownable{ address public owner; //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function Ownable(){ owner = msg.sender; } //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? modifier onlyOwner(){ require(msg.sender == owner); _; } //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?newOwner¿? function transferOwnership(address newOwner)onlyOwner{ if(newOwner != address(0)){ owner =newOwner; } } } contract pigAccessControl is Ownable{ /** *government¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? *¿?¿?¿?¿?¿?¿?¿?pigcore¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? */ ///¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? //¿?¿?¿?¿?¿? address public governmentAdddress; User public user; //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? bool public paused = false; enum Role{Farm, Slaugthethouse, Logistics, Market}//¿?¿? struct User{ address roleAddress; uint256 roleId; string location; Role role; } mapping (address => User) public FarmMap; mapping (address => User) public SlaughterhouseMap; mapping (address => User) public LogisticsMap; mapping (address => User) public MarkeMap; //¿?¿?government¿?¿?¿?¿?¿?¿?¿?¿? modifier onlyGovernment(){ require(msg.sender == governmentAdddress); _; } //¿?¿?farm¿?¿?¿?¿?¿?¿?¿?¿? modifier onlyFarm(){ require(msg.sender == user.roleAddress); _; } //¿?¿?slaughterhouse¿?¿?¿?¿?¿?¿?¿?¿? modifier onlySlaughterhouse(){ require(msg.sender == user.roleAddress); _; } //¿?¿?logistics¿?¿?¿?¿?¿?¿?¿?¿? modifier onlyLogistics(){ require(msg.sender == user.roleAddress); _; } //¿?¿?market¿?¿?¿?¿?¿?¿?¿?¿? modifier onlyMarket(){ require(msg.sender == user.roleAddress); _; } //¿?¿?¿?¿?¿?¿?¿?¿?¿?government,¿?¿?¿?¿?¿?¿?government¿?¿?¿? //_newGovernment¿?¿?government¿?¿?¿? function setGovernment(address _newGovernment)external onlyOwner { require(_newGovernment != address(0)); governmentAdddress = _newGovernment; } function newUser(uint256 ID, string location,Role role) returns(bool, address,Role,string){ if(role == Role.Farm){ //user = FarmMap[msg.sender]; user.roleAddress = msg.sender; user.roleId = ID; user.location = location; user.role = role; FarmMap[msg.sender] = user; }else if(role == Role.Slaugthethouse){ //user = SlaughterhouseMap[msg.sender]; user.roleAddress = msg.sender; user.roleId = ID; user.location = location; user.role = role; SlaughterhouseMap[msg.sender] = user; }else if(role == Role.Logistics){ // user = LogisticsMap[msg.sender]; user.roleAddress = msg.sender; user.roleId = ID; user.location = location; user.role = role; LogisticsMap[msg.sender] = user; }else if(role == Role.Market){ //user = MarkeMap[msg.sender]; user.roleAddress = msg.sender; user.roleId = ID; user.location = location; user.role = role; MarkeMap[msg.sender] = user; }else{ return (false,user.roleAddress, user.role,"the actor is not belong"); } if(user.roleId != 0x0){ return (false, user.roleAddress, user.role,"this ID has been occupied!"); } user.roleAddress = msg.sender; user.roleId = ID; user.location = location; user.role = role; return (true, user.roleAddress, user.role,"Success"); } //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? modifier whennotPaused{ require(!paused); _; } //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? modifier whenPaused{ require(paused); _; } //¿?¿?government¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?,¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function pause() external onlyGovernment whennotPaused{ paused == true; } //¿?¿?government¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?,¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function unpause() public onlyGovernment whenPaused { paused == false; } } ///¿?¿?ERC721¿?¿?¿?¿?¿? contract ERC721 { // Required methods //¿?¿?¿?¿?token¿?¿?¿? function totalSupply() public view returns (uint256 total); //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function balanceOf(address _owner) public view returns (uint256 balance); //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function ownerOf(uint256 _tokenId) external view returns (address owner); //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function transfer(address _to, uint256 _tokenId) external; // Events event Transfer(address from, address to, uint256 tokenId); function tokensOfOwner(address _owner) external view returns (uint256[] tokenIds); // ERC-165 Compatibility (ethereum/EIPs#165) function supportsInterface(bytes4 _interfaceID) external view returns (bool); } /// ¿?¿?pig¿?¿?¿?¿?¿?¿?¿?pig¿?¿?¿?¿?¿? contract pigBase is pigAccessControl{ //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?Birth¿?¿?¿? event Birth(uint256 pigID, address owner, uint64 birthTime, uint256 breed, uint256 weight, int8 gender); //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? event Transfer(address from, address to, uint256 tokenId); /** * pig¿?¿?¿? */ struct pig{ //¿?¿?¿?¿?¿? address currentAddress; //¿?¿?¿?¿? uint64 birthTime; //¿?¿? uint256 breed; //¿?¿? uint256 weight; //¿?¿? int8 gender; } //¿?¿?¿?¿?¿?¿?pig¿?¿?¿?¿?¿?,¿?¿?pig¿?ID¿?¿?¿?¿?¿?¿?¿?¿? pig[] pigs; //¿?pigID¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? mapping(uint256 => address) public pigIndexToOwner; //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? mapping(address => uint256) public ownershipTokenCount; //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function _transfer(address _from, address _to, uint256 _tokenId)internal{ ownershipTokenCount[_to]++; // ¿?¿?¿?¿? pigIndexToOwner[_tokenId] = _to; // ¿?¿?¿?¿?¿?¿?¿?¿?¿?0x0¿?¿?¿? if(_from != address(0)){ ownershipTokenCount[_from]--; } //¿?¿?¿?¿?¿?¿?¿?¿? Transfer(_from, _to, _tokenId); } /** * ¿?¿?¿?¿?newpig¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? * ¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?,¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? * ¿?¿?¿?Birth¿?¿?¿?Transfer¿?¿?¿? */ function createPig ( uint256 _breed, uint256 _weight, int8 _gender ) external returns (uint256) { pig memory _pig = pig({ currentAddress : msg.sender, birthTime : uint64(now), breed : _breed, weight : _weight, gender : _gender }); uint256 newPigID = pigs.push(_pig) - 1; // ¿?¿?Birth¿?¿? emit Birth(newPigID, msg.sender,uint64(now), _breed, _weight, _gender); // ¿?¿?¿?¿?¿?¿?¿?¿?¿?Transfer¿?¿? // ¿?¿?ERC721¿?¿? _transfer(0, msg.sender, newPigID); return newPigID; } } /// ¿?¿?¿?¿?¿?KittyBase¿?ERC721¿?¿?¿?ERC721¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? contract pigOwnership is pigBase,ERC721{ //¿?¿?ERC721¿?Name¿?symbol¿?¿?¿?¿?¿?¿?¿?Token string public constant name = "Pig¿?s Life"; string public constant symbol = "PIE"; bytes4 constant InterfaceSignature_ERC165 = bytes4(keccak256('supportsInterface(bytes4)')); bytes4 constant InterfaceSignature_ERC721 = bytes4(keccak256('name()')) ^ bytes4(keccak256('symbol()')) ^ bytes4(keccak256('totalSupply()')) ^ bytes4(keccak256('balanceOf(address)')) ^ bytes4(keccak256('ownerOf(uint256)')) ^ bytes4(keccak256('approve(address,uint256)')) ^ bytes4(keccak256('transfer(address,uint256)')) ^ bytes4(keccak256('transferFrom(address,address,uint256)')) ^ bytes4(keccak256('tokensOfOwner(address)')) ^ bytes4(keccak256('tokenMetadata(uint256,string)')); //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?ERC721¿?ERC165¿?¿? function supportsInterface(bytes4 _interfaceID)external view returns(bool){ return((_interfaceID == InterfaceSignature_ERC721) || (_interfaceID == InterfaceSignature_ERC165)); } // ¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? // _currentAddress ¿?¿?¿?¿?¿?¿?¿?¿? function _owns(address _currentAddress, uint256 _tokenId) internal view returns (bool){ return pigIndexToOwner[_tokenId] == _currentAddress; } //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function balanceOf(address _owner)public view returns(uint256 count){ return ownershipTokenCount[_owner]; } //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?ERC-721¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function transfer(address _to, uint256 _tokenId) external { // ¿?¿?¿?¿?¿?0x0 require(_to != address(0)); require(_to !=address(this)); // ¿?¿?¿?¿?¿?¿?¿?¿? require(_owns(msg.sender,_tokenId)); // ¿?¿?¿?¿?¿?¿?¿?Transfer¿?¿? _transfer(msg.sender, _to, _tokenId); pig storage Pig = pigs[_tokenId]; Pig.currentAddress = pigIndexToOwner[_tokenId]; // pigs.push(Pig); emit Transfer(msg.sender, _to, _tokenId); } //¿?¿?¿?¿?¿?¿?¿?¿? function totalSupply()public view returns(uint){ return pigs.length; } //¿?¿?¿?¿?¿?¿?¿?¿? function ownerOf(uint256 _tokenId)external view returns(address owner){ owner = pigIndexToOwner[_tokenId]; require(owner != address(0)); } // ¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿? function tokensOfOwner(address _owner)external view returns(uint256[] ownerTokens){ // ¿?¿?_owner¿?¿?¿?¿?¿?¿?¿? uint256 tokenCount = balanceOf(_owner); if(tokenCount == 0){ // ¿?¿?¿?¿?¿?¿?¿?¿?¿? return new uint256[](0); }else{ //¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?result¿?¿?¿?¿?tokenCount uint256[] memory result = new uint256[](tokenCount); // ¿?¿?¿?¿?¿?¿?¿?¿? uint256 tolalPigs = totalSupply(); // ¿?¿?¿?¿?¿?¿? uint256 resultIndex = 0; } // ¿?¿?ID¿?1¿?¿?¿?¿? uint256 pigID; // ¿?1¿?¿?¿?¿?¿?¿?¿?¿?¿?tolalPigs for(pigID =0; pigID < tolalPigs; pigID++){ // ¿?¿?¿?¿?pigID¿?¿?¿?¿?¿?¿?¿?_owner if(pigIndexToOwner[pigID] == _owner){ // ¿?¿?¿?¿?¿?pigID¿?¿?result¿?¿?resultIndex¿?¿? result[resultIndex] = pigID; resultIndex++; } } return result; } } contract pigSeparation is pigOwnership{ //¿?¿?¿?¿?¿?¿? //¿?¿?¿?¿?¿?¿? } ///¿?¿?¿? contract pigCore is pigOwnership{ function getPig(uint256 _id) external view returns( address currentAddress, uint64 birthTime, uint256 breed, uint256 weight, int8 gender ){ pig storage Pig = pigs[_id]; currentAddress = address(Pig.currentAddress); birthTime = uint64(Pig.birthTime); breed = uint256(Pig.breed); weight = uint256(Pig.weight); gender = int8(Pig.gender); } }
- Loading branch information