mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 00:11:05 +00:00
WIP starting to update subxt from subxt-core changes
This commit is contained in:
@@ -11,8 +11,7 @@ use crate::{
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
use frame_decode::extrinsics::Extrinsic;
|
||||
use scale_decode::DecodeAsType;
|
||||
use subxt_metadata::PalletMetadata;
|
||||
use scale_decode::{DecodeAsFields, DecodeAsType};
|
||||
|
||||
pub use crate::blocks::StaticExtrinsic;
|
||||
|
||||
@@ -278,7 +277,7 @@ where
|
||||
|
||||
/// Decode and provide the extrinsic fields back in the form of a [`scale_value::Composite`]
|
||||
/// type which represents the named or unnamed fields that were present in the extrinsic.
|
||||
pub fn field_values(&self) -> Result<scale_value::Composite<u32>, ExtrinsicError> {
|
||||
pub fn decode_as_fields<E: DecodeAsFields>(&self) -> Result<E, ExtrinsicError> {
|
||||
let bytes = &mut self.field_bytes();
|
||||
let mut fields = self.decoded_info().call_data().map(|d| {
|
||||
let name = if d.name().is_empty() {
|
||||
@@ -288,12 +287,11 @@ where
|
||||
};
|
||||
scale_decode::Field::new(*d.ty(), name)
|
||||
});
|
||||
let decoded =
|
||||
scale_value::scale::decode_as_fields(bytes, &mut fields, self.metadata.types())
|
||||
.map_err(|e| ExtrinsicError::CannotDecodeFields {
|
||||
extrinsic_index: self.index as usize,
|
||||
error: e.into()
|
||||
})?;
|
||||
let decoded = E::decode_as_fields(bytes, &mut fields, self.metadata.types())
|
||||
.map_err(|e| ExtrinsicError::CannotDecodeFields {
|
||||
extrinsic_index: self.index as usize,
|
||||
error: e.into()
|
||||
})?;
|
||||
|
||||
Ok(decoded)
|
||||
}
|
||||
@@ -353,14 +351,6 @@ pub struct FoundExtrinsic<T: Config, E> {
|
||||
pub value: E,
|
||||
}
|
||||
|
||||
/// Details for the given extrinsic plucked from the metadata.
|
||||
pub struct ExtrinsicMetadataDetails<'a> {
|
||||
/// Metadata for the pallet that the extrinsic belongs to.
|
||||
pub pallet: PalletMetadata<'a>,
|
||||
/// Metadata for the variant which describes the pallet extrinsics.
|
||||
pub variant: &'a scale_info::Variant<scale_info::form::PortableForm>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -76,7 +76,7 @@ pub use crate::error::ExtrinsicError;
|
||||
pub use extrinsic_transaction_extensions::{
|
||||
ExtrinsicTransactionExtension, ExtrinsicTransactionExtensions,
|
||||
};
|
||||
pub use extrinsics::{ExtrinsicDetails, ExtrinsicMetadataDetails, Extrinsics, FoundExtrinsic};
|
||||
pub use extrinsics::{ExtrinsicDetails, Extrinsics, FoundExtrinsic};
|
||||
pub use static_extrinsic::StaticExtrinsic;
|
||||
|
||||
/// Instantiate a new [`Extrinsics`] object, given a vector containing each extrinsic hash (in the
|
||||
|
||||
@@ -11,13 +11,12 @@ use crate::{
|
||||
};
|
||||
|
||||
use derive_where::derive_where;
|
||||
use scale_decode::DecodeAsType;
|
||||
use scale_decode::{DecodeAsFields, DecodeAsType};
|
||||
use subxt_core::blocks::{ExtrinsicDetails as CoreExtrinsicDetails, Extrinsics as CoreExtrinsics};
|
||||
|
||||
// Re-export anything that's directly returned/used in the APIs below.
|
||||
pub use subxt_core::blocks::{
|
||||
ExtrinsicMetadataDetails, ExtrinsicTransactionExtension, ExtrinsicParams,
|
||||
StaticExtrinsic,
|
||||
ExtrinsicTransactionExtension, ExtrinsicTransactionExtensions, StaticExtrinsic,
|
||||
};
|
||||
|
||||
/// The body of a block.
|
||||
@@ -198,7 +197,7 @@ where
|
||||
}
|
||||
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::transaction_extensions()`].
|
||||
pub fn transaction_extensions(&self) -> Option<ExtrinsicExtrinsicParams<'_, T>> {
|
||||
pub fn transaction_extensions(&self) -> Option<ExtrinsicTransactionExtensions<'_, T>> {
|
||||
self.inner.transaction_extensions()
|
||||
}
|
||||
|
||||
@@ -213,23 +212,18 @@ where
|
||||
}
|
||||
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::pallet_name()`].
|
||||
pub fn pallet_name(&self) -> Result<&str, Error> {
|
||||
self.inner.pallet_name().map_err(Into::into)
|
||||
pub fn pallet_name(&self) -> &str {
|
||||
self.inner.pallet_name()
|
||||
}
|
||||
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::variant_name()`].
|
||||
pub fn variant_name(&self) -> Result<&str, Error> {
|
||||
self.inner.variant_name().map_err(Into::into)
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::call_name()`].
|
||||
pub fn call_name(&self) -> &str {
|
||||
self.inner.call_name()
|
||||
}
|
||||
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::extrinsic_metadata()`].
|
||||
pub fn extrinsic_metadata(&self) -> Result<ExtrinsicMetadataDetails<'_>, Error> {
|
||||
self.inner.extrinsic_metadata().map_err(Into::into)
|
||||
}
|
||||
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::field_values()`].
|
||||
pub fn field_values(&self) -> Result<scale_value::Composite<u32>, Error> {
|
||||
self.inner.field_values().map_err(Into::into)
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::decode_as_fields()`].
|
||||
pub fn decode_as_fields<E: DecodeAsFields>(&self) -> Result<E, Error> {
|
||||
self.inner.decode_as_fields().map_err(Into::into)
|
||||
}
|
||||
|
||||
/// See [`subxt_core::blocks::ExtrinsicDetails::as_extrinsic()`].
|
||||
|
||||
@@ -15,7 +15,7 @@ pub use block_types::Block;
|
||||
pub use blocks_client::BlocksClient;
|
||||
pub use extrinsic_types::{
|
||||
ExtrinsicDetails, ExtrinsicEvents, ExtrinsicTransactionExtension,
|
||||
ExtrinsicExtrinsicParams, Extrinsics, FoundExtrinsic, StaticExtrinsic,
|
||||
ExtrinsicTransactionExtensions, Extrinsics, FoundExtrinsic, StaticExtrinsic,
|
||||
};
|
||||
|
||||
// We get account nonce info in tx_client, too, so re-use the logic:
|
||||
|
||||
@@ -8,5 +8,5 @@ mod constants_client;
|
||||
|
||||
pub use constants_client::ConstantsClient;
|
||||
pub use subxt_core::constants::address::{
|
||||
Address, DefaultAddress, DynamicAddress, StaticAddress, dynamic,
|
||||
Address, DynamicAddress, StaticAddress, dynamic,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::client::OfflineClientT;
|
||||
use crate::{Config, Error};
|
||||
use derive_where::derive_where;
|
||||
|
||||
use subxt_core::custom_values::address::{Address, Yes};
|
||||
use subxt_core::custom_values::address::{Address, Maybe};
|
||||
|
||||
/// A client for accessing custom values stored in the metadata.
|
||||
#[derive_where(Clone; Client)]
|
||||
@@ -24,7 +24,7 @@ impl<T, Client> CustomValuesClient<T, Client> {
|
||||
impl<T: Config, Client: OfflineClientT<T>> CustomValuesClient<T, Client> {
|
||||
/// Access a custom value by the address it is registered under. This can be just a [str] to get back a dynamic value,
|
||||
/// or a static address from the generated static interface to get a value of a static type returned.
|
||||
pub fn at<Addr: Address<IsDecodable = Yes> + ?Sized>(
|
||||
pub fn at<Addr: Address<IsDecodable = Maybe> + ?Sized>(
|
||||
&self,
|
||||
address: &Addr,
|
||||
) -> Result<Addr::Target, Error> {
|
||||
@@ -46,7 +46,7 @@ impl<T: Config, Client: OfflineClientT<T>> CustomValuesClient<T, Client> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::custom_values::CustomValuesClient;
|
||||
use crate::custom_values::{self, CustomValuesClient};
|
||||
use crate::{Metadata, OfflineClient, SubstrateConfig};
|
||||
use codec::Encode;
|
||||
use scale_decode::DecodeAsType;
|
||||
@@ -117,10 +117,12 @@ mod tests {
|
||||
},
|
||||
mock_metadata(),
|
||||
);
|
||||
|
||||
let custom_value_client = CustomValuesClient::new(client);
|
||||
assert!(custom_value_client.at("No one").is_err());
|
||||
let person_decoded_value_thunk = custom_value_client.at("Person").unwrap();
|
||||
let person: Person = person_decoded_value_thunk.as_type().unwrap();
|
||||
|
||||
let person_addr = custom_values::dynamic::<Person>("Person");
|
||||
let person = custom_value_client.at(&person_addr).unwrap();
|
||||
assert_eq!(
|
||||
person,
|
||||
Person {
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
mod custom_values_client;
|
||||
|
||||
pub use custom_values_client::CustomValuesClient;
|
||||
pub use subxt_core::custom_values::address::{Address, StaticAddress, Yes};
|
||||
pub use subxt_core::custom_values::address::{Address, StaticAddress, DynamicAddress, dynamic};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! A representation of the dispatch error; an error returned when
|
||||
//! something fails in trying to submit/execute a transaction.
|
||||
|
||||
use crate::metadata::{DecodeWithMetadata, Metadata};
|
||||
use crate::metadata::Metadata;
|
||||
use core::fmt::Debug;
|
||||
use scale_decode::{DecodeAsType, TypeResolver, visitor::DecodeAsTypeResult};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
config::{Config, HashFor},
|
||||
};
|
||||
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};
|
||||
@@ -138,8 +138,8 @@ 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_fields_as<E: DecodeAsFields>(&self) -> Result<E, Error> {
|
||||
self.inner.decode_fields_as().map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Attempt to decode these [`EventDetails`] into a type representing the event fields.
|
||||
|
||||
+2
-4
@@ -68,15 +68,13 @@ pub mod config {
|
||||
|
||||
/// Types representing the metadata obtained from a node.
|
||||
pub mod metadata {
|
||||
pub use subxt_core::metadata::{DecodeWithMetadata, Metadata};
|
||||
// Expose metadata types under a sub module in case somebody needs to reference them:
|
||||
pub use subxt_metadata as types;
|
||||
pub use subxt_metadata::*;
|
||||
}
|
||||
|
||||
/// Submit dynamic transactions.
|
||||
pub mod dynamic {
|
||||
pub use subxt_core::dynamic::{
|
||||
At, DecodedValue, DecodedValueThunk, Value, constant, runtime_api_call, tx, storage,
|
||||
At, DecodedValue, Value, constant, runtime_api_call, tx, storage,
|
||||
view_function_call,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ mod runtime_types;
|
||||
pub use runtime_client::RuntimeApiClient;
|
||||
pub use runtime_types::RuntimeApi;
|
||||
pub use subxt_core::runtime_api::payload::{
|
||||
DefaultPayload, DynamicPayload, Payload, StaticPayload, dynamic,
|
||||
DynamicPayload, Payload, StaticPayload, dynamic,
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::{
|
||||
client::{OfflineClientT, OnlineClientT},
|
||||
config::{Config, HashFor},
|
||||
error::{Error, MetadataError, StorageError},
|
||||
metadata::DecodeWithMetadata,
|
||||
storage::storage_value::StorageValue,
|
||||
};
|
||||
use codec::Decode;
|
||||
|
||||
@@ -8,7 +8,7 @@ mod view_function_types;
|
||||
mod view_functions_client;
|
||||
|
||||
pub use subxt_core::view_functions::payload::{
|
||||
DefaultPayload, DynamicPayload, Payload, StaticPayload, dynamic,
|
||||
DynamicPayload, Payload, StaticPayload, dynamic,
|
||||
};
|
||||
pub use view_function_types::ViewFunctionsApi;
|
||||
pub use view_functions_client::ViewFunctionsClient;
|
||||
|
||||
Reference in New Issue
Block a user