insert delivered_amount based on close time (#252)

This commit is contained in:
CJ Cobb
2022-09-07 18:28:07 -04:00
committed by GitHub
parent ef39c04e1e
commit ac45cce5bd
3 changed files with 11 additions and 7 deletions

View File

@@ -296,7 +296,8 @@ std::optional<ripple::STAmount>
getDeliveredAmount( getDeliveredAmount(
std::shared_ptr<ripple::STTx const> const& txn, std::shared_ptr<ripple::STTx const> const& txn,
std::shared_ptr<ripple::TxMeta const> const& meta, std::shared_ptr<ripple::TxMeta const> const& meta,
std::uint32_t const ledgerSequence) std::uint32_t const ledgerSequence,
uint32_t date)
{ {
if (meta->hasDeliveredAmount()) if (meta->hasDeliveredAmount())
return meta->getDeliveredAmount(); return meta->getDeliveredAmount();
@@ -312,7 +313,7 @@ getDeliveredAmount(
// then its absence indicates that the amount delivered is listed in the // then its absence indicates that the amount delivered is listed in the
// Amount field. DeliveredAmount went live January 24, 2014. // Amount field. DeliveredAmount went live January 24, 2014.
// 446000000 is in Feb 2014, well after DeliveredAmount went live // 446000000 is in Feb 2014, well after DeliveredAmount went live
if (ledgerSequence >= 4594095) if (ledgerSequence >= 4594095 || date > 446000000)
{ {
return txn->getFieldAmount(ripple::sfAmount); return txn->getFieldAmount(ripple::sfAmount);
} }
@@ -458,7 +459,7 @@ toExpandedJson(Backend::TransactionAndMetadata const& blobs)
auto [txn, meta] = deserializeTxPlusMeta(blobs, blobs.ledgerSequence); auto [txn, meta] = deserializeTxPlusMeta(blobs, blobs.ledgerSequence);
auto txnJson = toJson(*txn); auto txnJson = toJson(*txn);
auto metaJson = toJson(*meta); auto metaJson = toJson(*meta);
insertDeliveredAmount(metaJson, txn, meta); insertDeliveredAmount(metaJson, txn, meta, blobs.date);
return {txnJson, metaJson}; return {txnJson, metaJson};
} }
@@ -466,11 +467,12 @@ bool
insertDeliveredAmount( insertDeliveredAmount(
boost::json::object& metaJson, boost::json::object& metaJson,
std::shared_ptr<ripple::STTx const> const& txn, std::shared_ptr<ripple::STTx const> const& txn,
std::shared_ptr<ripple::TxMeta const> const& meta) std::shared_ptr<ripple::TxMeta const> const& meta,
uint32_t date)
{ {
if (canHaveDeliveredAmount(txn, meta)) if (canHaveDeliveredAmount(txn, meta))
{ {
if (auto amt = getDeliveredAmount(txn, meta, meta->getLgrSeq())) if (auto amt = getDeliveredAmount(txn, meta, meta->getLgrSeq(), date))
metaJson["delivered_amount"] = metaJson["delivered_amount"] =
toBoostJson(amt->getJson(ripple::JsonOptions::include_date)); toBoostJson(amt->getJson(ripple::JsonOptions::include_date));
else else

View File

@@ -62,7 +62,8 @@ bool
insertDeliveredAmount( insertDeliveredAmount(
boost::json::object& metaJson, boost::json::object& metaJson,
std::shared_ptr<ripple::STTx const> const& txn, std::shared_ptr<ripple::STTx const> const& txn,
std::shared_ptr<ripple::TxMeta const> const& meta); std::shared_ptr<ripple::TxMeta const> const& meta,
uint32_t date);
boost::json::object boost::json::object
toJson(ripple::STBase const& obj); toJson(ripple::STBase const& obj);

View File

@@ -257,7 +257,8 @@ SubscriptionManager::pubTransaction(
boost::json::object pubObj; boost::json::object pubObj;
pubObj["transaction"] = RPC::toJson(*tx); pubObj["transaction"] = RPC::toJson(*tx);
pubObj["meta"] = RPC::toJson(*meta); pubObj["meta"] = RPC::toJson(*meta);
RPC::insertDeliveredAmount(pubObj["meta"].as_object(), tx, meta); RPC::insertDeliveredAmount(
pubObj["meta"].as_object(), tx, meta, blobs.date);
pubObj["type"] = "transaction"; pubObj["type"] = "transaction";
pubObj["validated"] = true; pubObj["validated"] = true;
pubObj["status"] = "closed"; pubObj["status"] = "closed";