Skip to content

Commit

Permalink
Output from account_tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 26, 2023
1 parent 92635aa commit e4ce8b1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
21 changes: 18 additions & 3 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand All @@ -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;
}
Expand Down
47 changes: 31 additions & 16 deletions src/test/rpc/AccountTx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e4ce8b1

Please sign in to comment.