Skip to content

Commit 333091b

Browse files
authored
Merge pull request #907 from evoskuil/master
Integrate optimized address queries.
2 parents 97d1939 + ee4a3ec commit 333091b

File tree

1 file changed

+10
-49
lines changed

1 file changed

+10
-49
lines changed

src/protocols/protocol_explore.cpp

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -955,30 +955,12 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
955955
void protocol_explore::do_get_address(uint8_t media, const hash_cptr& hash,
956956
const address_handler& handler) NOEXCEPT
957957
{
958-
const auto& query = archive();
959-
960-
// TODO: push into database as single call.
961-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
962-
// TODO: change query to return code to differentiate cancel vs. integrity.
963-
database::output_links links{};
964-
if (!query.to_address_outputs(stopping_, links, *hash))
965-
{
966-
handler(network::error::operation_canceled, {}, {});
967-
return;
968-
}
969-
970958
outpoints set{};
971-
for (const auto& link: links)
959+
if (const auto ec = archive().to_address_outputs(stopping_, set, *hash))
972960
{
973-
if (stopping_)
974-
{
975-
handler(network::error::operation_canceled, {}, {});
976-
return;
977-
}
978-
979-
set.insert(query.get_spent(link));
961+
handler(ec, {}, {});
962+
return;
980963
}
981-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
982964

983965
handler(network::error::success, media, std::move(set));
984966
}
@@ -1046,30 +1028,13 @@ bool protocol_explore::handle_get_address_confirmed(const code& ec,
10461028
void protocol_explore::do_get_address_confirmed(uint8_t media,
10471029
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
10481030
{
1049-
const auto& query = archive();
1050-
1051-
// TODO: push into database as single call.
1052-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1053-
// TODO: change query to return code to differentiate cancel vs. integrity.
1054-
database::output_links links{};
1055-
if (!query.to_confirmed_unspent_outputs(stopping_, links, *hash))
1056-
{
1057-
handler(network::error::operation_canceled, {}, {});
1058-
return;
1059-
}
1060-
10611031
outpoints set{};
1062-
for (const auto& link: links)
1032+
if (const auto ec = archive().to_confirmed_unspent_outputs(stopping_, set,
1033+
*hash))
10631034
{
1064-
if (stopping_)
1065-
{
1066-
handler(network::error::operation_canceled, {}, {});
1067-
return;
1068-
}
1069-
1070-
set.insert(query.get_spent(link));
1035+
handler(ec, {}, {});
1036+
return;
10711037
}
1072-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10731038

10741039
handler(network::error::success, media, std::move(set));
10751040
}
@@ -1124,17 +1089,13 @@ bool protocol_explore::handle_get_address_balance(const code& ec,
11241089
void protocol_explore::do_get_address_balance(uint8_t media,
11251090
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT
11261091
{
1127-
const auto& query = archive();
1128-
1129-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1130-
// TODO: change query to return code to differentiate cancel vs. integrity.
11311092
uint64_t balance{};
1132-
if (!query.get_confirmed_balance(stopping_, balance, *hash))
1093+
if (const auto ec = archive().get_confirmed_balance(stopping_, balance,
1094+
*hash))
11331095
{
1134-
send_internal_server_error(database::error::integrity);
1096+
handler(ec, {}, {});
11351097
return;
11361098
}
1137-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11381099

11391100
handler(network::error::success, media, balance);
11401101
}

0 commit comments

Comments
 (0)