From 7f5d273e53d5e549bfab598618a41b83ca35da2a Mon Sep 17 00:00:00 2001 From: seelabs Date: Mon, 31 Aug 2015 12:17:25 -0400 Subject: [PATCH] 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 --- src/ripple/app/ledger/Ledger.cpp | 21 ++++++++++++++------- src/ripple/app/ledger/Ledger.h | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index eda631e86..2df9ff19b 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -626,7 +626,7 @@ std::tuple loadLedgerHelper(std::string const& sqlSuffix) { Ledger::pointer ledger; - uint256 ledgerHash; + uint256 ledgerHash{}; std::uint32_t ledgerSeq{0}; auto db = getApp ().getLedgerDB ().checkoutDb (); @@ -665,11 +665,15 @@ loadLedgerHelper(std::string const& sqlSuffix) ledgerSeq = rangeCheckedCast(ledgerSeq64.value_or (0)); - uint256 prevHash, accountHash, transHash; - ledgerHash.SetHexExact (sLedgerHash.value_or("")); - prevHash.SetHexExact (sPrevHash.value_or("")); - accountHash.SetHexExact (sAccountHash.value_or("")); - transHash.SetHexExact (sTransHash.value_or("")); + uint256 prevHash{}, accountHash{}, transHash{}; + if (sLedgerHash) + ledgerHash.SetHexExact (*sLedgerHash); + if (sPrevHash) + prevHash.SetHexExact (*sPrevHash); + if (sAccountHash) + accountHash.SetHexExact (*sAccountHash); + if (sTransHash) + transHash.SetHexExact (*sTransHash); bool loaded = false; ledger = std::make_shared(prevHash, @@ -818,7 +822,10 @@ Ledger::getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq) std::pair& hashes = ret[rangeCheckedCast(ls)]; hashes.first.SetHexExact (lh); - hashes.second.SetHexExact (ph.value_or ("")); + if (ph) + hashes.second.SetHexExact (*ph); + else + hashes.second.zero (); if (!ph) { WriteLog (lsWARNING, Ledger) diff --git a/src/ripple/app/ledger/Ledger.h b/src/ripple/app/ledger/Ledger.h index eab3c1dfd..359540e93 100644 --- a/src/ripple/app/ledger/Ledger.h +++ b/src/ripple/app/ledger/Ledger.h @@ -68,8 +68,9 @@ extern create_genesis_t const create_genesis; 3) Mutable ledgers cannot be shared. @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 , public DigestAwareReadView , public TxsRawView