mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
Tidy up OrderBook
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
|
||||
OrderBook::OrderBook(SerializedLedgerEntry::ref ledgerEntry)
|
||||
{
|
||||
const STAmount saTakerGets = ledgerEntry->getFieldAmount(sfTakerGets);
|
||||
const STAmount saTakerPays = ledgerEntry->getFieldAmount(sfTakerPays);
|
||||
|
||||
mCurrencyIn = saTakerPays.getCurrency();
|
||||
mCurrencyOut = saTakerGets.getCurrency();
|
||||
mIssuerIn = saTakerPays.getIssuer();
|
||||
mIssuerOut = saTakerGets.getIssuer();
|
||||
|
||||
mBookBase=Ledger::getBookBase(mCurrencyIn, mIssuerIn, mCurrencyOut, mIssuerOut);
|
||||
}
|
||||
|
||||
|
||||
// vim:ts=4
|
||||
@@ -1,45 +0,0 @@
|
||||
|
||||
#ifndef ORDERBOOK_H
|
||||
#define ORDERBOOK_H
|
||||
|
||||
/*
|
||||
Encapsulates the SLE for an orderbook
|
||||
*/
|
||||
class OrderBook
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<OrderBook> pointer;
|
||||
typedef const boost::shared_ptr<OrderBook>& ref;
|
||||
|
||||
OrderBook(uint256 const& index, const uint160& ci, const uint160& co, const uint160& ii, const uint160& io) :
|
||||
mBookBase(index),
|
||||
mCurrencyIn(ci),
|
||||
mCurrencyOut(co),
|
||||
mIssuerIn(ii),
|
||||
mIssuerOut(io)
|
||||
{ ; }
|
||||
|
||||
uint256& getBookBase(){ return(mBookBase); }
|
||||
uint160& getCurrencyIn(){ return(mCurrencyIn); }
|
||||
uint160& getCurrencyOut(){ return(mCurrencyOut); }
|
||||
uint160& getIssuerIn(){ return(mIssuerIn); }
|
||||
uint160& getIssuerOut(){ return(mIssuerOut); }
|
||||
|
||||
// looks through the best offers to see how much it would cost to take the given amount
|
||||
STAmount& getTakePrice(STAmount& takeAmount);
|
||||
|
||||
private:
|
||||
uint256 mBookBase;
|
||||
|
||||
uint160 mCurrencyIn;
|
||||
uint160 mCurrencyOut;
|
||||
uint160 mIssuerIn;
|
||||
uint160 mIssuerOut;
|
||||
|
||||
//SerializedLedgerEntry::pointer mLedgerEntry;
|
||||
OrderBook(SerializedLedgerEntry::ref ledgerEntry); // For accounts in a ledger
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
@@ -44,6 +44,7 @@ void OrderBookDB::setup(Ledger::ref ledger)
|
||||
uint256 index = Ledger::getBookBase(ci, ii, co, io);
|
||||
if (mSeen.insert(index).second)
|
||||
{
|
||||
// VFALCO TODO Reduce the clunkiness of these parameter wrappers
|
||||
OrderBook::pointer book = boost::make_shared<OrderBook>(boost::cref(index),
|
||||
boost::cref(ci), boost::cref(co), boost::cref(ii), boost::cref(io));
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
#ifndef ORDERBOOK_DB_H
|
||||
#define ORDERBOOK_DB_H
|
||||
|
||||
#include "OrderBook.h"
|
||||
|
||||
|
||||
//
|
||||
// XXX Eventually make this cached and just update it as transactions come in.
|
||||
// But, for now it is probably faster to just generate it each time.
|
||||
|
||||
39
src/cpp/ripple/ripple_OrderBook.cpp
Normal file
39
src/cpp/ripple/ripple_OrderBook.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
|
||||
OrderBook::OrderBook (uint256 const& index,
|
||||
uint160 const& currencyIn,
|
||||
uint160 const& currencyOut,
|
||||
uint160 const& issuerIn,
|
||||
uint160 const& issuerOut)
|
||||
: mBookBase (index)
|
||||
, mCurrencyIn (currencyIn)
|
||||
, mCurrencyOut (currencyOut)
|
||||
, mIssuerIn (issuerIn)
|
||||
, mIssuerOut (issuerOut)
|
||||
{
|
||||
}
|
||||
|
||||
uint256 const& OrderBook::getBookBase () const
|
||||
{
|
||||
return mBookBase;
|
||||
}
|
||||
|
||||
uint160 const& OrderBook::getCurrencyIn () const
|
||||
{
|
||||
return mCurrencyIn;
|
||||
}
|
||||
|
||||
uint160 const& OrderBook::getCurrencyOut () const
|
||||
{
|
||||
return mCurrencyOut;
|
||||
}
|
||||
|
||||
uint160 const& OrderBook::getIssuerIn () const
|
||||
{
|
||||
return mIssuerIn;
|
||||
}
|
||||
|
||||
uint160 const& OrderBook::getIssuerOut () const
|
||||
{
|
||||
return mIssuerOut;
|
||||
}
|
||||
50
src/cpp/ripple/ripple_OrderBook.h
Normal file
50
src/cpp/ripple/ripple_OrderBook.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef RIPPLE_ORDERBOOK_H
|
||||
#define RIPPLE_ORDERBOOK_H
|
||||
|
||||
/** Describes a serialized ledger entry for an order book.
|
||||
*/
|
||||
class OrderBook
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr <OrderBook> pointer;
|
||||
|
||||
typedef boost::shared_ptr <OrderBook> const& ref;
|
||||
|
||||
public:
|
||||
/** Construct from a currency specification.
|
||||
|
||||
@param index ???
|
||||
@param currencyIn The base currency.
|
||||
@param currencyOut The destination currency.
|
||||
@param issuerIn The base issuer.
|
||||
@param issuerOut The destination issuer.
|
||||
*/
|
||||
// VFALCO NOTE what is the meaning of the index parameter?
|
||||
// VFALCO TODO group the issuer and currency parameters together.
|
||||
// VFALCO TODO give typedef names to uint256 / uint160 params
|
||||
OrderBook (uint256 const& index,
|
||||
uint160 const& currencyIn,
|
||||
uint160 const& currencyOut,
|
||||
uint160 const& issuerIn,
|
||||
uint160 const& issuerOut);
|
||||
|
||||
uint256 const& getBookBase () const;
|
||||
|
||||
uint160 const& getCurrencyIn () const;
|
||||
|
||||
uint160 const& getCurrencyOut () const;
|
||||
|
||||
uint160 const& getIssuerIn () const;
|
||||
|
||||
uint160 const& getIssuerOut () const;
|
||||
|
||||
|
||||
private:
|
||||
uint256 const mBookBase;
|
||||
uint160 const mCurrencyIn;
|
||||
uint160 const mCurrencyOut;
|
||||
uint160 const mIssuerIn;
|
||||
uint160 const mIssuerOut;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user