Test: move test/proto_alpha_isolate into proto_alpha/lib_protocol/test

This commit is contained in:
Grégoire Henry 2018-02-02 17:00:33 +01:00
parent 14d902a3fc
commit 868514af2b
161 changed files with 1043 additions and 13 deletions

View File

@ -0,0 +1,42 @@
# This is a very simple accounts system.
# (Left key) initializes or deposits into an account
# (Right key (pair tez (signed tez))) withdraws tez amount to a
# DEFAULT_ACCOUNT created from the key if the balance is available
# and the key is correctly signed
parameter (or key_hash (pair key (pair tez signature)));
# Maps the key to the balance they have stored
storage (map key_hash tez);
return unit;
code { DUP; CAR;
# Deposit into account
IF_LEFT { DUP; DIIP{ CDR; DUP };
DIP{ SWAP }; GET;
# Create the account
IF_NONE { DIP{ AMOUNT; SOME }; UPDATE; UNIT; PAIR }
# Add to an existing account
{ AMOUNT; ADD; SOME; SWAP; UPDATE; UNIT; PAIR }}
# Withdrawl
{ DUP; DUP; DUP; DUP;
# Check signature on data
CAR; DIIP{ CDAR; H }; DIP{ CDDR; PAIR }; CHECK_SIGNATURE;
IF {} { FAIL };
# Get user account information
DIIP{ CDR; DUP }; CAR; HASH_KEY; DIP{ SWAP }; GET;
# Account does not exist
IF_NONE { FAIL }
# Account exists
{ DUP; DIIP{ DUP; CDAR; DUP };
# Ensure funds are available
DIP{ CMPLT }; SWAP;
IF { FAIL }
{ SUB; DIP{ DUP; DIP{ SWAP }}; DUP;
# Delete account if balance is 0
PUSH tez "0.00"; CMPEQ;
IF { DROP; NONE tez }
# Otherwise update storage with new balance
{ SOME };
SWAP; CAR; HASH_KEY; UPDATE;
SWAP; DUP; CDAR;
# Execute the transfer
DIP{ CAR; HASH_KEY; DEFAULT_ACCOUNT }; UNIT; TRANSFER_TOKENS;
PAIR }}}}

View File

@ -0,0 +1,10 @@
parameter int;
storage unit;
return int;
code {CAR; # Get the parameter
PUSH int 1; # We're adding 1, so we need to put 1 on the stack
ADD; # Add the two numbers
UNIT; # We need to put the storage value on the stack
SWAP; # The values must be rearranged to match the return calling convention
PAIR} # Create the end value

View File

@ -0,0 +1,9 @@
parameter (list int);
storage unit;
return (list int);
code { CAR; # Get the parameter
LAMBDA int int { PUSH int 1; ADD }; # Create a lambda that adds 1
MAP; # Map over the list
UNIT; # Push Unit
SWAP; # Reorder the stack for the PAIR
PAIR } # Match the calling convetion

View File

@ -0,0 +1,4 @@
parameter (pair int timestamp);
storage unit;
return timestamp;
code { CAR; DUP; CAR; DIP{CDR}; ADD; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair timestamp int);
storage unit;
return timestamp;
code { CAR; DUP; CAR; DIP{CDR}; ADD; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,4 @@
parameter nat;
storage timestamp;
return (pair nat bool);
code {DUP; CAR; DIP{CDR; DUP; NOW; CMPGT}; PAIR; PAIR};

View File

@ -0,0 +1,6 @@
parameter nat;
return (pair nat bool);
storage unit;
code { CAR; PUSH bool True; SWAP;
PAIR; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair (bool @first) (bool @second));
return bool;
storage unit;
code { CAR @param; DUP; CAR @first; DIP{CDR @second}; AND; UNIT; SWAP; PAIR };

View File

@ -0,0 +1,15 @@
parameter (pair (list int) (list int));
return (list int);
storage unit;
code { CAR; DUP; DIP{CDR}; CAR; # Unpack lists
NIL int; SWAP; # Setup reverse accumulator
LAMBDA (pair int (list int))
(list int)
{DUP; CAR; DIP{CDR}; CONS};
REDUCE; # Reverse list
LAMBDA (pair int (list int))
(list int)
{DUP; CAR; DIP{CDR}; CONS};
REDUCE; # Append reversed list
UNIT; SWAP; PAIR} # Calling convention

View File

@ -0,0 +1,4 @@
parameter bool;
storage unit;
return unit;
code {CAR; ASSERT; UNIT; UNIT; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; ASSERT_CMPEQ; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; ASSERT_CMPGE; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; ASSERT_CMPGT; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; ASSERT_CMPLE; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; ASSERT_CMPLT; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; ASSERT_CMPNEQ; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; COMPARE; ASSERT_EQ; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; COMPARE; ASSERT_GE; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; COMPARE; ASSERT_GT; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; COMPARE; ASSERT_LE; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; COMPARE; ASSERT_LT; UNIT; DUP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair int int);
storage unit;
return unit;
code {CAR; DUP; CAR; DIP{CDR}; COMPARE; ASSERT_NEQ; UNIT; DUP; PAIR}

View File

@ -0,0 +1,7 @@
parameter unit;
return unit;
storage tez; # How much you have to send me
code {CDR; DUP; # Get the amount required (once for comparison, once to save back in storage)
AMOUNT; CMPLT; # Check to make sure no one is wasting my time
IF {FAIL} {UNIT; PAIR}} # Finish the transaction or reject the person

View File

@ -0,0 +1,9 @@
parameter key_hash;
storage (pair timestamp (pair tez key_hash));
return unit;
code { DUP; CDAR; DUP; NOW; CMPGT; IF {FAIL} {}; SWAP; # Check if auction has ended
DUP; CAR; DIP{CDDR}; AMOUNT; PAIR; SWAP; DIP{SWAP; PAIR}; # Setup replacement storage
DUP; CAR; AMOUNT; CMPLE; IF {FAIL} {}; # Check to make sure that the new amount is greater
DUP; CAR; # Get amount of refund
DIP{CDR; DEFAULT_ACCOUNT}; UNIT; TRANSFER_TOKENS; # Make refund
PAIR} # Calling convention

View File

@ -0,0 +1,6 @@
parameter unit;
storage (pair timestamp (pair (contract unit unit) (contract unit unit)));
return unit;
code { CDR; DUP; CAR; NOW; CMPLT; IF {FAIL} {};
DUP; CDAR; PUSH tez "100"; UNIT; TRANSFER_TOKENS; DROP;
DUP; CDDR; PUSH tez "100"; UNIT; TRANSFER_TOKENS; PAIR }

View File

@ -0,0 +1,4 @@
parameter unit;
storage unit;
return tez;
code {DROP; UNIT; BALANCE; PAIR};

View File

@ -0,0 +1,7 @@
parameter nat;
return (list nat);
storage unit;
code { CAR @counter; NIL @acc nat; SWAP; DUP @cmp_num; PUSH nat 0; CMPNEQ;
LOOP { DUP; DIP {SWAP}; CONS @acc; SWAP; PUSH nat 1; SWAP; SUB @counter;
DUP; DIP{ABS}; PUSH int 0; CMPNEQ};
CONS; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,4 @@
parameter (pair (pair unit (string @no_name)) bool);
storage unit;
return unit;
code { CAR @name; CADR @second_name; DROP; UNIT; UNIT; PAIR }

View File

@ -0,0 +1,7 @@
parameter key;
storage (pair signature string);
return bool;
code { DUP; DUP;
DIP{ CDR; DUP; CAR;
DIP{CDR; H}; PAIR};
CAR; CHECK_SIGNATURE; DIP{CDR}; PAIR};

View File

@ -0,0 +1,10 @@
parameter (pair tez tez);
return (list bool);
storage unit;
code {CAR; DUP; DUP; DUP; DUP; DIIIIIP {NIL bool};
DIIIIP {DUP; CAR; DIP {CDR}; COMPARE; LE; CONS};
DIIIP {DUP; CAR; DIP {CDR}; COMPARE; GE; CONS};
DIIP{DUP; CAR; DIP {CDR}; COMPARE; LT; CONS};
DIP {DUP; CAR; DIP {CDR}; COMPARE; GT; CONS};
DUP; CAR; DIP {CDR}; COMPARE; EQ; CONS;
UNIT; SWAP; PAIR};

View File

@ -0,0 +1,11 @@
parameter string;
storage string;
return string;
code {DUP; # We're going to need both the storage and parameter
CAR; # Get the parameter
DIP{CDR; # Get the storage value
DUP}; # We need to replace it in the storage, so we dup it
SWAP; # Get the order we want (this is optional)
CONCAT; # Concatenate the strings
PAIR} # Pair them up, matching the calling convention

View File

@ -0,0 +1,5 @@
parameter (list string);
return (list string);
storage unit;
code{ CAR; LAMBDA string string { PUSH @hello string "Hello "; CONCAT };
MAP; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,6 @@
parameter (list string);
return string;
storage unit;
code {CAR; PUSH string ""; SWAP;
LAMBDA (pair string string) string {DUP; CDR; DIP{CAR}; CONCAT};
REDUCE; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,11 @@
parameter (or string (option int));
storage unit;
return string;
code { CAR; # Access the storage
IF_LEFT {} # The string is on top of the stack, nothing to do
{ IF_NONE { FAIL} # Fail if None
{ PUSH int 0; CMPGT; # Check for negative number
IF {FAIL} # Fail if negative
{PUSH string ""}}}; # Push the empty string
UNIT; SWAP; PAIR} # Calling convention

View File

@ -0,0 +1,12 @@
parameter nat;
storage (list nat);
return unit;
code { DUP; # Duplicate the storage and parameter
CAR; # Extract the parameter
DIP{CDR}; # Extract the storage
DUP; # Duplicate the parameter
DIP{CONS}; # Add the first instance of the parameter to the list
CONS; # Add the second instance of the parameter to the list
PUSH unit Unit; # Put the value Unit on the stack (calling convention)
PAIR} # Finish the calling convention

View File

@ -0,0 +1,10 @@
parameter (pair (list string) (list string));
storage unit;
return bool;
code {CAR; DUP; CAR; DIP{CDR}; EMPTY_SET string; SWAP;
LAMBDA (pair string (set string)) (set string) {DUP; CAR; DIP{CDR}; PUSH bool True; SWAP; UPDATE};
REDUCE; PUSH bool True; SWAP; PAIR; SWAP;
LAMBDA (pair string (pair (set string) bool))
(pair (set string) bool)
{DUP; DUP; CAR; DIP{CDAR; DIP{CDDR}; DUP}; MEM; DIP{SWAP}; AND; SWAP; PAIR};
REDUCE; CDR; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,5 @@
parameter key_hash;
return unit;
storage (contract unit unit);
code {CAR; DIP{PUSH tez "100.00"; PUSH bool False; NONE key_hash};
CREATE_ACCOUNT; UNIT; PAIR};

View File

@ -0,0 +1,22 @@
parameter unit;
return (contract (list int) (list int));
storage unit;
code { CAR; # Get the UNIT value (starting storage for contract)
LAMBDA (pair (list int) unit) # Start of stack for contract (see above)
(pair (list int) unit) # End of stack for contract (see above)
# See the contract above. I copied and pasted
{ CAR;
LAMBDA int int {PUSH int 1; ADD};
MAP;
UNIT;
SWAP;
PAIR };
AMOUNT; # Push the starting balance
PUSH bool False; # Not spendable
DUP; # Or delegatable
NONE key_hash; # No delegate
PUSH key_hash "tz1cxcwwnzENRdhe2Kb8ZdTrdNy4bFNyScx5";
CREATE_CONTRACT; # Create the contract
UNIT; # Ending calling convention stuff
SWAP;
PAIR}

View File

@ -0,0 +1,13 @@
parameter key_hash;
storage string;
return unit;
code {CAR;
DIP{UNIT;
LAMBDA (pair string unit)
(pair string unit)
{CAR; UNIT; SWAP; PAIR};
PUSH tez "100.00"; PUSH bool False;
PUSH bool False; NONE key_hash};
CREATE_CONTRACT; DIP{PUSH string ""}; PUSH tez "0.00";
PUSH string "abcdefg"; TRANSFER_TOKENS;
DIP{DROP}; UNIT; PAIR};

View File

@ -0,0 +1,14 @@
parameter key_hash;
storage string;
return unit;
code { CAR;
DIP { UNIT;
PUSH tez "100.00"; PUSH bool False;
PUSH bool False; NONE key_hash };
CREATE_CONTRACT { parameter string ;
storage unit ;
return string ;
code {CAR; UNIT; SWAP; PAIR } } ;
DIP{PUSH string ""}; PUSH tez "0.00";
PUSH string "abcdefg"; TRANSFER_TOKENS;
DIP{DROP}; UNIT; PAIR};

View File

@ -0,0 +1,15 @@
# NONE if user wants to get the value
# SOME (signed hash of the string, string)
parameter (option (pair signature (pair string nat)));
return string;
storage (pair (pair key nat) string);
code { DUP; CAR; DIP{CDR; DUP};
IF_NONE { AMOUNT; PUSH tez "1.00"; # The fee I'm charging for queries
CMPLE; IF {} {FAIL};
CDR; PAIR}
{ SWAP; DIP{DUP}; CAAR; DIP{DUP; CAR; DIP{CDR; H}; PAIR};
CHECK_SIGNATURE;
IF { CDR; DUP; DIP{CAR; DIP{CAAR}}; CDR; PUSH nat 1; ADD;
DIP{SWAP}; SWAP; PAIR; PAIR; PUSH string ""; PAIR}
{FAIL}}}

View File

@ -0,0 +1,5 @@
parameter key_hash;
return unit;
storage unit;
code {DIP{UNIT}; CAR; DEFAULT_ACCOUNT;
PUSH tez "100.00"; UNIT; TRANSFER_TOKENS; PAIR}

View File

@ -0,0 +1,4 @@
parameter (pair timestamp timestamp);
return int;
storage unit;
code { CAR; DUP; CAR; DIP{CDR}; SUB; UNIT; SWAP; PAIR }

View File

@ -0,0 +1,9 @@
parameter (or string (pair string (lambda unit string)));
return string;
storage (map string (lambda unit string));
code { DUP; DIP{CDR}; CAR; # Unpack stack
IF_LEFT { DIP{DUP}; GET; # Get lambda if it exists
IF_NONE {FAIL} {}; # Fail if it doesn't
UNIT; EXEC } # Execute the lambda
{ DUP; CAR; DIP {CDR; SOME}; UPDATE; PUSH string ""}; # Update the storage
PAIR} # Calling convention

View File

@ -0,0 +1,5 @@
parameter unit;
storage unit;
return unit;
code {}

View File

@ -0,0 +1,7 @@
storage unit;
return (map string string);
parameter unit;
code {DROP;
EMPTY_MAP string string;
PUSH string "world"; SOME; PUSH string "hello"; UPDATE;
UNIT; SWAP; PAIR};

View File

@ -0,0 +1,6 @@
parameter string;
return string;
storage unit;
code {CAR;
LAMBDA string string {PUSH string "_abc"; SWAP; CONCAT};
SWAP; EXEC; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,6 @@
parameter unit;
code
{ # This contract will never accept a incoming transaction
FAIL};
return unit;
storage unit;

View File

@ -0,0 +1,5 @@
# Fail if the amount transferred is less than 10
parameter unit;
storage unit;
return unit;
code {AMOUNT; PUSH tez "10"; CMPGT; IF {FAIL} {}}

View File

@ -0,0 +1,4 @@
parameter (list nat);
return nat;
storage unit;
code{CAR; IF_CONS {DIP{DROP}} {FAIL}; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,4 @@
parameter string;
storage (map string string);
return (option string);
code {DUP; CAR; DIP{CDR; DUP}; GET; PAIR};

View File

@ -0,0 +1,7 @@
parameter unit ;
code
{ # This contract stops accepting transactions after N incoming transactions
CDR ; DUP ; PUSH int 0 ; CMPLT; IF {PUSH int -1 ; ADD} {FAIL};
UNIT; PAIR} ;
return unit ;
storage int

View File

@ -0,0 +1,4 @@
parameter (pair tez (pair timestamp int)) ;
return string ;
storage unit ;
code { CAR ; H ; UNIT ; SWAP ; PAIR }

View File

@ -0,0 +1,4 @@
parameter key;
return key_hash;
storage unit;
code {CAR; HASH_KEY; DIP{UNIT}; PAIR}

View File

@ -0,0 +1,4 @@
parameter string;
return string;
storage unit;
code {CAR; H; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,5 @@
parameter string;
return string;
storage unit;
code {};

View File

@ -0,0 +1,4 @@
parameter bool;
storage unit;
return bool;
code {CAR; IF {PUSH bool True} {PUSH bool False}; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,4 @@
parameter (option string);
return string;
storage unit;
code { CAR; IF_SOME {} {PUSH string ""}; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,4 @@
parameter unit;
storage unit;
return unit;
code { DROP; PUSH bool True; LOOP {PUSH bool True}; UNIT; UNIT; PAIR }

View File

@ -0,0 +1,27 @@
parameter (list int);
return (list int);
storage unit;
code { CAR; # Access list
# Insert procedure
LAMBDA (pair int (list int))
(list int)
{ DUP; CDR; DIP{CAR}; # Unpack accumulator and existing list
DIIP{NIL int}; PUSH bool True; # Setup loop
LOOP { IF_CONS { SWAP;
DIP{DUP; DIIP{DUP}; DIP{CMPLT}; SWAP}; # Duplicate numbers
SWAP;
# If less than
IF { DIP{SWAP; DIP{CONS}}; PUSH bool True}
# Otherwise
{ SWAP; CONS; PUSH bool False}}
# Ending case
{ NIL int; PUSH bool False}};
SWAP; CONS; SWAP; # Finish lists
LAMBDA (pair int (list int))
(list int)
{DUP; CAR; DIP{CDR}; CONS};
REDUCE};
NIL int; SWAP; DIP{SWAP}; # Accumulator for reverse onto
REDUCE; # Execute reverse onto
UNIT; SWAP; PAIR} # Calling convention

View File

@ -0,0 +1,21 @@
# NONE if user wants to get the value
# SOME (signed hash of the string, string)
parameter (option (pair signature int));
return int;
# The key used to update the contract
# The data
storage (pair key int);
code {DUP; DUP; CAR;
IF_NONE {PUSH tez "1.00"; # Fee pattern from July 26
AMOUNT; CMPLE; IF {FAIL} {};
# Provide the data
CDR; DIP {CDDR}}
{DUP; DIP{SWAP}; SWAP; CDAR; # Move key to the top
DIP {DUP; CAR; DIP {CDR; H}; PAIR}; # Arrange the new piece of data
CHECK_SIGNATURE; # Check to ensure the data is authentic
# Update data
IF {CDR; SWAP; DIP{DUP}; CDAR; PAIR}
# Revert the update. This could be replaced with FAIL
{DROP; DUP; CDR; DIP{CDDR}}};
# Cleanup
SWAP; PAIR}

View File

@ -0,0 +1,18 @@
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 };

View File

@ -0,0 +1,4 @@
parameter (list string);
return (list string);
storage unit;
code {}

View File

@ -0,0 +1,4 @@
parameter (list string);
return (list string);
storage unit;
code {CAR; LAMBDA string string {}; MAP; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,6 @@
parameter (list int);
storage unit;
return int;
code { CAR; PUSH int 1; SWAP;
ITER { MUL };
UNIT; SWAP; PAIR}

View File

@ -0,0 +1,6 @@
parameter (list string);
return string;
storage unit;
code { CAR; PUSH string ""; SWAP;
ITER { CONCAT };
UNIT; SWAP; PAIR}

View File

@ -0,0 +1,6 @@
parameter (list int);
return (list int);
storage unit;
code { CAR; PUSH int 0; SWAP;
MAP { DIP{DUP}; ADD; DIP{PUSH int 1; ADD}};
UNIT; SWAP; PAIR; DIP{DROP}}

View File

@ -0,0 +1,9 @@
parameter unit;
storage (list (contract unit unit));
return unit;
code { CDR; PUSH bool True; # Setup loop
LOOP {IF_CONS { PUSH tez "1.00"; UNIT; TRANSFER_TOKENS; # Make transfer
DROP; PUSH bool True} # Setup for next round of loop
{ NIL (contract unit unit); PUSH bool False}}; # Data to satisfy types and end loop
UNIT; PAIR}; # Calling convention

View File

@ -0,0 +1,18 @@
parameter unit;
storage (pair timestamp (pair tez (contract unit unit)));
return unit;
code { CDR; # Ignore the parameter
DUP; # Duplicate the storage
CAR; # Get the timestamp
NOW; # Push the current timestamp
CMPLT; # Compare to the current time
IF {FAIL} {}; # Fail if it is too soon
DUP; # Duplicate the storage value
# this must be on the bottom of the stack for us to call transfer tokens
CDR; # Ignore the timestamp, focussing in on the tranfser data
DUP; # Duplicate the transfer information
CAR; # Get the amount of the transfer on top of the stack
DIP{CDR}; # Put the contract underneath it
UNIT; # Put the contract's argument type on top of the stack
TRANSFER_TOKENS; # Make the transfer
PAIR} # Pair up to meet the calling convention

View File

@ -0,0 +1,8 @@
parameter (list string);
return (list string);
storage unit;
code { CAR; NIL string; SWAP; PAIR; LEFT (list string);
LOOP_LEFT { DUP; CAR; DIP{CDR};
IF_CONS { SWAP; DIP{CONS}; PAIR; LEFT (list string) }
{ RIGHT (pair (list string) (list string)) }; };
UNIT; SWAP; PAIR }

View File

@ -0,0 +1,6 @@
return unit;
parameter unit;
storage unit;
code { PUSH unit Unit ;
DUUP @truc ;
DROP ; DROP }

View File

@ -0,0 +1,4 @@
parameter unit;
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
return unit;
code { MAP_CDADDAADR { PUSH tez "1.00" ; ADD } };

View File

@ -0,0 +1,4 @@
parameter bool;
storage (pair bool nat);
return unit;
code { DUP; CAR; DIP{CDR}; SWAP; MAP_CAR { AND } ; UNIT; PAIR };

View File

@ -0,0 +1,4 @@
parameter (map nat nat);
return (map nat nat);
storage unit;
code {}

View File

@ -0,0 +1,7 @@
parameter (map int int);
return (pair int int);
storage unit;
code { CAR; PUSH int 0; DUP; PAIR; SWAP;
ITER { DIP {DUP; CAR; DIP{CDR}}; DUP; # Last instr
DIP{CAR; ADD}; SWAP; DIP{CDR; ADD}; PAIR };
UNIT; SWAP; PAIR}

View File

@ -0,0 +1,4 @@
parameter (map string nat);
return nat;
storage unit;
code {CAR; SIZE; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,10 @@
parameter (list int);
storage unit;
return (option int);
code {CAR; DIP{NONE int};
LAMBDA
(pair int (option int))
(option int)
{DUP; DUP; CAR; SWAP; CDR;
IF_NONE {DIP{DROP}; SOME} {CMPGT; IF {CDR} {CAR; SOME}}};
REDUCE; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,13 @@
parameter (pair int int);
return int;
storage unit;
code { CAR; # Ignore the storage
DUP; # Duplicate so we can get both the numbers passed as parameters
DUP; # Second dup so we can access the lesser number
CAR; DIP{CDR}; # Unpack the numbers on top of the stack
CMPLT; # Compare the two numbers, placing a boolean on top of the stack
IF {CAR} {CDR}; # Access the first number if the boolean was true
UNIT; # Push storage value
SWAP; # Correct order for calling convention pair
PAIR} # Pair the numbers satisfying the calling convention

View File

@ -0,0 +1,4 @@
parameter unit;
code {};
return unit;
storage unit;

View File

@ -0,0 +1,4 @@
parameter bool;
return bool;
storage unit;
code {CAR; NOT; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,5 @@
parameter (pair bool bool);
return bool;
storage unit;
code {CAR; DUP; CAR; SWAP; CDR; OR;
UNIT; SWAP; PAIR};

View File

@ -0,0 +1,17 @@
storage unit ;
parameter nat ;
return (list (contract unit unit)) ;
code
{ CAR ; DUP ; PUSH nat 0 ; CMPNEQ ;
DIIP { NIL (contract unit unit) } ;
LOOP
{ PUSH tez "5.00" ;
PUSH bool True ; # delegatable
NONE key_hash ; # delegate
PUSH key_hash "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" ; # manager
CREATE_ACCOUNT ;
SWAP ; DIP { CONS } ;
PUSH nat 1 ; SWAP ; SUB ; ABS ;
DUP ; PUSH nat 0 ; CMPNEQ } ;
DROP ;
UNIT ; SWAP ; PAIR }

View File

@ -0,0 +1,4 @@
parameter (pair bool bool);
return (pair bool bool);
storage unit;
code {}

View File

@ -0,0 +1,4 @@
parameter unit;
return unit;
storage unit;
code { UNIT; UNIT; UNIT; UNIT; UNIT; PAIAAIAIAIR @name; DROP}

View File

@ -0,0 +1,26 @@
parameter (or (pair string (pair tez (contract unit unit))) nat);
return unit;
storage (pair (contract nat (pair nat bool)) (pair nat (map nat (pair string (pair tez (contract unit unit))))));
code { DUP; DIP{CDR}; CAR; # Get the input while preserving the output
IF_LEFT { DIP{ DUP; CAR; SWAP; CDR; DUP; CAR; DIP{CDR}};
SOME; SWAP; DUP; DIP{UPDATE}; # Add the element to the map
PUSH nat 1; ADD; PAIR; SWAP; # Add 1 to the index
PAIR; UNIT; PAIR} # Cleanup and finish
# Check our other contract to see if the transaction is allowed
{ DIP{DUP; CAR}; PUSH tez "0.00"; SWAP; TRANSFER_TOKENS;
# Arrange the stack
DUP; CDR;
IF { CAR; DUP; DIIP{DUP; CDDR; DUP};
DIP{ GET; # Get the value of the data
IF_NONE {FAIL} {}; # This should not happen
SWAP;
NONE (pair string (pair tez (contract unit unit)))};
UPDATE; # Delete the element
SWAP;
# More stack arranging
DIP{ SWAP; DUP; CAR; DIP{CDR}};
DIP{DIP{CAR; PAIR}; PAIR};
DUP; CDAR;
DIP{CDDR}; UNIT; TRANSFER_TOKENS; # Make the transfer
PAIR}
{ FAIL }}}

View File

@ -0,0 +1,24 @@
storage (pair (map nat (pair bool bool)) (pair key key));
return bool;
parameter (or nat (pair signature nat));
code { DUP; CAR; DIP{CDR}; # Stack rangling
IF_LEFT { DIP{DUP; CAR}; GET; # Get the value stored for that index
IF_NONE { PUSH bool False} # If not referenced, reject
{ DUP; CAR; DIP{CDR}; AND};
PAIR}
{ DUP; CAR; DIP{CDR; DUP; H}; PAIR; SWAP; # Create the signature pair
DIP{ DIP{DUP; CDR; DIP{CAR}; DUP};
SWAP; CAR; DIP{DUP}; CHECK_SIGNATURE }; # Check the first signature
SWAP;
# If the signature typechecked, get and update the first element of the pair
IF { DIP{DROP; SWAP; DUP}; DUP;
DIP{ GET; IF_NONE{PUSH (pair bool bool) (Pair False False)} {};
CDR; PUSH bool True; PAIR; SOME }}
# Check the second signature
{ DIP{DIP{DUP; CDR}; SWAP; CHECK_SIGNATURE}; SWAP;
IF { DUP; DIP{DIP{SWAP; DUP}; GET}; SWAP;
IF_NONE {PUSH (pair bool bool) (Pair False False)} {};
CAR; PUSH bool True; SWAP; PAIR; SOME; SWAP}
{FAIL}};
# Update the stored value and finish off
UPDATE; PAIR; PUSH bool False; PAIR}}

View File

@ -0,0 +1,17 @@
parameter unit;
storage (option
(pair (pair (contract unit unit) (contract unit unit))
(pair (pair timestamp (contract (option (pair signature int)) int))
(pair tez int))));
return unit;
code { CDR; IF_NONE {FAIL} {}; # Check if settlement has already ocurred
DUP; CDAAR; NOW; CMPLT; IF {FAIL} {}; # Check the timestamp
DUP; CDADR; DIP{SOME}; PUSH tez "1.01"; NONE (pair signature int);
TRANSFER_TOKENS; DIP{IF_NONE{FAIL} {}};
DIP{DUP; CDDR; DUP; CDR}; CMPGT;
SWAP;
DIP{ IF {CAAR} {CADR};
DIP{ NONE (pair (pair (contract unit unit) (contract unit unit))
(pair (pair timestamp (contract (option (pair signature int)) int))
(pair tez int)))}};
CAR; UNIT; TRANSFER_TOKENS; PAIR}

View File

@ -0,0 +1,24 @@
parameter (option string);
storage (pair (pair nat nat) (map nat string));
return (option string);
code { DUP; CAR;
# Retrieving an element
IF_NONE { CDR; DUP; CAR; DIP{CDR; DUP}; DUP;
CAR; SWAP; DIP{GET}; # Check if an element is available
SWAP;
# Put NONE on stack and finish
IF_NONE { NONE string; DIP{PAIR}; PAIR}
# Reoption the element and remove the entry from the map
{ SOME;
DIP{ DUP; DIP{ CAR; DIP{ NONE string }; UPDATE };
# Increment the counter and cleanup
DUP; CAR; PUSH nat 1; ADD; DIP{ CDR }; PAIR; PAIR};
PAIR }}
# Arrange the stack
{ DIP{DUP; CDAR; DIP{CDDR}; DUP}; SWAP; CAR;
# Add the element to the map
DIP{ SOME; SWAP; CDR; DUP; DIP{UPDATE};
# Increment the second number
PUSH nat 1; ADD};
# Cleanup and finish
PAIR; PAIR; NONE string; PAIR }}

View File

@ -0,0 +1,22 @@
parameter (pair (lambda int int) (list int));
return (list int);
storage unit;
code { DIP{NIL int};
CAR;
DUP;
DIP{CAR; PAIR}; # Unpack data and setup accumulator
CDR;
LAMBDA (pair int (pair (lambda int int) (list int)))
(pair (lambda int int) (list int))
# Apply the lambda and add the new element to the list
{ DUP; CDAR;
DIP{ DUP; DIP{CDAR}; DUP;
CAR; DIP{CDDR; SWAP}; EXEC; CONS};
PAIR};
REDUCE; CDR; DIP{NIL int}; # First reduce
LAMBDA (pair int (list int))
(list int)
{DUP; CAR; DIP{CDR}; CONS};
REDUCE; # Correct list order
UNIT; SWAP; PAIR} # Calling convention

View File

@ -0,0 +1,6 @@
parameter unit;
storage (pair (contract unit unit) (contract unit unit));
return unit;
code { CDR; DUP; CAR; PUSH tez "5.00"; UNIT;
TRANSFER_TOKENS; DROP; DUP; CDR;
PUSH tez "5.00"; UNIT; TRANSFER_TOKENS; PAIR };

View File

@ -0,0 +1,4 @@
parameter unit;
code {CAR; PUSH nat 300; PAIR};
return nat;
storage unit;

View File

@ -0,0 +1,8 @@
parameter (list string);
storage unit;
return (list string);
code { CAR; NIL string; SWAP;
LAMBDA (pair string (list string))
(list string)
{DUP; CAR; DIP{CDR}; CONS};
REDUCE; UNIT; SWAP; PAIR};

View File

@ -0,0 +1,6 @@
parameter (list string);
return (list string);
storage unit;
code { CAR; NIL string; SWAP; PUSH bool True;
LOOP { IF_CONS {SWAP; DIP{CONS}; PUSH bool True} {NIL string; PUSH bool False}};
DROP; UNIT; SWAP; PAIR}

View File

@ -0,0 +1,4 @@
parameter unit ;
storage (contract unit unit) ;
return unit ;
code { MAP_CDR { DROP ; SELF } }

View File

@ -0,0 +1,6 @@
parameter tez;
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
return unit;
code { DUP ; CAR ; SWAP ; CDR ;
SET_CADDAADR @annot ;
UNIT ; PAIR };

View File

@ -0,0 +1,4 @@
parameter string;
storage (pair string nat);
return (pair string nat);
code { DUP; CDR; DIP{CAR}; SET_CAR @hello; DUP; PAIR };

View File

@ -0,0 +1,4 @@
parameter nat;
storage (pair string nat);
return (pair string nat);
code { DUP; CDR; DIP{CAR}; SET_CDR @annot; DUP; PAIR };

View File

@ -0,0 +1,4 @@
parameter (set string);
return (set string);
storage unit;
code {}

View File

@ -0,0 +1,4 @@
parameter (set int);
return int;
storage unit;
code { CAR; PUSH int 0; SWAP; ITER { ADD }; UNIT; SWAP; PAIR }

View File

@ -0,0 +1,4 @@
parameter string;
storage (set string);
return bool;
code {DUP; CAR; DIP{CDR}; MEM; DIP{EMPTY_SET string}; PAIR};

Some files were not shown because too many files have changed in this diff Show More