-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathblock.cpp
More file actions
40 lines (31 loc) · 846 Bytes
/
block.cpp
File metadata and controls
40 lines (31 loc) · 846 Bytes
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
40
#include "block.h"
Block::Block(std::string _preBlockHash,std::list<Transaction> _transactionList)
{
this->preBlockHash = _preBlockHash;
this->transactionList = _transactionList;
this->blockHash= generateHash();
}
std::string Block::generateHash()
{
std::string message = preBlockHash;
// Fetching transaction data
for(Transaction transaction: transactionList)
{
message += transaction.toString();
}
// Hashing the message
std::hash<std::string> hasher;
return std::to_string(hasher(message));
}
std::string Block::getHash()
{
return (std::string)this->blockHash;
}
std::string Block::getPreHash()
{
return this->preBlockHash;
}
std::list<Transaction> Block::getTransactionList()
{
return this->transactionList;
}