mirror of
https://github.com/XRPLF/rippled.git
synced 2026-03-13 16:22:31 +00:00
Compare commits
7 Commits
ximinez/le
...
copilot/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00d280c965 | ||
|
|
ad116a35ff | ||
|
|
249fb12e8f | ||
|
|
cbabee1bec | ||
|
|
cf2835e3c1 | ||
|
|
9b0e87a37e | ||
|
|
4a31ee1926 |
@@ -6,6 +6,13 @@ For info about how [API versioning](https://xrpl.org/request-formatting.html#api
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
### Modifications to `tx` and `account_tx`
|
||||
|
||||
In API version 2, the `tx_json` field in `tx` and `account_tx` responses includes server-added lower-case fields (`date`, `ledger_index`, and `ctid`) that are not part of the canonical signed transaction. In API version 3, these fields are removed from `tx_json` and are only present at the top-level result object.
|
||||
|
||||
- **Before (API v2)**: The `tx_json` object in the response contained `date`, `ledger_index`, and `ctid` fields alongside the canonical PascalCase transaction fields.
|
||||
- **After (API v3)**: The `tx_json` object contains only the canonical signed transaction fields. The `date`, `ledger_index`, and `ctid` fields appear exclusively at the top-level result object.
|
||||
|
||||
### Modifications to `amm_info`
|
||||
|
||||
The order of error checks has been changed to provide more specific error messages. ([#4924](https://github.com/XRPLF/rippled/pull/4924))
|
||||
|
||||
@@ -23,9 +23,10 @@ struct JsonOptions
|
||||
none = 0b0000'0000,
|
||||
include_date = 0b0000'0001,
|
||||
disable_API_prior_V2 = 0b0000'0010,
|
||||
disable_API_prior_V3 = 0b0000'0100,
|
||||
|
||||
// IMPORTANT `_all` must be union of all of the above; see also operator~
|
||||
_all = 0b0000'0011
|
||||
_all = 0b0000'0111
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
|
||||
@@ -2020,99 +2020,6 @@ rippleSendIOU(
|
||||
return terResult;
|
||||
}
|
||||
|
||||
template <class TAsset>
|
||||
static TER
|
||||
doSendMulti(
|
||||
std::string const& name,
|
||||
ApplyView& view,
|
||||
AccountID const& senderID,
|
||||
TAsset const& issue,
|
||||
MultiplePaymentDestinations const& receivers,
|
||||
STAmount& actual,
|
||||
beast::Journal j,
|
||||
WaiveTransferFee waiveFee,
|
||||
// Don't pass back parameters that the caller already has
|
||||
std::function<
|
||||
TER(AccountID const& senderID,
|
||||
AccountID const& receiverID,
|
||||
STAmount const& amount,
|
||||
bool checkIssuer)> doCredit,
|
||||
std::function<
|
||||
TER(AccountID const& issuer, STAmount const& takeFromSender, STAmount const& amount)>
|
||||
preMint = {})
|
||||
{
|
||||
// Use the same pattern for all the SendMulti functions to help avoid
|
||||
// divergence and copy/paste errors.
|
||||
auto const& issuer = issue.getIssuer();
|
||||
|
||||
// These values may not stay in sync
|
||||
STAmount takeFromSender{issue};
|
||||
actual = takeFromSender;
|
||||
|
||||
// Failures return immediately.
|
||||
for (auto const& r : receivers)
|
||||
{
|
||||
auto const& receiverID = r.first;
|
||||
STAmount amount{issue, r.second};
|
||||
|
||||
if (amount < beast::zero)
|
||||
{
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
/* If we aren't sending anything or if the sender is the same as the
|
||||
* receiver then we don't need to do anything.
|
||||
*/
|
||||
if (!amount || (senderID == receiverID))
|
||||
continue;
|
||||
|
||||
using namespace std::string_literals;
|
||||
XRPL_ASSERT(!isXRP(receiverID), ("xrpl::"s + name + " : receiver is not XRP").c_str());
|
||||
|
||||
if (senderID == issuer || receiverID == issuer || issuer == noAccount())
|
||||
{
|
||||
if (preMint)
|
||||
{
|
||||
if (auto const ter = preMint(issuer, takeFromSender, amount))
|
||||
return ter;
|
||||
}
|
||||
// Direct send: redeeming IOUs and/or sending own IOUs.
|
||||
if (auto const ter = doCredit(senderID, receiverID, amount, false))
|
||||
return ter;
|
||||
actual += amount;
|
||||
// Do not add amount to takeFromSender, because doCredit took
|
||||
// it.
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sending 3rd party: transit.
|
||||
|
||||
// Calculate the amount to transfer accounting
|
||||
// for any transfer fees if the fee is not waived:
|
||||
STAmount actualSend = (waiveFee == WaiveTransferFee::Yes || issue.native())
|
||||
? amount
|
||||
: multiply(amount, transferRate(view, amount));
|
||||
actual += actualSend;
|
||||
takeFromSender += actualSend;
|
||||
|
||||
JLOG(j.debug()) << name << "> " << to_string(senderID) << " - > " << to_string(receiverID)
|
||||
<< " : deliver=" << amount.getFullText()
|
||||
<< " cost=" << actualSend.getFullText();
|
||||
|
||||
if (TER const terResult = doCredit(issuer, receiverID, amount, true))
|
||||
return terResult;
|
||||
}
|
||||
|
||||
if (senderID != issuer && takeFromSender)
|
||||
{
|
||||
if (TER const terResult = doCredit(senderID, issuer, takeFromSender, true))
|
||||
return terResult;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
// Send regardless of limits.
|
||||
// --> receivers: Amount/currency/issuer to deliver to receivers.
|
||||
// <-- saActual: Amount actually cost to sender. Sender pays fees.
|
||||
@@ -2126,18 +2033,65 @@ rippleSendMultiIOU(
|
||||
beast::Journal j,
|
||||
WaiveTransferFee waiveFee)
|
||||
{
|
||||
auto const& issuer = issue.getIssuer();
|
||||
|
||||
XRPL_ASSERT(!isXRP(senderID), "xrpl::rippleSendMultiIOU : sender is not XRP");
|
||||
|
||||
auto doCredit = [&view, j](
|
||||
AccountID const& senderID,
|
||||
AccountID const& receiverID,
|
||||
STAmount const& amount,
|
||||
bool checkIssuer) {
|
||||
return rippleCreditIOU(view, senderID, receiverID, amount, checkIssuer, j);
|
||||
};
|
||||
// These may diverge
|
||||
STAmount takeFromSender{issue};
|
||||
actual = takeFromSender;
|
||||
|
||||
return doSendMulti(
|
||||
"rippleSendMultiIOU", view, senderID, issue, receivers, actual, j, waiveFee, doCredit);
|
||||
// Failures return immediately.
|
||||
for (auto const& r : receivers)
|
||||
{
|
||||
auto const& receiverID = r.first;
|
||||
STAmount amount{issue, r.second};
|
||||
|
||||
/* If we aren't sending anything or if the sender is the same as the
|
||||
* receiver then we don't need to do anything.
|
||||
*/
|
||||
if (!amount || (senderID == receiverID))
|
||||
continue;
|
||||
|
||||
XRPL_ASSERT(!isXRP(receiverID), "xrpl::rippleSendMultiIOU : receiver is not XRP");
|
||||
|
||||
if (senderID == issuer || receiverID == issuer || issuer == noAccount())
|
||||
{
|
||||
// Direct send: redeeming IOUs and/or sending own IOUs.
|
||||
if (auto const ter = rippleCreditIOU(view, senderID, receiverID, amount, false, j))
|
||||
return ter;
|
||||
actual += amount;
|
||||
// Do not add amount to takeFromSender, because rippleCreditIOU took
|
||||
// it.
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sending 3rd party IOUs: transit.
|
||||
|
||||
// Calculate the amount to transfer accounting
|
||||
// for any transfer fees if the fee is not waived:
|
||||
STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
|
||||
? amount
|
||||
: multiply(amount, transferRate(view, issuer));
|
||||
actual += actualSend;
|
||||
takeFromSender += actualSend;
|
||||
|
||||
JLOG(j.debug()) << "rippleSendMultiIOU> " << to_string(senderID) << " - > "
|
||||
<< to_string(receiverID) << " : deliver=" << amount.getFullText()
|
||||
<< " cost=" << actual.getFullText();
|
||||
|
||||
if (TER const terResult = rippleCreditIOU(view, issuer, receiverID, amount, true, j))
|
||||
return terResult;
|
||||
}
|
||||
|
||||
if (senderID != issuer && takeFromSender)
|
||||
{
|
||||
if (TER const terResult = rippleCreditIOU(view, senderID, issuer, takeFromSender, true, j))
|
||||
return terResult;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
static TER
|
||||
@@ -2271,9 +2225,9 @@ accountSendMultiIOU(
|
||||
XRPL_ASSERT_PARTS(
|
||||
receivers.size() > 1, "xrpl::accountSendMultiIOU", "multiple recipients provided");
|
||||
|
||||
STAmount actual;
|
||||
if (!issue.native())
|
||||
{
|
||||
STAmount actual;
|
||||
JLOG(j.trace()) << "accountSendMultiIOU: " << to_string(senderID) << " sending "
|
||||
<< receivers.size() << " IOUs";
|
||||
|
||||
@@ -2300,85 +2254,6 @@ accountSendMultiIOU(
|
||||
<< receivers.size() << " receivers.";
|
||||
}
|
||||
|
||||
auto doCredit = [&view, &sender, &receivers, j](
|
||||
AccountID const& senderID,
|
||||
AccountID const& receiverID,
|
||||
STAmount const& amount,
|
||||
bool /*checkIssuer*/) -> TER {
|
||||
if (!senderID)
|
||||
{
|
||||
SLE::pointer receiver =
|
||||
receiverID != beast::zero ? view.peek(keylet::account(receiverID)) : SLE::pointer();
|
||||
|
||||
if (auto stream = j.trace())
|
||||
{
|
||||
std::string receiver_bal("-");
|
||||
|
||||
if (receiver)
|
||||
receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
|
||||
|
||||
stream << "accountSendMultiIOU> " << to_string(senderID) << " -> "
|
||||
<< to_string(receiverID) << " (" << receiver_bal
|
||||
<< ") : " << amount.getFullText();
|
||||
}
|
||||
|
||||
if (receiver)
|
||||
{
|
||||
// Increment XRP balance.
|
||||
auto const rcvBal = receiver->getFieldAmount(sfBalance);
|
||||
receiver->setFieldAmount(sfBalance, rcvBal + amount);
|
||||
view.creditHook(xrpAccount(), receiverID, amount, -rcvBal);
|
||||
|
||||
view.update(receiver);
|
||||
}
|
||||
|
||||
if (auto stream = j.trace())
|
||||
{
|
||||
std::string receiver_bal("-");
|
||||
|
||||
if (receiver)
|
||||
receiver_bal = receiver->getFieldAmount(sfBalance).getFullText();
|
||||
|
||||
stream << "accountSendMultiIOU< " << to_string(senderID) << " -> "
|
||||
<< to_string(receiverID) << " (" << receiver_bal
|
||||
<< ") : " << amount.getFullText();
|
||||
}
|
||||
return tesSUCCESS;
|
||||
}
|
||||
// Sender
|
||||
if (sender)
|
||||
{
|
||||
if (sender->getFieldAmount(sfBalance) < amount)
|
||||
{
|
||||
return TER{tecFAILED_PROCESSING};
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const sndBal = sender->getFieldAmount(sfBalance);
|
||||
view.creditHook(senderID, xrpAccount(), amount, sndBal);
|
||||
|
||||
// Decrement XRP balance.
|
||||
sender->setFieldAmount(sfBalance, sndBal - amount);
|
||||
view.update(sender);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto stream = j.trace())
|
||||
{
|
||||
std::string sender_bal("-");
|
||||
|
||||
if (sender)
|
||||
sender_bal = sender->getFieldAmount(sfBalance).getFullText();
|
||||
|
||||
stream << "accountSendMultiIOU< " << to_string(senderID) << " (" << sender_bal
|
||||
<< ") -> " << receivers.size() << " receivers.";
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
};
|
||||
return doSendMulti(
|
||||
"accountSendMultiIOU", view, senderID, issue, receivers, actual, j, waiveFee, doCredit);
|
||||
|
||||
// Failures return immediately.
|
||||
STAmount takeFromSender{issue};
|
||||
for (auto const& r : receivers)
|
||||
@@ -2596,47 +2471,82 @@ rippleSendMultiMPT(
|
||||
beast::Journal j,
|
||||
WaiveTransferFee waiveFee)
|
||||
{
|
||||
// Safe to get MPT since rippleSendMultiMPT is only called by
|
||||
// accountSendMultiMPT
|
||||
auto const& issuer = mptIssue.getIssuer();
|
||||
|
||||
auto const sle = view.read(keylet::mptIssuance(mptIssue.getMptID()));
|
||||
if (!sle)
|
||||
return tecOBJECT_NOT_FOUND;
|
||||
|
||||
auto preMint = [&](AccountID const& issuer,
|
||||
STAmount const& takeFromSender,
|
||||
STAmount const& amount) -> TER {
|
||||
// if sender is issuer, check that the new OutstandingAmount will
|
||||
// not exceed MaximumAmount
|
||||
if (senderID == issuer)
|
||||
// These may diverge
|
||||
STAmount takeFromSender{mptIssue};
|
||||
actual = takeFromSender;
|
||||
|
||||
for (auto const& r : receivers)
|
||||
{
|
||||
auto const& receiverID = r.first;
|
||||
STAmount amount{mptIssue, r.second};
|
||||
|
||||
if (amount < beast::zero)
|
||||
{
|
||||
XRPL_ASSERT_PARTS(
|
||||
takeFromSender == beast::zero,
|
||||
"rippler::rippleSendMultiMPT",
|
||||
"sender == issuer, takeFromSender == zero");
|
||||
auto const sendAmount = amount.mpt().value();
|
||||
auto const maximumAmount = sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount);
|
||||
if (sendAmount > maximumAmount ||
|
||||
sle->getFieldU64(sfOutstandingAmount) > maximumAmount - sendAmount)
|
||||
return tecPATH_DRY;
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
};
|
||||
auto doCredit =
|
||||
[&view, j](
|
||||
AccountID const& senderID, AccountID const& receiverID, STAmount const& amount, bool) {
|
||||
return rippleCreditMPT(view, senderID, receiverID, amount, j);
|
||||
};
|
||||
/* If we aren't sending anything or if the sender is the same as the
|
||||
* receiver then we don't need to do anything.
|
||||
*/
|
||||
if (!amount || (senderID == receiverID))
|
||||
continue;
|
||||
|
||||
return doSendMulti(
|
||||
"rippleSendMultiMPT",
|
||||
view,
|
||||
senderID,
|
||||
mptIssue,
|
||||
receivers,
|
||||
actual,
|
||||
j,
|
||||
waiveFee,
|
||||
doCredit,
|
||||
preMint);
|
||||
if (senderID == issuer || receiverID == issuer)
|
||||
{
|
||||
// if sender is issuer, check that the new OutstandingAmount will
|
||||
// not exceed MaximumAmount
|
||||
if (senderID == issuer)
|
||||
{
|
||||
XRPL_ASSERT_PARTS(
|
||||
takeFromSender == beast::zero,
|
||||
"rippler::rippleSendMultiMPT",
|
||||
"sender == issuer, takeFromSender == zero");
|
||||
auto const sendAmount = amount.mpt().value();
|
||||
auto const maximumAmount = sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount);
|
||||
if (sendAmount > maximumAmount ||
|
||||
sle->getFieldU64(sfOutstandingAmount) > maximumAmount - sendAmount)
|
||||
return tecPATH_DRY;
|
||||
}
|
||||
|
||||
// Direct send: redeeming MPTs and/or sending own MPTs.
|
||||
if (auto const ter = rippleCreditMPT(view, senderID, receiverID, amount, j))
|
||||
return ter;
|
||||
actual += amount;
|
||||
// Do not add amount to takeFromSender, because rippleCreditMPT took
|
||||
// it
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sending 3rd party MPTs: transit.
|
||||
STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
|
||||
? amount
|
||||
: multiply(amount, transferRate(view, amount.get<MPTIssue>().getMptID()));
|
||||
actual += actualSend;
|
||||
takeFromSender += actualSend;
|
||||
|
||||
JLOG(j.debug()) << "rippleSendMultiMPT> " << to_string(senderID) << " - > "
|
||||
<< to_string(receiverID) << " : deliver=" << amount.getFullText()
|
||||
<< " cost=" << actualSend.getFullText();
|
||||
|
||||
if (auto const terResult = rippleCreditMPT(view, issuer, receiverID, amount, j))
|
||||
return terResult;
|
||||
}
|
||||
if (senderID != issuer && takeFromSender)
|
||||
{
|
||||
if (TER const terResult = rippleCreditMPT(view, senderID, issuer, takeFromSender, j))
|
||||
return terResult;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
static TER
|
||||
|
||||
@@ -122,20 +122,52 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
{
|
||||
auto const& payment = j[jss::result][jss::transactions][1u];
|
||||
|
||||
return (payment.isMember(jss::tx_json)) &&
|
||||
(payment[jss::tx_json][jss::TransactionType] == jss::Payment) &&
|
||||
(payment[jss::tx_json][jss::DeliverMax] == "10000000010") &&
|
||||
(!payment[jss::tx_json].isMember(jss::Amount)) &&
|
||||
(!payment[jss::tx_json].isMember(jss::hash)) &&
|
||||
(payment[jss::hash] ==
|
||||
"9F3085D85F472D1CC29627F260DF68EDE59D42D1D0C33E345"
|
||||
"ECF0D4CE981D0A8") &&
|
||||
(payment[jss::validated] == true) &&
|
||||
(payment[jss::ledger_index] == 3) &&
|
||||
(payment[jss::ledger_hash] ==
|
||||
"5476DCD816EA04CBBA57D47BBF1FC58A5217CC93A5ADD79CB"
|
||||
"580A5AFDD727E33") &&
|
||||
(payment[jss::close_time_iso] == "2000-01-01T00:00:10Z");
|
||||
if (apiVersion >= 3)
|
||||
{
|
||||
// In API v3, server-added lower-case fields must
|
||||
// not be in tx_json, but must be at result level
|
||||
return (payment.isMember(jss::tx_json)) &&
|
||||
(payment[jss::tx_json][jss::TransactionType] == jss::Payment) &&
|
||||
(payment[jss::tx_json][jss::DeliverMax] == "10000000010") &&
|
||||
(!payment[jss::tx_json].isMember(jss::Amount)) &&
|
||||
(!payment[jss::tx_json].isMember(jss::hash)) &&
|
||||
(!payment[jss::tx_json].isMember(jss::date)) &&
|
||||
(!payment[jss::tx_json].isMember(jss::ledger_index)) &&
|
||||
(!payment[jss::tx_json].isMember(jss::ctid)) &&
|
||||
// date and ctid must be at the transaction
|
||||
// object level (outside tx_json) in API v3
|
||||
(payment.isMember(jss::date)) && (payment.isMember(jss::ctid)) &&
|
||||
(payment[jss::hash] ==
|
||||
"9F3085D85F472D1CC29627F260DF68EDE59D42D1D0C33E345"
|
||||
"ECF0D4CE981D0A8") &&
|
||||
(payment[jss::validated] == true) &&
|
||||
(payment[jss::ledger_index] == 3) &&
|
||||
(payment[jss::ledger_hash] ==
|
||||
"5476DCD816EA04CBBA57D47BBF1FC58A5217CC93A5ADD79CB"
|
||||
"580A5AFDD727E33") &&
|
||||
(payment[jss::close_time_iso] == "2000-01-01T00:00:10Z");
|
||||
}
|
||||
else
|
||||
{
|
||||
// In API v2, date and ledger_index are still in
|
||||
// tx_json for backwards compatibility
|
||||
return (payment.isMember(jss::tx_json)) &&
|
||||
(payment[jss::tx_json][jss::TransactionType] == jss::Payment) &&
|
||||
(payment[jss::tx_json][jss::DeliverMax] == "10000000010") &&
|
||||
(!payment[jss::tx_json].isMember(jss::Amount)) &&
|
||||
(!payment[jss::tx_json].isMember(jss::hash)) &&
|
||||
(payment[jss::tx_json].isMember(jss::date)) &&
|
||||
(payment[jss::tx_json].isMember(jss::ledger_index)) &&
|
||||
(payment[jss::hash] ==
|
||||
"9F3085D85F472D1CC29627F260DF68EDE59D42D1D0C33E345"
|
||||
"ECF0D4CE981D0A8") &&
|
||||
(payment[jss::validated] == true) &&
|
||||
(payment[jss::ledger_index] == 3) &&
|
||||
(payment[jss::ledger_hash] ==
|
||||
"5476DCD816EA04CBBA57D47BBF1FC58A5217CC93A5ADD79CB"
|
||||
"580A5AFDD727E33") &&
|
||||
(payment[jss::close_time_iso] == "2000-01-01T00:00:10Z");
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
@@ -760,6 +760,25 @@ class Transaction_test : public beast::unit_test::suite
|
||||
result[jss::result][jss::ledger_hash] ==
|
||||
"B41882E20F0EC6228417D28B9AE0F33833645D35F6799DFB782AC97FC4BB51"
|
||||
"D2");
|
||||
|
||||
auto const& tx_json = result[jss::result][jss::tx_json];
|
||||
if (apiVersion >= 3)
|
||||
{
|
||||
// In API v3, server-added lower-case fields must not appear
|
||||
// inside tx_json; they are at the result level.
|
||||
BEAST_EXPECT(!tx_json.isMember(jss::date));
|
||||
BEAST_EXPECT(!tx_json.isMember(jss::ledger_index));
|
||||
BEAST_EXPECT(!tx_json.isMember(jss::ctid));
|
||||
// date must be at result level in API v3
|
||||
BEAST_EXPECT(result[jss::result].isMember(jss::date));
|
||||
}
|
||||
else
|
||||
{
|
||||
// In API v2, date and ledger_index are still included in
|
||||
// tx_json for backwards compatibility.
|
||||
BEAST_EXPECT(tx_json.isMember(jss::date));
|
||||
BEAST_EXPECT(tx_json.isMember(jss::ledger_index));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto memberIt = expected.begin(); memberIt != expected.end(); memberIt++)
|
||||
|
||||
@@ -141,28 +141,30 @@ Transaction::getJson(JsonOptions options, bool binary) const
|
||||
ret[jss::inLedger] = mLedgerIndex;
|
||||
}
|
||||
|
||||
// TODO: disable_API_prior_V3 to disable output of both `date` and
|
||||
// `ledger_index` elements (taking precedence over include_date)
|
||||
ret[jss::ledger_index] = mLedgerIndex;
|
||||
|
||||
if (options & JsonOptions::include_date)
|
||||
if (!(options & JsonOptions::disable_API_prior_V3))
|
||||
{
|
||||
auto ct = mApp.getLedgerMaster().getCloseTimeBySeq(mLedgerIndex);
|
||||
if (ct)
|
||||
ret[jss::date] = ct->time_since_epoch().count();
|
||||
}
|
||||
ret[jss::ledger_index] = mLedgerIndex;
|
||||
|
||||
// compute outgoing CTID
|
||||
// override local network id if it's explicitly in the txn
|
||||
std::optional netID = mNetworkID;
|
||||
if (mTransaction->isFieldPresent(sfNetworkID))
|
||||
netID = mTransaction->getFieldU32(sfNetworkID);
|
||||
if (options & JsonOptions::include_date)
|
||||
{
|
||||
auto ct = mApp.getLedgerMaster().getCloseTimeBySeq(mLedgerIndex);
|
||||
if (ct)
|
||||
ret[jss::date] = ct->time_since_epoch().count();
|
||||
}
|
||||
|
||||
if (mTxnSeq && netID)
|
||||
{
|
||||
std::optional<std::string> const ctid = RPC::encodeCTID(mLedgerIndex, *mTxnSeq, *netID);
|
||||
if (ctid)
|
||||
ret[jss::ctid] = *ctid;
|
||||
// compute outgoing CTID
|
||||
// override local network id if it's explicitly in the txn
|
||||
std::optional netID = mNetworkID;
|
||||
if (mTransaction->isFieldPresent(sfNetworkID))
|
||||
netID = mTransaction->getFieldU32(sfNetworkID);
|
||||
|
||||
if (mTxnSeq && netID)
|
||||
{
|
||||
std::optional<std::string> const ctid =
|
||||
RPC::encodeCTID(mLedgerIndex, *mTxnSeq, *netID);
|
||||
if (ctid)
|
||||
ret[jss::ctid] = *ctid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <xrpld/app/misc/DeliverMax.h>
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/rpc/CTID.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/DeliveredAmount.h>
|
||||
#include <xrpld/rpc/MPTokenIssuanceID.h>
|
||||
@@ -11,6 +12,7 @@
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/core/NetworkIDService.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
@@ -286,8 +288,10 @@ populateJsonResponse(
|
||||
auto const json_tx = (context.apiVersion > 1 ? jss::tx_json : jss::tx);
|
||||
if (context.apiVersion > 1)
|
||||
{
|
||||
jvObj[json_tx] = txn->getJson(
|
||||
JsonOptions::include_date | JsonOptions::disable_API_prior_V2, false);
|
||||
auto const opts = context.apiVersion >= 3
|
||||
? JsonOptions::disable_API_prior_V2 | JsonOptions::disable_API_prior_V3
|
||||
: JsonOptions::include_date | JsonOptions::disable_API_prior_V2;
|
||||
jvObj[json_tx] = txn->getJson(opts, false);
|
||||
jvObj[jss::hash] = to_string(txn->getID());
|
||||
jvObj[jss::ledger_index] = txn->getLedger();
|
||||
jvObj[jss::ledger_hash] =
|
||||
@@ -295,7 +299,20 @@ populateJsonResponse(
|
||||
|
||||
if (auto closeTime =
|
||||
context.ledgerMaster.getCloseTimeBySeq(txn->getLedger()))
|
||||
{
|
||||
jvObj[jss::close_time_iso] = to_string_iso(*closeTime);
|
||||
if (context.apiVersion >= 3)
|
||||
jvObj[jss::date] = closeTime->time_since_epoch().count();
|
||||
}
|
||||
|
||||
if (context.apiVersion >= 3 && txnMeta)
|
||||
{
|
||||
uint32_t const lgrSeq = txn->getLedger();
|
||||
uint32_t const txnIdx = txnMeta->getIndex();
|
||||
uint32_t const netID = context.app.getNetworkIDService().getNetworkID();
|
||||
if (auto const ctid = RPC::encodeCTID(lgrSeq, txnIdx, netID))
|
||||
jvObj[jss::ctid] = *ctid;
|
||||
}
|
||||
}
|
||||
else
|
||||
jvObj[json_tx] = txn->getJson(JsonOptions::include_date);
|
||||
|
||||
@@ -189,8 +189,14 @@ populateJsonResponse(
|
||||
auto const& sttx = result.txn->getSTransaction();
|
||||
if (context.apiVersion > 1)
|
||||
{
|
||||
constexpr auto optionsJson =
|
||||
// In API v2, include_date and disable_API_prior_V2 are used to
|
||||
// include date/ledger_index/ctid in tx_json. In API v3+, those
|
||||
// fields are excluded from tx_json and are only at result level.
|
||||
constexpr auto optionsV2 =
|
||||
JsonOptions::include_date | JsonOptions::disable_API_prior_V2;
|
||||
constexpr auto optionsV3 =
|
||||
JsonOptions::disable_API_prior_V2 | JsonOptions::disable_API_prior_V3;
|
||||
auto const optionsJson = context.apiVersion >= 3 ? optionsV3 : optionsV2;
|
||||
if (args.binary)
|
||||
response[jss::tx_blob] = result.txn->getJson(optionsJson, true);
|
||||
else
|
||||
@@ -210,7 +216,11 @@ populateJsonResponse(
|
||||
{
|
||||
response[jss::ledger_index] = result.txn->getLedger();
|
||||
if (result.closeTime)
|
||||
{
|
||||
response[jss::close_time_iso] = to_string_iso(*result.closeTime);
|
||||
if (context.apiVersion >= 3)
|
||||
response[jss::date] = result.closeTime->time_since_epoch().count();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user