-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.cpp
More file actions
52 lines (43 loc) · 1.03 KB
/
Block.cpp
File metadata and controls
52 lines (43 loc) · 1.03 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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Block.h"
BlockRecord::BlockRecord(std::string _data)
:data(_data), previousHash(), randomSeed(), winningHash(), timeStampString(), next(nullptr)
{
}
int BlockRecord::verifyBlock()
{
return 0;
}
std::string BlockRecord::createHashValue()
{
return std::string("hello world");
}
std::ostream& operator << (std::ostream& os, BlockRecord const& br)
{
os << br.data;
return os;
}
BlockChain::~BlockChain()
{
for(unsigned i = 0; i < __BlockChain.size(); i++)
{
delete __BlockChain[i];
}
}
BlockRecord *BlockChain::getHead()
{
if(__BlockChain.size() == 0) return nullptr;
else return __BlockChain[__BlockChain.size() - 1];
}
void BlockChain::appendBlock(BlockRecord *newBlock)
{
__BlockChain.push_back(newBlock);
}
std::ostream& operator << (std::ostream& os, BlockChain const& bc)
{
for(unsigned i = 0; i < bc.__BlockChain.size() - 1; i++)
{
os << *(bc.__BlockChain[i]) << ", ";
}
os << *(bc.__BlockChain[bc.__BlockChain.size() - 1]) << std::endl;
return os;
}