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

Commit

Permalink
Refactor SignerSource to expose DerivationPath to other kinds of sign…
Browse files Browse the repository at this point in the history
…ers (backport #16933) (#16940)

* Refactor SignerSource to expose DerivationPath to other kinds of signers (#16933)

* One use statement

* Add stdin uri scheme

* Convert parse_signer_source to return Result

* A-Z deps

* Convert Usb data to Locator

* Pull DerivationPath out of Locator

* Wrap SignerSource to share derivation_path

* Review comments

* Check Filepath existence, readability in parse_signer_source

(cherry picked from commit d6f30b7)

# Conflicts:
#	Cargo.lock
#	clap-utils/src/memo.rs
#	remote-wallet/src/locator.rs
#	sdk/Cargo.toml

* Fix conflicts

* Fix legacy compile test

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
  • Loading branch information
3 people authored Apr 29, 2021
1 parent 9cca790 commit 41ab35f
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 442 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions clap-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ uriparse = "0.6.3"
url = "2.1.0"
chrono = "0.4"

[dev-dependencies]
tempfile = "3.1.0"

[lib]
name = "solana_clap_utils"

Expand Down
6 changes: 4 additions & 2 deletions clap-utils/src/fee_payer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{input_validators, ArgConstant};
use clap::Arg;
use {
crate::{input_validators, ArgConstant},
clap::Arg,
};

pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant {
name: "fee_payer",
Expand Down
32 changes: 17 additions & 15 deletions clap-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use crate::keypair::{
keypair_from_seed_phrase, pubkey_from_path, resolve_signer_from_path, signer_from_path,
ASK_KEYWORD, SKIP_SEED_PHRASE_VALIDATION_ARG,
use {
crate::keypair::{
keypair_from_seed_phrase, pubkey_from_path, resolve_signer_from_path, signer_from_path,
ASK_KEYWORD, SKIP_SEED_PHRASE_VALIDATION_ARG,
},
chrono::DateTime,
clap::ArgMatches,
solana_remote_wallet::remote_wallet::RemoteWalletManager,
solana_sdk::{
clock::UnixTimestamp,
commitment_config::CommitmentConfig,
genesis_config::ClusterType,
native_token::sol_to_lamports,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair, Signature, Signer},
},
std::{str::FromStr, sync::Arc},
};
use chrono::DateTime;
use clap::ArgMatches;
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::{
clock::UnixTimestamp,
commitment_config::CommitmentConfig,
genesis_config::ClusterType,
native_token::sol_to_lamports,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair, Signature, Signer},
};
use std::{str::FromStr, sync::Arc};

// Return parsed values from matches at `name`
pub fn values_of<T>(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<T>>
Expand Down
27 changes: 16 additions & 11 deletions clap-utils/src/input_validators.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::keypair::{parse_signer_source, SignerSource, ASK_KEYWORD};
use chrono::DateTime;
use solana_sdk::{
clock::{Epoch, Slot},
hash::Hash,
pubkey::{Pubkey, MAX_SEED_LEN},
signature::{read_keypair_file, Signature},
use {
crate::keypair::{parse_signer_source, SignerSourceKind, ASK_KEYWORD},
chrono::DateTime,
solana_sdk::{
clock::{Epoch, Slot},
hash::Hash,
pubkey::{Pubkey, MAX_SEED_LEN},
signature::{read_keypair_file, Signature},
},
std::fmt::Display,
std::str::FromStr,
};
use std::fmt::Display;
use std::str::FromStr;

fn is_parsable_generic<U, T>(string: T) -> Result<(), String>
where
Expand Down Expand Up @@ -108,8 +110,11 @@ pub fn is_valid_pubkey<T>(string: T) -> Result<(), String>
where
T: AsRef<str> + Display,
{
match parse_signer_source(string.as_ref()) {
SignerSource::Filepath(path) => is_keypair(path),
match parse_signer_source(string.as_ref())
.map_err(|err| format!("{}", err))?
.kind
{
SignerSourceKind::Filepath(path) => is_keypair(path),
_ => Ok(()),
}
}
Expand Down
Loading

0 comments on commit 41ab35f

Please sign in to comment.