use subxt::Error;
use subxt::config::{
Config, DefaultExtrinsicParamsBuilder, DefaultTransactionExtensions, PolkadotConfig,
SubstrateConfig,
};
use subxt_signer::sr25519::dev;
#[subxt::subxt(
runtime_metadata_path = "../artifacts/polkadot_assethub_metadata_small.scale",
derive_for_type(
path = "staging_xcm::v5::location::Location",
derive = "Clone, codec::Encode",
recursive
)
)]
pub mod assethub {}
use assethub::runtime_types::staging_xcm::v5::junctions::Junctions;
use assethub::runtime_types::staging_xcm::v5::location::Location;
#[derive(Debug, Clone, Default)]
pub struct AssetHubConfig(SubstrateConfig);
impl Config for AssetHubConfig {
type Address = <PolkadotConfig as Config>::Address;
type AssetId = Location;
type AccountId = <SubstrateConfig as Config>::AccountId;
type Signature = <SubstrateConfig as Config>::Signature;
type Hasher = <SubstrateConfig as Config>::Hasher;
type Header = <SubstrateConfig as Config>::Header;
type TransactionExtensions = DefaultTransactionExtensions<AssetHubConfig>;
fn genesis_hash(&self) -> Option<subxt::config::HashFor<Self>> {
self.0.genesis_hash()
}
fn legacy_types_for_spec_version<'this>(
&'this self,
spec_version: u32,
) -> Option<scale_info_legacy::TypeRegistrySet<'this>> {
self.0.legacy_types_for_spec_version(spec_version)
}
fn metadata_for_spec_version(&self, spec_version: u32) -> Option<subxt::ArcMetadata> {
self.0.metadata_for_spec_version(spec_version)
}
fn set_metadata_for_spec_version(&self, spec_version: u32, metadata: subxt::ArcMetadata) {
self.0.set_metadata_for_spec_version(spec_version, metadata);
}
fn spec_and_transaction_version_for_block_number(
&self,
block_number: u64,
) -> Option<(u32, u32)> {
self.0
.spec_and_transaction_version_for_block_number(block_number)
}
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let client = subxt::OnlineClient::<AssetHubConfig>::new().await?;
let tx_payload = assethub::tx().system().remark(b"Hello".to_vec());
let location = Location {
parents: 3,
interior: Junctions::Here,
};
let tx_config = DefaultExtrinsicParamsBuilder::<AssetHubConfig>::new()
.tip_of(1234, location)
.build();
let _ = client
.tx()
.await?
.sign_and_submit_then_watch(&tx_payload, &dev::alice(), tx_config)
.await;
Ok(())
}