diff --git a/scripts/wallet-sanity.sh b/scripts/wallet-sanity.sh index bfa20f392..676abe540 100755 --- a/scripts/wallet-sanity.sh +++ b/scripts/wallet-sanity.sh @@ -33,6 +33,25 @@ pay_and_confirm() { $solana_wallet "${entrypoint[@]}" confirm "$signature" } +leader_readiness=false +timeout=60 +while [ $timeout -gt 0 ] +do + expected_output="Leader ready" + exec 42>&1 + output=$($solana_wallet "${entrypoint[@]}" leader-ready | tee >(cat - >&42)) + if [[ "$output" =~ $expected_output ]]; then + leader_readiness=true + break + fi + sleep 2 + (( timeout=timeout-2 )) +done +if [ "$leader_readiness" = false ]; then + echo "Timed out waiting for leader" + exit 1 +fi + $solana_keygen $solana_wallet "${entrypoint[@]}" address check_balance_output "No account found" "Your balance is: 0" diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index 5c28f47b4..a330f30d4 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -162,6 +162,9 @@ fn main() -> Result<(), Box> { .help("/path/to/program.o"), ) // TODO: Add "loader" argument; current default is bpf_loader + ).subcommand( + SubCommand::with_name("leader-ready") + .about("Determine leader readiness") ).subcommand( SubCommand::with_name("pay") .about("Send a payment") diff --git a/src/wallet.rs b/src/wallet.rs index 88ddbbb61..d22225c2a 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -42,6 +42,7 @@ pub enum WalletCommand { Cancel(Pubkey), Confirm(Signature), Deploy(String), + GetLeaderReadiness, // Pay(tokens, to, timestamp, timestamp_pubkey, witness(es), cancelable) Pay( i64, @@ -145,6 +146,7 @@ pub fn parse_command( .unwrap() .to_string(), )), + ("leader-ready", Some(_matches)) => Ok(WalletCommand::GetLeaderReadiness), ("pay", Some(pay_matches)) => { let tokens = pay_matches.value_of("tokens").unwrap().parse()?; let to = if pay_matches.is_present("to") { @@ -452,6 +454,20 @@ pub fn process_command(config: &WalletConfig) -> Result { + // TODO: This logic is currently only correct for initial network boot; + // needs updating for leader rotation + let transaction_count = RpcRequest::GetTransactionCount + .make_rpc_request(&config.rpc_addr, 1, None)? + .as_u64(); + match transaction_count { + Some(0) => Ok("Leader not ready".to_string()), + Some(_) => Ok("Leader ready".to_string()), + None => Err(WalletError::RpcRequestError( + "Received result of an unexpected type".to_string(), + ))?, + } + } // If client has positive balance, pay tokens to another address WalletCommand::Pay(tokens, to, timestamp, timestamp_pubkey, ref witnesses, cancelable) => { let last_id = get_last_id(&config)?;