Skip to content

Commit

Permalink
impl From<AccountId20> for Location (#1472)
Browse files Browse the repository at this point in the history
* from AccountId20 to Location

* suggestion
  • Loading branch information
ozgunozerk committed Jul 26, 2024
1 parent d200959 commit 42b4490
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions primitives/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -39,6 +42,7 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-runtime-interface/std",
"xcm/std",
]
serde = [
"dep:serde",
Expand Down
13 changes: 13 additions & 0 deletions primitives/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -171,6 +174,16 @@ impl From<AccountId32> for AccountId20 {
}
}

impl From<AccountId20> 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))]
Expand Down

0 comments on commit 42b4490

Please sign in to comment.