Browse Source

amount: add a helper for msat == sat

Handy dandy method for verifying that a millisatoshi-typed amount is
equivalent to a satoshi-typed amount.
nifty/pset-pre
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
3a4a3597a3
  1. 10
      common/amount.c
  2. 2
      common/amount.h

10
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)))

2
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. */

Loading…
Cancel
Save