From f1636409982fc1d0c9ae632d84b2aa99b0926ede Mon Sep 17 00:00:00 2001 From: Vadim Obradovich Date: Mon, 20 Jan 2025 13:25:10 +0100 Subject: [PATCH] feat(gclient): impl `at_block` for query at specific block (#778) --- rs/src/gclient/calls.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/rs/src/gclient/calls.rs b/rs/src/gclient/calls.rs index c55d8eca..73878192 100644 --- a/rs/src/gclient/calls.rs +++ b/rs/src/gclient/calls.rs @@ -1,5 +1,5 @@ use crate::{ - calls::Remoting, + calls::{Query, Remoting}, errors::{Result, RtlError}, events::Listener, prelude::*, @@ -16,6 +16,7 @@ use gear_core_errors::ReplyCode; #[derive(Debug, Default)] pub struct GClientArgs { voucher: Option<(VoucherId, bool)>, + at_block: Option, } impl GClientArgs { @@ -23,6 +24,11 @@ impl GClientArgs { self.voucher = Some((voucher_id, keep_alive)); self } + + fn at_block(mut self, hash: H256) -> Self { + self.at_block = Some(hash); + self + } } #[derive(Clone)] @@ -127,7 +133,7 @@ impl Remoting for GClientRemoting { payload: impl AsRef<[u8]>, #[cfg(not(feature = "ethexe"))] gas_limit: Option, value: ValueUnit, - _args: GClientArgs, + args: GClientArgs, ) -> Result> { let api = self.api; // Get Max gas amount if it is not explicitly set @@ -143,7 +149,14 @@ impl Remoting for GClientRemoting { let payload = payload.as_ref().to_vec(); let reply_info = api - .calculate_reply_for_handle(Some(origin), target, payload, gas_limit, value) + .calculate_reply_for_handle_at( + Some(origin), + target, + payload, + gas_limit, + value, + args.at_block, + ) .await?; match reply_info.code { @@ -202,3 +215,17 @@ async fn get_events_from_block( .await?; Ok(vec) } + +pub trait QueryAtBlock { + /// Query at a specific block. + fn at_block(self, hash: H256) -> Self; +} + +impl QueryAtBlock for T +where + T: Query, +{ + fn at_block(self, hash: H256) -> Self { + self.with_args(GClientArgs::default().at_block(hash)) + } +}