paymod: Generate type-safe accessor functions for modifier data

This should make it easy for JSON-RPC functions and modifiers to get the
associated data for a given modifier name. Useful if a modifier needs to
access its parent's modifier data, or in other functions that need to access
modifier data, e.g., when passing destination pointers into the `param()`
call.
This commit is contained in:
Christian Decker
2020-05-08 16:46:56 +02:00
parent 23b4dca3c7
commit aeb5cc0b7c
2 changed files with 26 additions and 0 deletions

View File

@@ -146,6 +146,19 @@ void payment_continue(struct payment *p)
abort();
}
void *payment_mod_get_data(const struct payment *p,
const struct payment_modifier *mod)
{
for (size_t i = 0; p->modifiers[i] != NULL; i++)
if (p->modifiers[i] == mod)
return p->modifier_data[i];
/* If we ever get here it means that we asked for the data for a
* non-existent modifier. This is a compile-time/wiring issue, so we
* better check that modifiers match the data we ask for. */
abort();
}
static inline struct dummy_data *
dummy_data_init(struct payment *p)
{