mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-23 03:47:59 +00:00
Configurable Config and Extra types (#373)
* WIP config * WIP separate default config * Separate trait impls on client * WIP introduce new ApiConfig (to be renamed) trait * Update generated polkadot codegen * Allow configuring Config and Extra types independently * Add extra default configuration * Revert ir parsing of config attr * Add default-features = false to substrate deps * Revert "Add default-features = false to substrate deps" This reverts commit 099d20cd4cbf8000ff938d1dc090ecbc28a5e788.
This commit is contained in:
@@ -68,7 +68,7 @@ pub fn generate_calls(
|
||||
pub fn #fn_name(
|
||||
&self,
|
||||
#( #call_fn_args, )*
|
||||
) -> ::subxt::SubmittableExtrinsic<'a, T, #call_struct_name> {
|
||||
) -> ::subxt::SubmittableExtrinsic<'a, T, E, A, #call_struct_name> {
|
||||
let call = #call_struct_name { #( #call_args, )* };
|
||||
::subxt::SubmittableExtrinsic::new(self.client, call)
|
||||
}
|
||||
@@ -82,16 +82,19 @@ pub fn generate_calls(
|
||||
use super::#types_mod_ident;
|
||||
#( #call_structs )*
|
||||
|
||||
pub struct TransactionApi<'a, T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>> {
|
||||
pub struct TransactionApi<'a, T: ::subxt::Config, E, A> {
|
||||
client: &'a ::subxt::Client<T>,
|
||||
marker: ::core::marker::PhantomData<(E, A)>,
|
||||
}
|
||||
|
||||
impl<'a, T: ::subxt::Config> TransactionApi<'a, T>
|
||||
impl<'a, T, E, A> TransactionApi<'a, T, E, A>
|
||||
where
|
||||
T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>,
|
||||
T: ::subxt::Config,
|
||||
E: ::subxt::SignedExtra<T>,
|
||||
A: ::subxt::AccountData<T>,
|
||||
{
|
||||
pub fn new(client: &'a ::subxt::Client<T>) -> Self {
|
||||
Self { client }
|
||||
Self { client, marker: ::core::marker::PhantomData }
|
||||
}
|
||||
|
||||
#( #call_fns )*
|
||||
|
||||
+27
-44
@@ -152,6 +152,7 @@ impl RuntimeGenerator {
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let modules = pallets_with_mod_names.iter().map(|(pallet, mod_name)| {
|
||||
let calls = if let Some(ref calls) = pallet.calls {
|
||||
calls::generate_calls(&type_gen, pallet, calls, types_mod_ident)
|
||||
@@ -222,76 +223,55 @@ impl RuntimeGenerator {
|
||||
#( #modules )*
|
||||
#types_mod
|
||||
|
||||
/// Default configuration of common types for a target Substrate runtime.
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
pub struct DefaultConfig;
|
||||
/// The default storage entry from which to fetch an account nonce, required for
|
||||
/// constructing a transaction.
|
||||
pub type DefaultAccountData = self::system::storage::Account;
|
||||
|
||||
impl ::subxt::Config for DefaultConfig {
|
||||
type Index = u32;
|
||||
type BlockNumber = u32;
|
||||
type Hash = ::subxt::sp_core::H256;
|
||||
type Hashing = ::subxt::sp_runtime::traits::BlakeTwo256;
|
||||
type AccountId = ::subxt::sp_runtime::AccountId32;
|
||||
type Address = ::subxt::sp_runtime::MultiAddress<Self::AccountId, u32>;
|
||||
type Header = ::subxt::sp_runtime::generic::Header<
|
||||
Self::BlockNumber, ::subxt::sp_runtime::traits::BlakeTwo256
|
||||
>;
|
||||
type Signature = ::subxt::sp_runtime::MultiSignature;
|
||||
type Extrinsic = ::subxt::sp_runtime::OpaqueExtrinsic;
|
||||
}
|
||||
|
||||
impl ::subxt::ExtrinsicExtraData<DefaultConfig> for DefaultConfig {
|
||||
type AccountData = AccountData;
|
||||
type Extra = ::subxt::DefaultExtra<DefaultConfig>;
|
||||
}
|
||||
|
||||
pub type AccountData = self::system::storage::Account;
|
||||
|
||||
impl ::subxt::AccountData<DefaultConfig> for AccountData {
|
||||
fn nonce(result: &<Self as ::subxt::StorageEntry>::Value) -> <DefaultConfig as ::subxt::Config>::Index {
|
||||
impl ::subxt::AccountData<::subxt::DefaultConfig> for DefaultAccountData {
|
||||
fn nonce(result: &<Self as ::subxt::StorageEntry>::Value) -> <::subxt::DefaultConfig as ::subxt::Config>::Index {
|
||||
result.nonce
|
||||
}
|
||||
fn storage_entry(account_id: <DefaultConfig as ::subxt::Config>::AccountId) -> Self {
|
||||
fn storage_entry(account_id: <::subxt::DefaultConfig as ::subxt::Config>::AccountId) -> Self {
|
||||
Self(account_id)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RuntimeApi<T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>> {
|
||||
pub struct RuntimeApi<T: ::subxt::Config, E> {
|
||||
pub client: ::subxt::Client<T>,
|
||||
marker: ::core::marker::PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<T> ::core::convert::From<::subxt::Client<T>> for RuntimeApi<T>
|
||||
impl<T, E> ::core::convert::From<::subxt::Client<T>> for RuntimeApi<T, E>
|
||||
where
|
||||
T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>,
|
||||
T: ::subxt::Config,
|
||||
E: ::subxt::SignedExtra<T>,
|
||||
{
|
||||
fn from(client: ::subxt::Client<T>) -> Self {
|
||||
Self { client }
|
||||
Self { client, marker: ::core::marker::PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> RuntimeApi<T>
|
||||
impl<'a, T, E> RuntimeApi<T, E>
|
||||
where
|
||||
T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>,
|
||||
T: ::subxt::Config,
|
||||
E: ::subxt::SignedExtra<T>,
|
||||
{
|
||||
pub fn storage(&'a self) -> StorageApi<'a, T> {
|
||||
StorageApi { client: &self.client }
|
||||
}
|
||||
|
||||
pub fn tx(&'a self) -> TransactionApi<'a, T> {
|
||||
TransactionApi { client: &self.client }
|
||||
pub fn tx(&'a self) -> TransactionApi<'a, T, E, DefaultAccountData> {
|
||||
TransactionApi { client: &self.client, marker: ::core::marker::PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StorageApi<'a, T>
|
||||
where
|
||||
T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>,
|
||||
{
|
||||
pub struct StorageApi<'a, T: ::subxt::Config> {
|
||||
client: &'a ::subxt::Client<T>,
|
||||
}
|
||||
|
||||
impl<'a, T> StorageApi<'a, T>
|
||||
where
|
||||
T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>,
|
||||
T: ::subxt::Config,
|
||||
{
|
||||
#(
|
||||
pub fn #pallets_with_storage(&self) -> #pallets_with_storage::storage::StorageApi<'a, T> {
|
||||
@@ -300,16 +280,19 @@ impl RuntimeGenerator {
|
||||
)*
|
||||
}
|
||||
|
||||
pub struct TransactionApi<'a, T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>> {
|
||||
pub struct TransactionApi<'a, T: ::subxt::Config, E, A> {
|
||||
client: &'a ::subxt::Client<T>,
|
||||
marker: ::core::marker::PhantomData<(E, A)>,
|
||||
}
|
||||
|
||||
impl<'a, T> TransactionApi<'a, T>
|
||||
impl<'a, T, E, A> TransactionApi<'a, T, E, A>
|
||||
where
|
||||
T: ::subxt::Config + ::subxt::ExtrinsicExtraData<T>,
|
||||
T: ::subxt::Config,
|
||||
E: ::subxt::SignedExtra<T>,
|
||||
A: ::subxt::AccountData<T>,
|
||||
{
|
||||
#(
|
||||
pub fn #pallets_with_calls(&self) -> #pallets_with_calls::calls::TransactionApi<'a, T> {
|
||||
pub fn #pallets_with_calls(&self) -> #pallets_with_calls::calls::TransactionApi<'a, T, E, A> {
|
||||
#pallets_with_calls::calls::TransactionApi::new(self.client)
|
||||
}
|
||||
)*
|
||||
|
||||
Reference in New Issue
Block a user