Skip to content

Commit

Permalink
common/lease_rates: more things const.
Browse files Browse the repository at this point in the history
And fix up lease_rates_fromhex to be the obvious calling convention.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and niftynei committed Jul 15, 2021
1 parent 04497c7 commit ed51715
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
6 changes: 3 additions & 3 deletions common/json_tok.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,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),
Expand Down
22 changes: 10 additions & 12 deletions common/lease_rates.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions common/lease_rates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit ed51715

Please sign in to comment.