SimpleSavingsWallet.sol 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. pragma solidity ^0.4.21;
  2. import "../ownership/Heritable.sol";
  3. /**
  4. * @title SimpleSavingsWallet
  5. * @dev Simplest form of savings wallet whose ownership can be claimed by a heir
  6. * if owner dies.
  7. * In this example, we take a very simple savings wallet providing two operations
  8. * (to send and receive funds) and extend its capabilities by making it Heritable.
  9. * The account that creates the contract is set as owner, who has the authority to
  10. * choose an heir account. Heir account can reclaim the contract ownership in the
  11. * case that the owner dies.
  12. */
  13. contract SimpleSavingsWallet is Heritable {
  14. event Sent(address indexed payee, uint256 amount, uint256 balance);
  15. event Received(address indexed payer, uint256 amount, uint256 balance);
  16. function SimpleSavingsWallet(uint256 _heartbeatTimeout) Heritable(_heartbeatTimeout) public {}
  17. /**
  18. * @dev wallet can receive funds.
  19. */
  20. function () public payable {
  21. emit Received(msg.sender, msg.value, address(this).balance);
  22. }
  23. /**
  24. * @dev wallet can send funds
  25. */
  26. function sendTo(address payee, uint256 amount) public onlyOwner {
  27. require(payee != 0 && payee != address(this));
  28. require(amount > 0);
  29. payee.transfer(amount);
  30. emit Sent(payee, amount, address(this).balance);
  31. }
  32. }