add RippleLines

This commit is contained in:
jed
2012-08-15 10:35:12 -07:00
parent 463a2abc9b
commit 4f285dc603
10 changed files with 112 additions and 86 deletions

View File

@@ -50,6 +50,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>BOOST_TEST_ALTERNATIVE_INIT_API;BOOST_TEST_NO_MAIN;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\OpenSSL\include;..\boost_1_47_0;..\protobuf-2.4.1\src\</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -125,12 +126,14 @@
<ClCompile Include="src\NicknameState.cpp" />
<ClCompile Include="src\PackedMessage.cpp" />
<ClCompile Include="src\ParseSection.cpp" />
<ClCompile Include="src\Pathfinder.cpp" />
<ClCompile Include="src\Peer.cpp" />
<ClCompile Include="src\PeerDoor.cpp" />
<ClCompile Include="src\PlatRand.cpp" />
<ClCompile Include="src\PubKeyCache.cpp" />
<ClCompile Include="src\RequestParser.cpp" />
<ClCompile Include="src\rfc1751.cpp" />
<ClCompile Include="src\RippleLines.cpp" />
<ClCompile Include="src\RippleState.cpp" />
<ClCompile Include="src\rpc.cpp" />
<ClCompile Include="src\RPCCommands.cpp" />
@@ -210,11 +213,13 @@
<ClInclude Include="src\NicknameState.h" />
<ClInclude Include="src\PackedMessage.h" />
<ClInclude Include="src\ParseSection.h" />
<ClInclude Include="src\Pathfinder.h" />
<ClInclude Include="src\Peer.h" />
<ClInclude Include="src\PeerDoor.h" />
<ClInclude Include="src\PubKeyCache.h" />
<ClInclude Include="src\RequestParser.h" />
<ClInclude Include="src\rfc1751.h" />
<ClInclude Include="src\RippleLines.h" />
<ClInclude Include="src\RippleState.h" />
<ClInclude Include="src\RPC.h" />
<ClInclude Include="src\RPCCommands.h" />
@@ -259,6 +264,13 @@
<None Include="validators.txt" />
<None Include="wallet.xml" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@@ -276,6 +276,12 @@
<ClCompile Include="src\SNTPClient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Pathfinder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\RippleLines.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="KnownNodeList.h">
@@ -506,6 +512,12 @@
<ClInclude Include="src\Wallet.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Pathfinder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\RippleLines.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="wallet.xml" />

View File

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

View File

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

View File

@@ -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<unsigned char>& rawLedger);
bool findRawTransaction(const uint256& transactionHash, std::vector<unsigned char>& rawTransaction);

View File

@@ -12,6 +12,7 @@
#include "NicknameState.h"
#include "utils.h"
#include "Log.h"
#include "RippleLines.h"
#include <iostream>
@@ -1654,70 +1655,27 @@ Json::Value RPCServer::doRippleLinesGet(const Json::Value &params)
// 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;
}

48
src/RippleLines.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include "RippleLines.h"
#include "Application.h"
#include "Log.h"
#include <boost/foreach.hpp>
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);
}
}

19
src/RippleLines.h Normal file
View File

@@ -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<RippleState::pointer> 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<RippleState::pointer>& getLines(){ return(mLines); }
};

View File

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

View File

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