From 42b4490f6c6ffdab2cd3a6d4aef419b1c4729f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCn=20=C3=96zerk?= Date: Fri, 26 Jul 2024 09:43:12 +0300 Subject: [PATCH] `impl From for Location` (#1472) * from AccountId20 to Location * suggestion --- Cargo.lock | 1 + primitives/account/Cargo.toml | 4 ++++ primitives/account/src/lib.rs | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5736848654..8f0ff629de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2824,6 +2824,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-runtime-interface 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.12.0)", + "staging-xcm", ] [[package]] diff --git a/primitives/account/Cargo.toml b/primitives/account/Cargo.toml index 80186587f1..cff2294b91 100644 --- a/primitives/account/Cargo.toml +++ b/primitives/account/Cargo.toml @@ -22,6 +22,9 @@ sp-io = { workspace = true } sp-runtime = { workspace = true } sp-runtime-interface = { workspace = true } +# Polkadot / XCM +xcm = { workspace = true } + [dev-dependencies] [features] @@ -39,6 +42,7 @@ std = [ "sp-io/std", "sp-runtime/std", "sp-runtime-interface/std", + "xcm/std", ] serde = [ "dep:serde", diff --git a/primitives/account/src/lib.rs b/primitives/account/src/lib.rs index 97e9c47fd3..b1f1588dcb 100644 --- a/primitives/account/src/lib.rs +++ b/primitives/account/src/lib.rs @@ -31,6 +31,9 @@ use sp_io::hashing::keccak_256; use sp_runtime::MultiSignature; use sp_runtime_interface::pass_by::PassByInner; +// Polkadot / XCM +use xcm::latest::{Junction, Location}; + /// A fully Ethereum-compatible `AccountId`. /// Conforms to H160 address and ECDSA key standards. /// Alternative to H256->H160 mapping. @@ -171,6 +174,16 @@ impl From for AccountId20 { } } +impl From for Location { + fn from(id: AccountId20) -> Self { + Junction::AccountKey20 { + network: None, + key: id.into(), + } + .into() + } +} + #[derive(Clone, Eq, PartialEq)] #[derive(RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]