pub struct Block {
pub header: BlockHeader,
pub body: TransactionBody,
}
Expand description
A block as expressed in the Mimblewimble protocol. The reward is non-explicit, assumed to be deducible from block height (similar to bitcoin’s schedule) and expressed as a global transaction fee (added v.H), additive to the total of fees ever collected.
Fields§
§header: BlockHeader
The header with metadata and commitments to the rest of the data
body: TransactionBody
The body - inputs/outputs/kernels
Implementations§
source§impl Block
impl Block
sourcepub fn new(
prev: &BlockHeader,
txs: &[Transaction],
difficulty: Difficulty,
reward_output: (Output, TxKernel)
) -> Result<Block, Error>
pub fn new( prev: &BlockHeader, txs: &[Transaction], difficulty: Difficulty, reward_output: (Output, TxKernel) ) -> Result<Block, Error>
Builds a new block from the header of the previous block, a vector of transactions and the private key that will receive the reward. Checks that all transactions are valid and calculates the Merkle tree.
TODO - Move this somewhere where only tests will use it. *** Only used in tests. ***
sourcepub fn hydrate_from(
cb: CompactBlock,
txs: &[Transaction]
) -> Result<Block, Error>
pub fn hydrate_from( cb: CompactBlock, txs: &[Transaction] ) -> Result<Block, Error>
Hydrate a block from a compact block. Note: caller must validate the block themselves, we do not validate it here.
sourcepub fn with_header(header: BlockHeader) -> Block
pub fn with_header(header: BlockHeader) -> Block
Build a new empty block from a specified header
sourcepub fn from_reward(
prev: &BlockHeader,
txs: &[Transaction],
reward_out: Output,
reward_kern: TxKernel,
difficulty: Difficulty
) -> Result<Block, Error>
pub fn from_reward( prev: &BlockHeader, txs: &[Transaction], reward_out: Output, reward_kern: TxKernel, difficulty: Difficulty ) -> Result<Block, Error>
Builds a new block ready to mine from the header of the previous block, a vector of transactions and the reward information. Checks that all transactions are valid and calculates the Merkle tree.
sourcepub fn with_reward(self, reward_out: Output, reward_kern: TxKernel) -> Block
pub fn with_reward(self, reward_out: Output, reward_kern: TxKernel) -> Block
Consumes this block and returns a new block with the coinbase output and kernels added
sourcepub fn total_fees(&self) -> u64
pub fn total_fees(&self) -> u64
Sum of all fees (inputs less outputs) in the block
sourcepub fn validate_read(&self) -> Result<(), Error>
pub fn validate_read(&self) -> Result<(), Error>
“Lightweight” validation that we can perform quickly during read/deserialization. Subset of full validation that skips expensive verification steps, specifically -
- rangeproof verification (on the body)
- kernel signature verification (on the body)
- coinbase sum verification
- kernel sum verification
sourcepub fn validate(&self, prev_kernel_offset: &BlindingFactor) -> Result<(), Error>
pub fn validate(&self, prev_kernel_offset: &BlindingFactor) -> Result<(), Error>
Validates all the elements in a block that can be checked without additional data. Includes commitment sums and kernels, Merkle trees, reward, etc.
sourcepub fn verify_coinbase(&self) -> Result<(), Error>
pub fn verify_coinbase(&self) -> Result<(), Error>
Validate the coinbase.body.outputs generated by miners. Check the sum of coinbase-marked outputs match the sum of coinbase-marked kernels accounting for fees.
Trait Implementations§
source§impl Committed for Block
impl Committed for Block
Provides all information from a block that allows the calculation of total Pedersen commitment.
source§fn inputs_committed(&self) -> Vec<Commitment>
fn inputs_committed(&self) -> Vec<Commitment>
source§fn outputs_committed(&self) -> Vec<Commitment>
fn outputs_committed(&self) -> Vec<Commitment>
source§fn kernels_committed(&self) -> Vec<Commitment>
fn kernels_committed(&self) -> Vec<Commitment>
source§fn sum_kernel_excesses(
&self,
offset: &BlindingFactor
) -> Result<(Commitment, Commitment), Error>
fn sum_kernel_excesses( &self, offset: &BlindingFactor ) -> Result<(Commitment, Commitment), Error>
source§fn sum_commitments(&self, overage: i64) -> Result<Commitment, Error>
fn sum_commitments(&self, overage: i64) -> Result<Commitment, Error>
source§fn verify_kernel_sums(
&self,
overage: i64,
kernel_offset: BlindingFactor
) -> Result<(Commitment, Commitment), Error>
fn verify_kernel_sums( &self, overage: i64, kernel_offset: BlindingFactor ) -> Result<(Commitment, Commitment), Error>
source§impl Default for Block
impl Default for Block
Default properties for a block, everything zeroed out and empty vectors.
source§impl From<Block> for CompactBlock
impl From<Block> for CompactBlock
source§impl From<UntrustedBlock> for Block
impl From<UntrustedBlock> for Block
source§fn from(block: UntrustedBlock) -> Self
fn from(block: UntrustedBlock) -> Self
source§impl Readable for Block
impl Readable for Block
Implementation of Readable for a block, defines how to read a full block from a binary stream.
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin 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
source§impl<H> ShortIdentifiable for Hwhere
H: Hashed,
impl<H> ShortIdentifiable for Hwhere
H: Hashed,
source§fn short_id(&self, hash: &Hash, nonce: u64) -> ShortId
fn short_id(&self, hash: &Hash, nonce: u64) -> ShortId
Generate a short_id via the following -
- extract k0/k1 from block_hash hashed with the nonce (first two u64
values) * initialize a siphasher24 with k0/k1
- self.hash() passing in the siphasher24 instance
- drop the 2 most significant bytes (to return a 6 byte short_id)