Blocks

A block records some or all of the most recent transactions that have not yet entered any prior blocks. Thus, a block is like a page of a ledger or record book.

Computation

What does a block contain:

  • hash – Hash of the current block – 32 byte

  • PoW - Proof of Work - 32 byte

  • Prev_hash - Previous Block hash - 32 byte

  • txes - the contained transactions - N * 32 byte (N is the count of txes)

  • Timestamp - the timestamp of the block - 64bit unsigned integer

  • Sig - the signature of the block - 16384 byte

You can create a new Block by passing in the prev_hash to the constructor. This will create a Block with empty hash, pow, txes and sig fields, the timestamp is set to the current timestamp.

  • add_tx(hash) - adds the transaction hash to the block

  • block_to_blob() - serializes the block, returns a Vec‹u8›

  • block_from_vec(Vec) - Deserialize the block, and returns it

  • hash() - Returns the computed hash for the block

  • close_block(keypair, pow) – closes the block, signs it, and returns the hash for the block

The hash is an SHA3-256 cryptographic hash, which is calculated when close_block is called.

Last updated