From 22747149a9040c075e3f1f4eec8500f31b515659 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Fri, 8 Dec 2023 20:45:03 +0100 Subject: [PATCH] Add convenience constants to `Denomination` `Denomination::Bitcoin` and `Denomination::Satoshi` are often used, especially in test code so this change adds `BTC` and `SAT` - short, readable constants. Notably this doesn't add the other constants as that would lead to either unidiomatic names or confusing casing (MSAT meaning millisat not megasat) and they are not used that much anyway. --- units/src/amount.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/units/src/amount.rs b/units/src/amount.rs index 9feba679..b1b34c51 100644 --- a/units/src/amount.rs +++ b/units/src/amount.rs @@ -59,6 +59,12 @@ pub enum Denomination { } impl Denomination { + /// Convenience alias for `Denomination::Bitcoin`. + pub const BTC: Self = Denomination::Bitcoin; + + /// Convenience alias for `Denomination::Satoshi`. + pub const SAT: Self = Denomination::Satoshi; + /// The number of decimal places more than a satoshi. fn precision(self) -> i8 { match self {