pub struct Metadata<N>where
N: Network,{ /* private fields */ }Implementations§
Source§impl<N> Metadata<N>where
N: Network,
impl<N> Metadata<N>where
N: Network,
Sourcepub fn verify(
&self,
expected_round: u64,
expected_height: u32,
expected_cumulative_weight: u128,
expected_cumulative_proof_target: u128,
expected_coinbase_target: u64,
expected_proof_target: u64,
expected_last_coinbase_target: u64,
expected_last_coinbase_timestamp: i64,
expected_timestamp: i64,
current_timestamp: i64,
) -> Result<(), Error>
pub fn verify( &self, expected_round: u64, expected_height: u32, expected_cumulative_weight: u128, expected_cumulative_proof_target: u128, expected_coinbase_target: u64, expected_proof_target: u64, expected_last_coinbase_target: u64, expected_last_coinbase_timestamp: i64, expected_timestamp: i64, current_timestamp: i64, ) -> Result<(), Error>
Ensures the block metadata is correct.
Source§impl<N> Metadata<N>where
N: Network,
impl<N> Metadata<N>where
N: Network,
Sourcepub fn new(
network: u16,
round: u64,
height: u32,
cumulative_weight: u128,
cumulative_proof_target: u128,
coinbase_target: u64,
proof_target: u64,
last_coinbase_target: u64,
last_coinbase_timestamp: i64,
timestamp: i64,
) -> Result<Metadata<N>, Error>
pub fn new( network: u16, round: u64, height: u32, cumulative_weight: u128, cumulative_proof_target: u128, coinbase_target: u64, proof_target: u64, last_coinbase_target: u64, last_coinbase_timestamp: i64, timestamp: i64, ) -> Result<Metadata<N>, Error>
Initializes a new metadata with the given inputs.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns true if the block metadata is well-formed.
Consider using Self::check_validity to get more information on invalid block metadata.
Sourcepub fn check_validity(&self) -> Result<(), Error>
pub fn check_validity(&self) -> Result<(), Error>
Returns Ok(()) if the block metadata is well-formed, and error describing (one of) the problem(s) in the block header.
Source§impl<N> Metadata<N>where
N: Network,
impl<N> Metadata<N>where
N: Network,
Sourcepub const fn cumulative_weight(&self) -> u128
pub const fn cumulative_weight(&self) -> u128
Returns the cumulative weight for this block.
Sourcepub const fn cumulative_proof_target(&self) -> u128
pub const fn cumulative_proof_target(&self) -> u128
Returns the cumulative proof target for this block.
Sourcepub const fn coinbase_target(&self) -> u64
pub const fn coinbase_target(&self) -> u64
Returns the coinbase target for this block.
Sourcepub const fn proof_target(&self) -> u64
pub const fn proof_target(&self) -> u64
Returns the proof target for this block.
Sourcepub const fn last_coinbase_target(&self) -> u64
pub const fn last_coinbase_target(&self) -> u64
Returns the coinbase target of the last coinbase.
Sourcepub const fn last_coinbase_timestamp(&self) -> i64
pub const fn last_coinbase_timestamp(&self) -> i64
Returns the block timestamp of the last coinbase.
Trait Implementations§
Source§impl<'de, N> Deserialize<'de> for Metadata<N>where
N: Network,
impl<'de, N> Deserialize<'de> for Metadata<N>where
N: Network,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Metadata<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Metadata<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserializes the metadata from a JSON-string or buffer.
Source§impl<N> FromBytes for Metadata<N>where
N: Network,
impl<N> FromBytes for Metadata<N>where
N: Network,
Source§fn read_le<R>(reader: R) -> Result<Metadata<N>, Error>where
R: Read,
fn read_le<R>(reader: R) -> Result<Metadata<N>, Error>where
R: Read,
Reads the metadata from the buffer.
Source§fn from_bytes_le(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
fn from_bytes_le(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
Self from a byte array in little-endian order.Source§fn from_bytes_le_unchecked(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
fn from_bytes_le_unchecked(bytes: &[u8]) -> Result<Self, Error>where
Self: Sized,
Self::from_bytes_le but avoids costly checks.
This shall only be called when deserializing from a trusted source, such as local storage. Read moreSource§fn read_le_unchecked<R>(reader: R) -> Result<Self, Error>
fn read_le_unchecked<R>(reader: R) -> Result<Self, Error>
Self::read_le but avoids costly checks.
This shall only be called when deserializing from a trusted source, such as local storage. Read moreSource§impl<N> Serialize for Metadata<N>where
N: Network,
impl<N> Serialize for Metadata<N>where
N: Network,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serializes the metadata to a JSON-string or buffer.
Source§impl<N> ToBits for Metadata<N>where
N: Network,
impl<N> ToBits for Metadata<N>where
N: Network,
Source§fn write_bits_le(&self, vec: &mut Vec<bool>)
fn write_bits_le(&self, vec: &mut Vec<bool>)
Returns the little-endian bits of the metadata.
Source§fn write_bits_be(&self, vec: &mut Vec<bool>)
fn write_bits_be(&self, vec: &mut Vec<bool>)
Returns the big-endian bits of the metadata.
Source§fn to_bits_le(&self) -> Vec<bool>
fn to_bits_le(&self) -> Vec<bool>
self as a boolean array in little-endian order.Source§fn to_bits_be(&self) -> Vec<bool>
fn to_bits_be(&self) -> Vec<bool>
self as a boolean array in big-endian order.impl<N> Copy for Metadata<N>
impl<N> Eq for Metadata<N>
impl<N> StructuralPartialEq for Metadata<N>where
N: Network,
Auto Trait Implementations§
impl<N> Freeze for Metadata<N>
impl<N> RefUnwindSafe for Metadata<N>where
N: RefUnwindSafe,
impl<N> Send for Metadata<N>
impl<N> Sync for Metadata<N>
impl<N> Unpin for Metadata<N>where
N: Unpin,
impl<N> UnwindSafe for Metadata<N>where
N: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
fn take_from_value<D>(
value: &mut Value,
field: &str,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.