-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blockchain.cpp
39 lines (30 loc) · 921 Bytes
/
Blockchain.cpp
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
#include "Blockchain.h"
Blockchain::Blockchain() {
this->latestProposedBlock = nullptr;
this->blockAccepted = false;
}
void Blockchain::addBlock() {
if (!this->blockchain.empty()) {
auto lastBlock = this->blockchain.back();
this->latestProposedBlock->setPreviousHash(lastBlock.getCurrentHash());
}
this->latestProposedBlock->addTransactionsToBlock();
this->blockchain.push_back(*this->latestProposedBlock);
this->blockAccepted = true;
}
bool Blockchain::getBlockAccepted() {
return this->blockAccepted;
}
void Blockchain::setBlockAccepted(bool blockAccepted) {
this->blockAccepted = false;
}
void Blockchain::displayBlockchain() {
cout << "Successfully mined block with hash: " + (this->blockchain.end()-1)->getCurrentHash() << endl;
}
void Blockchain::proposeBlock(Block* block) {
this->latestProposedBlock = block;
}
Block* Blockchain::getProposedBlock()
{
return this->latestProposedBlock;
}