CLI: Factor out ProgramId moniker resolution
This commit is contained in:
committed by
mergify[bot]
parent
aa3aac766f
commit
84e7ba0b3f
@ -898,6 +898,15 @@ pub fn parse_command(
|
|||||||
|
|
||||||
pub type ProcessResult = Result<String, Box<dyn std::error::Error>>;
|
pub type ProcessResult = Result<String, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
|
fn resolve_derived_address_program_id(matches: &ArgMatches<'_>, arg_name: &str) -> Option<Pubkey> {
|
||||||
|
matches.value_of(arg_name).and_then(|v| match v {
|
||||||
|
"NONCE" => Some(system_program::id()),
|
||||||
|
"STAKE" => Some(solana_stake_program::id()),
|
||||||
|
"VOTE" => Some(solana_vote_program::id()),
|
||||||
|
_ => pubkey_of(matches, arg_name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_create_address_with_seed(
|
pub fn parse_create_address_with_seed(
|
||||||
matches: &ArgMatches<'_>,
|
matches: &ArgMatches<'_>,
|
||||||
default_signer: &DefaultSigner,
|
default_signer: &DefaultSigner,
|
||||||
@ -910,12 +919,7 @@ pub fn parse_create_address_with_seed(
|
|||||||
vec![default_signer.signer_from_path(matches, wallet_manager)?]
|
vec![default_signer.signer_from_path(matches, wallet_manager)?]
|
||||||
};
|
};
|
||||||
|
|
||||||
let program_id = match matches.value_of("program_id").unwrap() {
|
let program_id = resolve_derived_address_program_id(matches, "program_id").unwrap();
|
||||||
"NONCE" => system_program::id(),
|
|
||||||
"STAKE" => solana_stake_program::id(),
|
|
||||||
"VOTE" => solana_vote_program::id(),
|
|
||||||
_ => pubkey_of(matches, "program_id").unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let seed = matches.value_of("seed").unwrap().to_string();
|
let seed = matches.value_of("seed").unwrap().to_string();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user