Skip to content

Commit 265d619

Browse files
author
Krzysztof Okupski
committed
Restructured wallet class
1 parent 4af2745 commit 265d619

File tree

2 files changed

+44
-62
lines changed

2 files changed

+44
-62
lines changed

src/api/wallet.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,50 @@ using std::string;
2323
using std::vector;
2424

2525

26+
BitcoinAPI::BitcoinAPI(){
27+
conn = {};
28+
}
29+
30+
BitcoinAPI::BitcoinAPI(const string& user, const string& password, const string& host, int port){
31+
conn.user = user;
32+
conn.password = password;
33+
conn.host = host;
34+
conn.port = port;
35+
conn.url = "http://"+ conn.user + ":"+ conn.password + "@" + conn.host + ":" + NumberToString(conn.port);
36+
}
37+
38+
bool BitcoinAPI::IsInit(){
39+
return !(conn.user.empty() || conn.password.empty() || conn.host.empty() || conn.port == 0);
40+
}
41+
42+
string BitcoinAPI::NumberToString (int number){
43+
std::ostringstream ss;
44+
ss << number;
45+
return ss.str();
46+
}
47+
48+
int BitcoinAPI::StringToNumber (const string &text){
49+
std::istringstream ss(text);
50+
int result;
51+
return ss >> result ? result : 0;
52+
}
53+
54+
Value BitcoinAPI::sendcommand(const string& command, const Value& params){
55+
Value result;
56+
Client c(new HttpClient(conn.url));
57+
58+
try{
59+
result = c.CallMethod(command, params);
60+
}
61+
catch (JsonRpcException& e){
62+
BitcoinException err(e.GetCode(), e.GetMessage());
63+
throw err;
64+
}
65+
66+
return result;
67+
}
68+
69+
2670
/* === General functions === */
2771
getinfo_t BitcoinAPI::getinfo() {
2872
string command = "getinfo";

src/api/walletbase.cpp

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)