-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblockchain.cpp
More file actions
52 lines (37 loc) · 1.19 KB
/
blockchain.cpp
File metadata and controls
52 lines (37 loc) · 1.19 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
//Isaac Mejía F.
#include"blockchain.hpp"
Blockchain::Blockchain(){
std::ifstream data("blockchain.txt");
std::string datax2;
//data. ? blockchain.push_back(this->newGenesis()) : recover_blockchain("blockchain.txt");
}
void Blockchain::addBlock(const std::string data){
block blockprev = this->blockchain[blockchain.size()-1];
block blockNext(data, blockprev.getHash());
blockchain.push_back(blockNext);
}
block Blockchain::newGenesis(){
return block("BLOQUE GENESIS", "");
}
std::ostream& operator<<(std::ostream& os, Blockchain b){
os<<"{ \n";
for(size_t i=0; i<b.blockchain.size();++i){
os<<"BLOQUE NUMERO: "<<i<<std::endl;
os<<b.blockchain[i]<<",\n\n";
}
os<<"} \n";
return os;
}
void Blockchain::save_blockchain(Blockchain blockchain){
std::ofstream l("Blockchain.txt");
l<<blockchain;
}
void Blockchain::recover_blockchain(const std::string file){
std::ifstream blockchain_file(file);
std::string temp_storage;
while(!blockchain_file.eof()){
blockchain_file>>temp_storage;
}
std::cout<<temp_storage<<std::endl;
blockchain_file.close();
}