Creating the genesis block
The very first block in a blockchain is called the genesis block. While we haven’t written any code for the blockchain, we would like to create the first block and get things started. The genesis block doesn’t store a previous hash since no block comes before it.
In the block.rs
file, we’ll begin by implementing functions specific to the Block
type. To achieve this, we must create a code block, like so:
impl Block{ // Functions related to the Block type can be implemented here ... }
The impl
keyword in Rust is used to define a set of methods associated with a specific type – in this case, Block
. This block acts as a container for functionality that is directly associated with the block structure, allowing us to define what operations can be performed with or on a block.
Move the new_block
function that we created in the Block section, where we learned how to create a block, to inside the preceding code block and all...