Created
April 13, 2018 17:18
-
-
Save koras/8990826ae580f3d3faf6eb22a41e5058 to your computer and use it in GitHub Desktop.
StorageContract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.18; | |
| /** | |
| * @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 ownerCEO; | |
| address ownerContract; | |
| bool pauseContractStorage = false; | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| function Ownable() public { | |
| ownerCEO = msg.sender; | |
| ownerContract = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == ownerCEO); | |
| _; | |
| } | |
| modifier onlyContract() { | |
| require(msg.sender == ownerContract && !pauseContractStorage || msg.sender == ownerCEO && !pauseContractStorage); | |
| _; | |
| } | |
| function transferOwnership(address newCEO) public onlyOwner { | |
| if (newCEO != address(0)) { | |
| ownerCEO = newCEO; | |
| } | |
| } | |
| function transferOwnershipContract(address newContract) public onlyOwner { | |
| if (newContract != address(0)) { | |
| ownerContract = newContract; | |
| } | |
| } | |
| } | |
| contract StorageRabbit is Ownable { | |
| // Long time | |
| uint public stepMoney = 2*60*60; | |
| // reward chain | |
| mapping (uint32 => uint32[32]) public rabbitMother; | |
| uint32[] rabbitMotherCount; | |
| mapping (uint32 => uint16) rabbitRole; | |
| mapping (uint32 => uint) rabbitSirePrice; | |
| mapping (uint32 => uint32[32]) public mapDNK; | |
| uint32[15] public cooldowns = [ | |
| uint32(1 minutes), | |
| uint32(2 minutes), | |
| uint32(4 minutes), | |
| uint32(8 minutes), | |
| uint32(16 minutes), | |
| uint32(32 minutes), | |
| uint32(1 hours), | |
| uint32(2 hours), | |
| uint32(4 hours), | |
| uint32(8 hours), | |
| uint32(16 hours), | |
| uint32(1 days), | |
| uint32(2 days), | |
| uint32(4 days), | |
| uint32(7 days) | |
| ]; | |
| struct Rabbit { | |
| // родители | |
| uint32 mother; | |
| uint32 sire; | |
| //indexGenome | |
| // uint256[32] gen; | |
| // может ли рожать | |
| bool birthbool; | |
| // дата рождения | |
| uint64 birthTime; | |
| // количество родов | |
| uint16 birthCount; | |
| // Время когда последний раз рожал Кролик | |
| uint64 birthLastTime; | |
| // кулдаун родов | |
| uint16 birthCooldown; | |
| } | |
| /** | |
| * Там где будем хранить информацию о кроликах | |
| */ | |
| Rabbit[] public rabbits; | |
| // mapping (uint32 => Rabbit) rabbits; | |
| uint32 public rabbitsCount = 0; | |
| /** | |
| * кому принадлежит кролик | |
| */ | |
| mapping (uint32 => address) public rabbitToOwner; | |
| /** | |
| * количество кроликов у текущего пользователя | |
| */ | |
| mapping (address => uint32) ownerRabbitCount; | |
| mapping (uint32 => string) public rabbitDescription; | |
| mapping (uint32 => string) public rabbitName; | |
| // @dev A mapping from owner address to count of tokens that address owns. | |
| // Used internally inside balanceOf() to resolve ownership count. | |
| mapping (address => uint256) ownershipTokenCount; | |
| // MARKET MARKET MARKET MARKET MARKET MARKET MARKET MARKET MARKET MARKET MARKET | |
| // ############################################################################# | |
| uint daysperiod = 1; | |
| uint sec = 1; | |
| // какое количество последний продаж учитывать в контракте перед формировании цены | |
| uint8 middlelast = 20; | |
| // средняя стоимость котика | |
| uint256 public middlePriceMoney = 1; | |
| // среднее время продаж | |
| uint256 middleSaleTime = 0; | |
| // на сколько определить стоимость продукта | |
| uint256 public moneyRange; | |
| // the last cost of a sold seal | |
| uint lastmoney = 0; | |
| // ID the last seal | |
| uint32 public lastIdGen0; | |
| // the time which was spent on the sale of the cat | |
| uint public lastTimeGen0; | |
| // number of seals currently on sale | |
| uint public bidCount = 0; | |
| /** | |
| * @param money; | |
| * @param timeStart; | |
| * @param timeFinish; | |
| */ | |
| struct BidClosed { | |
| uint money; | |
| uint timeStart; | |
| uint timeFinish; | |
| } | |
| mapping(uint32=>BidClosed) sellerOfRabbit; | |
| BidClosed[] public bidClosedArray; | |
| //how many closed auctions | |
| uint public closedCountBID = 0; | |
| /** | |
| * @param _rabbitID; | |
| * @param _rabbitSeller; | |
| * @param startMoney; | |
| * @param finishMoney; | |
| */ | |
| struct Bids { | |
| uint32 rabbitID; | |
| address rabbitSeller; | |
| uint startMoney; | |
| uint finishMoney; | |
| } | |
| Bids[] public bidsArray; | |
| uint public bidsCount = 0; | |
| /** | |
| * Google map storage | |
| * @param money; | |
| * @param timeStart; | |
| * @param timeFinish; | |
| */ | |
| struct GoogleMap { | |
| uint32 rabbitID; | |
| int64 lat; | |
| int64 long; | |
| } | |
| GoogleMap[] public googleMaps; | |
| uint32 googleMapsCount = 0; | |
| mapping (uint32 => bool) public googleMapsRabbits; | |
| mapping (uint32 => uint32) public googleMapsKey; | |
| // uint32[] googleMapsRabbits; | |
| } | |
| contract SetRabbit is StorageRabbit { | |
| function setPause() public onlyContract { | |
| if (pauseContractStorage) { | |
| pauseContractStorage = false; | |
| } else { | |
| pauseContractStorage = true; | |
| } | |
| } | |
| function setmiddlelast(uint8 _middlelast) public onlyContract { | |
| middlelast = _middlelast; | |
| } | |
| function setStepMoney(uint _stepMoney) public onlyContract { | |
| stepMoney = _stepMoney; | |
| } | |
| // reward chain | |
| function setArrayRabbitMother(uint32 _childern, uint32 _matron) public onlyContract { | |
| rabbitMother[_childern] = rabbitMother[_matron]; | |
| } | |
| function setRabbitMother(uint32 _childern, uint32 _matron) public onlyContract { | |
| uint count = rabbitMotherCount[_childern]; | |
| if (count < 32) { | |
| rabbitMother[_childern][count++] = _matron; | |
| } | |
| } | |
| function setRabbitRole(uint32 _rabbitID, uint16 _rabbitRole) public onlyContract { | |
| rabbitRole[_rabbitID] = _rabbitRole; | |
| } | |
| function setSirePrice(uint32 _rabbitID, uint _sirePrice) public onlyContract { | |
| rabbitSirePrice[_rabbitID] = _sirePrice; | |
| } | |
| function setMapDNK(uint32 _rabbitID, uint32[32] arrayDNK) public onlyContract { | |
| mapDNK[_rabbitID] = arrayDNK; | |
| } | |
| function setRabbits(uint32 matron, | |
| uint32 sire, | |
| bool birthbool, | |
| uint16 birthCount, | |
| uint64 birthLastTime, | |
| uint16 birthCooldown ) | |
| public onlyContract returns(uint32 countRabbit) | |
| { | |
| Rabbit memory rabbitStorage = Rabbit( | |
| matron, | |
| sire, | |
| birthbool, | |
| uint64(now), | |
| birthCount, | |
| birthLastTime, | |
| birthCooldown); | |
| rabbits[rabbitsCount++] = rabbitStorage; | |
| countRabbit = rabbitsCount; | |
| } | |
| function setRabbitToOwner(uint32 _rabbitID, address _ownerAddress) public onlyContract { | |
| rabbitToOwner[_rabbitID] = _ownerAddress; | |
| } | |
| function setOwnerRabbitCount(address _ownerAddress, uint32 _count) public onlyContract { | |
| ownerRabbitCount[_ownerAddress] = _count; | |
| } | |
| function setRabbitDescription(uint32 rabbitID, string _rabbitDescription) public onlyContract { | |
| rabbitDescription[rabbitID] = _rabbitDescription; | |
| } | |
| function setRabbitName(uint32 rabbitID, string _rabbitName) public onlyContract { | |
| rabbitName[rabbitID] = _rabbitName; | |
| } | |
| function setOwnershipTokenCount(address _ownerAddress, uint256 _count) public onlyContract { | |
| ownershipTokenCount[_ownerAddress] = _count; | |
| } | |
| function addCountOwnershipToken(address _ownerAddress) public onlyContract { | |
| ownershipTokenCount[_ownerAddress]++; | |
| } | |
| function subCountOwnershipToken(address _ownerAddress) public onlyContract { | |
| ownershipTokenCount[_ownerAddress]--; | |
| } | |
| function setPeriod(uint256 _day) public onlyContract { | |
| daysperiod = _day; | |
| } | |
| /** MARKET */ | |
| function setMiddlePriceMoney(uint256 newMiddlePriceMoney) public onlyContract { | |
| middlePriceMoney = newMiddlePriceMoney; | |
| } | |
| function setMiddleSaleTime(uint256 newmiddleSaleTime) public onlyContract { | |
| middleSaleTime = newmiddleSaleTime; | |
| } | |
| function setMoneyRange(uint256 newmoneyRange) public onlyContract { | |
| moneyRange = newmoneyRange; | |
| } | |
| function setLastmoney(uint newlastmoney) public onlyContract { | |
| lastmoney = newlastmoney; | |
| } | |
| function setLastIdGen0(uint32 newLastIdGen0) public onlyContract { | |
| lastTimeGen0 = newLastIdGen0; | |
| } | |
| function setLastTimeGen0(uint _lastTimeGen0) public onlyContract { | |
| lastTimeGen0 = _lastTimeGen0; | |
| } | |
| function setBidCount(uint _bidCount) public onlyContract { | |
| bidCount = _bidCount; | |
| } | |
| function setSellerOfRabbit(uint32 rabbitid, uint money, uint timeStart, uint timeFinish) public onlyContract { | |
| BidClosed memory bidClosedTmp = BidClosed(money, timeStart, timeFinish); | |
| bidClosedArray.push(bidClosedTmp); | |
| sellerOfRabbit[rabbitid] = (bidClosedTmp); | |
| } | |
| function setBids(uint32 _rabbitid, address _rabbitSeller, uint _startMoney, uint _finishMoney) public onlyContract { | |
| Bids memory tmp = Bids(_rabbitid, _rabbitSeller, _startMoney, _finishMoney); | |
| bidsArray.push(tmp); | |
| bidsCount++; | |
| } | |
| function setClosedCountBID(uint newClosedCountBID) public onlyContract { | |
| closedCountBID = newClosedCountBID; | |
| } | |
| // Google map | |
| function setGoogleMap(uint32 _rabbitID, int64 _lat, int64 _long) public onlyContract { | |
| GoogleMap memory googleMaptmp = GoogleMap(_rabbitID, _lat, _long); | |
| if (googleMapsRabbits[_rabbitID]) { | |
| uint32 index32 = uint32(googleMapsKey[_rabbitID]); | |
| googleMaps[index32] = googleMaptmp; | |
| } else { | |
| uint32 key = uint32(googleMaps.push(googleMaptmp)-1); | |
| googleMapsKey[_rabbitID] = key; | |
| googleMapsRabbits[_rabbitID] = true; | |
| googleMapsCount++; | |
| } | |
| } | |
| } | |
| contract GetRabbit is SetRabbit { | |
| function isUIntStorage() external pure returns (bool) { | |
| return true; | |
| } | |
| function getPause() public onlyContract view returns(bool) { | |
| return pauseContractStorage; | |
| } | |
| function getStepMoney() public onlyContract view returns(uint) { | |
| return stepMoney; | |
| } | |
| // reward chain | |
| function getRabbitMother(uint32 rabbitIDmother) public onlyContract view returns(uint32[32] mothers) { | |
| mothers = rabbitMother[rabbitIDmother]; | |
| } | |
| // reward chain | |
| function getClosedCountBID() public onlyContract view returns(uint256) { | |
| return closedCountBID; | |
| } | |
| // reward chain | |
| function getMiddlelast() public onlyContract view returns(uint8) { | |
| return middlelast; | |
| } | |
| // reward chain | |
| function getMiddleSaleTime() public onlyContract view returns(uint256) { | |
| return middleSaleTime; | |
| } | |
| // reward chain | |
| function getCountRabbitMother(uint32 rabbitIDmother) public onlyContract view returns(uint mothersLength) { | |
| mothersLength = rabbitMother[rabbitIDmother].length; | |
| } | |
| function getRabbitRole(uint32 rabbitID) public onlyContract view returns(uint16 role) { | |
| role = rabbitRole[rabbitID]; | |
| return role; | |
| } | |
| function getSirePrice(uint32 rabbitIDsire) public onlyContract view returns(uint256 matingCost) { | |
| matingCost = rabbitSirePrice[rabbitIDsire]; | |
| return matingCost; | |
| } | |
| function getMapDNK(uint32 rabbitID) public onlyContract view returns(uint32[32] rabbitDNK) { | |
| rabbitDNK = mapDNK[rabbitID]; | |
| return rabbitDNK; | |
| } | |
| function getRabbits(uint32 rabbitID ) | |
| public onlyContract view returns ( | |
| uint32 getMatron, | |
| uint32 getSire, | |
| bool getBirthbool, | |
| uint16 getBirthCount, | |
| uint64 getBirthLastTime, | |
| uint16 getBirthCooldown ) | |
| { | |
| Rabbit memory rabbitTmp = rabbits[rabbitID]; | |
| getMatron = rabbitTmp.mother; | |
| getSire = rabbitTmp.sire; | |
| getBirthbool = rabbitTmp.birthbool; | |
| getBirthCount = rabbitTmp.birthCount; | |
| getBirthLastTime = rabbitTmp.birthLastTime; | |
| getBirthCooldown = rabbitTmp.birthCooldown; | |
| } | |
| function getRabbitToOwner(uint32 _rabbitID) public onlyContract view returns(address owner) { | |
| owner = rabbitToOwner[_rabbitID]; | |
| return owner; | |
| } | |
| function getOwnerRabbitCount(address owner) public onlyContract view returns(uint count) { | |
| count = ownerRabbitCount[owner]; | |
| return count; | |
| } | |
| function getRabbitDescription(uint32 _rabbitID) public onlyContract view returns(string description) { | |
| description = rabbitDescription[_rabbitID]; | |
| return description; | |
| } | |
| function getRabbitName(uint32 rabbitID) public onlyContract view returns(string name) { | |
| name = rabbitName[rabbitID]; | |
| return name; | |
| } | |
| function getOwnershipTokenCount(address _addressOwner) public onlyContract view returns(uint256 count) { | |
| count = ownershipTokenCount[_addressOwner]; | |
| return count; | |
| } | |
| /** MARKET */ | |
| function getSellerOfRabbit(uint32 rabbitid) | |
| public onlyContract view returns(uint moneyReturn, uint timeStartReturn, uint timeFinishReturn) | |
| { | |
| moneyReturn = sellerOfRabbit[rabbitid].money; | |
| timeStartReturn = sellerOfRabbit[rabbitid].timeStart; | |
| timeFinishReturn = sellerOfRabbit[rabbitid].timeFinish; | |
| } | |
| function getbidClosedArray(uint256 index) | |
| public onlyContract view returns(uint moneyReturn, uint timeStartReturn, uint timeFinishReturn) | |
| { | |
| moneyReturn = bidClosedArray[index].money; | |
| timeStartReturn = bidClosedArray[index].timeStart; | |
| timeFinishReturn = bidClosedArray[index].timeFinish; | |
| } | |
| /** | |
| * get all money contract | |
| */ | |
| function getMoneyContract(uint value) public onlyContract { | |
| ownerCEO.transfer(value); | |
| } | |
| } | |
| contract ControllerRabbit is GetRabbit { | |
| // https://ethereum.stackexchange.com/questions/1527/how-to-delete-an-element-at-a-certain-index-in-an-array | |
| function getBids(uint page) public onlyContract view returns(uint32[16] rabbitID, address[16]rabbitSeller, uint[16]startMoney, uint[16]finishMoney ) { | |
| uint pagecount = 16; | |
| uint pageend = 0; | |
| uint start = 0; | |
| if (page < 1) { | |
| page = 1; | |
| } | |
| pageend = page * pagecount; | |
| if (pageend > bidsArray.length) { | |
| pageend = bidsArray.length; | |
| } | |
| uint startArray = (page-1)*pagecount; | |
| for (uint i = startArray; i < pageend; i++) { | |
| start++; | |
| rabbitID[start] = uint32(bidsArray[i].rabbitID); | |
| rabbitSeller[start] = address(bidsArray[i].rabbitSeller); | |
| startMoney[start] = uint(bidsArray[i].startMoney); | |
| finishMoney[start] = uint(bidsArray[i].finishMoney); | |
| } | |
| } | |
| // https://ethereum.stackexchange.com/questions/1527/how-to-delete-an-element-at-a-certain-index-in-an-array | |
| function removeBids(uint32 _rabbitID) public onlyContract returns(bool) { | |
| for (uint i = 0; i < bidsArray.length; i++) { | |
| if (bidsArray[i].rabbitID == _rabbitID) { | |
| delete bidsArray[i]; | |
| bidsArray[i] = bidsArray[bidsArray.length-1]; | |
| bidsArray.length--; | |
| bidsCount--; | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| /** | |
| * Google map | |
| * dolgota i shirota goog | |
| * longitude and latitude goog | |
| * http://www.m-globe.ru/images2/pim3.jpg | |
| * LatLng: (-85, -177.64999999999998) | |
| * https://jsfiddle.net/yxm233jx/4/ | |
| * http://www.m-globe.ru/koordinaty.html | |
| */ | |
| function getGoogleMap(int64 latitude, int64 _long, int64 _latRange, int64 _longRange) public onlyContract view returns(uint32[256] rabbitsArray) { | |
| uint indexCount = 0; | |
| // bool left = false; | |
| bool right = false; | |
| bool top = false; | |
| uint iteration = 0; | |
| // int64 bigFloat = 10**14; | |
| int64 long1 = _long + _longRange; | |
| int64 long2 = _long - _longRange; | |
| int64 lat1 = latitude - _latRange; | |
| int64 lat2 = latitude + _latRange; | |
| if (lat2 > (180 * 10**14)) { | |
| lat2 = lat2 - (180 * 10**14) + (-180 * 10**14); | |
| right = true; // отрицательная широта до -180 | |
| } | |
| if (lat1 < (-180 * 10**14)) { | |
| lat1 = (180 * 10**14) - lat1 + (180 * 10**14); | |
| // left = true; // положительная широта до 180 | |
| } | |
| if (long1 > (90 * 10**14)) { | |
| long1 = long1 - (90 * 10**14) + (-90 * 10**14); | |
| top = true; // отрицательная долгота до -90 | |
| } | |
| // each array | |
| for (uint i = 0; i < googleMaps.length; i++) { | |
| iteration++; | |
| if (iteration < 256) { | |
| GoogleMap memory maps = googleMaps[i]; | |
| /* | |
| * ____lat1__________-180_|_+180__________lat2___ | |
| */ | |
| if (right && lat2 >= maps.lat && maps.lat >= (-180 * 10**14) || | |
| lat2 <= maps.lat && maps.lat <= (180 * 10**14)) { | |
| if (top && long1 >= maps.long && maps.long >= (-90 * 10**14) || | |
| long2 <= maps.long && maps.long <= (90 * 10**14)) { | |
| indexCount++; | |
| rabbitsArray[indexCount] = maps.rabbitID; | |
| } | |
| if (!top && long1 >= maps.long && maps.long >= long2) { | |
| indexCount++; | |
| rabbitsArray[indexCount] = maps.rabbitID; | |
| } | |
| } | |
| if (right == false && lat1 <= maps.lat && maps.lat <= lat2) { | |
| if (top && long1 >= maps.long && maps.long >= (-90 * 10**14) || | |
| long2 <= maps.long && maps.long <= (90 * 10 ** 14)) { | |
| indexCount++; | |
| rabbitsArray[indexCount] = maps.rabbitID; | |
| } | |
| if (!top && long1 >= maps.long && maps.long >= long2) { | |
| indexCount++; | |
| rabbitsArray[indexCount] = maps.rabbitID; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| function getGoogleMapIndex(uint _index) public onlyContract view | |
| returns(uint32 _rabbitID, int64 _lat, int64 _long) | |
| { | |
| GoogleMap memory maps = googleMaps[_index]; | |
| _rabbitID = maps.rabbitID; | |
| _lat = maps.lat; | |
| _long = maps.long; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment