Skip to content

Commit

Permalink
Rename RippleAsset to Issue and RippleBook to Book:
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
rec authored and nbougalis committed Jul 6, 2014
1 parent a96dee8 commit 206efbf
Show file tree
Hide file tree
Showing 42 changed files with 1,613 additions and 1,492 deletions.
7 changes: 4 additions & 3 deletions src/ripple/module/app/book/Amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class AmountType

if (sig == 0)
return os << "0";

if (sig < 0)
os << "-";
if (m_integral)
Expand All @@ -204,10 +204,11 @@ class AmountType
};

//------------------------------------------------------------------------------
// TODO(tom): remove this typedef and have exactly one name for STAmount.

typedef STAmount Amount;

}
}
} // core
} // ripple

#endif
11 changes: 1 addition & 10 deletions src/ripple/module/app/book/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/module/app/book/impl/BookTip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
}
Expand Down Expand Up @@ -65,7 +65,7 @@ BookTip::step ()
m_book = page;

// The quality immediately before the next quality
--m_book;
--m_book;

break;
}
Expand Down
8 changes: 2 additions & 6 deletions src/ripple/module/app/book/impl/Taker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/ripple/module/app/book/tests/Quality.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Quality_test : public beast::unit_test::suite
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>
Expand Down Expand Up @@ -241,9 +241,9 @@ class Quality_test : public beast::unit_test::suite
{
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));
Expand All @@ -264,9 +264,9 @@ class Quality_test : public beast::unit_test::suite
{
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));
Expand All @@ -289,8 +289,8 @@ class Quality_test : public beast::unit_test::suite
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);
Expand Down
40 changes: 19 additions & 21 deletions src/ripple/module/app/ledger/LedgerEntrySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ STAmount LedgerEntrySet::rippleOwed (
}
else
{
saBalance.clear (currency, uToAccountID);
saBalance.clear ({currency, uToAccountID});

WriteLog (lsDEBUG, LedgerEntrySet) << "rippleOwed:" <<
" No credit line between " <<
Expand Down Expand Up @@ -1146,7 +1146,7 @@ STAmount LedgerEntrySet::rippleLimit (
}
else
{
saLimit.clear (currency, uToAccountID);
saLimit.clear ({currency, uToAccountID});
}

return saLimit;
Expand Down Expand Up @@ -1237,7 +1237,7 @@ STAmount LedgerEntrySet::rippleHolds (

if (!sleRippleState)
{
saBalance.clear (currency, issuer);
saBalance.clear ({currency, issuer});
}
else if (account > issuer)
{
Expand Down Expand Up @@ -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:" <<
Expand All @@ -1366,7 +1364,7 @@ STAmount LedgerEntrySet::rippleTransferFee (
}
}

return STAmount (saAmount.getCurrency (), saAmount.getIssuer ());
return saAmount.zeroed();
}

TER LedgerEntrySet::trustCreate (
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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());

Expand Down
45 changes: 21 additions & 24 deletions src/ripple/module/app/ledger/OrderBookDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) &&
Expand All @@ -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;
}
}
Expand All @@ -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>";

Expand Down Expand Up @@ -139,15 +139,15 @@ 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;
}
}
else
{
for (auto ob : mDestMap[RippleAssetRef(co, io)])
for (auto ob : mDestMap[{co, io}])
{
if ((ob->getCurrencyIn() == ci) && (ob->getIssuerIn() == ii))
return;
Expand All @@ -157,19 +157,18 @@ 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
void OrderBookDB::getBooksByTakerPays (Account const& issuerID, Currency const& currencyID,
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
Expand All @@ -180,15 +179,15 @@ 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
void OrderBookDB::getBooksByTakerGets (Account const& issuerID, Currency const& currencyID,
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;
Expand All @@ -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);
}

Expand All @@ -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;
Expand Down
Loading

0 comments on commit 206efbf

Please sign in to comment.