diff --git a/newcoin.vcxproj b/newcoin.vcxproj
index d6c37b34c1..65bbd332c4 100644
--- a/newcoin.vcxproj
+++ b/newcoin.vcxproj
@@ -50,6 +50,7 @@
Disabled
BOOST_TEST_ALTERNATIVE_INIT_API;BOOST_TEST_NO_MAIN;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
..\OpenSSL\include;..\boost_1_47_0;..\protobuf-2.4.1\src\
+ ProgramDatabase
Console
@@ -125,12 +126,14 @@
+
+
@@ -210,11 +213,13 @@
+
+
@@ -259,6 +264,13 @@
+
+
+
+
+
+
+
diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters
index 2116e89379..b636aa2606 100644
--- a/newcoin.vcxproj.filters
+++ b/newcoin.vcxproj.filters
@@ -276,6 +276,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
@@ -506,6 +512,12 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
diff --git a/src/Ledger.h b/src/Ledger.h
index f830124e22..b90d440895 100644
--- a/src/Ledger.h
+++ b/src/Ledger.h
@@ -260,7 +260,7 @@ public:
// Ripple functions : credit lines
//
- // Index of node which is the ripple state between to accounts for a currency.
+ // Index of node which is the ripple state between two accounts for a currency.
static uint256 getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency);
static uint256 getRippleStateIndex(const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
{ return getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency); }
diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp
index afbf87e32a..c09d427e55 100644
--- a/src/NetworkOPs.cpp
+++ b/src/NetworkOPs.cpp
@@ -292,15 +292,6 @@ Json::Value NetworkOPs::getOwnerInfo(Ledger::pointer lpLedger, const NewcoinAddr
return jvObjects;
}
-//
-// Ripple functions
-//
-
-RippleState::pointer NetworkOPs::accessRippleState(const uint256& uLedger, const uint256& uIndex)
-{
- return mLedgerMaster->getLedgerByHash(uLedger)->accessRippleState(uIndex);
-}
-
//
// Other
//
diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h
index 8e8e45c24c..e631685bc0 100644
--- a/src/NetworkOPs.h
+++ b/src/NetworkOPs.h
@@ -145,21 +145,7 @@ public:
Json::Value getOwnerInfo(const uint256& uLedger, const NewcoinAddress& naAccount);
Json::Value getOwnerInfo(Ledger::pointer lpLedger, const NewcoinAddress& naAccount);
- //
- // Ripple functions
- //
-
- bool getDirLineInfo(const uint256& uLedger, const NewcoinAddress& naAccount, uint256& uRootIndex)
- {
- LedgerStateParms lspNode = lepNONE;
-
- uRootIndex = Ledger::getRippleDirIndex(naAccount.getAccountID());
-
- return !!mLedgerMaster->getLedgerByHash(uLedger)->getDirNode(lspNode, uRootIndex);
- }
-
- RippleState::pointer accessRippleState(const uint256& uLedger, const uint256& uIndex);
-
+
// raw object operations
bool findRawLedger(const uint256& ledgerHash, std::vector& rawLedger);
bool findRawTransaction(const uint256& transactionHash, std::vector& rawTransaction);
diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp
index 46ea9eda7d..db22f72683 100644
--- a/src/RPCServer.cpp
+++ b/src/RPCServer.cpp
@@ -12,6 +12,7 @@
#include "NicknameState.h"
#include "utils.h"
#include "Log.h"
+#include "RippleLines.h"
#include
@@ -1654,70 +1655,27 @@ Json::Value RPCServer::doRippleLinesGet(const Json::Value ¶ms)
// XXX This is wrong, we do access the current ledger and do need to worry about changes.
// We access a committed ledger and need not worry about changes.
- uint256 uRootIndex;
- if (mNetOps->getDirLineInfo(uCurrent, naAccount, uRootIndex))
+ RippleLines rippleLines(naAccount.getAccountID());
+ BOOST_FOREACH(RippleState::pointer line,rippleLines.getLines())
{
- Log(lsINFO) << "doRippleLinesGet: dir root index: " << uRootIndex.ToString();
- bool bDone = false;
+ STAmount saBalance = line->getBalance();
+ STAmount saLimit = line->getLimit();
+ STAmount saLimitPeer = line->getLimitPeer();
- while (!bDone)
- {
- uint64 uNodePrevious;
- uint64 uNodeNext;
- STVector256 svRippleNodes = mNetOps->getDirNodeInfo(uCurrent, uRootIndex, uNodePrevious, uNodeNext);
+ Json::Value jPeer = Json::Value(Json::objectValue);
- Log(lsINFO) << "doRippleLinesGet: previous: " << strHex(uNodePrevious);
- Log(lsINFO) << "doRippleLinesGet: next: " << strHex(uNodeNext);
- Log(lsINFO) << "doRippleLinesGet: lines: " << svRippleNodes.peekValue().size();
+ //jPeer["node"] = uNode.ToString();
- BOOST_FOREACH(uint256& uNode, svRippleNodes.peekValue())
- {
- Log(lsINFO) << "doRippleLinesGet: line index: " << uNode.ToString();
+ jPeer["account"] = line->getAccountIDPeer().humanAccountID();
+ // Amount reported is positive if current account holds other account's IOUs.
+ // Amount reported is negative if other account holds current account's IOUs.
+ jPeer["balance"] = saBalance.getText();
+ jPeer["currency"] = saBalance.getHumanCurrency();
+ jPeer["limit"] = saLimit.getText();
+ jPeer["limit_peer"] = saLimitPeer.getText();
- RippleState::pointer rsLine = mNetOps->accessRippleState(uCurrent, uNode);
-
- if (rsLine)
- {
- rsLine->setViewAccount(naAccount);
-
- STAmount saBalance = rsLine->getBalance();
- STAmount saLimit = rsLine->getLimit();
- STAmount saLimitPeer = rsLine->getLimitPeer();
-
- Json::Value jPeer = Json::Value(Json::objectValue);
-
- jPeer["node"] = uNode.ToString();
-
- jPeer["account"] = rsLine->getAccountIDPeer().humanAccountID();
- // Amount reported is positive if current account hold's other account's IOUs.
- // Amount reported is negative if other account hold's current account's IOUs.
- jPeer["balance"] = saBalance.getText();
- jPeer["currency"] = saBalance.getHumanCurrency();
- jPeer["limit"] = saLimit.getText();
- jPeer["limit_peer"] = saLimitPeer.getText();
-
- jsonLines.append(jPeer);
- }
- else
- {
- Log(lsWARNING) << "doRippleLinesGet: Bad index: " << uNode.ToString();
- }
- }
-
- if (uNodeNext)
- {
- uCurrent = Ledger::getDirNodeIndex(uRootIndex, uNodeNext);
- }
- else
- {
- bDone = true;
- }
- }
- }
- else
- {
- Log(lsINFO) << "doRippleLinesGet: no directory: " << uRootIndex.ToString();
+ jsonLines.append(jPeer);
}
ret["lines"] = jsonLines;
}
diff --git a/src/RippleLines.cpp b/src/RippleLines.cpp
new file mode 100644
index 0000000000..26e9fa827b
--- /dev/null
+++ b/src/RippleLines.cpp
@@ -0,0 +1,48 @@
+#include "RippleLines.h"
+#include "Application.h"
+#include "Log.h"
+#include
+
+RippleLines::RippleLines(const uint160& accountID, Ledger::pointer ledger)
+{
+ fillLines(accountID,ledger);
+}
+
+RippleLines::RippleLines(const uint160& accountID )
+{
+ fillLines(accountID,theApp->getMasterLedger().getCurrentLedger());
+}
+
+void RippleLines::fillLines(const uint160& accountID, Ledger::pointer ledger)
+{
+ uint256 rootIndex = Ledger::getRippleDirIndex(accountID);
+ uint256 currentIndex=rootIndex;
+
+ LedgerStateParms lspNode = lepNONE;
+
+ while(1)
+ {
+ SerializedLedgerEntry::pointer rippleDir=ledger->getDirNode(lspNode,currentIndex);
+ if(!rippleDir) return;
+
+ STVector256 svRippleNodes = rippleDir->getIFieldV256(sfIndexes);
+ BOOST_FOREACH(uint256& uNode, svRippleNodes.peekValue())
+ {
+ RippleState::pointer rsLine = ledger->accessRippleState(uNode);
+ if (rsLine)
+ {
+ rsLine->setViewAccount(accountID);
+ mLines.push_back(rsLine);
+ }
+ else
+ {
+ Log(lsWARNING) << "doRippleLinesGet: Bad index: " << uNode.ToString();
+ }
+ }
+
+ uint64 uNodeNext = rippleDir->getIFieldU64(sfIndexNext);
+ if(!uNodeNext) return;
+
+ currentIndex = Ledger::getDirNodeIndex(rootIndex, uNodeNext);
+ }
+}
diff --git a/src/RippleLines.h b/src/RippleLines.h
new file mode 100644
index 0000000000..13ea7f5dc4
--- /dev/null
+++ b/src/RippleLines.h
@@ -0,0 +1,19 @@
+#include "Ledger.h"
+#include "RippleState.h"
+
+/*
+This pulls all the ripple lines of a given account out of the ledger.
+It provides a vector so you to easily iterate through them
+*/
+
+class RippleLines
+{
+ std::vector mLines;
+ void fillLines(const uint160& accountID, Ledger::pointer ledger);
+public:
+
+ RippleLines(const uint160& accountID, Ledger::pointer ledger);
+ RippleLines(const uint160& accountID ); // looks in the current ledger
+
+ std::vector& getLines(){ return(mLines); }
+};
\ No newline at end of file
diff --git a/src/RippleState.cpp b/src/RippleState.cpp
index 0b319faab7..b4a4712d57 100644
--- a/src/RippleState.cpp
+++ b/src/RippleState.cpp
@@ -18,9 +18,9 @@ RippleState::RippleState(SerializedLedgerEntry::pointer ledgerEntry) :
mValid = true;
}
-void RippleState::setViewAccount(const NewcoinAddress& naView)
+void RippleState::setViewAccount(const uint160& accountID)
{
- bool bViewLowestNew = mLowID.getAccountID() == naView.getAccountID();
+ bool bViewLowestNew = mLowID.getAccountID() == accountID;
if (bViewLowestNew != mViewLowest)
{
diff --git a/src/RippleState.h b/src/RippleState.h
index 8efbae945f..e4b34eab41 100644
--- a/src/RippleState.h
+++ b/src/RippleState.h
@@ -32,7 +32,7 @@ private:
public:
RippleState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger
- void setViewAccount(const NewcoinAddress& naView);
+ void setViewAccount(const uint160& accountID);
const NewcoinAddress getAccountID() const { return mViewLowest ? mLowID : mHighID; }
const NewcoinAddress getAccountIDPeer() const { return mViewLowest ? mHighID : mLowID; }