Skip to content

Commit

Permalink
[Bugfix] Detect network in display_addresses
Browse files Browse the repository at this point in the history
Previously it would always be regtest
  • Loading branch information
chris-belcher committed Jun 1, 2022
1 parent 9b9f6b8 commit 66b2f63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,27 @@ pub fn display_wallet_balance(wallet_file_name: &PathBuf, long_form: Option<bool
}
}

pub fn display_wallet_addresses(wallet_file_name: &PathBuf, types: DisplayAddressType) {
pub fn display_wallet_addresses(
wallet_file_name: &PathBuf,
types: DisplayAddressType,
network: Option<String>,
) {
let network = match get_bitcoin_rpc() {
Ok((_rpc, network)) => network,
Err(error) => {
if let Some(net_str) = network {
str_to_bitcoin_network(net_str.as_str())
} else {
panic!(
"network string not provided, and error connecting to bitcoin node: {:?}",
error
);
}
}
};
let wallet = match Wallet::load_wallet_from_file(
wallet_file_name,
Network::Regtest,
network,
WalletSyncAddressAmount::Normal,
) {
Ok(w) => w,
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ enum Subcommand {
/// "swap", "incomingcontract", "outgoingcontract", "contract", "fidelitybond".
/// Default is "all"
types: Option<DisplayAddressType>,
/// Network in question, options are "main", "test", "signet", "regtest". Only used
/// if configured bitcoin node RPC is unreachable
network: Option<String>,
},

/// Prints receive invoice.
Expand Down Expand Up @@ -135,10 +138,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Subcommand::WalletBalance { long_form } => {
teleport::display_wallet_balance(&args.wallet_file_name, long_form);
}
Subcommand::DisplayWalletAddresses { types } => {
Subcommand::DisplayWalletAddresses { types, network } => {
teleport::display_wallet_addresses(
&args.wallet_file_name,
types.unwrap_or(DisplayAddressType::All),
network,
);
}
Subcommand::GetReceiveInvoice => {
Expand Down

0 comments on commit 66b2f63

Please sign in to comment.