[solana-test-validator] add support for keypair file parsing for --bpf-program address argument

This commit is contained in:
Paul Schaaf
2021-10-25 18:23:53 +02:00
committed by Michael Vines
parent 337b94b3bc
commit 58aa2b964b

View File

@@ -156,13 +156,14 @@ fn main() {
.arg( .arg(
Arg::with_name("bpf_program") Arg::with_name("bpf_program")
.long("bpf-program") .long("bpf-program")
.value_name("ADDRESS BPF_PROGRAM.SO") .value_name("ADDRESS_OR_PATH BPF_PROGRAM.SO")
.takes_value(true) .takes_value(true)
.number_of_values(2) .number_of_values(2)
.multiple(true) .multiple(true)
.help( .help(
"Add a BPF program to the genesis configuration. \ "Add a BPF program to the genesis configuration. \
If the ledger already exists then this parameter is silently ignored", If the ledger already exists then this parameter is silently ignored. \
First argument can be a public key or path to file that can be parsed as a keypair",
), ),
) )
.arg( .arg(
@@ -404,10 +405,13 @@ fn main() {
for address_program in values.chunks(2) { for address_program in values.chunks(2) {
match address_program { match address_program {
[address, program] => { [address, program] => {
let address = address.parse::<Pubkey>().unwrap_or_else(|err| { let address = address
println!("Error: invalid address {}: {}", address, err); .parse::<Pubkey>()
exit(1); .or_else(|_| read_keypair_file(address).map(|keypair| keypair.pubkey()))
}); .unwrap_or_else(|err| {
println!("Error: invalid address {}: {}", address, err);
exit(1);
});
let program_path = PathBuf::from(program); let program_path = PathBuf::from(program);
if !program_path.exists() { if !program_path.exists() {