Skip to content

Added importAddress function #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/bitcoinapi/bitcoinapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ using std::string;
using std::vector;


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

BitcoinAPI::~BitcoinAPI()
Expand Down Expand Up @@ -291,6 +291,15 @@ void BitcoinAPI::importprivkey(const string& bitcoinprivkey, const string& label
sendcommand(command, params);
}

void BitcoinAPI::importAddress(const string& address, const string& account, bool rescan) {
string command = "importaddress";
Value params, result;
params.append(address);
params.append(account);
params.append(rescan);
sendcommand(command, params);
}

string BitcoinAPI::addmultisigaddress(int nrequired, const vector<string>& keys) {
string command = "addmultisigaddress";
Value params, result;
Expand Down Expand Up @@ -428,6 +437,18 @@ double BitcoinAPI::getbalance(const string& account, int minconf) {
return result.asDouble();
}

double BitcoinAPI::getbalance(const string& account, int minconf, bool includeWatchOnly) {
string command = "getbalance";
Value params, result;
params.append(account);
params.append(minconf);
params.append(includeWatchOnly);
result = sendcommand(command, params);

return result.asDouble();
}


double BitcoinAPI::getunconfirmedbalance() {
string command = "getunconfirmedbalance";
Value params, result;
Expand Down
4 changes: 3 additions & 1 deletion src/bitcoinapi/bitcoinapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BitcoinAPI

public:
/* === Constructor and Destructor === */
BitcoinAPI(const std::string& user, const std::string& password, const std::string& host, int port);
BitcoinAPI(const std::string& user, const std::string& password, const std::string& host, int port, int httpTimeout);
~BitcoinAPI();

/* === Auxiliary functions === */
Expand Down Expand Up @@ -53,6 +53,7 @@ class BitcoinAPI
std::string dumpprivkey(const std::string& bitcoinaddress);
void importprivkey(const std::string& bitcoinprivkey);
void importprivkey(const std::string& bitcoinprivkey, const std::string& label, bool rescan = true);
void importAddress(const std::string& address, const std::string& account, bool rescan);

std::string addmultisigaddress(int nrequired, const std::vector<std::string>& keys);
std::string addmultisigaddress(int nrequired, const std::vector<std::string>& keys, const std::string& account);
Expand All @@ -74,6 +75,7 @@ class BitcoinAPI
/* === Accounting === */
double getbalance();
double getbalance(const std::string& account, int minconf = 1);
double getbalance(const std::string& account, int minconf = 1, bool includeWatchOnly = false);
double getunconfirmedbalance();

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