Unify JSON serialization format of transactions (#4775)

* Remove include <ranges>

* Formatting fix

* Output for subscriptions

* Output from sign, submit etc.

* Output from ledger

* Output from account_tx

* Output from transaction_entry

* Output from tx

* Store close_time_iso in API v2 output

* Add small APIv2 unit test for subscribe

* Add unit test for transaction_entry

* Add unit test for tx

* Remove inLedger from API version 2

* Set ledger_hash and ledger_index

* Move isValidated from RPCHelpers to LedgerMaster

* Store closeTime in LedgerFill

* Time formatting fix

* additional tests for Subscribe unit tests

* Improved comments

* Rename mInLedger to mLedgerIndex

* Minor fixes

* Set ledger_hash on closed ledger, even if not validated

* Update API-CHANGELOG.md

* Add ledger_hash, ledger_index to transaction_entry

* Fix validated and close_time_iso in account_tx

* Fix typos

* Improve getJson for Transaction and STTx

* Minor improvements

* Replace class enum JsonOptions with struct

We may consider turning this into a general-purpose template and using it elsewhere

* simplify the extraction of transactionID from Transaction object

* Remove obsolete comments

* Unconditionally set validated in account_tx output

* Minor improvements

* Minor fixes

---------

Co-authored-by: Chenna Keshava <ckeshavabs@gmail.com>
This commit is contained in:
Bronek Kozicki
2023-11-08 18:36:24 +00:00
committed by tequ
parent d75a6edc58
commit 41daa9f64c
32 changed files with 739 additions and 235 deletions

View File

@@ -36,6 +36,7 @@
#include <ripple/protocol/UintTypes.h>
#include <ripple/protocol/jss.h>
#include <boost/format.hpp>
#include <array>
#include <memory>
#include <type_traits>
@@ -228,25 +229,41 @@ STTx::checkSign(
return Unexpected("Internal signature check failure.");
}
Json::Value STTx::getJson(JsonOptions) const
Json::Value
STTx::getJson(JsonOptions options) const
{
Json::Value ret = STObject::getJson(JsonOptions::none);
ret[jss::hash] = to_string(getTransactionID());
if (!(options & JsonOptions::disable_API_prior_V2))
ret[jss::hash] = to_string(getTransactionID());
return ret;
}
Json::Value
STTx::getJson(JsonOptions options, bool binary) const
{
bool const V1 = !(options & JsonOptions::disable_API_prior_V2);
if (binary)
{
Json::Value ret;
Serializer s = STObject::getSerializer();
ret[jss::tx] = strHex(s.peekData());
ret[jss::hash] = to_string(getTransactionID());
return ret;
std::string const dataBin = strHex(s.peekData());
if (V1)
{
Json::Value ret(Json::objectValue);
ret[jss::tx] = dataBin;
ret[jss::hash] = to_string(getTransactionID());
return ret;
}
else
return Json::Value{dataBin};
}
return getJson(options);
Json::Value ret = STObject::getJson(JsonOptions::none);
if (V1)
ret[jss::hash] = to_string(getTransactionID());
return ret;
}
std::string const&