mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Split AccountItems and tidy up
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
|
||||
AccountItem::AccountItem(SerializedLedgerEntry::ref ledger) : mLedgerEntry(ledger)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AccountItems::AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType)
|
||||
{
|
||||
mOfType = ofType;
|
||||
|
||||
fillItems(accountID, ledger);
|
||||
}
|
||||
|
||||
void AccountItems::fillItems(const uint160& accountID, Ledger::ref ledger)
|
||||
{
|
||||
uint256 rootIndex = Ledger::getOwnerDirIndex(accountID);
|
||||
uint256 currentIndex = rootIndex;
|
||||
|
||||
while (1)
|
||||
{
|
||||
SLE::pointer ownerDir = ledger->getDirNode(currentIndex);
|
||||
if (!ownerDir) return;
|
||||
|
||||
BOOST_FOREACH(uint256 const& uNode, ownerDir->getFieldV256(sfIndexes).peekValue())
|
||||
{
|
||||
SLE::pointer sleCur = ledger->getSLEi(uNode);
|
||||
|
||||
AccountItem::pointer item = mOfType->makeItem(accountID, sleCur);
|
||||
if (item)
|
||||
{
|
||||
mItems.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
uint64 uNodeNext = ownerDir->getFieldU64(sfIndexNext);
|
||||
if (!uNodeNext) return;
|
||||
|
||||
currentIndex = Ledger::getDirNodeIndex(rootIndex, uNodeNext);
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value AccountItems::getJson(int v)
|
||||
{
|
||||
Json::Value ret(Json::arrayValue);
|
||||
BOOST_FOREACH(AccountItem::ref ai, mItems)
|
||||
ret.append(ai->getJson(v));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
@@ -1,50 +0,0 @@
|
||||
#ifndef __ACCOUNT_ITEMS__
|
||||
#define __ACCOUNT_ITEMS__
|
||||
|
||||
//
|
||||
// Fetch ledger entries from an account's owner dir.
|
||||
//
|
||||
class AccountItem
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<AccountItem> pointer;
|
||||
typedef const pointer& ref;
|
||||
|
||||
AccountItem(){ }
|
||||
AccountItem(SerializedLedgerEntry::ref ledger);
|
||||
virtual ~AccountItem() { ; }
|
||||
virtual AccountItem::pointer makeItem(const uint160& accountID, SerializedLedgerEntry::ref ledgerEntry)=0;
|
||||
virtual LedgerEntryType getType()=0;
|
||||
virtual Json::Value getJson(int)=0;
|
||||
|
||||
SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; }
|
||||
const SerializedLedgerEntry& peekSLE() const { return *mLedgerEntry; }
|
||||
SerializedLedgerEntry& peekSLE() { return *mLedgerEntry; }
|
||||
|
||||
Blob getRaw() const;
|
||||
|
||||
// VFALCO TODO make an accessor for mLedgerEntry so we can change protected to private
|
||||
protected:
|
||||
SerializedLedgerEntry::pointer mLedgerEntry;
|
||||
};
|
||||
|
||||
class AccountItems
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<AccountItems> pointer;
|
||||
|
||||
AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType);
|
||||
|
||||
std::vector<AccountItem::pointer>& getItems() { return(mItems); }
|
||||
Json::Value getJson(int);
|
||||
|
||||
private:
|
||||
AccountItem::pointer mOfType;
|
||||
|
||||
std::vector<AccountItem::pointer> mItems;
|
||||
void fillItems(const uint160& accountID, Ledger::ref ledger);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
@@ -11,10 +11,13 @@ public:
|
||||
typedef boost::shared_ptr<AccountState> pointer;
|
||||
|
||||
public:
|
||||
explicit AccountState(const RippleAddress& naAccountID); // For new accounts
|
||||
AccountState (SLE::ref ledgerEntry,const RippleAddress& naAccountI); // For accounts in a ledger
|
||||
// For new accounts
|
||||
explicit AccountState (const RippleAddress& naAccountID);
|
||||
|
||||
// For accounts in a ledger
|
||||
AccountState (SLE::ref ledgerEntry, const RippleAddress& naAccountI);
|
||||
|
||||
bool bHaveAuthorizedKey()
|
||||
bool haveAuthorizedKey ()
|
||||
{
|
||||
return mLedgerEntry->isFieldPresent(sfRegularKey);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef RIPPLE_OFFER_H
|
||||
#define RIPPLE_OFFER_H
|
||||
|
||||
#include "AccountItems.h"
|
||||
|
||||
class Offer : public AccountItem
|
||||
{
|
||||
RippleAddress mAccount;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#include "RippleCalc.h"
|
||||
#include "OrderBookDB.h"
|
||||
#include "AccountItems.h"
|
||||
|
||||
#if 0
|
||||
//
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "Pathfinder.h"
|
||||
#include "RPCHandler.h"
|
||||
#include "RPCSub.h"
|
||||
#include "AccountItems.h"
|
||||
#include "Wallet.h"
|
||||
#include "RippleCalc.h"
|
||||
#include "RPCErr.h"
|
||||
@@ -443,7 +442,7 @@ Json::Value RPCHandler::authorize(Ledger::ref lrLedger,
|
||||
|
||||
RippleAddress naMasterGenerator;
|
||||
|
||||
if (asSrc->bHaveAuthorizedKey())
|
||||
if (asSrc->haveAuthorizedKey())
|
||||
{
|
||||
Json::Value obj = getMasterGenerator(lrLedger, naRegularSeed, naMasterGenerator);
|
||||
|
||||
@@ -491,7 +490,7 @@ Json::Value RPCHandler::authorize(Ledger::ref lrLedger,
|
||||
naAccountPublic.setAccountPublic(naGenerator, iIndex);
|
||||
naAccountPrivate.setAccountPrivate(naGenerator, naRegularSeed, iIndex);
|
||||
|
||||
if (asSrc->bHaveAuthorizedKey() && (asSrc->getAuthorizedKey().getAccountID() != naAccountPublic.getAccountID()))
|
||||
if (asSrc->haveAuthorizedKey() && (asSrc->getAuthorizedKey().getAccountID() != naAccountPublic.getAccountID()))
|
||||
{
|
||||
// std::cerr << "iIndex: " << iIndex << std::endl;
|
||||
// std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// - Isolate ledger entry format.
|
||||
//
|
||||
|
||||
#include "AccountItems.h"
|
||||
|
||||
class RippleState : public AccountItem
|
||||
{
|
||||
public:
|
||||
|
||||
6
src/cpp/ripple/ripple_AccountItem.cpp
Normal file
6
src/cpp/ripple/ripple_AccountItem.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
AccountItem::AccountItem (SerializedLedgerEntry::ref ledger)
|
||||
: mLedgerEntry (ledger)
|
||||
{
|
||||
|
||||
}
|
||||
46
src/cpp/ripple/ripple_AccountItem.h
Normal file
46
src/cpp/ripple/ripple_AccountItem.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef RIPPLE_ACCOUNTITEM_H
|
||||
#define RIPPLE_ACCOUNTITEM_H
|
||||
|
||||
//
|
||||
// Fetch ledger entries from an account's owner dir.
|
||||
//
|
||||
/** Base class representing account items.
|
||||
*/
|
||||
class AccountItem
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr <AccountItem> pointer;
|
||||
typedef const pointer& ref;
|
||||
|
||||
public:
|
||||
AccountItem ()
|
||||
{ }
|
||||
|
||||
/** Construct from a flat ledger entry.
|
||||
*/
|
||||
explicit AccountItem (SerializedLedgerEntry::ref ledger);
|
||||
|
||||
virtual ~AccountItem() { ; }
|
||||
|
||||
virtual AccountItem::pointer makeItem (const uint160& accountID, SerializedLedgerEntry::ref ledgerEntry)=0;
|
||||
|
||||
virtual LedgerEntryType getType ()=0;
|
||||
|
||||
virtual Json::Value getJson(int)=0;
|
||||
|
||||
SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; }
|
||||
|
||||
const SerializedLedgerEntry& peekSLE() const { return *mLedgerEntry; }
|
||||
|
||||
SerializedLedgerEntry& peekSLE() { return *mLedgerEntry; }
|
||||
|
||||
Blob getRaw() const;
|
||||
|
||||
// VFALCO TODO Make this private and use the existing accessors
|
||||
//
|
||||
protected:
|
||||
// VFALCO TODO Research making the object pointed to const
|
||||
SerializedLedgerEntry::pointer mLedgerEntry;
|
||||
};
|
||||
|
||||
#endif
|
||||
63
src/cpp/ripple/ripple_AccountItems.cpp
Normal file
63
src/cpp/ripple/ripple_AccountItems.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
AccountItems::AccountItems (uint160 const& accountID,
|
||||
Ledger::ref ledger,
|
||||
AccountItem::pointer ofType)
|
||||
{
|
||||
mOfType = ofType;
|
||||
|
||||
fillItems(accountID, ledger);
|
||||
}
|
||||
|
||||
void AccountItems::fillItems(const uint160& accountID, Ledger::ref ledger)
|
||||
{
|
||||
uint256 const rootIndex = Ledger::getOwnerDirIndex(accountID);
|
||||
uint256 currentIndex = rootIndex;
|
||||
|
||||
// VFALCO TODO Rewrite all infinite loops to have clear terminating
|
||||
// conditions defined in one location.
|
||||
//
|
||||
while (1)
|
||||
{
|
||||
SLE::pointer ownerDir = ledger->getDirNode (currentIndex);
|
||||
|
||||
// VFALCO TODO Rewrite to not return from the middle of the function
|
||||
if (!ownerDir)
|
||||
return;
|
||||
|
||||
BOOST_FOREACH (uint256 const& uNode, ownerDir->getFieldV256 (sfIndexes).peekValue ())
|
||||
{
|
||||
// VFALCO TODO rename getSLEi() to something legible.
|
||||
SLE::pointer sleCur = ledger->getSLEi (uNode);
|
||||
|
||||
AccountItem::pointer item = mOfType->makeItem (accountID, sleCur);
|
||||
|
||||
// VFALCO NOTE Under what conditions would makeItem() return nullptr?
|
||||
if (item)
|
||||
{
|
||||
mItems.push_back (item);
|
||||
}
|
||||
}
|
||||
|
||||
uint64 uNodeNext = ownerDir->getFieldU64(sfIndexNext);
|
||||
|
||||
// VFALCO TODO Rewrite to not return from the middle of the function
|
||||
if (!uNodeNext)
|
||||
return;
|
||||
|
||||
currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext);
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value AccountItems::getJson(int v)
|
||||
{
|
||||
Json::Value ret (Json::arrayValue);
|
||||
|
||||
BOOST_FOREACH (AccountItem::ref ai, mItems)
|
||||
{
|
||||
ret.append (ai->getJson (v));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
36
src/cpp/ripple/ripple_AccountItems.h
Normal file
36
src/cpp/ripple/ripple_AccountItems.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef RIPPLE_ACCOUNTITEMS_H
|
||||
#define RIPPLE_ACCOUNTITEMS_H
|
||||
|
||||
/** A set of AccountItem objects.
|
||||
*/
|
||||
class AccountItems
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr <AccountItems> pointer;
|
||||
|
||||
typedef std::vector <AccountItem::pointer> Container;
|
||||
|
||||
// VFALCO TODO Create a typedef uint160 AccountID and replace
|
||||
AccountItems (uint160 const& accountID,
|
||||
Ledger::ref ledger,
|
||||
AccountItem::pointer ofType);
|
||||
|
||||
// VFALCO TODO rename to getContainer and make this change in every interface
|
||||
// that exposes the caller to the type of container.
|
||||
//
|
||||
Container& getItems() { return mItems; }
|
||||
|
||||
// VFALCO TODO What is the int for?
|
||||
Json::Value getJson (int);
|
||||
|
||||
private:
|
||||
void fillItems (const uint160& accountID, Ledger::ref ledger);
|
||||
|
||||
private:
|
||||
// VFALCO TODO This looks like its used as an exemplar, rename appropriately
|
||||
AccountItem::pointer mOfType;
|
||||
|
||||
Container mItems;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user