pub struct DefaultSigner {
    pub arg_name: String,
    pub path: String,
    /* private fields */
}
Expand description

A command line argument that loads a default signer in absence of other signers.

This type manages a default signing source which may be overridden by other signing sources via its generate_unique_signers method.

path is a signing source as documented by signer_from_path, and arg_name is the name of its clap command line argument, which is passed to signer_from_path as its keypair_name argument.

Fields§

§arg_name: String

The name of the signers command line argument.

§path: String

The signing source.

Implementations§

source§

impl DefaultSigner

source

pub fn new<AN: AsRef<str>, P: AsRef<str>>(arg_name: AN, path: P) -> Self

Create a new DefaultSigner.

path is a signing source as documented by signer_from_path, and arg_name is the name of its clap command line argument, which is passed to signer_from_path as its keypair_name argument.

Examples
use clap::{App, Arg, value_t_or_exit};
use safecoin_clap_utils::keypair::DefaultSigner;
use safecoin_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 default_signer = DefaultSigner::new("keypair", &keypair_str);
assert_eq!(default_signer.path, keypair_str);
source

pub fn generate_unique_signers( &self, bulk_signers: Vec<Option<Box<dyn Signer>>>, matches: &ArgMatches<'_>, wallet_manager: &mut Option<Arc<RemoteWalletManager>> ) -> Result<CliSignerInfo, Box<dyn Error>>

Generate a unique set of signers, possibly excluding this default signer.

This function allows a command line application to have a default signer, perhaps representing a default wallet, but to override that signer and instead sign with one or more other signers.

bulk_signers is a vector of signers, all of which are optional. If any of those signers is None, then the default signer will be loaded; if all of those signers are Some, then the default signer will not be loaded.

The returned value includes all of the bulk_signers that were not None, and maybe the default signer, if it was loaded.

Examples
use clap::{App, Arg, value_t_or_exit};
use safecoin_clap_utils::keypair::{DefaultSigner, signer_from_path};
use safecoin_clap_utils::offline::OfflineArgs;
use solana_sdk::signer::Signer;

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"))
    .arg(Arg::with_name("payer")
        .long("payer")
        .help("The account paying for the transaction"))
    .offline_args();

let mut wallet_manager = None;

let clap_matches = clap_app.get_matches();
let keypair_str = value_t_or_exit!(clap_matches, "keypair", String);
let maybe_payer = clap_matches.value_of("payer");

let default_signer = DefaultSigner::new("keypair", &keypair_str);
let maybe_payer_signer = maybe_payer.map(|payer| {
    signer_from_path(&clap_matches, payer, "payer", &mut wallet_manager)
}).transpose()?;
let bulk_signers = vec![maybe_payer_signer];

let unique_signers = default_signer.generate_unique_signers(
    bulk_signers,
    &clap_matches,
    &mut wallet_manager,
)?;
source

pub fn signer_from_path( &self, matches: &ArgMatches<'_>, wallet_manager: &mut Option<Arc<RemoteWalletManager>> ) -> Result<Box<dyn Signer>, Box<dyn Error>>

Loads the default 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 simply delegates to the signer_from_path free function, passing it the DefaultSigners path and arg_name fields as the path and keypair_name arguments.

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

Examples
use clap::{App, Arg, value_t_or_exit};
use safecoin_clap_utils::keypair::DefaultSigner;
use safecoin_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 default_signer = DefaultSigner::new("keypair", &keypair_str);
let mut wallet_manager = None;

let signer = default_signer.signer_from_path(
    &clap_matches,
    &mut wallet_manager,
)?;
source

pub fn signer_from_path_with_config( &self, matches: &ArgMatches<'_>, wallet_manager: &mut Option<Arc<RemoteWalletManager>>, config: &SignerFromPathConfig ) -> Result<Box<dyn Signer>, Box<dyn Error>>

Loads the default 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 simply delegates to the signer_from_path_with_config free function, passing it the DefaultSigners path and arg_name fields as the path and keypair_name arguments.

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

Examples
use clap::{App, Arg, value_t_or_exit};
use safecoin_clap_utils::keypair::{SignerFromPathConfig, DefaultSigner};
use safecoin_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 default_signer = DefaultSigner::new("keypair", &keypair_str);
let mut wallet_manager = None;

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

let signer = default_signer.signer_from_path_with_config(
    &clap_matches,
    &mut wallet_manager,
    &config,
)?;

Trait Implementations§

source§

impl Debug for DefaultSigner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for DefaultSigner

source§

fn default() -> DefaultSigner

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> AbiExample for T

§

default fn example() -> T

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more