Skip to content

Commit f5b073d

Browse files
committed
address hash is a single sha256 (unreversed).
1 parent 690dfe7 commit f5b073d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/parse/target.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ static hash_cptr to_hash(const std::string_view& token) NOEXCEPT
4646
emplace_shared<const hash_digest>(std::move(out)) : hash_cptr{};
4747
}
4848

49+
static hash_cptr to_base16(const std::string_view& token) NOEXCEPT
50+
{
51+
hash_digest out{};
52+
return decode_base16(out, token) ?
53+
emplace_shared<const hash_digest>(std::move(out)) : hash_cptr{};
54+
}
55+
4956
code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
5057
{
5158
const auto clean = split(path, "?", false, false).front();
@@ -89,11 +96,12 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
8996
if (segment == segments.size())
9097
return error::missing_hash;
9198

92-
const auto hash = to_hash(segments[segment++]);
93-
if (!hash) return error::invalid_hash;
99+
// address hash is a single sha256, and conventionally not reversed.
100+
const auto base16 = to_base16(segments[segment++]);
101+
if (!base16) return error::invalid_hash;
94102

95103
method = "address";
96-
params["hash"] = hash;
104+
params["hash"] = base16;
97105
}
98106
else if (target == "input")
99107
{

test/parse/target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__output_spenders_extra_segment__extra_s
847847

848848
// address
849849

850-
BOOST_AUTO_TEST_CASE(parse__parse_target__address_valid__expected)
850+
BOOST_AUTO_TEST_CASE(parse__parse_target__address_valid__unreversed_expected)
851851
{
852-
const std::string path = "/v255/address/0000000000000000000000000000000000000000000000000000000000000042";
852+
const std::string path = "/v255/address/4200000000000000000000000000000000000000000000000000000000000000";
853853

854854
request_t request{};
855855
BOOST_REQUIRE(!parse_target(request, path));

0 commit comments

Comments
 (0)