@@ -390,6 +390,29 @@ pub enum Currency {
390
390
Signet ,
391
391
}
392
392
393
+ impl From < Network > for Currency {
394
+ fn from ( network : Network ) -> Self {
395
+ match network {
396
+ Network :: Bitcoin => Currency :: Bitcoin ,
397
+ Network :: Testnet => Currency :: BitcoinTestnet ,
398
+ Network :: Regtest => Currency :: Regtest ,
399
+ Network :: Signet => Currency :: Signet ,
400
+ }
401
+ }
402
+ }
403
+
404
+ impl From < Currency > for Network {
405
+ fn from ( currency : Currency ) -> Self {
406
+ match currency {
407
+ Currency :: Bitcoin => Network :: Bitcoin ,
408
+ Currency :: BitcoinTestnet => Network :: Testnet ,
409
+ Currency :: Regtest => Network :: Regtest ,
410
+ Currency :: Simnet => Network :: Regtest ,
411
+ Currency :: Signet => Network :: Signet ,
412
+ }
413
+ }
414
+ }
415
+
393
416
/// Tagged field which may have an unknown tag
394
417
///
395
418
/// This is not exported to bindings users as we don't currently support TaggedField
@@ -1303,14 +1326,6 @@ impl Invoice {
1303
1326
/// Returns a list of all fallback addresses as [`Address`]es
1304
1327
pub fn fallback_addresses ( & self ) -> Vec < Address > {
1305
1328
self . fallbacks ( ) . iter ( ) . map ( |fallback| {
1306
- let network = match self . currency ( ) {
1307
- Currency :: Bitcoin => Network :: Bitcoin ,
1308
- Currency :: BitcoinTestnet => Network :: Testnet ,
1309
- Currency :: Regtest => Network :: Regtest ,
1310
- Currency :: Simnet => Network :: Regtest ,
1311
- Currency :: Signet => Network :: Signet ,
1312
- } ;
1313
-
1314
1329
let payload = match fallback {
1315
1330
Fallback :: SegWitProgram { version, program } => {
1316
1331
Payload :: WitnessProgram { version : * version, program : program. to_vec ( ) }
@@ -1323,7 +1338,7 @@ impl Invoice {
1323
1338
}
1324
1339
} ;
1325
1340
1326
- Address { payload, network }
1341
+ Address { payload, network : self . network ( ) }
1327
1342
} ) . collect ( )
1328
1343
}
1329
1344
@@ -1344,6 +1359,11 @@ impl Invoice {
1344
1359
self . signed_invoice . currency ( )
1345
1360
}
1346
1361
1362
+ /// Returns the network for which the invoice was issued
1363
+ pub fn network ( & self ) -> Network {
1364
+ self . signed_invoice . currency ( ) . into ( )
1365
+ }
1366
+
1347
1367
/// Returns the amount if specified in the invoice as millisatoshis.
1348
1368
pub fn amount_milli_satoshis ( & self ) -> Option < u64 > {
1349
1369
self . signed_invoice . amount_pico_btc ( ) . map ( |v| v / 10 )
0 commit comments