From c5caba0d63a4e15dfe95fbd2f17685e22f3b811c Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Thu, 11 Aug 2022 01:09:51 -0700 Subject: [PATCH] token-cli: use program_client for blockhash --- token/cli/src/config.rs | 2 +- token/cli/src/main.rs | 4 ++-- token/client/src/client.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 4f77ebff..04ebb00b 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -69,7 +69,7 @@ impl<'a> Config<'a> { )); let sign_only = matches.is_present(SIGN_ONLY_ARG.name); let program_client: Arc> = if sign_only { - let blockhash = value_of(matches, BLOCKHASH_ARG.name); + let blockhash = value_of(matches, BLOCKHASH_ARG.name).unwrap_or_default(); Arc::new(ProgramOfflineClient::new( blockhash, ProgramRpcClientSendTransaction, diff --git a/token/cli/src/main.rs b/token/cli/src/main.rs index 3cc03541..a526319d 100644 --- a/token/cli/src/main.rs +++ b/token/cli/src/main.rs @@ -3138,7 +3138,7 @@ async fn handle_tx<'a>( ) -> Result { let fee_payer = Some(&config.fee_payer); - let recent_blockhash = config.rpc_client.get_latest_blockhash().await?; + let recent_blockhash = config.program_client.get_latest_blockhash().await?; let message = if let Some(nonce_account) = config.nonce_account.as_ref() { let mut message = Message::new_with_nonce( instructions, @@ -3151,9 +3151,9 @@ async fn handle_tx<'a>( } else { Message::new_with_blockhash(&instructions, fee_payer, &recent_blockhash) }; - let fee = config.rpc_client.get_fee_for_message(&message).await?; if !config.sign_only { + let fee = config.rpc_client.get_fee_for_message(&message).await?; check_fee_payer_balance(config, minimum_balance_for_rent_exemption + fee).await?; } diff --git a/token/client/src/client.rs b/token/client/src/client.rs index 177fd657..195dfc2b 100644 --- a/token/client/src/client.rs +++ b/token/client/src/client.rs @@ -243,7 +243,7 @@ where /// Program client for offline signing. pub struct ProgramOfflineClient { - maybe_blockhash: Option, + blockhash: Hash, _send: ST, } @@ -254,9 +254,9 @@ impl fmt::Debug for ProgramOfflineClient { } impl ProgramOfflineClient { - pub fn new(maybe_blockhash: Option, send: ST) -> Self { + pub fn new(blockhash: Hash, send: ST) -> Self { Self { - maybe_blockhash, + blockhash, _send: send, } } @@ -275,7 +275,7 @@ where } async fn get_latest_blockhash(&self) -> ProgramClientResult { - Ok(self.maybe_blockhash.unwrap()) + Ok(self.blockhash) } async fn send_transaction(&self, transaction: &Transaction) -> ProgramClientResult {