solana_clap_utils::keypair

Function signer_from_path_with_config

source
pub fn signer_from_path_with_config(
    matches: &ArgMatches<'_>,
    path: &str,
    keypair_name: &str,
    wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
    config: &SignerFromPathConfig,
) -> Result<Box<dyn Signer>, Box<dyn Error>>
Expand description

Loads 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.

This is the same as signer_from_path except that it additionaolly accepts a SignerFromPathConfig argument.

If the allow_null_signer field of config is true, then pubkey signers are allowed to have zero associated signatures via additional “signer” command line arguments. It the same effect as if the “sign_only” clap argument is present.

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

§Examples

This shows a reasonable way to set up clap to parse all possible signer sources. Note the use of the OfflineArgs::offline_args method to add correct clap definitions of the --signer and --sign-only arguments, as required by the base-58 pubkey offline signing method.

use clap::{App, Arg, value_t_or_exit};
use solana_clap_utils::keypair::{signer_from_path_with_config, SignerFromPathConfig};
use solana_clap_utils::offline::OfflineArgs;

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"))
    .offline_args();

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

// Allow pubkey signers without accompanying signatures
let config = SignerFromPathConfig {
    allow_null_signer: true,
};

let signer = signer_from_path_with_config(
    &clap_matches,
    &keypair_str,
    "keypair",
    &mut wallet_manager,
    &config,
)?;