Skip to content

Commit

Permalink
Set ledger_hash and ledger_index
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 25, 2023
1 parent c4a83d3 commit 7f6bf53
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/ripple/app/ledger/impl/LedgerToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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()))
Expand Down
1 change: 0 additions & 1 deletion src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 13 additions & 3 deletions src/ripple/rpc/handlers/Tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct TxResult
bool validated = false;
std::optional<std::string> ctid;
std::optional<NetClock::time_point> closeTime;
std::optional<uint256> ledgerHash;
TxSearched searchedAll;
};

Expand Down Expand Up @@ -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};
}
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 7f6bf53

Please sign in to comment.