Rewrite Invoice's interface in terms of msats

InvoiceBuilder's interface was changed recently to work in terms of
msats. Update Invoice's interface to return the amount in msats, too,
and make amount_pico_btc private.
This commit is contained in:
Jeffrey Czyz 2021-10-04 09:20:49 -05:00
parent 73f601fd3d
commit 5feb4dc9c4
No known key found for this signature in database
GPG key ID: 3A4E08275D5E96D2

View file

@ -1219,8 +1219,13 @@ impl Invoice {
self.signed_invoice.currency() self.signed_invoice.currency()
} }
/// Returns the amount if specified in the invoice as millisatoshis.
pub fn amount_milli_satoshis(&self) -> Option<u64> {
self.signed_invoice.amount_pico_btc().map(|v| v / 10)
}
/// Returns the amount if specified in the invoice as pico <currency>. /// Returns the amount if specified in the invoice as pico <currency>.
pub fn amount_pico_btc(&self) -> Option<u64> { fn amount_pico_btc(&self) -> Option<u64> {
self.signed_invoice.amount_pico_btc() self.signed_invoice.amount_pico_btc()
} }
} }
@ -1867,6 +1872,7 @@ mod test {
assert!(invoice.check_signature().is_ok()); assert!(invoice.check_signature().is_ok());
assert_eq!(invoice.tagged_fields().count(), 10); assert_eq!(invoice.tagged_fields().count(), 10);
assert_eq!(invoice.amount_milli_satoshis(), Some(123));
assert_eq!(invoice.amount_pico_btc(), Some(1230)); assert_eq!(invoice.amount_pico_btc(), Some(1230));
assert_eq!(invoice.currency(), Currency::BitcoinTestnet); assert_eq!(invoice.currency(), Currency::BitcoinTestnet);
assert_eq!( assert_eq!(