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: U256Implementations§
Source§impl Block
impl Block
Sourcepub fn new(
offset: u64,
size: u64,
hash_prev: U256,
validator: U256,
nonce: U256,
hash: U256,
) -> Self
pub fn new( offset: u64, size: u64, hash_prev: U256, validator: U256, nonce: U256, hash: U256, ) -> Self
New block.
Sourcepub fn validate(
&self,
transactions: &[Transaction],
block_info_prev: &BlockInfo,
complexity: usize,
state: &State,
senders: &[U256],
) -> UqoinResult<()>
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.
Sourcepub fn build(
block_info_prev: &BlockInfo,
validator: U256,
transactions: &[Transaction],
nonce: U256,
complexity: usize,
state: &State,
senders: &[U256],
) -> UqoinResult<Self>
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.
Sourcepub fn validate_coins(
transactions: &[Transaction],
state: &State,
senders: &[U256],
) -> UqoinResult<()>
👎Deprecated since 0.1.0: use groups and check_unique instead
pub fn validate_coins( transactions: &[Transaction], state: &State, senders: &[U256], ) -> UqoinResult<()>
use groups and check_unique instead
Validate coins. The checks:
- All coins are unique.
- All transactions are valid (see
Transaction::validate_coins()).
Sourcepub fn validate_transactions(
transactions: &[Transaction],
validator: &U256,
state: &State,
senders: &[U256],
) -> UqoinResult<()>
pub fn validate_transactions( transactions: &[Transaction], validator: &U256, state: &State, senders: &[U256], ) -> UqoinResult<()>
Validate transactions. The checks:
- All coins are valid (see
validate_coins). - All transactions can be groupped into groups and extensions.
- Sender of each extension is the validator.
- 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.
Sourcepub fn validate_hash_complexity(
hash: &U256,
size: usize,
complexity: usize,
) -> UqoinResult<()>
pub fn validate_hash_complexity( hash: &U256, size: usize, complexity: usize, ) -> UqoinResult<()>
Validate hash for the certain complexity.
Sourcepub fn calc_msg(
block_hash_prev: &U256,
validator: &U256,
transactions: &[Transaction],
) -> U256
pub fn calc_msg( block_hash_prev: &U256, validator: &U256, transactions: &[Transaction], ) -> U256
calculate block message as hash of the important content.
Sourcepub fn calc_hash(msg: &U256, nonce: &U256) -> U256
pub fn calc_hash(msg: &U256, nonce: &U256) -> U256
Calculate block hash from message and nonce.
Sourcepub fn is_hash_valid(hash_bytes: &[u8], limit_hash_bytes: &[u8]) -> bool
pub fn is_hash_valid(hash_bytes: &[u8], limit_hash_bytes: &[u8]) -> bool
Chech if the hash corresponds to the necessary size.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Block
impl<'de> Deserialize<'de> for Block
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. 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> 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
Mutably borrows from an owned value. Read more