From 12d0d5c185ef0a442b296ae25c253ece31f2b921 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 27 Aug 2020 10:28:32 +0930 Subject: [PATCH] amount: cleanup usage. We've got some recently-added primitives which help. Signed-off-by: Rusty Russell --- common/onion.c | 2 +- plugins/libplugin-pay.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/common/onion.c b/common/onion.c index 76c5c2c73..4db8c207c 100644 --- a/common/onion.c +++ b/common/onion.c @@ -30,7 +30,7 @@ static u8 *make_v0_hop(const tal_t *ctx, /* Prepend 0 byte for realm */ u8 *buf = tal_arrz(ctx, u8, 1); towire_short_channel_id(&buf, scid); - towire_u64(&buf, forward.millisatoshis); /* Raw: low-level serializer */ + towire_amount_msat(&buf, forward); towire_u32(&buf, outgoing_cltv); towire(&buf, padding, ARRAY_SIZE(padding)); assert(tal_bytelen(buf) == 1 + 32); diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 374f1555f..efadc1a2f 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -611,7 +611,7 @@ static u8 *tal_towire_legacy_payload(const tal_t *ctx, const struct legacy_paylo /* Prepend 0 byte for realm */ u8 *buf = tal_arrz(ctx, u8, 1); towire_short_channel_id(&buf, &payload->scid); - towire_u64(&buf, payload->forward_amt.millisatoshis); /* Raw: low-level serializer */ + towire_amount_msat(&buf, payload->forward_amt); towire_u32(&buf, payload->outgoing_cltv); towire(&buf, padding, ARRAY_SIZE(padding)); assert(tal_bytelen(buf) == 1 + 32); @@ -2884,7 +2884,8 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) * multiply it by the number of targetted parts until the * total amount divided by part amount gives us at most that * number of parts. */ - while (target_amount * PRESPLIT_MAX_SPLITS < p->amount.millisatoshis) /* Raw: Multiplication comparison */ + while (amount_msat_less(amount_msat(target_amount * PRESPLIT_MAX_SPLITS), + p->amount)) target_amount *= PRESPLIT_MAX_SPLITS; /* We need to opt-in to the MPP sending facility no matter @@ -2904,9 +2905,9 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) p, "Cannot attempt payment, we have no channel to " "which we can add an HTLC"); } else if (p->amount.millisatoshis / target_amount > htlcs) /* Raw: division */ - target.millisatoshis = p->amount.millisatoshis / htlcs; /* Raw: division */ + target = amount_msat_div(p->amount, htlcs); else - target.millisatoshis = target_amount; /* Raw: init */ + target = amount_msat(target_amount); /* If we are already below the target size don't split it * either. */