Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2012-11-30 17:14:31 -08:00
12 changed files with 83 additions and 15 deletions

View File

@@ -296,9 +296,9 @@ void Config::load()
if (sectionSingleB(secConfig, SECTION_LEDGER_HISTORY, strTemp))
{
boost::to_lower(strTemp);
if ((strTemp == "no") || (strTemp == "none") || (strTemp == "off") || (strTemp == "false"))
if (strTemp == "none")
LEDGER_HISTORY = 0;
else if ((strTemp == "yes") || (strTemp == "full") || (strTemp == "on") || (strTemp == "-1"))
else if (strTemp == "full")
LEDGER_HISTORY = 1000000000u;
else
LEDGER_HISTORY = boost::lexical_cast<uint32>(strTemp);

View File

@@ -1180,4 +1180,22 @@ void Ledger::decPendingSaves()
--sPendingSaves;
}
void Ledger::ownerDirDescriber(SLE::ref sle, const uint160& owner)
{
sle->setFieldAccount(sfOwner, owner);
}
void Ledger::qualityDirDescriber(SLE::ref sle,
const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuer,
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuer,
const uint64& uRate)
{
sle->setFieldH160(sfTakerPaysCurrency, uTakerPaysCurrency);
sle->setFieldH160(sfTakerPaysIssuer, uTakerPaysIssuer);
sle->setFieldH160(sfTakerGetsCurrency, uTakerGetsCurrency);
sle->setFieldH160(sfTakerGetsIssuer, uTakerGetsIssuer);
sle->setFieldU64(sfExchangeRate, uRate);
}
// vim:ts=4

View File

@@ -262,7 +262,8 @@ public:
// Directories are doubly linked lists of nodes.
// Given a directory root and and index compute the index of a node.
static uint256 getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex=0);
static uint256 getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex = 0);
static void ownerDirDescriber(SLE::ref, const uint160& owner);
// Return a node: root or normal
SLE::pointer getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex);
@@ -271,9 +272,13 @@ public:
// Quality
//
static uint256 getQualityIndex(const uint256& uBase, const uint64 uNodeDir=0);
static uint256 getQualityIndex(const uint256& uBase, const uint64 uNodeDir = 0);
static uint256 getQualityNext(const uint256& uBase);
static uint64 getQuality(const uint256& uBase);
static void qualityDirDescriber(SLE::ref,
const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuer,
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuer,
const uint64& uRate);
//
// Ripple functions : credit lines

View File

@@ -492,9 +492,10 @@ void LedgerEntrySet::calcRawMeta(Serializer& s, TER result, uint32 index)
// We only append. This allow for things that watch append only structure to just monitor from the last node on ward.
// Within a node with no deletions order of elements is sequential. Otherwise, order of elements is random.
TER LedgerEntrySet::dirAdd(
uint64& uNodeDir,
const uint256& uRootIndex,
const uint256& uLedgerIndex)
uint64& uNodeDir,
const uint256& uRootIndex,
const uint256& uLedgerIndex,
boost::function<void (SLE::ref)> fDescriber)
{
SLE::pointer sleNode;
STVector256 svIndexes;
@@ -505,6 +506,7 @@ TER LedgerEntrySet::dirAdd(
// No root, make it.
sleRoot = entryCreate(ltDIR_NODE, uRootIndex);
sleRoot->setFieldH256(sfRootIndex, uRootIndex);
fDescriber(sleRoot);
sleNode = sleRoot;
uNodeDir = 0;
@@ -566,6 +568,8 @@ TER LedgerEntrySet::dirAdd(
// Create the new node.
sleNode = entryCreate(ltDIR_NODE, Ledger::getDirNodeIndex(uRootIndex, uNodeDir));
sleNode->setFieldH256(sfRootIndex, uRootIndex);
fDescriber(sleNode);
svIndexes = STVector256();
}
}

View File

@@ -2,6 +2,7 @@
#define __LEDGERENTRYSET__
#include <boost/unordered_map.hpp>
#include <boost/function.hpp>
#include "SerializedLedger.h"
#include "TransactionMeta.h"
@@ -86,9 +87,10 @@ public:
// Directory functions.
TER dirAdd(
uint64& uNodeDir, // Node of entry.
const uint256& uRootIndex,
const uint256& uLedgerIndex);
uint64& uNodeDir, // Node of entry.
const uint256& uRootIndex,
const uint256& uLedgerIndex,
boost::function<void (SLE::ref)> fDescriber);
TER dirDelete(
const bool bKeepRoot,

View File

@@ -46,6 +46,12 @@ static bool LEFInit()
;
DECLARE_LEF(DirectoryNode, ltDIR_NODE)
<< SOElement(sfOwner, SOE_OPTIONAL) // for owner directories
<< SOElement(sfTakerPaysCurrency, SOE_OPTIONAL) // for order book directories
<< SOElement(sfTakerPaysIssuer, SOE_OPTIONAL) // for order book directories
<< SOElement(sfTakerGetsCurrency, SOE_OPTIONAL) // for order book directories
<< SOElement(sfTakerGetsIssuer, SOE_OPTIONAL) // for order book directories
<< SOElement(sfExchangeRate, SOE_OPTIONAL) // for order book directories
<< SOElement(sfIndexes, SOE_REQUIRED)
<< SOElement(sfRootIndex, SOE_REQUIRED)
<< SOElement(sfIndexNext, SOE_OPTIONAL)

View File

@@ -24,6 +24,7 @@
// there's a functional network.
SETUP_LOG();
DECLARE_INSTANCE(InfoSub);
NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster) :
mMode(omDISCONNECTED), mNeedNetworkLedger(false), mNetTimer(io_service), mLedgerMaster(pLedgerMaster),
@@ -1079,6 +1080,7 @@ Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terRes
if (bAccepted) {
jvObj["ledger_index"] = lpCurrent->getLedgerSeq();
jvObj["ledger_hash"] = lpCurrent->getHash().ToString();
jvObj["transaction"]["date"] = lpCurrent->getCloseTimeNC();
}
else
{

View File

@@ -20,7 +20,9 @@
class Peer;
class LedgerConsensus;
class InfoSub
DEFINE_INSTANCE(InfoSub);
class InfoSub : public IS_INSTANCE(InfoSub)
{
public:

View File

@@ -1,5 +1,7 @@
#include "OfferCreateTransactor.h"
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
// Take as much as possible. Adjusts account balances. Charges fees on top to taker.
// --> uBookBase: The order book to take against.
@@ -393,7 +395,9 @@ TER OfferCreateTransactor::doApply()
% saTakerGets.getFullText());
// Add offer to owner's directory.
terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex);
terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex,
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
if (tesSUCCESS == terResult)
{
@@ -409,7 +413,9 @@ TER OfferCreateTransactor::doApply()
uDirectory = Ledger::getQualityIndex(uBookBase, uRate); // Use original rate.
// Add offer to order book.
terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex);
terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex,
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
}
if (tesSUCCESS == terResult)

View File

@@ -65,6 +65,7 @@
FIELD(BookNode, UINT64, 3)
FIELD(OwnerNode, UINT64, 4)
FIELD(BaseFee, UINT64, 5)
FIELD(ExchangeRate, UINT64, 6)
// 128-bit
FIELD(EmailHash, HASH128, 1)
@@ -84,6 +85,12 @@
FIELD(InvoiceID, HASH256, 17)
FIELD(Nickname, HASH256, 18)
// 160-bit (common)
FIELD(TakerPaysCurrency, HASH160, 1)
FIELD(TakerPaysIssuer, HASH160, 2)
FIELD(TakerGetsCurrency, HASH160, 3)
FIELD(TakerGetsIssuer, HASH160, 4)
// currency amount (common)
FIELD(Amount, AMOUNT, 1)
FIELD(Balance, AMOUNT, 2)

View File

@@ -1,5 +1,7 @@
#include "TrustSetTransactor.h"
#include <boost/bind.hpp>
TER TrustSetTransactor::doApply()
{
TER terResult = tesSUCCESS;
@@ -135,10 +137,18 @@ TER TrustSetTransactor::doApply()
uint64 uSrcRef; // Ignored, dirs never delete.
terResult = mEngine->getNodes().dirAdd(uSrcRef, Ledger::getOwnerDirIndex(mTxnAccountID), sleRippleState->getIndex());
terResult = mEngine->getNodes().dirAdd(
uSrcRef,
Ledger::getOwnerDirIndex(mTxnAccountID),
sleRippleState->getIndex(),
boost::bind(&Ledger::ownerDirDescriber, _1, mTxnAccountID));
if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().dirAdd(uSrcRef, Ledger::getOwnerDirIndex(uDstAccountID), sleRippleState->getIndex());
terResult = mEngine->getNodes().dirAdd(
uSrcRef,
Ledger::getOwnerDirIndex(uDstAccountID),
sleRippleState->getIndex(),
boost::bind(&Ledger::ownerDirDescriber, _1, uDstAccountID));
}
Log(lsINFO) << "doTrustSet<";