# Michelson pseudo-code to transform from source script.
# This transformation adds 'set_delegate' entrypoint, e.g.:
#
# parameter <parameter_expr> ;
# storage <storage_expr> ;
# code <code_expr> ;
#
# to:
parameter
(or
(or (key_hash %set_delegate)
(unit %remove_delegate))
(or %default string nat)
) ;
storage
(pair
key_hash # manager
(pair string nat)
) ;
code {
DUP ;
CAR ;
IF_LEFT
{ # 'set_delegate'/'remove_delegate' entrypoints
# Assert no token was sent:
# to send tokens, the default entry point should be used
PUSH mutez 0 ;
AMOUNT ;
ASSERT_CMPEQ ;
# Assert that the sender is the manager
DUP 2 ;
CDR ;
CAR ;
IMPLICIT_ACCOUNT ; ADDRESS ;
SENDER ;
IFCMPNEQ
{ SENDER ;
PUSH string "Only the owner can operate." ;
PAIR ;
FAILWITH ;
}
{ DIP { CDR ; NIL operation } ;
IF_LEFT
{ # 'set_delegate' entrypoint
SOME ;
SET_DELEGATE ;
CONS ;
PAIR ;
}
{ # 'remove_delegate' entrypoint
DROP ;
NONE key_hash ;
SET_DELEGATE ;
CONS ;
PAIR ;
}
}
}
{ # Transform the inputs to the original script types
DIP { CDR ; DUP ; CDR } ;
PAIR ;
# 'default' entrypoint - original code
{ UNPAIR;
IF_LEFT
{ DIP { UNPAIR ; DROP } }
{ DUG 1; UNPAIR ; DIP { DROP } } ;
PAIR ; NIL operation ; PAIR }
# Transform the outputs to the new script types (manager's storage is unchanged)
SWAP ;
CAR ;
SWAP ;
UNPAIR ;
DIP { SWAP ; PAIR } ;
PAIR ;
}
}