common: enforce that msat fields are called "xxx_msat".

Now we've fixed them all, make sure no new ones slip in!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-06-20 19:52:09 +09:30
parent fccb11a641
commit 01411d70be
4 changed files with 16 additions and 2 deletions

View file

@ -402,6 +402,8 @@ void json_add_amount_msat_compat(struct json_stream *result,
const char *msatfieldname)
{
json_add_u64(result, rawfieldname, msat.millisatoshis); /* Raw: low-level helper */
if (!deprecated_apis)
assert(strends(msatfieldname, "_msat"));
json_add_amount_msat_only(result, msatfieldname, msat);
}
@ -409,6 +411,8 @@ void json_add_amount_msat_only(struct json_stream *result,
const char *msatfieldname,
struct amount_msat msat)
{
if (!deprecated_apis)
assert(strends(msatfieldname, "_msat"));
json_add_string(result, msatfieldname,
type_to_string(tmpctx, struct amount_msat, &msat));
}

View file

@ -1616,7 +1616,13 @@ static void add_config(struct lightningd *ld,
/* FIXME: We actually treat it as if they specified
* --plugin for each one, so ignore these */
} else if (opt->cb_arg == (void *)opt_set_msat) {
json_add_amount_msat_only(response, name0, ld->config.max_dust_htlc_exposure_msat);
/* We allow -msat not _msat here, unlike
* json_add_amount_msat_only */
assert(strends(name0, "-msat"));
json_add_string(response, name0,
fmt_amount_msat(tmpctx,
*(struct amount_msat *)
opt->u.carg));
#if EXPERIMENTAL_FEATURES
} else if (opt->cb_arg == (void *)opt_set_accept_extra_tlv_types) {
/* TODO Actually print the option */

View file

@ -1825,7 +1825,9 @@ static void payment_add_attempt(struct json_stream *s, const char *fieldname, st
json_add_string(s, "failreason", p->failreason);
json_add_u64(s, "partid", p->partid);
json_add_amount_msat_only(s, "amount", p->amount);
if (deprecated_apis)
json_add_amount_msat_only(s, "amount", p->amount);
json_add_amount_msat_only(s, "amount_msat", p->amount);
if (p->parent != NULL)
json_add_u64(s, "parent_partid", p->parent->partid);

View file

@ -14,6 +14,8 @@ struct command_result *command_finished(struct command *cmd UNNEEDED, struct jso
/* Generated stub for command_still_pending */
struct command_result *command_still_pending(struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_still_pending called!\n"); abort(); }
/* Generated stub for deprecated_apis */
bool deprecated_apis;
/* Generated stub for feature_offered */
bool feature_offered(const u8 *features UNNEEDED, size_t f UNNEEDED)
{ fprintf(stderr, "feature_offered called!\n"); abort(); }