mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
Remove codec::Encode and codec::Decode derives from generated APIs by default (#2008)
* Remove codec::Encode and codec::Decode from generated APIs by default * clippy fixes * clippy * More fixes, and CompactAs only if Encode/Decode * revert println in example * fix lightclient test * fix docs * Fix another rust doc comment * Fix failing storage test * Remove now-unnecessary test * clippy * clippy * Remove pointless clone
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#![allow(missing_docs)]
|
||||
use subxt::ext::codec::Compact;
|
||||
use subxt::ext::codec::{Compact, Decode};
|
||||
use subxt::ext::frame_metadata::RuntimeMetadataPrefixed;
|
||||
use subxt::{OnlineClient, PolkadotConfig};
|
||||
|
||||
@@ -15,8 +15,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let runtime_apis = api.runtime_api().at_latest().await?;
|
||||
|
||||
// Ask for metadata and decode it:
|
||||
let (_, meta): (Compact<u32>, RuntimeMetadataPrefixed) =
|
||||
runtime_apis.call_raw("Metadata_metadata", None).await?;
|
||||
let result_bytes = runtime_apis.call_raw("Metadata_metadata", None).await?;
|
||||
let (_, meta): (Compact<u32>, RuntimeMetadataPrefixed) = Decode::decode(&mut &*result_bytes)?;
|
||||
|
||||
println!("{meta:?}");
|
||||
Ok(())
|
||||
|
||||
@@ -8,7 +8,7 @@ use subxt_signer::sr25519::dev;
|
||||
runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
|
||||
derive_for_type(
|
||||
path = "staging_xcm::v3::multilocation::MultiLocation",
|
||||
derive = "Clone",
|
||||
derive = "Clone, codec::Encode",
|
||||
recursive
|
||||
)
|
||||
)]
|
||||
|
||||
@@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Build a storage query to access account information.
|
||||
let account = dev::alice().public_key().into();
|
||||
let storage_query = polkadot::storage().system().account(&account);
|
||||
let storage_query = polkadot::storage().system().account(account);
|
||||
|
||||
// Use that query to `fetch` a result. This returns an `Option<_>`, which will be
|
||||
// `None` if no value exists at the given address. You can also use `fetch_default`
|
||||
|
||||
@@ -30,7 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Build a storage query to iterate over open multisig extrinsics from
|
||||
// new_multisig_1.multisig which is the AccountId of the alice + bob multisig account
|
||||
let alice_bob_account_id = &new_multisig_1.multisig;
|
||||
let alice_bob_account_id = new_multisig_1.multisig;
|
||||
let storage_query = polkadot::storage()
|
||||
.multisig()
|
||||
.multisigs_iter1(alice_bob_account_id);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
//! pub mod polkadot {}
|
||||
//!
|
||||
//! let account = dev::alice().public_key().into();
|
||||
//! let storage_query = polkadot::storage().system().account(&account);
|
||||
//! let storage_query = polkadot::storage().system().account(account);
|
||||
//! ```
|
||||
//!
|
||||
//! Alternately, we can dynamically construct a storage query. This will not be type checked or
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
|
||||
use super::Payload;
|
||||
use crate::{
|
||||
backend::{BackendExt, BlockRef},
|
||||
backend::BlockRef,
|
||||
client::OnlineClientT,
|
||||
config::{Config, HashFor},
|
||||
error::Error,
|
||||
};
|
||||
use codec::Decode;
|
||||
use derive_where::derive_where;
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
|
||||
@@ -45,20 +44,21 @@ where
|
||||
subxt_core::runtime_api::validate(payload, &self.client.metadata()).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Execute a raw runtime API call.
|
||||
pub fn call_raw<'a, Res: Decode>(
|
||||
/// Execute a raw runtime API call. This returns the raw bytes representing the result
|
||||
/// of this call. The caller is responsible for decoding the result.
|
||||
pub fn call_raw<'a>(
|
||||
&self,
|
||||
function: &'a str,
|
||||
call_parameters: Option<&'a [u8]>,
|
||||
) -> impl Future<Output = Result<Res, Error>> + use<'a, Res, Client, T> {
|
||||
) -> impl Future<Output = Result<Vec<u8>, Error>> + use<'a, Client, T> {
|
||||
let client = self.client.clone();
|
||||
let block_hash = self.block_ref.hash();
|
||||
// Ensure that the returned future doesn't have a lifetime tied to api.runtime_api(),
|
||||
// which is a temporary thing we'll be throwing away quickly:
|
||||
async move {
|
||||
let data: Res = client
|
||||
let data = client
|
||||
.backend()
|
||||
.call_decoding(function, call_parameters, block_hash)
|
||||
.call(function, call_parameters, block_hash)
|
||||
.await?;
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ where
|
||||
/// let api = OnlineClient::<PolkadotConfig>::new().await.unwrap();
|
||||
///
|
||||
/// // Address to a storage entry we'd like to access.
|
||||
/// let address = polkadot::storage().xcm_pallet().queries(&12345);
|
||||
/// let address = polkadot::storage().xcm_pallet().queries(12345);
|
||||
///
|
||||
/// // Fetch just the keys, returning up to 10 keys.
|
||||
/// let value = api
|
||||
|
||||
Reference in New Issue
Block a user