diff --git a/common/json_tok.c b/common/json_tok.c index 33af9eee0a6b..dc2df87aef52 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -591,9 +591,9 @@ struct command_result *param_lease_hex(struct command *cmd, const jsmntok_t *tok, struct lease_rates **rates) { - if (!lease_rates_fromhex(cmd, buffer + tok->start, - tok->end - tok->start, - rates)) + *rates = lease_rates_fromhex(cmd, buffer + tok->start, + tok->end - tok->start); + if (!*rates) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Could not decode '%s' %.*s", name, json_tok_full_len(tok), diff --git a/common/lease_rates.c b/common/lease_rates.c index fb05d454e2d6..8aab58eda440 100644 --- a/common/lease_rates.c +++ b/common/lease_rates.c @@ -18,7 +18,7 @@ bool lease_rates_empty(const struct lease_rates *rates) return lease_rates_eq(rates, &zero); } -void lease_rates_get_commitment(struct pubkey *pubkey, +void lease_rates_get_commitment(const struct pubkey *pubkey, u32 lease_expiry, u32 chan_fee_msat, u16 chan_fee_ppt, @@ -44,7 +44,7 @@ void lease_rates_get_commitment(struct pubkey *pubkey, sha256_done(&sctx, sha); } -bool lease_rates_calc_fee(struct lease_rates *rates, +bool lease_rates_calc_fee(const struct lease_rates *rates, struct amount_sat accept_funding_sats, struct amount_sat requested_sats, u32 onchain_feerate, @@ -103,22 +103,20 @@ char *lease_rates_tohex(const tal_t *ctx, const struct lease_rates *rates) return hex; } -bool lease_rates_fromhex(const tal_t *ctx, - const char *hexdata, size_t hexlen, - struct lease_rates **rates) +struct lease_rates *lease_rates_fromhex(const tal_t *ctx, + const char *hexdata, size_t hexlen) { const u8 *data = tal_hexdata(ctx, hexdata, hexlen); size_t len = tal_bytelen(data); + struct lease_rates *ret; - *rates = tal(ctx, struct lease_rates); - fromwire_lease_rates(&data, &len, *rates); + ret = tal(ctx, struct lease_rates); + fromwire_lease_rates(&data, &len, ret); - if (data == NULL) { - tal_free(*rates); - return false; - } + if (data == NULL || len != 0) + return tal_free(ret); - return true; + return ret; } char *lease_rates_fmt(const tal_t *ctx, const struct lease_rates *rates) diff --git a/common/lease_rates.h b/common/lease_rates.h index 3b70a83428b0..14bc947e7e71 100644 --- a/common/lease_rates.h +++ b/common/lease_rates.h @@ -14,7 +14,7 @@ struct sha256; bool lease_rates_empty(const struct lease_rates *rates); -void lease_rates_get_commitment(struct pubkey *pubkey, +void lease_rates_get_commitment(const struct pubkey *pubkey, u32 lease_expiry, u32 chan_fee_msat, u16 chan_fee_ppt, @@ -28,7 +28,7 @@ STRUCTEQ_DEF(lease_rates, 2, lease_fee_base_sat, channel_fee_max_base_msat); -bool lease_rates_calc_fee(struct lease_rates *rates, +bool lease_rates_calc_fee(const struct lease_rates *rates, struct amount_sat accept_funding_sats, struct amount_sat requested_sats, u32 onchain_feerate, @@ -42,9 +42,8 @@ WARN_UNUSED_RESULT bool lease_rates_set_lease_fee_sat(struct lease_rates *rates, char *lease_rates_tohex(const tal_t *ctx, const struct lease_rates *rates); /* Convert 'lease_rates' from a hexstring */ -bool lease_rates_fromhex(const tal_t *ctx, - const char *hexdata, size_t len, - struct lease_rates **rates); +struct lease_rates *lease_rates_fromhex(const tal_t *ctx, + const char *hexdata, size_t len); /* Format a string describing the passed in lease_rates */ char *lease_rates_fmt(const tal_t *ctx, const struct lease_rates *rates);