Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
program: --sign-only (offline signing)
Browse files Browse the repository at this point in the history
  • Loading branch information
norwnd committed Oct 25, 2023
1 parent a60d185 commit 2c57502
Show file tree
Hide file tree
Showing 7 changed files with 608 additions and 321 deletions.
26 changes: 24 additions & 2 deletions clap-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use {
crate::keypair::{
keypair_from_seed_phrase, pubkey_from_path, resolve_signer_from_path, signer_from_path,
ASK_KEYWORD, SKIP_SEED_PHRASE_VALIDATION_ARG,
signer_from_path_with_config, SignerFromPathConfig, ASK_KEYWORD,
SKIP_SEED_PHRASE_VALIDATION_ARG,
},
chrono::DateTime,
clap::ArgMatches,
Expand Down Expand Up @@ -118,7 +119,7 @@ pub fn pubkeys_sigs_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<(Pubk
})
}

// Return a signer from matches at `name`
// Return a signer from matches at `name` (returns error if signer is NullSigner).
#[allow(clippy::type_complexity)]
pub fn signer_of(
matches: &ArgMatches<'_>,
Expand All @@ -134,6 +135,27 @@ pub fn signer_of(
}
}

// Return a signer from matches at `name` (returns NullSigner and doesn't error).
#[allow(clippy::type_complexity)]
pub fn signer_of_allow_null_signer(
matches: &ArgMatches<'_>,
name: &str,
wallet_manager: &mut Option<Rc<RemoteWalletManager>>,
) -> Result<(Option<Box<dyn Signer>>, Option<Pubkey>), Box<dyn std::error::Error>> {
if let Some(location) = matches.value_of(name) {
// Allow pubkey signers without accompanying signatures
let config = SignerFromPathConfig {
allow_null_signer: true,
};
let signer =
signer_from_path_with_config(matches, location, name, wallet_manager, &config)?;
let signer_pubkey = signer.pubkey();
Ok((Some(signer), Some(signer_pubkey)))
} else {
Ok((None, None))
}
}

pub fn pubkey_of_signer(
matches: &ArgMatches<'_>,
name: &str,
Expand Down
1 change: 1 addition & 0 deletions clap-utils/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl SignOnly {
}
pub type CliSigners = Vec<Box<dyn Signer>>;
pub type SignerIndex = usize;
#[derive(Debug)]
pub struct CliSignerInfo {
pub signers: CliSigners,
}
Expand Down
14 changes: 13 additions & 1 deletion cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2090,14 +2090,26 @@ impl fmt::Display for CliProgramId {
#[serde(rename_all = "camelCase")]
pub struct CliProgramBuffer {
pub buffer: String,
pub program_data_max_len: usize,
pub min_rent_exempt_program_balance: u64,
}

impl QuietDisplay for CliProgramBuffer {}
impl VerboseDisplay for CliProgramBuffer {}

impl fmt::Display for CliProgramBuffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln_name_value(f, "Buffer:", &self.buffer)
writeln_name_value(f, "Buffer:", &self.buffer)?;
writeln_name_value(
f,
"Program data max length:",
&format!("{:?}", self.program_data_max_len),
)?;
writeln_name_value(
f,
"Min rent-exempt program balance:",
&format!("{:?}", self.min_rent_exempt_program_balance),
)
}
}

Expand Down
Loading

0 comments on commit 2c57502

Please sign in to comment.