Skip to content

Commit d22a8dd

Browse files
authored
Merge pull request #904 from evoskuil/master
Add parse for address subcomponents.
2 parents c3a4d02 + 4c84ec6 commit d22a8dd

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/parse/target.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,23 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
104104
const auto base16 = to_base16(segments[segment++]);
105105
if (!base16) return error::invalid_hash;
106106

107-
method = "address";
108107
params["hash"] = base16;
108+
if (segment == segments.size())
109+
{
110+
method = "address";
111+
}
112+
else
113+
{
114+
const auto subcomponent = segments[segment++];
115+
if (subcomponent == "confirmed")
116+
method = "address_confirmed";
117+
else if (subcomponent == "unconfirmed")
118+
method = "address_unconfirmed";
119+
else if (subcomponent == "balance")
120+
method = "address_balance";
121+
else
122+
return error::invalid_subcomponent;
123+
}
109124
}
110125
else if (target == "input")
111126
{

src/protocols/protocol_explore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
10501050

10511051
// TODO: there are currently no unconfirmed txs.
10521052

1053-
send_not_found();
1053+
send_not_implemented();
10541054
return true;
10551055
}
10561056

test/parse/target.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__block_height_invalid_height__invalid_n
102102
BOOST_AUTO_TEST_CASE(parse__parse_target__block_height_invalid_component__invalid_component)
103103
{
104104
request_t out{};
105-
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/extra"), node::error::invalid_component);
105+
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/invalid"), node::error::invalid_component);
106106
}
107107

108108
// block/hash
@@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__transaction_invalid_hash__invalid_hash
419419

420420
BOOST_AUTO_TEST_CASE(parse__parse_target__tx_invalid_component__invalid_component)
421421
{
422-
const std::string path = "/v3/tx/0000000000000000000000000000000000000000000000000000000000000000/extra";
422+
const std::string path = "/v3/tx/0000000000000000000000000000000000000000000000000000000000000000/invalid";
423423
request_t out{};
424424
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_component);
425425
}
@@ -757,7 +757,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__output_script_valid__expected)
757757

758758
BOOST_AUTO_TEST_CASE(parse__parse_target__output_script_invalid_subcomponent__invalid_subcomponent)
759759
{
760-
const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/extra";
760+
const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/invalid";
761761
request_t out{};
762762
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_subcomponent);
763763
}
@@ -885,13 +885,18 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__address_invalid_hash__invalid_hash)
885885
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/address/invalidhex"), node::error::invalid_hash);
886886
}
887887

888-
BOOST_AUTO_TEST_CASE(parse__parse_target__address_extra_segment__extra_segment)
888+
BOOST_AUTO_TEST_CASE(parse__parse_target__address_invalid_subcomponent__invalid_subcomponent)
889889
{
890-
const std::string path = "/v3/address/0000000000000000000000000000000000000000000000000000000000000000/extra";
890+
const std::string path = "/v3/address/0000000000000000000000000000000000000000000000000000000000000000/invalid";
891891
request_t out{};
892-
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::extra_segment);
892+
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_subcomponent);
893893
}
894894

895+
// TODO:
896+
// address/confirmed
897+
// address/unconfirmed
898+
// address/balance
899+
895900
// block_filter/height
896901

897902
BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_height_valid__expected)
@@ -920,7 +925,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_height_valid__expected)
920925
BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_height_invalid_subcomponent__invalid_subcomponent)
921926
{
922927
request_t out{};
923-
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/filter/42/extra"), node::error::invalid_subcomponent);
928+
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/filter/42/invalid"), node::error::invalid_subcomponent);
924929
}
925930

926931
// block_filter/hash
@@ -956,7 +961,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_hash_valid__expected)
956961

957962
BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_hash_invalid_subcomponent__invalid_subcomponent)
958963
{
959-
const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/filter/42/extra";
964+
const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/filter/42/invalid";
960965
request_t out{};
961966
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_subcomponent);
962967
}

0 commit comments

Comments
 (0)