From 7f6bf531f90ec9299b73eb654819de29d6d1b062 Mon Sep 17 00:00:00 2001 From: Bronek Kozicki Date: Tue, 24 Oct 2023 19:15:50 +0000 Subject: [PATCH] Set ledger_hash and ledger_index --- src/ripple/app/ledger/impl/LedgerToJson.cpp | 3 +++ src/ripple/app/misc/NetworkOPs.cpp | 1 - src/ripple/rpc/handlers/AccountTx.cpp | 4 ++++ src/ripple/rpc/handlers/Tx.cpp | 16 +++++++++++++--- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ripple/app/ledger/impl/LedgerToJson.cpp b/src/ripple/app/ledger/impl/LedgerToJson.cpp index 26f1ca2aefd..f3721156a0c 100644 --- a/src/ripple/app/ledger/impl/LedgerToJson.cpp +++ b/src/ripple/app/ledger/impl/LedgerToJson.cpp @@ -86,6 +86,7 @@ fillJson(Object& json, bool closed, LedgerInfo const& info, bool bFull) json[jss::close_time_human] = to_string(info.closeTime); if (!getCloseAgree(info)) json[jss::close_time_estimated] = true; + json[jss::close_time_iso] = to_string_iso(info.closeTime); } } @@ -160,6 +161,8 @@ fillJsonTx( txJson[jss::validated] = validated; if (validated) { + txJson[jss::ledger_index] = to_string(fill.ledger.seq()); + txJson[jss::ledger_hash] = to_string(fill.ledger.info().hash); if (auto close_time = fill.context->ledgerMaster.getCloseTimeBySeq( fill.ledger.seq())) diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 7c79c1b68e1..e624eef963c 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -3183,7 +3183,6 @@ NetworkOPsImp::transJson( { jvTx[jss::tx_json] = jvTx.removeMember(jss::transaction); jvTx[jss::hash] = hash; - // TODO set `jvObj[jss::close_time_iso]` if validated } else { diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index dc3e1e3936e..6ec7efd3d6c 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -337,6 +337,10 @@ populateJsonResponse( false, {std::ref(hash)}); jvObj[jss::hash] = hash; + jvObj[jss::ledger_index] = txn->getLedger(); + jvObj[jss::ledger_hash] = + to_string(context.ledgerMaster.getHashBySeq( + txn->getLedger())); } else jvObj[json_tx] = txn->getJson( diff --git a/src/ripple/rpc/handlers/Tx.cpp b/src/ripple/rpc/handlers/Tx.cpp index 2827256bbd0..39f49b50f7a 100644 --- a/src/ripple/rpc/handlers/Tx.cpp +++ b/src/ripple/rpc/handlers/Tx.cpp @@ -57,6 +57,7 @@ struct TxResult bool validated = false; std::optional ctid; std::optional closeTime; + std::optional ledgerHash; TxSearched searchedAll; }; @@ -147,6 +148,7 @@ doTxPostgres(RPC::Context& context, TxArgs const& args) context.app.getRelationalDatabase().getLedgerInfoByIndex( locator.getLedgerSequence()); res.closeTime = ledgerInfo->closeTime; + res.ledgerHash = ledgerInfo->hash; return {res, rpcSUCCESS}; } @@ -285,6 +287,7 @@ doTxHelp(RPC::Context& context, TxArgs args) uint32_t lgrSeq = ledger->info().seq; uint32_t txnIdx = meta->getAsObject().getFieldU32(sfTransactionIndex); uint32_t netID = context.app.config().NETWORK_ID; + result.ledgerHash = ledger->info().hash; if (txnIdx <= 0xFFFFU && netID < 0xFFFFU && lgrSeq < 0x0FFF'FFFFUL) result.ctid = @@ -339,9 +342,16 @@ populateJsonResponse( context.apiVersion); } response[jss::hash] = hash; - if (result.closeTime) - response[jss::close_time_iso] = - to_string_iso(*result.closeTime); + if (result.validated) + { + response[jss::ledger_index] = result.txn->getLedger(); + if (result.ledgerHash) + response[jss::ledger_hash] = to_string(*result.ledgerHash); + + if (result.closeTime) + response[jss::close_time_iso] = + to_string_iso(*result.closeTime); + } } else {