Compare commits

...

5 Commits

Author SHA1 Message Date
Mayukha Vadari
dbad94b7d2 try again 2026-07-22 14:06:27 -04:00
Mayukha Vadari
47cb75207b (hopefully) fix clang-tidy 2026-07-22 13:48:22 -04:00
Mayukha Vadari
c67e41d795 fix clang-tidy 2026-07-21 18:43:08 -04:00
Mayukha Vadari
8763260b55 Merge branch 'develop' of https://github.com/XRPLF/rippled into copilot/add-ctid-to-ledger-response 2026-07-21 18:24:25 -04:00
copilot-swe-agent[bot]
0dc26c871a fix: Add CTID to ledger command expanded transactions
The ledger RPC method now includes a ctid field in expanded transaction
objects, consistent with tx, account_tx, and transaction stream
subscriptions. The CTID is computed from the transaction metadata's
TransactionIndex field, the ledger sequence, and the network ID.
2026-05-27 20:56:13 +00:00
2 changed files with 103 additions and 0 deletions

View File

@@ -12,16 +12,19 @@
#include <test/jtx/ter.h>
#include <xrpld/app/misc/TxQ.h>
#include <xrpld/rpc/CTID.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/beast/unit_test/suite.h>
#include <xrpl/config/Constants.h>
#include <xrpl/core/NetworkIDService.h>
#include <xrpl/json/json_value.h>
#include <xrpl/json/to_string.h>
#include <xrpl/protocol/ErrorCodes.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/jss.h>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
@@ -709,6 +712,91 @@ class LedgerRPC_test : public beast::unit_test::Suite
}
}
void
testLedgerExpandedTransactionsCTID()
{
testcase("Expanded Transactions CTID");
using namespace test::jtx;
Env env{*this};
Account const alice{"alice"};
env.fund(XRP(10000), alice);
env.close();
uint32_t const netID = env.app().getNetworkIDService().getNetworkID();
// API v2 non-binary: CTID present
{
json::Value jvParams;
jvParams[jss::ledger_index] = "validated";
jvParams[jss::transactions] = true;
jvParams[jss::expand] = true;
jvParams[jss::api_version] = 2;
auto const jrr = env.rpc("json", "ledger", to_string(jvParams))[jss::result];
BEAST_EXPECT(jrr[jss::status] == "success");
auto const& txns = jrr[jss::ledger][jss::transactions];
BEAST_EXPECT(txns.isArray() && txns.size() > 0);
for (unsigned i = 0; i < txns.size(); ++i)
{
BEAST_EXPECT(txns[i].isMember(jss::ctid));
auto const expectedCtid =
RPC::encodeCTID(jrr[jss::ledger][jss::ledger_index].asUInt(), i, netID);
if (BEAST_EXPECT(expectedCtid.has_value()))
BEAST_EXPECT(txns[i][jss::ctid] == expectedCtid.value());
}
}
// API v1 non-binary: CTID present
{
json::Value jvParams;
jvParams[jss::ledger_index] = "validated";
jvParams[jss::transactions] = true;
jvParams[jss::expand] = true;
auto const jrr = env.rpc("json", "ledger", to_string(jvParams))[jss::result];
BEAST_EXPECT(jrr[jss::status] == "success");
auto const& txns = jrr[jss::ledger][jss::transactions];
BEAST_EXPECT(txns.isArray() && txns.size() > 0);
for (auto const& txn : txns)
{
BEAST_EXPECT(txn.isMember(jss::ctid));
}
}
// Binary expanded: CTID present
{
json::Value jvParams;
jvParams[jss::ledger_index] = "validated";
jvParams[jss::transactions] = true;
jvParams[jss::expand] = true;
jvParams[jss::binary] = true;
jvParams[jss::api_version] = 2;
auto const jrr = env.rpc("json", "ledger", to_string(jvParams))[jss::result];
BEAST_EXPECT(jrr[jss::status] == "success");
auto const& txns = jrr[jss::ledger][jss::transactions];
BEAST_EXPECT(txns.isArray() && txns.size() > 0);
for (auto const& txn : txns)
{
BEAST_EXPECT(txn.isMember(jss::ctid));
}
}
// Non-expanded: transactions are plain hash strings, no CTID
{
json::Value jvParams;
jvParams[jss::ledger_index] = "validated";
jvParams[jss::transactions] = true;
jvParams[jss::api_version] = 2;
auto const jrr = env.rpc("json", "ledger", to_string(jvParams))[jss::result];
BEAST_EXPECT(jrr[jss::status] == "success");
auto const& txns = jrr[jss::ledger][jss::transactions];
BEAST_EXPECT(txns.isArray() && txns.size() > 0);
for (auto const& txn : txns)
{
BEAST_EXPECT(txn.isString());
}
}
}
public:
void
run() override
@@ -723,6 +811,7 @@ public:
testNoQueue();
testQueue();
testLedgerAccountsOption();
testLedgerExpandedTransactionsCTID();
}
};

View File

@@ -3,6 +3,7 @@
#include <xrpld/app/ledger/LedgerMaster.h>
#include <xrpld/app/misc/DeliverMax.h>
#include <xrpld/app/misc/TxQ.h>
#include <xrpld/rpc/CTID.h>
#include <xrpld/rpc/Context.h>
#include <xrpld/rpc/DeliveredAmount.h>
#include <xrpld/rpc/MPTokenIssuanceID.h>
@@ -12,6 +13,7 @@
#include <xrpl/basics/chrono.h>
#include <xrpl/basics/strHex.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/core/NetworkIDService.h>
#include <xrpl/json/json_value.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
@@ -27,6 +29,7 @@
#include <xrpl/protocol/jss.h>
#include <xrpl/protocol/serialize.h>
#include <cstdint>
#include <exception>
#include <memory>
#include <string>
@@ -193,6 +196,17 @@ fillJsonTx(
}
}
// compute outgoing CTID
if ((fill.context != nullptr) && stMeta && stMeta->isFieldPresent(sfTransactionIndex))
{
uint32_t const lgrSeq = fill.ledger.seq();
uint32_t const txnIdx = stMeta->getFieldU32(sfTransactionIndex);
uint32_t const netID = fill.context->app.getNetworkIDService().getNetworkID();
if (auto ctid = RPC::encodeCTID(lgrSeq, txnIdx, netID))
txJson[jss::ctid] = *ctid;
}
if (((fill.options & static_cast<int>(LedgerFill::Options::OwnerFunds)) != 0) &&
txn->getTxnType() == ttOFFER_CREATE)
{