mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 20:57:59 +00:00
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:
@@ -23,27 +23,13 @@ use sp_std::vec::Vec;
|
||||
pub use sp_core::ed25519::*;
|
||||
|
||||
mod app {
|
||||
use sp_core::crypto::{CryptoTypePublicPair, Public as TraitPublic};
|
||||
use sp_core::testing::ED25519;
|
||||
use sp_core::ed25519::CRYPTO_ID;
|
||||
|
||||
crate::app_crypto!(super, ED25519);
|
||||
|
||||
impl crate::traits::BoundToRuntimeAppPublic for Public {
|
||||
type Public = Self;
|
||||
}
|
||||
|
||||
impl From<Public> for CryptoTypePublicPair {
|
||||
fn from(key: Public) -> Self {
|
||||
(&key).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Public> for CryptoTypePublicPair {
|
||||
fn from(key: &Public) -> Self {
|
||||
CryptoTypePublicPair(CRYPTO_ID, key.to_raw_vec())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use app::{Public as AppPublic, Signature as AppSignature};
|
||||
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,27 +23,13 @@ use sp_std::vec::Vec;
|
||||
pub use sp_core::sr25519::*;
|
||||
|
||||
mod app {
|
||||
use sp_core::crypto::{CryptoTypePublicPair, Public as TraitPublic};
|
||||
use sp_core::testing::SR25519;
|
||||
use sp_core::sr25519::CRYPTO_ID;
|
||||
|
||||
crate::app_crypto!(super, SR25519);
|
||||
|
||||
impl crate::traits::BoundToRuntimeAppPublic for Public {
|
||||
type Public = Self;
|
||||
}
|
||||
|
||||
impl From<Public> for CryptoTypePublicPair {
|
||||
fn from(key: Public) -> Self {
|
||||
(&key).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Public> for CryptoTypePublicPair {
|
||||
fn from(key: &Public) -> Self {
|
||||
CryptoTypePublicPair(CRYPTO_ID, key.to_raw_vec())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use app::{Public as AppPublic, Signature as AppSignature};
|
||||
|
||||
Reference in New Issue
Block a user