From f668e72dd6cdfbe5303222a2f1c28e197278a44d Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 26 May 2021 18:04:07 -0500 Subject: [PATCH] option_will_fund: print out lease rates in listnodes Note that we use the names from the spec. Changelog-Experimental: JSON-RPC: `listnodes` now includes the `lease_rates`, if available --- common/json_helpers.c | 14 ++++++++++++++ common/json_helpers.h | 5 +++++ plugins/topology.c | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/common/json_helpers.c b/common/json_helpers.c index 61450a302..924820c78 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -13,6 +13,7 @@ #include #include #include +#include bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok, uint64_t *satoshi) @@ -369,3 +370,16 @@ void json_add_preimage(struct json_stream *result, const char *fieldname, json_add_hex(result, fieldname, preimage, sizeof(*preimage)); } +void json_add_lease_rates(struct json_stream *result, + const struct lease_rates *rates) +{ + json_add_amount_sat_only(result, "lease_fee_base_msat", + amount_sat(rates->lease_fee_base_sat)); + json_add_num(result, "lease_fee_basis", rates->lease_fee_basis); + json_add_num(result, "funding_weight", rates->funding_weight); + json_add_amount_msat_only(result, + "channel_fee_max_base_msat", + amount_msat(rates->channel_fee_max_base_msat)); + json_add_num(result, "channel_fee_max_proportional_thousandths", + rates->channel_fee_max_proportional_thousandths); +} diff --git a/common/json_helpers.h b/common/json_helpers.h index 5d0b568f4..cfe12c5fd 100644 --- a/common/json_helpers.h +++ b/common/json_helpers.h @@ -11,6 +11,7 @@ struct amount_msat; struct amount_sat; struct bip340sig; struct channel_id; +struct lease_rates; struct node_id; struct preimage; struct pubkey; @@ -179,4 +180,8 @@ void json_add_psbt(struct json_stream *stream, const char *fieldname, const struct wally_psbt *psbt); +/* Add fields from the lease_rates to a json stream. + * Note that field names are set */ +void json_add_lease_rates(struct json_stream *result, + const struct lease_rates *rates); #endif /* LIGHTNING_COMMON_JSON_HELPERS_H */ diff --git a/plugins/topology.c b/plugins/topology.c index 6b81bc456..9a263df64 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -557,6 +557,12 @@ static void json_add_node(struct json_stream *js, for (size_t i = 0; i < tal_count(addrs); i++) json_add_address(js, NULL, &addrs[i]); json_array_end(js); + + if (na_tlvs->option_will_fund) { + json_object_start(js, "option_will_fund"); + json_add_lease_rates(js, na_tlvs->option_will_fund); + json_object_end(js); + } } out: json_object_end(js);