-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
type storage = unit
contract type X = sig
type storage
val%entry entry_a : nat -> storage -> operation list * storage
val%entry entry_b : int -> storage -> operation list * storage
end
contract type Y = sig
type storage
type pt =
| A of nat
| B of int
val%entry main : pt -> storage -> operation list * storage
end
(* 1 : Using entry syntax *)
let%entry main (parameter : nat * X.instance) s =
let num, c = parameter in
let op =
if num < 50p then
Contract.call c 0tz entry_a 1p
else
Contract.call c 0tz entry_b 1
in
([op], s)
(* 2 : Using entry manually *)
(* let%entry main (parameter : nat * Y.instance) s =
let num, c = parameter in
let arg =
if num < 50p then
Y.A 1p
else
Y.B 1
in
let op = Contract.call c 0tz arg in
([op], s) *)
For code block 1, it will compile to
parameter
(pair nat
(contract :X (or :_entries (nat %_Liq_entry_entry_a) (int %_Liq_entry_entry_b))));
storage unit;
code { DUP ;
DIP { CDR } ;
CAR ;
DUP @parameter ;
DUP ;
CDR @c ;
DUUUUP @s ;
NIL operation ;
PUSH nat 50 ;
DUUUUUP ;
CAR @num ;
COMPARE ;
LT ;
IF { DUUUP @c ;
PUSH mutez 0 ;
PUSH nat 1 ;
LEFT %_Liq_entry_entry_a % (int %_Liq_entry_entry_b) ;
TRANSFER_TOKENS }
{ DUUUP @c ;
PUSH mutez 0 ;
PUSH int 1 ;
RIGHT % %_Liq_entry_entry_b nat ;
TRANSFER_TOKENS } ;
DIIIP { DROP ; DROP ; DROP ; DROP } ;
RENAME @op ;
CONS ;
PAIR };
For code block 2, it will compile to
parameter (pair nat (contract :Y (or :Y.pt (nat %Y.A) (int %Y.B))));
storage unit;
code { DUP ;
DIP { CDR } ;
CAR ;
DUP @parameter ;
DUP ;
CDR @c ;
PUSH mutez 0 ;
PUSH nat 50 ;
DUUUUP ;
CAR @num ;
COMPARE ;
LT ;
IF { PUSH (or :Y.pt (nat %Y.A) (int %Y.B)) (Left 1) }
{ PUSH (or :Y.pt (nat %Y.A) (int %Y.B)) (Right 1) } ;
DIIIP { DROP ; DROP } ;
RENAME @arg ;
TRANSFER_TOKENS @op ;
SWAP ;
NIL operation ;
DUUUP ;
DIIIP { DROP } ;
CONS ;
PAIR };
Using multiple entries will generate larger size of code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels