Guest User

CryptoAlarm Smart Contract

a guest
Jul 1st, 2019
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.5.7;
  2.  
  3. contract AlarmClock {
  4.  
  5. mapping (address => uint) userComittedMoney;
  6. mapping (address => address) alarmAddress;
  7. /*
  8. Charity hard codded address
  9. */
  10. address payable charityAddress = HARD_CODDED_CHARITY_ADDRESS;
  11. /*
  12. Money locking function, user will lock money into this contract
  13. @param _alarmAddress user's alarm address
  14. */
  15. function lockMyMoney(address _alarmAddress) public payable{
  16. userComittedMoney[msg.sender] = msg.value;
  17. alarmAddress[msg.sender] = _alarmAddress;
  18. }
  19. /*
  20. Spending function, alarm will spend money from contract if
  21. user failed to wake up on time.
  22. @param _alarmAddress user's alarm address
  23. @param _amount amount to be charged from user
  24. */
  25. function spend(address _alarmAddress, uint _amount) public{
  26. require(userComittedMoney[msg.sender] >= _amount && alarmAddress[msg.sender]== _alarmAddress);
  27. charityAddress.transfer(_amount);
  28. userComittedMoney[msg.sender]-=_amount;
  29. }
  30. /*
  31. Withdraw money function, if user decided to stop trial, he/she will withdraw the rest
  32. of the money if exists.
  33. @param _alarmAddress user's alarm address
  34. */
  35. function withdrawMoney(address _alarmAddress) public {
  36. require(alarmAddress[msg.sender] == _alarmAddress && userComittedMoney[msg.sender]>0);
  37. msg.sender.transfer(userComittedMoney[msg.sender]);
  38. }
  39. }
RAW Paste Data