From 8934a3961fe7f0a86eecde8463ebca7421b9912f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:29:42 +0000 Subject: [PATCH] Add get_clock to BanksClient (#18591) (cherry picked from commit d30a36641eeff9f7136cbbd9bc9748a8b04e82f0) Co-authored-by: Kirill Fomichev --- banks-client/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/banks-client/src/lib.rs b/banks-client/src/lib.rs index cec904e528..b5e41f6d93 100644 --- a/banks-client/src/lib.rs +++ b/banks-client/src/lib.rs @@ -10,8 +10,14 @@ use futures::{future::join_all, Future, FutureExt}; pub use solana_banks_interface::{BanksClient as TarpcClient, TransactionStatus}; use solana_banks_interface::{BanksRequest, BanksResponse}; use solana_program::{ - clock::Slot, fee_calculator::FeeCalculator, hash::Hash, program_pack::Pack, pubkey::Pubkey, - rent::Rent, sysvar::Sysvar, + clock::Clock, + clock::Slot, + fee_calculator::FeeCalculator, + hash::Hash, + program_pack::Pack, + pubkey::Pubkey, + rent::Rent, + sysvar::{self, Sysvar}, }; use solana_sdk::{ account::{from_account, Account}, @@ -115,6 +121,17 @@ impl BanksClient { self.send_transaction_with_context(context::current(), transaction) } + /// Return the cluster clock + pub fn get_clock(&mut self) -> impl Future> + '_ { + self.get_account(sysvar::clock::id()).map(|result| { + let clock_sysvar = result? + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Clock sysvar not present"))?; + from_account::(&clock_sysvar).ok_or_else(|| { + io::Error::new(io::ErrorKind::Other, "Failed to deserialize Clock sysvar") + }) + }) + } + /// Return the fee parameters associated with a recent, rooted blockhash. The cluster /// will use the transaction's blockhash to look up these same fee parameters and /// use them to calculate the transaction fee.