mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-18 18:15:50 +00:00
Refactor usage of boost::format
This commit is contained in:
committed by
Vinnie Falco
parent
2ed8edc19d
commit
5fddf374f4
@@ -330,9 +330,9 @@ AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID)
|
||||
|
||||
if (!sle)
|
||||
{
|
||||
WriteLog (lsDEBUG, Ledger) << boost::str (boost::format ("Ledger:getAccountState: not found: %s: %s")
|
||||
% accountID.humanAccountID ()
|
||||
% Ledger::getAccountRootIndex (accountID).GetHex ());
|
||||
WriteLog (lsDEBUG, Ledger) << "Ledger:getAccountState:" <<
|
||||
" not found: " << accountID.humanAccountID () <<
|
||||
": " << Ledger::getAccountRootIndex (accountID).GetHex ();
|
||||
|
||||
return AccountState::pointer ();
|
||||
}
|
||||
@@ -1677,12 +1677,12 @@ uint256 Ledger::getBookBase (const uint160& uTakerPaysCurrency, const uint160& u
|
||||
|
||||
uint256 uBaseIndex = getQualityIndex (s.getSHA512Half ()); // Return with quality 0.
|
||||
|
||||
WriteLog (lsTRACE, Ledger) << boost::str (boost::format ("getBookBase(%s,%s,%s,%s) = %s")
|
||||
% STAmount::createHumanCurrency (uTakerPaysCurrency)
|
||||
% RippleAddress::createHumanAccountID (uTakerPaysIssuerID)
|
||||
% STAmount::createHumanCurrency (uTakerGetsCurrency)
|
||||
% RippleAddress::createHumanAccountID (uTakerGetsIssuerID)
|
||||
% uBaseIndex.ToString ());
|
||||
WriteLog (lsTRACE, Ledger) << "getBookBase" <<
|
||||
"(" << STAmount::createHumanCurrency (uTakerPaysCurrency) <<
|
||||
"," << RippleAddress::createHumanAccountID (uTakerPaysIssuerID) <<
|
||||
"," << STAmount::createHumanCurrency (uTakerGetsCurrency) <<
|
||||
"," << RippleAddress::createHumanAccountID (uTakerGetsIssuerID) <<
|
||||
") = " << uBaseIndex.ToString ();
|
||||
|
||||
assert (isValidBook (uTakerPaysCurrency, uTakerPaysIssuerID, uTakerGetsCurrency, uTakerGetsIssuerID));
|
||||
|
||||
|
||||
@@ -658,9 +658,9 @@ TER LedgerEntrySet::dirAdd (
|
||||
uint256 const& uLedgerIndex,
|
||||
std::function<void (SLE::ref, bool)> fDescriber)
|
||||
{
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("dirAdd: uRootIndex=%s uLedgerIndex=%s")
|
||||
% uRootIndex.ToString ()
|
||||
% uLedgerIndex.ToString ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd:" <<
|
||||
" uRootIndex=" << uRootIndex.ToString () <<
|
||||
" uLedgerIndex=" << uLedgerIndex.ToString ();
|
||||
|
||||
SLE::pointer sleNode;
|
||||
STVector256 svIndexes;
|
||||
@@ -731,9 +731,12 @@ TER LedgerEntrySet::dirAdd (
|
||||
svIndexes.peekValue ().push_back (uLedgerIndex); // Append entry.
|
||||
sleNode->setFieldV256 (sfIndexes, svIndexes); // Save entry.
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: creating: root: " << uRootIndex.ToString ();
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: appending: Entry: " << uLedgerIndex.ToString ();
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: appending: Node: " << strHex (uNodeDir);
|
||||
WriteLog (lsTRACE, LedgerEntrySet) <<
|
||||
"dirAdd: creating: root: " << uRootIndex.ToString ();
|
||||
WriteLog (lsTRACE, LedgerEntrySet) <<
|
||||
"dirAdd: appending: Entry: " << uLedgerIndex.ToString ();
|
||||
WriteLog (lsTRACE, LedgerEntrySet) <<
|
||||
"dirAdd: appending: Node: " << strHex (uNodeDir);
|
||||
// WriteLog (lsINFO, LedgerEntrySet) << "dirAdd: appending: PREV: " << svIndexes.peekValue()[0].ToString();
|
||||
|
||||
return tesSUCCESS;
|
||||
@@ -753,11 +756,10 @@ TER LedgerEntrySet::dirDelete (
|
||||
|
||||
if (!sleNode)
|
||||
{
|
||||
WriteLog (lsWARNING, LedgerEntrySet)
|
||||
<< boost::str (boost::format ("dirDelete: no such node: uRootIndex=%s uNodeDir=%s uLedgerIndex=%s")
|
||||
% uRootIndex.ToString ()
|
||||
% strHex (uNodeDir)
|
||||
% uLedgerIndex.ToString ());
|
||||
WriteLog (lsWARNING, LedgerEntrySet) << "dirDelete: no such node:" <<
|
||||
" uRootIndex=" << uRootIndex.ToString () <<
|
||||
" uNodeDir=" << strHex (uNodeDir) <<
|
||||
" uLedgerIndex=" << uLedgerIndex.ToString ();
|
||||
|
||||
if (!bSoft)
|
||||
{
|
||||
@@ -1003,7 +1005,10 @@ bool LedgerEntrySet::dirNext (
|
||||
}
|
||||
|
||||
uEntryIndex = vuiIndexes[uDirEntry++];
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("dirNext: uDirEntry=%d uEntryIndex=%s") % uDirEntry % uEntryIndex);
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "dirNext:" <<
|
||||
" uDirEntry=" << uDirEntry <<
|
||||
" uEntryIndex=" << uEntryIndex;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1118,13 +1123,11 @@ STAmount LedgerEntrySet::rippleOwed (const uint160& uToAccountID, const uint160&
|
||||
{
|
||||
saBalance.clear (uCurrencyID, uToAccountID);
|
||||
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleOwed: No credit line between "
|
||||
<< RippleAddress::createHumanAccountID (uFromAccountID)
|
||||
<< " and "
|
||||
<< RippleAddress::createHumanAccountID (uToAccountID)
|
||||
<< " for "
|
||||
<< STAmount::createHumanCurrency (uCurrencyID)
|
||||
<< "." ;
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleOwed:" <<
|
||||
" No credit line between " <<
|
||||
RippleAddress::createHumanAccountID (uFromAccountID) <<
|
||||
" and " << RippleAddress::createHumanAccountID (uToAccountID) <<
|
||||
" for " << STAmount::createHumanCurrency (uCurrencyID);
|
||||
#if 0
|
||||
// We could cut off coming here if we test for no line sooner.
|
||||
|
||||
@@ -1162,16 +1165,18 @@ STAmount LedgerEntrySet::rippleLimit (const uint160& uToAccountID, const uint160
|
||||
|
||||
std::uint32_t LedgerEntrySet::rippleTransferRate (const uint160& uIssuerID)
|
||||
{
|
||||
SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uIssuerID));
|
||||
SLE::pointer sleAccount (entryCache (
|
||||
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uIssuerID)));
|
||||
|
||||
std::uint32_t uQuality = sleAccount && sleAccount->isFieldPresent (sfTransferRate)
|
||||
? sleAccount->getFieldU32 (sfTransferRate)
|
||||
: QUALITY_ONE;
|
||||
std::uint32_t uQuality =
|
||||
sleAccount && sleAccount->isFieldPresent (sfTransferRate)
|
||||
? sleAccount->getFieldU32 (sfTransferRate)
|
||||
: QUALITY_ONE;
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("rippleTransferRate: uIssuerID=%s account_exists=%d transfer_rate=%f")
|
||||
% RippleAddress::createHumanAccountID (uIssuerID)
|
||||
% !!sleAccount
|
||||
% (uQuality / 1000000000.0));
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "rippleTransferRate:" <<
|
||||
" uIssuerID=" << RippleAddress::createHumanAccountID (uIssuerID) <<
|
||||
" account_exists=" << std::boolalpha << !!sleAccount <<
|
||||
" transfer_rate=" << (uQuality / 1000000000.0);
|
||||
|
||||
return uQuality;
|
||||
}
|
||||
@@ -1181,6 +1186,8 @@ LedgerEntrySet::rippleTransferRate (const uint160& uSenderID,
|
||||
const uint160& uReceiverID,
|
||||
const uint160& uIssuerID)
|
||||
{
|
||||
// If calculating the transfer rate from or to the issuer of the currency
|
||||
// no fees are assessed.
|
||||
return uSenderID == uIssuerID || uReceiverID == uIssuerID
|
||||
? QUALITY_ONE
|
||||
: rippleTransferRate (uIssuerID);
|
||||
@@ -1202,7 +1209,8 @@ LedgerEntrySet::rippleQualityIn (const uint160& uToAccountID,
|
||||
}
|
||||
else
|
||||
{
|
||||
sleRippleState = entryCache (ltRIPPLE_STATE, Ledger::getRippleStateIndex (uToAccountID, uFromAccountID, uCurrencyID));
|
||||
sleRippleState = entryCache (ltRIPPLE_STATE,
|
||||
Ledger::getRippleStateIndex (uToAccountID, uFromAccountID, uCurrencyID));
|
||||
|
||||
if (sleRippleState)
|
||||
{
|
||||
@@ -1222,13 +1230,13 @@ LedgerEntrySet::rippleQualityIn (const uint160& uToAccountID,
|
||||
}
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("rippleQuality: %s uToAccountID=%s uFromAccountID=%s uCurrencyID=%s bLine=%d uQuality=%f")
|
||||
% (sfLow == sfLowQualityIn ? "in" : "out")
|
||||
% RippleAddress::createHumanAccountID (uToAccountID)
|
||||
% RippleAddress::createHumanAccountID (uFromAccountID)
|
||||
% STAmount::createHumanCurrency (uCurrencyID)
|
||||
% !!sleRippleState
|
||||
% (uQuality / 1000000000.0));
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "rippleQuality: " <<
|
||||
(sfLow == sfLowQualityIn ? "in" : "out") <<
|
||||
" uToAccountID=" << RippleAddress::createHumanAccountID (uToAccountID) <<
|
||||
" uFromAccountID=" << RippleAddress::createHumanAccountID (uFromAccountID) <<
|
||||
" uCurrencyID=" << STAmount::createHumanCurrency (uCurrencyID) <<
|
||||
" bLine=" << std::boolalpha << !!sleRippleState <<
|
||||
" uQuality=" << (uQuality / 1000000000.0);
|
||||
|
||||
// assert(uToAccountID == uFromAccountID || !!sleRippleState);
|
||||
|
||||
@@ -1239,8 +1247,9 @@ LedgerEntrySet::rippleQualityIn (const uint160& uToAccountID,
|
||||
// <-- IOU's uAccountID has of uIssuerID.
|
||||
STAmount LedgerEntrySet::rippleHolds (const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID)
|
||||
{
|
||||
STAmount saBalance;
|
||||
SLE::pointer sleRippleState = entryCache (ltRIPPLE_STATE, Ledger::getRippleStateIndex (uAccountID, uIssuerID, uCurrencyID));
|
||||
STAmount saBalance;
|
||||
SLE::pointer sleRippleState = entryCache (ltRIPPLE_STATE,
|
||||
Ledger::getRippleStateIndex (uAccountID, uIssuerID, uCurrencyID));
|
||||
|
||||
if (!sleRippleState)
|
||||
{
|
||||
@@ -1272,10 +1281,11 @@ STAmount LedgerEntrySet::accountHolds (const uint160& uAccountID, const uint160&
|
||||
|
||||
if (!uCurrencyID)
|
||||
{
|
||||
SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uAccountID));
|
||||
std::uint64_t uReserve = mLedger->getReserve (sleAccount->getFieldU32 (sfOwnerCount));
|
||||
SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT,
|
||||
Ledger::getAccountRootIndex (uAccountID));
|
||||
std::uint64_t uReserve = mLedger->getReserve (sleAccount->getFieldU32 (sfOwnerCount));
|
||||
|
||||
STAmount saBalance = sleAccount->getFieldAmount (sfBalance);
|
||||
STAmount saBalance = sleAccount->getFieldAmount (sfBalance);
|
||||
|
||||
if (saBalance < uReserve)
|
||||
{
|
||||
@@ -1283,22 +1293,22 @@ STAmount LedgerEntrySet::accountHolds (const uint160& uAccountID, const uint160&
|
||||
}
|
||||
else
|
||||
{
|
||||
saAmount = saBalance - uReserve;
|
||||
saAmount = saBalance - uReserve;
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountHolds: uAccountID=%s saAmount=%s saBalance=%s uReserve=%d")
|
||||
% RippleAddress::createHumanAccountID (uAccountID)
|
||||
% saAmount.getFullText ()
|
||||
% saBalance.getFullText ()
|
||||
% uReserve);
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountHolds:" <<
|
||||
" uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
|
||||
" saAmount=" << saAmount.getFullText () <<
|
||||
" saBalance=" << saBalance.getFullText () <<
|
||||
" uReserve=" << uReserve;
|
||||
}
|
||||
else
|
||||
{
|
||||
saAmount = rippleHolds (uAccountID, uCurrencyID, uIssuerID);
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountHolds: uAccountID=%s saAmount=%s")
|
||||
% RippleAddress::createHumanAccountID (uAccountID)
|
||||
% saAmount.getFullText ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountHolds:" <<
|
||||
" uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
|
||||
" saAmount=" << saAmount.getFullText ();
|
||||
}
|
||||
|
||||
return saAmount;
|
||||
@@ -1318,39 +1328,49 @@ STAmount LedgerEntrySet::accountFunds (const uint160& uAccountID, const STAmount
|
||||
{
|
||||
saFunds = saDefault;
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountFunds: uAccountID=%s saDefault=%s SELF-FUNDED")
|
||||
% RippleAddress::createHumanAccountID (uAccountID)
|
||||
% saDefault.getFullText ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountFunds:" <<
|
||||
" uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
|
||||
" saDefault=" << saDefault.getFullText () <<
|
||||
" SELF-FUNDED";
|
||||
}
|
||||
else
|
||||
{
|
||||
saFunds = accountHolds (uAccountID, saDefault.getCurrency (), saDefault.getIssuer ());
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountFunds: uAccountID=%s saDefault=%s saFunds=%s")
|
||||
% RippleAddress::createHumanAccountID (uAccountID)
|
||||
% saDefault.getFullText ()
|
||||
% saFunds.getFullText ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountFunds:" <<
|
||||
" uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
|
||||
" saDefault=" << saDefault.getFullText () <<
|
||||
" saFunds=" << saFunds.getFullText ();
|
||||
}
|
||||
|
||||
return saFunds;
|
||||
}
|
||||
|
||||
// Calculate transit fee.
|
||||
STAmount LedgerEntrySet::rippleTransferFee (const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount)
|
||||
STAmount LedgerEntrySet::rippleTransferFee (
|
||||
const uint160& uSenderID,
|
||||
const uint160& uReceiverID,
|
||||
const uint160& uIssuerID,
|
||||
const STAmount& saAmount)
|
||||
{
|
||||
if (uSenderID != uIssuerID && uReceiverID != uIssuerID)
|
||||
{
|
||||
std::uint32_t uTransitRate = rippleTransferRate (uIssuerID);
|
||||
std::uint32_t uTransitRate = rippleTransferRate (uIssuerID);
|
||||
|
||||
if (QUALITY_ONE != uTransitRate)
|
||||
{
|
||||
STAmount saTransitRate (CURRENCY_ONE, ACCOUNT_ONE, static_cast<std::uint64_t> (uTransitRate), -9);
|
||||
// NIKB use STAmount::saFromRate
|
||||
STAmount saTransitRate (
|
||||
CURRENCY_ONE, ACCOUNT_ONE,
|
||||
static_cast<std::uint64_t> (uTransitRate), -9);
|
||||
|
||||
STAmount saTransferTotal = STAmount::multiply (saAmount, saTransitRate, saAmount.getCurrency (), saAmount.getIssuer ());
|
||||
STAmount saTransferFee = saTransferTotal - saAmount;
|
||||
STAmount saTransferTotal = STAmount::multiply (
|
||||
saAmount, saTransitRate,
|
||||
saAmount.getCurrency (), saAmount.getIssuer ());
|
||||
STAmount saTransferFee = saTransferTotal - saAmount;
|
||||
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << boost::str (boost::format ("rippleTransferFee: saTransferFee=%s")
|
||||
% saTransferFee.getFullText ());
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleTransferFee:" <<
|
||||
" saTransferFee=" << saTransferFee.getFullText ();
|
||||
|
||||
return saTransferFee;
|
||||
}
|
||||
@@ -1487,21 +1507,21 @@ TER LedgerEntrySet::rippleCredit (const uint160& uSenderID, const uint160& uRece
|
||||
|
||||
saBalance.setIssuer (ACCOUNT_ONE);
|
||||
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << boost::str (boost::format ("rippleCredit: create line: %s --> %s : %s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% RippleAddress::createHumanAccountID (uReceiverID)
|
||||
% saAmount.getFullText ());
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleCredit: "
|
||||
"create line: " << RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
|
||||
" : " << saAmount.getFullText ();
|
||||
|
||||
terResult = trustCreate (
|
||||
bSenderHigh,
|
||||
uSenderID,
|
||||
uReceiverID,
|
||||
uIndex,
|
||||
entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)),
|
||||
false,
|
||||
false,
|
||||
saBalance,
|
||||
saReceiverLimit);
|
||||
terResult = trustCreate (
|
||||
bSenderHigh,
|
||||
uSenderID,
|
||||
uReceiverID,
|
||||
uIndex,
|
||||
entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)),
|
||||
false,
|
||||
false,
|
||||
saBalance,
|
||||
saReceiverLimit);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1514,12 +1534,12 @@ TER LedgerEntrySet::rippleCredit (const uint160& uSenderID, const uint160& uRece
|
||||
|
||||
saBalance -= saAmount;
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("rippleCredit: %s --> %s : before=%s amount=%s after=%s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% RippleAddress::createHumanAccountID (uReceiverID)
|
||||
% saBefore.getFullText ()
|
||||
% saAmount.getFullText ()
|
||||
% saBalance.getFullText ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "rippleCredit: " <<
|
||||
RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
|
||||
" : before=" << saBefore.getFullText () <<
|
||||
" amount=" << saAmount.getFullText () <<
|
||||
" after=" << saBalance.getFullText ();
|
||||
|
||||
bool bDelete = false;
|
||||
std::uint32_t uFlags;
|
||||
@@ -1597,12 +1617,12 @@ TER LedgerEntrySet::rippleSend (const uint160& uSenderID, const uint160& uReceiv
|
||||
|
||||
saActual.setIssuer (uIssuerID); // XXX Make sure this done in + above.
|
||||
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << boost::str (boost::format ("rippleSend> %s -- > %s : deliver=%s fee=%s cost=%s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% RippleAddress::createHumanAccountID (uReceiverID)
|
||||
% saAmount.getFullText ()
|
||||
% saTransitFee.getFullText ()
|
||||
% saActual.getFullText ());
|
||||
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleSend> " <<
|
||||
RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" - > " << RippleAddress::createHumanAccountID (uReceiverID) <<
|
||||
" : deliver=" << saAmount.getFullText () <<
|
||||
" fee=" << saTransitFee.getFullText () <<
|
||||
" cost=" << saActual.getFullText ();
|
||||
|
||||
terResult = rippleCredit (uIssuerID, uReceiverID, saAmount);
|
||||
|
||||
@@ -1626,54 +1646,70 @@ TER LedgerEntrySet::accountSend (const uint160& uSenderID, const uint160& uRecei
|
||||
else if (saAmount.isNative ())
|
||||
{
|
||||
// XRP send which does not check reserve and can do pure adjustment.
|
||||
SLE::pointer sleSender = !!uSenderID
|
||||
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uSenderID))
|
||||
: SLE::pointer ();
|
||||
SLE::pointer sleReceiver = !!uReceiverID
|
||||
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID))
|
||||
: SLE::pointer ();
|
||||
SLE::pointer sleSender = !!uSenderID
|
||||
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uSenderID))
|
||||
: SLE::pointer ();
|
||||
SLE::pointer sleReceiver = !!uReceiverID
|
||||
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID))
|
||||
: SLE::pointer ();
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountSend> %s (%s) -> %s (%s) : %s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% (sleSender ? (sleSender->getFieldAmount (sfBalance)).getFullText () : "-")
|
||||
% RippleAddress::createHumanAccountID (uReceiverID)
|
||||
% (sleReceiver ? (sleReceiver->getFieldAmount (sfBalance)).getFullText () : "-")
|
||||
% saAmount.getFullText ());
|
||||
auto get_balance = [](SLE::pointer acct)
|
||||
{
|
||||
std::string ret ("-");
|
||||
|
||||
if (acct)
|
||||
ret = acct->getFieldAmount (sfBalance).getFullText ();
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountSend> " <<
|
||||
RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" (" << get_balance(sleSender) <<
|
||||
") -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
|
||||
" (" << get_balance(sleReceiver) <<
|
||||
") : " << saAmount.getFullText ();
|
||||
|
||||
if (sleSender)
|
||||
{
|
||||
if (sleSender->getFieldAmount (sfBalance) < saAmount)
|
||||
{
|
||||
terResult = is_bit_set (mParams, tapOPEN_LEDGER) ? telFAILED_PROCESSING : tecFAILED_PROCESSING;
|
||||
terResult = is_bit_set (mParams, tapOPEN_LEDGER)
|
||||
? telFAILED_PROCESSING
|
||||
: tecFAILED_PROCESSING;
|
||||
}
|
||||
else
|
||||
{
|
||||
sleSender->setFieldAmount (sfBalance, sleSender->getFieldAmount (sfBalance) - saAmount); // Decrement XRP balance.
|
||||
// Decrement XRP balance.
|
||||
sleSender->setFieldAmount (sfBalance,
|
||||
sleSender->getFieldAmount (sfBalance) - saAmount);
|
||||
entryModify (sleSender);
|
||||
}
|
||||
}
|
||||
|
||||
if (tesSUCCESS == terResult && sleReceiver)
|
||||
{
|
||||
sleReceiver->setFieldAmount (sfBalance, sleReceiver->getFieldAmount (sfBalance) + saAmount); // Increment XRP balance.
|
||||
// Increment XRP balance.
|
||||
sleReceiver->setFieldAmount (sfBalance,
|
||||
sleReceiver->getFieldAmount (sfBalance) + saAmount);
|
||||
entryModify (sleReceiver);
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountSend< %s (%s) -> %s (%s) : %s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% (sleSender ? (sleSender->getFieldAmount (sfBalance)).getFullText () : "-")
|
||||
% RippleAddress::createHumanAccountID (uReceiverID)
|
||||
% (sleReceiver ? (sleReceiver->getFieldAmount (sfBalance)).getFullText () : "-")
|
||||
% saAmount.getFullText ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountSend< " <<
|
||||
RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" (" << get_balance(sleSender) <<
|
||||
") -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
|
||||
" (" << get_balance(sleReceiver) <<
|
||||
") : " << saAmount.getFullText ();
|
||||
}
|
||||
else
|
||||
{
|
||||
STAmount saActual;
|
||||
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountSend: %s -> %s : %s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% RippleAddress::createHumanAccountID (uReceiverID)
|
||||
% saAmount.getFullText ());
|
||||
WriteLog (lsTRACE, LedgerEntrySet) << "accountSend: " <<
|
||||
RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
|
||||
" : " << saAmount.getFullText ();
|
||||
|
||||
|
||||
terResult = rippleSend (uSenderID, uReceiverID, saAmount, saActual);
|
||||
|
||||
@@ -44,9 +44,9 @@ bool ContinuousLedgerTiming::shouldClose (
|
||||
(currentMSeconds < -1000) || (currentMSeconds > 600000))
|
||||
{
|
||||
WriteLog (lsWARNING, LedgerTiming) <<
|
||||
boost::str (boost::format ("CLC::shouldClose range Trans=%s, Prop: %d/%d, Secs: %d (last:%d)")
|
||||
% (anyTransactions ? "yes" : "no") % previousProposers % proposersClosed
|
||||
% currentMSeconds % previousMSeconds);
|
||||
"CLC::shouldClose range Trans=" << (anyTransactions ? "yes" : "no") <<
|
||||
" Prop: " << previousProposers << "/" << proposersClosed <<
|
||||
" Secs: " << currentMSeconds << " (last: " << previousMSeconds << ")";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,9 @@ bool ContinuousLedgerTiming::shouldClose (
|
||||
// no transactions so far this interval
|
||||
if (proposersClosed > (previousProposers / 4)) // did we miss a transaction?
|
||||
{
|
||||
WriteLog (lsTRACE, LedgerTiming) << "no transactions, many proposers: now (" << proposersClosed << " closed, "
|
||||
<< previousProposers << " before)";
|
||||
WriteLog (lsTRACE, LedgerTiming) <<
|
||||
"no transactions, many proposers: now (" << proposersClosed <<
|
||||
" closed, " << previousProposers << " before)";
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -78,13 +79,15 @@ bool ContinuousLedgerTiming::shouldClose (
|
||||
|
||||
if ((openMSeconds < LEDGER_MIN_CLOSE) && ((proposersClosed + proposersValidated) < (previousProposers / 2 )))
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerTiming) << "Must wait minimum time before closing";
|
||||
WriteLog (lsDEBUG, LedgerTiming) <<
|
||||
"Must wait minimum time before closing";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((currentMSeconds < previousMSeconds) && ((proposersClosed + proposersValidated) < previousProposers))
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerTiming) << "We are waiting for more closes/validations";
|
||||
WriteLog (lsDEBUG, LedgerTiming) <<
|
||||
"We are waiting for more closes/validations";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,9 +106,12 @@ bool ContinuousLedgerTiming::haveConsensus (
|
||||
bool forReal, // deciding whether to stop consensus process
|
||||
bool& failed) // we can't reach a consensus
|
||||
{
|
||||
WriteLog (lsTRACE, LedgerTiming) << boost::str (boost::format ("CLC::haveConsensus: prop=%d/%d agree=%d validated=%d time=%d/%d%s") %
|
||||
currentProposers % previousProposers % currentAgree % currentFinished % currentAgreeTime % previousAgreeTime %
|
||||
(forReal ? "" : "X"));
|
||||
WriteLog (lsTRACE, LedgerTiming) <<
|
||||
"CLC::haveConsensus: prop=" << currentProposers <<
|
||||
"/" << previousProposers <<
|
||||
" agree=" << currentAgree << " validated=" << currentFinished <<
|
||||
" time=" << currentAgreeTime << "/" << previousAgreeTime <<
|
||||
(forReal ? "" : "X");
|
||||
|
||||
if (currentAgreeTime <= LEDGER_MIN_CONSENSUS)
|
||||
return false;
|
||||
@@ -115,7 +121,8 @@ bool ContinuousLedgerTiming::haveConsensus (
|
||||
// Less than 3/4 of the last ledger's proposers are present, we may need more time
|
||||
if (currentAgreeTime < (previousAgreeTime + LEDGER_MIN_CONSENSUS))
|
||||
{
|
||||
CondLog (forReal, lsTRACE, LedgerTiming) << "too fast, not enough proposers";
|
||||
CondLog (forReal, lsTRACE, LedgerTiming) <<
|
||||
"too fast, not enough proposers";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +138,8 @@ bool ContinuousLedgerTiming::haveConsensus (
|
||||
// If 80% of the nodes on your UNL have moved on, you should declare consensus
|
||||
if (((currentFinished * 100) / (currentProposers + 1)) > 80)
|
||||
{
|
||||
CondLog (forReal, lsWARNING, LedgerTiming) << "We see no consensus, but 80% of nodes have moved on";
|
||||
CondLog (forReal, lsWARNING, LedgerTiming) <<
|
||||
"We see no consensus, but 80% of nodes have moved on";
|
||||
failed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2568,11 +2568,14 @@ void NetworkOPsImp::pubAccountTransaction (Ledger::ref lpCurrent, const Accepted
|
||||
}
|
||||
}
|
||||
}
|
||||
m_journal.info << boost::str (boost::format ("pubAccountTransaction: iProposed=%d iAccepted=%d") % iProposed % iAccepted);
|
||||
m_journal.info << "pubAccountTransaction:" <<
|
||||
" iProposed=" << iProposed <<
|
||||
" iAccepted=" << iAccepted;
|
||||
|
||||
if (!notify.empty ())
|
||||
{
|
||||
Json::Value jvObj = transJson (*alTx.getTxn (), alTx.getResult (), bAccepted, lpCurrent);
|
||||
Json::Value jvObj = transJson (
|
||||
*alTx.getTxn (), alTx.getResult (), bAccepted, lpCurrent);
|
||||
|
||||
if (alTx.isApplied ())
|
||||
jvObj["meta"] = alTx.getMeta ()->getJson (0);
|
||||
@@ -2600,7 +2603,8 @@ void NetworkOPsImp::subAccount (InfoSub::ref isrListener,
|
||||
// For the connection, monitor each account.
|
||||
BOOST_FOREACH (const RippleAddress & naAccountID, vnaAccountIDs)
|
||||
{
|
||||
m_journal.trace << boost::str (boost::format ("subAccount: account: %d") % naAccountID.humanAccountID ());
|
||||
m_journal.trace << "subAccount:"
|
||||
" account: " << naAccountID.humanAccountID ();
|
||||
|
||||
isrListener->insertSubAccountInfo (naAccountID, uLedgerIndex);
|
||||
}
|
||||
@@ -2832,7 +2836,9 @@ InfoSub::pointer NetworkOPsImp::addRpcSub (const std::string& strUrl, InfoSub::r
|
||||
}
|
||||
|
||||
#ifndef USE_NEW_BOOK_PAGE
|
||||
|
||||
// NIKB FIXME this should be looked at. There's no reason why this shouldn't
|
||||
// work, but it demonstrated poor performance.
|
||||
//
|
||||
// FIXME : support iLimit.
|
||||
void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTakerPaysCurrencyID, const uint160& uTakerPaysIssuerID, const uint160& uTakerGetsCurrencyID, const uint160& uTakerGetsIssuerID, const uint160& uTakerID, const bool bProof, const unsigned int iLimit, const Json::Value& jvMarker, Json::Value& jvResult)
|
||||
{ // CAUTION: This is the old get book page logic
|
||||
@@ -2843,11 +2849,22 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
|
||||
const uint256 uBookEnd = Ledger::getQualityNext (uBookBase);
|
||||
uint256 uTipIndex = uBookBase;
|
||||
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uTakerPaysCurrencyID=%s uTakerPaysIssuerID=%s") % STAmount::createHumanCurrency (uTakerPaysCurrencyID) % RippleAddress::createHumanAccountID (uTakerPaysIssuerID));
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uTakerGetsCurrencyID=%s uTakerGetsIssuerID=%s") % STAmount::createHumanCurrency (uTakerGetsCurrencyID) % RippleAddress::createHumanAccountID (uTakerGetsIssuerID));
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uBookBase=%s") % uBookBase);
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uBookEnd=%s") % uBookEnd);
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uTipIndex=%s") % uTipIndex);
|
||||
if (m_journal.trace)
|
||||
{
|
||||
m_journal.trace << "getBookPage:" <<
|
||||
" uTakerPaysCurrencyID=" <<
|
||||
STAmount::createHumanCurrency (uTakerPaysCurrencyID) <<
|
||||
" uTakerPaysIssuerID=" <<
|
||||
RippleAddress::createHumanAccountID (uTakerPaysIssuerID);
|
||||
m_journal.trace << "getBookPage:" <<
|
||||
" uTakerGetsCurrencyID=" <<
|
||||
STAmount::createHumanCurrency (uTakerGetsCurrencyID) <<
|
||||
" uTakerGetsIssuerID=" <<
|
||||
RippleAddress::createHumanAccountID (uTakerGetsIssuerID);
|
||||
m_journal.trace << "getBookPage: uBookBase=" << uBookBase;
|
||||
m_journal.trace << "getBookPage: uBookEnd=" << uBookEnd;
|
||||
m_journal.trace << "getBookPage: uTipIndex=" << uTipIndex;
|
||||
}
|
||||
|
||||
LedgerEntrySet lesActive (lpLedger, tapNONE, true);
|
||||
|
||||
@@ -2888,8 +2905,8 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
|
||||
|
||||
lesActive.dirFirst (uTipIndex, sleOfferDir, uBookEntry, uOfferIndex);
|
||||
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uTipIndex=%s") % uTipIndex);
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uOfferIndex=%s") % uOfferIndex);
|
||||
m_journal.trace << "getBookPage: uTipIndex=" << uTipIndex;
|
||||
m_journal.trace << "getBookPage: uOfferIndex=" << uOfferIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2979,9 +2996,13 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
|
||||
std::min (saTakerPays, STAmount::multiply (saTakerGetsFunded, saDirRate, saTakerPays)).setJson (jvOffer["taker_pays_funded"]);
|
||||
}
|
||||
|
||||
STAmount saOwnerPays = (QUALITY_ONE == uOfferRate)
|
||||
? saTakerGetsFunded
|
||||
: std::min (saOwnerFunds, STAmount::multiply (saTakerGetsFunded, STAmount (CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9)));
|
||||
STAmount saOwnerPays = (QUALITY_ONE == uOfferRate)
|
||||
? saTakerGetsFunded
|
||||
: std::min (
|
||||
saOwnerFunds,
|
||||
STAmount::multiply (
|
||||
saTakerGetsFunded,
|
||||
STAmount (CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9)));
|
||||
|
||||
umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
|
||||
|
||||
@@ -2995,7 +3016,7 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
|
||||
else
|
||||
{
|
||||
m_journal.warning << "Missing offer";
|
||||
}
|
||||
}
|
||||
|
||||
if (!lesActive.dirNext (uTipIndex, sleOfferDir, uBookEntry, uOfferIndex))
|
||||
{
|
||||
@@ -3003,7 +3024,7 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
|
||||
}
|
||||
else
|
||||
{
|
||||
m_journal.trace << boost::str (boost::format ("getBookPage: uOfferIndex=%s") % uOfferIndex);
|
||||
m_journal.trace << "getBookPage: uOfferIndex=" << uOfferIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ TER PathState::pushImply (
|
||||
const Node& pnPrv = vpnNodes.back ();
|
||||
TER terResult = tesSUCCESS;
|
||||
|
||||
WriteLog (lsTRACE, RippleCalc) << "pushImply> "
|
||||
<< RippleAddress::createHumanAccountID (uAccountID)
|
||||
<< " " << STAmount::createHumanCurrency (uCurrencyID)
|
||||
<< " " << RippleAddress::createHumanAccountID (uIssuerID);
|
||||
WriteLog (lsTRACE, RippleCalc) << "pushImply>" <<
|
||||
" " << RippleAddress::createHumanAccountID (uAccountID) <<
|
||||
" " << STAmount::createHumanCurrency (uCurrencyID) <<
|
||||
" " << RippleAddress::createHumanAccountID (uIssuerID);
|
||||
|
||||
if (pnPrv.uCurrencyID != uCurrencyID)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ TER PathState::pushImply (
|
||||
uIssuerID);
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("pushImply< : %s") % transToken (terResult));
|
||||
WriteLog (lsTRACE, RippleCalc) << "pushImply< : " << transToken (terResult);
|
||||
|
||||
return terResult;
|
||||
}
|
||||
@@ -190,11 +190,11 @@ TER PathState::pushNode (
|
||||
const bool bIssuer = is_bit_set (iType, STPathElement::typeIssuer);
|
||||
TER terResult = tesSUCCESS;
|
||||
|
||||
WriteLog (lsTRACE, RippleCalc) << "pushNode> "
|
||||
<< iType
|
||||
<< ": " << (bAccount ? RippleAddress::createHumanAccountID (uAccountID) : "-")
|
||||
<< " " << (bCurrency ? STAmount::createHumanCurrency (uCurrencyID) : "-")
|
||||
<< "/" << (bIssuer ? RippleAddress::createHumanAccountID (uIssuerID) : "-");
|
||||
WriteLog (lsTRACE, RippleCalc) << "pushNode> " <<
|
||||
iType <<
|
||||
": " << (bAccount ? RippleAddress::createHumanAccountID (uAccountID) : "-") <<
|
||||
" " << (bCurrency ? STAmount::createHumanCurrency (uCurrencyID) : "-") <<
|
||||
"/" << (bIssuer ? RippleAddress::createHumanAccountID (uIssuerID) : "-");
|
||||
|
||||
pnCur.uFlags = iType;
|
||||
pnCur.uCurrencyID = bCurrency ? uCurrencyID : pnPrv.uCurrencyID;
|
||||
@@ -322,9 +322,10 @@ TER PathState::pushNode (
|
||||
if (saOwed <= zero
|
||||
&& -saOwed >= (saLimit = lesEntries.rippleLimit (pnCur.uAccountID, pnBck.uAccountID, pnCur.uCurrencyID)))
|
||||
{
|
||||
WriteLog (lsWARNING, RippleCalc) << boost::str (boost::format ("pushNode: dry: saOwed=%s saLimit=%s")
|
||||
% saOwed
|
||||
% saLimit);
|
||||
WriteLog (lsWARNING, RippleCalc) <<
|
||||
"pushNode: dry:" <<
|
||||
" saOwed=" << saOwed <<
|
||||
" saLimit=" << saLimit;
|
||||
|
||||
terResult = tecPATH_DRY;
|
||||
}
|
||||
@@ -366,9 +367,9 @@ TER PathState::pushNode (
|
||||
|
||||
// Insert intermediary issuer account if needed.
|
||||
terResult = pushImply (
|
||||
ACCOUNT_XRP, // Rippling, but offers don't have an account.
|
||||
pnPrv.uCurrencyID,
|
||||
pnPrv.uIssuerID);
|
||||
ACCOUNT_XRP, // Rippling, but offers don't have an account.
|
||||
pnPrv.uCurrencyID,
|
||||
pnPrv.uIssuerID);
|
||||
}
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
@@ -377,7 +378,7 @@ TER PathState::pushNode (
|
||||
}
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("pushNode< : %s") % transToken (terResult));
|
||||
WriteLog (lsTRACE, RippleCalc) << "pushNode< : " << transToken (terResult);
|
||||
|
||||
return terResult;
|
||||
}
|
||||
@@ -401,7 +402,7 @@ void PathState::setExpanded (
|
||||
const uint160 uOutIssuerID = saOutReq.getIssuer ();
|
||||
const uint160 uSenderIssuerID = !!uMaxCurrencyID ? uSenderID : ACCOUNT_XRP; // Sender is always issuer for non-XRP.
|
||||
|
||||
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("setExpanded> %s") % spSourcePath.getJson (0));
|
||||
WriteLog (lsTRACE, RippleCalc) << "setExpanded> " << spSourcePath.getJson (0);
|
||||
|
||||
lesEntries = lesSource.duplicate ();
|
||||
|
||||
@@ -424,10 +425,10 @@ void PathState::setExpanded (
|
||||
uMaxCurrencyID, // Max specifies the currency.
|
||||
uSenderIssuerID);
|
||||
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: pushed: account=%s currency=%s issuer=%s")
|
||||
% RippleAddress::createHumanAccountID (uSenderID)
|
||||
% STAmount::createHumanCurrency (uMaxCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uSenderIssuerID));
|
||||
WriteLog (lsDEBUG, RippleCalc) << "setExpanded: pushed:" <<
|
||||
" account=" << RippleAddress::createHumanAccountID (uSenderID) <<
|
||||
" currency=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
|
||||
" issuer=" << RippleAddress::createHumanAccountID (uSenderIssuerID);
|
||||
|
||||
if (tesSUCCESS == terStatus
|
||||
&& uMaxIssuerID != uSenderIssuerID) // Issuer was not same as sender.
|
||||
@@ -447,29 +448,30 @@ void PathState::setExpanded (
|
||||
: uOutIssuerID // Use implied node.
|
||||
: ACCOUNT_XRP;
|
||||
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: implied check: uMaxIssuerID=%s uSenderIssuerID=%s uNxtCurrencyID=%s uNxtAccountID=%s")
|
||||
% RippleAddress::createHumanAccountID (uMaxIssuerID)
|
||||
% RippleAddress::createHumanAccountID (uSenderIssuerID)
|
||||
% STAmount::createHumanCurrency (uNxtCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uNxtAccountID));
|
||||
WriteLog (lsDEBUG, RippleCalc) << "setExpanded: implied check:" <<
|
||||
" uMaxIssuerID=" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
|
||||
" uSenderIssuerID=" << RippleAddress::createHumanAccountID (uSenderIssuerID) <<
|
||||
" uNxtCurrencyID=" << STAmount::createHumanCurrency (uNxtCurrencyID) <<
|
||||
" uNxtAccountID=" << RippleAddress::createHumanAccountID (uNxtAccountID);
|
||||
|
||||
// Can't just use push implied, because it can't compensate for next account.
|
||||
if (!uNxtCurrencyID // Next is XRP, offer next. Must go through issuer.
|
||||
|| uMaxCurrencyID != uNxtCurrencyID // Next is different currency, offer next...
|
||||
|| uMaxIssuerID != uNxtAccountID) // Next is not implied issuer
|
||||
{
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: sender implied: account=%s currency=%s issuer=%s")
|
||||
% RippleAddress::createHumanAccountID (uMaxIssuerID)
|
||||
% STAmount::createHumanCurrency (uMaxCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uMaxIssuerID));
|
||||
WriteLog (lsDEBUG, RippleCalc) << "setExpanded: sender implied:" <<
|
||||
" account=" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
|
||||
" currency=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
|
||||
" issuer=" << RippleAddress::createHumanAccountID (uMaxIssuerID);
|
||||
|
||||
// Add account implied by SendMax.
|
||||
terStatus = pushNode (
|
||||
!!uMaxCurrencyID
|
||||
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
|
||||
: STPathElement::typeAccount | STPathElement::typeCurrency,
|
||||
uMaxIssuerID,
|
||||
uMaxCurrencyID,
|
||||
uMaxIssuerID);
|
||||
!!uMaxCurrencyID
|
||||
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
|
||||
: STPathElement::typeAccount | STPathElement::typeCurrency,
|
||||
uMaxIssuerID,
|
||||
uMaxCurrencyID,
|
||||
uMaxIssuerID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,8 +479,10 @@ void PathState::setExpanded (
|
||||
{
|
||||
if (tesSUCCESS == terStatus)
|
||||
{
|
||||
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("setExpanded: element in path:"));
|
||||
terStatus = pushNode (speElement.getNodeType (), speElement.getAccountID (), speElement.getCurrency (), speElement.getIssuerID ());
|
||||
WriteLog (lsTRACE, RippleCalc) << "setExpanded: element in path";
|
||||
terStatus = pushNode (
|
||||
speElement.getNodeType (), speElement.getAccountID (),
|
||||
speElement.getCurrency (), speElement.getIssuerID ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,17 +495,18 @@ void PathState::setExpanded (
|
||||
|| pnPrv.uAccountID != uOutIssuerID)) // Need the implied issuer.
|
||||
{
|
||||
// Add implied account.
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: receiver implied: account=%s currency=%s issuer=%s")
|
||||
% RippleAddress::createHumanAccountID (uOutIssuerID)
|
||||
% STAmount::createHumanCurrency (uOutCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uOutIssuerID));
|
||||
WriteLog (lsDEBUG, RippleCalc) << "setExpanded: receiver implied:" <<
|
||||
" account=" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
|
||||
" currency=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
|
||||
" issuer=" << RippleAddress::createHumanAccountID (uOutIssuerID);
|
||||
|
||||
terStatus = pushNode (
|
||||
!!uOutCurrencyID
|
||||
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
|
||||
: STPathElement::typeAccount | STPathElement::typeCurrency,
|
||||
uOutIssuerID,
|
||||
uOutCurrencyID,
|
||||
uOutIssuerID);
|
||||
!!uOutCurrencyID
|
||||
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
|
||||
: STPathElement::typeAccount | STPathElement::typeCurrency,
|
||||
uOutIssuerID,
|
||||
uOutCurrencyID,
|
||||
uOutIssuerID);
|
||||
}
|
||||
|
||||
if (tesSUCCESS == terStatus)
|
||||
@@ -510,12 +515,12 @@ void PathState::setExpanded (
|
||||
// Last node is always an account.
|
||||
|
||||
terStatus = pushNode (
|
||||
!!uOutCurrencyID
|
||||
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
|
||||
: STPathElement::typeAccount | STPathElement::typeCurrency,
|
||||
uReceiverID, // Receive to output
|
||||
uOutCurrencyID, // Desired currency
|
||||
uReceiverID);
|
||||
!!uOutCurrencyID
|
||||
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
|
||||
: STPathElement::typeAccount | STPathElement::typeCurrency,
|
||||
uReceiverID, // Receive to output
|
||||
uOutCurrencyID, // Desired currency
|
||||
uReceiverID);
|
||||
}
|
||||
|
||||
if (tesSUCCESS == terStatus)
|
||||
@@ -532,20 +537,20 @@ void PathState::setExpanded (
|
||||
if (!umForward.insert (std::make_pair (std::make_tuple (pnCur.uAccountID, pnCur.uCurrencyID, pnCur.uIssuerID), uNode)).second)
|
||||
{
|
||||
// Failed to insert. Have a loop.
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: loop detected: %s")
|
||||
% getJson ());
|
||||
WriteLog (lsDEBUG, RippleCalc) <<
|
||||
"setExpanded: loop detected: " << getJson ();
|
||||
|
||||
terStatus = temBAD_PATH_LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: in=%s/%s out=%s/%s %s")
|
||||
% STAmount::createHumanCurrency (uMaxCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uMaxIssuerID)
|
||||
% STAmount::createHumanCurrency (uOutCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uOutIssuerID)
|
||||
% getJson ());
|
||||
WriteLog (lsDEBUG, RippleCalc) << "setExpanded:" <<
|
||||
" in=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
|
||||
"/" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
|
||||
" out=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
|
||||
"/" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
|
||||
": " << getJson ();
|
||||
}
|
||||
|
||||
// Set to a canonical path.
|
||||
@@ -755,12 +760,12 @@ void PathState::setCanonical (
|
||||
}
|
||||
}
|
||||
|
||||
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setCanonical: in=%s/%s out=%s/%s %s")
|
||||
% STAmount::createHumanCurrency (uMaxCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uMaxIssuerID)
|
||||
% STAmount::createHumanCurrency (uOutCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (uOutIssuerID)
|
||||
% getJson ());
|
||||
WriteLog (lsDEBUG, RippleCalc) << "setCanonical:" <<
|
||||
" in=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
|
||||
"/" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
|
||||
" out=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
|
||||
"/" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
|
||||
": " << getJson ();
|
||||
}
|
||||
|
||||
/** Check if a sequence of three accounts violates the no ripple constrains
|
||||
@@ -924,7 +929,7 @@ Json::Value PathState::getJson () const
|
||||
jvPathState["out_pass"] = saOutPass.getJson (0);
|
||||
|
||||
if (uQuality)
|
||||
jvPathState["uQuality"] = boost::str (boost::format ("%d") % uQuality);
|
||||
jvPathState["uQuality"] = boost::lexical_cast<std::string>(uQuality);
|
||||
|
||||
return jvPathState;
|
||||
}
|
||||
|
||||
@@ -128,13 +128,12 @@ bool Pathfinder::findPaths (int iLevel, const unsigned int iMaxPaths, STPathSet&
|
||||
{ // pathsOut contains only non-default paths without source or destiation
|
||||
// On input, pathsOut contains any paths you want to ensure are included if still good
|
||||
|
||||
WriteLog (lsTRACE, Pathfinder) << boost::str (boost::format ("findPaths> mSrcAccountID=%s mDstAccountID=%s mDstAmount=%s mSrcCurrencyID=%s mSrcIssuerID=%s")
|
||||
% RippleAddress::createHumanAccountID (mSrcAccountID)
|
||||
% RippleAddress::createHumanAccountID (mDstAccountID)
|
||||
% mDstAmount.getFullText ()
|
||||
% STAmount::createHumanCurrency (mSrcCurrencyID)
|
||||
% RippleAddress::createHumanAccountID (mSrcIssuerID)
|
||||
);
|
||||
WriteLog (lsTRACE, Pathfinder) << "findPaths>"
|
||||
" mSrcAccountID=" << RippleAddress::createHumanAccountID (mSrcAccountID) <<
|
||||
" mDstAccountID=" << RippleAddress::createHumanAccountID (mDstAccountID) <<
|
||||
" mDstAmount=" << mDstAmount.getFullText () <<
|
||||
" mSrcCurrencyID=" << STAmount::createHumanCurrency (mSrcCurrencyID) <<
|
||||
" mSrcIssuerID=" << RippleAddress::createHumanAccountID (mSrcIssuerID);
|
||||
|
||||
if (!mLedger)
|
||||
{
|
||||
@@ -319,28 +318,27 @@ STPathSet Pathfinder::filterPaths(int iMaxPaths, STPath& extraPath)
|
||||
|
||||
if (tesSUCCESS != terResult)
|
||||
{
|
||||
WriteLog (lsDEBUG, Pathfinder)
|
||||
<< boost::str (boost::format ("findPaths: dropping: %s: %s")
|
||||
% transToken (terResult)
|
||||
% spCurrent.getJson (0));
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"findPaths: dropping: " << transToken (terResult) <<
|
||||
": " << spCurrent.getJson (0);
|
||||
}
|
||||
else if (saDstAmountAct < saMinDstAmount)
|
||||
{
|
||||
WriteLog (lsDEBUG, Pathfinder)
|
||||
<< boost::str (boost::format ("findPaths: dropping: outputs %s: %s")
|
||||
% saDstAmountAct
|
||||
% spCurrent.getJson (0));
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"findPaths: dropping: outputs " << saDstAmountAct <<
|
||||
": %s" << spCurrent.getJson (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::uint64_t uQuality = STAmount::getRate (saDstAmountAct, saMaxAmountAct);
|
||||
std::uint64_t uQuality (
|
||||
STAmount::getRate (saDstAmountAct, saMaxAmountAct));
|
||||
|
||||
WriteLog (lsDEBUG, Pathfinder)
|
||||
<< boost::str (boost::format ("findPaths: quality: %d: %s")
|
||||
% uQuality
|
||||
% spCurrent.getJson (0));
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"findPaths: quality: " << uQuality <<
|
||||
": " << spCurrent.getJson (0);
|
||||
|
||||
vMap.push_back (path_LQ_t (uQuality, spCurrent.mPath.size (), saDstAmountAct, i));
|
||||
vMap.push_back (path_LQ_t (
|
||||
uQuality, spCurrent.mPath.size (), saDstAmountAct, i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,24 +365,30 @@ STPathSet Pathfinder::filterPaths(int iMaxPaths, STPath& extraPath)
|
||||
{
|
||||
// found an extra path that can move the whole amount
|
||||
extraPath = mCompletePaths[lqt.get<3>()];
|
||||
WriteLog (lsDEBUG, Pathfinder) << "Found extra full path: " << extraPath.getJson(0);
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"Found extra full path: " << extraPath.getJson(0);
|
||||
}
|
||||
else
|
||||
WriteLog (lsDEBUG, Pathfinder) << "Skipping a non-filling path: " << mCompletePaths[lqt.get<3> ()].getJson (0);
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"Skipping a non-filling path: " <<
|
||||
mCompletePaths[lqt.get<3> ()].getJson (0);
|
||||
}
|
||||
|
||||
if (remaining > zero)
|
||||
{
|
||||
WriteLog (lsINFO, Pathfinder) << "Paths could not send " << remaining << " of " << mDstAmount;
|
||||
WriteLog (lsINFO, Pathfinder) <<
|
||||
"Paths could not send " << remaining << " of " << mDstAmount;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog (lsDEBUG, Pathfinder) << boost::str (boost::format ("findPaths: RESULTS: %s") % spsDst.getJson (0));
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"findPaths: RESULTS: " << spsDst.getJson (0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog (lsDEBUG, Pathfinder) << boost::str (boost::format ("findPaths: RESULTS: non-defaults filtered away"));
|
||||
WriteLog (lsDEBUG, Pathfinder) <<
|
||||
"findPaths: RESULTS: non-defaults filtered away";
|
||||
}
|
||||
|
||||
return spsDst;
|
||||
|
||||
@@ -105,10 +105,7 @@ bool STAmount::bSetJson (const Json::Value& jvSource)
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
WriteLog (lsINFO, STAmount)
|
||||
<< boost::str (boost::format ("bSetJson(): caught: %s")
|
||||
% e.what ());
|
||||
|
||||
WriteLog (lsINFO, STAmount) << "bSetJson(): caught: " << e.what ();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -120,11 +117,11 @@ STAmount::STAmount (SField::ref n, const Json::Value& v)
|
||||
|
||||
if (v.isObject ())
|
||||
{
|
||||
WriteLog (lsTRACE, STAmount)
|
||||
<< boost::str (boost::format ("value='%s', currency='%s', issuer='%s'")
|
||||
% v["value"].asString ()
|
||||
% v["currency"].asString ()
|
||||
% v["issuer"].asString ());
|
||||
WriteLog (lsTRACE, STAmount) <<
|
||||
"value='" << v["value"].asString () <<
|
||||
"', currency='" << v["currency"].asString () <<
|
||||
"', issuer='" << v["issuer"].asString () <<
|
||||
"')";
|
||||
|
||||
value = v["value"];
|
||||
currency = v["currency"];
|
||||
@@ -222,51 +219,58 @@ STAmount::STAmount (SField::ref n, const Json::Value& v)
|
||||
|
||||
std::string STAmount::createHumanCurrency (const uint160& uCurrency)
|
||||
{
|
||||
std::string sCurrency;
|
||||
static uint160 sFiatBits("FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000");
|
||||
static uint160 const sFiatBits("FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000");
|
||||
|
||||
if (uCurrency.isZero ())
|
||||
{
|
||||
return SYSTEM_CURRENCY_CODE;
|
||||
}
|
||||
else if (CURRENCY_ONE == uCurrency)
|
||||
|
||||
if (CURRENCY_ONE == uCurrency)
|
||||
{
|
||||
return "1";
|
||||
}
|
||||
else if (CURRENCY_BAD == uCurrency)
|
||||
|
||||
if (CURRENCY_BAD == uCurrency)
|
||||
{
|
||||
return uCurrency.ToString ();
|
||||
}
|
||||
else if ((uCurrency & sFiatBits).isZero ())
|
||||
|
||||
if ((uCurrency & sFiatBits).isZero ())
|
||||
{
|
||||
Serializer s (160 / 8);
|
||||
Serializer s (160 / 8);
|
||||
|
||||
s.add160 (uCurrency);
|
||||
|
||||
SerializerIterator sit (s);
|
||||
|
||||
Blob vucZeros = sit.getRaw (96 / 8);
|
||||
Blob vucIso = sit.getRaw (24 / 8);
|
||||
Blob vucVersion = sit.getRaw (16 / 8);
|
||||
Blob vucReserved = sit.getRaw (24 / 8);
|
||||
Blob const vucZeros (sit.getRaw (96 / 8));
|
||||
Blob const vucIso (sit.getRaw (24 / 8));
|
||||
Blob const vucVersion (sit.getRaw (16 / 8));
|
||||
Blob const vucReserved (sit.getRaw (24 / 8));
|
||||
|
||||
bool bIso = isZeroFilled (vucZeros.begin (), vucZeros.size ()) // Leading zeros
|
||||
&& isZeroFilled (vucVersion.begin (), vucVersion.size ()) // Zero version
|
||||
&& isZeroFilled (vucReserved.begin (), vucReserved.size ()); // Reserved is zero.
|
||||
auto is_zero_filled = [](Blob const& blob)
|
||||
{
|
||||
auto ret = std::find_if (blob.cbegin (), blob.cend (),
|
||||
[](unsigned char c)
|
||||
{
|
||||
return c != 0;
|
||||
});
|
||||
|
||||
return ret == blob.cend ();
|
||||
};
|
||||
|
||||
bool bIso = is_zero_filled (vucZeros) // Leading zeros
|
||||
&& is_zero_filled (vucVersion) // Zero version
|
||||
&& is_zero_filled (vucReserved); // Reserved is zero.
|
||||
|
||||
if (bIso)
|
||||
{
|
||||
sCurrency.assign (vucIso.begin (), vucIso.end ());
|
||||
}
|
||||
else
|
||||
{
|
||||
sCurrency = uCurrency.ToString ();
|
||||
}
|
||||
return std::string (vucIso.begin (), vucIso.end ());
|
||||
|
||||
return uCurrency.ToString ();
|
||||
}
|
||||
else
|
||||
sCurrency = uCurrency.GetHex ();
|
||||
|
||||
return sCurrency;
|
||||
return uCurrency.GetHex ();
|
||||
}
|
||||
|
||||
bool STAmount::setValue (const std::string& sAmount)
|
||||
@@ -1081,30 +1085,22 @@ STAmount STAmount::deserialize (SerializerIterator& it)
|
||||
|
||||
std::string STAmount::getFullText () const
|
||||
{
|
||||
static const boost::format nativeFormat ("%s/" SYSTEM_CURRENCY_CODE);
|
||||
static const boost::format noIssuer ("%s/%s/0");
|
||||
static const boost::format issuerOne ("%s/%s/1");
|
||||
static const boost::format normal ("%s/%s/%s");
|
||||
std::string ret;
|
||||
|
||||
if (mIsNative)
|
||||
ret.reserve(64);
|
||||
ret = getText () + "/" + getHumanCurrency ();
|
||||
|
||||
if (!mIsNative)
|
||||
{
|
||||
return str (boost::format (nativeFormat) % getText ());
|
||||
}
|
||||
else if (!mIssuer)
|
||||
{
|
||||
return str (boost::format (noIssuer) % getText () % getHumanCurrency ());
|
||||
}
|
||||
else if (mIssuer == ACCOUNT_ONE)
|
||||
{
|
||||
return str (boost::format (issuerOne) % getText () % getHumanCurrency ());
|
||||
}
|
||||
else
|
||||
{
|
||||
return str (boost::format (normal)
|
||||
% getText ()
|
||||
% getHumanCurrency ()
|
||||
% RippleAddress::createHumanAccountID (mIssuer));
|
||||
if (!mIssuer)
|
||||
ret += "/0";
|
||||
else if (mIssuer == ACCOUNT_ONE)
|
||||
ret += "/1";
|
||||
else
|
||||
ret += RippleAddress::createHumanAccountID (mIssuer);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
STAmount STAmount::getRound () const
|
||||
|
||||
@@ -780,16 +780,6 @@ public:
|
||||
|
||||
static void canonicalizeRound (bool isNative, std::uint64_t& value, int& offset, bool roundUp);
|
||||
|
||||
private:
|
||||
template <class Iterator>
|
||||
static bool isZeroFilled (Iterator first, int iSize)
|
||||
{
|
||||
while (iSize && !*first++)
|
||||
--iSize;
|
||||
|
||||
return !iSize;
|
||||
}
|
||||
|
||||
private:
|
||||
uint160 mCurrency; // Compared by ==. Always update mIsNative.
|
||||
uint160 mIssuer; // Not compared by ==. 0 for XRP.
|
||||
|
||||
Reference in New Issue
Block a user