use unc_account_id::AccountId;
use unc_gas::UncGas;
use unc_primitives::views::{ChunkHeaderView, ChunkView};
use crate::types::{Gas, ShardId, UncToken};
use crate::{BlockHeight, CryptoHash};
#[derive(Debug, Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct Chunk {
pub author: AccountId,
pub header: ChunkHeader,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[non_exhaustive]
pub struct ChunkHeader {
pub chunk_hash: CryptoHash,
pub prev_block_hash: CryptoHash,
pub height_created: BlockHeight,
pub height_included: BlockHeight,
pub shard_id: ShardId,
pub gas_used: Gas,
pub gas_limit: Gas,
pub balance_burnt: UncToken,
pub tx_root: CryptoHash,
pub outcome_root: CryptoHash,
pub prev_state_root: CryptoHash,
pub outgoing_receipts_root: CryptoHash,
pub encoded_merkle_root: CryptoHash,
pub encoded_length: u64,
}
impl From<ChunkView> for Chunk {
fn from(view: ChunkView) -> Self {
Self {
author: view.author,
header: view.header.into(),
}
}
}
impl From<ChunkHeaderView> for ChunkHeader {
fn from(view: ChunkHeaderView) -> Self {
Self {
chunk_hash: view.chunk_hash.into(),
prev_block_hash: view.prev_block_hash.into(),
height_created: view.height_created,
height_included: view.height_included,
shard_id: view.shard_id,
gas_used: UncGas::from_gas(view.gas_used),
gas_limit: UncGas::from_gas(view.gas_limit),
balance_burnt: UncToken::from_attounc(view.balance_burnt),
tx_root: view.tx_root.into(),
outcome_root: view.outcome_root.into(),
prev_state_root: view.prev_state_root.into(),
outgoing_receipts_root: view.outgoing_receipts_root.into(),
encoded_merkle_root: view.encoded_merkle_root.into(),
encoded_length: view.encoded_length,
}
}
}
impl Chunk {
pub fn hash(&self) -> &CryptoHash {
&self.header.chunk_hash
}
pub fn shard_id(&self) -> ShardId {
self.header.shard_id
}
}