Skip to content

Commit

Permalink
CLI: Print address ephemeral keypair seed phrase to stderr on deploy …
Browse files Browse the repository at this point in the history
…failure

(cherry picked from commit 2905ccc)

# Conflicts:
#	cli/Cargo.toml
#	cli/src/cli.rs
  • Loading branch information
t-nelson committed Oct 21, 2020
1 parent 63fe350 commit e64ad8d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ solana-transaction-status = { path = "../transaction-status", version = "1.3.19"
solana-version = { path = "../version", version = "1.3.19" }
solana-vote-program = { path = "../programs/vote", version = "1.3.19" }
solana-vote-signer = { path = "../vote-signer", version = "1.3.19" }
tiny-bip39 = "0.7.0"
thiserror = "1.0.20"
url = "2.1.1"

Expand Down
48 changes: 45 additions & 3 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
checks::*, cluster_query::*, feature::*, inflation::*, nonce::*, spend_utils::*, stake::*,
validator_info::*, vote::*,
};
use bip39::{Language, Mnemonic, MnemonicType, Seed};
use chrono::prelude::*;
use clap::{value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand};
use log::*;
Expand Down Expand Up @@ -51,7 +52,7 @@ use solana_sdk::{
loader_instruction,
message::Message,
pubkey::{Pubkey, MAX_SEED_LEN},
signature::{Keypair, Signature, Signer, SignerError},
signature::{keypair_from_seed, Keypair, Signature, Signer, SignerError},
signers::Signers,
system_instruction::{self, SystemError},
system_program,
Expand Down Expand Up @@ -1240,7 +1241,48 @@ fn process_deploy(
address: Option<SignerIndex>,
use_deprecated_loader: bool,
) -> ProcessResult {
let new_keypair = Keypair::new(); // Create ephemeral keypair to use for program address, if not provided
const WORDS: usize = 12;
// Create ephemeral keypair to use for program address, if not provided
let mnemonic = Mnemonic::new(MnemonicType::for_word_count(WORDS)?, Language::English);
let seed = Seed::new(&mnemonic, "");
let new_keypair = keypair_from_seed(seed.as_bytes())?;

let result = do_process_deploy(
rpc_client,
config,
program_location,
address,
use_deprecated_loader,
new_keypair,
);

if result.is_err() && address.is_none() {
let phrase: &str = mnemonic.phrase();
let divider = String::from_utf8(vec![b'='; phrase.len()]).unwrap();
eprintln!(
"{}\nTo reuse this address, recover the ephemeral keypair file with",
divider
);
eprintln!(
"`solana-keygen recover` and the following {}-word seed phrase,",
WORDS
);
eprintln!(
"then pass it as the [ADDRESS_SIGNER] argument to `solana deploy ...`\n{}\n{}\n{}",
divider, phrase, divider
);
}
result
}

fn do_process_deploy(
rpc_client: &RpcClient,
config: &CliConfig,
program_location: &str,
address: Option<SignerIndex>,
use_deprecated_loader: bool,
new_keypair: Keypair,
) -> ProcessResult {
let program_id = if let Some(i) = address {
config.signers[i]
} else {
Expand Down Expand Up @@ -2617,7 +2659,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
.arg(
Arg::with_name("address_signer")
.index(2)
.value_name("SIGNER_KEYPAIR")
.value_name("ADDRESS_SIGNER")
.takes_value(true)
.validator(is_valid_signer)
.help("The signer for the desired address of the program [default: new random address]")
Expand Down

0 comments on commit e64ad8d

Please sign in to comment.