mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
common/lease_rates: more things const.
And fix up lease_rates_fromhex to be the obvious calling convention. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
neil saitug
parent
6da915c96a
commit
1aa2ba0991
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user