Michelson: replace direct transfers with an internal operation queue

This commit is contained in:
Benjamin Canou 2018-04-05 17:17:27 +02:00 committed by Grégoire Henry
parent 59cccd53aa
commit 595685cf42
279 changed files with 1521 additions and 1827 deletions

View File

@ -6,15 +6,14 @@
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 }
IF_NONE { DIP{ AMOUNT; SOME }; UPDATE; NIL operation; PAIR }
# Add to an existing account
{ AMOUNT; ADD; SOME; SWAP; UPDATE; UNIT; PAIR }}
{ AMOUNT; ADD; SOME; SWAP; UPDATE; NIL operation; PAIR }}
# Withdrawl
{ DUP; DUP; DUP; DUP;
# Check signature on data
@ -38,5 +37,7 @@ code { DUP; CAR;
SWAP; CAR; HASH_KEY; UPDATE;
SWAP; DUP; CDAR;
# Execute the transfer
DIP{ CAR; HASH_KEY; IMPLICIT_ACCOUNT }; UNIT; TRANSFER_TOKENS;
DIP{ CAR; HASH_KEY; IMPLICIT_ACCOUNT }; UNIT;
TRANSFER_TOKENS;
NIL operation; SWAP; CONS;
PAIR }}}}

View File

@ -1,10 +1,7 @@
parameter int;
storage unit;
return int;
storage 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
NIL operation; # We put an empty list of operations on the stack
PAIR} # Create the end value

View File

@ -1,9 +1,7 @@
parameter (list int);
storage unit;
return (list int);
code { CAR; # Get the parameter
storage (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
MAP; # Map over the list
NIL operation; # No internal op
PAIR } # Match the calling convetion

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,6 @@
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
IF {FAIL} # Reject the person
{NIL operation;PAIR}} # Finish the transaction

View File

@ -1,9 +1,8 @@
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; IMPLICIT_ACCOUNT}; UNIT; TRANSFER_TOKENS; # Make refund
PAIR} # Calling convention
NIL operation; SWAP; CONS; PAIR} # Calling convention

View File

@ -1,6 +1,6 @@
parameter unit;
storage (pair timestamp (pair (contract unit unit) (contract unit unit)));
return unit;
storage (pair timestamp (pair (contract unit) (contract 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 }
DUP; CDAR; PUSH tez "100"; UNIT; TRANSFER_TOKENS; SWAP;
DUP; CDDR; PUSH tez "100"; UNIT; TRANSFER_TOKENS; DIP {SWAP} ;
NIL operation ; SWAP ; CONS ; SWAP ; CONS ; PAIR }

View File

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

View File

@ -1,8 +1,7 @@
parameter (pair (pair @set_pair int (option int)) (pair @check_pair int (option int))) ;
storage (pair (big_map int int) unit) ;
return unit ;
code { DUP ; DIP { CDAR } ;
DUP ; DIP { CADR; DUP ; CAR ; DIP { CDR } ; UPDATE ; DUP } ;
CADR ; DUP ; CDR ; DIP { CAR ; GET } ;
IF_SOME { SWAP ; IF_SOME { ASSERT_CMPEQ } {FAIL}} { ASSERT_NONE } ;
UNIT ; SWAP ; PAIR ; UNIT ; PAIR }
UNIT ; SWAP ; PAIR ; NIL operation ; PAIR }

View File

@ -1,6 +1,5 @@
# Fails if the boolean does not match the membership criteria
parameter (pair int bool) ;
storage (pair (big_map int unit) unit) ;
return unit ;
code { DUP ; DUP ; CADR ; DIP { CAAR ; DIP { CDAR ; DUP } ; MEM } ;
ASSERT_CMPEQ ; UNIT ; SWAP ; PAIR ; UNIT ; PAIR }
ASSERT_CMPEQ ; UNIT ; SWAP ; PAIR ; NIL operation ; PAIR }

View File

@ -1,9 +1,8 @@
parameter (list (pair string int)) ;
storage (pair (big_map string int) unit) ;
return unit ;
code { UNPAAIAIR ;
ITER { UNPAIR ; DUUUP ; DUUP; GET ;
IF_NONE { PUSH int 0 } {} ;
SWAP ; DIP { ADD ; SOME } ;
UPDATE } ;
PAIR ; UNIT ; PAIR }
PAIR ; NIL operation ; PAIR }

View File

@ -1,7 +1,6 @@
parameter nat;
return (list nat);
storage unit;
storage (list nat);
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};
CONS; NIL operation; PAIR};

View File

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

View File

@ -1,7 +1,8 @@
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};
CAR; CHECK_SIGNATURE;
IF {} {FAIL} ;
CDR; NIL operation ; PAIR};

View File

@ -1,10 +1,9 @@
parameter (pair tez tez);
return (list bool);
storage unit;
storage (list bool);
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};
NIL operation; PAIR};

View File

@ -1,11 +1,8 @@
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
DIP{CDR}; # Get the storage value
SWAP; # Get the order we want (this is optional)
CONCAT; # Concatenate the strings
PAIR} # Pair them up, matching the calling convention
NIL operation; PAIR} # Match the calling convention

View File

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

View File

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

View File

@ -1,11 +1,9 @@
parameter (or string (option int));
storage unit;
return string;
storage 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
NIL operation; PAIR} # Calling convention

View File

@ -1,12 +1,9 @@
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
NIL operation; PAIR} # Finish the calling convention

View File

@ -1,10 +1,9 @@
parameter (pair (list string) (list string));
storage unit;
return bool;
storage (option 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};
REDUCE; CDR; SOME; NIL operation; PAIR};

View File

@ -0,0 +1,16 @@
storage nat ;
parameter nat ;
code { UNPAIR ;
DIP { SELF ; ADDRESS ; SOURCE;
IFCMPEQ {} { DROP ; PUSH @storage nat 1 } };
DUP ;
PUSH nat 1 ;
IFCMPGE
{ DROP ; NIL operation ; PAIR }
{ PUSH nat 1 ; SWAP ; SUB @parameter ; ISNAT ;
IF_NONE
{ NIL operation ; PAIR }
{ DUP ; DIP { PUSH nat 1 ; ADD ; MUL @storage } ; SWAP;
DIP { DIP { PUSH nat 4000 ; SELF; PUSH tez "0" } ;
TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS } ;
SWAP ; PAIR } } }

View File

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

View File

@ -1,15 +1,13 @@
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)
storage (contract (list int));
code { DROP; NIL int; # starting storage for contract
LAMBDA (pair (list int) (list int)) # Start of stack for contract (see above)
(pair (list operation) (list int)) # 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;
NIL operation;
PAIR };
AMOUNT; # Push the starting balance
PUSH bool False; # Not spendable
@ -17,6 +15,4 @@ code { CAR; # Get the UNIT value (starting storage for cont
NONE key_hash; # No delegate
PUSH key_hash "tz1cxcwwnzENRdhe2Kb8ZdTrdNy4bFNyScx5";
CREATE_CONTRACT; # Create the contract
UNIT; # Ending calling convention stuff
SWAP;
PAIR}
NIL operation; PAIR} # Ending calling convention stuff

View File

@ -1,13 +1,12 @@
parameter key_hash;
storage string;
return unit;
code {CAR;
DIP{UNIT;
LAMBDA (pair string unit)
(pair string unit)
{CAR; UNIT; SWAP; PAIR};
DIP{PUSH string "dummy";
LAMBDA (pair string string)
(pair (list operation) string)
{CAR; NIL operation; 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};
NIL operation; SWAP; CONS; PAIR};

View File

@ -1,14 +1,12 @@
parameter key_hash;
storage string;
return unit;
storage unit;
code { CAR;
DIP { UNIT;
DIP { PUSH string "dummy";
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 } } ;
storage string ;
code {CAR; NIL operation; PAIR } } ;
DIP{PUSH string ""}; PUSH tez "0.00";
PUSH string "abcdefg"; TRANSFER_TOKENS;
DIP{DROP}; UNIT; PAIR};
DIP{DROP}; NIL operation; SWAP; CONS; UNIT; SWAP; PAIR};

View File

@ -1,15 +1,8 @@
# NONE if user wants to get the value
# SOME (signed hash of the string, string)
parameter (option (pair signature (pair string nat)));
return string;
parameter (pair signature (pair string nat));
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}}}
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; NIL operation; PAIR}
{FAIL}}

View File

@ -1,5 +1,5 @@
parameter key_hash;
return unit;
storage unit;
code {DIP{UNIT}; CAR; IMPLICIT_ACCOUNT;
PUSH tez "100.00"; UNIT; TRANSFER_TOKENS; PAIR}
PUSH tez "100.00"; UNIT; TRANSFER_TOKENS;
NIL operation; SWAP; CONS; PAIR}

View File

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

View File

@ -1,9 +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
storage (pair string (map string (lambda unit string)));
code { DUP; DIP{CDDR}; 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
PAIR;
NIL operation; PAIR} # Calling convention

View File

@ -1,5 +1,3 @@
parameter unit;
storage unit;
return unit;
code {}
code {CDR; NIL operation; PAIR}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
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
storage int ;
code { # This contract stops accepting transactions after N incoming transactions
CDR ; DUP ; PUSH int 0 ; CMPLT; IF {PUSH int -1 ; ADD} {FAIL};
NIL operation ; PAIR} ;

View File

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

View File

@ -1,4 +1,3 @@
parameter key;
return key_hash;
storage unit;
code {CAR; HASH_KEY; DIP{UNIT}; PAIR}
storage (option key_hash);
code {CAR; HASH_KEY; SOME ;NIL operation; PAIR}

View File

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

View File

@ -1,5 +1,3 @@
parameter string;
return string;
storage unit;
code {};
storage string;
code {CAR; NIL operation; PAIR};

View File

@ -1,4 +1,3 @@
parameter bool;
storage unit;
return bool;
code {CAR; IF {PUSH bool True} {PUSH bool False}; UNIT; SWAP; PAIR};
storage (option bool);
code {CAR; IF {PUSH bool True} {PUSH bool False}; SOME; NIL operation; PAIR};

View File

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

View File

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

View File

@ -1,7 +1,5 @@
parameter (list int);
return (list int);
storage unit;
storage (list int);
code { CAR; # Access list
# Insert procedure
LAMBDA (pair int (list int))
@ -23,5 +21,5 @@ code { CAR; # Access list
{DUP; CAR; DIP{CDR}; CONS};
REDUCE};
NIL int; SWAP; DIP{SWAP}; # Accumulator for reverse onto
REDUCE; # Execute reverse onto
UNIT; SWAP; PAIR} # Calling convention
REDUCE; # Execute reverse onto
NIL operation; PAIR} # Calling convention

View File

@ -1,9 +1,5 @@
# NONE if user wants to get the value
# SOME (signed hash of the string, string)
# (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
@ -18,4 +14,4 @@ code {DUP; DUP; CAR;
# Revert the update. This could be replaced with FAIL
{DROP; DUP; CDR; DIP{CDDR}}};
# Cleanup
SWAP; PAIR}
DIP{DROP}; NIL operation; PAIR}

View File

@ -1,11 +1,11 @@
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 }
IF { CAR; AMOUNT; PAIR; NOW; PUSH int 604800; ADD; PAIR;
NIL operation }
# 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
@ -13,6 +13,7 @@ code { DUP; CDAR;
# New storage
DIP{ AMOUNT; PAIR; NOW; PUSH int 604800; ADD; PAIR };
# Pay funds to old king
IMPLICIT_ACCOUNT; AMOUNT; UNIT; TRANSFER_TOKENS; DROP }};
IMPLICIT_ACCOUNT; AMOUNT; UNIT; TRANSFER_TOKENS;
NIL operation; SWAP; CONS}};
# Cleanup
UNIT; PAIR };
PAIR };

View File

@ -1,4 +1,3 @@
parameter (list string);
return (list string);
storage unit;
code {}
storage (list string);
code {CAR; NIL operation; PAIR}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,8 @@
parameter unit;
storage (list (contract unit unit));
return unit;
code { CDR; PUSH bool True; # Setup loop
storage (list (contract unit));
code { CDR; DUP;
DIP {NIL operation}; 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
SWAP; DIP {CONS}; PUSH bool True} # Setup for next round of loop
{ NIL (contract unit); PUSH bool False}}; # Data to satisfy types and end loop
DROP; PAIR}; # Calling convention

View File

@ -1,6 +1,5 @@
parameter unit;
storage (pair timestamp (pair tez (contract unit unit)));
return unit;
storage (pair timestamp (pair tez (contract unit)));
code { CDR; # Ignore the parameter
DUP; # Duplicate the storage
CAR; # Get the timestamp
@ -14,5 +13,6 @@ code { CDR; # Ignore the parameter
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
TRANSFER_TOKENS; # Emit the transfer
NIL operation; SWAP; CONS;# Make a singleton list of internal operations
PAIR} # Pair up to meet the calling convention

View File

@ -1,8 +1,7 @@
parameter (list string);
return (list string);
storage unit;
storage (list string);
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 }
NIL operation; PAIR }

View File

@ -1,6 +1,6 @@
return unit;
parameter unit;
storage unit;
code { PUSH unit Unit ;
storage (pair @truc unit unit);
code { DROP; UNIT ; UNIT ; PAIR ; UNIT ;
DUUP @truc ;
DROP ; DROP }
DIP { DROP ; DROP } ;
NIL operation ; PAIR }

View File

@ -1,4 +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 } };
code { MAP_CDADDAADR { PUSH tez "1.00" ; ADD } ;
NIL operation ; SWAP; SET_CAR };

View File

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

View File

@ -1,4 +1,3 @@
parameter (map nat nat);
return (map nat nat);
storage unit;
code {}
storage (map nat nat);
code { CAR ; NIL operation ; PAIR }

View File

@ -1,7 +1,6 @@
parameter (map int int);
return (pair int int);
storage unit;
storage (pair int int);
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}
NIL operation; PAIR}

View File

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

View File

@ -1,10 +1,9 @@
parameter (list int);
storage unit;
return (option int);
storage (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};
REDUCE; NIL operation; PAIR};

View File

@ -1,13 +1,11 @@
parameter (pair int int);
return int;
storage unit;
storage int;
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
NIL operation; # Return no op
PAIR} # Pair the numbers satisfying the calling convention

View File

@ -1,4 +1,3 @@
parameter unit;
code {};
return unit;
storage unit;
code {CDR; NIL operation; PAIR};

View File

@ -1,4 +1,3 @@
parameter bool;
return bool;
storage unit;
code {CAR; NOT; UNIT; SWAP; PAIR};
storage (option bool);
code {CAR; NOT; SOME; NIL operation; PAIR};

View File

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

View File

@ -1,9 +1,8 @@
storage unit ;
parameter nat ;
return (list (contract unit unit)) ;
storage (list (contract unit)) ;
code
{ CAR ; DUP ; PUSH nat 0 ; CMPNEQ ;
DIIP { NIL (contract unit unit) } ;
DIIP { NIL (contract unit) } ;
LOOP
{ PUSH tez "5.00" ;
PUSH bool True ; # delegatable
@ -14,4 +13,4 @@ code
PUSH nat 1 ; SWAP ; SUB ; ABS ;
DUP ; PUSH nat 0 ; CMPNEQ } ;
DROP ;
UNIT ; SWAP ; PAIR }
NIL operation ; PAIR }

View File

@ -1,4 +1,3 @@
parameter (pair bool bool);
return (pair bool bool);
storage unit;
code {}
storage (option (pair bool bool));
code {CAR; SOME; NIL operation; PAIR}

View File

@ -1,4 +1,4 @@
parameter unit;
return unit;
storage unit;
code { UNIT; UNIT; UNIT; UNIT; UNIT; PAIAAIAIAIR @name; DROP}
code { UNIT; UNIT; UNIT; UNIT; UNIT; PAIAAIAIAIR @name; DROP;
CDR; NIL operation; PAIR}

View File

@ -1,26 +0,0 @@
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

@ -1,7 +1,6 @@
storage (pair (map nat (pair bool bool)) (pair key key));
return bool;
storage (pair bool (pair (map nat (pair bool bool)) (pair key key)));
parameter (or nat (pair signature nat));
code { DUP; CAR; DIP{CDR}; # Stack rangling
code { DUP; CAR; DIP{CDDR}; # 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};
@ -21,4 +20,5 @@ code { DUP; CAR; DIP{CDR}; # Stack rangling
CAR; PUSH bool True; SWAP; PAIR; SOME; SWAP}
{FAIL}};
# Update the stored value and finish off
UPDATE; PAIR; PUSH bool False; PAIR}}
UPDATE; PAIR; PUSH bool False; PAIR};
NIL operation; PAIR }

View File

@ -1,17 +0,0 @@
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

@ -1,9 +1,8 @@
parameter (option string);
storage (pair (pair nat nat) (map nat string));
return (option string);
storage (pair (option string) (pair (pair nat nat) (map nat string)));
code { DUP; CAR;
# Retrieving an element
IF_NONE { CDR; DUP; CAR; DIP{CDR; DUP}; DUP;
IF_NONE { CDDR; DUP; CAR; DIP{CDR; DUP}; DUP;
CAR; SWAP; DIP{GET}; # Check if an element is available
SWAP;
# Put NONE on stack and finish
@ -15,10 +14,11 @@ code { DUP; CAR;
DUP; CAR; PUSH nat 1; ADD; DIP{ CDR }; PAIR; PAIR};
PAIR }}
# Arrange the stack
{ DIP{DUP; CDAR; DIP{CDDR}; DUP}; SWAP; CAR;
{ DIP{DUP; CDDAR; DIP{CDDDR}; 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 }}
PAIR; PAIR; NONE string; PAIR };
NIL operation; PAIR}

View File

@ -1,7 +1,6 @@
parameter (pair (lambda int int) (list int));
return (list int);
storage unit;
storage (list int);
code { DIP{NIL int};
CAR;
DUP;
@ -19,4 +18,4 @@ code { DIP{NIL int};
(list int)
{DUP; CAR; DIP{CDR}; CONS};
REDUCE; # Correct list order
UNIT; SWAP; PAIR} # Calling convention
NIL operation; PAIR} # Calling convention

View File

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

View File

@ -1,4 +1,3 @@
parameter unit;
code {CAR; PUSH nat 300; PAIR};
return nat;
storage unit;
storage (option nat);
code {DROP; PUSH nat 300; SOME; NIL operation; PAIR};

View File

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

View File

@ -1,6 +1,5 @@
parameter (list string);
return (list string);
storage unit;
storage (list string);
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}
DROP; NIL operation; PAIR}

View File

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

View File

@ -1,6 +1,5 @@
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 };
NIL operation ; PAIR };

View File

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

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