SimpleSavingsWallet.sol 1.2 KB

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