mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add support for transfer fees to RPC book_offers.
This commit is contained in:
@@ -1066,6 +1066,8 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
|
|||||||
return saBalance;
|
return saBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the amount an account can spend without going into debt.
|
||||||
|
//
|
||||||
// <-- saAmount: amount of uCurrencyID held by uAccountID. May be negative.
|
// <-- saAmount: amount of uCurrencyID held by uAccountID. May be negative.
|
||||||
STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID)
|
STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1784,16 +1784,9 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
|
|||||||
STAmount saDirRate;
|
STAmount saDirRate;
|
||||||
|
|
||||||
// unsigned int iLeft = iLimit;
|
// unsigned int iLeft = iLimit;
|
||||||
SLE::pointer sleGetsIssuer = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uTakerGetsIssuerID));
|
|
||||||
|
|
||||||
if (!sleGetsIssuer)
|
uint32 uTransferRate = lesActive.rippleTransferRate(uTakerGetsIssuerID);
|
||||||
{
|
|
||||||
// Order book can not exist if TakerGetsIssuer account does not exist.
|
|
||||||
|
|
||||||
nothing();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (!bDone) {
|
while (!bDone) {
|
||||||
if (bDirectAdvance) {
|
if (bDirectAdvance) {
|
||||||
bDirectAdvance = false;
|
bDirectAdvance = false;
|
||||||
@@ -1850,15 +1843,35 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
|
|||||||
saOwnerFunds = lesActive.accountHolds(uOfferOwnerID, uTakerGetsCurrencyID, uTakerGetsIssuerID);
|
saOwnerFunds = lesActive.accountHolds(uOfferOwnerID, uTakerGetsCurrencyID, uTakerGetsIssuerID);
|
||||||
// cLog(lsINFO) << boost::str(boost::format("getBookPage: saOwnerFunds=%s (new)") % saOwnerFunds.getFullText());
|
// cLog(lsINFO) << boost::str(boost::format("getBookPage: saOwnerFunds=%s (new)") % saOwnerFunds.getFullText());
|
||||||
if (saOwnerFunds.isNegative())
|
if (saOwnerFunds.isNegative())
|
||||||
|
{
|
||||||
|
// Treat negative funds as zero.
|
||||||
|
|
||||||
saOwnerFunds.zero();
|
saOwnerFunds.zero();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value jvOffer = sleOffer->getJson(0);
|
Json::Value jvOffer = sleOffer->getJson(0);
|
||||||
|
|
||||||
STAmount saTakerGetsFunded;
|
STAmount saTakerGetsFunded;
|
||||||
|
STAmount saOwnerFundsLimit;
|
||||||
|
uint32 uOfferRate;
|
||||||
|
|
||||||
if (saOwnerFunds >= saTakerGets)
|
|
||||||
|
if (uTransferRate != QUALITY_ONE // Have a tranfer fee.
|
||||||
|
&& uTakerID != uTakerGetsIssuerID // Not taking offers of own IOUs.
|
||||||
|
&& uTakerGetsIssuerID != uOfferOwnerID) { // Offer owner not issuing ownfunds
|
||||||
|
// Need to charge a transfer fee to offer owner.
|
||||||
|
uOfferRate = uTransferRate;
|
||||||
|
saOwnerFundsLimit = STAmount::divide(saOwnerFunds, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uOfferRate = QUALITY_ONE;
|
||||||
|
saOwnerFundsLimit = saOwnerFunds;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saOwnerFundsLimit >= saTakerGets)
|
||||||
{
|
{
|
||||||
// Sufficient funds no shenanigans.
|
// Sufficient funds no shenanigans.
|
||||||
saTakerGetsFunded = saTakerGets;
|
saTakerGetsFunded = saTakerGets;
|
||||||
@@ -1873,15 +1886,19 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
|
|||||||
// cLog(lsINFO) << boost::str(boost::format("getBookPage: multiply=%s") % STAmount::multiply(saTakerGetsFunded, saDirRate, saTakerPays).getFullText());
|
// cLog(lsINFO) << boost::str(boost::format("getBookPage: multiply=%s") % STAmount::multiply(saTakerGetsFunded, saDirRate, saTakerPays).getFullText());
|
||||||
STAmount saTakerPaysFunded;
|
STAmount saTakerPaysFunded;
|
||||||
|
|
||||||
saTakerGetsFunded = saOwnerFunds;
|
saTakerGetsFunded = saOwnerFundsLimit;
|
||||||
saTakerPaysFunded = std::min(saTakerPays, STAmount::multiply(saTakerGetsFunded, saDirRate, saTakerPays));
|
saTakerPaysFunded = std::min(saTakerPays, STAmount::multiply(saTakerGetsFunded, saDirRate, saTakerPays));
|
||||||
|
|
||||||
// Only provide, if not fully funded.
|
// Only provide, if not fully funded.
|
||||||
jvOffer["taker_gets_funded"] = saTakerGetsFunded.getJson(0);
|
jvOffer["taker_gets_funded"] = saTakerGetsFunded.getJson(0);
|
||||||
jvOffer["taker_pays_funded"] = saTakerPaysFunded.getJson(0);
|
jvOffer["taker_pays_funded"] = saTakerPaysFunded.getJson(0);
|
||||||
}
|
|
||||||
|
|
||||||
STAmount saOwnerBalance = saOwnerFunds-saTakerGetsFunded;
|
}
|
||||||
|
STAmount saOwnerPays = QUALITY_ONE == uOfferRate
|
||||||
|
? saTakerGetsFunded
|
||||||
|
: std::min(saOwnerFunds, STAmount::multiply(saTakerGetsFunded, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9)));
|
||||||
|
|
||||||
|
STAmount saOwnerBalance = saOwnerFunds-saOwnerPays;
|
||||||
|
|
||||||
umBalance[uOfferOwnerID] = saOwnerBalance;
|
umBalance[uOfferOwnerID] = saOwnerBalance;
|
||||||
|
|
||||||
@@ -1901,7 +1918,6 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
jvResult["offers"] = jvOffers;
|
jvResult["offers"] = jvOffers;
|
||||||
// jvResult["marker"] = Json::Value(Json::arrayValue);
|
// jvResult["marker"] = Json::Value(Json::arrayValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user