Merge v0.50.x to master (#2127)

* v0.50.0: Integrate frame-decode, redo storage APIs and break up Error. (#2100)

* WIP integrating new frame-decode and working out new storage APIS

* WIP: first pass adding new storage things to subxt-core

* Second pass over Address type and start impl in Subxt

* WIP new storage APIs

* WIP New storage APIs roughly completed, lots of errors still

* Remove PlainorMap enum; plain and map values now use same struct to simplify usage

* Begin 'fixing' errors

* WIP splitting errors and tidying payload/address traits

* Get subxt-core compiling

* Small fixes in subxt-core and remove metadata mod

* subxt-core: cargo check --all-targets passes

* Fix test

* WIP starting to update subxt from subxt-core changes

* WIP splitting up subxt errors into smaller variants

* WIP errors: add DispatchError errors

* Port new Storage APIs to subxt-core

* cargo check -p subxt passes

* Quick-fix errors in subxt-cli (explore subcommand)

* fmt

* Finish fixing codegen up and start fixing examples

* get Subxt examples compiling and bytes_at for constants

* Add some arcs to limit lifetimes in subxt/subxt-core storage APIs

* A little Arcing to allow more method chaining in Storage APIs, aligning with Subxt

* Update codegen test

* cargo check --all-targets passing

* cargo check --features 'unstable-light-client' passing

* clippy

* Remove unused dep in subxt

* use published frame-decode

* fix wasm-example

* Add new tx extension to fix daily tests

* Remove unused subxt_core::dynamic::DecodedValue type

* Update book to match changes

* Update docs to fix more broken bits

* Add missing docs

* fmt

* allow larger result errs for now

* Add missing alloc imports in subxt-core

* Fix doc tests and fix bug getting constant info

* Fix V14 -> Metadata transform for storage & constants

* Fix parachain example

* Fix FFI example

* BlockLength decodes t ostruct, not u128

* use fetch/iter shorthands rather than entry in most storage tests

* Fix some integration tests

* Fix Runtime codegen tests

* Expose the dynamic custom_value selecter and use in a UI test

* Update codegen metadata

* Tidy CLI storage query and support (str,str) as a storage address

* Add (str,str) as valid constant address too

* Show string tuple in constants example

* Via the magic of traits, avoid needing any clones of queries/addresses and accept references to them

* clippy

* [v0.50] update scale-info-legacy and frame-decode to latest (#2119)

* bump scale-info-legacy and frame-decode to latest

* Remove something we don't need in this PR

* Fully remove unused for now dep

* [v0.50] Convert historic metadata to subxt::Metadata (#2120)

* First pass converting historic metadatas to our subxt::Metadata type

* use published frame-decode

* fmt and rename legacy metadata macro

* Enable legacy feature where needed in subxt_metadata so it compiles on its own

* Use cargo hack more in CI and fix subxt-metadata features

* Add tests for metadata conversion (need to optimise; some too expensive right now

* Address performance and equality issues in metadata conversion testing

* fmt

* fmt all

* clippy

* Fix a doc link

* Test codegen and fixes to make it work

* Remove local frame-decode patch

* bump frame-decode to latest

* [v0.50.0] Allow visiting extrinsic fields in subxt_historic (#2124)

* Allow visiting extrinsic fields

* fmt

* Don't use local scale-decode dep

* Clippy and tidy

* Extend 'subxt codegen' CLI to work with legacy metadatas

* Simplify historic extrinsics example now that AccountId32s have paths/names

* clippy

* clippy

* clippy..

* Allow visiting storage values, too, and clean up extrinsic visiting a little by narrowing lifetime

* Try to fix flaky test

* Add custom value decode to extrinsics example

* Remove useless else branch ra thought I needed

* Simplify examples

* Prep to release v0.0.5 (#2126)
This commit is contained in:
James Wilson
2025-11-22 10:44:03 +00:00
committed by GitHub
parent 586b814ecd
commit 8203679cbd
158 changed files with 13736 additions and 16451 deletions
+17 -9
View File
@@ -6,7 +6,7 @@ use crate::backend::{Backend, BackendExt, BlockRef};
use crate::{
client::OnlineClientT,
config::{Config, HashFor},
error::Error,
error::EventsError,
events::Events,
};
use derive_where::derive_where;
@@ -44,12 +44,14 @@ where
pub fn at(
&self,
block_ref: impl Into<BlockRef<HashFor<T>>>,
) -> impl Future<Output = Result<Events<T>, Error>> + Send + 'static {
) -> impl Future<Output = Result<Events<T>, EventsError>> + Send + 'static {
self.at_or_latest(Some(block_ref.into()))
}
/// Obtain events for the latest finalized block.
pub fn at_latest(&self) -> impl Future<Output = Result<Events<T>, Error>> + Send + 'static {
pub fn at_latest(
&self,
) -> impl Future<Output = Result<Events<T>, EventsError>> + Send + 'static {
self.at_or_latest(None)
}
@@ -57,7 +59,7 @@ where
fn at_or_latest(
&self,
block_ref: Option<BlockRef<HashFor<T>>>,
) -> impl Future<Output = Result<Events<T>, Error>> + Send + 'static {
) -> impl Future<Output = Result<Events<T>, EventsError>> + 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();
@@ -65,7 +67,11 @@ where
// If a block ref isn't provided, we'll get the latest finalized block to use.
let block_ref = match block_ref {
Some(r) => r,
None => client.backend().latest_finalized_block_ref().await?,
None => client
.backend()
.latest_finalized_block_ref()
.await
.map_err(EventsError::CannotGetLatestFinalizedBlock)?,
};
let event_bytes = get_event_bytes(client.backend(), block_ref.hash()).await?;
@@ -88,9 +94,11 @@ fn system_events_key() -> [u8; 32] {
pub(crate) async fn get_event_bytes<T: Config>(
backend: &dyn Backend<T>,
block_hash: HashFor<T>,
) -> Result<Vec<u8>, Error> {
Ok(backend
) -> Result<Vec<u8>, EventsError> {
let bytes = backend
.storage_fetch_value(system_events_key().to_vec(), block_hash)
.await?
.unwrap_or_default())
.await
.map_err(EventsError::CannotFetchEventBytes)?
.unwrap_or_default();
Ok(bytes)
}
+12 -11
View File
@@ -1,9 +1,10 @@
use crate::{
Error, Metadata,
Metadata,
config::{Config, HashFor},
error::EventsError,
};
use derive_where::derive_where;
use scale_decode::DecodeAsType;
use scale_decode::{DecodeAsFields, DecodeAsType};
use subxt_core::events::{EventDetails as CoreEventDetails, Events as CoreEvents};
pub use subxt_core::events::{EventMetadataDetails, Phase, StaticEvent};
@@ -49,7 +50,7 @@ impl<T: Config> Events<T> {
// use of it with our `FilterEvents` stuff.
pub fn iter(
&self,
) -> impl Iterator<Item = Result<EventDetails<T>, Error>> + Send + Sync + 'static {
) -> impl Iterator<Item = Result<EventDetails<T>, EventsError>> + Send + Sync + 'static {
self.inner
.iter()
.map(|item| item.map(|e| EventDetails { inner: e }).map_err(Into::into))
@@ -58,24 +59,24 @@ impl<T: Config> Events<T> {
/// Iterate through the events using metadata to dynamically decode and skip
/// them, and return only those which should decode to the provided `Ev` type.
/// If an error occurs, all subsequent iterations return `None`.
pub fn find<Ev: StaticEvent>(&self) -> impl Iterator<Item = Result<Ev, Error>> {
pub fn find<Ev: StaticEvent>(&self) -> impl Iterator<Item = Result<Ev, EventsError>> {
self.inner.find::<Ev>().map(|item| item.map_err(Into::into))
}
/// Iterate through the events using metadata to dynamically decode and skip
/// them, and return the first event found which decodes to the provided `Ev` type.
pub fn find_first<Ev: StaticEvent>(&self) -> Result<Option<Ev>, Error> {
pub fn find_first<Ev: StaticEvent>(&self) -> Result<Option<Ev>, EventsError> {
self.inner.find_first::<Ev>().map_err(Into::into)
}
/// Iterate through the events using metadata to dynamically decode and skip
/// them, and return the last event found which decodes to the provided `Ev` type.
pub fn find_last<Ev: StaticEvent>(&self) -> Result<Option<Ev>, Error> {
pub fn find_last<Ev: StaticEvent>(&self) -> Result<Option<Ev>, EventsError> {
self.inner.find_last::<Ev>().map_err(Into::into)
}
/// Find an event that decodes to the type provided. Returns true if it was found.
pub fn has<Ev: StaticEvent>(&self) -> Result<bool, Error> {
pub fn has<Ev: StaticEvent>(&self) -> Result<bool, EventsError> {
self.inner.has::<Ev>().map_err(Into::into)
}
}
@@ -138,20 +139,20 @@ impl<T: Config> EventDetails<T> {
/// Decode and provide the event fields back in the form of a [`scale_value::Composite`]
/// type which represents the named or unnamed fields that were present in the event.
pub fn field_values(&self) -> Result<scale_value::Composite<u32>, Error> {
self.inner.field_values().map_err(Into::into)
pub fn decode_as_fields<E: DecodeAsFields>(&self) -> Result<E, EventsError> {
self.inner.decode_as_fields().map_err(Into::into)
}
/// Attempt to decode these [`EventDetails`] into a type representing the event fields.
/// Such types are exposed in the codegen as `pallet_name::events::EventName` types.
pub fn as_event<E: StaticEvent>(&self) -> Result<Option<E>, Error> {
pub fn as_event<E: StaticEvent>(&self) -> Result<Option<E>, EventsError> {
self.inner.as_event::<E>().map_err(Into::into)
}
/// Attempt to decode these [`EventDetails`] into a root event type (which includes
/// the pallet and event enum variants as well as the event fields). A compatible
/// type for this is exposed via static codegen as a root level `Event` type.
pub fn as_root_event<E: DecodeAsType>(&self) -> Result<E, Error> {
pub fn as_root_event<E: DecodeAsType>(&self) -> Result<E, EventsError> {
self.inner.as_root_event::<E>().map_err(Into::into)
}
+2 -2
View File
@@ -9,8 +9,8 @@
mod events_client;
mod events_type;
use crate::Error;
use crate::client::OnlineClientT;
use crate::error::EventsError;
use subxt_core::{
Metadata,
config::{Config, HashFor},
@@ -24,7 +24,7 @@ pub async fn new_events_from_client<T, C>(
metadata: Metadata,
block_hash: HashFor<T>,
client: C,
) -> Result<Events<T>, Error>
) -> Result<Events<T>, EventsError>
where
T: Config,
C: OnlineClientT<T>,