Skip to content
This repository was archived by the owner on Dec 5, 2020. It is now read-only.
Open
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
31 changes: 22 additions & 9 deletions src/bitpaywalletclient/bpwalletclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ bool BitPayWalletClient::GetFeeLevels()
return false;

long httpStatusCode = 0;
if (SendRequest("get", "https://www.digitalbitbox.com/fees/levels.json?r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode, false)) {
// we could read our "internal" fees
feeLevelsObject.read(response);
if (response.size() > 10 && feeLevelsObject.isArray()) {
return true;
}
}

response.clear();
httpStatusCode = 0;
if (!SendRequest("get", "/v1/feelevels/?network=livenet&r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode))
return false;

Expand Down Expand Up @@ -605,7 +615,7 @@ int64_t BitPayWalletClient::GetFeeForPriority(int prio)
}
}

return 2000; //default fallback feerate
return 0; //don't use a fallback fee, abort at this point
}

bool BitPayWalletClient::GetWallets(std::string& response)
Expand All @@ -631,7 +641,7 @@ bool BitPayWalletClient::GetTransactionHistory(std::string& response)
return false;

long httpStatusCode = 0;
if (!SendRequest("get", "/v1/txhistory/?limit=50&r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode))
if (!SendRequest("get", "/v1/txhistory/?r="+std::to_string(CheapRandom()), "{}", response, httpStatusCode))
return false;

if (httpStatusCode != 200)
Expand Down Expand Up @@ -1102,7 +1112,8 @@ bool BitPayWalletClient::SendRequest(const std::string& method,
const std::string& url,
const std::string& args,
std::string& responseOut,
long& httpcodeOut)
long& httpcodeOut,
bool bws)
{
CURL* curl;
CURLcode res;
Expand All @@ -1114,18 +1125,20 @@ bool BitPayWalletClient::SendRequest(const std::string& method,
if (curl) {
struct curl_slist* chunk = NULL;
std::string hashOut;
std::string signature = SignRequest(method, url, args, hashOut);
if (signature.empty()) {
std::string signature = bws ? SignRequest(method, url, args, hashOut) : "";
if (signature.empty() && bws) {
BP_LOG_MSG("SignRequest failed.");
DBB::LogPrintDebug("SignRequest failed.", "");
success = false;
} else {
chunk = curl_slist_append(chunk, ("x-identity: " + GetCopayerId()).c_str()); //requestPubKey).c_str());
chunk = curl_slist_append(chunk, ("x-signature: " + signature).c_str());
chunk = curl_slist_append(chunk, ("x-client-version: dbb-1.0.0"));
if (bws) {
chunk = curl_slist_append(chunk, ("x-identity: " + GetCopayerId()).c_str()); //requestPubKey).c_str());
chunk = curl_slist_append(chunk, ("x-signature: " + signature).c_str());
chunk = curl_slist_append(chunk, ("x-client-version: dbb-1.0.0"));
}
chunk = curl_slist_append(chunk, "Content-Type: application/json");
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
curl_easy_setopt(curl, CURLOPT_URL, (baseURL + url).c_str());
curl_easy_setopt(curl, CURLOPT_URL, (bws ? (baseURL + url) : url).c_str());
if (method == "post")
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, args.c_str());

Expand Down
3 changes: 2 additions & 1 deletion src/bitpaywalletclient/bpwalletclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class BitPayWalletClient
const std::string& url,
const std::string& args,
std::string& responseOut,
long& httpStatusCodeOut);
long& httpStatusCodeOut,
bool bws = true);

//!set the master extended public key
void setMasterPubKey(const std::string& xPubKey);
Expand Down
23 changes: 14 additions & 9 deletions src/qt/dbb_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2159,17 +2159,22 @@ void DBBDaemonGui::createTxProposalPressed()
std::string errorOut;

int64_t fee = singleWallet->client.GetFeeForPriority(this->ui->feeLevel->currentIndex());

if (!singleWallet->client.CreatePaymentProposal(this->ui->sendToAddress->text().toStdString(), amount, fee, proposalOut, errorOut)) {
if (fee == 0) {
emit changeNetLoading(false);
emit shouldHideModalInfo();
emit shouldShowAlert("Error", QString::fromStdString(errorOut));
}
else
{
emit changeNetLoading(false);
emit shouldUpdateModalInfo(tr("Start Signing Process"));
emit createTxProposalDone(singleWallet, "", proposalOut);
emit shouldShowAlert("Error", tr("Could not estimate fees. Make sure you are online."));
} else {
if (!singleWallet->client.CreatePaymentProposal(this->ui->sendToAddress->text().toStdString(), amount, fee, proposalOut, errorOut)) {
emit changeNetLoading(false);
emit shouldHideModalInfo();
emit shouldShowAlert("Error", QString::fromStdString(errorOut));
}
else
{
emit changeNetLoading(false);
emit shouldUpdateModalInfo(tr("Start Signing Process"));
emit createTxProposalDone(singleWallet, "", proposalOut);
}
}

thread->completed();
Expand Down