Commit bd2ff0a1 authored by J H's avatar J H

Add the fifth tutorial

parent 9b8e9d74
parameter int; # the participant's guess
storage (pair
int # the number of guesses made by participants
address # the address to send the winning pot to if the participants fail
);
code {
# (pair parameter storage) : []
# make sure that the participant has contributed at least 1 tez
PUSH mutez 1000000;
AMOUNT;
IFCMPGE {} { PUSH string "You did not provide enough tez."; FAILWITH; };
# check that the number of guesses has not been exceeded
UNPAIR; SWAP; # storage : parameter : []
DUP; # storage : storage : parameter : []
CAR; # int : storage : parameter : []
DIP { PUSH int 15; };
IFCMPLT { # check if guess is correct
SWAP; # parameter : storage : []
PUSH int 34;
IFCMPEQ { # the participant guessed correctly, give them the tokens.
SENDER;
CONTRACT unit;
IF_SOME {} { FAILWITH; };
BALANCE;
UNIT;
TRANSFER_TOKENS;
NIL operation; SWAP; CONS; PAIR;
}
{ # the participant guessed incorrectly, increment the number of guesses performed.
UNPAIR;
PUSH int 1;
ADD;
PAIR;
NIL operation; PAIR;
};
}
{ # attempts exceeded, give winnings to the specified address
DIP { DROP; }; # storage : []
DUP; CDR;
CONTRACT unit;
IF_SOME {} { FAILWITH; };
BALANCE;
UNIT;
TRANSFER_TOKENS;
NIL operation; SWAP; CONS; PAIR;
};
};
This diff is collapsed.
......@@ -7,3 +7,4 @@ An introduction to writing smart contracts on Tezos
- 02: [Hello Tezos](02)
- 03: [Contract Origination and Interaction](03)
- 04: [Michelson Data Structures](04)
- 05: [Tezos Tokens in Michelson](05)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment