-
Notifications
You must be signed in to change notification settings - Fork 1
/
bdb.cpp
87 lines (77 loc) · 2.33 KB
/
bdb.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "bdb.h"
#include "block.h"
#include "id.h"
#include <string.h>
#include <string>
using namespace std;
void printchain(uint8_t *tophash, DB *db) {
printf("******************************\n");
uint8_t tophash_temp[32];
memcpy(tophash_temp, tophash, 32);
RSA *rsa_pub;
DBT key, data;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
uint8_t genesis_hash[32];
memset(genesis_hash, 0x00, 32);
block blk;
while(hashcmp(tophash_temp, genesis_hash)) {
key.data = tophash_temp;
key.size = 32;
data.data = &blk;
data.ulen = sizeof(block);
data.flags = DB_DBT_USERMEM;
if(db->get(db, NULL, &key, &data, 0)==0) {
printf("-------------------------------------------\n");
printf("blk.src: %s\n", blk.src);
printblk(blk);
memcpy(tophash_temp, blk.phash, 32);
}
else {
printf("db->get() returns non-zero\n");
break;
}
}
printf("******************************\n");
}
uint32_t sumOfDiff(uint8_t *tophash, DB *db) {
uint8_t tophash_temp[32];
memcpy(tophash_temp, tophash, 32);
DBT key, data;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
uint8_t genesis_hash[32];
memset(genesis_hash, 0x00, 32);
block blk;
uint32_t sumofdiff = 0x00;
printf("tophash_temp: ");
for(int i = 0; i<32; i++) {
printf("%02x", (tophash_temp[i]));
}
printf("\n");
printf("********************************************\n");
while(hashcmp(tophash_temp, genesis_hash)) {
key.data = tophash_temp;
key.size = 32;
data.data = &blk;
data.ulen = sizeof(block);
data.flags = DB_DBT_USERMEM;
if(db->get(db, NULL, &key, &data, 0)==0) {
//printf("-------------------------------------------\n");
printf("At block with hash:\t");
for(int i=0;i<5;i++) {
printf("%02x", tophash_temp[i]);
}
printf("\n");
sumofdiff++;
printf("Sum of Difficulties:\t%04x\n", sumofdiff);
memcpy(tophash_temp, blk.phash, 32);
}
else {
printf("db->get() returns non-zero\n");
break;
}
}
printf("********************************************\n");
return sumofdiff;
}