memoscan
← all memos

Memo 0x7752fb39…dfc8d9 on Ethereum

<p>uint[] clockwork;</p><p>uint hour;</p><p>&nbsp;</p><p>struct Reg{</p><p>bool rank;</p><p>uint id;</p><p>}</p><p>mapping(address=&gt; Reg) accountID;</p><p>&nbsp;</p><p>uint[][2] index;</p><p>uint[][2] courtUtility;</p><p>&nbsp;</p><p>function incrementCourtUtility() internal{</p><p>courtUtility[0].push(index[true].length/2 + index[false].length);</p><p>courtUtility[1].push(courtUtility[0].length);</p><p>}</p><p>&nbsp;</p><p>bool[3][][] pairData;</p><p>&nbsp;</p><p>function eventScheduler(){</p><p>if(clockwork.length==0) clockwork.length=24;</p><p>uint randomHour=getRandomNumber() % clockwork.length;</p><p>if(clockwork[randomHour]==0) hour=randomHour;</p><p>else hour=clockwork[randomHour];</p><p>if(clockwork[clockwork.length - 1]==0) clockwork[randomHour]=clockwork.length - 1;</p><p>else clockwork[randomHour]&nbsp;=clockwork[clockwork.length - 1];</p><p>clockwork.length--;</p><p>}</p><p>&nbsp;</p><p>function assignID(bool _rank) internal{</p><p>index[_rank].length++;</p><p>accountID[msg.sender].rank=_rank;</p><p>accountID[msg.sender].id=index[_rank].length;</p><p>}</p><p>function shuffle(bool _rank) internal returns (uint id){</p><p>if(index[_rank].length !=0) id=getRandomNumber() % index[_rank].length;</p><p>assignID(_rank);</p><p>index[_rank][index[_rank].length - 1]=index[_rank][id];</p><p>return id;</p><p>}</p><p>function register(){</p><p>index[true][shuffle(true)]=index[true].length;</p><p>if(index[true].length%2==0){</p><p>incrementCourtUtility();</p><p>pairData.length++;</p><p>pairData[pairData.length - 1].length=2;</p><p>}</p><p>}</p><p>function assignCourt(bool _reassign) internal{</p><p>uint height=index[true].length/2 - index[false].length % index[true].length/2;</p><p>uint id=getRandomNumber() % height;</p><p>if(_reassign==false){</p><p>index[false][shuffle(false)]=courtUtility[id];</p><p>}</p><p>else{</p><p>assignID(false);</p><p>index[false][index[false].length - 1]=courtUtility[id];</p><p>}</p><p>delete courtUtility[1][courtUtility[0][id]];</p><p>courtUtility[id]=courtUtility[height-1];</p><p>courtUtility[1][courtUtility[height-1]]=id;</p><p>courtUtility[height-1]=courtUtility[courtUtility.length - 1];</p><p>courtUtility[1][courtUtility[courtUtility.length - 1]]=height-1;</p><p>courtUtility.length--;</p><p>incrementCourtUtility();</p><p>}</p><p>function immigrate(){assignCourt(false);}</p><p>function reassign(){assignCourt(true);}</p><p>&nbsp;</p><p>&nbsp;</p><p>function getIndex(address _account) internal returns (uint){</p><p>return index[accountID[_account].rank][accountID[_account].id - 1];</p><p>}</p><p>function getPair(address _account) internal returns (uint){</p><p>if(accountID[_account].rank==true) return (1 + getIndex(_account))/2;</p><p>return getIndex(_account) % index[true].length/2;</p><p>}</p><p>&nbsp;</p><p>function sign(address _account, bytes _signature){</p><p>&nbsp;</p><p>uint pairID=getPair(_account);</p><p>require(pairData[pairID].length !=0);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; address signer;</p><p>&nbsp;</p><p>if(_signature !=0){</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytes32 sig1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytes32 sig2;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assembly{</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sig1 :=mload(add(_signature,0x20))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sig2 :=mload(add(_signature,0x40))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytes32 msgHash=keccak256(_account);</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; address v1=ecrecover(msgHash, 27, r, s);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(pairID==getPair(v1) &amp;&amp; accountID[v1].rank==true) signer=v1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; address v2=ecrecover(msgHash, 28, r, s);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(pairID==getPair(v2) &amp;&amp; accountID[v2]. rank==true) signer=v2;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</p><p>&nbsp; &nbsp; &nbsp; &nbsp;}</p><p>&nbsp; &nbsp; &nbsp; &nbsp; else if(pairID==getPair(msg.sender) &amp;&amp;&nbsp; accountID[msg.sender].rank==true) signer=msg.sender;</p><p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</p><p>uint signerID=(1+getIndex(signer))%2;</p><p>&nbsp;</p><p>uint id;</p><p>&nbsp;</p><p>if(accountID[_account].rank==true){</p><p>id=(1 + getIndex(_account))%2;</p><p>}</p><p>else{</p><p>id=2 + getIndex(_account) / pairData.length;</p><p>if(pairData[pairID].length &lt; id + 1) pairData[pairID].length=id;</p><p>}</p><p>pairData[pairID][id][signerID]=true;</p><p>}</p>