mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
libplugin: make set callback for options take plugin ptr, check correct type.
I added a plugin arg and was surprised that compile didn't break. This is because typesafe_cb et al are conditional casts: if the type isn't as expected it has no effect, but we're passing plugin_option() through varargs, so everything is accepted! Add a noop inline to check type, and fix up the two cases where we used `const char *` instead of `char *`. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1202,7 +1202,7 @@ param_funder_opt(struct command *cmd, const char *name,
|
||||
opt_str = tal_strndup(cmd, buffer + tok->start,
|
||||
tok->end - tok->start);
|
||||
|
||||
err = funding_option(opt_str, *opt);
|
||||
err = funding_option(cmd->plugin, opt_str, *opt);
|
||||
if (err)
|
||||
return command_fail_badparam(cmd, name, buffer, tok, err);
|
||||
|
||||
@@ -1222,7 +1222,7 @@ param_policy_mod(struct command *cmd, const char *name,
|
||||
arg_str = tal_strndup(cmd, buffer + tok->start,
|
||||
tok->end - tok->start);
|
||||
|
||||
err = u64_option(arg_str, *mod);
|
||||
err = u64_option(cmd->plugin, arg_str, *mod);
|
||||
if (err) {
|
||||
tal_free(err);
|
||||
if (!parse_amount_sat(&sats, arg_str, strlen(arg_str)))
|
||||
@@ -1518,7 +1518,7 @@ const struct plugin_notification notifs[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static char *option_channel_base(const char *arg, struct funder_policy *policy)
|
||||
static char *option_channel_base(struct plugin *plugin, const char *arg, struct funder_policy *policy)
|
||||
{
|
||||
struct amount_msat amt;
|
||||
|
||||
@@ -1536,15 +1536,16 @@ static char *option_channel_base(const char *arg, struct funder_policy *policy)
|
||||
}
|
||||
|
||||
static char *
|
||||
option_channel_fee_proportional_thousandths_max(const char *arg,
|
||||
option_channel_fee_proportional_thousandths_max(struct plugin *plugin,
|
||||
const char *arg,
|
||||
struct funder_policy *policy)
|
||||
{
|
||||
if (!policy->rates)
|
||||
policy->rates = default_lease_rates(policy);
|
||||
return u16_option(arg, &policy->rates->channel_fee_max_proportional_thousandths);
|
||||
return u16_option(plugin, arg, &policy->rates->channel_fee_max_proportional_thousandths);
|
||||
}
|
||||
|
||||
static char *amount_option(const char *arg, struct amount_sat *amt)
|
||||
static char *amount_option(struct plugin *plugin, const char *arg, struct amount_sat *amt)
|
||||
{
|
||||
if (!parse_amount_sat(amt, arg, strlen(arg)))
|
||||
return tal_fmt(tmpctx, "Unable to parse amount '%s'", arg);
|
||||
@@ -1552,7 +1553,7 @@ static char *amount_option(const char *arg, struct amount_sat *amt)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *option_lease_fee_base(const char *arg,
|
||||
static char *option_lease_fee_base(struct plugin *plugin, const char *arg,
|
||||
struct funder_policy *policy)
|
||||
{
|
||||
struct amount_sat amt;
|
||||
@@ -1560,7 +1561,7 @@ static char *option_lease_fee_base(const char *arg,
|
||||
if (!policy->rates)
|
||||
policy->rates = default_lease_rates(policy);
|
||||
|
||||
err = amount_option(arg, &amt);
|
||||
err = amount_option(plugin, arg, &amt);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -1571,28 +1572,29 @@ static char *option_lease_fee_base(const char *arg,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *option_lease_fee_basis(const char *arg,
|
||||
static char *option_lease_fee_basis(struct plugin *plugin, const char *arg,
|
||||
struct funder_policy *policy)
|
||||
{
|
||||
if (!policy->rates)
|
||||
policy->rates = default_lease_rates(policy);
|
||||
return u16_option(arg, &policy->rates->lease_fee_basis);
|
||||
return u16_option(plugin, arg, &policy->rates->lease_fee_basis);
|
||||
}
|
||||
|
||||
static char *option_lease_weight_max(const char *arg,
|
||||
static char *option_lease_weight_max(struct plugin *plugin, const char *arg,
|
||||
struct funder_policy *policy)
|
||||
{
|
||||
if (!policy->rates)
|
||||
policy->rates = default_lease_rates(policy);
|
||||
return u16_option(arg, &policy->rates->funding_weight);
|
||||
return u16_option(plugin, arg, &policy->rates->funding_weight);
|
||||
}
|
||||
|
||||
static char *amount_sat_or_u64_option(const char *arg, u64 *amt)
|
||||
static char *amount_sat_or_u64_option(struct plugin *plugin,
|
||||
const char *arg, u64 *amt)
|
||||
{
|
||||
struct amount_sat sats;
|
||||
char *err;
|
||||
|
||||
err = u64_option(arg, amt);
|
||||
err = u64_option(plugin, arg, amt);
|
||||
if (err) {
|
||||
tal_free(err);
|
||||
if (!parse_amount_sat(&sats, arg, strlen(arg)))
|
||||
|
||||
Reference in New Issue
Block a user