solana_clap_utils::keypair

Function pubkey_from_path

Source
pub fn pubkey_from_path(
    matches: &ArgMatches<'_>,
    path: &str,
    keypair_name: &str,
    wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
) -> Result<Pubkey, Box<dyn Error>>
Expand description

Loads the pubkey of a Signer from one of several possible sources.

The path is not strictly a file system path, but is interpreted as various types of signing source, depending on its format, one of which is a path to a keypair file. Some sources may require user interaction in the course of calling this function.

The only difference between this function and signer_from_path is in the case of a “pubkey” path: this function does not require that accompanying command line arguments contain an offline signature.

See signer_from_path for full documentation of how this function interprets its arguments.

§Examples

use clap::{App, Arg, value_t_or_exit};
use solana_clap_utils::keypair::pubkey_from_path;

let clap_app = App::new("my-program")
    // The argument we'll parse as a signer "path"
    .arg(Arg::with_name("keypair")
        .required(true)
        .help("The default signer"));

let clap_matches = clap_app.get_matches();
let keypair_str = value_t_or_exit!(clap_matches, "keypair", String);
let mut wallet_manager = None;
let pubkey = pubkey_from_path(
    &clap_matches,
    &keypair_str,
    "keypair",
    &mut wallet_manager,
)?;