From f44d2a356d4ae860fdbd110923a166b5d4165d22 Mon Sep 17 00:00:00 2001 From: Hidenori Shinohara Date: Wed, 13 Jan 2021 18:07:29 -0500 Subject: [PATCH 1/4] Add issuer information when printing Asset --- src/util/XDRCereal.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/util/XDRCereal.cpp b/src/util/XDRCereal.cpp index 05fe1e047d..22004267ac 100644 --- a/src/util/XDRCereal.cpp +++ b/src/util/XDRCereal.cpp @@ -37,8 +37,19 @@ cereal_override(cereal::JSONOutputArchive& ar, } void -cereal_override(cereal::JSONOutputArchive& ar, const stellar::Asset& s, - const char* field) +cereal_override(cereal::JSONOutputArchive& ar, stellar::Asset const& asset, + char const* field) { - xdr::archive(ar, stellar::assetToString(s), field); + if (asset.type() == stellar::ASSET_TYPE_NATIVE) + { + xdr::archive(ar, std::string("NATIVE"), field); + } + else + { + ar.setNextName(field); + ar.startNode(); + xdr::archive(ar, stellar::assetToString(asset), "assetCode"); + xdr::archive(ar, stellar::getIssuer(asset), "issuer"); + ar.finishNode(); + } } From aa7f719d4d935c35c1ed6ecc81218980e474fa6c Mon Sep 17 00:00:00 2001 From: Hidenori Shinohara Date: Sat, 20 Feb 2021 13:35:25 -0500 Subject: [PATCH 2/4] Update the way a container is printed --- src/util/XDRCereal.h | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/util/XDRCereal.h b/src/util/XDRCereal.h index 55da65e1b2..b45bb67f9d 100644 --- a/src/util/XDRCereal.h +++ b/src/util/XDRCereal.h @@ -34,21 +34,36 @@ cereal_override(cereal::JSONOutputArchive& ar, const xdr::opaque_array& s, field); } -// We still need one explicit composite-container override because cereal -// appears to process arrays-of-arrays internally, without calling back through -// an NVP adaptor. -template -void -cereal_override(cereal::JSONOutputArchive& ar, - const xdr::xarray& s, const char* field) +template +std::enable_if_t::is_container> +cereal_override(cereal::JSONOutputArchive& ar, T const& t, const char* field) { - std::vector tmp; - for (auto const& h : s) + // CEREAL_SAVE_FUNCTION_NAME in include/cereal/archives/json.hpp runs + // ar.setNextName() and ar(). ar() in turns calls process() in + // include/cereal/cereal.hpp which calls prologue(), processImpl(), + // epilogue(). We are imitating this behavior here by creating a sub-object + // using prologue(), printing the content with xdr::archive, and finally + // calling epilogue(). We must use xdr::archive instead of ar() because we + // need to access the nested cereal_overrides. + // + // tl;dr This does what ar(cereal::make_nvp(...)) does while using nested + // cereal_overrides. + ar.setNextName(field); + cereal::prologue(ar, t); + + // It does not matter what value we pass here to cereal::make_size_tag + // since it will be ignored. See the comment + // + // > SizeTags are strictly ignored for JSON, they just indicate + // > that the current node should be made into an array + // + // in include/cereal/archives/json.hpp + ar(cereal::make_size_tag(0)); + for (auto const& element : t) { - tmp.emplace_back( - stellar::binToHex(stellar::ByteSlice(h.data(), h.size()))); + xdr::archive(ar, element); } - xdr::archive(ar, tmp, field); + cereal::epilogue(ar, t); } template From d7d72834fbfe8e906f976ae8e7bb4b73c3d0f747 Mon Sep 17 00:00:00 2001 From: Hidenori Shinohara Date: Fri, 8 Jan 2021 17:50:46 -0500 Subject: [PATCH 3/4] Make the name field of xdr_to_string mandatory since otherwise Cereal would print "value0" --- src/catchup/ApplyCheckpointWork.cpp | 9 +++--- .../simulation/TxSimApplyTransactionsWork.cpp | 28 +++++++++-------- src/herder/TxSetFrame.cpp | 16 +++++----- src/invariant/InvariantManagerImpl.cpp | 7 +++-- src/invariant/LiabilitiesMatchOffers.cpp | 25 ++++++++-------- src/ledger/InternalLedgerEntry.cpp | 30 +++++++++++-------- src/ledger/LedgerManagerImpl.cpp | 6 ++-- src/main/CommandHandler.cpp | 3 +- src/simulation/LoadGenerator.cpp | 4 +-- src/test/FuzzerImpl.cpp | 19 +++++++----- src/test/TestPrinter.cpp | 11 +++---- src/test/TestPrinter.h | 2 +- src/transactions/OperationFrame.cpp | 4 +-- src/transactions/TransactionFrame.cpp | 16 ++++------ src/util/XDRCereal.h | 12 ++------ 15 files changed, 97 insertions(+), 95 deletions(-) diff --git a/src/catchup/ApplyCheckpointWork.cpp b/src/catchup/ApplyCheckpointWork.cpp index 57313a0396..aeee8275ea 100644 --- a/src/catchup/ApplyCheckpointWork.cpp +++ b/src/catchup/ApplyCheckpointWork.cpp @@ -257,11 +257,12 @@ ApplyCheckpointWork::onRun() { auto& lm = mApp.getLedgerManager(); - CLOG_DEBUG(History, "LedgerManager LCL:\n{}", - xdr_to_string(lm.getLastClosedLedgerHeader())); + CLOG_DEBUG(History, "{}", + xdr_to_string(lm.getLastClosedLedgerHeader(), + "LedgerManager LCL")); - CLOG_DEBUG(History, "Replay header:\n{}", - xdr_to_string(mHeaderHistoryEntry)); + CLOG_DEBUG(History, "{}", + xdr_to_string(mHeaderHistoryEntry, "Replay header")); if (lm.getLastClosedLedgerHeader().hash != mHeaderHistoryEntry.hash) { diff --git a/src/catchup/simulation/TxSimApplyTransactionsWork.cpp b/src/catchup/simulation/TxSimApplyTransactionsWork.cpp index 86d884f91a..93593051b4 100644 --- a/src/catchup/simulation/TxSimApplyTransactionsWork.cpp +++ b/src/catchup/simulation/TxSimApplyTransactionsWork.cpp @@ -66,9 +66,9 @@ checkOperationResults(xdr::xvector const& expected, { if (expected[i].code() != actual[i].code()) { - CLOG_ERROR(History, "Expected operation result {} but got {}", - xdr_to_string(expected[i].code()), - xdr_to_string(actual[i].code())); + CLOG_ERROR(History, "Expected {} but got {}", + xdr_to_string(expected[i].code(), "OperationResultCode"), + xdr_to_string(actual[i].code(), "OperationResultCode")); continue; } @@ -154,10 +154,10 @@ checkOperationResults(xdr::xvector const& expected, if (!match) { - CLOG_ERROR(History, "Expected operation result: {}", - xdr_to_string(expectedOpRes)); - CLOG_ERROR(History, "Actual operation result: {}", - xdr_to_string(actualOpRes)); + CLOG_ERROR(History, "Expected {}", + xdr_to_string(expectedOpRes, "OperationResult")); + CLOG_ERROR(History, "Actual {}", + xdr_to_string(actualOpRes, "OperationResult")); } } } @@ -179,9 +179,9 @@ checkResults(Application& app, uint32_t ledger, if (dbRes.code() != archiveRes.code()) { CLOG_ERROR( - History, - "Expected result code {} does not agree with {} for tx {}", - xdr_to_string(archiveRes.code()), xdr_to_string(dbRes.code()), + History, "Expected {} does not agree with {} for tx {}", + xdr_to_string(archiveRes.code(), "TransactionResultCode"), + xdr_to_string(dbRes.code(), "TransactionResultCode"), binToHex(results[i].transactionHash)); } else if (dbRes.code() == txFEE_BUMP_INNER_FAILED || @@ -193,11 +193,13 @@ checkResults(Application& app, uint32_t ledger, { CLOG_ERROR( History, - "Expected result code {} does not agree with {} for " + "Expected {} does not agree with {} for " "fee-bump inner tx {}", xdr_to_string( - archiveRes.innerResultPair().result.result.code()), - xdr_to_string(dbRes.innerResultPair().result.result.code()), + archiveRes.innerResultPair().result.result.code(), + "TransactionResultCode"), + xdr_to_string(dbRes.innerResultPair().result.result.code(), + "TransactionResultCode"), binToHex(archiveRes.innerResultPair().transactionHash)); } else if (dbRes.innerResultPair().result.result.code() == txFAILED || diff --git a/src/herder/TxSetFrame.cpp b/src/herder/TxSetFrame.cpp index c13aa67c5c..1b94d14aa5 100644 --- a/src/herder/TxSetFrame.cpp +++ b/src/herder/TxSetFrame.cpp @@ -298,12 +298,13 @@ TxSetFrame::checkOrTrim(Application& app, { if (justCheck) { - CLOG_DEBUG(Herder, - "Got bad txSet: {} tx invalid lastSeq:{} tx: {} " - "result: {}", - hexAbbrev(mPreviousLedgerHash), lastSeq, - xdr_to_string(tx->getEnvelope()), - tx->getResultCode()); + CLOG_DEBUG( + Herder, + "Got bad txSet: {} tx invalid lastSeq:{} tx: {} " + "result: {}", + hexAbbrev(mPreviousLedgerHash), lastSeq, + xdr_to_string(tx->getEnvelope(), "TransactionEnvelope"), + tx->getResultCode()); return false; } trimmed.emplace_back(tx); @@ -343,7 +344,8 @@ TxSetFrame::checkOrTrim(Application& app, CLOG_DEBUG(Herder, "Got bad txSet: {} account can't pay fee tx: {}", hexAbbrev(mPreviousLedgerHash), - xdr_to_string(tx->getEnvelope())); + xdr_to_string(tx->getEnvelope(), + "TransactionEnvelope")); return false; } while (iter != kv.second.end()) diff --git a/src/invariant/InvariantManagerImpl.cpp b/src/invariant/InvariantManagerImpl.cpp index 0d34a11417..39f4e2ff54 100644 --- a/src/invariant/InvariantManagerImpl.cpp +++ b/src/invariant/InvariantManagerImpl.cpp @@ -115,9 +115,10 @@ InvariantManagerImpl::checkOnOperationApply(Operation const& operation, continue; } - auto message = fmt::format( - R"(Invariant "{}" does not hold on operation: {}{}{})", - invariant->getName(), result, "\n", xdr_to_string(operation)); + auto message = + fmt::format(R"(Invariant "{}" does not hold on operation: {}{}{})", + invariant->getName(), result, "\n", + xdr_to_string(operation, "Operation")); onInvariantFailure(invariant, message, ltxDelta.header.current.ledgerSeq); } diff --git a/src/invariant/LiabilitiesMatchOffers.cpp b/src/invariant/LiabilitiesMatchOffers.cpp index 9c533fdbf9..bb7ca06cf1 100644 --- a/src/invariant/LiabilitiesMatchOffers.cpp +++ b/src/invariant/LiabilitiesMatchOffers.cpp @@ -100,7 +100,7 @@ checkAuthorized(LedgerEntry const* current, LedgerEntry const* previous) { return fmt::format( "Liabilities increased on unauthorized trust line {}", - xdr_to_string(trust)); + xdr_to_string(trust, "TrustLineEntry")); } } else @@ -110,7 +110,7 @@ checkAuthorized(LedgerEntry const* current, LedgerEntry const* previous) { return fmt::format( "Unauthorized trust line has liabilities {}", - xdr_to_string(trust)); + xdr_to_string(trust, "TrustLineEntry")); } } } @@ -256,8 +256,8 @@ checkBalanceAndLimit(LedgerHeader const& header, LedgerEntry const* current, (INT64_MAX - account.balance < liabilities.buying)) { return fmt::format( - "Balance not compatible with liabilities for account {}", - xdr_to_string(account)); + "Balance not compatible with liabilities for {}", + xdr_to_string(account, "AccountEntry")); } } } @@ -273,9 +273,8 @@ checkBalanceAndLimit(LedgerHeader const& header, LedgerEntry const* current, if ((trust.balance < liabilities.selling) || (trust.limit - trust.balance < liabilities.buying)) { - return fmt::format( - "Balance not compatible with liabilities for trustline {}", - xdr_to_string(trust)); + return fmt::format("Balance not compatible with liabilities for {}", + xdr_to_string(trust, "TrustLineEntry")); } } return {}; @@ -346,20 +345,20 @@ LiabilitiesMatchOffers::checkOnOperationApply(Operation const& operation, return fmt::format( "Change in buying liabilities differed from " "change in total buying liabilities of " - "offers by {} for account {} in asset {}", + "offers by {} for {} in {}", assetLiabilities.second.buying, - xdr_to_string(accLiabilities.first), - xdr_to_string(assetLiabilities.first)); + xdr_to_string(accLiabilities.first, "account"), + xdr_to_string(assetLiabilities.first, "asset")); } else if (assetLiabilities.second.selling != 0) { return fmt::format( "Change in selling liabilities differed from " "change in total selling liabilities of " - "offers by {} for account {} in asset {}", + "offers by {} for {} in {}", assetLiabilities.second.selling, - xdr_to_string(accLiabilities.first), - xdr_to_string(assetLiabilities.first)); + xdr_to_string(accLiabilities.first, "account"), + xdr_to_string(assetLiabilities.first, "asset")); } } } diff --git a/src/ledger/InternalLedgerEntry.cpp b/src/ledger/InternalLedgerEntry.cpp index 54340543fa..01d969e9db 100644 --- a/src/ledger/InternalLedgerEntry.cpp +++ b/src/ledger/InternalLedgerEntry.cpp @@ -282,13 +282,16 @@ InternalLedgerKey::toString() const switch (mType) { case InternalLedgerEntryType::LEDGER_ENTRY: - return xdr_to_string(ledgerKey()); + return xdr_to_string(ledgerKey(), "LedgerKey"); + case InternalLedgerEntryType::SPONSORSHIP: - return fmt::format("{{\n sponsoredID = {}\n}}\n", - xdr_to_string(sponsorshipKey().sponsoredID)); + return fmt::format( + "{{\n {}\n}}\n", + xdr_to_string(sponsorshipKey().sponsoredID, "sponsoredID")); case InternalLedgerEntryType::SPONSORSHIP_COUNTER: - return fmt::format("{{\n sponsoringID = {}\n}}\n", - xdr_to_string(sponsorshipCounterKey().sponsoringID)); + return fmt::format("{{\n {}\n}}\n", + xdr_to_string(sponsorshipCounterKey().sponsoringID, + "sponsoringID")); default: abort(); } @@ -558,16 +561,17 @@ InternalLedgerEntry::toString() const switch (mType) { case InternalLedgerEntryType::LEDGER_ENTRY: - return xdr_to_string(ledgerEntry()); + return xdr_to_string(ledgerEntry(), "LedgerEntry"); case InternalLedgerEntryType::SPONSORSHIP: - return fmt::format("{{\n sponsoredID = {},\n sponsoringID = {}\n}}\n", - xdr_to_string(sponsorshipEntry().sponsoredID), - xdr_to_string(sponsorshipEntry().sponsoringID)); - case InternalLedgerEntryType::SPONSORSHIP_COUNTER: return fmt::format( - "{{\n sponsoringID = {},\n numSponsoring = {}\n}}\n", - xdr_to_string(sponsorshipCounterEntry().sponsoringID), - sponsorshipCounterEntry().numSponsoring); + "{{\n {},\n {}\n}}\n", + xdr_to_string(sponsorshipEntry().sponsoredID, "sponsoredID"), + xdr_to_string(sponsorshipEntry().sponsoringID, "sponsoringID")); + case InternalLedgerEntryType::SPONSORSHIP_COUNTER: + return fmt::format("{{\n {},\n numSponsoring = {}\n}}\n", + xdr_to_string(sponsorshipCounterEntry().sponsoringID, + "sponsoringID"), + sponsorshipCounterEntry().numSponsoring); default: abort(); } diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index a77a9460a1..444a9e9f4e 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -555,8 +555,8 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData) txSet->previousLedgerHash()), ledgerAbbrev(getLastClosedLedgerHeader())); - CLOG_ERROR(Ledger, "Full LCL: {}", - xdr_to_string(getLastClosedLedgerHeader())); + CLOG_ERROR(Ledger, "{}", + xdr_to_string(getLastClosedLedgerHeader(), "Full LCL")); CLOG_ERROR(Ledger, "{}", POSSIBLY_CORRUPTED_LOCAL_DATA); throw std::runtime_error("txset mismatch"); @@ -623,7 +623,7 @@ LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData) case Upgrades::UpgradeValidity::INVALID: throw std::runtime_error( fmt::format(FMT_STRING("Invalid upgrade at index {}: {}"), i, - xdr_to_string(lupgrade))); + xdr_to_string(lupgrade, "LedgerUpgrade"))); } try diff --git a/src/main/CommandHandler.cpp b/src/main/CommandHandler.cpp index e477d4ebed..2fa723ed28 100644 --- a/src/main/CommandHandler.cpp +++ b/src/main/CommandHandler.cpp @@ -951,7 +951,8 @@ CommandHandler::testTx(std::string const& params, std::string& retStr) root["status"] = TX_STATUS_STRING[static_cast(status)]; if (status == TransactionQueue::AddResult::ADD_STATUS_ERROR) { - root["detail"] = xdr_to_string(txFrame->getResult().result.code()); + root["detail"] = xdr_to_string(txFrame->getResult().result.code(), + "TransactionResultCode"); } } else diff --git a/src/simulation/LoadGenerator.cpp b/src/simulation/LoadGenerator.cpp index a051744e7a..86c769acac 100644 --- a/src/simulation/LoadGenerator.cpp +++ b/src/simulation/LoadGenerator.cpp @@ -647,8 +647,8 @@ LoadGenerator::TxInfo::execute(Application& app, bool isCreate, { CLOG_INFO(LoadGen, "tx rejected '{}': {} ===> {}", TX_STATUS_STRING[static_cast(status)], - xdr_to_string(txf->getEnvelope()), - xdr_to_string(txf->getResult())); + xdr_to_string(txf->getEnvelope(), "TransactionEnvelope"), + xdr_to_string(txf->getResult(), "TransactionResult")); if (status == TransactionQueue::AddResult::ADD_STATUS_ERROR) { code = txf->getResultCode(); diff --git a/src/test/FuzzerImpl.cpp b/src/test/FuzzerImpl.cpp index 1599506b81..2888b516fe 100644 --- a/src/test/FuzzerImpl.cpp +++ b/src/test/FuzzerImpl.cpp @@ -789,11 +789,11 @@ applySetupOperations(LedgerTxn& ltx, PublicKey const& sourceAccount, if (txFramePtr->getResultCode() != txSUCCESS) { - auto const msg = - fmt::format(FMT_STRING("Error {} while setting up fuzzing -- " - "transaction result {}"), - txFramePtr->getResultCode(), - xdr_to_string(txFramePtr->getResult())); + auto const msg = fmt::format( + FMT_STRING("Error {} while setting up fuzzing -- " + "{}"), + txFramePtr->getResultCode(), + xdr_to_string(txFramePtr->getResult(), "TransactionResult")); LOG_FATAL(DEFAULT_LOG, "{}", msg); throw std::runtime_error(msg); } @@ -816,8 +816,9 @@ applySetupOperations(LedgerTxn& ltx, PublicKey const& sourceAccount, { auto const msg = fmt::format( FMT_STRING("Manage offer result {} while setting " - "up fuzzing -- operation is {}"), - xdr_to_string(tr), xdr_to_string(op)); + "up fuzzing -- {}"), + xdr_to_string(tr, "Operation"), + xdr_to_string(op, "Operation")); LOG_FATAL(DEFAULT_LOG, "{}", msg); throw std::runtime_error(msg); } @@ -1280,7 +1281,9 @@ TransactionFuzzer::inject(std::string const& filename) } resetTxInternalState(*mApp); - LOG_TRACE(DEFAULT_LOG, "Fuzz ops ({}): {}", ops.size(), xdr_to_string(ops)); + LOG_TRACE(DEFAULT_LOG, "{}", + xdr_to_string(ops, fmt::format("Fuzz ops ({})", ops.size()))); + LedgerTxn ltx(mApp->getLedgerTxnRoot()); applyFuzzOperations(ltx, mSourceAccountID, ops.begin(), ops.end(), *mApp); } diff --git a/src/test/TestPrinter.cpp b/src/test/TestPrinter.cpp index a83fdf9bd3..c8be5c84f8 100644 --- a/src/test/TestPrinter.cpp +++ b/src/test/TestPrinter.cpp @@ -13,11 +13,12 @@ namespace Catch std::string StringMaker::convert(stellar::OfferState const& os) { - return fmt::format( - "selling: {}, buying: {}, price: {}, amount: {}, type: {}", - xdr_to_string(os.selling), xdr_to_string(os.buying), - xdr_to_string(os.price), os.amount, - os.type == stellar::OfferType::PASSIVE ? "passive" : "active"); + return fmt::format("{}, {}, {}, amount: {}, type: {}", + xdr_to_string(os.selling, "selling"), + xdr_to_string(os.buying, "buying"), + xdr_to_string(os.price, "price"), os.amount, + os.type == stellar::OfferType::PASSIVE ? "passive" + : "active"); } std::string diff --git a/src/test/TestPrinter.h b/src/test/TestPrinter.h index edd374259a..755cbde668 100644 --- a/src/test/TestPrinter.h +++ b/src/test/TestPrinter.h @@ -23,7 +23,7 @@ struct StringMaker::valid>::type> static std::string convert(T const& val) { - return xdr_to_string(val); + return xdr_to_string(val, "value"); } }; diff --git a/src/transactions/OperationFrame.cpp b/src/transactions/OperationFrame.cpp index 414250f754..1fcbb56d80 100644 --- a/src/transactions/OperationFrame.cpp +++ b/src/transactions/OperationFrame.cpp @@ -122,7 +122,7 @@ OperationFrame::apply(SignatureChecker& signatureChecker, bool res; if (Logging::logTrace("Tx")) { - CLOG_TRACE(Tx, "Operation: {}", xdr_to_string(mOperation)); + CLOG_TRACE(Tx, "{}", xdr_to_string(mOperation, "Operation")); } res = checkValid(signatureChecker, ltx, true); if (res) @@ -130,7 +130,7 @@ OperationFrame::apply(SignatureChecker& signatureChecker, res = doApply(ltx); if (Logging::logTrace("Tx")) { - CLOG_TRACE(Tx, "Operation result: {}", xdr_to_string(mResult)); + CLOG_TRACE(Tx, "{}", xdr_to_string(mResult, "OperationResult")); } } diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index 4a57083cc8..55567aae9b 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -817,19 +817,15 @@ TransactionFrame::applyOperations(SignatureChecker& signatureChecker, } catch (std::exception& e) { - CLOG_ERROR(Tx, - "Exception while applying operations (fullHash= {}, " - "contentsHash= {}): {}", - xdr_to_string(getFullHash()), - xdr_to_string(getContentsHash()), e.what()); + CLOG_ERROR(Tx, "Exception while applying operations ({}, {}): {}", + xdr_to_string(getFullHash(), "fullHash"), + xdr_to_string(getContentsHash(), "contentsHash"), e.what()); } catch (...) { - CLOG_ERROR(Tx, - "Unknown exception while applying operations (fullHash= {}, " - "contentsHash= {})", - xdr_to_string(getFullHash()), - xdr_to_string(getContentsHash())); + CLOG_ERROR(Tx, "Unknown exception while applying operations ({}, {})", + xdr_to_string(getFullHash(), "fullHash"), + xdr_to_string(getContentsHash(), "contentsHash")); } // This is only reachable if an exception is thrown getResult().result.code(txINTERNAL_ERROR); diff --git a/src/util/XDRCereal.h b/src/util/XDRCereal.h index b45bb67f9d..ba4e90f7d2 100644 --- a/src/util/XDRCereal.h +++ b/src/util/XDRCereal.h @@ -119,11 +119,10 @@ cereal_override(cereal::JSONOutputArchive& ar, const xdr::pointer& t, // during the enable_if call in the cereal adaptor fails to find them. #include -// If name is a nonempty string, the output string begins with it. // If compact = true, the output string will not contain any indentation. template std::string -xdr_to_string(const T& t, std::string const& name = "", bool compact = false) +xdr_to_string(const T& t, std::string const& name, bool compact = false) { std::stringstream os; @@ -133,14 +132,7 @@ xdr_to_string(const T& t, std::string const& name = "", bool compact = false) cereal::JSONOutputArchive ar( os, compact ? cereal::JSONOutputArchive::Options::NoIndent() : cereal::JSONOutputArchive::Options::Default()); - if (!name.empty()) - { - ar(cereal::make_nvp(name, t)); - } - else - { - ar(t); - } + ar(cereal::make_nvp(name, t)); } return os.str(); } From 8df71d8d5f90b2e9a1e7a08dfb76b0f04cb98e05 Mon Sep 17 00:00:00 2001 From: Hidenori Shinohara Date: Fri, 12 Feb 2021 12:16:18 -0500 Subject: [PATCH 4/4] Make xdr_to_string use xdr::archive --- src/util/XDRCereal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/XDRCereal.h b/src/util/XDRCereal.h index ba4e90f7d2..5c99bfd740 100644 --- a/src/util/XDRCereal.h +++ b/src/util/XDRCereal.h @@ -132,7 +132,7 @@ xdr_to_string(const T& t, std::string const& name, bool compact = false) cereal::JSONOutputArchive ar( os, compact ? cereal::JSONOutputArchive::Options::NoIndent() : cereal::JSONOutputArchive::Options::Default()); - ar(cereal::make_nvp(name, t)); + xdr::archive(ar, t, name.c_str()); } return os.str(); }