Merge remote-tracking branch 'origin/master' into lexnv/metadata_v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-04-13 20:13:39 +03:00
30 changed files with 631 additions and 314 deletions
+1 -1
View File
@@ -287,7 +287,7 @@ where
Some(events) => events.clone(),
None => {
events::EventsClient::new(client.clone())
.at(Some(block_hash))
.at(block_hash)
.await?
}
};
+17 -2
View File
@@ -39,8 +39,7 @@ where
T: Config,
Client: OnlineClientT<T>,
{
/// Obtain block details given the provided block hash, or the latest block if `None` is
/// provided.
/// Obtain block details given the provided block hash.
///
/// # Warning
///
@@ -48,6 +47,22 @@ where
/// runtime upgrade. You can attempt to retrieve older blocks,
/// but may run into errors attempting to work with them.
pub fn at(
&self,
block_hash: T::Hash,
) -> impl Future<Output = Result<Block<T, Client>, Error>> + Send + 'static {
self.at_or_latest(Some(block_hash))
}
/// Obtain block details of the latest block hash.
pub fn at_latest(
&self,
) -> impl Future<Output = Result<Block<T, Client>, Error>> + Send + 'static {
self.at_or_latest(None)
}
/// Obtain block details given the provided block hash, or the latest block if `None` is
/// provided.
fn at_or_latest(
&self,
block_hash: Option<T::Hash>,
) -> impl Future<Output = Result<Block<T, Client>, Error>> + Send + 'static {
+13
View File
@@ -37,6 +37,19 @@ where
/// runtime upgrade. You can attempt to retrieve events from older blocks,
/// but may run into errors attempting to work with them.
pub fn at(
&self,
block_hash: T::Hash,
) -> impl Future<Output = Result<Events<T>, Error>> + Send + 'static {
self.at_or_latest(Some(block_hash))
}
/// Obtain events at the latest block hash.
pub fn at_latest(&self) -> impl Future<Output = Result<Events<T>, Error>> + Send + 'static {
self.at_or_latest(None)
}
/// Obtain events at some block hash.
fn at_or_latest(
&self,
block_hash: Option<T::Hash>,
) -> impl Future<Output = Result<Events<T>, Error>> + Send + 'static {
+13 -11
View File
@@ -31,23 +31,25 @@ where
T: Config,
Client: OnlineClientT<T>,
{
/// Obtain a runtime API at some block hash.
pub fn at(
/// Obtain a runtime API interface at some block hash.
pub fn at(&self, block_hash: T::Hash) -> RuntimeApi<T, Client> {
RuntimeApi::new(self.client.clone(), block_hash)
}
/// Obtain a runtime API interface at the latest block hash.
pub fn at_latest(
&self,
block_hash: Option<T::Hash>,
) -> impl Future<Output = Result<RuntimeApi<T, Client>, Error>> + Send + 'static {
// Clone and pass the client in like this so that we can explicitly
// return a Future that's Send + 'static, rather than tied to &self.
let client = self.client.clone();
async move {
// If block hash is not provided, get the hash
// for the latest block and use that.
let block_hash = match block_hash {
Some(hash) => hash,
None => client.rpc().block_hash(None).await?.expect(
"substrate RPC returns the best block when no block number is provided; qed",
),
};
// get the hash for the latest block and use that.
let block_hash = client
.rpc()
.block_hash(None)
.await?
.expect("didn't pass a block number; qed");
Ok(RuntimeApi::new(client, block_hash))
}
+12 -12
View File
@@ -71,24 +71,24 @@ where
Client: OnlineClientT<T>,
{
/// Obtain storage at some block hash.
pub fn at(
pub fn at(&self, block_hash: T::Hash) -> Storage<T, Client> {
Storage::new(self.client.clone(), block_hash)
}
/// Obtain storage at the latest block hash.
pub fn at_latest(
&self,
block_hash: Option<T::Hash>,
) -> impl Future<Output = Result<Storage<T, Client>, Error>> + Send + 'static {
// Clone and pass the client in like this so that we can explicitly
// return a Future that's Send + 'static, rather than tied to &self.
let client = self.client.clone();
async move {
// If block hash is not provided, get the hash
// for the latest block and use that.
let block_hash = match block_hash {
Some(hash) => hash,
None => client
.rpc()
.block_hash(None)
.await?
.expect("didn't pass a block number; qed"),
};
// get the hash for the latest block and use that.
let block_hash = client
.rpc()
.block_hash(None)
.await?
.expect("didn't pass a block number; qed");
Ok(Storage::new(client, block_hash))
}
+2 -2
View File
@@ -75,7 +75,7 @@ where
/// // Fetch just the keys, returning up to 10 keys.
/// let value = api
/// .storage()
/// .at(None)
/// .at_latest()
/// .await
/// .unwrap()
/// .fetch(&address)
@@ -185,7 +185,7 @@ where
/// // Iterate over keys and values at that address.
/// let mut iter = api
/// .storage()
/// .at(None)
/// .at_latest()
/// .await
/// .unwrap()
/// .iter(address, 10)
+1 -1
View File
@@ -397,7 +397,7 @@ impl<T: Config, C: OnlineClientT<T>> TxInBlock<T, C> {
.ok_or(Error::Transaction(TransactionError::BlockNotFound))?;
let events = EventsClient::new(self.client.clone())
.at(Some(self.block_hash))
.at(self.block_hash)
.await?;
Ok(crate::blocks::ExtrinsicEvents::new(