Skip to content

Commit

Permalink
Fix some bugs in ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKrawisz committed Sep 22, 2024
1 parent f5c8551 commit eeda0e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions include/gigamonkey/pay/ARC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace Gigamonkey::ARC {
// or if the body is JSON and Content-Type is set to "application/json"
bool valid () const;

operator bool () const {
return !is_error ();
}

using net::HTTP::response::response;
response (net::HTTP::response &&);

Expand Down Expand Up @@ -326,7 +330,7 @@ namespace Gigamonkey::ARC {
}

string inline health::reason (const JSON &j) {
auto r = j["reason"];
auto &r = j["reason"];
if (!r.is_string ()) return "";
return r;
}
Expand Down Expand Up @@ -384,8 +388,8 @@ namespace Gigamonkey::ARC {
}

Gigamonkey::satoshis_per_byte inline policy::mining_fee (const JSON &j) {
auto spb = j["miningFee"];
return Gigamonkey::satoshis_per_byte {Bitcoin::satoshi {int64 (j["satoshis"])}, j["bytes"]};
auto &spb = j["miningFee"];
return Gigamonkey::satoshis_per_byte {Bitcoin::satoshi {int64 (spb["satoshis"])}, spb["bytes"]};
}

bool inline policy_response::valid () const {
Expand Down
3 changes: 1 addition & 2 deletions src/gigamonkey/pay/ARC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace Gigamonkey::ARC {

maybe<JSON> response::body (const net::HTTP::response &r) {
try {
JSON j = JSON::parse (r.Body);
if (success::valid (j)) return j;
return JSON::parse (r.Body);
} catch (JSON::exception) {}
return {};
}
Expand Down

0 comments on commit eeda0e7

Please sign in to comment.