Skip to content

Commit

Permalink
start helperizing parse_address
Browse files Browse the repository at this point in the history
  • Loading branch information
zancas committed Jan 17, 2025
1 parent 576c0a4 commit 399a1b6
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl Command for ParseAddressCommand {
indoc! {r#"
Parse an address
Usage:
parse_address [address]
parse_address <address> [orchard]
Example
parse_address tmSwk8bjXdCgBvpS8Kybk5nUyE21QFcDqre
Expand All @@ -228,18 +228,28 @@ impl Command for ParseAddressCommand {
}

fn exec(&self, args: &[&str], _lightclient: &LightClient) -> String {
if args.len() > 2 {
return self.help().to_string();
}
fn make_decoded_chain_pair(
address: &str,
) -> Option<(
zcash_client_backend::address::Address,
crate::config::ChainType,
)> {
[
crate::config::ChainType::Mainnet,
crate::config::ChainType::Testnet,
crate::config::ChainType::Regtest(
crate::config::RegtestNetwork::all_upgrades_active(),
),
]
.iter()
.find_map(|chain| Address::decode(chain, address).zip(Some(*chain)))
}
match args.len() {
1 => json::stringify_pretty(
[
crate::config::ChainType::Mainnet,
crate::config::ChainType::Testnet,
crate::config::ChainType::Regtest(
crate::config::RegtestNetwork::all_upgrades_active(),
),
]
.iter()
.find_map(|chain| Address::decode(chain, args[0]).zip(Some(chain)))
.map_or(
make_decoded_chain_pair(args[0]).map_or(
object! {
"status" => "Invalid address",
"chain_name" => json::JsonValue::Null,
Expand Down

0 comments on commit 399a1b6

Please sign in to comment.