Skip to content

Commit 015a8ea

Browse files
authored
Merge pull request #920 from evoskuil/master
Fix unstranded handling in address completion, simplify.
2 parents a0e7f00 + 62eca6b commit 015a8ea

File tree

3 files changed

+38
-62
lines changed

3 files changed

+38
-62
lines changed

include/bitcoin/node/protocols/protocol_explore.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,17 @@ class BCN_API protocol_explore
148148
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
149149

150150
private:
151-
using balance_handler = std::function<void(code, uint8_t, uint64_t)>;
152-
using address_handler = std::function<void(code, uint8_t,
153-
database::outpoints&&)>;
154-
155151
void do_get_address(uint8_t media, bool turbo,
156-
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
152+
const system::hash_cptr& hash) NOEXCEPT;
157153
void do_get_address_confirmed(uint8_t media, bool turbo,
158-
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
159-
void do_get_address_unconfirmed(uint8_t media, bool turbo,
160-
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
154+
const system::hash_cptr& hash) NOEXCEPT;
155+
////void do_get_address_unconfirmed(uint8_t media, bool turbo,
156+
//// const system::hash_cptr& hash) NOEXCEPT;
161157
void complete_get_address(const code& ec, uint8_t media,
162158
const database::outpoints& set) NOEXCEPT;
163159

164160
void do_get_address_balance(uint8_t media, bool turbo,
165-
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT;
161+
const system::hash_cptr& hash) NOEXCEPT;
166162
void complete_get_address_balance(const code& ec, uint8_t media,
167163
const uint64_t balance) NOEXCEPT;
168164

src/parse/query.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@ bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
8787
return true;
8888
}
8989

90-
////if (contains(accepts, json) || format == "json")
91-
////{
92-
//// params["media"] = to_value(json);
93-
//// return true;
94-
////}
95-
96-
// Default to json.
97-
params["media"] = to_value(json);
98-
return true;
90+
////// Default format to json.
91+
////params["media"] = to_value(json);
92+
////return true;
93+
94+
if (contains(accepts, json) || format == "json")
95+
{
96+
params["media"] = to_value(json);
97+
return true;
98+
}
99+
100+
return false;
99101
}
100102

101103
BC_POP_WARNING()

src/protocols/protocol_explore.cpp

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -943,24 +943,20 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
943943
return true;
944944
}
945945

946-
address_handler complete = BIND(complete_get_address, _1, _2, _3);
947-
PARALLEL(do_get_address, media, turbo, hash, std::move(complete));
946+
PARALLEL(do_get_address, media, turbo, hash);
948947
return true;
949948
}
950949

951950
// private
952951
void protocol_explore::do_get_address(uint8_t media, bool turbo,
953-
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
952+
const hash_cptr& hash) NOEXCEPT
954953
{
955-
outpoints set{};
956-
if (const auto ec = archive().get_address_outputs(stopping_, set,
957-
*hash, turbo))
958-
{
959-
handler(ec, {}, {});
960-
return;
961-
}
954+
BC_ASSERT(!stranded());
962955

963-
handler(network::error::success, media, std::move(set));
956+
outpoints set{};
957+
const auto& query = archive();
958+
const auto ec = query.get_address_outputs(stopping_, set, *hash, turbo);
959+
POST(complete_get_address, ec, media, std::move(set));
964960
}
965961

966962
// This is shared by the three get_address... methods.
@@ -1017,24 +1013,20 @@ bool protocol_explore::handle_get_address_confirmed(const code& ec,
10171013
return true;
10181014
}
10191015

1020-
address_handler complete = BIND(complete_get_address, _1, _2, _3);
1021-
PARALLEL(do_get_address_confirmed, media, turbo, hash, std::move(complete));
1016+
PARALLEL(do_get_address_confirmed, media, turbo, hash);
10221017
return true;
10231018
}
10241019

10251020
// private
10261021
void protocol_explore::do_get_address_confirmed(uint8_t media, bool turbo,
1027-
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
1022+
const hash_cptr& hash) NOEXCEPT
10281023
{
1029-
outpoints set{};
1030-
if (const auto ec = archive().get_confirmed_unspent_outputs(stopping_,
1031-
set, *hash, turbo))
1032-
{
1033-
handler(ec, {}, {});
1034-
return;
1035-
}
1024+
BC_ASSERT(!stranded());
10361025

1037-
handler(network::error::success, media, std::move(set));
1026+
outpoints set{};
1027+
const auto& query = archive();
1028+
auto ec = query.get_confirmed_unspent_outputs(stopping_, set, *hash, turbo);
1029+
POST(complete_get_address, ec, media, std::move(set));
10381030
}
10391031

10401032
// handle_get_address_unconfirmed
@@ -1050,16 +1042,6 @@ bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
10501042
// TODO: there are currently no unconfirmed txs.
10511043
send_not_implemented();
10521044
return true;
1053-
1054-
////address_handler complete = BIND(complete_get_address, _1, _2, _3);
1055-
////PARALLEL(do_get_address_unconfirmed, media, turbo, hash, std::move(complete));
1056-
////return true;
1057-
}
1058-
1059-
void protocol_explore::do_get_address_unconfirmed(uint8_t media, bool,
1060-
const system::hash_cptr&, const address_handler& handler) NOEXCEPT
1061-
{
1062-
handler(network::error::success, media, {});
10631045
}
10641046

10651047
// handle_get_address_balance
@@ -1079,31 +1061,27 @@ bool protocol_explore::handle_get_address_balance(const code& ec,
10791061
return true;
10801062
}
10811063

1082-
balance_handler complete = BIND(complete_get_address_balance, _1, _2, _3);
1083-
PARALLEL(do_get_address_balance, media, turbo, hash, std::move(complete));
1064+
PARALLEL(do_get_address_balance, media, turbo, hash);
10841065
return true;
10851066
}
10861067

10871068
void protocol_explore::do_get_address_balance(uint8_t media, bool turbo,
1088-
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT
1069+
const system::hash_cptr& hash) NOEXCEPT
10891070
{
1090-
uint64_t balance{};
1091-
if (const auto ec = archive().get_confirmed_balance(stopping_, balance,
1092-
*hash, turbo))
1093-
{
1094-
handler(ec, {}, {});
1095-
return;
1096-
}
1071+
BC_ASSERT(!stranded());
10971072

1098-
handler(network::error::success, media, balance);
1073+
uint64_t balance{};
1074+
const auto& query = archive();
1075+
auto ec = query.get_confirmed_balance(stopping_, balance, *hash, turbo);
1076+
POST(complete_get_address_balance, ec, media, balance);
10991077
}
11001078

11011079
void protocol_explore::complete_get_address_balance(const code& ec,
11021080
uint8_t media, uint64_t balance) NOEXCEPT
11031081
{
11041082
BC_ASSERT(stranded());
11051083

1106-
// This suppresses the error response resulting from cancelation.
1084+
// Suppresses cancelation error response.
11071085
if (stopped())
11081086
return;
11091087

0 commit comments

Comments
 (0)