mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-02 12:44:26 +01:00
common: add msat to sat convert helper.
We don't always want to round down, sometimes we want to fail. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -18,6 +18,16 @@ bool amount_sat_to_msat(struct amount_msat *msat,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool amount_msat_to_sat(struct amount_sat *sat,
|
||||
struct amount_msat msat)
|
||||
{
|
||||
if (msat.millisatoshis % MSAT_PER_SAT)
|
||||
return false;
|
||||
sat->satoshis = msat.millisatoshis / MSAT_PER_SAT;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* You can always truncate millisatoshis->satoshis. */
|
||||
struct amount_sat amount_msat_to_sat_round_down(struct amount_msat msat)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,10 @@ struct amount_sat amount_sat(u64 satoshis);
|
||||
WARN_UNUSED_RESULT bool amount_sat_to_msat(struct amount_msat *msat,
|
||||
struct amount_sat sat);
|
||||
|
||||
/* You may not always be able to convert millisatoshis->satoshis without rounding. */
|
||||
WARN_UNUSED_RESULT bool amount_msat_to_sat(struct amount_sat *sat,
|
||||
struct amount_msat msat);
|
||||
|
||||
/* You can always truncate millisatoshis->satoshis. */
|
||||
struct amount_sat amount_msat_to_sat_round_down(struct amount_msat msat);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user