mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 18:51:12 +00:00
start fixing examples and cleaning up interface
This commit is contained in:
@@ -11,11 +11,8 @@ use crate::client::ClientBase;
|
||||
|
||||
use super::Config;
|
||||
use crate::ExtrinsicParamsError;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt::Debug;
|
||||
|
||||
use derive_more::Display;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// This trait allows you to configure the "signed extra" and
|
||||
/// "additional" parameters that are a part of the transaction payload
|
||||
@@ -29,7 +26,7 @@ pub trait ExtrinsicParams<T: Config>: ExtrinsicParamsEncoder + Sized + 'static {
|
||||
/// Construct a new instance of our [`ExtrinsicParams`].
|
||||
fn new(
|
||||
nonce: u64,
|
||||
client: &ClientBase<T>,
|
||||
client: ClientBase<T>,
|
||||
other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError>;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckSpecVersion {
|
||||
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
client: &ClientBase<T>,
|
||||
client: ClientBase<T>,
|
||||
_other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CheckSpecVersion(client.runtime_version().spec_version))
|
||||
@@ -73,7 +73,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckNonce {
|
||||
|
||||
fn new(
|
||||
nonce: u64,
|
||||
_client: &ClientBase<T>,
|
||||
_client: ClientBase<T>,
|
||||
_other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CheckNonce(Compact(nonce)))
|
||||
@@ -101,7 +101,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckTxVersion {
|
||||
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
client: &ClientBase<T>,
|
||||
client: ClientBase<T>,
|
||||
_other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CheckTxVersion(client.runtime_version().transaction_version))
|
||||
@@ -129,7 +129,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckGenesis<T> {
|
||||
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
client: &ClientBase<T>,
|
||||
client: ClientBase<T>,
|
||||
_other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CheckGenesis(client.genesis_hash()))
|
||||
@@ -195,7 +195,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckMortality<T> {
|
||||
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
client: &ClientBase<T>,
|
||||
client: ClientBase<T>,
|
||||
other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CheckMortality {
|
||||
@@ -286,7 +286,7 @@ impl<T: Config> ExtrinsicParams<T> for ChargeAssetTxPayment<T> {
|
||||
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
_client: &ClientBase<T>,
|
||||
_client: ClientBase<T>,
|
||||
other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(ChargeAssetTxPayment {
|
||||
@@ -344,7 +344,7 @@ impl<T: Config> ExtrinsicParams<T> for ChargeTransactionPayment {
|
||||
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
_client: &ClientBase<T>,
|
||||
_client: ClientBase<T>,
|
||||
other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(ChargeTransactionPayment {
|
||||
@@ -388,7 +388,7 @@ macro_rules! impl_tuples {
|
||||
|
||||
fn new(
|
||||
nonce: u64,
|
||||
client: &ClientBase<T>,
|
||||
client: ClientBase<T>,
|
||||
other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
let metadata = client.metadata();
|
||||
@@ -405,7 +405,7 @@ macro_rules! impl_tuples {
|
||||
}
|
||||
// Break and record as soon as we find a match:
|
||||
if $ident::matches(e.identifier(), e.extra_ty(), types) {
|
||||
let ext = $ident::new(nonce, client, other_params.$index)?;
|
||||
let ext = $ident::new(nonce, client.clone(), other_params.$index)?;
|
||||
let boxed_ext: Box<dyn ExtrinsicParamsEncoder> = Box::new(ext);
|
||||
exts_by_index.insert(idx, boxed_ext);
|
||||
break
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
use super::{Config, DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder, Hasher, Header};
|
||||
pub use crate::utils::{AccountId32, MultiAddress, MultiSignature};
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use codec::{Decode, Encode};
|
||||
pub use primitive_types::{H256, U256};
|
||||
@@ -289,10 +288,7 @@ impl From<U256> for NumberOrHex {
|
||||
}
|
||||
}
|
||||
|
||||
/// A quick helper to encode some bytes to hex.
|
||||
fn to_hex(bytes: impl AsRef<[u8]>) -> String {
|
||||
alloc::format!("0x{}", hex::encode(bytes.as_ref()))
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
@@ -52,7 +52,7 @@ pub fn get_constant<Address: ConstantAddress>(
|
||||
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
|
||||
&mut constant.value(),
|
||||
constant.ty(),
|
||||
&metadata,
|
||||
metadata,
|
||||
)?;
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn get_custom_value<Address: CustomValueAddress<IsDecodable = Yes> + ?Sized>
|
||||
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
|
||||
&mut custom_value.bytes(),
|
||||
custom_value.type_id(),
|
||||
&metadata,
|
||||
metadata,
|
||||
)?;
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
+1
-7
@@ -33,14 +33,8 @@ pub use config::{
|
||||
pub use metadata::Metadata;
|
||||
pub use signer::Signer;
|
||||
pub use storage::StorageAddress;
|
||||
pub use utils::{AccountId32, MultiAddress, MultiSignature, H160, H256, H512};
|
||||
pub use utils::{AccountId32, MultiAddress, MultiSignature, H160, H256, H512, Yes, to_hex};
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
mod marker {
|
||||
/// A unit marker struct signalling that some property is true
|
||||
pub struct Yes;
|
||||
}
|
||||
|
||||
pub use marker::Yes;
|
||||
|
||||
@@ -78,3 +78,11 @@ unsafe impl<T> Sync for PhantomDataSendSync<T> {}
|
||||
/// with collections like BTreeMap. This has the same type params
|
||||
/// as `BTreeMap` which allows us to easily swap the two during codegen.
|
||||
pub type KeyedVec<K, V> = Vec<(K, V)>;
|
||||
|
||||
/// A unit marker struct signalling that some property is true
|
||||
pub struct Yes;
|
||||
|
||||
/// A quick helper to encode some bytes to hex.
|
||||
pub fn to_hex(bytes: impl AsRef<[u8]>) -> String {
|
||||
alloc::format!("0x{}", hex::encode(bytes.as_ref()))
|
||||
}
|
||||
@@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
};
|
||||
|
||||
// 2. A runtime version (system_version constant on a Substrate node has these):
|
||||
let runtime_version = subxt::backend::RuntimeVersion {
|
||||
let runtime_version = subxt_core::RuntimeVersion {
|
||||
spec_version: 9370,
|
||||
transaction_version: 20,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#![allow(missing_docs)]
|
||||
use codec::Encode;
|
||||
use subxt::client::OfflineClientT;
|
||||
use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder, ExtrinsicParamsError};
|
||||
use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder};
|
||||
use subxt_core::error::ExtrinsicParamsError;
|
||||
use subxt_signer::sr25519::dev;
|
||||
|
||||
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
|
||||
|
||||
@@ -3,11 +3,11 @@ use codec::Encode;
|
||||
use scale_encode::EncodeAsType;
|
||||
use scale_info::PortableRegistry;
|
||||
use subxt::client::OfflineClientT;
|
||||
use subxt::config::signed_extensions;
|
||||
use subxt::config::{
|
||||
Config, DefaultExtrinsicParamsBuilder, ExtrinsicParams, ExtrinsicParamsEncoder,
|
||||
ExtrinsicParamsError,
|
||||
};
|
||||
use subxt_core::config::signed_extensions;
|
||||
use subxt_core::error::ExtrinsicParamsError;
|
||||
use subxt_signer::sr25519::dev;
|
||||
|
||||
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
|
||||
@@ -60,9 +60,9 @@ impl<T: Config> signed_extensions::SignedExtension<T> for CustomSignedExtension
|
||||
impl<T: Config> ExtrinsicParams<T> for CustomSignedExtension {
|
||||
type OtherParams = ();
|
||||
|
||||
fn new<Client: OfflineClientT<T>>(
|
||||
fn new(
|
||||
_nonce: u64,
|
||||
_client: Client,
|
||||
_client: subxt_core::ClientBase,
|
||||
_other_params: Self::OtherParams,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CustomSignedExtension)
|
||||
|
||||
@@ -10,7 +10,7 @@ use codec::Decode;
|
||||
use derivative::Derivative;
|
||||
use primitive_types::U256;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use subxt_core::metadata::Metadata;
|
||||
use subxt_core::{metadata::Metadata, to_hex};
|
||||
|
||||
/// An interface to call the legacy RPC methods. This interface is instantiated with
|
||||
/// some `T: Config` trait which determines some of the types that the RPC methods will
|
||||
@@ -656,11 +656,6 @@ impl From<U256> for NumberOrHex {
|
||||
}
|
||||
}
|
||||
|
||||
/// A quick helper to encode some bytes to hex.
|
||||
fn to_hex(bytes: impl AsRef<[u8]>) -> String {
|
||||
format!("0x{}", hex::encode(bytes.as_ref()))
|
||||
}
|
||||
|
||||
/// Hex-serialized shim for `Vec<u8>`.
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Hash, PartialOrd, Ord, Debug)]
|
||||
pub struct Bytes(#[serde(with = "impl_serde::serialize")] pub Vec<u8>);
|
||||
|
||||
@@ -14,6 +14,7 @@ use futures::{Stream, StreamExt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::task::Poll;
|
||||
use subxt_core::to_hex;
|
||||
|
||||
/// An interface to call the unstable RPC methods. This interface is instantiated with
|
||||
/// some `T: Config` trait which determines some of the types that the RPC methods will
|
||||
@@ -739,10 +740,6 @@ impl From<Vec<u8>> for Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_hex(bytes: impl AsRef<[u8]>) -> String {
|
||||
format!("0x{}", hex::encode(bytes.as_ref()))
|
||||
}
|
||||
|
||||
/// Attempt to deserialize either a string or integer into an integer.
|
||||
/// See <https://github.com/paritytech/json-rpc-interface-spec/issues/83>
|
||||
pub(crate) mod unsigned_number_as_string {
|
||||
|
||||
@@ -118,7 +118,7 @@ impl<T: Config> LightClient<T> {
|
||||
// traits to use these things:
|
||||
|
||||
/// Return the [`subxt_core::metadata`] used in this client.
|
||||
fn metadata(&self) -> subxt_core::metadata {
|
||||
fn metadata(&self) -> subxt_core::Metadata {
|
||||
self.client.metadata()
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ impl<T: Config> LightClient<T> {
|
||||
}
|
||||
|
||||
/// Return the runtime version.
|
||||
fn runtime_version(&self) -> crate::backend::RuntimeVersion {
|
||||
fn runtime_version(&self) -> subxt_core::RuntimeVersion {
|
||||
self.client.runtime_version()
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ impl<T: Config> OnlineClientT<T> for LightClient<T> {
|
||||
}
|
||||
|
||||
impl<T: Config> OfflineClientT<T> for LightClient<T> {
|
||||
fn metadata(&self) -> subxt_core::metadata {
|
||||
fn metadata(&self) -> subxt_core::Metadata {
|
||||
self.metadata()
|
||||
}
|
||||
|
||||
@@ -188,7 +188,11 @@ impl<T: Config> OfflineClientT<T> for LightClient<T> {
|
||||
self.genesis_hash()
|
||||
}
|
||||
|
||||
fn runtime_version(&self) -> crate::backend::RuntimeVersion {
|
||||
fn runtime_version(&self) -> subxt_core::RuntimeVersion {
|
||||
self.runtime_version()
|
||||
}
|
||||
|
||||
fn base(&self) -> subxt_core::ClientBase<T> {
|
||||
self.client.base()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
};
|
||||
use derivative::Derivative;
|
||||
use futures::future;
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
use subxt_core::{ClientBase, RuntimeVersion};
|
||||
|
||||
|
||||
@@ -3,14 +3,9 @@
|
||||
// see LICENSE for license details.
|
||||
|
||||
use super::ConstantAddress;
|
||||
use crate::{
|
||||
client::OfflineClientT,
|
||||
error::{Error, MetadataError},
|
||||
Config,
|
||||
};
|
||||
use crate::{client::OfflineClientT, error::Error, Config};
|
||||
|
||||
use derivative::Derivative;
|
||||
use subxt_core::metadata::DecodeWithMetadata;
|
||||
|
||||
/// A client for accessing constants.
|
||||
#[derive(Derivative)]
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
//! This module provides the entry points to create dynamic
|
||||
//! transactions, storage and constant lookups.
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
use scale_decode::DecodeAsType;
|
||||
use subxt_core::metadata::{DecodeWithMetadata, Metadata};
|
||||
|
||||
pub use scale_value::{At, Value};
|
||||
|
||||
/// A [`scale_value::Value`] type endowed with contextual information
|
||||
/// regarding what type was used to decode each part of it. This implements
|
||||
/// [`subxt_core::metadata::DecodeWithMetadata`], and is used as a return type
|
||||
/// for dynamic requests.
|
||||
pub type DecodedValue = scale_value::Value<scale_value::scale::TypeId>;
|
||||
|
||||
// Submit dynamic transactions.
|
||||
pub use crate::tx::dynamic as tx;
|
||||
|
||||
// Lookup constants dynamically.
|
||||
pub use crate::constants::dynamic as constant;
|
||||
|
||||
// Lookup storage values dynamically.
|
||||
pub use crate::storage::dynamic as storage;
|
||||
|
||||
// Execute runtime API function call dynamically.
|
||||
pub use crate::runtime_api::dynamic as runtime_api_call;
|
||||
+4
-5
@@ -47,7 +47,6 @@ pub mod blocks;
|
||||
pub mod client;
|
||||
pub mod constants;
|
||||
pub mod custom_values;
|
||||
pub mod dynamic;
|
||||
pub mod error;
|
||||
pub mod events;
|
||||
pub mod runtime_api;
|
||||
@@ -66,10 +65,10 @@ pub use crate::{
|
||||
error::Error,
|
||||
};
|
||||
|
||||
pub use subxt_core::config;
|
||||
pub use subxt_core::config::{Config, PolkadotConfig, SubstrateConfig};
|
||||
|
||||
use subxt_core::metadata::Metadata;
|
||||
// pub use subxt_core::config;
|
||||
// pub use subxt_core::config::{Config, PolkadotConfig, SubstrateConfig};
|
||||
// pub use subxt_core::dynamic;
|
||||
pub use subxt_core::*;
|
||||
|
||||
/// Re-export external crates that are made use of in the subxt API.
|
||||
pub mod ext {
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ macro_rules! cfg_jsonrpsee_web {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) use {cfg_feature, cfg_jsonrpsee, cfg_substrate_compat, cfg_unstable_light_client};
|
||||
pub(crate) use {cfg_feature, cfg_jsonrpsee, cfg_unstable_light_client};
|
||||
|
||||
// Only used by light-client.
|
||||
#[allow(unused)]
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
//! additional and signed extra parameters are used when constructing an extrinsic, and is a part
|
||||
//! of the chain configuration (see [`crate::config::Config`]).
|
||||
|
||||
use crate::macros::cfg_substrate_compat;
|
||||
|
||||
mod tx_client;
|
||||
mod tx_progress;
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
|
||||
// 3. Construct our custom additional/extra params.
|
||||
let additional_and_extra_params = <T::ExtrinsicParams as ExtrinsicParams<T>>::new(
|
||||
account_nonce,
|
||||
&self.client.base(),
|
||||
self.client.base(),
|
||||
other_params,
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user