-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadLastBlock.cpp
More file actions
63 lines (45 loc) · 1.33 KB
/
readLastBlock.cpp
File metadata and controls
63 lines (45 loc) · 1.33 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
53
54
55
56
57
58
59
60
61
62
63
string readLastBlock(string ruta, bool display){
vector <vector<string>> blockChain;
vector <string> blockParams;
ifstream file;
string frase;
string line;
int arreglo[6];
int blockCount = 0;
int lineCount = -1;
string prevHash;
file.open(ruta, ios::app);
vector <string> types = {"senderID", "amount", "receiverID", "blockProof", "prevHash", "blockHash"};
if(file.is_open()){
while(getline(file, line, ',')){
lineCount += 1;
line = replaceLines(line, ' ');
if(lineCount >= 6){
blockCount += 1;
blockChain.push_back(blockParams);
lineCount = 0;
blockParams = {};
}else{
}
blockParams.push_back(line);
}
cout << "Total Proof: " <<blockCount << endl;
cout << "Params: " << lineCount << endl << endl;
for(int j = blockCount-1; j < blockChain.size();j++){
for(int i = 0; i < 6; i++){
if(display){
cout << types[i] << ": ";
cout << blockChain[j][i] << endl;
}
if(i == 4){
prevHash = blockChain [j][i];
}
}
if(display){
cout << endl;
}
}
}
file.close();
return prevHash;
}