bookkeeper: expose currencyrate_str and bkpr_of so report.c can access them.
What changed, and why it matters
This is a routine code cleanup in the bookkeeper plugin. Two internal helper functions are made visible to other source files so they can be reused in an upcoming report feature. There is no security-relevant change.
No security action required; treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes the static qualifier from bkpr_of() and extracts the currency-rate formatting logic from json_add_currencyrate() into a new non-static currencyrate_str() helper, declared in bookkeeper.h. json_add_currencyrate() is refactored to call currencyrate_str(). This is a pure refactoring/reuse change with no functional or security impact.
Changed components
plugins/bkpr/bookkeeper.cplugins/bkpr/bookkeeper.hInspect captured patch +28 / −6
diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c
index ee1f0b4b..55a79cf3 100644
--- a/plugins/bkpr/bookkeeper.c
+++ b/plugins/bkpr/bookkeeper.c
@@ -42,7 +42,7 @@
/* We accept currencyrate from about 60 seconds ago */
#define CURRENCYRATE_TOLERANCE_SECONDS 60
-static struct bkpr *bkpr_of(struct plugin *plugin)
+struct bkpr *bkpr_of(struct plugin *plugin)
{
return plugin_get_data(plugin, struct bkpr);
}
@@ -59,17 +59,30 @@ static const struct currencyrate *covering_currencyrate(const struct bkpr *bkpr,
return NULL;
}
+const char *currencyrate_str(const tal_t *ctx,
+ const struct bkpr *bkpr,
+ u64 timestamp)
+{
+ const struct currencyrate *crate;
+
+ crate = covering_currencyrate(bkpr, timestamp);
+ if (!crate)
+ return NULL;
+
+ return tal_fmt(ctx, "%"PRIu64".%04"PRIu64,
+ crate->raw_rate / RATE_MUL_FACTOR,
+ crate->raw_rate % RATE_MUL_FACTOR);
+}
+
void json_add_currencyrate(struct json_stream *result,
const char *fieldname,
const struct bkpr *bkpr,
u64 timestamp)
{
- const struct currencyrate *crate = covering_currencyrate(bkpr, timestamp);
+ const char *str = currencyrate_str(NULL, bkpr, timestamp);
- if (crate)
- json_add_primitive_fmt(result, fieldname, "%"PRIu64".%04"PRIu64,
- crate->raw_rate / RATE_MUL_FACTOR,
- crate->raw_rate % RATE_MUL_FACTOR);
+ if (str)
+ json_add_primitive(result, fieldname, take(str));
}
struct refresh_cb {
diff --git a/plugins/bkpr/bookkeeper.h b/plugins/bkpr/bookkeeper.h
index 76234fea..921f5730 100644
--- a/plugins/bkpr/bookkeeper.h
+++ b/plugins/bkpr/bookkeeper.h
@@ -6,6 +6,7 @@
#include <common/json_parse.h>
struct command;
+struct plugin;
/* Most currencies have 2 decimal places, but 4 is the current maximum. */
#define RATE_MUL_FACTOR 10000
@@ -42,6 +43,14 @@ struct bkpr {
struct command *currency_cmds;
};
+/* Get bkpr struct for the plugin */
+struct bkpr *bkpr_of(struct plugin *plugin);
+
+/* Get currency rate for this timestamp, as string, or NULL. */
+const char *currencyrate_str(const tal_t *ctx,
+ const struct bkpr *bkpr,
+ u64 timestamp);
+
/* Add optional currencyrate for this timestamp */
void json_add_currencyrate(struct json_stream *result,
const char *fieldname,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.