Skip to content

Commit

Permalink
Fix checkpoint parse.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 24, 2024
1 parent 04e69b3 commit 1242af3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/system/chain/checkpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ bool operator==(const checkpoint& left, const checkpoint& right) NOEXCEPT;
bool operator!=(const checkpoint& left, const checkpoint& right) NOEXCEPT;

// TODO: rationalize with config.
std::istream& operator>>(std::istream& stream, checkpoint& out) THROWS;
std::ostream& operator<<(std::ostream& stream, const checkpoint& in) NOEXCEPT;
std::istream& operator>>(std::istream& stream, checkpoint& out) NOEXCEPT;

typedef std::vector<checkpoint> checkpoints;

Expand Down
21 changes: 10 additions & 11 deletions src/chain/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,24 @@ bool operator!=(const checkpoint& left, const checkpoint& right) NOEXCEPT

// TODO: add from_string.
// TODO: add get_line/put_line to reader and eliminate stream_result.
std::istream& operator>>(std::istream& stream, checkpoint& out) NOEXCEPT
std::istream& operator>>(std::istream& stream, checkpoint& out) THROWS
{
std::string value;
stream >> value;

hash_digest hash;
size_t height(zero);
const auto tokens = split(value, ":");

if (tokens.size() == two &&
decode_hash(hash, tokens.front()) &&
deserialize(height, tokens.back()))
{
out = { hash, height };
return stream_result(stream, true);
}
// std::string avoids boolean override.
const auto tokens = split(value, std::string{ ":" });

if (tokens.size() != two ||
!decode_hash(hash, tokens.front()) ||
!deserialize(height, tokens.back()))
throw istream_exception(value);

out = {};
return stream_result(stream, false);
out = { hash, height };
return stream;
}

bool checkpoint::is_valid() const NOEXCEPT
Expand Down

0 comments on commit 1242af3

Please sign in to comment.