Skip to content

Commit

Permalink
Fix funding network test for testnets
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Jun 16, 2022
1 parent 522795d commit 11db1a7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lnpd/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,20 @@ impl FundingWallet {
fs::OpenOptions::new().read(true).write(true).create(false).open(wallet_path)?;
let wallet_data = WalletData::strict_decode(&wallet_file)?;

let network = chain.try_into()?;
if DescriptorExt::<bitcoin::PublicKey>::network(&wallet_data.descriptor)? != network {
let target_network = chain.try_into()?;
let wallet_network = DescriptorExt::<bitcoin::PublicKey>::network(&wallet_data.descriptor)?;

let is_correct_network = match (wallet_network, target_network) {
(Network::Bitcoin, Network::Bitcoin) => true,
(Network::Testnet, Network::Testnet | Network::Regtest | Network::Signet) => true,
_ => false,
};

if !is_correct_network {
return Err(Error::ChainMismatch);
}

FundingWallet::init(network, wallet_data, wallet_file, electrum_url)
FundingWallet::init(target_network, wallet_data, wallet_file, electrum_url)
}

fn init(
Expand Down

0 comments on commit 11db1a7

Please sign in to comment.