Convert Public to CryptoTypePublicPair (#6014)

* Tabify code

* Implement CryptoTypePublicPair in app_crypto

* Cleanup redundancy

* Introduce to_public_crypto_pair to Public trait

* Implement method for test
This commit is contained in:
Rakan Alhneiti
2020-05-13 19:44:54 +02:00
committed by GitHub
parent daf8cf0600
commit 6bdfae2bcb
8 changed files with 52 additions and 50 deletions
@@ -262,6 +262,10 @@ macro_rules! app_crypto_public_common {
impl $crate::Public for Public {
fn from_slice(x: &[u8]) -> Self { Self(<$public>::from_slice(x)) }
fn to_public_crypto_pair(&self) -> $crate::CryptoTypePublicPair {
$crate::CryptoTypePublicPair($crypto_type, self.to_raw_vec())
}
}
impl $crate::AppPublic for Public {
@@ -298,6 +302,21 @@ macro_rules! app_crypto_public_common {
<$public as $crate::RuntimePublic>::to_raw_vec(&self.0)
}
}
impl From<Public> for $crate::CryptoTypePublicPair {
fn from(key: Public) -> Self {
(&key).into()
}
}
impl From<&Public> for $crate::CryptoTypePublicPair {
fn from(key: &Public) -> Self {
$crate::CryptoTypePublicPair(
$crypto_type,
$crate::Public::to_raw_vec(key),
)
}
}
}
}