Split AccountItems and tidy up

This commit is contained in:
Vinnie Falco
2013-06-12 10:06:13 -07:00
parent 39a6950c49
commit f6a2920692
14 changed files with 240 additions and 174 deletions

View File

@@ -184,7 +184,8 @@
#include "src/cpp/ripple/AccountItems.h"
#include "src/cpp/ripple/ripple_AccountItem.h"
#include "src/cpp/ripple/ripple_AccountItems.h"
#include "src/cpp/ripple/ripple_AcceptedLedgerTx.h"
#include "src/cpp/ripple/ripple_AcceptedLedger.h"
#include "src/cpp/ripple/LedgerEntrySet.h"
@@ -267,7 +268,8 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
#include "src/cpp/database/database.cpp"
#include "src/cpp/database/SqliteDatabase.cpp"
#include "src/cpp/ripple/AccountItems.cpp" // no log
#include "src/cpp/ripple/ripple_AccountItem.cpp"
#include "src/cpp/ripple/ripple_AccountItems.cpp"
#include "src/cpp/ripple/AccountSetTransactor.cpp"
#include "src/cpp/ripple/AccountState.cpp" // no log
#include "src/cpp/ripple/CallRPC.cpp"

View File

@@ -731,12 +731,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\AccountItems.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\AccountSetTransactor.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -749,6 +743,18 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_AccountItem.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_AccountItems.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_Application.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -1710,9 +1716,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_AcceptedLedger.h" />
<ClInclude Include="src\cpp\ripple\AccountItems.h" />
<ClInclude Include="src\cpp\ripple\AccountSetTransactor.h" />
<ClInclude Include="src\cpp\ripple\AccountState.h" />
<ClInclude Include="src\cpp\ripple\ripple_AccountItem.h" />
<ClInclude Include="src\cpp\ripple\ripple_AccountItems.h" />
<ClInclude Include="src\cpp\ripple\ripple_IApplication.h" />
<ClInclude Include="src\cpp\ripple\AutoSocket.h" />
<ClInclude Include="src\cpp\ripple\CallRPC.h" />

View File

@@ -136,6 +136,9 @@
<Filter Include="1. Modules\ripple_data\utility">
<UniqueIdentifier>{ba524810-8446-4c50-ad59-d284747ba220}</UniqueIdentifier>
</Filter>
<Filter Include="1. Modules\ripple_main\refactored\shamap">
<UniqueIdentifier>{5b22fcf9-c9f0-4260-9a17-7b448e30bb57}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\cpp\database\sqlite3.c">
@@ -633,9 +636,6 @@
<ClCompile Include="src\cpp\ripple\ripple_UniqueNodeList.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\AccountItems.cpp">
<Filter>1. Modules\ripple_main\_unfactored\ledger</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\AccountState.cpp">
<Filter>1. Modules\ripple_main\_unfactored\ledger</Filter>
</ClCompile>
@@ -780,30 +780,6 @@
<ClCompile Include="src\cpp\ripple\ripple_InfoSub.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapNode.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapItem.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapTreeNode.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapMissingNode.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapSync.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapSyncFilters.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMap.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapDelta.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_PeerSet.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
@@ -855,6 +831,36 @@
<ClCompile Include="modules\ripple_main\ripple_main_pt4.cpp">
<Filter>1. Modules\ripple_main</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_AccountItem.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_AccountItems.cpp">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapDelta.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapItem.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapMissingNode.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapNode.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapSync.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapSyncFilters.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMapTreeNode.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_SHAMap.cpp">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="database\sqlite3ext.h">
@@ -1382,9 +1388,6 @@
<ClInclude Include="src\cpp\ripple\ripple_IUniqueNodeList.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\AccountItems.h">
<Filter>1. Modules\ripple_main\_unfactored\ledger</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\AccountState.h">
<Filter>1. Modules\ripple_main\_unfactored\ledger</Filter>
</ClInclude>
@@ -1532,30 +1535,6 @@
<ClInclude Include="src\cpp\ripple\ripple_InfoSub.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapNode.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapItem.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapTreeNode.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapMissingNode.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapSyncFilter.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapAddNode.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapSyncFilters.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMap.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_PeerSet.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
@@ -1604,6 +1583,36 @@
<ClInclude Include="src\cpp\ripple\ripple_OrderBook.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_AccountItem.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_AccountItems.h">
<Filter>1. Modules\ripple_main\refactored</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapTreeNode.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapAddNode.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapItem.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapMissingNode.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapNode.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapSyncFilter.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMapSyncFilters.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_SHAMap.h">
<Filter>1. Modules\ripple_main\refactored\shamap</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="SConstruct" />

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}

View File

@@ -1,8 +1,6 @@
#ifndef RIPPLE_OFFER_H
#define RIPPLE_OFFER_H
#include "AccountItems.h"
class Offer : public AccountItem
{
RippleAddress mAccount;

View File

@@ -5,7 +5,6 @@
#include "RippleCalc.h"
#include "OrderBookDB.h"
#include "AccountItems.h"
#if 0
//

View File

@@ -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;

View File

@@ -6,8 +6,6 @@
// - Isolate ledger entry format.
//
#include "AccountItems.h"
class RippleState : public AccountItem
{
public:

View File

@@ -0,0 +1,6 @@
AccountItem::AccountItem (SerializedLedgerEntry::ref ledger)
: mLedgerEntry (ledger)
{
}

View 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

View 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

View 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