diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index bd939a92f1c..2a4ae3648e3 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -326,10 +326,23 @@ populateJsonResponse( { Json::Value& jvObj = jvTxns.append(Json::objectValue); - jvObj[jss::tx] = txn->getJson(JsonOptions::include_date); + auto const json_tx = + (context.apiVersion > 1 ? jss::tx_json : jss::tx); + if (context.apiVersion > 1) + { + std::string hash; + jvObj[json_tx] = txn->getJson( + JsonOptions::include_date, false, {std::ref(hash)}); + jvObj[jss::hash] = hash; + // TODO set `jvObj[jss::close_time_iso]` + } + else + jvObj[json_tx] = + txn->getJson(JsonOptions::include_date); + auto const& sttx = txn->getSTransaction(); RPC::insertDeliverMax( - jvObj[jss::tx], sttx->getTxnType(), context.apiVersion); + jvObj[json_tx], sttx->getTxnType(), context.apiVersion); if (txnMeta) { jvObj[jss::meta] = @@ -352,7 +365,9 @@ populateJsonResponse( Json::Value& jvObj = jvTxns.append(Json::objectValue); jvObj[jss::tx_blob] = strHex(std::get<0>(binaryData)); - jvObj[jss::meta] = strHex(std::get<1>(binaryData)); + auto const json_meta = + (context.apiVersion > 1 ? jss::meta_blob : jss::meta); + jvObj[json_meta] = strHex(std::get<1>(binaryData)); jvObj[jss::ledger_index] = std::get<2>(binaryData); jvObj[jss::validated] = true; } diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index 8c583ee1254..3cfcda75847 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -120,22 +120,37 @@ class AccountTx_test : public beast::unit_test::suite // All other ledgers have no txs auto hasTxs = [apiVersion](Json::Value const& j) { - return j.isMember(jss::result) && - (j[jss::result][jss::status] == "success") && - (j[jss::result][jss::transactions].size() == 2) && - (j[jss::result][jss::transactions][0u][jss::tx] - [jss::TransactionType] == jss::AccountSet) && - (j[jss::result][jss::transactions][1u][jss::tx] - [jss::TransactionType] == jss::Payment) && - (j[jss::result][jss::transactions][1u][jss::tx] - [jss::DeliverMax] == "10000000010") && - ((apiVersion > 1 && - !j[jss::result][jss::transactions][1u][jss::tx].isMember( - jss::Amount)) || - (apiVersion <= 1 && - j[jss::result][jss::transactions][1u][jss::tx][jss::Amount] == - j[jss::result][jss::transactions][1u][jss::tx] - [jss::DeliverMax])); + switch (apiVersion) + { + case 1: + return j.isMember(jss::result) && + (j[jss::result][jss::status] == "success") && + (j[jss::result][jss::transactions].size() == 2) && + (j[jss::result][jss::transactions][0u][jss::tx] + [jss::TransactionType] == jss::AccountSet) && + (j[jss::result][jss::transactions][1u][jss::tx] + [jss::TransactionType] == jss::Payment) && + (j[jss::result][jss::transactions][1u][jss::tx] + [jss::DeliverMax] == "10000000010") && + (j[jss::result][jss::transactions][1u][jss::tx] + [jss::Amount] == + j[jss::result][jss::transactions][1u][jss::tx] + [jss::DeliverMax]); + case 2: + return j.isMember(jss::result) && + (j[jss::result][jss::status] == "success") && + (j[jss::result][jss::transactions].size() == 2) && + (j[jss::result][jss::transactions][0u][jss::tx_json] + [jss::TransactionType] == jss::AccountSet) && + (j[jss::result][jss::transactions][1u][jss::tx_json] + [jss::TransactionType] == jss::Payment) && + (j[jss::result][jss::transactions][1u][jss::tx_json] + [jss::DeliverMax] == "10000000010") && + (!j[jss::result][jss::transactions][1u][jss::tx_json] + .isMember(jss::Amount)); + default: + return false; + } }; auto noTxs = [](Json::Value const& j) {