diff --git a/primitives/account/src/lib.rs b/primitives/account/src/lib.rs index 9e2d10c4e2..48118b69b8 100644 --- a/primitives/account/src/lib.rs +++ b/primitives/account/src/lib.rs @@ -84,6 +84,19 @@ impl From<[u8; 20]> for AccountId20 { } } +impl<'a> TryFrom<&'a [u8]> for AccountId20 { + type Error = (); + fn try_from(x: &'a [u8]) -> Result { + if x.len() == 20 { + let mut data = [0; 20]; + data.copy_from_slice(x); + Ok(AccountId20(data)) + } else { + Err(()) + } + } +} + impl From for [u8; 20] { fn from(val: AccountId20) -> Self { val.0 @@ -102,6 +115,30 @@ impl From for H160 { } } +impl AsRef<[u8]> for AccountId20 { + fn as_ref(&self) -> &[u8] { + &self.0[..] + } +} + +impl AsMut<[u8]> for AccountId20 { + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0[..] + } +} + +impl AsRef<[u8; 20]> for AccountId20 { + fn as_ref(&self) -> &[u8; 20] { + &self.0 + } +} + +impl AsMut<[u8; 20]> for AccountId20 { + fn as_mut(&mut self) -> &mut [u8; 20] { + &mut self.0 + } +} + impl From for AccountId20 { fn from(pk: ecdsa::Public) -> Self { let decompressed = libsecp256k1::PublicKey::parse_compressed(&pk.0) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 74ab61d7ba..b541575816 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,8 +1,5 @@ [toolchain] -# Stable -#channel = "1.70.0" # rustc 1.70.0 (84c898d65 2023-05-13) -# Nightly -channel = "nightly-2023-05-23" # rustc 1.71.0-nightly (8b4b20836 2023-05-22) -components = ["rustfmt", "clippy"] -targets = ["wasm32-unknown-unknown"] -profile = "minimal" +channel = "nightly-2023-05-22" +components = ["cargo", "clippy", "rustc", "rustfmt", "rust-src"] +profile = "minimal" +targets = ["wasm32-unknown-unknown"]