Drop panic if `rust-bitcoin` adds a new `Network`
authorMatt Corallo <git@bluematt.me>
Sun, 26 Nov 2023 19:07:10 +0000 (19:07 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 26 Nov 2023 19:07:10 +0000 (19:07 +0000)
`rust-bitcoin` 0.30 added `#[non_exhaustive]` to the `Network`
enum, allowing them to "add support" for a new network type without
a major version change in the future. When upgrading, we added a
simple `unreachable` for the general match arm, which would break
in a minor version change of `rust-bitcoin`.

While it seems [possible rust-bitcoin will change
this](https://github.com/rust-bitcoin/rust-bitcoin/issues/2225),
we still shouldn't ba panicking, which we drop here in favor of a
`debug_assert`ion, and a default value.

lightning-invoice/src/lib.rs

index d30fb638d340eea056ce3a7b83a92c713bcf30ec..d87c6c89372080b5696fd754f35fb8eeddf1c75d 100644 (file)
@@ -407,7 +407,10 @@ impl From<Network> for Currency {
                        Network::Testnet => Currency::BitcoinTestnet,
                        Network::Regtest => Currency::Regtest,
                        Network::Signet => Currency::Signet,
-                       _ => unreachable!(),
+                       _ => {
+                               debug_assert!(false, "Need to handle new rust-bitcoin network type");
+                               Currency::Regtest
+                       },
                }
        }
 }