pcli/command/view/
address.rsuse anyhow::Result;
use base64::Engine;
use rand_core::OsRng;
use std::str::FromStr;
use penumbra_keys::{keys::AddressIndex, Address, FullViewingKey};
#[derive(Debug, clap::Parser)]
pub struct AddressCmd {
#[clap(default_value = "0")]
address_or_index: String,
#[clap(short, long)]
ephemeral: bool,
#[clap(long)]
base64: bool,
#[clap(long)]
transparent: bool,
#[clap(long)]
fvk: bool,
#[clap(long)]
from_fvk: Option<String>,
}
impl AddressCmd {
pub fn offline(&self) -> bool {
true
}
pub fn exec(&self, fvk: &FullViewingKey) -> Result<()> {
let index: Result<u32, _> = self.address_or_index.parse();
if let Ok(index) = index {
let (address, _dtk) = match self.ephemeral {
false => fvk.incoming().payment_address(index.into()),
true => fvk.incoming().ephemeral_address(OsRng, index.into()),
};
if self.base64 {
println!(
"{}",
base64::engine::general_purpose::STANDARD.encode(address.to_vec()),
);
} else if self.transparent {
if index != 0 {
return Err(anyhow::anyhow!(
"warning: index must be 0 to use transparent address encoding"
));
}
println!("{}", fvk.incoming().transparent_address());
} else {
if self.fvk {
eprintln!("🔥 CAUTION: POSSESSION OF THE FOLLOWING FULL VIEWING KEY WILL");
eprintln!("🔥 PROVIDE VISIBILITY TO ALL ACTIVITY ON ITS ASSOCIATED ACCOUNTS.");
eprintln!("🔥 DISTRIBUTE WITH CARE!");
eprintln!("");
println!("{}", fvk);
} else if let Some(fvk) = &self.from_fvk {
let (address, _) = FullViewingKey::payment_address(
&FullViewingKey::from_str(&fvk[..])?,
AddressIndex::new(0),
);
println!("{}", address);
} else {
println!("{}", address);
}
};
} else {
let address: Address = self
.address_or_index
.parse()
.map_err(|_| anyhow::anyhow!("Provided address is invalid."))?;
match fvk.address_index(&address) {
Some(address_index) => println!(
"Address is viewable with this full viewing key. Account index is {0}. {1}",
address_index.account,
match address_index.randomizer != [0u8; 12] {
true => "Address is an IBC deposit address.",
false => "",
}
),
None => println!("Address is not viewable with this full viewing key."),
}
}
Ok(())
}
}