address review comments

This commit is contained in:
Pankaj Garg 2019-03-01 17:16:49 -08:00 committed by Grimes
parent ae557104a5
commit 6b83ce4937
1 changed files with 13 additions and 55 deletions

View File

@ -86,7 +86,7 @@ impl LocalCluster {
&ledger_path, &ledger_path,
voting_keypair, voting_keypair,
Some(&leader_node_info), Some(&leader_node_info),
&FullnodeConfig::default(), &fullnode_config,
); );
let (thread, exit, _) = validator_server.start(None); let (thread, exit, _) = validator_server.start(None);
fullnode_hdls.push((thread, exit)); fullnode_hdls.push((thread, exit));
@ -143,69 +143,27 @@ impl LocalCluster {
from_account: &Arc<Keypair>, from_account: &Arc<Keypair>,
amount: u64, amount: u64,
) -> Result<()> { ) -> Result<()> {
let pubkey = from_account.pubkey();
let node_balance = client.poll_get_balance(&pubkey)?;
info!("node balance is {}", node_balance);
if node_balance < 1 {
return Err(Error::new(
ErrorKind::Other,
"insufficient tokens, one token required",
));
}
// Create the vote account if necessary // Create the vote account if necessary
if client.poll_get_balance(&vote_account).unwrap_or(0) == 0 { if client.poll_get_balance(&vote_account).unwrap_or(0) == 0 {
// Need at least two tokens as one token will be spent on a vote_account_new() transaction let mut transaction = VoteTransaction::fund_staking_account(
if node_balance < 2 {
error!("insufficient tokens, two tokens required");
return Err(Error::new(
ErrorKind::Other,
"insufficient tokens, two tokens required",
));
}
loop {
let last_id = client.get_last_id();
info!("create_and_fund_vote_account last_id={:?}", last_id);
let transaction = VoteTransaction::fund_staking_account(
from_account, from_account,
vote_account, vote_account,
last_id, client.get_last_id(),
amount, amount,
1, 1,
); );
match client.transfer_signed(&transaction) { client
Ok(signature) => { .retry_transfer(&from_account, &mut transaction, 5)
match client.poll_for_signature(&signature) { .expect("client transfer");
Ok(_) => match client.poll_get_balance(&vote_account) { retry_get_balance(client, &vote_account, Some(amount)).expect("get balance");
Ok(balance) => {
info!("vote account balance: {}", balance);
break;
}
Err(e) => {
info!("Failed to get vote account balance: {:?}", e);
}
},
Err(e) => {
info!(
"vote_account_new signature not found: {:?}: {:?}",
signature, e
);
}
};
}
Err(e) => {
info!("Failed to send vote_account_new transaction: {:?}", e);
}
};
}
} }
info!("Checking for vote account registration"); info!("Checking for vote account registration");
let vote_account_user_data = client.get_account_userdata(&vote_account); let vote_account_user_data = client.get_account_userdata(&vote_account);
if let Ok(Some(vote_account_user_data)) = vote_account_user_data { if let Ok(Some(vote_account_user_data)) = vote_account_user_data {
if let Ok(vote_state) = VoteState::deserialize(&vote_account_user_data) { if let Ok(vote_state) = VoteState::deserialize(&vote_account_user_data) {
if vote_state.delegate_id == pubkey { if vote_state.delegate_id == from_account.pubkey() {
return Ok(()); return Ok(());
} }
} }