Refactor usage of boost::format

This commit is contained in:
Nik Bougalis
2014-04-13 14:13:58 -07:00
committed by Vinnie Falco
parent 2ed8edc19d
commit 5fddf374f4
8 changed files with 370 additions and 310 deletions

View File

@@ -330,9 +330,9 @@ AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID)
if (!sle) if (!sle)
{ {
WriteLog (lsDEBUG, Ledger) << boost::str (boost::format ("Ledger:getAccountState: not found: %s: %s") WriteLog (lsDEBUG, Ledger) << "Ledger:getAccountState:" <<
% accountID.humanAccountID () " not found: " << accountID.humanAccountID () <<
% Ledger::getAccountRootIndex (accountID).GetHex ()); ": " << Ledger::getAccountRootIndex (accountID).GetHex ();
return AccountState::pointer (); 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. uint256 uBaseIndex = getQualityIndex (s.getSHA512Half ()); // Return with quality 0.
WriteLog (lsTRACE, Ledger) << boost::str (boost::format ("getBookBase(%s,%s,%s,%s) = %s") WriteLog (lsTRACE, Ledger) << "getBookBase" <<
% STAmount::createHumanCurrency (uTakerPaysCurrency) "(" << STAmount::createHumanCurrency (uTakerPaysCurrency) <<
% RippleAddress::createHumanAccountID (uTakerPaysIssuerID) "," << RippleAddress::createHumanAccountID (uTakerPaysIssuerID) <<
% STAmount::createHumanCurrency (uTakerGetsCurrency) "," << STAmount::createHumanCurrency (uTakerGetsCurrency) <<
% RippleAddress::createHumanAccountID (uTakerGetsIssuerID) "," << RippleAddress::createHumanAccountID (uTakerGetsIssuerID) <<
% uBaseIndex.ToString ()); ") = " << uBaseIndex.ToString ();
assert (isValidBook (uTakerPaysCurrency, uTakerPaysIssuerID, uTakerGetsCurrency, uTakerGetsIssuerID)); assert (isValidBook (uTakerPaysCurrency, uTakerPaysIssuerID, uTakerGetsCurrency, uTakerGetsIssuerID));

View File

@@ -658,9 +658,9 @@ TER LedgerEntrySet::dirAdd (
uint256 const& uLedgerIndex, uint256 const& uLedgerIndex,
std::function<void (SLE::ref, bool)> fDescriber) std::function<void (SLE::ref, bool)> fDescriber)
{ {
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("dirAdd: uRootIndex=%s uLedgerIndex=%s") WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd:" <<
% uRootIndex.ToString () " uRootIndex=" << uRootIndex.ToString () <<
% uLedgerIndex.ToString ()); " uLedgerIndex=" << uLedgerIndex.ToString ();
SLE::pointer sleNode; SLE::pointer sleNode;
STVector256 svIndexes; STVector256 svIndexes;
@@ -731,9 +731,12 @@ TER LedgerEntrySet::dirAdd (
svIndexes.peekValue ().push_back (uLedgerIndex); // Append entry. svIndexes.peekValue ().push_back (uLedgerIndex); // Append entry.
sleNode->setFieldV256 (sfIndexes, svIndexes); // Save entry. sleNode->setFieldV256 (sfIndexes, svIndexes); // Save entry.
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: creating: root: " << uRootIndex.ToString (); WriteLog (lsTRACE, LedgerEntrySet) <<
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: appending: Entry: " << uLedgerIndex.ToString (); "dirAdd: creating: root: " << uRootIndex.ToString ();
WriteLog (lsTRACE, LedgerEntrySet) << "dirAdd: appending: Node: " << strHex (uNodeDir); 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(); // WriteLog (lsINFO, LedgerEntrySet) << "dirAdd: appending: PREV: " << svIndexes.peekValue()[0].ToString();
return tesSUCCESS; return tesSUCCESS;
@@ -753,11 +756,10 @@ TER LedgerEntrySet::dirDelete (
if (!sleNode) if (!sleNode)
{ {
WriteLog (lsWARNING, LedgerEntrySet) WriteLog (lsWARNING, LedgerEntrySet) << "dirDelete: no such node:" <<
<< boost::str (boost::format ("dirDelete: no such node: uRootIndex=%s uNodeDir=%s uLedgerIndex=%s") " uRootIndex=" << uRootIndex.ToString () <<
% uRootIndex.ToString () " uNodeDir=" << strHex (uNodeDir) <<
% strHex (uNodeDir) " uLedgerIndex=" << uLedgerIndex.ToString ();
% uLedgerIndex.ToString ());
if (!bSoft) if (!bSoft)
{ {
@@ -1003,7 +1005,10 @@ bool LedgerEntrySet::dirNext (
} }
uEntryIndex = vuiIndexes[uDirEntry++]; 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; return true;
} }
@@ -1118,13 +1123,11 @@ STAmount LedgerEntrySet::rippleOwed (const uint160& uToAccountID, const uint160&
{ {
saBalance.clear (uCurrencyID, uToAccountID); saBalance.clear (uCurrencyID, uToAccountID);
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleOwed: No credit line between " WriteLog (lsDEBUG, LedgerEntrySet) << "rippleOwed:" <<
<< RippleAddress::createHumanAccountID (uFromAccountID) " No credit line between " <<
<< " and " RippleAddress::createHumanAccountID (uFromAccountID) <<
<< RippleAddress::createHumanAccountID (uToAccountID) " and " << RippleAddress::createHumanAccountID (uToAccountID) <<
<< " for " " for " << STAmount::createHumanCurrency (uCurrencyID);
<< STAmount::createHumanCurrency (uCurrencyID)
<< "." ;
#if 0 #if 0
// We could cut off coming here if we test for no line sooner. // 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) 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) std::uint32_t uQuality =
? sleAccount->getFieldU32 (sfTransferRate) sleAccount && sleAccount->isFieldPresent (sfTransferRate)
: QUALITY_ONE; ? sleAccount->getFieldU32 (sfTransferRate)
: QUALITY_ONE;
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("rippleTransferRate: uIssuerID=%s account_exists=%d transfer_rate=%f") WriteLog (lsTRACE, LedgerEntrySet) << "rippleTransferRate:" <<
% RippleAddress::createHumanAccountID (uIssuerID) " uIssuerID=" << RippleAddress::createHumanAccountID (uIssuerID) <<
% !!sleAccount " account_exists=" << std::boolalpha << !!sleAccount <<
% (uQuality / 1000000000.0)); " transfer_rate=" << (uQuality / 1000000000.0);
return uQuality; return uQuality;
} }
@@ -1181,6 +1186,8 @@ LedgerEntrySet::rippleTransferRate (const uint160& uSenderID,
const uint160& uReceiverID, const uint160& uReceiverID,
const uint160& uIssuerID) 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 return uSenderID == uIssuerID || uReceiverID == uIssuerID
? QUALITY_ONE ? QUALITY_ONE
: rippleTransferRate (uIssuerID); : rippleTransferRate (uIssuerID);
@@ -1202,7 +1209,8 @@ LedgerEntrySet::rippleQualityIn (const uint160& uToAccountID,
} }
else else
{ {
sleRippleState = entryCache (ltRIPPLE_STATE, Ledger::getRippleStateIndex (uToAccountID, uFromAccountID, uCurrencyID)); sleRippleState = entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (uToAccountID, uFromAccountID, uCurrencyID));
if (sleRippleState) 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") WriteLog (lsTRACE, LedgerEntrySet) << "rippleQuality: " <<
% (sfLow == sfLowQualityIn ? "in" : "out") (sfLow == sfLowQualityIn ? "in" : "out") <<
% RippleAddress::createHumanAccountID (uToAccountID) " uToAccountID=" << RippleAddress::createHumanAccountID (uToAccountID) <<
% RippleAddress::createHumanAccountID (uFromAccountID) " uFromAccountID=" << RippleAddress::createHumanAccountID (uFromAccountID) <<
% STAmount::createHumanCurrency (uCurrencyID) " uCurrencyID=" << STAmount::createHumanCurrency (uCurrencyID) <<
% !!sleRippleState " bLine=" << std::boolalpha << !!sleRippleState <<
% (uQuality / 1000000000.0)); " uQuality=" << (uQuality / 1000000000.0);
// assert(uToAccountID == uFromAccountID || !!sleRippleState); // assert(uToAccountID == uFromAccountID || !!sleRippleState);
@@ -1239,8 +1247,9 @@ LedgerEntrySet::rippleQualityIn (const uint160& uToAccountID,
// <-- IOU's uAccountID has of uIssuerID. // <-- IOU's uAccountID has of uIssuerID.
STAmount LedgerEntrySet::rippleHolds (const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID) STAmount LedgerEntrySet::rippleHolds (const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID)
{ {
STAmount saBalance; STAmount saBalance;
SLE::pointer sleRippleState = entryCache (ltRIPPLE_STATE, Ledger::getRippleStateIndex (uAccountID, uIssuerID, uCurrencyID)); SLE::pointer sleRippleState = entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (uAccountID, uIssuerID, uCurrencyID));
if (!sleRippleState) if (!sleRippleState)
{ {
@@ -1272,10 +1281,11 @@ STAmount LedgerEntrySet::accountHolds (const uint160& uAccountID, const uint160&
if (!uCurrencyID) if (!uCurrencyID)
{ {
SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uAccountID)); SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT,
std::uint64_t uReserve = mLedger->getReserve (sleAccount->getFieldU32 (sfOwnerCount)); 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) if (saBalance < uReserve)
{ {
@@ -1283,22 +1293,22 @@ STAmount LedgerEntrySet::accountHolds (const uint160& uAccountID, const uint160&
} }
else else
{ {
saAmount = saBalance - uReserve; saAmount = saBalance - uReserve;
} }
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountHolds: uAccountID=%s saAmount=%s saBalance=%s uReserve=%d") WriteLog (lsTRACE, LedgerEntrySet) << "accountHolds:" <<
% RippleAddress::createHumanAccountID (uAccountID) " uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
% saAmount.getFullText () " saAmount=" << saAmount.getFullText () <<
% saBalance.getFullText () " saBalance=" << saBalance.getFullText () <<
% uReserve); " uReserve=" << uReserve;
} }
else else
{ {
saAmount = rippleHolds (uAccountID, uCurrencyID, uIssuerID); saAmount = rippleHolds (uAccountID, uCurrencyID, uIssuerID);
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountHolds: uAccountID=%s saAmount=%s") WriteLog (lsTRACE, LedgerEntrySet) << "accountHolds:" <<
% RippleAddress::createHumanAccountID (uAccountID) " uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
% saAmount.getFullText ()); " saAmount=" << saAmount.getFullText ();
} }
return saAmount; return saAmount;
@@ -1318,39 +1328,49 @@ STAmount LedgerEntrySet::accountFunds (const uint160& uAccountID, const STAmount
{ {
saFunds = saDefault; saFunds = saDefault;
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountFunds: uAccountID=%s saDefault=%s SELF-FUNDED") WriteLog (lsTRACE, LedgerEntrySet) << "accountFunds:" <<
% RippleAddress::createHumanAccountID (uAccountID) " uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
% saDefault.getFullText ()); " saDefault=" << saDefault.getFullText () <<
" SELF-FUNDED";
} }
else else
{ {
saFunds = accountHolds (uAccountID, saDefault.getCurrency (), saDefault.getIssuer ()); saFunds = accountHolds (uAccountID, saDefault.getCurrency (), saDefault.getIssuer ());
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountFunds: uAccountID=%s saDefault=%s saFunds=%s") WriteLog (lsTRACE, LedgerEntrySet) << "accountFunds:" <<
% RippleAddress::createHumanAccountID (uAccountID) " uAccountID=" << RippleAddress::createHumanAccountID (uAccountID) <<
% saDefault.getFullText () " saDefault=" << saDefault.getFullText () <<
% saFunds.getFullText ()); " saFunds=" << saFunds.getFullText ();
} }
return saFunds; return saFunds;
} }
// Calculate transit fee. // 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) if (uSenderID != uIssuerID && uReceiverID != uIssuerID)
{ {
std::uint32_t uTransitRate = rippleTransferRate (uIssuerID); std::uint32_t uTransitRate = rippleTransferRate (uIssuerID);
if (QUALITY_ONE != uTransitRate) 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 saTransferTotal = STAmount::multiply (
STAmount saTransferFee = saTransferTotal - saAmount; saAmount, saTransitRate,
saAmount.getCurrency (), saAmount.getIssuer ());
STAmount saTransferFee = saTransferTotal - saAmount;
WriteLog (lsDEBUG, LedgerEntrySet) << boost::str (boost::format ("rippleTransferFee: saTransferFee=%s") WriteLog (lsDEBUG, LedgerEntrySet) << "rippleTransferFee:" <<
% saTransferFee.getFullText ()); " saTransferFee=" << saTransferFee.getFullText ();
return saTransferFee; return saTransferFee;
} }
@@ -1487,21 +1507,21 @@ TER LedgerEntrySet::rippleCredit (const uint160& uSenderID, const uint160& uRece
saBalance.setIssuer (ACCOUNT_ONE); saBalance.setIssuer (ACCOUNT_ONE);
WriteLog (lsDEBUG, LedgerEntrySet) << boost::str (boost::format ("rippleCredit: create line: %s --> %s : %s") WriteLog (lsDEBUG, LedgerEntrySet) << "rippleCredit: "
% RippleAddress::createHumanAccountID (uSenderID) "create line: " << RippleAddress::createHumanAccountID (uSenderID) <<
% RippleAddress::createHumanAccountID (uReceiverID) " -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
% saAmount.getFullText ()); " : " << saAmount.getFullText ();
terResult = trustCreate ( terResult = trustCreate (
bSenderHigh, bSenderHigh,
uSenderID, uSenderID,
uReceiverID, uReceiverID,
uIndex, uIndex,
entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)), entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)),
false, false,
false, false,
saBalance, saBalance,
saReceiverLimit); saReceiverLimit);
} }
else else
{ {
@@ -1514,12 +1534,12 @@ TER LedgerEntrySet::rippleCredit (const uint160& uSenderID, const uint160& uRece
saBalance -= saAmount; saBalance -= saAmount;
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("rippleCredit: %s --> %s : before=%s amount=%s after=%s") WriteLog (lsTRACE, LedgerEntrySet) << "rippleCredit: " <<
% RippleAddress::createHumanAccountID (uSenderID) RippleAddress::createHumanAccountID (uSenderID) <<
% RippleAddress::createHumanAccountID (uReceiverID) " -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
% saBefore.getFullText () " : before=" << saBefore.getFullText () <<
% saAmount.getFullText () " amount=" << saAmount.getFullText () <<
% saBalance.getFullText ()); " after=" << saBalance.getFullText ();
bool bDelete = false; bool bDelete = false;
std::uint32_t uFlags; 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. 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") WriteLog (lsDEBUG, LedgerEntrySet) << "rippleSend> " <<
% RippleAddress::createHumanAccountID (uSenderID) RippleAddress::createHumanAccountID (uSenderID) <<
% RippleAddress::createHumanAccountID (uReceiverID) " - > " << RippleAddress::createHumanAccountID (uReceiverID) <<
% saAmount.getFullText () " : deliver=" << saAmount.getFullText () <<
% saTransitFee.getFullText () " fee=" << saTransitFee.getFullText () <<
% saActual.getFullText ()); " cost=" << saActual.getFullText ();
terResult = rippleCredit (uIssuerID, uReceiverID, saAmount); terResult = rippleCredit (uIssuerID, uReceiverID, saAmount);
@@ -1626,54 +1646,70 @@ TER LedgerEntrySet::accountSend (const uint160& uSenderID, const uint160& uRecei
else if (saAmount.isNative ()) else if (saAmount.isNative ())
{ {
// XRP send which does not check reserve and can do pure adjustment. // XRP send which does not check reserve and can do pure adjustment.
SLE::pointer sleSender = !!uSenderID SLE::pointer sleSender = !!uSenderID
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uSenderID)) ? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uSenderID))
: SLE::pointer (); : SLE::pointer ();
SLE::pointer sleReceiver = !!uReceiverID SLE::pointer sleReceiver = !!uReceiverID
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)) ? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID))
: SLE::pointer (); : SLE::pointer ();
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountSend> %s (%s) -> %s (%s) : %s") auto get_balance = [](SLE::pointer acct)
% RippleAddress::createHumanAccountID (uSenderID) {
% (sleSender ? (sleSender->getFieldAmount (sfBalance)).getFullText () : "-") std::string ret ("-");
% RippleAddress::createHumanAccountID (uReceiverID)
% (sleReceiver ? (sleReceiver->getFieldAmount (sfBalance)).getFullText () : "-") if (acct)
% saAmount.getFullText ()); 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)
{ {
if (sleSender->getFieldAmount (sfBalance) < saAmount) 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 else
{ {
sleSender->setFieldAmount (sfBalance, sleSender->getFieldAmount (sfBalance) - saAmount); // Decrement XRP balance. // Decrement XRP balance.
sleSender->setFieldAmount (sfBalance,
sleSender->getFieldAmount (sfBalance) - saAmount);
entryModify (sleSender); entryModify (sleSender);
} }
} }
if (tesSUCCESS == terResult && sleReceiver) 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); entryModify (sleReceiver);
} }
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountSend< %s (%s) -> %s (%s) : %s") WriteLog (lsTRACE, LedgerEntrySet) << "accountSend< " <<
% RippleAddress::createHumanAccountID (uSenderID) RippleAddress::createHumanAccountID (uSenderID) <<
% (sleSender ? (sleSender->getFieldAmount (sfBalance)).getFullText () : "-") " (" << get_balance(sleSender) <<
% RippleAddress::createHumanAccountID (uReceiverID) ") -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
% (sleReceiver ? (sleReceiver->getFieldAmount (sfBalance)).getFullText () : "-") " (" << get_balance(sleReceiver) <<
% saAmount.getFullText ()); ") : " << saAmount.getFullText ();
} }
else else
{ {
STAmount saActual; STAmount saActual;
WriteLog (lsTRACE, LedgerEntrySet) << boost::str (boost::format ("accountSend: %s -> %s : %s") WriteLog (lsTRACE, LedgerEntrySet) << "accountSend: " <<
% RippleAddress::createHumanAccountID (uSenderID) RippleAddress::createHumanAccountID (uSenderID) <<
% RippleAddress::createHumanAccountID (uReceiverID) " -> " << RippleAddress::createHumanAccountID (uReceiverID) <<
% saAmount.getFullText ()); " : " << saAmount.getFullText ();
terResult = rippleSend (uSenderID, uReceiverID, saAmount, saActual); terResult = rippleSend (uSenderID, uReceiverID, saAmount, saActual);

View File

@@ -44,9 +44,9 @@ bool ContinuousLedgerTiming::shouldClose (
(currentMSeconds < -1000) || (currentMSeconds > 600000)) (currentMSeconds < -1000) || (currentMSeconds > 600000))
{ {
WriteLog (lsWARNING, LedgerTiming) << WriteLog (lsWARNING, LedgerTiming) <<
boost::str (boost::format ("CLC::shouldClose range Trans=%s, Prop: %d/%d, Secs: %d (last:%d)") "CLC::shouldClose range Trans=" << (anyTransactions ? "yes" : "no") <<
% (anyTransactions ? "yes" : "no") % previousProposers % proposersClosed " Prop: " << previousProposers << "/" << proposersClosed <<
% currentMSeconds % previousMSeconds); " Secs: " << currentMSeconds << " (last: " << previousMSeconds << ")";
return true; return true;
} }
@@ -55,8 +55,9 @@ bool ContinuousLedgerTiming::shouldClose (
// no transactions so far this interval // no transactions so far this interval
if (proposersClosed > (previousProposers / 4)) // did we miss a transaction? if (proposersClosed > (previousProposers / 4)) // did we miss a transaction?
{ {
WriteLog (lsTRACE, LedgerTiming) << "no transactions, many proposers: now (" << proposersClosed << " closed, " WriteLog (lsTRACE, LedgerTiming) <<
<< previousProposers << " before)"; "no transactions, many proposers: now (" << proposersClosed <<
" closed, " << previousProposers << " before)";
return true; return true;
} }
@@ -78,13 +79,15 @@ bool ContinuousLedgerTiming::shouldClose (
if ((openMSeconds < LEDGER_MIN_CLOSE) && ((proposersClosed + proposersValidated) < (previousProposers / 2 ))) 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; return false;
} }
if ((currentMSeconds < previousMSeconds) && ((proposersClosed + proposersValidated) < previousProposers)) 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; return false;
} }
@@ -103,9 +106,12 @@ bool ContinuousLedgerTiming::haveConsensus (
bool forReal, // deciding whether to stop consensus process bool forReal, // deciding whether to stop consensus process
bool& failed) // we can't reach a consensus 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") % WriteLog (lsTRACE, LedgerTiming) <<
currentProposers % previousProposers % currentAgree % currentFinished % currentAgreeTime % previousAgreeTime % "CLC::haveConsensus: prop=" << currentProposers <<
(forReal ? "" : "X")); "/" << previousProposers <<
" agree=" << currentAgree << " validated=" << currentFinished <<
" time=" << currentAgreeTime << "/" << previousAgreeTime <<
(forReal ? "" : "X");
if (currentAgreeTime <= LEDGER_MIN_CONSENSUS) if (currentAgreeTime <= LEDGER_MIN_CONSENSUS)
return false; 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 // Less than 3/4 of the last ledger's proposers are present, we may need more time
if (currentAgreeTime < (previousAgreeTime + LEDGER_MIN_CONSENSUS)) 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; 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 80% of the nodes on your UNL have moved on, you should declare consensus
if (((currentFinished * 100) / (currentProposers + 1)) > 80) 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; failed = true;
return true; return true;
} }

View File

@@ -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 ()) 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 ()) if (alTx.isApplied ())
jvObj["meta"] = alTx.getMeta ()->getJson (0); jvObj["meta"] = alTx.getMeta ()->getJson (0);
@@ -2600,7 +2603,8 @@ void NetworkOPsImp::subAccount (InfoSub::ref isrListener,
// For the connection, monitor each account. // For the connection, monitor each account.
BOOST_FOREACH (const RippleAddress & naAccountID, vnaAccountIDs) 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); isrListener->insertSubAccountInfo (naAccountID, uLedgerIndex);
} }
@@ -2832,7 +2836,9 @@ InfoSub::pointer NetworkOPsImp::addRpcSub (const std::string& strUrl, InfoSub::r
} }
#ifndef USE_NEW_BOOK_PAGE #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. // 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) 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 { // 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); const uint256 uBookEnd = Ledger::getQualityNext (uBookBase);
uint256 uTipIndex = uBookBase; uint256 uTipIndex = uBookBase;
m_journal.trace << boost::str (boost::format ("getBookPage: uTakerPaysCurrencyID=%s uTakerPaysIssuerID=%s") % STAmount::createHumanCurrency (uTakerPaysCurrencyID) % RippleAddress::createHumanAccountID (uTakerPaysIssuerID)); if (m_journal.trace)
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 << "getBookPage:" <<
m_journal.trace << boost::str (boost::format ("getBookPage: uBookEnd=%s") % uBookEnd); " uTakerPaysCurrencyID=" <<
m_journal.trace << boost::str (boost::format ("getBookPage: uTipIndex=%s") % uTipIndex); 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); LedgerEntrySet lesActive (lpLedger, tapNONE, true);
@@ -2888,8 +2905,8 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
lesActive.dirFirst (uTipIndex, sleOfferDir, uBookEntry, uOfferIndex); lesActive.dirFirst (uTipIndex, sleOfferDir, uBookEntry, uOfferIndex);
m_journal.trace << boost::str (boost::format ("getBookPage: uTipIndex=%s") % uTipIndex); m_journal.trace << "getBookPage: uTipIndex=" << uTipIndex;
m_journal.trace << boost::str (boost::format ("getBookPage: uOfferIndex=%s") % uOfferIndex); 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"]); std::min (saTakerPays, STAmount::multiply (saTakerGetsFunded, saDirRate, saTakerPays)).setJson (jvOffer["taker_pays_funded"]);
} }
STAmount saOwnerPays = (QUALITY_ONE == uOfferRate) STAmount saOwnerPays = (QUALITY_ONE == uOfferRate)
? saTakerGetsFunded ? saTakerGetsFunded
: std::min (saOwnerFunds, STAmount::multiply (saTakerGetsFunded, STAmount (CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9))); : std::min (
saOwnerFunds,
STAmount::multiply (
saTakerGetsFunded,
STAmount (CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9)));
umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays; umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
@@ -2995,7 +3016,7 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
else else
{ {
m_journal.warning << "Missing offer"; m_journal.warning << "Missing offer";
} }
if (!lesActive.dirNext (uTipIndex, sleOfferDir, uBookEntry, uOfferIndex)) if (!lesActive.dirNext (uTipIndex, sleOfferDir, uBookEntry, uOfferIndex))
{ {
@@ -3003,7 +3024,7 @@ void NetworkOPsImp::getBookPage (Ledger::pointer lpLedger, const uint160& uTaker
} }
else else
{ {
m_journal.trace << boost::str (boost::format ("getBookPage: uOfferIndex=%s") % uOfferIndex); m_journal.trace << "getBookPage: uOfferIndex=" << uOfferIndex;
} }
} }
} }

View File

@@ -129,10 +129,10 @@ TER PathState::pushImply (
const Node& pnPrv = vpnNodes.back (); const Node& pnPrv = vpnNodes.back ();
TER terResult = tesSUCCESS; TER terResult = tesSUCCESS;
WriteLog (lsTRACE, RippleCalc) << "pushImply> " WriteLog (lsTRACE, RippleCalc) << "pushImply>" <<
<< RippleAddress::createHumanAccountID (uAccountID) " " << RippleAddress::createHumanAccountID (uAccountID) <<
<< " " << STAmount::createHumanCurrency (uCurrencyID) " " << STAmount::createHumanCurrency (uCurrencyID) <<
<< " " << RippleAddress::createHumanAccountID (uIssuerID); " " << RippleAddress::createHumanAccountID (uIssuerID);
if (pnPrv.uCurrencyID != uCurrencyID) if (pnPrv.uCurrencyID != uCurrencyID)
{ {
@@ -164,7 +164,7 @@ TER PathState::pushImply (
uIssuerID); uIssuerID);
} }
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("pushImply< : %s") % transToken (terResult)); WriteLog (lsTRACE, RippleCalc) << "pushImply< : " << transToken (terResult);
return terResult; return terResult;
} }
@@ -190,11 +190,11 @@ TER PathState::pushNode (
const bool bIssuer = is_bit_set (iType, STPathElement::typeIssuer); const bool bIssuer = is_bit_set (iType, STPathElement::typeIssuer);
TER terResult = tesSUCCESS; TER terResult = tesSUCCESS;
WriteLog (lsTRACE, RippleCalc) << "pushNode> " WriteLog (lsTRACE, RippleCalc) << "pushNode> " <<
<< iType iType <<
<< ": " << (bAccount ? RippleAddress::createHumanAccountID (uAccountID) : "-") ": " << (bAccount ? RippleAddress::createHumanAccountID (uAccountID) : "-") <<
<< " " << (bCurrency ? STAmount::createHumanCurrency (uCurrencyID) : "-") " " << (bCurrency ? STAmount::createHumanCurrency (uCurrencyID) : "-") <<
<< "/" << (bIssuer ? RippleAddress::createHumanAccountID (uIssuerID) : "-"); "/" << (bIssuer ? RippleAddress::createHumanAccountID (uIssuerID) : "-");
pnCur.uFlags = iType; pnCur.uFlags = iType;
pnCur.uCurrencyID = bCurrency ? uCurrencyID : pnPrv.uCurrencyID; pnCur.uCurrencyID = bCurrency ? uCurrencyID : pnPrv.uCurrencyID;
@@ -322,9 +322,10 @@ TER PathState::pushNode (
if (saOwed <= zero if (saOwed <= zero
&& -saOwed >= (saLimit = lesEntries.rippleLimit (pnCur.uAccountID, pnBck.uAccountID, pnCur.uCurrencyID))) && -saOwed >= (saLimit = lesEntries.rippleLimit (pnCur.uAccountID, pnBck.uAccountID, pnCur.uCurrencyID)))
{ {
WriteLog (lsWARNING, RippleCalc) << boost::str (boost::format ("pushNode: dry: saOwed=%s saLimit=%s") WriteLog (lsWARNING, RippleCalc) <<
% saOwed "pushNode: dry:" <<
% saLimit); " saOwed=" << saOwed <<
" saLimit=" << saLimit;
terResult = tecPATH_DRY; terResult = tecPATH_DRY;
} }
@@ -366,9 +367,9 @@ TER PathState::pushNode (
// Insert intermediary issuer account if needed. // Insert intermediary issuer account if needed.
terResult = pushImply ( terResult = pushImply (
ACCOUNT_XRP, // Rippling, but offers don't have an account. ACCOUNT_XRP, // Rippling, but offers don't have an account.
pnPrv.uCurrencyID, pnPrv.uCurrencyID,
pnPrv.uIssuerID); pnPrv.uIssuerID);
} }
if (tesSUCCESS == terResult) 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; return terResult;
} }
@@ -401,7 +402,7 @@ void PathState::setExpanded (
const uint160 uOutIssuerID = saOutReq.getIssuer (); const uint160 uOutIssuerID = saOutReq.getIssuer ();
const uint160 uSenderIssuerID = !!uMaxCurrencyID ? uSenderID : ACCOUNT_XRP; // Sender is always issuer for non-XRP. 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 (); lesEntries = lesSource.duplicate ();
@@ -424,10 +425,10 @@ void PathState::setExpanded (
uMaxCurrencyID, // Max specifies the currency. uMaxCurrencyID, // Max specifies the currency.
uSenderIssuerID); uSenderIssuerID);
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: pushed: account=%s currency=%s issuer=%s") WriteLog (lsDEBUG, RippleCalc) << "setExpanded: pushed:" <<
% RippleAddress::createHumanAccountID (uSenderID) " account=" << RippleAddress::createHumanAccountID (uSenderID) <<
% STAmount::createHumanCurrency (uMaxCurrencyID) " currency=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
% RippleAddress::createHumanAccountID (uSenderIssuerID)); " issuer=" << RippleAddress::createHumanAccountID (uSenderIssuerID);
if (tesSUCCESS == terStatus if (tesSUCCESS == terStatus
&& uMaxIssuerID != uSenderIssuerID) // Issuer was not same as sender. && uMaxIssuerID != uSenderIssuerID) // Issuer was not same as sender.
@@ -447,29 +448,30 @@ void PathState::setExpanded (
: uOutIssuerID // Use implied node. : uOutIssuerID // Use implied node.
: ACCOUNT_XRP; : ACCOUNT_XRP;
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: implied check: uMaxIssuerID=%s uSenderIssuerID=%s uNxtCurrencyID=%s uNxtAccountID=%s") WriteLog (lsDEBUG, RippleCalc) << "setExpanded: implied check:" <<
% RippleAddress::createHumanAccountID (uMaxIssuerID) " uMaxIssuerID=" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
% RippleAddress::createHumanAccountID (uSenderIssuerID) " uSenderIssuerID=" << RippleAddress::createHumanAccountID (uSenderIssuerID) <<
% STAmount::createHumanCurrency (uNxtCurrencyID) " uNxtCurrencyID=" << STAmount::createHumanCurrency (uNxtCurrencyID) <<
% RippleAddress::createHumanAccountID (uNxtAccountID)); " uNxtAccountID=" << RippleAddress::createHumanAccountID (uNxtAccountID);
// Can't just use push implied, because it can't compensate for next account. // 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. if (!uNxtCurrencyID // Next is XRP, offer next. Must go through issuer.
|| uMaxCurrencyID != uNxtCurrencyID // Next is different currency, offer next... || uMaxCurrencyID != uNxtCurrencyID // Next is different currency, offer next...
|| uMaxIssuerID != uNxtAccountID) // Next is not implied issuer || uMaxIssuerID != uNxtAccountID) // Next is not implied issuer
{ {
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: sender implied: account=%s currency=%s issuer=%s") WriteLog (lsDEBUG, RippleCalc) << "setExpanded: sender implied:" <<
% RippleAddress::createHumanAccountID (uMaxIssuerID) " account=" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
% STAmount::createHumanCurrency (uMaxCurrencyID) " currency=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
% RippleAddress::createHumanAccountID (uMaxIssuerID)); " issuer=" << RippleAddress::createHumanAccountID (uMaxIssuerID);
// Add account implied by SendMax. // Add account implied by SendMax.
terStatus = pushNode ( terStatus = pushNode (
!!uMaxCurrencyID !!uMaxCurrencyID
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
: STPathElement::typeAccount | STPathElement::typeCurrency, : STPathElement::typeAccount | STPathElement::typeCurrency,
uMaxIssuerID, uMaxIssuerID,
uMaxCurrencyID, uMaxCurrencyID,
uMaxIssuerID); uMaxIssuerID);
} }
} }
@@ -477,8 +479,10 @@ void PathState::setExpanded (
{ {
if (tesSUCCESS == terStatus) if (tesSUCCESS == terStatus)
{ {
WriteLog (lsTRACE, RippleCalc) << boost::str (boost::format ("setExpanded: element in path:")); WriteLog (lsTRACE, RippleCalc) << "setExpanded: element in path";
terStatus = pushNode (speElement.getNodeType (), speElement.getAccountID (), speElement.getCurrency (), speElement.getIssuerID ()); terStatus = pushNode (
speElement.getNodeType (), speElement.getAccountID (),
speElement.getCurrency (), speElement.getIssuerID ());
} }
} }
@@ -491,17 +495,18 @@ void PathState::setExpanded (
|| pnPrv.uAccountID != uOutIssuerID)) // Need the implied issuer. || pnPrv.uAccountID != uOutIssuerID)) // Need the implied issuer.
{ {
// Add implied account. // Add implied account.
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: receiver implied: account=%s currency=%s issuer=%s") WriteLog (lsDEBUG, RippleCalc) << "setExpanded: receiver implied:" <<
% RippleAddress::createHumanAccountID (uOutIssuerID) " account=" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
% STAmount::createHumanCurrency (uOutCurrencyID) " currency=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
% RippleAddress::createHumanAccountID (uOutIssuerID)); " issuer=" << RippleAddress::createHumanAccountID (uOutIssuerID);
terStatus = pushNode ( terStatus = pushNode (
!!uOutCurrencyID !!uOutCurrencyID
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
: STPathElement::typeAccount | STPathElement::typeCurrency, : STPathElement::typeAccount | STPathElement::typeCurrency,
uOutIssuerID, uOutIssuerID,
uOutCurrencyID, uOutCurrencyID,
uOutIssuerID); uOutIssuerID);
} }
if (tesSUCCESS == terStatus) if (tesSUCCESS == terStatus)
@@ -510,12 +515,12 @@ void PathState::setExpanded (
// Last node is always an account. // Last node is always an account.
terStatus = pushNode ( terStatus = pushNode (
!!uOutCurrencyID !!uOutCurrencyID
? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
: STPathElement::typeAccount | STPathElement::typeCurrency, : STPathElement::typeAccount | STPathElement::typeCurrency,
uReceiverID, // Receive to output uReceiverID, // Receive to output
uOutCurrencyID, // Desired currency uOutCurrencyID, // Desired currency
uReceiverID); uReceiverID);
} }
if (tesSUCCESS == terStatus) 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) if (!umForward.insert (std::make_pair (std::make_tuple (pnCur.uAccountID, pnCur.uCurrencyID, pnCur.uIssuerID), uNode)).second)
{ {
// Failed to insert. Have a loop. // Failed to insert. Have a loop.
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: loop detected: %s") WriteLog (lsDEBUG, RippleCalc) <<
% getJson ()); "setExpanded: loop detected: " << getJson ();
terStatus = temBAD_PATH_LOOP; terStatus = temBAD_PATH_LOOP;
} }
} }
} }
WriteLog (lsDEBUG, RippleCalc) << boost::str (boost::format ("setExpanded: in=%s/%s out=%s/%s %s") WriteLog (lsDEBUG, RippleCalc) << "setExpanded:" <<
% STAmount::createHumanCurrency (uMaxCurrencyID) " in=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
% RippleAddress::createHumanAccountID (uMaxIssuerID) "/" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
% STAmount::createHumanCurrency (uOutCurrencyID) " out=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
% RippleAddress::createHumanAccountID (uOutIssuerID) "/" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
% getJson ()); ": " << getJson ();
} }
// Set to a canonical path. // 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") WriteLog (lsDEBUG, RippleCalc) << "setCanonical:" <<
% STAmount::createHumanCurrency (uMaxCurrencyID) " in=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
% RippleAddress::createHumanAccountID (uMaxIssuerID) "/" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
% STAmount::createHumanCurrency (uOutCurrencyID) " out=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
% RippleAddress::createHumanAccountID (uOutIssuerID) "/" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
% getJson ()); ": " << getJson ();
} }
/** Check if a sequence of three accounts violates the no ripple constrains /** 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); jvPathState["out_pass"] = saOutPass.getJson (0);
if (uQuality) if (uQuality)
jvPathState["uQuality"] = boost::str (boost::format ("%d") % uQuality); jvPathState["uQuality"] = boost::lexical_cast<std::string>(uQuality);
return jvPathState; return jvPathState;
} }

View File

@@ -128,13 +128,12 @@ bool Pathfinder::findPaths (int iLevel, const unsigned int iMaxPaths, STPathSet&
{ // pathsOut contains only non-default paths without source or destiation { // 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 // 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") WriteLog (lsTRACE, Pathfinder) << "findPaths>"
% RippleAddress::createHumanAccountID (mSrcAccountID) " mSrcAccountID=" << RippleAddress::createHumanAccountID (mSrcAccountID) <<
% RippleAddress::createHumanAccountID (mDstAccountID) " mDstAccountID=" << RippleAddress::createHumanAccountID (mDstAccountID) <<
% mDstAmount.getFullText () " mDstAmount=" << mDstAmount.getFullText () <<
% STAmount::createHumanCurrency (mSrcCurrencyID) " mSrcCurrencyID=" << STAmount::createHumanCurrency (mSrcCurrencyID) <<
% RippleAddress::createHumanAccountID (mSrcIssuerID) " mSrcIssuerID=" << RippleAddress::createHumanAccountID (mSrcIssuerID);
);
if (!mLedger) if (!mLedger)
{ {
@@ -319,28 +318,27 @@ STPathSet Pathfinder::filterPaths(int iMaxPaths, STPath& extraPath)
if (tesSUCCESS != terResult) if (tesSUCCESS != terResult)
{ {
WriteLog (lsDEBUG, Pathfinder) WriteLog (lsDEBUG, Pathfinder) <<
<< boost::str (boost::format ("findPaths: dropping: %s: %s") "findPaths: dropping: " << transToken (terResult) <<
% transToken (terResult) ": " << spCurrent.getJson (0);
% spCurrent.getJson (0));
} }
else if (saDstAmountAct < saMinDstAmount) else if (saDstAmountAct < saMinDstAmount)
{ {
WriteLog (lsDEBUG, Pathfinder) WriteLog (lsDEBUG, Pathfinder) <<
<< boost::str (boost::format ("findPaths: dropping: outputs %s: %s") "findPaths: dropping: outputs " << saDstAmountAct <<
% saDstAmountAct ": %s" << spCurrent.getJson (0);
% spCurrent.getJson (0));
} }
else else
{ {
std::uint64_t uQuality = STAmount::getRate (saDstAmountAct, saMaxAmountAct); std::uint64_t uQuality (
STAmount::getRate (saDstAmountAct, saMaxAmountAct));
WriteLog (lsDEBUG, Pathfinder) WriteLog (lsDEBUG, Pathfinder) <<
<< boost::str (boost::format ("findPaths: quality: %d: %s") "findPaths: quality: " << uQuality <<
% uQuality ": " << spCurrent.getJson (0);
% 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 // found an extra path that can move the whole amount
extraPath = mCompletePaths[lqt.get<3>()]; 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 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) if (remaining > zero)
{ {
WriteLog (lsINFO, Pathfinder) << "Paths could not send " << remaining << " of " << mDstAmount; WriteLog (lsINFO, Pathfinder) <<
"Paths could not send " << remaining << " of " << mDstAmount;
} }
else else
{ {
WriteLog (lsDEBUG, Pathfinder) << boost::str (boost::format ("findPaths: RESULTS: %s") % spsDst.getJson (0)); WriteLog (lsDEBUG, Pathfinder) <<
"findPaths: RESULTS: " << spsDst.getJson (0);
} }
} }
else 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; return spsDst;

View File

@@ -105,10 +105,7 @@ bool STAmount::bSetJson (const Json::Value& jvSource)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
WriteLog (lsINFO, STAmount) WriteLog (lsINFO, STAmount) << "bSetJson(): caught: " << e.what ();
<< boost::str (boost::format ("bSetJson(): caught: %s")
% e.what ());
return false; return false;
} }
} }
@@ -120,11 +117,11 @@ STAmount::STAmount (SField::ref n, const Json::Value& v)
if (v.isObject ()) if (v.isObject ())
{ {
WriteLog (lsTRACE, STAmount) WriteLog (lsTRACE, STAmount) <<
<< boost::str (boost::format ("value='%s', currency='%s', issuer='%s'") "value='" << v["value"].asString () <<
% v["value"].asString () "', currency='" << v["currency"].asString () <<
% v["currency"].asString () "', issuer='" << v["issuer"].asString () <<
% v["issuer"].asString ()); "')";
value = v["value"]; value = v["value"];
currency = v["currency"]; 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 STAmount::createHumanCurrency (const uint160& uCurrency)
{ {
std::string sCurrency; static uint160 const sFiatBits("FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000");
static uint160 sFiatBits("FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000");
if (uCurrency.isZero ()) if (uCurrency.isZero ())
{ {
return SYSTEM_CURRENCY_CODE; return SYSTEM_CURRENCY_CODE;
} }
else if (CURRENCY_ONE == uCurrency)
if (CURRENCY_ONE == uCurrency)
{ {
return "1"; return "1";
} }
else if (CURRENCY_BAD == uCurrency)
if (CURRENCY_BAD == uCurrency)
{ {
return uCurrency.ToString (); return uCurrency.ToString ();
} }
else if ((uCurrency & sFiatBits).isZero ())
if ((uCurrency & sFiatBits).isZero ())
{ {
Serializer s (160 / 8); Serializer s (160 / 8);
s.add160 (uCurrency); s.add160 (uCurrency);
SerializerIterator sit (s); SerializerIterator sit (s);
Blob vucZeros = sit.getRaw (96 / 8); Blob const vucZeros (sit.getRaw (96 / 8));
Blob vucIso = sit.getRaw (24 / 8); Blob const vucIso (sit.getRaw (24 / 8));
Blob vucVersion = sit.getRaw (16 / 8); Blob const vucVersion (sit.getRaw (16 / 8));
Blob vucReserved = sit.getRaw (24 / 8); Blob const vucReserved (sit.getRaw (24 / 8));
bool bIso = isZeroFilled (vucZeros.begin (), vucZeros.size ()) // Leading zeros auto is_zero_filled = [](Blob const& blob)
&& isZeroFilled (vucVersion.begin (), vucVersion.size ()) // Zero version {
&& isZeroFilled (vucReserved.begin (), vucReserved.size ()); // Reserved is zero. 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) if (bIso)
{ return std::string (vucIso.begin (), vucIso.end ());
sCurrency.assign (vucIso.begin (), vucIso.end ());
} return uCurrency.ToString ();
else
{
sCurrency = uCurrency.ToString ();
}
} }
else
sCurrency = uCurrency.GetHex ();
return sCurrency; return uCurrency.GetHex ();
} }
bool STAmount::setValue (const std::string& sAmount) bool STAmount::setValue (const std::string& sAmount)
@@ -1081,30 +1085,22 @@ STAmount STAmount::deserialize (SerializerIterator& it)
std::string STAmount::getFullText () const std::string STAmount::getFullText () const
{ {
static const boost::format nativeFormat ("%s/" SYSTEM_CURRENCY_CODE); std::string ret;
static const boost::format noIssuer ("%s/%s/0");
static const boost::format issuerOne ("%s/%s/1");
static const boost::format normal ("%s/%s/%s");
if (mIsNative) ret.reserve(64);
ret = getText () + "/" + getHumanCurrency ();
if (!mIsNative)
{ {
return str (boost::format (nativeFormat) % getText ()); if (!mIssuer)
} ret += "/0";
else if (!mIssuer) else if (mIssuer == ACCOUNT_ONE)
{ ret += "/1";
return str (boost::format (noIssuer) % getText () % getHumanCurrency ()); else
} ret += RippleAddress::createHumanAccountID (mIssuer);
else if (mIssuer == ACCOUNT_ONE)
{
return str (boost::format (issuerOne) % getText () % getHumanCurrency ());
}
else
{
return str (boost::format (normal)
% getText ()
% getHumanCurrency ()
% RippleAddress::createHumanAccountID (mIssuer));
} }
return ret;
} }
STAmount STAmount::getRound () const STAmount STAmount::getRound () const

View File

@@ -780,16 +780,6 @@ public:
static void canonicalizeRound (bool isNative, std::uint64_t& value, int& offset, bool roundUp); 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: private:
uint160 mCurrency; // Compared by ==. Always update mIsNative. uint160 mCurrency; // Compared by ==. Always update mIsNative.
uint160 mIssuer; // Not compared by ==. 0 for XRP. uint160 mIssuer; // Not compared by ==. 0 for XRP.