diff --git a/common/amount.c b/common/amount.c index e17a68044..ca48d86e0 100644 --- a/common/amount.c +++ b/common/amount.c @@ -507,6 +507,22 @@ struct amount_sat amount_sat_div(struct amount_sat sat, u64 div) return sat; } +bool amount_sat_mul(struct amount_sat *res, struct amount_sat sat, u64 mul) +{ + if ( mul_overflows_u64(sat.satoshis, mul)) + return false; + res->satoshis = sat.satoshis * mul; + return true; +} + +bool amount_msat_mul(struct amount_msat *res, struct amount_msat msat, u64 mul) +{ + if ( mul_overflows_u64(msat.millisatoshis, mul)) + return false; + res->millisatoshis = msat.millisatoshis * mul; + return true; +} + bool amount_msat_fee(struct amount_msat *fee, struct amount_msat amt, u32 fee_base_msat, diff --git a/common/amount.h b/common/amount.h index b16e92593..de3dd5a3a 100644 --- a/common/amount.h +++ b/common/amount.h @@ -92,6 +92,9 @@ WARN_UNUSED_RESULT bool amount_sat_scale(struct amount_sat *val, struct amount_msat amount_msat_div(struct amount_msat msat, u64 div); struct amount_sat amount_sat_div(struct amount_sat sat, u64 div); +bool amount_sat_mul(struct amount_sat *res, struct amount_sat sat, u64 mul); +bool amount_msat_mul(struct amount_msat *res, struct amount_msat msat, u64 mul); + /* Is a == b? */ bool amount_sat_eq(struct amount_sat a, struct amount_sat b); bool amount_msat_eq(struct amount_msat a, struct amount_msat b);