mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 08:37:56 +00:00
Use primitive-types crate to unify Parity Ethereum primitives (#1187)
* Unify primitive types with parity-ethereum * Update primtive-types patch version * Fix merge issue * Add necessary fixed-hash features * Fix node-primitives compile * Reexport impl_serde::serialize as bytes to avoid path changes
This commit is contained in:
@@ -16,65 +16,7 @@
|
||||
|
||||
//! A fixed hash type.
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use bytes;
|
||||
|
||||
macro_rules! impl_rest {
|
||||
($name: ident, $len: expr) => {
|
||||
#[cfg(feature = "std")]
|
||||
impl Serialize for $name {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
bytes::serialize(&self.0, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<'de> Deserialize<'de> for $name {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
||||
bytes::deserialize_check_len(deserializer, bytes::ExpectedLen::Exact($len))
|
||||
.map(|x| $name::from_slice(&x))
|
||||
}
|
||||
}
|
||||
|
||||
impl ::codec::Encode for $name {
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
impl ::codec::Decode for $name {
|
||||
fn decode<I: ::codec::Input>(input: &mut I) -> Option<Self> {
|
||||
<[u8; $len] as ::codec::Decode>::decode(input).map($name)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl From<u64> for $name {
|
||||
fn from(val: u64) -> Self {
|
||||
Self::from_low_u64_be(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
construct_fixed_hash!{
|
||||
/// Fixed-size uninterpreted hash type with 20 bytes (160 bits) size.
|
||||
pub struct H160(20);
|
||||
}
|
||||
construct_fixed_hash!{
|
||||
/// Fixed-size uninterpreted hash type with 32 bytes (256 bits) size.
|
||||
pub struct H256(32);
|
||||
}
|
||||
construct_fixed_hash!{
|
||||
/// Fixed-size uninterpreted hash type with 64 bytes (512 bits) size.
|
||||
pub struct H512(64);
|
||||
}
|
||||
|
||||
impl_rest!(H160, 20);
|
||||
impl_rest!(H256, 32);
|
||||
impl_rest!(H512, 64);
|
||||
pub use primitive_types::{H160, H256, H512};
|
||||
|
||||
/// Hash conversion. Used to convert between unbound associated hash types in traits,
|
||||
/// implemented by the same hash type.
|
||||
|
||||
Reference in New Issue
Block a user