add_strategy
function add_strategy(op: meta, account_details: (gtv) -> account_details, action: (account, gtv) -> unit?): map<text, _strategy>(source)
Used to add new strategies to the dapp. This does not need to be called for FT4-defined strategies.
This function helps avoid a common issue where a strategy is registered with the wrong name. If that happens, many functions of this module will throw errors pointing to that strategy as missing, since they won't be able to find it.
Example usage:
operation my_strategy(
main: accounts.auth_descriptor,
disposable: accounts.auth_descriptor? = null
) {
strategies.require_register_account_next_operation();
}
function account_details(gtv) {
val params = struct<ras_open>.from_gtv(gtv);
val signers = accounts.get_signers(params.main);
return strategies.account_details(
account_id = accounts.get_account_id_from_signers(signers),
main = params.main,
disposable = params.disposable
);
}
function my_custom_logic(accounts.account, gtv) {
// custom logic that the strategy has to follow
}
@extend(strategies.strategy)
function () = strategies.add_strategy(
op = rell.meta(my_strategy),
account_details = account_details(*),
action = my_custom_logic(*)
);
Content copied to clipboard
Parameters
op
the custom operation that defines the strategy and its name
account_details
the function that retrieves the account details from op
action
the function that implements the strategy logic. If null, _no_action
is called.
See also
_strategy
for more information about the parameters of this function
_no_action
for more information on performing no action