-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlastwillandtestament.se
38 lines (37 loc) · 1.93 KB
/
lastwillandtestament.se
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Last Will & Testament using a "dead-man's-switch"
# If the contract isn't touched by the creator at least once per month, he's dead
# Therefore, split all funds among the heirs
init:
# On contract creation, record the creator
contract.storage["CREATOR"] = tx.origin
code:
# A future transaction received from the creator does three things:
# 1) It's proves he's alive and supresses distribution for another 30 days
# 2) It naturally increases the contract's balance by the amount of the transaction value
# 3) It optionally supplies a new list of heirs
if tx.origin == contract.storage["CREATOR"]:
# Here we record the time of this touch by the creator. He's still alive.
contract.storage["LAST_TOUCH"] = block.timestamp
if msg.datasize > 0:
# The creator defines heirs by supplying their payment addresses as (padded 32-byte) inputs to the contract
# He can change these by supplying a new set of addresses which replaces all of the old set
while i <= msg.datasize:
# each heir will be recorded for future reference in the storage range 1000+
i = (i + 1)
contract.storage[(1000 + i)] = msg.data[i-1]
while i <= contract.storage["HEIR_COUNT"]:
# any extra former heirs are removed
i = (i + 1)
contract.storage[(1000 + i)] = 0
# remember how many heirs we have for later
contract.storage["HEIR_COUNT"] = msg.datasize
else:
# A transaction received by anyone else triggers distribution to heirs if we haven't heard from the creator
# (there are 2,592,000 seconds in a month)
if block.timestamp > (contract.storage["LAST_TOUCH"] + 2592000):
# calculate the equal portion for each heir
PORTION = (contract.balance / contract.storage["HEIR_COUNT"])
# distribute the portions out to the heirs
while i < contract.storage["HEIR_COUNT"]:
send(contract.storage[(1000 + i)], PORTION, (tx.gas - 100))
i = (i + 1)