Skip to content

Commit

Permalink
Set ledger_hash on closed ledger, even if not validated
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 30, 2023
1 parent ef1276c commit 54f1d60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/ripple/app/ledger/impl/LedgerToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ fillJsonTx(
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});
}

if (!fill.ledger.open())
txJson[jss::ledger_hash] = to_string(fill.ledger.info().hash);

const bool validated =
fill.context->ledgerMaster.isValidated(fill.ledger);
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 (fill.closeTime)
txJson[jss::close_time_iso] =
to_string_iso(*fill.closeTime);
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3117,10 +3117,12 @@ NetworkOPsImp::transJson(
jvObj[jss::meta], *ledger, transaction, meta->get());
}

if (!ledger->open())
jvObj[jss::ledger_hash] = to_string(ledger->info().hash);

if (validated)
{
jvObj[jss::ledger_index] = ledger->info().seq;
jvObj[jss::ledger_hash] = to_string(ledger->info().hash);
jvObj[jss::transaction][jss::date] =
ledger->info().closeTime.time_since_epoch().count();
jvObj[jss::validated] = true;
Expand Down
11 changes: 7 additions & 4 deletions src/ripple/rpc/handlers/Tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ doTxHelp(RPC::Context& context, TxArgs args)
std::shared_ptr<Ledger const> ledger =
context.ledgerMaster.getLedgerBySeq(txn->getLedger());

if (ledger && !ledger->open())
result.ledgerHash = ledger->info().hash;

if (ledger && meta)
{
if (args.binary)
Expand All @@ -287,7 +290,6 @@ 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 =
Expand Down Expand Up @@ -341,13 +343,14 @@ populateJsonResponse(
sttx->getTxnType(),
context.apiVersion);
}

if (result.ledgerHash)
response[jss::ledger_hash] = to_string(*result.ledgerHash);

response[jss::hash] = hash;
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);
Expand Down

0 comments on commit 54f1d60

Please sign in to comment.