Skip to content

Commit

Permalink
Merge pull request #1453 from dorianvp/parse_address_default
Browse files Browse the repository at this point in the history
Add invalid value for parse_address command
  • Loading branch information
juanky201271 authored Oct 14, 2024
2 parents 5f8149c + 632bd3f commit 91ef21f
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,50 +227,57 @@ impl Command for ParseAddressCommand {
]
.iter()
.find_map(|chain| Address::decode(chain, args[0]).zip(Some(chain)))
.map(|(recipient_address, chain_name)| {
let chain_name_string = match chain_name {
crate::config::ChainType::Mainnet => "main",
crate::config::ChainType::Testnet => "test",
crate::config::ChainType::Regtest(_) => "regtest",
};
match recipient_address {
Address::Sapling(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "sapling",
},
Address::Transparent(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "transparent",
},
Address::Unified(ua) => {
let mut receivers_available = vec![];
if ua.orchard().is_some() {
receivers_available.push("orchard")
}
if ua.sapling().is_some() {
receivers_available.push("sapling")
}
if ua.transparent().is_some() {
receivers_available.push("transparent")
}
object! {
.map_or(
object! {
"status" => "Invalid address",
"chain_name" => json::JsonValue::Null,
"address_kind" => json::JsonValue::Null,
},
|(recipient_address, chain_name)| {
let chain_name_string = match chain_name {
crate::config::ChainType::Mainnet => "main",
crate::config::ChainType::Testnet => "test",
crate::config::ChainType::Regtest(_) => "regtest",
};
match recipient_address {
Address::Sapling(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "unified",
"receivers_available" => receivers_available,
}
}
Address::Tex(_) => {
object! {
"address_kind" => "sapling",
},
Address::Transparent(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "tex",
"address_kind" => "transparent",
},
Address::Unified(ua) => {
let mut receivers_available = vec![];
if ua.orchard().is_some() {
receivers_available.push("orchard")
}
if ua.sapling().is_some() {
receivers_available.push("sapling")
}
if ua.transparent().is_some() {
receivers_available.push("transparent")
}
object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "unified",
"receivers_available" => receivers_available,
}
}
Address::Tex(_) => {
object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "tex",
}
}
}
}
}),
},
),
4,
),
_ => self.help().to_string(),
Expand Down

0 comments on commit 91ef21f

Please sign in to comment.