Rename RippleAsset to Issue and RippleBook to Book:

* Split STAmount out of SerializedTypes.h
* New concept of "Issue consistency": when either both or neither of its
  currency and account are XRP.
* Stop checking for consistency of Issue in its constructor.
* Clarification of mIsNative logic in STAmount.
* Usual cleanups.
This commit is contained in:
Tom Ritchford
2014-07-03 18:20:47 -04:00
committed by Nik Bougalis
parent a96dee85d2
commit 206efbf30d
42 changed files with 1611 additions and 1490 deletions

View File

@@ -191,7 +191,7 @@ public:
if (sig == 0)
return os << "0";
if (sig < 0)
os << "-";
if (m_integral)
@@ -204,10 +204,11 @@ public:
};
//------------------------------------------------------------------------------
// TODO(tom): remove this typedef and have exactly one name for STAmount.
typedef STAmount Amount;
}
}
} // core
} // ripple
#endif

View File

@@ -21,8 +21,7 @@
#define RIPPLE_CORE_TYPES_H_INCLUDED
#include <ripple/module/app/ledger/LedgerEntrySet.h>
#include <ripple/types/api/RippleAssets.h>
#include <ripple/types/api/base_uint.h>
#include <ripple/types/api/Book.h>
#include <chrono>
#include <cstdint>
@@ -33,14 +32,6 @@ namespace core {
/** A mutable view that overlays an immutable ledger to track changes. */
typedef LedgerEntrySet LedgerView;
/** Asset identifiers. */
typedef RippleAsset Asset;
typedef RippleAssetRef AssetRef;
/** Uniquely identifies an order book. */
typedef RippleBook Book;
typedef RippleBookRef BookRef;
/** A clock representing network time.
This measures seconds since the Ripple epoch as seen
by the ledger close clock.

View File

@@ -26,8 +26,8 @@ BookTip::BookTip (LedgerView& view, BookRef book)
: m_view (view)
, m_valid (false)
, m_book (Ledger::getBookBase (
book.in.currency, book.in.issuer,
book.out.currency, book.out.issuer))
book.in.currency, book.in.account,
book.out.currency, book.out.account))
, m_end (Ledger::getQualityNext (m_book))
{
}
@@ -65,7 +65,7 @@ BookTip::step ()
m_book = page;
// The quality immediately before the next quality
--m_book;
--m_book;
break;
}

View File

@@ -46,11 +46,7 @@ Taker::remaining_offer () const
{
// If the taker is done, then there's no offer to place.
if (done ())
{
return Amounts (
Amount (m_amount.in.getCurrency (), m_amount.in.getIssuer ()),
Amount (m_amount.out.getCurrency (), m_amount.out.getIssuer ()));
}
return Amounts (m_amount.in.zeroed(), m_amount.out.zeroed());
// Avoid math altogether if we didn't cross.
if (m_amount == m_remain)
@@ -272,7 +268,7 @@ Taker::cross (Offer const& leg1, Offer const& leg2)
Amounts flow1 (flow (amount1, leg1, m_account));
amount2 = leg2.quality().ceil_in (amount2, flow1.out);
Amounts flow2 (flow (amount2, leg2, m_account));
m_remain.out -= amount2.out;

View File

@@ -32,7 +32,7 @@ public:
Amount
static raw (std::uint64_t mantissa, int exponent)
{
return Amount (Currency(3), Account(3), mantissa, exponent);
return Amount ({Currency(3), Account(3)}, mantissa, exponent);
}
template <class Integer>
@@ -241,9 +241,9 @@ public:
{
testcase ("comparisons");
Amount const amount1 (noCurrency (), noAccount (), 231);
Amount const amount2 (noCurrency (), noAccount (), 462);
Amount const amount3 (noCurrency (), noAccount (), 924);
Amount const amount1 (noIssue(), 231);
Amount const amount2 (noIssue(), 462);
Amount const amount3 (noIssue(), 924);
Quality const q11 (core::Amounts (amount1, amount1));
Quality const q12 (core::Amounts (amount1, amount2));
@@ -264,9 +264,9 @@ public:
{
testcase ("composition");
Amount const amount1 (noCurrency (), noAccount (), 231);
Amount const amount2 (noCurrency (), noAccount (), 462);
Amount const amount3 (noCurrency (), noAccount (), 924);
Amount const amount1 (noIssue(), 231);
Amount const amount2 (noIssue(), 462);
Amount const amount3 (noIssue(), 924);
Quality const q11 (core::Amounts (amount1, amount1));
Quality const q12 (core::Amounts (amount1, amount2));
@@ -289,8 +289,8 @@ public:
testcase ("operations");
Quality const q11 (core::Amounts (
Amount (noCurrency (), noAccount (), 731),
Amount (noCurrency (), noAccount (), 731)));
Amount (noIssue(), 731),
Amount (noIssue(), 731)));
Quality qa (q11);
Quality qb (q11);

View File

@@ -1114,7 +1114,7 @@ STAmount LedgerEntrySet::rippleOwed (
}
else
{
saBalance.clear (currency, uToAccountID);
saBalance.clear ({currency, uToAccountID});
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleOwed:" <<
" No credit line between " <<
@@ -1146,7 +1146,7 @@ STAmount LedgerEntrySet::rippleLimit (
}
else
{
saLimit.clear (currency, uToAccountID);
saLimit.clear ({currency, uToAccountID});
}
return saLimit;
@@ -1237,7 +1237,7 @@ STAmount LedgerEntrySet::rippleHolds (
if (!sleRippleState)
{
saBalance.clear (currency, issuer);
saBalance.clear ({currency, issuer});
}
else if (account > issuer)
{
@@ -1351,12 +1351,10 @@ STAmount LedgerEntrySet::rippleTransferFee (
{
// NIKB use STAmount::saFromRate
STAmount saTransitRate (
noCurrency(), noAccount(),
static_cast<std::uint64_t> (uTransitRate), -9);
noIssue(), static_cast<std::uint64_t> (uTransitRate), -9);
STAmount saTransferTotal = STAmount::multiply (
saAmount, saTransitRate,
saAmount.getCurrency (), saAmount.getIssuer ());
saAmount, saTransitRate, saAmount.issue ());
STAmount saTransferFee = saTransferTotal - saAmount;
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleTransferFee:" <<
@@ -1366,7 +1364,7 @@ STAmount LedgerEntrySet::rippleTransferFee (
}
}
return STAmount (saAmount.getCurrency (), saAmount.getIssuer ());
return saAmount.zeroed();
}
TER LedgerEntrySet::trustCreate (
@@ -1413,42 +1411,42 @@ TER LedgerEntrySet::trustCreate (
if (tesSUCCESS == terResult)
{
const bool bSetDst = saLimit.getIssuer () == uDstAccountID;
const bool bSetHigh = bSrcHigh ^ bSetDst;
const bool bSetDst = saLimit.getIssuer () == uDstAccountID;
const bool bSetHigh = bSrcHigh ^ bSetDst;
// Remember deletion hints.
sleRippleState->setFieldU64 (sfLowNode, uLowNode);
sleRippleState->setFieldU64 (sfHighNode, uHighNode);
sleRippleState->setFieldAmount (
!bSetHigh ? sfLowLimit : sfHighLimit, saLimit);
bSetHigh ? sfHighLimit : sfLowLimit, saLimit);
sleRippleState->setFieldAmount (
bSetHigh ? sfLowLimit : sfHighLimit,
STAmount (saBalance.getCurrency (),
bSetDst ? uSrcAccountID : uDstAccountID));
STAmount ({saBalance.getCurrency (),
bSetDst ? uSrcAccountID : uDstAccountID}));
if (uQualityIn)
sleRippleState->setFieldU32 (
!bSetHigh ? sfLowQualityIn : sfHighQualityIn, uQualityIn);
bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn);
if (uQualityOut)
sleRippleState->setFieldU32 (
!bSetHigh ? sfLowQualityOut : sfHighQualityOut, uQualityOut);
bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut);
std::uint32_t uFlags = !bSetHigh ? lsfLowReserve : lsfHighReserve;
std::uint32_t uFlags = bSetHigh ? lsfHighReserve : lsfLowReserve;
if (bAuth)
{
uFlags |= (!bSetHigh ? lsfLowAuth : lsfHighAuth);
uFlags |= (bSetHigh ? lsfHighAuth : lsfLowAuth);
}
if (bNoRipple)
{
uFlags |= (!bSetHigh ? lsfLowNoRipple : lsfHighNoRipple);
uFlags |= (bSetHigh ? lsfHighNoRipple : lsfLowNoRipple);
}
sleRippleState->setFieldU32 (sfFlags, uFlags);
ownerCountAdjust (
!bSetDst ? uSrcAccountID : uDstAccountID, 1, sleAccount);
bSetDst ? uDstAccountID : uSrcAccountID, 1, sleAccount);
// ONLY: Create ripple balance.
sleRippleState->setFieldAmount (
@@ -1528,8 +1526,8 @@ TER LedgerEntrySet::rippleCredit (
if (!sleRippleState)
{
STAmount saReceiverLimit = STAmount (currency, uReceiverID);
STAmount saBalance = saAmount;
STAmount saReceiverLimit({currency, uReceiverID});
STAmount saBalance = saAmount;
saBalance.setIssuer (noAccount());

View File

@@ -61,9 +61,9 @@ void OrderBookDB::setup (Ledger::ref ledger)
static void updateHelper (SLE::ref entry,
ripple::unordered_set< uint256 >& seen,
ripple::unordered_map< RippleAsset, std::vector<OrderBook::pointer> >& destMap,
ripple::unordered_map< RippleAsset, std::vector<OrderBook::pointer> >& sourceMap,
ripple::unordered_set< RippleAsset >& XRPBooks,
ripple::unordered_map< Issue, std::vector<OrderBook::pointer> >& destMap,
ripple::unordered_map< Issue, std::vector<OrderBook::pointer> >& sourceMap,
ripple::unordered_set< Issue >& XRPBooks,
int& books)
{
if ((entry->getType () == ltDIR_NODE) && (entry->isFieldPresent (sfExchangeRate)) &&
@@ -85,10 +85,10 @@ static void updateHelper (SLE::ref entry,
OrderBook::pointer book = std::make_shared<OrderBook> (std::cref (index),
std::cref (ci), std::cref (co), std::cref (ii), std::cref (io));
sourceMap[RippleAssetRef (ci, ii)].push_back (book);
destMap[RippleAssetRef (co, io)].push_back (book);
sourceMap[IssueRef (ci, ii)].push_back (book);
destMap[IssueRef (co, io)].push_back (book);
if (co.isZero())
XRPBooks.insert(RippleAssetRef (ci, ii));
XRPBooks.insert(IssueRef (ci, ii));
++books;
}
}
@@ -97,9 +97,9 @@ static void updateHelper (SLE::ref entry,
void OrderBookDB::update (Ledger::pointer ledger)
{
ripple::unordered_set< uint256 > seen;
ripple::unordered_map< RippleAsset, std::vector<OrderBook::pointer> > destMap;
ripple::unordered_map< RippleAsset, std::vector<OrderBook::pointer> > sourceMap;
ripple::unordered_set< RippleAsset > XRPBooks;
ripple::unordered_map< Issue, std::vector<OrderBook::pointer> > destMap;
ripple::unordered_map< Issue, std::vector<OrderBook::pointer> > sourceMap;
ripple::unordered_set< Issue > XRPBooks;
WriteLog (lsDEBUG, OrderBookDB) << "OrderBookDB::update>";
@@ -139,7 +139,7 @@ void OrderBookDB::addOrderBook(Currency const& ci, Currency const& co,
if (toXRP)
{ // We don't want to search through all the to-XRP or from-XRP order books!
for (auto ob : mSourceMap[RippleAssetRef(ci, ii)])
for (auto ob : mSourceMap[{ci, ii}])
{
if (ob->getCurrencyOut().isZero ()) // also to XRP
return;
@@ -147,7 +147,7 @@ void OrderBookDB::addOrderBook(Currency const& ci, Currency const& co,
}
else
{
for (auto ob : mDestMap[RippleAssetRef(co, io)])
for (auto ob : mDestMap[{co, io}])
{
if ((ob->getCurrencyIn() == ci) && (ob->getIssuerIn() == ii))
return;
@@ -157,10 +157,10 @@ void OrderBookDB::addOrderBook(Currency const& ci, Currency const& co,
uint256 index = Ledger::getBookBase(ci, ii, co, io);
auto book = std::make_shared<OrderBook> (index, ci, co, ii, io);
mSourceMap[RippleAssetRef (ci, ii)].push_back (book);
mDestMap[RippleAssetRef (co, io)].push_back (book);
mSourceMap[{ci, ii}].push_back (book);
mDestMap[{co, io}].push_back (book);
if (toXRP)
mXRPBooks.insert(RippleAssetRef (ci, ii));
mXRPBooks.insert({ci, ii});
}
// return list of all orderbooks that want this issuerID and currencyID
@@ -168,8 +168,7 @@ void OrderBookDB::getBooksByTakerPays (Account const& issuerID, Currency const&
std::vector<OrderBook::pointer>& bookRet)
{
ScopedLockType sl (mLock);
auto it = mSourceMap.find (RippleAssetRef (currencyID, issuerID));
auto it = mSourceMap.find ({currencyID, issuerID});
if (it != mSourceMap.end ())
bookRet = it->second;
else
@@ -180,7 +179,7 @@ bool OrderBookDB::isBookToXRP(Account const& issuerID, Currency const& currencyI
{
ScopedLockType sl (mLock);
return mXRPBooks.count(RippleAssetRef(currencyID, issuerID)) > 0;
return mXRPBooks.count({currencyID, issuerID}) > 0;
}
// return list of all orderbooks that give this issuerID and currencyID
@@ -188,7 +187,7 @@ void OrderBookDB::getBooksByTakerGets (Account const& issuerID, Currency const&
std::vector<OrderBook::pointer>& bookRet)
{
ScopedLockType sl (mLock);
auto it = mDestMap.find (RippleAssetRef (currencyID, issuerID));
auto it = mDestMap.find ({currencyID, issuerID});
if (it != mDestMap.end ())
bookRet = it->second;
@@ -206,9 +205,8 @@ BookListeners::pointer OrderBookDB::makeBookListeners (Currency const& currencyP
{
ret = std::make_shared<BookListeners> ();
mListeners [RippleBookRef (
RippleAssetRef (currencyPays, issuerPays),
RippleAssetRef (currencyGets, issuerGets))] = ret;
mListeners [BookRef ({currencyPays, issuerPays},
{currencyGets, issuerGets})] = ret;
assert (getBookListeners (currencyPays, currencyGets, issuerPays, issuerGets) == ret);
}
@@ -221,9 +219,8 @@ BookListeners::pointer OrderBookDB::getBookListeners (Currency const& currencyPa
BookListeners::pointer ret;
ScopedLockType sl (mLock);
auto it0 (mListeners.find (RippleBookRef (
RippleAssetRef (currencyPays, issuerPays),
RippleAssetRef (currencyGets, issuerGets))));
auto it0 (mListeners.find (BookRef (
{currencyPays, issuerPays}, {currencyGets, issuerGets})));
if (it0 != mListeners.end ())
ret = it0->second;

View File

@@ -79,7 +79,7 @@ public:
void processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, Json::Value const& jvObj);
private:
typedef ripple::unordered_map <RippleAsset, std::vector<OrderBook::pointer>>
typedef ripple::unordered_map <Issue, std::vector<OrderBook::pointer>>
AssetToOrderBook;
// by ci/ii
@@ -89,13 +89,13 @@ private:
AssetToOrderBook mDestMap;
// does an order book to XRP exist
ripple::unordered_set <RippleAsset> mXRPBooks;
ripple::unordered_set <Issue> mXRPBooks;
typedef RippleRecursiveMutex LockType;
typedef std::lock_guard <LockType> ScopedLockType;
LockType mLock;
typedef ripple::unordered_map <RippleBook, BookListeners::pointer>
typedef ripple::unordered_map <Book, BookListeners::pointer>
BookToListenersMap;
BookToListenersMap mListeners;

View File

@@ -3004,8 +3004,7 @@ void NetworkOPsImp::getBookPage (
// Need to charge a transfer fee to offer owner.
uOfferRate = uTransferRate;
saOwnerFundsLimit = STAmount::divide (
saOwnerFunds, STAmount (noCurrency(), noAccount(),
uOfferRate, -9));
saOwnerFunds, STAmount (noIssue(), uOfferRate, -9));
// TODO(tom): why -9?
}
else
@@ -3038,7 +3037,7 @@ void NetworkOPsImp::getBookPage (
saOwnerFunds,
STAmount::multiply (
saTakerGetsFunded,
STAmount (noCurrency(), noAccount(),
STAmount (noIssue(),
uOfferRate, -9)));
umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
@@ -3165,7 +3164,7 @@ void NetworkOPsImp::getBookPage (
// Need to charge a transfer fee to offer owner.
uOfferRate = uTransferRate;
// TODO(tom): where does -9 come from?!
STAmount amount (noCurrency(), noAccount(), uOfferRate, -9);
STAmount amount (noIssue(), uOfferRate, -9);
saOwnerFundsLimit = STAmount::divide (saOwnerFunds, amount);
}
else
@@ -3198,7 +3197,7 @@ void NetworkOPsImp::getBookPage (
: std::min (saOwnerFunds,
STAmount::multiply (
saTakerGetsFunded, STAmount (
noCurrency(), noAccount(), uOfferRate,
noIssue(), uOfferRate,
-9)));
umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;

View File

@@ -39,7 +39,7 @@ public:
@param issuerOut The destination issuer.
*/
// VFALCO NOTE what is the meaning of the index parameter?
// VFALCO TODO Replace with RippleAsset
// VFALCO TODO Replace with Issue
OrderBook (uint256 const& index,
Currency const& currencyIn,
Currency const& currencyOut,

View File

@@ -264,7 +264,7 @@ TER nodeDeliverFwd (
// Do outbound debiting.
// Send to issuer/limbo total amount including fees (issuer gets
// fees).
auto id = !!node.currency_ ? Account(node.issuer_) : xrpIssuer();
auto id = !!node.currency_ ? Account(node.issuer_) : xrpAccount();
auto outPassTotal = saOutPassAct + saOutPassFees;
rippleCalc.mActiveLedger.accountSend (node.offerOwnerAccount_, id, outPassTotal);
@@ -296,7 +296,7 @@ TER nodeDeliverFwd (
|| uInAccountID != node.offerOwnerAccount_)
{
auto id = !isXRP(previousNode.currency_) ?
uInAccountID : xrpIssuer();
uInAccountID : xrpAccount();
resultCode = rippleCalc.mActiveLedger.accountSend (
id, node.offerOwnerAccount_, saInPassAct);

View File

@@ -78,18 +78,11 @@ TER computeForwardLiquidityForAccount (
// rev.
// For nextNodeIsAccount
STAmount saPrvRedeemAct (
previousNode.saFwdRedeem.getCurrency (),
previousNode.saFwdRedeem.getIssuer ());
STAmount saPrvIssueAct (
previousNode.saFwdIssue.getCurrency (),
previousNode.saFwdIssue.getIssuer ());
auto saPrvRedeemAct = previousNode.saFwdRedeem.zeroed();
auto saPrvIssueAct = previousNode.saFwdIssue.zeroed();
// For !previousNodeIsAccount
STAmount saPrvDeliverAct (
previousNode.saFwdDeliver.getCurrency (),
previousNode.saFwdDeliver.getIssuer ());
auto saPrvDeliverAct = previousNode.saFwdDeliver.zeroed ();
WriteLog (lsTRACE, RippleCalc)
<< "computeForwardLiquidityForAccount> "
@@ -167,7 +160,7 @@ TER computeForwardLiquidityForAccount (
? previousNode.saFwdIssue // No fee.
: STAmount::mulRound (
previousNode.saFwdIssue,
STAmount (noCurrency(), noAccount(), uQualityIn, -9),
STAmount (noIssue(), uQualityIn, -9),
true); // Amount to credit.
// Amount to credit. Credit for less than received as a surcharge.
@@ -329,7 +322,7 @@ TER computeForwardLiquidityForAccount (
node.saFwdDeliver = std::min (
node.saFwdDeliver,
rippleCalc.mActiveLedger.accountHolds (
node.account_, xrpCurrency(), xrpIssuer()));
node.account_, xrpCurrency(), xrpAccount()));
}
@@ -360,7 +353,7 @@ TER computeForwardLiquidityForAccount (
// Deliver XRP to limbo.
resultCode = rippleCalc.mActiveLedger.accountSend (
node.account_, xrpIssuer(), node.saFwdDeliver);
node.account_, xrpAccount(), node.saFwdDeliver);
}
}
}

View File

@@ -84,19 +84,19 @@ TER computeReverseLiquidityForAccount (
const STAmount saPrvOwed = (previousNodeIsAccount && nodeIndex != 0)
? rippleCalc.mActiveLedger.rippleOwed (
node.account_, previousAccountID, node.currency_)
: STAmount (node.currency_, node.account_);
: STAmount ({node.currency_, node.account_});
// The limit amount that the previous account may owe.
const STAmount saPrvLimit = (previousNodeIsAccount && nodeIndex != 0)
? rippleCalc.mActiveLedger.rippleLimit (
node.account_, previousAccountID, node.currency_)
: STAmount (node.currency_, node.account_);
: STAmount ({node.currency_, node.account_});
// Next account is owed.
const STAmount saNxtOwed = (nextNodeIsAccount && nodeIndex != lastNodeIndex)
? rippleCalc.mActiveLedger.rippleOwed (
node.account_, nextAccountID, node.currency_)
: STAmount (node.currency_, node.account_);
: STAmount ({node.currency_, node.account_});
WriteLog (lsTRACE, RippleCalc)
<< "computeReverseLiquidityForAccount>"
@@ -114,7 +114,7 @@ TER computeReverseLiquidityForAccount (
// Previous can redeem the owed IOUs it holds.
const STAmount saPrvRedeemReq = (saPrvOwed > zero)
? saPrvOwed
: STAmount (saPrvOwed.getCurrency (), saPrvOwed.getIssuer ());
: STAmount (saPrvOwed.issue ());
// This is the amount we're actually going to be setting for the previous
// node.
@@ -129,27 +129,25 @@ TER computeReverseLiquidityForAccount (
// Precompute these values in case we have an order book.
auto deliverCurrency = previousNode.saRevDeliver.getCurrency ();
const STAmount saPrvDeliverReq (
deliverCurrency, previousNode.saRevDeliver.getIssuer (), -1);
{deliverCurrency, previousNode.saRevDeliver.getIssuer ()}, -1);
// Unlimited delivery.
STAmount& saPrvDeliverAct = previousNode.saRevDeliver;
STAmount& saPrvDeliverAct = previousNode.saRevDeliver;
// For nextNodeIsAccount
const STAmount& saCurRedeemReq = node.saRevRedeem;
// Set to zero, because we're trying to hit the previous node.
STAmount saCurRedeemAct (
saCurRedeemReq.getCurrency (), saCurRedeemReq.getIssuer ());
auto saCurRedeemAct = saCurRedeemReq.zeroed();
const STAmount& saCurIssueReq = node.saRevIssue;
// Track the amount we actually redeem.
STAmount saCurIssueAct (
saCurIssueReq.getCurrency (), saCurIssueReq.getIssuer ());
auto saCurIssueAct = saCurIssueReq.zeroed();
// For !nextNodeIsAccount
const STAmount& saCurDeliverReq = node.saRevDeliver;
STAmount saCurDeliverAct (
saCurDeliverReq.getCurrency (), saCurDeliverReq.getIssuer ());
auto saCurDeliverAct = saCurDeliverReq.zeroed();
WriteLog (lsTRACE, RippleCalc)
<< "computeReverseLiquidityForAccount:"
@@ -192,8 +190,7 @@ TER computeReverseLiquidityForAccount (
const STAmount saCurWantedReq = std::min (
pathState.outReq() - pathState.outAct(),
saPrvLimit + saPrvOwed);
STAmount saCurWantedAct (
saCurWantedReq.getCurrency (), saCurWantedReq.getIssuer ());
auto saCurWantedAct = saCurWantedReq.zeroed ();
WriteLog (lsTRACE, RippleCalc)
<< "computeReverseLiquidityForAccount: account --> ACCOUNT --> $ :"

View File

@@ -139,11 +139,11 @@ void computeRippleLiquidity (
// current actual = current request * (quality out / quality in).
auto numerator = STAmount::mulRound (
saCur, uQualityOut, currency, uCurIssuerID, true);
saCur, uQualityOut, {currency, uCurIssuerID}, true);
// True means "round up" to get best flow.
STAmount saCurIn = STAmount::divRound (
numerator, uQualityIn, currency, uCurIssuerID, true);
numerator, uQualityIn, {currency, uCurIssuerID}, true);
WriteLog (lsTRACE, RippleCalc)
<< "computeRippleLiquidity:"
@@ -170,12 +170,13 @@ void computeRippleLiquidity (
// This is inverted compared to the code above because we're
// going the other way
Issue issue{currency, uCurIssuerID};
auto numerator = STAmount::mulRound (
saPrv, uQualityIn, currency, uCurIssuerID, true);
saPrv, uQualityIn, issue, true);
// A part of current. All of previous. (Cur is the driver
// variable.)
STAmount saCurOut = STAmount::divRound (
numerator, uQualityOut, currency, uCurIssuerID, true);
numerator, uQualityOut, issue, true);
WriteLog (lsTRACE, RippleCalc)
<< "computeRippleLiquidity:4: saCurReq=" << saCurReq;

View File

@@ -361,7 +361,7 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
if (!sameAccount || (c != saDstAmount.getCurrency ()))
{
if (c.isZero ())
sourceCurrencies.insert (std::make_pair (c, xrpIssuer()));
sourceCurrencies.insert (std::make_pair (c, xrpAccount()));
else
sourceCurrencies.insert (std::make_pair (c, raSrcAccount.getAccountID ()));
}
@@ -414,7 +414,7 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
for (auto const& currIssuer: sourceCurrencies)
{
{
STAmount test (currIssuer.first, currIssuer.second, 1);
STAmount test ({currIssuer.first, currIssuer.second}, 1);
if (m_journal.debug)
{
m_journal.debug
@@ -436,11 +436,12 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
PathState::List pathStateList;
STAmount saMaxAmountAct;
STAmount saDstAmountAct;
STAmount saMaxAmount (
currIssuer.first,
currIssuer.second.isNonZero () ? Account(currIssuer.second) :
(currIssuer.first.isZero () ? xrpIssuer() :
raSrcAccount.getAccountID ()), 1);
auto& account = currIssuer.second.isNonZero ()
? Account(currIssuer.second)
: isXRP (currIssuer.first)
? xrpAccount()
: raSrcAccount.getAccountID ();
STAmount saMaxAmount ({currIssuer.first, account}, 1);
saMaxAmount.negate ();
m_journal.debug << iIdentifier << " Paths found, calling rippleCalc";

View File

@@ -45,7 +45,7 @@ public:
typedef const pointer& ref;
typedef const wptr& wref;
// TODO(tom): Use RippleAsset instead!
// TODO(tom): Use Issue instead!
typedef std::pair<Currency, Account> CurrencyIssuer;
public:

View File

@@ -78,7 +78,7 @@ TER PathState::pushImpliedNodes (
if (nodes_.back ().currency_ != currency)
{
// Currency is different, need to convert via an offer from an order
// book. xrpIssuer() does double duty as signaling "this is an order
// book. xrpAccount() does double duty as signaling "this is an order
// book".
// Corresponds to "Implies an offer directory" in the diagram, currently
@@ -88,8 +88,8 @@ TER PathState::pushImpliedNodes (
: STPathElement::typeCurrency | STPathElement::typeIssuer;
// The offer's output is what is now wanted.
// xrpIssuer() is a placeholder for offers.
resultCode = pushNode (type, xrpIssuer(), currency, issuer);
// xrpAccount() is a placeholder for offers.
resultCode = pushNode (type, xrpAccount(), currency, issuer);
}
@@ -193,13 +193,13 @@ TER PathState::pushNode (
? issuer
: !!node.currency_ // Not XRP.
? account
: xrpIssuer();
: xrpAccount();
// Zero value - for accounts.
node.saRevRedeem = STAmount (node.currency_, account);
node.saRevRedeem = STAmount ({node.currency_, account});
node.saRevIssue = node.saRevRedeem;
// For order books only - zero currency with the issuer ID.
node.saRevDeliver = STAmount (node.currency_, node.issuer_);
node.saRevDeliver = STAmount ({node.currency_, node.issuer_});
node.saFwdDeliver = node.saRevDeliver;
if (pathIsEmpty)
@@ -220,7 +220,7 @@ TER PathState::pushNode (
resultCode = pushImpliedNodes (
node.account_, node.currency_,
isXRP(node.currency_) ? xrpIssuer() : account);
isXRP(node.currency_) ? xrpAccount() : account);
// Note: previousNode may no longer be the immediately previous node.
}
@@ -322,9 +322,9 @@ TER PathState::pushNode (
? Account(previousNode.issuer_) // Default to previous issuer
: Account(previousNode.account_)
// Or previous account if no previous issuer.
: xrpIssuer();
: xrpAccount();
node.saRateMax = saZero;
node.saRevDeliver = STAmount (node.currency_, node.issuer_);
node.saRevDeliver = STAmount({node.currency_, node.issuer_});
node.saFwdDeliver = node.saRevDeliver;
if (node.currency_.isZero() != node.issuer_.isZero())
@@ -345,7 +345,7 @@ TER PathState::pushNode (
// Insert intermediary issuer account if needed.
resultCode = pushImpliedNodes (
xrpIssuer(), // Rippling, but offers don't have an account.
xrpAccount(), // Rippling, but offers don't have an account.
previousNode.currency_,
previousNode.issuer_);
}
@@ -389,7 +389,7 @@ void PathState::expandPath (
const Currency currencyOutID = saOutReq.getCurrency ();
const Account issuerOutID = saOutReq.getIssuer ();
const Account uSenderIssuerID
= isXRP(uMaxCurrencyID) ? xrpIssuer() : uSenderID;
= isXRP(uMaxCurrencyID) ? xrpAccount() : uSenderID;
// Sender is always issuer for non-XRP.
WriteLog (lsTRACE, RippleCalc)
@@ -450,7 +450,7 @@ void PathState::expandPath (
? (issuerOutID == uReceiverID)
? Account(uReceiverID)
: Account(issuerOutID) // Use implied node.
: xrpIssuer();
: xrpAccount();
WriteLog (lsDEBUG, RippleCalc)
<< "expandPath: implied check:"

View File

@@ -111,7 +111,7 @@ Pathfinder::Pathfinder (
mDstAmount (saDstAmount),
mSrcCurrencyID (uSrcCurrencyID),
mSrcIssuerID (uSrcIssuerID),
mSrcAmount (uSrcCurrencyID, uSrcIssuerID, 1u, 0, true),
mSrcAmount ({uSrcCurrencyID, uSrcIssuerID}, 1u, 0, true),
mLedger (cache->getLedger ()), mRLCache (cache)
{
@@ -502,7 +502,7 @@ int Pathfinder::getPathsOut (
Currency const& currencyID, Account const& accountID,
bool isDstCurrency, Account const& dstAccount)
{
// VFALCO TODO Use RippleAsset here
// VFALCO TODO Use Issue here
auto currencyAccount = std::make_pair(currencyID, accountID);
auto it = mPOMap.find (currencyAccount);
@@ -791,7 +791,7 @@ void Pathfinder::addLink(
{
STPathElement pathElement(
STPathElement::typeCurrency,
xrpIssuer(), xrpCurrency(), xrpIssuer());
xrpAccount(), xrpCurrency(), xrpAccount());
incompletePaths.assembleAdd(currentPath, pathElement);
}
}
@@ -804,7 +804,7 @@ void Pathfinder::addLink(
BOOST_FOREACH(OrderBook::ref book, books)
{
if (!currentPath.hasSeen (
xrpIssuer(),
xrpAccount(),
book->getCurrencyOut(),
book->getIssuerOut()) &&
!matchesOrigin(
@@ -821,7 +821,7 @@ void Pathfinder::addLink(
// add the order book itself
newPath.addElement(STPathElement(
STPathElement::typeCurrency,
xrpIssuer(), xrpCurrency(), xrpIssuer()));
xrpAccount(), xrpCurrency(), xrpAccount()));
if (mDstAmount.getCurrency().isZero())
{ // destination is XRP, add account and path is complete
@@ -835,7 +835,7 @@ void Pathfinder::addLink(
{ // Don't want the book if we've already seen the issuer
// add the order book itself
newPath.addElement(STPathElement(STPathElement::typeCurrency | STPathElement::typeIssuer,
xrpIssuer(), book->getCurrencyOut(), book->getIssuerOut()));
xrpAccount(), book->getCurrencyOut(), book->getIssuerOut()));
if ((book->getIssuerOut() == mDstAccountID) && book->getCurrencyOut() == mDstAmount.getCurrency())
{ // with the destination account, this path is complete

View File

@@ -55,13 +55,13 @@ TER rippleCalculate (
PathState::List& pathStateList,
// Issuer:
// XRP: xrpIssuer()
// XRP: xrpAccount()
// non-XRP: uSrcAccountID (for any issuer) or another account with trust
// node.
STAmount const& saMaxAmountReq, // --> -1 = no limit.
// Issuer:
// XRP: xrpIssuer()
// XRP: xrpAccount()
// non-XRP: uDstAccountID (for any issuer) or another account with trust
// node.
STAmount const& saDstAmountReq,

View File

@@ -40,19 +40,19 @@ CreateOffer::CreateOffer (
}
TER
CreateOffer::checkAcceptAsset(core::AssetRef asset) const
CreateOffer::checkAcceptAsset(IssueRef issue) const
{
/* Only valid for custom currencies */
assert (!asset.is_xrp ());
assert (!isXRP (issue.currency));
SLE::pointer const issuerAccount = mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (asset.issuer));
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issue.account));
if (!issuerAccount)
{
if (m_journal.warning) m_journal.warning <<
"delay: can't receive IOUs from non-existent issuer: " <<
to_string (asset.issuer);
to_string (issue.account);
return (mParams & tapRETRY)
? terNO_ACCOUNT
@@ -63,7 +63,7 @@ CreateOffer::checkAcceptAsset(core::AssetRef asset) const
{
SLE::pointer const trustLine (mEngine->entryCache (
ltRIPPLE_STATE, Ledger::getRippleStateIndex (
mTxnAccountID, asset.issuer, asset.currency)));
mTxnAccountID, issue.account, issue.currency)));
if (!trustLine)
{
@@ -75,7 +75,7 @@ CreateOffer::checkAcceptAsset(core::AssetRef asset) const
// Entries have a canonical representation, determined by a
// lexicographical "greater than" comparison employing strict weak
// ordering. Determine which entry we need to access.
bool const canonical_gt (mTxnAccountID > asset.issuer);
bool const canonical_gt (mTxnAccountID > issue.account);
bool const need_auth (trustLine->getFieldU32 (sfFlags) &
(canonical_gt ? lsfLowAuth : lsfHighAuth));
@@ -279,7 +279,7 @@ CreateOffer::doApply ()
// Make sure that we are authorized to hold what the taker will pay us.
if (terResult == tesSUCCESS && !saTakerPays.isNative ())
terResult = checkAcceptAsset (core::Asset (uPaysCurrency, uPaysIssuerID));
terResult = checkAcceptAsset (Issue (uPaysCurrency, uPaysIssuerID));
bool crossed = false;
bool const bOpenLedger (mParams & tapOPEN_LEDGER);
@@ -358,7 +358,7 @@ CreateOffer::doApply ()
// Earlier, we verified that the amounts, as specified in the offer,
// were not negative. That they are now suggests that something went
// very wrong with offer crossing.
m_journal.fatal << (crossed ? "Partially consumed" : "Full") <<
m_journal.fatal << (crossed ? "Partially consumed" : "Full") <<
" offer has negative component:" <<
" pays=" << saTakerPays.getFullText () <<
" gets=" << saTakerGets.getFullText ();

View File

@@ -32,7 +32,7 @@ class CreateOffer
{
protected:
/** Determine if we are authorized to hold the asset we want to get */
TER checkAcceptAsset(core::AssetRef asset) const;
TER checkAcceptAsset(IssueRef asset) const;
/** Fill offer as much as possible by consuming offers already on the books.
We adjusts account balances and charges fees on top to taker.
@@ -65,4 +65,3 @@ std::unique_ptr <Transactor> make_CreateOffer (
}
#endif

View File

@@ -41,20 +41,17 @@ CreateOfferBridged::crossOffers (
core::LedgerView view_cancel (view.duplicate());
core::AssetRef const asset_in (
taker_amount.in.getCurrency(), taker_amount.in.getIssuer());
core::AssetRef const asset_out (
taker_amount.out.getCurrency(), taker_amount.out.getIssuer());
auto& asset_in = taker_amount.in.issue();
auto& asset_out = taker_amount.out.issue();
core::OfferStream offers_direct (view, view_cancel,
core::Book (asset_in, asset_out), when, m_journal);
Book (asset_in, asset_out), when, m_journal);
core::OfferStream offers_leg1 (view, view_cancel,
core::Book (asset_in, xrp_asset ()), when, m_journal);
Book (asset_in, xrpIssue ()), when, m_journal);
core::OfferStream offers_leg2 (view, view_cancel,
core::Book (xrp_asset (), asset_out), when, m_journal);
Book (xrpIssue (), asset_out), when, m_journal);
core::Taker taker (view, mTxnAccountID, taker_amount, options);

View File

@@ -45,16 +45,11 @@ CreateOfferDirect::crossOffers (
mEngine->getLedger ()->getParentCloseTimeNC ());
core::LedgerView view_cancel (view.duplicate());
core::OfferStream offers (view, view_cancel,
core::Book (
core::AssetRef (
taker_amount.in.getCurrency(), taker_amount.in.getIssuer()),
core::AssetRef (
taker_amount.out.getCurrency(), taker_amount.out.getIssuer())),
core::OfferStream offers (
view, view_cancel,
Book (taker_amount.in.issue(), taker_amount.out.issue()),
when, m_journal);
Account& account = mTxnAccountID;
// TODO(tom): why is that last line needed?
core::Taker taker (offers.view(), account, taker_amount, options);
core::Taker taker (offers.view(), mTxnAccountID, taker_amount, options);
TER cross_result (tesSUCCESS);

View File

@@ -39,8 +39,9 @@ TER Payment::doApply ()
maxSourceAmount = saDstAmount;
else
maxSourceAmount = STAmount (
saDstAmount.getCurrency (), mTxnAccountID, saDstAmount.getMantissa (),
saDstAmount.getExponent (), saDstAmount < zero);
{saDstAmount.getCurrency (), mTxnAccountID},
saDstAmount.getMantissa (), saDstAmount.getExponent (),
saDstAmount < zero);
auto const& uSrcCurrency = maxSourceAmount.getCurrency ();
auto const& uDstCurrency = saDstAmount.getCurrency ();

View File

@@ -352,12 +352,12 @@ TER SetTrust::doApply ()
}
else if (badCurrency() == currency)
{
terResult = temBAD_CURRENCY;
terResult = temBAD_CURRENCY;
}
else
{
// Zero balance in currency.
STAmount saBalance (STAmount (currency, noAccount()));
STAmount saBalance ({currency, noAccount()});
uint256 index (Ledger::getRippleStateIndex (
mTxnAccountID, uDstAccountID, currency));