Skip to content

Commit 4c40521

Browse files
committed
Add handle_get_address_confirmed/unconfirmed/balance.
1 parent 51a0c05 commit 4c40521

File tree

1 file changed

+76
-12
lines changed

1 file changed

+76
-12
lines changed

src/protocols/protocol_explore.cpp

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -992,41 +992,105 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
992992
}
993993

994994
bool protocol_explore::handle_get_address_confirmed(const code& ec,
995-
interface::address_confirmed, uint8_t, uint8_t ,
996-
const hash_cptr& ) NOEXCEPT
995+
interface::address_confirmed, uint8_t, uint8_t media,
996+
const hash_cptr& hash) NOEXCEPT
997997
{
998998
if (stopped(ec))
999999
return false;
10001000

1001-
// TODO.
1001+
const auto& query = archive();
1002+
if (!query.address_enabled())
1003+
{
1004+
send_not_implemented();
1005+
return true;
1006+
}
1007+
1008+
// TODO: post queries to thread (both stopping() and this are stranded).
1009+
1010+
database::output_links outputs{};
1011+
if (!query.to_confirmed_unspent_outputs(stopping_, outputs, *hash))
1012+
{
1013+
send_internal_server_error(database::error::integrity);
1014+
return true;
1015+
}
1016+
1017+
if (outputs.empty())
1018+
{
1019+
send_not_found();
1020+
return true;
1021+
}
1022+
1023+
outpoint_set out{};
1024+
for (const auto& output: outputs)
1025+
out.insert(query.get_spent(output));
1026+
1027+
const auto size = out.size() * chain::outpoint::serialized_size();
1028+
switch (media)
1029+
{
1030+
case data:
1031+
send_chunk(to_bin_array(out, size));
1032+
return true;
1033+
case text:
1034+
send_text(to_hex_array(out, size));
1035+
return true;
1036+
case json:
1037+
send_json(value_from(out), two * size);
1038+
return true;
1039+
}
10021040

1003-
send_not_implemented();
1041+
send_not_found();
10041042
return true;
10051043
}
10061044

10071045
bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
1008-
interface::address_unconfirmed, uint8_t, uint8_t ,
1009-
const hash_cptr& ) NOEXCEPT
1046+
interface::address_unconfirmed, uint8_t, uint8_t, const hash_cptr&) NOEXCEPT
10101047
{
10111048
if (stopped(ec))
10121049
return false;
10131050

1014-
// TODO.
1051+
// TODO: there are currently no unconfirmed txs.
10151052

1016-
send_not_implemented();
1053+
send_not_found();
10171054
return true;
10181055
}
10191056

10201057
bool protocol_explore::handle_get_address_balance(const code& ec,
1021-
interface::address_balance, uint8_t, uint8_t,
1022-
const hash_cptr&) NOEXCEPT
1058+
interface::address_balance, uint8_t, uint8_t media,
1059+
const hash_cptr& hash) NOEXCEPT
10231060
{
10241061
if (stopped(ec))
10251062
return false;
10261063

1027-
// TODO.
1064+
const auto& query = archive();
1065+
if (!query.address_enabled())
1066+
{
1067+
send_not_implemented();
1068+
return true;
1069+
}
1070+
1071+
// TODO: post queries to thread (both stopping() and this are stranded).
1072+
1073+
uint64_t balance{};
1074+
if (!query.get_confirmed_balance(stopping_, balance, *hash))
1075+
{
1076+
send_internal_server_error(database::error::integrity);
1077+
return true;
1078+
}
1079+
1080+
switch (media)
1081+
{
1082+
case data:
1083+
send_chunk(to_little_endian_size(balance));
1084+
return true;
1085+
case text:
1086+
send_text(encode_base16(to_little_endian_size(balance)));
1087+
return true;
1088+
case json:
1089+
send_json(balance, two * sizeof(balance));
1090+
return true;
1091+
}
10281092

1029-
send_not_implemented();
1093+
send_not_found();
10301094
return true;
10311095
}
10321096

0 commit comments

Comments
 (0)