From a5fbb012999563d4dc01df6604ea58b5f812c999 Mon Sep 17 00:00:00 2001 From: cyan317 <120398799+cindyyan317@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:01:27 +0000 Subject: [PATCH] fix (#999) Fix #985 --- src/rpc/handlers/AccountTx.cpp | 55 ++++++++++++----------- unittests/rpc/handlers/AccountTxTests.cpp | 24 ++++++++++ 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/rpc/handlers/AccountTx.cpp b/src/rpc/handlers/AccountTx.cpp index a63c610d..c348cb41 100644 --- a/src/rpc/handlers/AccountTx.cpp +++ b/src/rpc/handlers/AccountTx.cpp @@ -164,7 +164,9 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con } 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); if (txn.contains(JS(TransactionType))) { @@ -177,35 +179,38 @@ AccountTxHandler::process(AccountTxHandler::Input input, Context const& ctx) con continue; } - auto const txKey = ctx.apiVersion < 2u ? JS(tx) : JS(tx_json); - obj[JS(meta)] = std::move(meta); - obj[txKey] = std::move(txn); - obj[txKey].as_object()[JS(date)] = txnPlusMeta.date; - obj[txKey].as_object()[JS(ledger_index)] = txnPlusMeta.ledgerSequence; + if (!input.binary) { + auto const txKey = ctx.apiVersion < 2u ? JS(tx) : JS(tx_json); + obj[JS(meta)] = std::move(meta); + obj[txKey] = std::move(txn); + obj[txKey].as_object()[JS(date)] = txnPlusMeta.date; + obj[txKey].as_object()[JS(ledger_index)] = txnPlusMeta.ledgerSequence; - if (ctx.apiVersion < 2u) { - obj[txKey].as_object()[JS(inLedger)] = txnPlusMeta.ledgerSequence; - } else { - obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence; - if (obj[txKey].as_object().contains(JS(hash))) { - obj[JS(hash)] = obj[txKey].as_object()[JS(hash)]; - obj[txKey].as_object().erase(JS(hash)); - } - if (auto const ledgerInfo = - sharedPtrBackend_->fetchLedgerBySequence(txnPlusMeta.ledgerSequence, ctx.yield); - ledgerInfo) { - obj[JS(ledger_hash)] = ripple::strHex(ledgerInfo->hash); - obj[JS(close_time_iso)] = ripple::to_string_iso(ledgerInfo->closeTime); + if (ctx.apiVersion < 2u) { + obj[txKey].as_object()[JS(inLedger)] = txnPlusMeta.ledgerSequence; + } else { + obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence; + if (obj[txKey].as_object().contains(JS(hash))) { + obj[JS(hash)] = obj[txKey].as_object()[JS(hash)]; + obj[txKey].as_object().erase(JS(hash)); + } + if (auto const ledgerInfo = + sharedPtrBackend_->fetchLedgerBySequence(txnPlusMeta.ledgerSequence, ctx.yield); + ledgerInfo) { + obj[JS(ledger_hash)] = ripple::strHex(ledgerInfo->hash); + 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; - - response.transactions.push_back(obj); + obj[JS(ledger_index)] = txnPlusMeta.ledgerSequence; + response.transactions.push_back(std::move(obj)); } response.limit = input.limit; diff --git a/unittests/rpc/handlers/AccountTxTests.cpp b/unittests/rpc/handlers/AccountTxTests.cpp index 0b2a1fca..1290f36e 100644 --- a/unittests/rpc/handlers/AccountTxTests.cpp +++ b/unittests/rpc/handlers/AccountTxTests.cpp @@ -1854,8 +1854,32 @@ generateTransactionTypeTestValues() } ])", 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{ "PaymentChannelClaim", + R"({ + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "ledger_index": "validated", + "tx_type": "PaymentChannelClaim", + "binary": true + })", + "[]"}, + AccountTxTransactionBundle{ + "FilterWhenBinaryTrueEmptyResult", R"({ "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "ledger_index": "validated",