Skip to main content

Dynamic_entrypoints

Important: The Test module is only available inside the ligo run test command. See also Testing LIGO.

val set :
('p, 's) dynamic_entrypoint
-> ('p, 's) entrypoint option
-> dynamic_entrypoints
-> dynamic_entrypoints
const set : <P, S>(x1: dynamic_entrypoint<P, S>, x2: option<entrypoint>, x3: dynamic_entrypoints) => dynamic_entrypoints

To set an dynamic entrypoint within a static entrypoint, just use Dynamic_entrypoints.set:

[@entry]
let set_one (one_v2 : (unit, int) entrypoint) (s : storage) : operation list * storage =
let dynamic_entrypoints =
Dynamic_entrypoints.set one (Some one_v2) s.dynamic_entrypoints in
[], {s with dynamic_entrypoints}
@entry
const set_one = (one_v2 : entrypoint<unit, int>, s : storage) : [list<operation>, storage] => {
let dynamic_entrypoints =
Dynamic_entrypoints.set(one, Some(one_v2), s.dynamic_entrypoints);
return [list([]), {...s, dynamic_entrypoints}]
}
val get :
('p, 's) dynamic_entrypoint
-> dynamic_entrypoints
-> ('p, 's) entrypoint option
const get : <P, S>(x1: dynamic_entrypoint<P, S>, x2: dynamic_entrypoints) => option<dynamic_entrypoint<P, S>>

To get an dynamic entrypoint within a static entrypoint and call it just use Dynamic_entrypoints.get

[@entry]
let call_one () (s : storage) : operation list * storage =
match Dynamic_entrypoints.get one s.dynamic_entrypoints with
Some f ->
let op, storage = f () s.storage in
op, {s with storage}
| None -> failwith (-1)
@entry
const call_one = ([], s : storage) : [list<operation>, storage] =>
match (Dynamic_entrypoints.get(one, s.dynamic_entrypoints)) {
when (Some(f)): do {
const [op, storage] = f([], s.storage);
return [op, ({...s, storage})]
};
when (None): failwith(-1);
}
val set_bytes :
('p, 's) dynamic_entrypoint
-> bytes option
-> dynamic_entrypoints
-> dynamic_entrypoints
const set_bytes : <P, S>(x1: dynamic_entrypoint<P, S>, x2: option<bytes>, x3: dynamic_entrypoints) => dynamic_entrypoints

You can use Dynamic_entrypoints.set_entrypoint_bytes to set an entrypoints to its bytes encoding directly. If your encoding is wrong, any call to Dynamic_entrypoints.get will fail at run-time