From 92635aa4e9bd482b7f4f5031b7d62ee7150a6567 Mon Sep 17 00:00:00 2001 From: Bronek Kozicki Date: Wed, 18 Oct 2023 17:23:49 +0100 Subject: [PATCH] Output from ledger --- src/ripple/app/ledger/impl/LedgerToJson.cpp | 66 ++++++++++++++++----- src/ripple/protocol/jss.h | 1 + 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/ripple/app/ledger/impl/LedgerToJson.cpp b/src/ripple/app/ledger/impl/LedgerToJson.cpp index 55123ba2362..81e84303933 100644 --- a/src/ripple/app/ledger/impl/LedgerToJson.cpp +++ b/src/ripple/app/ledger/impl/LedgerToJson.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -118,24 +119,57 @@ fillJsonTx( if (bBinary) { txJson[jss::tx_blob] = serializeHex(*txn); + if (fill.context->apiVersion > 1) + txJson[jss::hash] = to_string(txn->getTransactionID()); + + auto const json_meta = + (fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta); if (stMeta) - txJson[jss::meta] = serializeHex(*stMeta); + txJson[json_meta] = serializeHex(*stMeta); } else { - copyFrom(txJson, txn->getJson(JsonOptions::none)); - RPC::insertDeliverMax(txJson, txnType, fill.context->apiVersion); - if (stMeta) + if (fill.context->apiVersion > 1) + { + std::string hash; + copyFrom( + txJson[jss::tx_json], + txn->getJson( + JsonOptions::none, false, {std::optional(std::ref(hash))})); + txJson[jss::hash] = hash; + // TODO set `txJson[jss::close_time_iso]` + RPC::insertDeliverMax( + txJson[jss::tx_json], txnType, fill.context->apiVersion); + + if (stMeta) + { + txJson[jss::meta] = stMeta->getJson(JsonOptions::none); + + // If applicable, insert delivered amount + if (txnType == ttPAYMENT || txnType == ttCHECK_CASH) + RPC::insertDeliveredAmount( + txJson[jss::meta], + fill.ledger, + txn, + {txn->getTransactionID(), fill.ledger.seq(), *stMeta}); + } + } + else { - txJson[jss::metaData] = stMeta->getJson(JsonOptions::none); - - // If applicable, insert delivered amount - if (txnType == ttPAYMENT || txnType == ttCHECK_CASH) - RPC::insertDeliveredAmount( - txJson[jss::metaData], - fill.ledger, - txn, - {txn->getTransactionID(), fill.ledger.seq(), *stMeta}); + copyFrom(txJson, txn->getJson(JsonOptions::none)); + RPC::insertDeliverMax(txJson, txnType, fill.context->apiVersion); + if (stMeta) + { + txJson[jss::metaData] = stMeta->getJson(JsonOptions::none); + + // If applicable, insert delivered amount + if (txnType == ttPAYMENT || txnType == ttCHECK_CASH) + RPC::insertDeliveredAmount( + txJson[jss::metaData], + fill.ledger, + txn, + {txn->getTransactionID(), fill.ledger.seq(), *stMeta}); + } } } @@ -254,7 +288,11 @@ fillJsonQueue(Object& json, LedgerFill const& fill) if (tx.lastResult) txJson["last_result"] = transToken(*tx.lastResult); - txJson[jss::tx] = fillJsonTx(fill, bBinary, bExpanded, tx.txn, nullptr); + auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn, nullptr); + if (fill.context->apiVersion > 1) + copyFrom(txJson, temp); + else + copyFrom(txJson[jss::tx], temp); } } diff --git a/src/ripple/protocol/jss.h b/src/ripple/protocol/jss.h index d4b213bcb1b..281a410127d 100644 --- a/src/ripple/protocol/jss.h +++ b/src/ripple/protocol/jss.h @@ -460,6 +460,7 @@ JSS(median_fee); // out: TxQ JSS(median_level); // out: TxQ JSS(message); // error. JSS(meta); // out: NetworkOPs, AccountTx*, Tx +JSS(meta_blob); // out: NetworkOPs, AccountTx*, Tx JSS(metaData); JSS(metadata); // out: TransactionEntry JSS(method); // RPC