@@ -64,18 +64,47 @@ struct MempoolFiles {
64
64
{}
65
65
};
66
66
67
+ class SaferBitcoinApi {
68
+ std::string username;
69
+ std::string password;
70
+ std::string address;
71
+ int port;
72
+ BitcoinAPI bitcoinAPI;
73
+
74
+ public:
75
+
76
+ SaferBitcoinApi (std::string username_, std::string password_, std::string address_, int port_) :
77
+ username (std::move(username_)), password(std::move(password_)), address(std::move(address_)), port(port_), bitcoinAPI(username, password, address, port) {}
78
+
79
+ std::vector<chaintip_t > getchaintips () {
80
+ return bitcoinAPI.getchaintips ();
81
+ }
82
+
83
+ int getblockcount () {
84
+ return bitcoinAPI.getblockcount ();
85
+ }
86
+
87
+ std::string getpreviousblockhash (const std::string& blockhash) {
88
+ return bitcoinAPI.getpreviousblockhash (blockhash);
89
+ }
90
+
91
+ std::vector<std::string> getrawmempool () {
92
+ return bitcoinAPI.getrawmempool ();
93
+ }
94
+ };
95
+
67
96
class MempoolRecorder {
68
97
blocksci::Blockchain chain;
69
98
blocksci::BlockHeight lastHeight;
70
99
std::unordered_map<blocksci::uint256, MempoolRecord, std::hash<blocksci::uint256>> mempool;
71
- BitcoinAPI &bitcoinAPI;
100
+ SaferBitcoinApi &bitcoinAPI;
72
101
73
102
MempoolFiles files;
74
103
std::unordered_map<std::string, std::pair<BlockRecord, int >> blocksSeen;
75
104
76
105
static constexpr int heightCutoff = 1000 ;
77
106
public:
78
- MempoolRecorder (const std::string &dataLocation, BitcoinAPI &bitcoinAPI_) :
107
+ MempoolRecorder (const std::string &dataLocation, SaferBitcoinApi &bitcoinAPI_) :
79
108
chain (dataLocation),
80
109
lastHeight (static_cast <int >(chain.size())),
81
110
bitcoinAPI (bitcoinAPI_),
@@ -114,7 +143,7 @@ class MempoolRecorder {
114
143
updateTxTimes (system_clock::to_time_t (system_clock::now ()));
115
144
updateBlockTimes (system_clock::to_time_t (system_clock::now ()));
116
145
} catch (BitcoinException& e){
117
- std::cout << " Failed to update mempool with error: " << e.what () << std::endl;
146
+ std::cerr << " Failed to update mempool with error: " << e.what () << std::endl;
118
147
}
119
148
}
120
149
@@ -203,7 +232,7 @@ int main(int argc, char * argv[]) {
203
232
return 0 ;
204
233
}
205
234
206
- BitcoinAPI bitcoinAPI{username, password, address, port};
235
+ SaferBitcoinApi bitcoinAPI{username, password, address, port};
207
236
208
237
auto connected = false ;
209
238
while (!connected) {
0 commit comments