mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 23:20:33 +00:00
Compare commits
5 Commits
mvadari/er
...
copilot/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbad94b7d2 | ||
|
|
47cb75207b | ||
|
|
c67e41d795 | ||
|
|
8763260b55 | ||
|
|
0dc26c871a |
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user