From 3a4a3597a32997172ea38b8514f7a85f9cdd8c01 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Wed, 1 Apr 2020 20:37:12 -0500 Subject: [PATCH] amount: add a helper for msat == sat Handy dandy method for verifying that a millisatoshi-typed amount is equivalent to a satoshi-typed amount. --- common/amount.c | 10 ++++++++++ common/amount.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/common/amount.c b/common/amount.c index e2a6e1299..e989d69a6 100644 --- a/common/amount.c +++ b/common/amount.c @@ -381,6 +381,16 @@ bool amount_msat_less_eq_sat(struct amount_msat msat, struct amount_sat sat) return msat.millisatoshis <= msat_from_sat.millisatoshis; } +bool amount_msat_eq_sat(struct amount_msat msat, struct amount_sat sat) +{ + struct amount_msat msat_from_sat; + + if (!amount_sat_to_msat(&msat_from_sat, sat)) + return false; + + return msat.millisatoshis == msat_from_sat.millisatoshis; +} + bool amount_msat_to_u32(struct amount_msat msat, u32 *millisatoshis) { if (amount_msat_greater_eq(msat, AMOUNT_MSAT(0x100000000))) diff --git a/common/amount.h b/common/amount.h index f5d9ef7f1..8bd7cd4ef 100644 --- a/common/amount.h +++ b/common/amount.h @@ -105,6 +105,8 @@ bool amount_msat_greater_eq_sat(struct amount_msat msat, struct amount_sat sat); bool amount_msat_less_sat(struct amount_msat msat, struct amount_sat sat); /* Is msat <= sat? */ bool amount_msat_less_eq_sat(struct amount_msat msat, struct amount_sat sat); +/* Is msat == sat? */ +bool amount_msat_eq_sat(struct amount_msat msat, struct amount_sat sat); /* Check whether this asset is actually the main / fee-paying asset of the * current chain. */