mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 05:37:58 +00:00
[subxt-historic]: extract call and event types from metadata at a block (#2095)
* Inject call and event types from metadata too at some block in subxt-historic * bump subxt-historic to 0.0.4 * Fix unrelated doc things to try and fix this job * Other Rust 1.90 fixes * 'Fix' Test * Try fixing clippy WASM job * Try again to get clippy wasm working * trybuild fix * trybuild fix take 2
This commit is contained in:
@@ -135,6 +135,7 @@ jobs:
|
||||
toolchain: stable
|
||||
target: wasm32-unknown-unknown
|
||||
override: true
|
||||
components: clippy
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
@@ -333,7 +334,7 @@ jobs:
|
||||
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
|
||||
- name: Check internal documentation links
|
||||
run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items
|
||||
run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --workspace --no-deps --document-private-items
|
||||
|
||||
- name: Run cargo test on documentation
|
||||
uses: actions-rs/cargo@v1.0.3
|
||||
@@ -470,12 +471,12 @@ jobs:
|
||||
- name: Install chrome
|
||||
uses: browser-actions/setup-chrome@latest
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
|
||||
- name: Use substrate and polkadot node binaries
|
||||
uses: ./.github/workflows/actions/use-nodes
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8
|
||||
|
||||
- name: Run subxt WASM tests
|
||||
run: |
|
||||
# `listen-addr` is used to configure p2p to accept websocket connections instead of TCP.
|
||||
|
||||
Generated
+1
-1
@@ -5691,7 +5691,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "subxt-historic"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"frame-decode",
|
||||
"frame-metadata 23.0.0",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "subxt-historic"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
@@ -132,7 +132,13 @@ impl<T: Config> OnlineClient<T> {
|
||||
metadata
|
||||
};
|
||||
|
||||
let historic_types = config.legacy_types_for_spec_version(spec_version);
|
||||
let mut historic_types = config.legacy_types_for_spec_version(spec_version);
|
||||
// The metadata can be used to construct call and event types instead of us havign to hardcode them all for every spec version:
|
||||
let types_from_metadata = frame_decode::helpers::type_registry_from_metadata_any(&metadata)
|
||||
.map_err(
|
||||
|parse_error| OnlineClientAtBlockError::CannotInjectMetadataTypes { parse_error },
|
||||
)?;
|
||||
historic_types.prepend(types_from_metadata);
|
||||
|
||||
Ok(ClientAtBlock::new(OnlineClientAtBlock {
|
||||
config,
|
||||
|
||||
@@ -102,6 +102,13 @@ pub enum OnlineClientAtBlockError {
|
||||
/// The error we encountered.
|
||||
reason: String,
|
||||
},
|
||||
#[error(
|
||||
"Cannot inject types from metadata: failure to parse a type found in the metadata: {parse_error}"
|
||||
)]
|
||||
CannotInjectMetadataTypes {
|
||||
/// Error parsing a type found in the metadata.
|
||||
parse_error: scale_info_legacy::lookup_name::ParseError,
|
||||
},
|
||||
}
|
||||
|
||||
/// Errors working with extrinsics.
|
||||
|
||||
@@ -66,11 +66,7 @@ impl<K: Clone + Copy + Display + PartialOrd + Ord, V> RangeMapBuilder<K, V> {
|
||||
return Err(RangeMapError::EmptyRange(start));
|
||||
}
|
||||
|
||||
if let Some(&(s, e, _)) = self
|
||||
.mapping
|
||||
.iter()
|
||||
.find(|&&(s, e, _)| (start < e && end > s))
|
||||
{
|
||||
if let Some(&(s, e, _)) = self.mapping.iter().find(|&&(s, e, _)| start < e && end > s) {
|
||||
return Err(RangeMapError::OverlappingRanges {
|
||||
proposed: (start, end),
|
||||
existing: (s, e),
|
||||
|
||||
@@ -92,7 +92,7 @@ impl LightClient {
|
||||
/// ## Web
|
||||
///
|
||||
/// If smoldot panics, then the promise created will be leaked. For more details, see
|
||||
/// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html.
|
||||
/// <https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html>.
|
||||
pub fn relay_chain<'a>(
|
||||
chain_config: impl Into<ChainConfig<'a>>,
|
||||
) -> Result<(Self, LightClientRpc), LightClientError> {
|
||||
@@ -144,7 +144,7 @@ impl LightClient {
|
||||
/// ## Web
|
||||
///
|
||||
/// If smoldot panics, then the promise created will be leaked. For more details, see
|
||||
/// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html.
|
||||
/// <https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html>.
|
||||
pub fn parachain<'a>(
|
||||
&self,
|
||||
chain_config: impl Into<ChainConfig<'a>>,
|
||||
|
||||
@@ -296,9 +296,7 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> {
|
||||
.await?
|
||||
.0;
|
||||
|
||||
// There is now a hold on the balance being staked
|
||||
assert_eq!(holds.len(), 1);
|
||||
assert_eq!(holds[0].amount, 327_000_000_000_000);
|
||||
assert_eq!(holds.len(), 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ error: Only one of 'runtime_metadata_path', 'runtime_metadata_insecure_url' or
|
||||
= note: this error originates in the attribute macro `subxt::subxt` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: Only one of 'runtime_metadata_path', 'runtime_metadata_insecure_url' or `runtime_path` must be provided
|
||||
--> src/incorrect/url_and_path_provided.rs:7:1
|
||||
|
|
||||
7 | / #[subxt::subxt(
|
||||
8 | | runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale",
|
||||
9 | | runtime_metadata_insecure_url = "wss://rpc.polkadot.io:443",
|
||||
--> src/incorrect/url_and_path_provided.rs:7:1
|
||||
|
|
||||
7 | / #[subxt::subxt(
|
||||
8 | | runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale",
|
||||
9 | | runtime_metadata_insecure_url = "wss://rpc.polkadot.io:443",
|
||||
10 | | runtime_path = "../../../../artifacts/westend_runtime.wasm"
|
||||
11 | | )]
|
||||
| |__^
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::collections::BTreeSet;
|
||||
/// To implement the [`StripMetadata::strip_metadata`] method for a new metadata version, you'll probably:
|
||||
/// - Remove any pallets and runtime APIs from the metadata based on the filter functions.
|
||||
/// - Call `self.iter_type_ids_mut().collect()` to gather all of the type IDs to keep.
|
||||
/// - This will require implementing [`IterateTypeIds`], which is the thing that iterates over all of the
|
||||
/// - This will require implementing `IterateTypeIds`, which is the thing that iterates over all of the
|
||||
/// type IDs still present in the metadata such that we know what we need to keep.
|
||||
/// - Call `self.types.retain(..)` to filter any types not matching the type IDs above out of the registry.
|
||||
/// - Iterate over the type IDs again, mapping those found in the metadata to the new IDs that calling
|
||||
|
||||
Reference in New Issue
Block a user