From 82c49db841c838648a31bb71f1a66f550b06c34d Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Wed, 18 Sep 2019 19:04:17 -0500 Subject: [PATCH] amount: helper method for adding sats to an msat amount see title. --- common/amount.c | 12 ++++++++++++ common/amount.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/common/amount.c b/common/amount.c index 71eee872c..e2a6e1299 100644 --- a/common/amount.c +++ b/common/amount.c @@ -283,6 +283,18 @@ WARN_UNUSED_RESULT bool amount_sat_sub_msat(struct amount_msat *val, return amount_msat_sub(val, msata, b); } +WARN_UNUSED_RESULT bool amount_msat_add_sat(struct amount_msat *val, + struct amount_msat a, + struct amount_sat b) +{ + struct amount_msat msatb; + + if (!amount_sat_to_msat(&msatb, b)) + return false; + + return amount_msat_add(val, a, msatb); +} + bool amount_sat_eq(struct amount_sat a, struct amount_sat b) { return a.satoshis == b.satoshis; diff --git a/common/amount.h b/common/amount.h index c401d272e..f5d9ef7f1 100644 --- a/common/amount.h +++ b/common/amount.h @@ -70,6 +70,9 @@ WARN_UNUSED_RESULT bool amount_sat_sub(struct amount_sat *val, WARN_UNUSED_RESULT bool amount_msat_sub_sat(struct amount_msat *val, struct amount_msat a, struct amount_sat b); +WARN_UNUSED_RESULT bool amount_msat_add_sat(struct amount_msat *val, + struct amount_msat a, + struct amount_sat b); WARN_UNUSED_RESULT bool amount_sat_sub_msat(struct amount_msat *val, struct amount_sat a, struct amount_msat b);