Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (62 sloc) 2.26 KB
# Eddie Murphy - I want half
# https://www.youtube.com/watch?v=Q4YJHvzo2io
# by:
# - Yves Candel
# - Nick Savers
# - Joris Bontje
# Constract Storage indexes
I_STATE = 1000
I_PARTNER_1 = 1001
I_PARTNER_2 = 1002
I_WITHDRAW_TO = 1003
I_WITHDRAW_AMOUNT = 1004
I_WITHDRAW_CREATOR = 1005
I_DIVORCE_CREATOR = 1006
C_CANCEL_PERIOD = 1000
# Status enumeration
S_START = 0
S_PROPOSED = 1
S_MARRIED = 2
S_DIVORCED = 3
# Transaction triggers
TX_WITHDRAW = 1
TX_DIVORCE = 2
if tx.value < 100 * block.basefee:
stop
state = contract.storage[I_STATE]
if state == S_START:
contract.storage[I_PARTNER_1] = tx.sender
contract.storage[I_PARTNER_2] = tx.data[0]
contract.storage[I_STATE] = S_PROPOSED
stop
partner_1 = contract.storage[I_PARTNER_1]
partner_2 = contract.storage[I_PARTNER_2]
if state == S_PROPOSED:
if tx.sender == partner_2 and tx.data[0] == partner_1:
contract.storage[I_STATE] = S_MARRIED
else if tx.sender == partner_1 and tx.data[0] == partner_1:
if block.timestamp < C_CANCEL_PERIOD:
stop
contract.storage[I_STATE] = S_START
mktx(tx.sender, block.account_balance(contract.address), 0, 0)
else if state == S_MARRIED and tx.sender == partner_1 or tx.sender == partner_2:
if tx.data[0] == TX_WITHDRAW:
creator = contract.storage[I_WITHDRAW_CREATOR]
if creator != 0 and contract.storage[I_WITHDRAW_TO] == tx.data[1] and contract.storage[I_WITHDRAW_AMOUNT] == tx.data[2] and creator != tx.sender:
mktx(tx.data[1], tx.data[2], 0, 0)
contract.storage[I_WITHDRAW_TO] = 0
contract.storage[I_WITHDRAW_AMOUNT] = 0
contract.storage[I_WITHDRAW_CREATOR] = 0
else:
contract.storage[I_WITHDRAW_TO] = tx.data[1]
contract.storage[I_WITHDRAW_AMOUNT] = tx.data[2]
contract.storage[I_WITHDRAW_CREATOR] = tx.sender
else if tx.data[0] == TX_DIVORCE:
creator = contract.storage[I_DIVORCE_CREATOR]
if creator != 0 and creator != tx.sender:
balance = block.account_balance(contract.address)
mktx(partner_1, balance / 2, 0, 0)
mktx(partner_2, balance / 2, 0, 0)
contract.storage[I_STATE] = S_DIVORCED
else:
contract.storage[I_DIVORCE_CREATOR] = tx.sender