Skip to content

Commit

Permalink
Add constructor, tuck away client (solana-labs#30)
Browse files Browse the repository at this point in the history
* Add constructor, tuck away client

* Fix unwrap() caught by CI
  • Loading branch information
garious authored May 8, 2020
1 parent 5f9d678 commit d3a9058
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let config = Config::load(&command_args.config_file)?;
let json_rpc_url = command_args.url.unwrap_or(config.json_rpc_url);
let client = RpcClient::new(json_rpc_url);
let thin_client = ThinClient(client);
let thin_client = ThinClient::new(client);

match resolve_command(command_args.command)? {
Command::DistributeTokens(args) => {
Expand Down
6 changes: 5 additions & 1 deletion src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ impl Client for BankClient {
}
}

pub struct ThinClient<C: Client>(pub C);
pub struct ThinClient<C: Client>(C);

impl<C: Client> ThinClient<C> {
pub fn new(client: C) -> Self {
Self(client)
}

pub fn async_send_transaction(&self, transaction: Transaction) -> Result<Signature> {
self.0.async_send_transaction1(transaction)
}
Expand Down
15 changes: 8 additions & 7 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,12 @@ fn finalize_transactions<T: Client>(
let progress_bar = new_spinner_progress_bar();

while opt_confirmations.is_some() || !unconfirmed_transactions.is_empty() {
let confirmations = opt_confirmations.unwrap();
progress_bar.set_message(&format!(
"[{}/{}] Finalizing transactions",
confirmations, 32,
));
if let Some(confirmations) = opt_confirmations {
progress_bar.set_message(&format!(
"[{}/{}] Finalizing transactions",
confirmations, 32,
));
}

if !dry_run {
for transaction in unconfirmed_transactions {
Expand Down Expand Up @@ -589,7 +590,7 @@ pub fn process_transaction_log(args: &TransactionLogArgs) -> Result<(), Error> {
use solana_sdk::{pubkey::Pubkey, signature::Keypair};
use tempfile::{tempdir, NamedTempFile};
pub fn test_process_distribute_tokens_with_client<C: Client>(client: C, sender_keypair: Keypair) {
let thin_client = ThinClient(client);
let thin_client = ThinClient::new(client);
let fee_payer = Keypair::new();
thin_client
.transfer(sol_to_lamports(1.0), &sender_keypair, &fee_payer.pubkey())
Expand Down Expand Up @@ -661,7 +662,7 @@ pub fn test_process_distribute_tokens_with_client<C: Client>(client: C, sender_k
}

pub fn test_process_distribute_stake_with_client<C: Client>(client: C, sender_keypair: Keypair) {
let thin_client = ThinClient(client);
let thin_client = ThinClient::new(client);
let fee_payer = Keypair::new();
thin_client
.transfer(sol_to_lamports(1.0), &sender_keypair, &fee_payer.pubkey())
Expand Down

0 comments on commit d3a9058

Please sign in to comment.