Skip to main content

Dynamic_entrypoints

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

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
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}]
}
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
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);
}
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