Fix #985
This commit is contained in:
cyan317
2023-11-24 16:01:27 +00:00
committed by GitHub
parent 3b75d88a35
commit a5fbb01299
2 changed files with 54 additions and 25 deletions

View File

@@ -164,7 +164,9 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con
} }
boost::json::object obj; boost::json::object obj;
if (!input.binary) {
// if binary is true or transactionType is specified, we need to expand the transaction
if (!input.binary || input.transactionType.has_value()) {
auto [txn, meta] = toExpandedJson(txnPlusMeta, ctx.apiVersion, NFTokenjson::ENABLE); auto [txn, meta] = toExpandedJson(txnPlusMeta, ctx.apiVersion, NFTokenjson::ENABLE);
if (txn.contains(JS(TransactionType))) { if (txn.contains(JS(TransactionType))) {
@@ -177,35 +179,38 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con
continue; continue;
} }
auto const txKey = ctx.apiVersion < 2u ? JS(tx) : JS(tx_json); if (!input.binary) {
obj[JS(meta)] = std::move(meta); auto const txKey = ctx.apiVersion < 2u ? JS(tx) : JS(tx_json);
obj[txKey] = std::move(txn); obj[JS(meta)] = std::move(meta);
obj[txKey].as_object()[JS(date)] = txnPlusMeta.date; obj[txKey] = std::move(txn);
obj[txKey].as_object()[JS(ledger_index)] = txnPlusMeta.ledgerSequence; obj[txKey].as_object()[JS(date)] = txnPlusMeta.date;
obj[txKey].as_object()[JS(ledger_index)] = txnPlusMeta.ledgerSequence;
if (ctx.apiVersion < 2u) { if (ctx.apiVersion < 2u) {
obj[txKey].as_object()[JS(inLedger)] = txnPlusMeta.ledgerSequence; obj[txKey].as_object()[JS(inLedger)] = txnPlusMeta.ledgerSequence;
} else { } else {
obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence; obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence;
if (obj[txKey].as_object().contains(JS(hash))) { if (obj[txKey].as_object().contains(JS(hash))) {
obj[JS(hash)] = obj[txKey].as_object()[JS(hash)]; obj[JS(hash)] = obj[txKey].as_object()[JS(hash)];
obj[txKey].as_object().erase(JS(hash)); obj[txKey].as_object().erase(JS(hash));
} }
if (auto const ledgerInfo = if (auto const ledgerInfo =
sharedPtrBackend_->fetchLedgerBySequence(txnPlusMeta.ledgerSequence, ctx.yield); sharedPtrBackend_->fetchLedgerBySequence(txnPlusMeta.ledgerSequence, ctx.yield);
ledgerInfo) { ledgerInfo) {
obj[JS(ledger_hash)] = ripple::strHex(ledgerInfo->hash); obj[JS(ledger_hash)] = ripple::strHex(ledgerInfo->hash);
obj[JS(close_time_iso)] = ripple::to_string_iso(ledgerInfo->closeTime); obj[JS(close_time_iso)] = ripple::to_string_iso(ledgerInfo->closeTime);
}
} }
obj[JS(validated)] = true;
response.transactions.push_back(std::move(obj));
continue;
} }
} else {
obj = toJsonWithBinaryTx(txnPlusMeta, ctx.apiVersion);
obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence;
} }
// binary is true
obj = toJsonWithBinaryTx(txnPlusMeta, ctx.apiVersion);
obj[JS(validated)] = true; obj[JS(validated)] = true;
obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence;
response.transactions.push_back(obj); response.transactions.push_back(std::move(obj));
} }
response.limit = input.limit; response.limit = input.limit;

View File

@@ -1854,8 +1854,32 @@ generateTransactionTypeTestValues()
} }
])", ])",
2u}, 2u},
AccountTxTransactionBundle{
"FilterWhenBinaryTrue",
R"({
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"ledger_index": "validated",
"tx_type": "Payment",
"binary": true
})",
R"([{
"meta": "201C00000000F8E5110061E762400000000000001681144B4E9C06F24296074F7BC48F92A97916C6DC5EA9E1E1E5110061E76240000000000000178114D31252CF902EF8DD8451243869B38667CBD89DF3E1E1F1031000",
"tx_blob": "120000240000002061400000000000000168400000000000000173047465737481144B4E9C06F24296074F7BC48F92A97916C6DC5EA98314D31252CF902EF8DD8451243869B38667CBD89DF3",
"ledger_index": 30,
"validated": true
}])",
1u},
AccountTxTransactionBundle{ AccountTxTransactionBundle{
"PaymentChannelClaim", "PaymentChannelClaim",
R"({
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"ledger_index": "validated",
"tx_type": "PaymentChannelClaim",
"binary": true
})",
"[]"},
AccountTxTransactionBundle{
"FilterWhenBinaryTrueEmptyResult",
R"({ R"({
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"ledger_index": "validated", "ledger_index": "validated",