@@ -40,20 +40,25 @@ using namespace network::messages::peer;
4040using namespace std ::placeholders;
4141using namespace boost ::json;
4242
43- DEFINE_JSON_TO_TAG (point_set)
43+ using inpoint = database::inpoint;
44+ using outpoint = database::outpoint;
45+ using inpoints = database::inpoints;
46+ using outpoints = database::outpoints;
47+
48+ DEFINE_JSON_TO_TAG (inpoints)
4449{
45- point_set out{};
46- for (const auto & point : value.as_array ())
47- out.insert (value_to<chain::point >(point));
50+ inpoints out{};
51+ for (const auto & point: value.as_array ())
52+ out.insert (value_to<inpoint >(point));
4853
4954 return out;
5055}
5156
52- DEFINE_JSON_TO_TAG (outpoint_set )
57+ DEFINE_JSON_TO_TAG (outpoints )
5358{
54- outpoint_set out{};
55- for (const auto & outpoint : value.as_array ())
56- out.insert (value_to<chain:: outpoint>(outpoint ));
59+ outpoints out{};
60+ for (const auto & point : value.as_array ())
61+ out.insert (value_to<outpoint>(point ));
5762
5863 return out;
5964}
@@ -869,17 +874,10 @@ bool protocol_explore::handle_get_output_spender(const code& ec,
869874
870875 const auto & query = archive ();
871876 const chain::point spent{ *hash, index };
872- const auto link = query.to_confirmed_spender (spent);
873- if (link.is_terminal ())
874- {
875- send_not_found ();
876- return true ;
877- }
878-
879- const auto spender = query.get_spender (link);
877+ const auto spender = query.get_spender (query.to_confirmed_spender (spent));
880878 if (spender.index () == chain::point::null_index)
881879 {
882- send_internal_server_error (database::error::integrity );
880+ send_not_found ( );
883881 return true ;
884882 }
885883
@@ -908,29 +906,24 @@ bool protocol_explore::handle_get_output_spenders(const code& ec,
908906 if (stopped (ec))
909907 return false ;
910908
911- const auto & query = archive ();
912- const auto points = query.to_spenders (*hash, index);
913- if (points.empty ())
909+ const auto ins = archive ().get_spenders ({ *hash, index });
910+ if (ins.empty ())
914911 {
915912 send_not_found ();
916913 return true ;
917914 }
918915
919- point_set out{};
920- for (const auto & point: points)
921- out.insert (query.get_spender (point));
922-
923- const auto size = out.size () * chain::point::serialized_size ();
916+ const auto size = ins.size () * inpoint::serialized_size ();
924917 switch (media)
925918 {
926919 case data:
927- send_chunk (to_bin_array (out , size));
920+ send_chunk (to_bin_array (ins , size));
928921 return true ;
929922 case text:
930- send_text (to_hex_array (out , size));
923+ send_text (to_hex_array (ins , size));
931924 return true ;
932925 case json:
933- send_json (value_from (out ), two * size);
926+ send_json (value_from (ins ), two * size);
934927 return true ;
935928 }
936929
@@ -962,29 +955,28 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
962955void protocol_explore::do_get_address (uint8_t media, const hash_cptr& hash,
963956 const address_handler& handler) NOEXCEPT
964957{
965- // Not stranded, query is threadsafe.
966958 const auto & query = archive ();
967959
968- // TODO: push into database as single call, generalize outpoint_set .
960+ // TODO: push into database as single call.
969961 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
970962 // TODO: change query to return code to differentiate cancel vs. integrity.
971- database::output_links outputs {};
972- if (!query.to_address_outputs (stopping_, outputs , *hash))
963+ database::output_links links {};
964+ if (!query.to_address_outputs (stopping_, links , *hash))
973965 {
974966 handler (network::error::operation_canceled, {}, {});
975967 return ;
976968 }
977969
978- outpoint_set set{};
979- for (const auto & output: outputs )
970+ outpoints set{};
971+ for (const auto & link: links )
980972 {
981973 if (stopping_)
982974 {
983975 handler (network::error::operation_canceled, {}, {});
984976 return ;
985977 }
986978
987- set.insert (query.get_spent (output ));
979+ set.insert (query.get_spent (link ));
988980 }
989981 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
990982
@@ -993,7 +985,7 @@ void protocol_explore::do_get_address(uint8_t media, const hash_cptr& hash,
993985
994986// This is shared by the tree get_address.. methods.
995987void protocol_explore::complete_get_address (const code& ec, uint8_t media,
996- const outpoint_set & set) NOEXCEPT
988+ const outpoints & set) NOEXCEPT
997989{
998990 BC_ASSERT (stranded ());
999991
@@ -1056,26 +1048,26 @@ void protocol_explore::do_get_address_confirmed(uint8_t media,
10561048{
10571049 const auto & query = archive ();
10581050
1059- // TODO: push into database as single call, generalize outpoint_set .
1051+ // TODO: push into database as single call.
10601052 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10611053 // TODO: change query to return code to differentiate cancel vs. integrity.
1062- database::output_links outputs {};
1063- if (!query.to_confirmed_unspent_outputs (stopping_, outputs , *hash))
1054+ database::output_links links {};
1055+ if (!query.to_confirmed_unspent_outputs (stopping_, links , *hash))
10641056 {
10651057 handler (network::error::operation_canceled, {}, {});
10661058 return ;
10671059 }
10681060
1069- outpoint_set set{};
1070- for (const auto & output : outputs )
1061+ outpoints set{};
1062+ for (const auto & link: links )
10711063 {
10721064 if (stopping_)
10731065 {
10741066 handler (network::error::operation_canceled, {}, {});
10751067 return ;
10761068 }
10771069
1078- set.insert (query.get_spent (output ));
1070+ set.insert (query.get_spent (link ));
10791071 }
10801072 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10811073
0 commit comments