mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-02 16:26:48 +00:00
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.
This commit is contained in:
committed by
GitHub
parent
f9551ac5ca
commit
0dc26c871a
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user