Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/parse/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,23 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
const auto base16 = to_base16(segments[segment++]);
if (!base16) return error::invalid_hash;

method = "address";
params["hash"] = base16;
if (segment == segments.size())
{
method = "address";
}
else
{
const auto subcomponent = segments[segment++];
if (subcomponent == "confirmed")
method = "address_confirmed";
else if (subcomponent == "unconfirmed")
method = "address_unconfirmed";
else if (subcomponent == "balance")
method = "address_balance";
else
return error::invalid_subcomponent;
}
}
else if (target == "input")
{
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/protocol_explore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ bool protocol_explore::handle_get_address_unconfirmed(const code& ec,

// TODO: there are currently no unconfirmed txs.

send_not_found();
send_not_implemented();
return true;
}

Expand Down
21 changes: 13 additions & 8 deletions test/parse/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__block_height_invalid_height__invalid_n
BOOST_AUTO_TEST_CASE(parse__parse_target__block_height_invalid_component__invalid_component)
{
request_t out{};
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/extra"), node::error::invalid_component);
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/invalid"), node::error::invalid_component);
}

// block/hash
Expand Down Expand Up @@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__transaction_invalid_hash__invalid_hash

BOOST_AUTO_TEST_CASE(parse__parse_target__tx_invalid_component__invalid_component)
{
const std::string path = "/v3/tx/0000000000000000000000000000000000000000000000000000000000000000/extra";
const std::string path = "/v3/tx/0000000000000000000000000000000000000000000000000000000000000000/invalid";
request_t out{};
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_component);
}
Expand Down Expand Up @@ -757,7 +757,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__output_script_valid__expected)

BOOST_AUTO_TEST_CASE(parse__parse_target__output_script_invalid_subcomponent__invalid_subcomponent)
{
const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/extra";
const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/invalid";
request_t out{};
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_subcomponent);
}
Expand Down Expand Up @@ -885,13 +885,18 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__address_invalid_hash__invalid_hash)
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/address/invalidhex"), node::error::invalid_hash);
}

BOOST_AUTO_TEST_CASE(parse__parse_target__address_extra_segment__extra_segment)
BOOST_AUTO_TEST_CASE(parse__parse_target__address_invalid_subcomponent__invalid_subcomponent)
{
const std::string path = "/v3/address/0000000000000000000000000000000000000000000000000000000000000000/extra";
const std::string path = "/v3/address/0000000000000000000000000000000000000000000000000000000000000000/invalid";
request_t out{};
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::extra_segment);
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_subcomponent);
}

// TODO:
// address/confirmed
// address/unconfirmed
// address/balance

// block_filter/height

BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_height_valid__expected)
Expand Down Expand Up @@ -920,7 +925,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_height_valid__expected)
BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_height_invalid_subcomponent__invalid_subcomponent)
{
request_t out{};
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/filter/42/extra"), node::error::invalid_subcomponent);
BOOST_REQUIRE_EQUAL(parse_target(out, "/v3/block/height/123/filter/42/invalid"), node::error::invalid_subcomponent);
}

// block_filter/hash
Expand Down Expand Up @@ -956,7 +961,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_hash_valid__expected)

BOOST_AUTO_TEST_CASE(parse__parse_target__block_filter_hash_invalid_subcomponent__invalid_subcomponent)
{
const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/filter/42/extra";
const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/filter/42/invalid";
request_t out{};
BOOST_REQUIRE_EQUAL(parse_target(out, path), node::error::invalid_subcomponent);
}
Expand Down
Loading