mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25:51 +00:00
Fix account_lines, account_offers and book_offers result (RIPD-682):
The RPC account_lines and account_offers commands respond with the correct ledger info. account_offers, account_lines and book_offers allow admins unlimited size on the limit param. Specifying a negative value on limit clamps to the minimum value allowed. Incorrect types for limit are correctly reported in the result.
This commit is contained in:
@@ -243,13 +243,9 @@ public:
|
||||
// Book functions
|
||||
//
|
||||
|
||||
void getBookPage (Ledger::pointer lpLedger,
|
||||
Book const&,
|
||||
Account const& uTakerID,
|
||||
const bool bProof,
|
||||
const unsigned int iLimit,
|
||||
Json::Value const& jvMarker,
|
||||
Json::Value& jvResult);
|
||||
void getBookPage (bool bAdmin, Ledger::pointer lpLedger, Book const&,
|
||||
Account const& uTakerID, const bool bProof, const unsigned int iLimit,
|
||||
Json::Value const& jvMarker, Json::Value& jvResult);
|
||||
|
||||
// ledger proposal/close functions
|
||||
void processTrustedProposal (
|
||||
@@ -3082,6 +3078,7 @@ InfoSub::pointer NetworkOPsImp::addRpcSub (
|
||||
//
|
||||
// FIXME : support iLimit.
|
||||
void NetworkOPsImp::getBookPage (
|
||||
bool bAdmin,
|
||||
Ledger::pointer lpLedger,
|
||||
Book const& book,
|
||||
Account const& uTakerID,
|
||||
@@ -3119,14 +3116,13 @@ void NetworkOPsImp::getBookPage (
|
||||
unsigned int uBookEntry;
|
||||
STAmount saDirRate;
|
||||
|
||||
unsigned int iLeft = iLimit;
|
||||
|
||||
if (iLeft == 0 || iLeft > 300)
|
||||
iLeft = 300;
|
||||
|
||||
auto uTransferRate = rippleTransferRate (lesActive, book.out.account);
|
||||
|
||||
while (! bDone && iLeft-- > 0)
|
||||
unsigned int left (iLimit == 0 ? 300 : iLimit);
|
||||
if (! bAdmin && left > 300)
|
||||
left = 300;
|
||||
|
||||
while (!bDone && left-- > 0)
|
||||
{
|
||||
if (bDirectAdvance)
|
||||
{
|
||||
@@ -3300,6 +3296,7 @@ void NetworkOPsImp::getBookPage (
|
||||
|
||||
// FIXME : support iLimit.
|
||||
void NetworkOPsImp::getBookPage (
|
||||
bool bAdmin,
|
||||
Ledger::pointer lpLedger,
|
||||
Book const& book,
|
||||
Account const& uTakerID,
|
||||
@@ -3315,18 +3312,16 @@ void NetworkOPsImp::getBookPage (
|
||||
LedgerEntrySet lesActive (lpLedger, tapNONE, true);
|
||||
OrderBookIterator obIterator (lesActive, book);
|
||||
|
||||
unsigned int iLeft = iLimit;
|
||||
|
||||
if (iLeft == 0 || iLeft > 300)
|
||||
iLeft = 300;
|
||||
|
||||
auto uTransferRate = rippleTransferRate (lesActive, book.out.account);
|
||||
|
||||
const bool bGlobalFreeze = lesActive.isGlobalFrozen (book.out.account) ||
|
||||
lesActive.isGlobalFrozen (book.in.account);
|
||||
|
||||
unsigned int left (iLimit == 0 ? 300 : iLimit);
|
||||
if (! bAdmin && left > 300)
|
||||
left = 300;
|
||||
|
||||
while (iLeft-- > 0 && obIterator.nextOffer ())
|
||||
while (left-- > 0 && obIterator.nextOffer ())
|
||||
{
|
||||
|
||||
SLE::pointer sleOffer = obIterator.getCurrentOffer();
|
||||
|
||||
@@ -187,6 +187,7 @@ public:
|
||||
//
|
||||
|
||||
virtual void getBookPage (
|
||||
bool bAdmin,
|
||||
Ledger::pointer lpLedger,
|
||||
Book const& book,
|
||||
Account const& uTakerID,
|
||||
|
||||
@@ -74,27 +74,29 @@ void addLine (Json::Value& jsonLines, RippleState const& line)
|
||||
// }
|
||||
Json::Value doAccountLines (RPC::Context& context)
|
||||
{
|
||||
auto& params = context.params_;
|
||||
auto const& params (context.params_);
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error ("account");
|
||||
|
||||
Ledger::pointer ledger;
|
||||
Json::Value result (RPC::lookupLedger (params, ledger, context.netOps_));
|
||||
|
||||
if (! ledger)
|
||||
return result;
|
||||
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error ("account");
|
||||
|
||||
std::string strIdent (params[jss::account].asString ());
|
||||
bool bIndex (params.isMember (jss::account_index));
|
||||
int iIndex (bIndex ? params[jss::account_index].asUInt () : 0);
|
||||
RippleAddress rippleAddress;
|
||||
|
||||
result = RPC::accountFromString (
|
||||
ledger, rippleAddress, bIndex, strIdent, iIndex, false, context.netOps_);
|
||||
Json::Value const jv (RPC::accountFromString (ledger, rippleAddress, bIndex,
|
||||
strIdent, iIndex, false, context.netOps_));
|
||||
if (! jv.empty ())
|
||||
{
|
||||
for (Json::Value::const_iterator it (jv.begin ()); it != jv.end (); ++it)
|
||||
result[it.memberName ()] = it.key ();
|
||||
|
||||
if (! result.empty ())
|
||||
return result;
|
||||
}
|
||||
|
||||
if (! ledger->hasAccount (rippleAddress))
|
||||
return rpcError (rpcACT_NOT_FOUND);
|
||||
@@ -113,8 +115,8 @@ Json::Value doAccountLines (RPC::Context& context)
|
||||
if (bPeerIndex)
|
||||
result[jss::peer_index] = iPeerIndex;
|
||||
|
||||
result = RPC::accountFromString (ledger, rippleAddressPeer, bPeerIndex, strPeer,
|
||||
iPeerIndex, false, context.netOps_);
|
||||
result = RPC::accountFromString (ledger, rippleAddressPeer, bPeerIndex,
|
||||
strPeer, iPeerIndex, false, context.netOps_);
|
||||
|
||||
if (! result.empty ())
|
||||
return result;
|
||||
@@ -127,9 +129,18 @@ Json::Value doAccountLines (RPC::Context& context)
|
||||
unsigned int limit;
|
||||
if (params.isMember (jss::limit))
|
||||
{
|
||||
limit = std::max (RPC::Tuning::minLinesPerRequest,
|
||||
std::min (params[jss::limit].asUInt (),
|
||||
RPC::Tuning::maxLinesPerRequest));
|
||||
auto const& jvLimit (params[jss::limit]);
|
||||
if (! jvLimit.isIntegral ())
|
||||
return RPC::expected_field_error ("limit", "unsigned integer");
|
||||
|
||||
limit = jvLimit.isUInt () ? jvLimit.asUInt () :
|
||||
std::max (0, jvLimit.asInt ());
|
||||
|
||||
if (context.role_ != Config::ADMIN)
|
||||
{
|
||||
limit = std::max (RPC::Tuning::minLinesPerRequest,
|
||||
std::min (limit, RPC::Tuning::maxLinesPerRequest));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -150,7 +161,7 @@ Json::Value doAccountLines (RPC::Context& context)
|
||||
Json::Value const& marker (params[jss::marker]);
|
||||
|
||||
if (! marker.isString ())
|
||||
return rpcError (rpcACT_MALFORMED);
|
||||
return RPC::expected_field_error ("marker", "string");
|
||||
|
||||
startAfter.SetHex (marker.asString ());
|
||||
SLE::pointer sleLine (ledger->getSLEi (startAfter));
|
||||
|
||||
@@ -32,27 +32,28 @@ namespace ripple {
|
||||
Json::Value doAccountOffers (RPC::Context& context)
|
||||
{
|
||||
auto const& params (context.params_);
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error ("account");
|
||||
|
||||
Ledger::pointer ledger;
|
||||
Json::Value result (RPC::lookupLedger (params, ledger, context.netOps_));
|
||||
|
||||
if (! ledger)
|
||||
return result;
|
||||
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error ("account");
|
||||
|
||||
std::string strIdent (params[jss::account].asString ());
|
||||
bool bIndex (params.isMember (jss::account_index));
|
||||
int const iIndex (bIndex ? params[jss::account_index].asUInt () : 0);
|
||||
|
||||
RippleAddress rippleAddress;
|
||||
|
||||
result = RPC::accountFromString (ledger, rippleAddress, bIndex, strIdent,
|
||||
iIndex, false, context.netOps_);
|
||||
Json::Value const jv (RPC::accountFromString (ledger, rippleAddress, bIndex,
|
||||
strIdent, iIndex, false, context.netOps_));
|
||||
if (! jv.empty ())
|
||||
{
|
||||
for (Json::Value::const_iterator it (jv.begin ()); it != jv.end (); ++it)
|
||||
result[it.memberName ()] = it.key ();
|
||||
|
||||
if (! result.empty ())
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get info on account.
|
||||
result[jss::account] = rippleAddress.humanAccountID ();
|
||||
@@ -66,9 +67,18 @@ Json::Value doAccountOffers (RPC::Context& context)
|
||||
unsigned int limit;
|
||||
if (params.isMember (jss::limit))
|
||||
{
|
||||
limit = std::max (RPC::Tuning::minOffersPerRequest,
|
||||
std::min (params[jss::limit].asUInt (),
|
||||
RPC::Tuning::maxOffersPerRequest));
|
||||
auto const& jvLimit (params[jss::limit]);
|
||||
if (! jvLimit.isIntegral ())
|
||||
return RPC::expected_field_error ("limit", "unsigned integer");
|
||||
|
||||
limit = jvLimit.isUInt () ? jvLimit.asUInt () :
|
||||
std::max (0, jvLimit.asInt ());
|
||||
|
||||
if (context.role_ != Config::ADMIN)
|
||||
{
|
||||
limit = std::max (RPC::Tuning::minOffersPerRequest,
|
||||
std::min (limit, RPC::Tuning::maxOffersPerRequest));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -89,7 +99,7 @@ Json::Value doAccountOffers (RPC::Context& context)
|
||||
Json::Value const& marker (params[jss::marker]);
|
||||
|
||||
if (! marker.isString ())
|
||||
return rpcError (rpcACT_MALFORMED);
|
||||
return RPC::expected_field_error ("marker", "string");
|
||||
|
||||
startAfter.SetHex (marker.asString ());
|
||||
SLE::pointer sleOffer (ledger->getSLEi (startAfter));
|
||||
|
||||
@@ -162,15 +162,21 @@ Json::Value doBookOffers (RPC::Context& context)
|
||||
return RPC::make_error (rpcBAD_MARKET);
|
||||
}
|
||||
|
||||
if (context.params_.isMember ("limit") &&
|
||||
!context.params_ ["limit"].isIntegral())
|
||||
unsigned int iLimit;
|
||||
if (context.params_.isMember (jss::limit))
|
||||
{
|
||||
return RPC::expected_field_error ("limit", "integer");
|
||||
}
|
||||
auto const& jvLimit (context.params_[jss::limit]);
|
||||
|
||||
unsigned int const iLimit (context.params_.isMember ("limit")
|
||||
? context.params_ ["limit"].asUInt ()
|
||||
: 0);
|
||||
if (! jvLimit.isIntegral ())
|
||||
return RPC::expected_field_error ("limit", "unsigned integer");
|
||||
|
||||
iLimit = jvLimit.isUInt () ? jvLimit.asUInt () :
|
||||
std::max (0, jvLimit.asInt ());
|
||||
}
|
||||
else
|
||||
{
|
||||
iLimit = 0;
|
||||
}
|
||||
|
||||
bool const bProof (context.params_.isMember ("proof"));
|
||||
|
||||
@@ -179,6 +185,7 @@ Json::Value doBookOffers (RPC::Context& context)
|
||||
: Json::Value (Json::nullValue));
|
||||
|
||||
context.netOps_.getBookPage (
|
||||
context.role_ == Config::ADMIN,
|
||||
lpLedger,
|
||||
{{pay_currency, pay_issuer}, {get_currency, get_issuer}},
|
||||
raTakerID.getAccountID (), bProof, iLimit, jvMarker, jvResult);
|
||||
|
||||
@@ -309,6 +309,7 @@ Json::Value doSubscribe (RPC::Context& context)
|
||||
Json::Value jvAsks (Json::objectValue);
|
||||
|
||||
context.netOps_.getBookPage (
|
||||
context.role_ == Config::ADMIN,
|
||||
lpLedger, book, raTakerID.getAccountID (), false, 0,
|
||||
jvMarker, jvBids);
|
||||
|
||||
@@ -316,6 +317,7 @@ Json::Value doSubscribe (RPC::Context& context)
|
||||
jvResult[jss::bids] = jvBids[jss::offers];
|
||||
|
||||
context.netOps_.getBookPage (
|
||||
context.role_ == Config::ADMIN,
|
||||
lpLedger, book, raTakerID.getAccountID (),
|
||||
false, 0, jvMarker, jvAsks);
|
||||
|
||||
@@ -325,6 +327,7 @@ Json::Value doSubscribe (RPC::Context& context)
|
||||
else
|
||||
{
|
||||
context.netOps_.getBookPage (
|
||||
context.role_ == Config::ADMIN,
|
||||
lpLedger, book, raTakerID.getAccountID (), false, 0,
|
||||
jvMarker, jvResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user