token-cli: use program_client for blockhash

This commit is contained in:
hanako mumei 2022-08-11 01:09:51 -07:00 committed by hana
parent 3d42786e6e
commit c5caba0d63
3 changed files with 7 additions and 7 deletions

View File

@ -69,7 +69,7 @@ impl<'a> Config<'a> {
));
let sign_only = matches.is_present(SIGN_ONLY_ARG.name);
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = 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,

View File

@ -3138,7 +3138,7 @@ async fn handle_tx<'a>(
) -> Result<TransactionReturnData, Error> {
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?;
}

View File

@ -243,7 +243,7 @@ where
/// Program client for offline signing.
pub struct ProgramOfflineClient<ST> {
maybe_blockhash: Option<Hash>,
blockhash: Hash,
_send: ST,
}
@ -254,9 +254,9 @@ impl<ST> fmt::Debug for ProgramOfflineClient<ST> {
}
impl<ST> ProgramOfflineClient<ST> {
pub fn new(maybe_blockhash: Option<Hash>, 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<Hash> {
Ok(self.maybe_blockhash.unwrap())
Ok(self.blockhash)
}
async fn send_transaction(&self, transaction: &Transaction) -> ProgramClientResult<ST::Output> {