Plumb GetTransactionCount through solana-wallet

This commit is contained in:
Tyera Eulberg 2018-10-25 11:20:17 -06:00 committed by Tyera Eulberg
parent 9314eea7e9
commit 02cfa76916
3 changed files with 10 additions and 14 deletions

View File

@ -35,19 +35,18 @@ pay_and_confirm() {
leader_readiness=false leader_readiness=false
timeout=60 timeout=60
while [ $timeout -gt 0 ] while [[ $timeout -gt 0 ]]; do
do
expected_output="Leader ready" expected_output="Leader ready"
exec 42>&1 exec 42>&1
output=$($solana_wallet "${entrypoint[@]}" leader-ready | tee >(cat - >&42)) output=$($solana_wallet "${entrypoint[@]}" get-transaction-count | tee >(cat - >&42))
if [[ "$output" =~ $expected_output ]]; then if [[ $output -gt 0 ]]; then
leader_readiness=true leader_readiness=true
break break
fi fi
sleep 2 sleep 2
(( timeout=timeout-2 )) (( timeout=timeout-2 ))
done done
if [ "$leader_readiness" = false ]; then if ! "$leader_readiness"; then
echo "Timed out waiting for leader" echo "Timed out waiting for leader"
exit 1 exit 1
fi fi

View File

@ -163,8 +163,8 @@ fn main() -> Result<(), Box<error::Error>> {
) )
// TODO: Add "loader" argument; current default is bpf_loader // TODO: Add "loader" argument; current default is bpf_loader
).subcommand( ).subcommand(
SubCommand::with_name("leader-ready") SubCommand::with_name("get-transaction-count")
.about("Determine leader readiness") .about("Get current transaction count")
).subcommand( ).subcommand(
SubCommand::with_name("pay") SubCommand::with_name("pay")
.about("Send a payment") .about("Send a payment")

View File

@ -42,7 +42,7 @@ pub enum WalletCommand {
Cancel(Pubkey), Cancel(Pubkey),
Confirm(Signature), Confirm(Signature),
Deploy(String), Deploy(String),
GetLeaderReadiness, GetTransactionCount,
// Pay(tokens, to, timestamp, timestamp_pubkey, witness(es), cancelable) // Pay(tokens, to, timestamp, timestamp_pubkey, witness(es), cancelable)
Pay( Pay(
i64, i64,
@ -146,7 +146,7 @@ pub fn parse_command(
.unwrap() .unwrap()
.to_string(), .to_string(),
)), )),
("leader-ready", Some(_matches)) => Ok(WalletCommand::GetLeaderReadiness), ("get-transaction-count", Some(_matches)) => Ok(WalletCommand::GetTransactionCount),
("pay", Some(pay_matches)) => { ("pay", Some(pay_matches)) => {
let tokens = pay_matches.value_of("tokens").unwrap().parse()?; let tokens = pay_matches.value_of("tokens").unwrap().parse()?;
let to = if pay_matches.is_present("to") { let to = if pay_matches.is_present("to") {
@ -454,15 +454,12 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<error::Error
"programId": format!("{}", program.pubkey()), "programId": format!("{}", program.pubkey()),
}).to_string()) }).to_string())
} }
WalletCommand::GetLeaderReadiness => { WalletCommand::GetTransactionCount => {
// TODO: This logic is currently only correct for initial network boot;
// needs updating for leader rotation
let transaction_count = RpcRequest::GetTransactionCount let transaction_count = RpcRequest::GetTransactionCount
.make_rpc_request(&config.rpc_addr, 1, None)? .make_rpc_request(&config.rpc_addr, 1, None)?
.as_u64(); .as_u64();
match transaction_count { match transaction_count {
Some(0) => Ok("Leader not ready".to_string()), Some(count) => Ok(count.to_string()),
Some(_) => Ok("Leader ready".to_string()),
None => Err(WalletError::RpcRequestError( None => Err(WalletError::RpcRequestError(
"Received result of an unexpected type".to_string(), "Received result of an unexpected type".to_string(),
))?, ))?,