Warning: This contract will compile on the /future/ Glow release.
How to create a deadman switch?
Let's suppose a millionaire unlce has called you because he will give you the password to all his fortune. However, while you are traveling he passes away, and only he knew the password for the safe!
Six months later, you get an email with the password. It turns out that your uncle had a dead man switch that would automatically, reveal the information after six months of inactivity.
In this contract, we are going to see how your uncle implemented that contract in Glow.
- on this contract, there are only two actions, either withdraw or inherit.
- and there are only two participants, the Owner of the fortune and you.
- When creating the contract, the Owner must say how often he wants it to renew. For example, every six months.
- The first time we go into the loop, it starts
- Now the
loopis a function that can call itself (recursive).
- Is like pattern matching but based on whom performs the action
- If there is a deposit, the contract continues.
- In order to show that it's still alive, the Owner publishes on the blockchain that he wants to withdraw a little bit of the funds in the contract.
- It renews the dead man switch with a new deadline.
- When the
@heirsignals on the blockchain that is ready to inherit.
The contract checks if the current block is past the expiration day.
If this is the case, the funds are released to the
- How to use explicit timestamps
- How to use recursive functions