-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.h
More file actions
39 lines (31 loc) · 1.2 KB
/
Block.h
File metadata and controls
39 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef BLOCK_H
#define BLOCK_H
#include <string>
#include <ctime>
class Block {
public:
// Constructor
Block(std::string previousHash, std::string sender, std::string receiver, double amount,std::string hsh,int non);
Block(std::string previousHash, std::string sender, std::string receiver, double amount);
// Getters for block information
std::string getHash() const;
std::string getPreviousHash() const;
std::string getTransactionData() const;
int getNonce() const;
// Mining and hash functions
void mineBlock(int difficulty);
void recalculateHash();
void setPreviousHash(std::string prevHash){
previousHash = prevHash;
} // Function to recalculate the block's hash if needed
private:
std::string previousHash; // Hash of the previous block
std::string sender; // Transaction sender
std::string receiver; // Transaction receiver
double amount; // Transaction amount
time_t timestamp; // Block timestamp
int nonce; // Nonce value for mining
std::string hash; // Current block's hash
std::string calculateHash(); // Calculate the block's hash based on data
};
#endif