Compare commits

..

1 Commits

Author SHA1 Message Date
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
6 changed files with 109 additions and 29 deletions

View File

@@ -5,17 +5,8 @@ on:
types:
- checks_requested
pull_request:
types:
- opened
- edited
- reopened
- synchronize
- ready_for_review
branches:
- develop
- "release-*"
- "release/*"
- "staging/*"
types: [opened, edited, reopened, synchronize, ready_for_review]
branches: [develop]
jobs:
check_description:

View File

@@ -5,17 +5,8 @@ on:
types:
- checks_requested
pull_request:
types:
- opened
- edited
- reopened
- synchronize
- ready_for_review
branches:
- develop
- "release-*"
- "release/*"
- "staging/*"
types: [opened, edited, reopened, synchronize, ready_for_review]
branches: [develop]
jobs:
check_title:

View File

@@ -325,6 +325,9 @@ SHAMap::descend(SHAMapInnerNode& parent, int branch) const
return node;
node = fetchNode(parent.getChildHash(branch));
if (!node)
return {};
node = parent.canonicalizeChild(branch, std::move(node));
return node;
}
@@ -336,7 +339,7 @@ SHAMap::descendNoStore(SHAMapInnerNode& parent, int branch) const
{
intr_ptr::SharedPtr<SHAMapTreeNode> ret = parent.getChild(branch);
if (!ret && backed_)
ret = fetchNodeNT(parent.getChildHash(branch));
ret = fetchNode(parent.getChildHash(branch));
return ret;
}

View File

@@ -67,12 +67,6 @@ SHAMap::visitNodes(std::function<bool(SHAMapTreeNode&)> const& function) const
if (!node->isEmptyBranch(pos))
{
intr_ptr::SharedPtr<SHAMapTreeNode> const child = descendNoStore(*node, pos);
if (!child)
{
// Node was evicted after rotation; skip this subtree.
++pos;
continue;
}
if (!function(*child))
return;

View File

@@ -12,9 +12,11 @@
#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/core/NetworkIDService.h>
#include <xrpl/json/json_value.h>
#include <xrpl/json/to_string.h>
#include <xrpl/protocol/ErrorCodes.h>
@@ -706,6 +708,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);
BEAST_EXPECT(expectedCtid.has_value());
BEAST_EXPECT(txns[i][jss::ctid] == *expectedCtid);
}
}
// 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 (unsigned i = 0; i < txns.size(); ++i)
{
BEAST_EXPECT(txns[i].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 (unsigned i = 0; i < txns.size(); ++i)
{
BEAST_EXPECT(txns[i].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 (unsigned i = 0; i < txns.size(); ++i)
{
BEAST_EXPECT(txns[i].isString());
}
}
}
public:
void
run() override
@@ -720,6 +807,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>
@@ -193,6 +195,17 @@ fillJsonTx(
}
}
// compute outgoing CTID
if (fill.context && 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)
{