Merge rust-bitcoin/rust-bitcoin#2268: Add convenience constants to `Denomination`

22747149a9 Add convenience constants to `Denomination` (Martin Habovstiak)

Pull request description:

  `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.

ACKs for top commit:
  apoelstra:
    ACK 22747149a9
  tcharding:
    ACK 22747149a9

Tree-SHA512: fb49e61c28f5df14d5432a81ec946a367696fe36e96798d35831cd5cb88b813fe3aa1e7be201997956b4d4f6e5431e4da20d0d24e4d6c036aa199fc9b9c87da1
This commit is contained in:
Andrew Poelstra 2024-01-22 13:54:46 +00:00
commit ce1704a6e7
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 6 additions and 0 deletions

View File

@ -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 {