Skip to content

Commit 36adef1

Browse files
authored
Merge pull request #14 from bahadirbb/master
Added importAddress function
2 parents 8e5fc7a + 9408c58 commit 36adef1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/bitcoinapi/bitcoinapi.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ using std::string;
3131
using std::vector;
3232

3333

34-
BitcoinAPI::BitcoinAPI(const string& user, const string& password, const string& host, int port)
34+
BitcoinAPI::BitcoinAPI(const string& user, const string& password, const string& host, int port, int httpTimeout)
3535
: httpClient(new HttpClient("http://" + user + ":" + password + "@" + host + ":" + IntegerToString(port))),
3636
client(new Client(*httpClient, JSONRPC_CLIENT_V1))
3737
{
38-
httpClient->SetTimeout(50000);
38+
httpClient->SetTimeout(httpTimeout);
3939
}
4040

4141
BitcoinAPI::~BitcoinAPI()
@@ -291,6 +291,15 @@ void BitcoinAPI::importprivkey(const string& bitcoinprivkey, const string& label
291291
sendcommand(command, params);
292292
}
293293

294+
void BitcoinAPI::importAddress(const string& address, const string& account, bool rescan) {
295+
string command = "importaddress";
296+
Value params, result;
297+
params.append(address);
298+
params.append(account);
299+
params.append(rescan);
300+
sendcommand(command, params);
301+
}
302+
294303
string BitcoinAPI::addmultisigaddress(int nrequired, const vector<string>& keys) {
295304
string command = "addmultisigaddress";
296305
Value params, result;
@@ -428,6 +437,18 @@ double BitcoinAPI::getbalance(const string& account, int minconf) {
428437
return result.asDouble();
429438
}
430439

440+
double BitcoinAPI::getbalance(const string& account, int minconf, bool includeWatchOnly) {
441+
string command = "getbalance";
442+
Value params, result;
443+
params.append(account);
444+
params.append(minconf);
445+
params.append(includeWatchOnly);
446+
result = sendcommand(command, params);
447+
448+
return result.asDouble();
449+
}
450+
451+
431452
double BitcoinAPI::getunconfirmedbalance() {
432453
string command = "getunconfirmedbalance";
433454
Value params, result;

src/bitcoinapi/bitcoinapi.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BitcoinAPI
2525

2626
public:
2727
/* === Constructor and Destructor === */
28-
BitcoinAPI(const std::string& user, const std::string& password, const std::string& host, int port);
28+
BitcoinAPI(const std::string& user, const std::string& password, const std::string& host, int port, int httpTimeout);
2929
~BitcoinAPI();
3030

3131
/* === Auxiliary functions === */
@@ -53,6 +53,7 @@ class BitcoinAPI
5353
std::string dumpprivkey(const std::string& bitcoinaddress);
5454
void importprivkey(const std::string& bitcoinprivkey);
5555
void importprivkey(const std::string& bitcoinprivkey, const std::string& label, bool rescan = true);
56+
void importAddress(const std::string& address, const std::string& account, bool rescan);
5657

5758
std::string addmultisigaddress(int nrequired, const std::vector<std::string>& keys);
5859
std::string addmultisigaddress(int nrequired, const std::vector<std::string>& keys, const std::string& account);
@@ -74,6 +75,7 @@ class BitcoinAPI
7475
/* === Accounting === */
7576
double getbalance();
7677
double getbalance(const std::string& account, int minconf = 1);
78+
double getbalance(const std::string& account, int minconf = 1, bool includeWatchOnly = false);
7779
double getunconfirmedbalance();
7880

7981
double getreceivedbyaccount(const std::string& account, int minconf = 1);

0 commit comments

Comments
 (0)