ligo/test/contracts/king_of_tez.tz

19 lines
745 B
Plaintext
Raw Normal View History

parameter key_hash;
storage (pair timestamp (pair tez key_hash));
return unit;
code { DUP; CDAR;
# If the time is more than 2 weeks, any amount makes you king
NOW; CMPGT;
# User becomes king of tez
IF { CAR; AMOUNT; PAIR; NOW; PUSH int 604800; ADD; PAIR }
# Check balance to see if user has paid enough to become the new king
{ DUP; CDDAR; AMOUNT; CMPLT;
IF { FAIL } # user has not paid out
{ CAR; DUP;
# New storage
DIP{ AMOUNT; PAIR; NOW; PUSH int 604800; ADD; PAIR };
# Pay funds to old king
DEFAULT_ACCOUNT; AMOUNT; UNIT; TRANSFER_TOKENS; DROP }};
# Cleanup
UNIT; PAIR };