Projects Inventory

Simulation of Blockchain Technology Gaming Project in C++

Explanation

  1. Headers:
    • <iostream>: For input and output operations.
    • <vector>: For using the std::vector container.
    • <string>: For using the std::string class.
    • <sstream>: For string stream operations.
    • Advertisement
    • <iomanip>: For formatting output.
    • <openssl/sha.h>: For SHA256 hashing. (You need OpenSSL library installed.)
  2. Function sha256:
    • Parameters:
      • const string& input: The input string to hash.
    • Functionality:
      • Computes the SHA256 hash of the input string.
      • Returns the hash as a hexadecimal string.
  3. Block Class:
    • Attributes:
      • previousHash: The hash of the previous block.
      • Advertisement
      • hash: The hash of the current block.
      • data: The data stored in the block.
      • timestamp: The time when the block was created.
    • Constructor:
      • Initializes the block with data and the hash of the previous block.
    • Methods:
      • string calculateHash() const: Computes the hash of the block using SHA256.
  4. Blockchain Class:
    • Attributes:
      • chain: A vector of Block objects representing the blockchain.
    • Methods:
      • Blockchain(): Creates the genesis block and initializes the blockchain.
      • void addBlock(const Block& newBlock): Adds a new block to the blockchain.
      • void printChain() const: Prints the details of each block in the blockchain.
  5. Main Function:
    • Initialization:
      • Creates a Blockchain object.
    • Adding Blocks:
      • Adds several blocks to the blockchain with sample data.
    • Display:
      • Prints the contents of the blockchain.

Notes:

Exit mobile version