Created
August 16, 2018 04:11
-
-
Save ernestognw/991d299e8fe10b918cad93267e5018ca to your computer and use it in GitHub Desktop.
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
| // Aplicacion de citas descentralizadas | |
| // 1. Puedes comprar "liken" | |
| // 2. Le asignas "liken" a las cuentas que te gustan | |
| // 3. Determinar un tiempo | |
| // 4. funcion que le pasas la direccion y te dice quien le dio mas likes | |
| // 5. Obtener info solo si hay match | |
| //block.number | |
| //now | |
| pragma solidity ^0.4.24; | |
| contract Ethinder { | |
| // Variables | |
| uint price = 1 ether; | |
| uint timeToElapse; | |
| uint availableLikens; | |
| uint initialMoment; | |
| mapping (address => currentWinner) public winnersBalance; | |
| mapping (address => uint) public likenBalance; | |
| mapping (address => string) public messages; | |
| struct currentWinner { | |
| address winner; | |
| uint likensGiven; | |
| } | |
| constructor(uint _timeToElapse, uint _availableLikens){ | |
| timeToElapse = _timeToElapse; | |
| availableLikens = _availableLikens; | |
| initialMoment = now; | |
| } | |
| // Modificadores | |
| modifier onlyOnTime(){ | |
| // if(now - initialMoment > timeToElapse) | |
| // revert(); | |
| _; | |
| } | |
| modifier onlyOutOfTime(){ | |
| // if(now - initialMoment < timeToElapse) | |
| // revert(); | |
| _; | |
| } | |
| // Funciones | |
| // buyLiken | |
| function buyLiken(uint _likensToBuy) payable onlyOnTime(){ | |
| uint amount = _likensToBuy * price; | |
| if (_likensToBuy > availableLikens){ | |
| revert(); | |
| } | |
| if (msg.value < amount){ | |
| revert(); | |
| } | |
| if (msg.value > amount){ | |
| msg.sender.transfer(msg.value - amount); | |
| } | |
| availableLikens -= _likensToBuy; | |
| likenBalance[msg.sender] += _likensToBuy; | |
| } | |
| // giveLiken | |
| function giveLiken(address _handsomeOne, uint _likensToGive) onlyOnTime(){ | |
| if (likenBalance[msg.sender] < _likensToGive){ | |
| revert(); | |
| } | |
| if (winnersBalance[_handsomeOne].likensGiven > _likensToGive){ | |
| revert(); | |
| } | |
| winnersBalance[_handsomeOne].likensGiven = _likensToGive; | |
| winnersBalance[_handsomeOne].winner = msg.sender; | |
| likenBalance[_handsomeOne] += _likensToGive; | |
| likenBalance[msg.sender] -= _likensToGive; | |
| } | |
| // checkUserLinken | |
| function checkUserLinken(address _userToCheck) public view returns(uint) { | |
| return (likenBalance[_userToCheck]); | |
| } | |
| // checkHandsomeOnePrice | |
| function checkHandsomeOnePrice(address _handsomeOneToCheck) public view returns(uint){ | |
| return (winnersBalance[_handsomeOneToCheck].likensGiven); | |
| } | |
| // Regresa el tiempo trasncurrido | |
| function checkTimeElapsed() public view returns(uint){ | |
| return (now - initialMoment); | |
| } | |
| // sellLiken | |
| function sellLiken(uint _likensToSell) payable { | |
| if (likenBalance[msg.sender] < _likensToSell){ | |
| revert(); | |
| } | |
| availableLikens += _likensToSell; | |
| likenBalance[msg.sender] -= _likensToSell; | |
| msg.sender.transfer(_likensToSell * price); | |
| } | |
| // getMyWinner | |
| function getMyWinner() public view returns(address){ | |
| return (winnersBalance[msg.sender].winner); | |
| } | |
| // checkLikens | |
| function checkLikens() public view returns(uint){ | |
| return (availableLikens); | |
| } | |
| // sendMessage | |
| function sendMessage(address _userToSend, string _message) onlyOutOfTime() { | |
| if (winnersBalance[_userToSend].winner != msg.sender){ | |
| revert(); | |
| } | |
| messages[_userToSend] = _message; | |
| } | |
| // checkMyMessages | |
| function checkMyMessages() onlyOutOfTime() public view returns (string){ | |
| return (messages[msg.sender]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment