Skip to main content

Block

Struct Block 

Source
pub struct Block {
    pub offset: u64,
    pub size: u64,
    pub hash_prev: U256,
    pub validator: U256,
    pub nonce: U256,
    pub hash: U256,
}
Expand description

Basic structure for block.

Fields§

§offset: u64§size: u64§hash_prev: U256§validator: U256§nonce: U256§hash: U256

Implementations§

Source§

impl Block

Source

pub fn new( offset: u64, size: u64, hash_prev: U256, validator: U256, nonce: U256, hash: U256, ) -> Self

New block.

Source

pub fn validate( &self, transactions: &[Transaction], block_info_prev: &BlockInfo, complexity: usize, state: &State, senders: &[U256], ) -> UqoinResult<()>

Full validation of the block that includes transactions, info of the previous block, complexity, state between this block and the previous one.

Source

pub fn build( block_info_prev: &BlockInfo, validator: U256, transactions: &[Transaction], nonce: U256, complexity: usize, state: &State, senders: &[U256], ) -> UqoinResult<Self>

Build a new block for the transactions. It validates the final hash.

Source

pub fn validate_coins( transactions: &[Transaction], state: &State, senders: &[U256], ) -> UqoinResult<()>

👎Deprecated since 0.1.0:

use groups and check_unique instead

Validate coins. The checks:

  1. All coins are unique.
  2. All transactions are valid (see Transaction::validate_coins()).
Source

pub fn validate_transactions( transactions: &[Transaction], validator: &U256, state: &State, senders: &[U256], ) -> UqoinResult<()>

Validate transactions. The checks:

  1. All coins are valid (see validate_coins).
  2. All transactions can be groupped into groups and extensions.
  3. Sender of each extension is the validator.
  4. Values of groups and extensions correspond each other. Each group or extension has valid structure after the groupping because they cannot be created invalid due to inner validation.
Source

pub fn validate_hash_complexity( hash: &U256, size: usize, complexity: usize, ) -> UqoinResult<()>

Validate hash for the certain complexity.

Source

pub fn calc_msg( block_hash_prev: &U256, validator: &U256, transactions: &[Transaction], ) -> U256

calculate block message as hash of the important content.

Source

pub fn calc_hash(msg: &U256, nonce: &U256) -> U256

Calculate block hash from message and nonce.

Source

pub fn is_hash_valid(hash_bytes: &[u8], limit_hash_bytes: &[u8]) -> bool

Chech if the hash corresponds to the necessary size.

Source

pub fn mine<R: Rng>( rng: &mut R, block_hash_prev: &U256, validator: &U256, transactions: &[Transaction], complexity: usize, iterations: Option<usize>, ) -> Option<[u8; 32]>

Find correct nonce bytes to mine the block.

Trait Implementations§

Source§

impl Clone for Block

Source§

fn clone(&self) -> Block

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Block

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Block

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Block

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnsafeUnpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V