You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a go at trying to create a custom type which implements Config to instantiate an API with, like so:
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct MyConfig;
impl Config for MyConfig {
type Index = <DefaultConfig as Config>::Index;
type BlockNumber = <DefaultConfig as Config>::BlockNumber;
type Hash = <DefaultConfig as Config>::Hash;
type Hashing = <DefaultConfig as Config>::Hashing;
type AccountId = <DefaultConfig as Config>::AccountId;
type Address = <DefaultConfig as Config>::Address;
type Header = <DefaultConfig as Config>::Header;
type Signature = <DefaultConfig as Config>::Signature;
type Extrinsic = <DefaultConfig as Config>::Extrinsic;
}
let api = ClientBuilder::new()
.build()
.await?
.to_runtime_api::<polkadot::RuntimeApi<MyConfig, DefaultExtra<MyConfig>>>();
(I tried this in the examples/transfer_subscribe.rs example).
My custom type uses the same types that DefaultConfig uses, but when I try to compile this example I run into:
error[E0599]: the method `balances` exists for struct `polkadot::TransactionApi<'_, MyConfig, DefaultExtraWithTxPayment<MyConfig, extrinsic::extra::ChargeTransactionPayment<MyConfig>>, system::storage::Account>`, but its trait bounds were not satisfied
--> examples/transfer_subscribe.rs:70:10
|
35 | #[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
| ---------------------------------------------------------------------------
| |
| method `balances` not found for this
| doesn't satisfy `_: subxt::AccountData<MyConfig>`
...
70 | .balances()
| ^^^^^^^^ method cannot be called on `polkadot::TransactionApi<'_, MyConfig, DefaultExtraWithTxPayment<MyConfig, extrinsic::extra::ChargeTransactionPayment<MyConfig>>, system::storage::Account>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`system::storage::Account: subxt::AccountData<MyConfig>`
I believe that the error exists because DefaultConfig is still hardcoded into a bit of the codegen:
pub type DefaultAccountData = self::system::storage::Account;
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: <::subxt::DefaultConfig as ::subxt::Config>::AccountId) -> Self {
Self(account_id)
}
}
This DefaultAccountData type is passed as a type param to TransactionApi as the param A, which expects:
impl<'a, T, E, A> TransactionApi<'a, T, E, A>
where
T: ::subxt::Config,
E: ::subxt::SignedExtra<T>,
A: ::subxt::AccountData<T>,
But of course, DefaultAccountData does not implement AccountData for generic configs; only for the DefaultConfig, which prevents other configs being inserted in its place I believe.
::subxt::AccountData does however require that the types it knows about align with those generated from system::storage::Account, and so it's not a simple case of making the impl more generic.
I'm not entirely sure what the best course of action is here; perhaps expose the type inside system::storage::Account and bound uses of Config such that the account ID types line up? But if that were the fix, then why have AccountId in the config at all if it's a hard requirement in the generated code? Likely I am not understanding the reasoning behind this code properly yet.
The text was updated successfully, but these errors were encountered:
I had a go at trying to create a custom type which implements
Config
to instantiate an API with, like so:(I tried this in the
examples/transfer_subscribe.rs
example).My custom type uses the same types that
DefaultConfig
uses, but when I try to compile this example I run into:I believe that the error exists because
DefaultConfig
is still hardcoded into a bit of the codegen:This
DefaultAccountData
type is passed as a type param toTransactionApi
as the paramA
, which expects:But of course,
DefaultAccountData
does not implementAccountData
for generic configs; only for theDefaultConfig
, which prevents other configs being inserted in its place I believe.::subxt::AccountData
does however require that the types it knows about align with those generated fromsystem::storage::Account
, and so it's not a simple case of making the impl more generic.I'm not entirely sure what the best course of action is here; perhaps expose the type inside
system::storage::Account
and bound uses ofConfig
such that the account ID types line up? But if that were the fix, then why have AccountId in the config at all if it's a hard requirement in the generated code? Likely I am not understanding the reasoning behind this code properly yet.The text was updated successfully, but these errors were encountered: