Skip to content

Commit

Permalink
Don't read Amount field if it is not present (RIPD-1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr authored and seelabs committed Jun 1, 2018
1 parent 57ab0a0 commit 34d3f93
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/ripple/rpc/impl/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,28 +441,31 @@ addPaymentDeliveredAmount(Json::Value& meta, RPC::Context& context,
return;
}

// Ledger 4594095 is the first ledger in which the DeliveredAmount field
// was present when a partial payment was made and its absence indicates
// that the amount delivered is listed in the Amount field.
if (transaction->getLedger () >= 4594095)
if (serializedTx->isFieldPresent (sfAmount))
{
meta[jss::delivered_amount] =
serializedTx->getFieldAmount (sfAmount).getJson (1);
return;
}
// Ledger 4594095 is the first ledger in which the DeliveredAmount field
// was present when a partial payment was made and its absence indicates
// that the amount delivered is listed in the Amount field.
if (transaction->getLedger () >= 4594095)
{
meta[jss::delivered_amount] =
serializedTx->getFieldAmount (sfAmount).getJson (1);
return;
}

// If the ledger closed long after the DeliveredAmount code was deployed
// then its absence indicates that the amount delivered is listed in the
// Amount field. DeliveredAmount went live January 24, 2014.
using namespace std::chrono_literals;
auto const ct =
context.ledgerMaster.getCloseTimeBySeq (transaction->getLedger ());
if (ct && (*ct > NetClock::time_point{446000000s}))
{
// 446000000 is in Feb 2014, well after DeliveredAmount went live
meta[jss::delivered_amount] =
serializedTx->getFieldAmount (sfAmount).getJson (1);
return;
// If the ledger closed long after the DeliveredAmount code was deployed
// then its absence indicates that the amount delivered is listed in the
// Amount field. DeliveredAmount went live January 24, 2014.
using namespace std::chrono_literals;
auto const ct =
context.ledgerMaster.getCloseTimeBySeq (transaction->getLedger ());
if (ct && (*ct > NetClock::time_point{446000000s}))
{
// 446000000 is in Feb 2014, well after DeliveredAmount went live
meta[jss::delivered_amount] =
serializedTx->getFieldAmount (sfAmount).getJson (1);
return;
}
}

// Otherwise we report "unavailable" which cannot be parsed into a
Expand Down

0 comments on commit 34d3f93

Please sign in to comment.