mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 04:28:01 +00:00
Allow for remapping type parameters in type substitutions (#735)
* feat!: Allow for remapping type parameters in type substitutions * chore: cargo fmt * chore: cargo clippy * chore: Remove some old code * a little tidy * address comment nit Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
use subxt::utils::AccountId32;
|
||||
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
pub struct CustomAddress(u16);
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
pub struct Generic<T>(T);
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
pub struct Second<T, U>(U, PhantomData<T>);
|
||||
|
||||
#[subxt::subxt(
|
||||
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
|
||||
substitute_type(
|
||||
type = "sp_runtime::multiaddress::MultiAddress<A, B>",
|
||||
with = "crate::CustomAddress"
|
||||
)
|
||||
)]
|
||||
pub mod node_runtime {}
|
||||
|
||||
#[subxt::subxt(
|
||||
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
|
||||
substitute_type(
|
||||
type = "sp_runtime::multiaddress::MultiAddress<A, B>",
|
||||
with = "crate::Generic<A>"
|
||||
)
|
||||
)]
|
||||
pub mod node_runtime2 {}
|
||||
|
||||
#[subxt::subxt(
|
||||
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
|
||||
substitute_type(
|
||||
type = "sp_runtime::multiaddress::MultiAddress<A, B>",
|
||||
with = "crate::Generic<B>"
|
||||
)
|
||||
)]
|
||||
pub mod node_runtime3 {}
|
||||
|
||||
#[subxt::subxt(
|
||||
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
|
||||
substitute_type(
|
||||
type = "sp_runtime::multiaddress::MultiAddress<A, B>",
|
||||
with = "crate::Second<B, A>"
|
||||
)
|
||||
)]
|
||||
pub mod node_runtime4 {}
|
||||
|
||||
fn main() {
|
||||
// We assume Polkadot's config of MultiAddress<AccountId32, ()> here
|
||||
let _ = node_runtime::tx()
|
||||
.balances()
|
||||
.transfer(CustomAddress(1337), 123);
|
||||
|
||||
let _ = node_runtime2::tx()
|
||||
.balances()
|
||||
.transfer(Generic(AccountId32::from([0x01;32])), 123);
|
||||
|
||||
let _ = node_runtime3::tx()
|
||||
.balances()
|
||||
.transfer(Generic(()), 123);
|
||||
|
||||
let _ = node_runtime4::tx()
|
||||
.balances()
|
||||
.transfer(Second(AccountId32::from([0x01;32]), PhantomData), 123);
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
#[subxt::subxt(runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale")]
|
||||
pub mod node_runtime {
|
||||
#[subxt::subxt(substitute_type = "sp_arithmetic::per_things::Perbill")]
|
||||
use sp_runtime::Perbill;
|
||||
}
|
||||
#[subxt::subxt(
|
||||
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
|
||||
substitute_type(
|
||||
type = "sp_arithmetic::per_things::Perbill",
|
||||
with = "sp_runtime::Perbill"
|
||||
)
|
||||
)]
|
||||
pub mod node_runtime {}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: The substitute path must be a global absolute path; try prefixing with `::` or `crate`
|
||||
--> src/incorrect/substitute_path_not_absolute.rs:4:9
|
||||
--> src/incorrect/substitute_path_not_absolute.rs:5:16
|
||||
|
|
||||
4 | use sp_runtime::Perbill;
|
||||
| ^^^^^^^^^^
|
||||
5 | with = "sp_runtime::Perbill"
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Reference in New Issue
Block a user