Tidy SetHex* function calls & misc cleanups

* Renamed SetHexExact -> SetHexUnchecked
* Removed calls to SetHexUnchecked with empty strings
* Marked ledger class as final, as it calls virtuals in its ctor
This commit is contained in:
seelabs
2015-08-31 12:17:25 -04:00
committed by Nik Bougalis
parent b0e6be93ff
commit 7f5d273e53
2 changed files with 16 additions and 8 deletions

View File

@@ -626,7 +626,7 @@ std::tuple<Ledger::pointer, std::uint32_t, uint256>
loadLedgerHelper(std::string const& sqlSuffix) loadLedgerHelper(std::string const& sqlSuffix)
{ {
Ledger::pointer ledger; Ledger::pointer ledger;
uint256 ledgerHash; uint256 ledgerHash{};
std::uint32_t ledgerSeq{0}; std::uint32_t ledgerSeq{0};
auto db = getApp ().getLedgerDB ().checkoutDb (); auto db = getApp ().getLedgerDB ().checkoutDb ();
@@ -665,11 +665,15 @@ loadLedgerHelper(std::string const& sqlSuffix)
ledgerSeq = ledgerSeq =
rangeCheckedCast<std::uint32_t>(ledgerSeq64.value_or (0)); rangeCheckedCast<std::uint32_t>(ledgerSeq64.value_or (0));
uint256 prevHash, accountHash, transHash; uint256 prevHash{}, accountHash{}, transHash{};
ledgerHash.SetHexExact (sLedgerHash.value_or("")); if (sLedgerHash)
prevHash.SetHexExact (sPrevHash.value_or("")); ledgerHash.SetHexExact (*sLedgerHash);
accountHash.SetHexExact (sAccountHash.value_or("")); if (sPrevHash)
transHash.SetHexExact (sTransHash.value_or("")); prevHash.SetHexExact (*sPrevHash);
if (sAccountHash)
accountHash.SetHexExact (*sAccountHash);
if (sTransHash)
transHash.SetHexExact (*sTransHash);
bool loaded = false; bool loaded = false;
ledger = std::make_shared<Ledger>(prevHash, ledger = std::make_shared<Ledger>(prevHash,
@@ -818,7 +822,10 @@ Ledger::getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq)
std::pair<uint256, uint256>& hashes = std::pair<uint256, uint256>& hashes =
ret[rangeCheckedCast<std::uint32_t>(ls)]; ret[rangeCheckedCast<std::uint32_t>(ls)];
hashes.first.SetHexExact (lh); hashes.first.SetHexExact (lh);
hashes.second.SetHexExact (ph.value_or ("")); if (ph)
hashes.second.SetHexExact (*ph);
else
hashes.second.zero ();
if (!ph) if (!ph)
{ {
WriteLog (lsWARNING, Ledger) WriteLog (lsWARNING, Ledger)

View File

@@ -68,8 +68,9 @@ extern create_genesis_t const create_genesis;
3) Mutable ledgers cannot be shared. 3) Mutable ledgers cannot be shared.
@note Presented to clients as ReadView @note Presented to clients as ReadView
@note Calls virtuals in the constructor, so marked as final
*/ */
class Ledger class Ledger final
: public std::enable_shared_from_this <Ledger> : public std::enable_shared_from_this <Ledger>
, public DigestAwareReadView , public DigestAwareReadView
, public TxsRawView , public TxsRawView