pcli/command/view/
noble_address.rs

1use anyhow::Result;
2use rand_core::OsRng;
3
4use penumbra_sdk_keys::{Address, FullViewingKey};
5
6#[derive(Debug, clap::Parser)]
7pub struct NobleAddressCmd {
8    /// The address to provide information about
9    #[clap(default_value = "0")]
10    address_or_index: String,
11    /// Generate an ephemeral address instead of an indexed one.
12    #[clap(short, long)]
13    ephemeral: bool,
14    /// The Noble IBC channel to use for forwarding.
15    #[clap(long)]
16    channel: String,
17}
18
19impl NobleAddressCmd {
20    /// Determine if this command requires a network sync before it executes.
21    pub fn offline(&self) -> bool {
22        true
23    }
24
25    pub fn exec(&self, fvk: &FullViewingKey) -> Result<()> {
26        let index: Result<u32, _> = self.address_or_index.parse();
27
28        let address = if let Ok(index) = index {
29            // address index provided
30            let (address, _dtk) = match self.ephemeral {
31                false => fvk.incoming().payment_address(index.into()),
32                true => fvk.incoming().ephemeral_address(OsRng, index.into()),
33            };
34
35            address
36        } else {
37            // address or nothing provided
38            let address: Address = self
39                .address_or_index
40                .parse()
41                .map_err(|_| anyhow::anyhow!("Provided address is invalid."))?;
42
43            address
44        };
45
46        let noble_address = address.noble_forwarding_address(&self.channel);
47
48        println!("{}", noble_address);
49
50        Ok(())
51    }
52}