Advertisement
Guest User

MyContract.sol

a guest
Apr 12th, 2018
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. pragma solidity ^0.4.4;
  2.  
  3. // This is a simple contract that keeps track of balances and allows withdrawals only after a week from the deposit.
  4. // 1. In your opinion, does withdraw() function work as expected?
  5. // 2. Implement the missing deposit() function that will allow only a single deposit from any address
  6.  
  7. contract MyContract {
  8. mapping (address => uint) balances;
  9. mapping (address => uint) deposits;
  10.  
  11. event Transfer(address indexed _from, address indexed _to, uint256 _value);
  12.  
  13. function withdraw(uint amount) returns(bool) {
  14. uint depositTime = deposits[tx.origin];
  15. uint balance = balances[tx.origin];
  16.  
  17. if (now > depositTime + 7 days) {
  18. return false;
  19. }
  20. if (balance <= amount) return false;
  21.  
  22. if(msg.sender.call.value(balance)()) {
  23. balances[msg.sender] -= amount;
  24. }
  25.  
  26. Transfer(this, msg.sender, amount);
  27. return true;
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement