mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
Conflicts: src/LedgerNode.cpp
This commit is contained in:
@@ -19,7 +19,8 @@ AccountState::AccountState(const NewcoinAddress& id) : mValid(false)
|
||||
mValid = true;
|
||||
}
|
||||
|
||||
AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedgerEntry(ledgerEntry), mValid(false)
|
||||
AccountState::AccountState(const SerializedLedgerEntry::pointer& ledgerEntry) :
|
||||
mLedgerEntry(ledgerEntry), mValid(false)
|
||||
{
|
||||
if (!mLedgerEntry) return;
|
||||
if (mLedgerEntry->getType() != ltACCOUNT_ROOT) return;
|
||||
|
||||
@@ -27,8 +27,8 @@ private:
|
||||
bool mValid;
|
||||
|
||||
public:
|
||||
AccountState(const NewcoinAddress& AccountID); // For new accounts
|
||||
AccountState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger
|
||||
AccountState(const NewcoinAddress& AccountID); // For new accounts
|
||||
AccountState(const SerializedLedgerEntry::pointer& ledgerEntry); // For accounts in a ledger
|
||||
|
||||
bool bHaveAuthorizedKey()
|
||||
{
|
||||
|
||||
@@ -491,18 +491,6 @@ STAmount STAmount::operator-(void) const
|
||||
return STAmount(name, mCurrency, mValue, mOffset, mIsNative, !mIsNegative);
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator=(const STAmount& a)
|
||||
{
|
||||
mValue = a.mValue;
|
||||
mOffset = a.mOffset;
|
||||
mIssuer = a.mIssuer;
|
||||
mCurrency = a.mCurrency;
|
||||
mIsNative = a.mIsNative;
|
||||
mIsNegative = a.mIsNegative;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator=(uint64 v)
|
||||
{ // does not copy name, does not change currency type
|
||||
mOffset = 0;
|
||||
|
||||
@@ -37,7 +37,7 @@ bool CanonicalTXKey::operator>=(const CanonicalTXKey& key)const
|
||||
return mTXid >= key.mTXid;
|
||||
}
|
||||
|
||||
void CanonicalTXSet::push_back(SerializedTransaction::pointer txn)
|
||||
void CanonicalTXSet::push_back(const SerializedTransaction::pointer& txn)
|
||||
{
|
||||
uint256 effectiveAccount = mSetHash;
|
||||
effectiveAccount ^= txn->getSourceAccount().getAccountID().to256();
|
||||
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
public:
|
||||
CanonicalTXSet(const uint256& lclHash) : mSetHash(lclHash) { ; }
|
||||
|
||||
void push_back(SerializedTransaction::pointer txn);
|
||||
void push_back(const SerializedTransaction::pointer& txn);
|
||||
iterator erase(const iterator& it);
|
||||
|
||||
iterator begin() { return mMap.begin(); }
|
||||
|
||||
@@ -226,7 +226,7 @@ void ConnectionPool::policyHandler(const boost::system::error_code& ecResult)
|
||||
|
||||
// YYY: Should probably do this in the background.
|
||||
// YYY: Might end up sending to disconnected peer?
|
||||
void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg)
|
||||
void ConnectionPool::relayMessage(Peer* fromPeer, const PackedMessage::pointer& msg)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mPeerLock);
|
||||
|
||||
@@ -339,7 +339,8 @@ std::vector<Peer::pointer> ConnectionPool::getPeerVector()
|
||||
|
||||
// Now know peer's node public key. Determine if we want to stay connected.
|
||||
// <-- bNew: false = redundant
|
||||
bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort)
|
||||
bool ConnectionPool::peerConnected(const Peer::pointer& peer, const NewcoinAddress& naPeer,
|
||||
const std::string& strIP, int iPort)
|
||||
{
|
||||
bool bNew = false;
|
||||
|
||||
@@ -397,7 +398,7 @@ bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& naP
|
||||
}
|
||||
|
||||
// We maintain a map of public key to peer for connected and verified peers. Maintain it.
|
||||
void ConnectionPool::peerDisconnected(Peer::pointer peer, const NewcoinAddress& naPeer)
|
||||
void ConnectionPool::peerDisconnected(const Peer::pointer& peer, const NewcoinAddress& naPeer)
|
||||
{
|
||||
if (naPeer.isValid())
|
||||
{
|
||||
@@ -484,7 +485,7 @@ bool ConnectionPool::peerScanSet(const std::string& strIp, int iPort)
|
||||
}
|
||||
|
||||
// --> strIp: not empty
|
||||
void ConnectionPool::peerClosed(Peer::pointer peer, const std::string& strIp, int iPort)
|
||||
void ConnectionPool::peerClosed(const Peer::pointer& peer, const std::string& strIp, int iPort)
|
||||
{
|
||||
ipPort ipPeer = make_pair(strIp, iPort);
|
||||
bool bScanRefresh = false;
|
||||
@@ -539,7 +540,7 @@ void ConnectionPool::peerClosed(Peer::pointer peer, const std::string& strIp, in
|
||||
scanRefresh();
|
||||
}
|
||||
|
||||
void ConnectionPool::peerVerified(Peer::pointer peer)
|
||||
void ConnectionPool::peerVerified(const Peer::pointer& peer)
|
||||
{
|
||||
if (mScanning && mScanning == peer)
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
void start();
|
||||
|
||||
// Send message to network.
|
||||
void relayMessage(Peer* fromPeer, PackedMessage::pointer msg);
|
||||
void relayMessage(Peer* fromPeer, const PackedMessage::pointer& msg);
|
||||
|
||||
// Manual connection request.
|
||||
// Queue for immediate scanning.
|
||||
@@ -72,16 +72,16 @@ public:
|
||||
|
||||
// We know peers node public key.
|
||||
// <-- bool: false=reject
|
||||
bool peerConnected(Peer::pointer peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort);
|
||||
bool peerConnected(const Peer::pointer& peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort);
|
||||
|
||||
// No longer connected.
|
||||
void peerDisconnected(Peer::pointer peer, const NewcoinAddress& naPeer);
|
||||
void peerDisconnected(const Peer::pointer& peer, const NewcoinAddress& naPeer);
|
||||
|
||||
// As client accepted.
|
||||
void peerVerified(Peer::pointer peer);
|
||||
void peerVerified(const Peer::pointer& peer);
|
||||
|
||||
// As client failed connect and be accepted.
|
||||
void peerClosed(Peer::pointer peer, const std::string& strIp, int iPort);
|
||||
void peerClosed(const Peer::pointer& peer, const std::string& strIp, int iPort);
|
||||
|
||||
Json::Value getPeersJson();
|
||||
std::vector<Peer::pointer> getPeerVector();
|
||||
@@ -98,11 +98,6 @@ public:
|
||||
void policyLowWater();
|
||||
void policyEnforce();
|
||||
|
||||
#if 0
|
||||
//std::vector<std::pair<PackedMessage::pointer,int> > mBroadcastMessages;
|
||||
|
||||
bool isMessageKnown(PackedMessage::pointer msg);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern void splitIpPort(const std::string& strIpPort, std::string& strIp, int& iPort);
|
||||
|
||||
@@ -211,7 +211,7 @@ RippleState::pointer Ledger::accessRippleState(const uint256& uNode)
|
||||
return boost::make_shared<RippleState>(sle);
|
||||
}
|
||||
|
||||
bool Ledger::addTransaction(Transaction::pointer trans)
|
||||
bool Ledger::addTransaction(const Transaction::pointer& trans)
|
||||
{ // low-level - just add to table
|
||||
assert(!mAccepted);
|
||||
assert(trans->getID().isNonZero());
|
||||
@@ -258,7 +258,7 @@ uint256 Ledger::getHash()
|
||||
return(mHash);
|
||||
}
|
||||
|
||||
void Ledger::saveAcceptedLedger(Ledger::pointer ledger)
|
||||
void Ledger::saveAcceptedLedger(const Ledger::pointer& ledger)
|
||||
{
|
||||
static boost::format ledgerExists("SELECT LedgerSeq FROM Ledgers where LedgerSeq = %d;");
|
||||
static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;");
|
||||
|
||||
12
src/Ledger.h
12
src/Ledger.h
@@ -81,7 +81,7 @@ private:
|
||||
|
||||
protected:
|
||||
|
||||
bool addTransaction(Transaction::pointer);
|
||||
bool addTransaction(const Transaction::pointer&);
|
||||
bool addTransaction(const uint256& id, const Serializer& txn);
|
||||
|
||||
static Ledger::pointer getSQL(const std::string& sqlStatement);
|
||||
@@ -156,12 +156,12 @@ public:
|
||||
|
||||
// high-level functions
|
||||
AccountState::pointer getAccountState(const NewcoinAddress& acctID);
|
||||
LedgerStateParms writeBack(LedgerStateParms parms, SLE::pointer);
|
||||
LedgerStateParms writeBack(LedgerStateParms parms, const SLE::pointer&);
|
||||
SLE::pointer getAccountRoot(const uint160& accountID);
|
||||
SLE::pointer getAccountRoot(const NewcoinAddress& naAccountID);
|
||||
|
||||
// database functions
|
||||
static void saveAcceptedLedger(Ledger::pointer);
|
||||
static void saveAcceptedLedger(const Ledger::pointer&);
|
||||
static Ledger::pointer loadByIndex(uint32 ledgerIndex);
|
||||
static Ledger::pointer loadByHash(const uint256& ledgerHash);
|
||||
|
||||
@@ -281,12 +281,6 @@ public:
|
||||
SLE::pointer getRippleState(const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
|
||||
{ return getRippleState(getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency)); }
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
bool isCompatible(boost::shared_ptr<Ledger> other);
|
||||
// bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko);
|
||||
|
||||
void addJson(Json::Value&, int options);
|
||||
|
||||
static bool unitTest();
|
||||
|
||||
@@ -257,7 +257,7 @@ void LedgerAcquire::trigger(const Peer::pointer& peer, bool timer)
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL, Peer::pointer peer)
|
||||
void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL, const Peer::pointer& peer)
|
||||
{
|
||||
if (!peer)
|
||||
sendRequest(tmGL);
|
||||
|
||||
@@ -31,7 +31,7 @@ protected:
|
||||
virtual ~PeerSet() { ; }
|
||||
|
||||
void sendRequest(const newcoin::TMGetLedger& message);
|
||||
void sendRequest(const newcoin::TMGetLedger& message, Peer::pointer peer);
|
||||
void sendRequest(const newcoin::TMGetLedger& message, const Peer::pointer& peer);
|
||||
|
||||
public:
|
||||
const uint256& getHash() const { return mHash; }
|
||||
|
||||
@@ -83,7 +83,7 @@ void TransactionAcquire::trigger(const Peer::pointer& peer, bool timer)
|
||||
}
|
||||
|
||||
bool TransactionAcquire::takeNodes(const std::list<SHAMapNode>& nodeIDs,
|
||||
const std::list< std::vector<unsigned char> >& data, Peer::pointer peer)
|
||||
const std::list< std::vector<unsigned char> >& data, const Peer::pointer& peer)
|
||||
{
|
||||
if (mComplete)
|
||||
return true;
|
||||
@@ -191,7 +191,7 @@ bool LCTransaction::updatePosition(int percentTime, bool proposing)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer previousLedger, uint32 closeTime)
|
||||
LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, const Ledger::pointer& previousLedger, uint32 closeTime)
|
||||
: mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger),
|
||||
mCurrentMSeconds(0), mClosePercent(0), mHaveCloseTimeConsensus(false)
|
||||
{
|
||||
@@ -297,7 +297,7 @@ void LedgerConsensus::takeInitialPosition(Ledger& initialLedger)
|
||||
propose(std::vector<uint256>(), std::vector<uint256>());
|
||||
}
|
||||
|
||||
void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2)
|
||||
void LedgerConsensus::createDisputes(const SHAMap::pointer& m1, const SHAMap::pointer& m2)
|
||||
{
|
||||
SHAMap::SHAMapDiff differences;
|
||||
m1->compare(m2, differences, 16384);
|
||||
@@ -317,7 +317,7 @@ void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2)
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired)
|
||||
void LedgerConsensus::mapComplete(const uint256& hash, const SHAMap::pointer& map, bool acquired)
|
||||
{
|
||||
if (acquired)
|
||||
Log(lsINFO) << "We have acquired TXS " << hash.GetHex();
|
||||
@@ -370,7 +370,7 @@ void LedgerConsensus::sendHaveTxSet(const uint256& hash, bool direct)
|
||||
theApp->getConnectionPool().relayMessage(NULL, packet);
|
||||
}
|
||||
|
||||
void LedgerConsensus::adjustCount(SHAMap::pointer map, const std::vector<uint160>& peers)
|
||||
void LedgerConsensus::adjustCount(const SHAMap::pointer& map, const std::vector<uint160>& peers)
|
||||
{ // Adjust the counts on all disputed transactions based on the set of peers taking this position
|
||||
for (boost::unordered_map<uint256, LCTransaction::pointer>::iterator it = mDisputes.begin(), end = mDisputes.end();
|
||||
it != end; ++it)
|
||||
@@ -645,7 +645,7 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void LedgerConsensus::startAcquiring(TransactionAcquire::pointer acquire)
|
||||
void LedgerConsensus::startAcquiring(const TransactionAcquire::pointer& acquire)
|
||||
{
|
||||
boost::unordered_map< uint256, std::vector< boost::weak_ptr<Peer> > >::iterator it =
|
||||
mPeerData.find(acquire->getHash());
|
||||
@@ -713,7 +713,7 @@ void LedgerConsensus::addDisputedTransaction(const uint256& txID, const std::vec
|
||||
}
|
||||
}
|
||||
|
||||
bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
|
||||
bool LedgerConsensus::peerPosition(const LedgerProposal::pointer& newPosition)
|
||||
{
|
||||
LedgerProposal::pointer& currentPosition = mPeerPositions[newPosition->getPeerID()];
|
||||
|
||||
@@ -746,7 +746,7 @@ bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, newcoin::TxSetStatus status)
|
||||
bool LedgerConsensus::peerHasSet(const Peer::pointer& peer, const uint256& hashSet, newcoin::TxSetStatus status)
|
||||
{
|
||||
if (status != newcoin::tsHAVE) // Indirect requests are for future support
|
||||
return true;
|
||||
@@ -763,7 +763,7 @@ bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, new
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerConsensus::peerGaveNodes(Peer::pointer peer, const uint256& setHash,
|
||||
bool LedgerConsensus::peerGaveNodes(const Peer::pointer& peer, const uint256& setHash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData)
|
||||
{
|
||||
boost::unordered_map<uint256, TransactionAcquire::pointer>::iterator acq = mAcquiring.find(setHash);
|
||||
@@ -791,8 +791,8 @@ void LedgerConsensus::Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::p
|
||||
This->accept(txSet);
|
||||
}
|
||||
|
||||
void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn,
|
||||
Ledger::pointer ledger, CanonicalTXSet& failedTransactions, bool final)
|
||||
void LedgerConsensus::applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn,
|
||||
const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool final)
|
||||
{
|
||||
TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL | tepMETADATA) : tepNONE;
|
||||
#ifndef TRUST_NETWORK
|
||||
@@ -824,8 +824,8 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTran
|
||||
#endif
|
||||
}
|
||||
|
||||
void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer applyLedger, Ledger::pointer checkLedger,
|
||||
CanonicalTXSet& failedTransactions, bool final)
|
||||
void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger::pointer& applyLedger,
|
||||
const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final)
|
||||
{
|
||||
TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL) : tepNONE;
|
||||
TransactionEngine engine(applyLedger);
|
||||
@@ -881,7 +881,7 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer app
|
||||
} while (successes > 0);
|
||||
}
|
||||
|
||||
void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
void LedgerConsensus::accept(const SHAMap::pointer& set)
|
||||
{
|
||||
assert(set->getHash() == mOurPosition->getCurrentHash());
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
SHAMap::pointer getMap() { return mMap; }
|
||||
|
||||
bool takeNodes(const std::list<SHAMapNode>& IDs, const std::list< std::vector<unsigned char> >& data,
|
||||
Peer::pointer);
|
||||
const Peer::pointer&);
|
||||
};
|
||||
|
||||
class LCTransaction
|
||||
@@ -113,24 +113,24 @@ protected:
|
||||
|
||||
// final accept logic
|
||||
static void Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::pointer txSet);
|
||||
void accept(SHAMap::pointer txSet);
|
||||
void accept(const SHAMap::pointer& txSet);
|
||||
|
||||
void weHave(const uint256& id, Peer::pointer avoidPeer);
|
||||
void startAcquiring(TransactionAcquire::pointer);
|
||||
void weHave(const uint256& id, const Peer::pointer& avoidPeer);
|
||||
void startAcquiring(const TransactionAcquire::pointer&);
|
||||
SHAMap::pointer find(const uint256& hash);
|
||||
|
||||
void createDisputes(SHAMap::pointer, SHAMap::pointer);
|
||||
void createDisputes(const SHAMap::pointer&, const SHAMap::pointer&);
|
||||
void addDisputedTransaction(const uint256&, const std::vector<unsigned char>& transaction);
|
||||
void adjustCount(SHAMap::pointer map, const std::vector<uint160>& peers);
|
||||
void adjustCount(const SHAMap::pointer& map, const std::vector<uint160>& peers);
|
||||
void propose(const std::vector<uint256>& addedTx, const std::vector<uint256>& removedTx);
|
||||
|
||||
void addPosition(LedgerProposal&, bool ours);
|
||||
void removePosition(LedgerProposal&, bool ours);
|
||||
void sendHaveTxSet(const uint256& set, bool direct);
|
||||
void applyTransactions(SHAMap::pointer transactionSet, Ledger::pointer targetLedger, Ledger::pointer checkLedger,
|
||||
CanonicalTXSet& failedTransactions, bool final);
|
||||
void applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn, Ledger::pointer targetLedger,
|
||||
CanonicalTXSet& failedTransactions, bool final);
|
||||
void applyTransactions(const SHAMap::pointer& transactionSet, const Ledger::pointer& targetLedger,
|
||||
const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final);
|
||||
void applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn,
|
||||
const Ledger::pointer& targetLedger, CanonicalTXSet& failedTransactions, bool final);
|
||||
|
||||
// manipulating our own position
|
||||
void statusChange(newcoin::NodeEvent, Ledger& ledger);
|
||||
@@ -141,7 +141,7 @@ protected:
|
||||
void endConsensus();
|
||||
|
||||
public:
|
||||
LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer previousLedger, uint32 closeTime);
|
||||
LedgerConsensus(const uint256& prevLCLHash, const Ledger::pointer& previousLedger, uint32 closeTime);
|
||||
|
||||
int startup();
|
||||
Json::Value getJson();
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
|
||||
SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire);
|
||||
TransactionAcquire::pointer getAcquiring(const uint256& hash);
|
||||
void mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired);
|
||||
void mapComplete(const uint256& hash, const SHAMap::pointer& map, bool acquired);
|
||||
void checkLCL();
|
||||
|
||||
void timerEntry();
|
||||
@@ -165,11 +165,11 @@ public:
|
||||
|
||||
bool haveConsensus();
|
||||
|
||||
bool peerPosition(LedgerProposal::pointer);
|
||||
bool peerPosition(const LedgerProposal::pointer&);
|
||||
|
||||
bool peerHasSet(Peer::pointer peer, const uint256& set, newcoin::TxSetStatus status);
|
||||
bool peerHasSet(const Peer::pointer& peer, const uint256& set, newcoin::TxSetStatus status);
|
||||
|
||||
bool peerGaveNodes(Peer::pointer peer, const uint256& setHash,
|
||||
bool peerGaveNodes(const Peer::pointer& peer, const uint256& setHash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData);
|
||||
};
|
||||
|
||||
|
||||
@@ -90,7 +90,8 @@ Ledger::pointer LedgerHistory::canonicalizeLedger(Ledger::pointer ledger, bool s
|
||||
if (!save)
|
||||
{ // return input ledger if not in map, otherwise, return corresponding map ledger
|
||||
Ledger::pointer ret = mLedgersByHash.fetch(h);
|
||||
if (ret) return ret;
|
||||
if (ret)
|
||||
return ret;
|
||||
return ledger;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ uint32 LedgerMaster::getCurrentLedgerIndex()
|
||||
return mCurrentLedger->getLedgerSeq();
|
||||
}
|
||||
|
||||
bool LedgerMaster::addHeldTransaction(Transaction::pointer transaction)
|
||||
bool LedgerMaster::addHeldTransaction(const Transaction::pointer& transaction)
|
||||
{ // returns true if transaction was added
|
||||
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||
return mHeldTransactionsByID.insert(std::make_pair(transaction->getID(), transaction)).second;
|
||||
}
|
||||
|
||||
void LedgerMaster::pushLedger(Ledger::pointer newLedger)
|
||||
void LedgerMaster::pushLedger(const Ledger::pointer& newLedger)
|
||||
{
|
||||
// Caller should already have properly assembled this ledger into "ready-to-close" form --
|
||||
// all candidate transactions must already be appled
|
||||
@@ -35,7 +35,7 @@ void LedgerMaster::pushLedger(Ledger::pointer newLedger)
|
||||
mEngine.setLedger(newLedger);
|
||||
}
|
||||
|
||||
void LedgerMaster::pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL)
|
||||
void LedgerMaster::pushLedger(const Ledger::pointer& newLCL, const Ledger::pointer& newOL)
|
||||
{
|
||||
assert(newLCL->isClosed() && newLCL->isAccepted());
|
||||
assert(!newOL->isClosed() && !newOL->isAccepted());
|
||||
@@ -54,7 +54,7 @@ void LedgerMaster::pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL)
|
||||
mEngine.setLedger(newOL);
|
||||
}
|
||||
|
||||
void LedgerMaster::switchLedgers(Ledger::pointer lastClosed, Ledger::pointer current)
|
||||
void LedgerMaster::switchLedgers(const Ledger::pointer& lastClosed, const Ledger::pointer& current)
|
||||
{
|
||||
assert(lastClosed && current);
|
||||
mFinalizedLedger = lastClosed;
|
||||
@@ -66,7 +66,7 @@ void LedgerMaster::switchLedgers(Ledger::pointer lastClosed, Ledger::pointer cur
|
||||
mEngine.setLedger(mCurrentLedger);
|
||||
}
|
||||
|
||||
void LedgerMaster::storeLedger(Ledger::pointer ledger)
|
||||
void LedgerMaster::storeLedger(const Ledger::pointer& ledger)
|
||||
{
|
||||
mLedgerHistory.addLedger(ledger);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ class LedgerMaster
|
||||
std::map<uint256, Transaction::pointer> mHeldTransactionsByID;
|
||||
|
||||
void applyFutureTransactions(uint32 ledgerIndex);
|
||||
bool isValidTransaction(Transaction::pointer trans);
|
||||
bool isTransactionOnFutureList(Transaction::pointer trans);
|
||||
bool isValidTransaction(const Transaction::pointer& trans);
|
||||
bool isTransactionOnFutureList(const Transaction::pointer& trans);
|
||||
|
||||
public:
|
||||
|
||||
@@ -48,11 +48,11 @@ public:
|
||||
TransactionEngineResult doTransaction(const SerializedTransaction& txn, uint32 targetLedger,
|
||||
TransactionEngineParams params);
|
||||
|
||||
void pushLedger(Ledger::pointer newLedger);
|
||||
void pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL);
|
||||
void storeLedger(Ledger::pointer);
|
||||
void pushLedger(const Ledger::pointer& newLedger);
|
||||
void pushLedger(const Ledger::pointer& newLCL, const Ledger::pointer& newOL);
|
||||
void storeLedger(const Ledger::pointer&);
|
||||
|
||||
void switchLedgers(Ledger::pointer lastClosed, Ledger::pointer newCurrent);
|
||||
void switchLedgers(const Ledger::pointer& lastClosed, const Ledger::pointer& newCurrent);
|
||||
|
||||
Ledger::pointer closeLedger();
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
return mLedgerHistory.getLedgerByHash(hash);
|
||||
}
|
||||
|
||||
bool addHeldTransaction(Transaction::pointer trans);
|
||||
bool addHeldTransaction(const Transaction::pointer& trans);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,200 @@
|
||||
|
||||
#include "Ledger.h"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include "utils.h"
|
||||
#include "Log.h"
|
||||
|
||||
// XXX Use shared locks where possible?
|
||||
|
||||
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, const SLE::pointer& entry)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
bool create = false;
|
||||
|
||||
if (!mAccountStateMap->hasItem(entry->getIndex()))
|
||||
{
|
||||
if ((parms & lepCREATE) == 0)
|
||||
{
|
||||
Log(lsERROR) << "WriteBack non-existent node without create";
|
||||
return lepMISSING;
|
||||
}
|
||||
create = true;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer item = boost::make_shared<SHAMapItem>(entry->getIndex());
|
||||
entry->add(item->peekSerializer());
|
||||
|
||||
if (create)
|
||||
{
|
||||
assert(!mAccountStateMap->hasItem(entry->getIndex()));
|
||||
if(!mAccountStateMap->addGiveItem(item, false, false)) // FIXME: TX metadata
|
||||
{
|
||||
assert(false);
|
||||
return lepERROR;
|
||||
}
|
||||
return lepCREATED;
|
||||
}
|
||||
|
||||
if (!mAccountStateMap->updateGiveItem(item, false, false)) // FIXME: TX metadata
|
||||
{
|
||||
assert(false);
|
||||
return lepERROR;
|
||||
}
|
||||
return lepOKAY;
|
||||
}
|
||||
|
||||
SLE::pointer Ledger::getSLE(const uint256& uHash)
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekItem(uHash);
|
||||
if (!node)
|
||||
return SLE::pointer();
|
||||
return boost::make_shared<SLE>(node->peekSerializer(), node->getTag());
|
||||
}
|
||||
|
||||
uint256 Ledger::getFirstLedgerIndex()
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekFirstItem();
|
||||
return node ? node->getTag() : uint256();
|
||||
}
|
||||
|
||||
uint256 Ledger::getLastLedgerIndex()
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekLastItem();
|
||||
return node ? node->getTag() : uint256();
|
||||
}
|
||||
|
||||
uint256 Ledger::getNextLedgerIndex(const uint256& uHash)
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekNextItem(uHash);
|
||||
return node ? node->getTag() : uint256();
|
||||
}
|
||||
|
||||
uint256 Ledger::getNextLedgerIndex(const uint256& uHash, const uint256& uEnd)
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekNextItem(uHash);
|
||||
if ((!node) || (node->getTag() > uEnd))
|
||||
return uint256();
|
||||
return node->getTag();
|
||||
}
|
||||
|
||||
uint256 Ledger::getPrevLedgerIndex(const uint256& uHash)
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekPrevItem(uHash);
|
||||
return node ? node->getTag() : uint256();
|
||||
}
|
||||
|
||||
uint256 Ledger::getPrevLedgerIndex(const uint256& uHash, const uint256& uBegin)
|
||||
{
|
||||
SHAMapItem::pointer node = mAccountStateMap->peekNextItem(uHash);
|
||||
if ((!node) || (node->getTag() < uBegin))
|
||||
return uint256();
|
||||
return node->getTag();
|
||||
}
|
||||
|
||||
SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
|
||||
LedgerEntryType let )
|
||||
{
|
||||
SHAMapItem::pointer account = mAccountStateMap->peekItem(nodeID);
|
||||
|
||||
if (!account)
|
||||
{
|
||||
if ( (parms & lepCREATE) == 0 )
|
||||
{
|
||||
parms = lepMISSING;
|
||||
return SLE::pointer();
|
||||
}
|
||||
|
||||
parms = parms | lepCREATED | lepOKAY;
|
||||
SLE::pointer sle=boost::make_shared<SLE>(let);
|
||||
sle->setIndex(nodeID);
|
||||
|
||||
return sle;
|
||||
}
|
||||
|
||||
SLE::pointer sle =
|
||||
boost::make_shared<SLE>(account->peekSerializer(), nodeID);
|
||||
|
||||
if (sle->getType() != let)
|
||||
{ // maybe it's a currency or something
|
||||
parms = parms | lepWRONGTYPE;
|
||||
return SLE::pointer();
|
||||
}
|
||||
|
||||
parms = parms | lepOKAY;
|
||||
|
||||
return sle;
|
||||
}
|
||||
|
||||
SLE::pointer Ledger::getAccountRoot(const uint160& accountID)
|
||||
{
|
||||
LedgerStateParms qry = lepNONE;
|
||||
|
||||
return getASNode(qry, getAccountRootIndex(accountID), ltACCOUNT_ROOT);
|
||||
}
|
||||
|
||||
SLE::pointer Ledger::getAccountRoot(const NewcoinAddress& naAccountID)
|
||||
{
|
||||
LedgerStateParms qry = lepNONE;
|
||||
|
||||
return getASNode(qry, getAccountRootIndex(naAccountID.getAccountID()), ltACCOUNT_ROOT);
|
||||
}
|
||||
|
||||
//
|
||||
// Directory
|
||||
//
|
||||
|
||||
SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, uNodeIndex, ltDIR_NODE);
|
||||
}
|
||||
|
||||
//
|
||||
// Generator Map
|
||||
//
|
||||
|
||||
SLE::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, getGeneratorIndex(uGeneratorID), ltGENERATOR_MAP);
|
||||
}
|
||||
|
||||
//
|
||||
// Nickname
|
||||
//
|
||||
|
||||
SLE::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& uNickname)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, uNickname, ltNICKNAME);
|
||||
}
|
||||
|
||||
//
|
||||
// Offer
|
||||
//
|
||||
|
||||
|
||||
SLE::pointer Ledger::getOffer(LedgerStateParms& parms, const uint256& uIndex)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, uIndex, ltOFFER);
|
||||
}
|
||||
|
||||
//
|
||||
// Ripple State
|
||||
//
|
||||
|
||||
SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, uNode, ltRIPPLE_STATE);
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -52,7 +52,7 @@ uint32 NetworkOPs::getCurrentLedgerID()
|
||||
}
|
||||
|
||||
// Sterilize transaction through serialization.
|
||||
Transaction::pointer NetworkOPs::submitTransaction(Transaction::pointer tpTrans)
|
||||
Transaction::pointer NetworkOPs::submitTransaction(const Transaction::pointer& tpTrans)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
@@ -65,6 +65,7 @@ Transaction::pointer NetworkOPs::submitTransaction(Transaction::pointer tpTrans)
|
||||
Transaction::pointer tpTransNew = Transaction::sharedTransaction(s.getData(), true);
|
||||
|
||||
assert(tpTransNew);
|
||||
assert(tpTransNew->getSTransaction()->isEquivalent(*tpTrans->getSTransaction()));
|
||||
|
||||
(void) NetworkOPs::processTransaction(tpTransNew);
|
||||
|
||||
@@ -650,7 +651,7 @@ SHAMap::pointer NetworkOPs::getTXMap(const uint256& hash)
|
||||
return mConsensus->getTransactionTree(hash, false);
|
||||
}
|
||||
|
||||
bool NetworkOPs::gotTXData(boost::shared_ptr<Peer> peer, const uint256& hash,
|
||||
bool NetworkOPs::gotTXData(const boost::shared_ptr<Peer>& peer, const uint256& hash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData)
|
||||
{
|
||||
if (!mConsensus)
|
||||
@@ -658,14 +659,14 @@ bool NetworkOPs::gotTXData(boost::shared_ptr<Peer> peer, const uint256& hash,
|
||||
return mConsensus->peerGaveNodes(peer, hash, nodeIDs, nodeData);
|
||||
}
|
||||
|
||||
bool NetworkOPs::hasTXSet(boost::shared_ptr<Peer> peer, const uint256& set, newcoin::TxSetStatus status)
|
||||
bool NetworkOPs::hasTXSet(const boost::shared_ptr<Peer>& peer, const uint256& set, newcoin::TxSetStatus status)
|
||||
{
|
||||
if (!mConsensus)
|
||||
return false;
|
||||
return mConsensus->peerHasSet(peer, set, status);
|
||||
}
|
||||
|
||||
void NetworkOPs::mapComplete(const uint256& hash, SHAMap::pointer map)
|
||||
void NetworkOPs::mapComplete(const uint256& hash, const SHAMap::pointer& map)
|
||||
{
|
||||
if (mConsensus)
|
||||
mConsensus->mapComplete(hash, map, true);
|
||||
@@ -746,7 +747,7 @@ std::vector<NewcoinAddress>
|
||||
return accounts;
|
||||
}
|
||||
|
||||
bool NetworkOPs::recvValidation(SerializedValidation::pointer val)
|
||||
bool NetworkOPs::recvValidation(const SerializedValidation::pointer& val)
|
||||
{
|
||||
Log(lsINFO) << "recvValidation " << val->getLedgerHash().GetHex();
|
||||
return theApp->getValidations().addValidation(val);
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
//
|
||||
// Transaction operations
|
||||
//
|
||||
Transaction::pointer submitTransaction(Transaction::pointer tpTrans);
|
||||
Transaction::pointer submitTransaction(const Transaction::pointer& tpTrans);
|
||||
|
||||
Transaction::pointer processTransaction(Transaction::pointer transaction, uint32 targetLedger = 0,
|
||||
Peer* source = NULL);
|
||||
@@ -161,12 +161,12 @@ public:
|
||||
// ledger proposal/close functions
|
||||
bool recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint32 closeTime,
|
||||
const std::string& pubKey, const std::string& signature);
|
||||
bool gotTXData(boost::shared_ptr<Peer> peer, const uint256& hash,
|
||||
bool gotTXData(const boost::shared_ptr<Peer>& peer, const uint256& hash,
|
||||
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData);
|
||||
bool recvValidation(SerializedValidation::pointer val);
|
||||
bool recvValidation(const SerializedValidation::pointer& val);
|
||||
SHAMap::pointer getTXMap(const uint256& hash);
|
||||
bool hasTXSet(boost::shared_ptr<Peer> peer, const uint256& set, newcoin::TxSetStatus status);
|
||||
void mapComplete(const uint256& hash, SHAMap::pointer map);
|
||||
bool hasTXSet(const boost::shared_ptr<Peer>& peer, const uint256& set, newcoin::TxSetStatus status);
|
||||
void mapComplete(const uint256& hash, const SHAMap::pointer& map);
|
||||
|
||||
// network state machine
|
||||
void checkState(const boost::system::error_code& result);
|
||||
|
||||
@@ -42,7 +42,7 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id)
|
||||
return ckp;
|
||||
}
|
||||
|
||||
CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key)
|
||||
CKey::pointer PubKeyCache::store(const NewcoinAddress& id, const CKey::pointer& key)
|
||||
{ // stored if needed, returns cached copy (possibly the original)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
@@ -51,14 +51,14 @@ CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key)
|
||||
return pit.first->second;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> pk=key->GetPubKey();
|
||||
std::vector<unsigned char> pk = key->GetPubKey();
|
||||
std::string encodedPK;
|
||||
theApp->getTxnDB()->getDB()->escape(&(pk.front()), pk.size(), encodedPK);
|
||||
|
||||
std::string sql="INSERT INTO PubKeys (ID,PubKey) VALUES ('";
|
||||
sql+=id.humanAccountID();
|
||||
sql+="',";
|
||||
sql+=encodedPK;
|
||||
std::string sql = "INSERT INTO PubKeys (ID,PubKey) VALUES ('";
|
||||
sql += id.humanAccountID();
|
||||
sql += "',";
|
||||
sql += encodedPK;
|
||||
sql.append(");");
|
||||
|
||||
ScopedLock dbl(theApp->getTxnDB()->getDBLock());
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
PubKeyCache() { ; }
|
||||
|
||||
CKey::pointer locate(const NewcoinAddress& id);
|
||||
CKey::pointer store(const NewcoinAddress& id, CKey::pointer key);
|
||||
CKey::pointer store(const NewcoinAddress& id, const CKey::pointer& key);
|
||||
void clear();
|
||||
};
|
||||
|
||||
|
||||
@@ -1315,9 +1315,9 @@ Json::Value RPCServer::doPeers(const Json::Value& params)
|
||||
}
|
||||
|
||||
// ripple <regular_seed> <paying_account>
|
||||
// <source_max> <source_currency> <source_issuerID> [noredeem] [noissue]
|
||||
// <source_max> <source_currency> [<source_issuerID>] // XXX [noredeem] [noissue]
|
||||
// <path>+
|
||||
// full|partial <dest_account> <dest_amount> <dest_currency> <dest_issuerID>
|
||||
// full|partial <dest_account> <dest_amount> <dest_currency> [<dest_issuerID>]
|
||||
//
|
||||
// path:
|
||||
// path <path_element>+
|
||||
@@ -1331,6 +1331,7 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms)
|
||||
STAmount saSrcAmountMax;
|
||||
uint160 uSrcCurrencyID;
|
||||
NewcoinAddress naSrcAccountID;
|
||||
NewcoinAddress naSrcIssuerID;
|
||||
bool bSrcRedeem = true;
|
||||
bool bSrcIssue = true;
|
||||
bool bPartial;
|
||||
@@ -1338,11 +1339,12 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms)
|
||||
NewcoinAddress naDstAccountID;
|
||||
STAmount saDstAmount;
|
||||
uint160 uDstCurrencyID;
|
||||
NewcoinAddress naDstIssuerID;
|
||||
|
||||
std::vector<paymentNode> vpnPath;
|
||||
STPathSet spsPaths;
|
||||
|
||||
naSrcIssuerID.setAccountID(params[4u].asString()); // <source_issuerID>
|
||||
|
||||
if (!naSeed.setSeedGeneric(params[0u].asString())) // <regular_seed>
|
||||
{
|
||||
return RPCError(rpcBAD_SEED);
|
||||
@@ -1351,13 +1353,18 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms)
|
||||
{
|
||||
return RPCError(rpcSRC_ACT_MALFORMED);
|
||||
}
|
||||
// <source_max> <source_currency> <source_issuerID>
|
||||
else if (!saSrcAmountMax.setFullValue(params[2u].asString(), params[3u].asString(), params[4u].asString()))
|
||||
// <source_max> <source_currency> [<source_issuerID>]
|
||||
else if (!saSrcAmountMax.setFullValue(params[2u].asString(), params[3u].asString(), params[naSrcIssuerID.isValid() ? 4u : 1u].asString()))
|
||||
{
|
||||
// Log(lsINFO) << "naSrcIssuerID.isValid(): " << naSrcIssuerID.isValid();
|
||||
// Log(lsINFO) << "source_max: " << params[2u].asString();
|
||||
// Log(lsINFO) << "source_currency: " << params[3u].asString();
|
||||
// Log(lsINFO) << "source_issuer: " << params[naSrcIssuerID.isValid() ? 4u : 2u].asString();
|
||||
|
||||
return RPCError(rpcSRC_AMT_MALFORMED);
|
||||
}
|
||||
|
||||
int iArg = 5;
|
||||
int iArg = 4 + naSrcIssuerID.isValid();
|
||||
|
||||
if (params[iArg].asString() == "noredeem") // [noredeem]
|
||||
{
|
||||
@@ -1483,14 +1490,21 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms)
|
||||
{
|
||||
return RPCError(rpcDST_ACT_MALFORMED);
|
||||
}
|
||||
|
||||
const unsigned int uDstIssuer = params.size() == iArg + 3 ? iArg+2 : iArg-1;
|
||||
|
||||
// <dest_amount> <dest_currency> <dest_issuerID>
|
||||
else if (params.size() != iArg + 3 || !saDstAmount.setFullValue(params[iArg].asString(), params[iArg+1].asString(), params[iArg+2].asString()))
|
||||
if (params.size() != iArg + 2 && params.size() != iArg + 3)
|
||||
{
|
||||
Log(lsINFO) << "params.size(): " << params.size();
|
||||
Log(lsINFO) << " iArg: " << iArg;
|
||||
Log(lsINFO) << " Amount: " << params[iArg].asString();
|
||||
Log(lsINFO) << "Currency: " << params[iArg+1].asString();
|
||||
Log(lsINFO) << " Issuer: " << params[iArg+2].asString();
|
||||
// Log(lsINFO) << "params.size(): " << params.size();
|
||||
|
||||
return RPCError(rpcDST_AMT_MALFORMED);
|
||||
}
|
||||
else if (!saDstAmount.setFullValue(params[iArg].asString(), params[iArg+1].asString(), params[uDstIssuer].asString()))
|
||||
{
|
||||
// Log(lsINFO) << " Amount: " << params[iArg].asString();
|
||||
// Log(lsINFO) << "Currency: " << params[iArg+1].asString();
|
||||
// Log(lsINFO) << " Issuer: " << params[uDstIssuer].asString();
|
||||
|
||||
return RPCError(rpcDST_AMT_MALFORMED);
|
||||
}
|
||||
@@ -1515,6 +1529,8 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms)
|
||||
// YYY Limit paths length and count.
|
||||
if (!asDst)
|
||||
{
|
||||
Log(lsINFO) << "naDstAccountID: " << naDstAccountID.humanAccountID();
|
||||
|
||||
return RPCError(rpcDST_ACT_MISSING);
|
||||
}
|
||||
|
||||
@@ -2526,7 +2542,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
|
||||
{ "password_fund", &RPCServer::doPasswordFund, 2, 3, false, optCurrent },
|
||||
{ "password_set", &RPCServer::doPasswordSet, 2, 3, false, optNetwork },
|
||||
{ "peers", &RPCServer::doPeers, 0, 0, true },
|
||||
{ "ripple", &RPCServer::doRipple, 10, -1, false, optCurrent|optClosed },
|
||||
{ "ripple", &RPCServer::doRipple, 8, -1, false, optCurrent|optClosed },
|
||||
{ "ripple_lines_get", &RPCServer::doRippleLinesGet, 1, 2, false, optCurrent },
|
||||
{ "ripple_line_set", &RPCServer::doRippleLineSet, 4, 7, false, optCurrent },
|
||||
{ "send", &RPCServer::doSend, 3, 7, false, optCurrent },
|
||||
|
||||
@@ -498,7 +498,7 @@ bool SHAMap::delItem(const uint256& id)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction, bool hasMeta)
|
||||
bool SHAMap::addGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bool hasMeta)
|
||||
{ // add the specified item, does not update
|
||||
#ifdef ST_DEBUG
|
||||
std::cerr << "aGI " << item->getTag().GetHex() << std::endl;
|
||||
@@ -596,7 +596,7 @@ bool SHAMap::addItem(const SHAMapItem& i, bool isTransaction, bool hasMetaData)
|
||||
return addGiveItem(boost::make_shared<SHAMapItem>(i), isTransaction, hasMetaData);
|
||||
}
|
||||
|
||||
bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction, bool hasMeta)
|
||||
bool SHAMap::updateGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bool hasMeta)
|
||||
{ // can't change the tag but can change the hash
|
||||
uint256 tag = item->getTag();
|
||||
|
||||
|
||||
10
src/SHAMap.h
10
src/SHAMap.h
@@ -160,7 +160,7 @@ private:
|
||||
public:
|
||||
SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node
|
||||
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
||||
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq);
|
||||
SHAMapTreeNode(const SHAMapNode& nodeID, const SHAMapItem::pointer& item, TNType type, uint32 seq);
|
||||
|
||||
// raw node functions
|
||||
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq, SHANodeFormat format);
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
bool hasItem() const { return !!mItem; }
|
||||
SHAMapItem::pointer peekItem() { return mItem; }
|
||||
SHAMapItem::pointer getItem() const;
|
||||
bool setItem(SHAMapItem::pointer& i, TNType type);
|
||||
bool setItem(const SHAMapItem::pointer& i, TNType type);
|
||||
const uint256& getTag() const { return mItem->getTag(); }
|
||||
const std::vector<unsigned char>& peekData() { return mItem->peekData(); }
|
||||
std::vector<unsigned char> getData() const { return mItem->getData(); }
|
||||
@@ -311,8 +311,8 @@ public:
|
||||
uint256 getHash() { return root->getNodeHash(); }
|
||||
|
||||
// save a copy if you have a temporary anyway
|
||||
bool updateGiveItem(SHAMapItem::pointer, bool isTransaction, bool hasMeta);
|
||||
bool addGiveItem(SHAMapItem::pointer, bool isTransaction, bool hasMeta);
|
||||
bool updateGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
|
||||
bool addGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
|
||||
|
||||
// save a copy if you only need a temporary
|
||||
SHAMapItem::pointer peekItem(const uint256& id);
|
||||
@@ -345,7 +345,7 @@ public:
|
||||
|
||||
// caution: otherMap must be accessed only by this function
|
||||
// return value: true=successfully completed, false=too different
|
||||
bool compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxCount);
|
||||
bool compare(const SHAMap::pointer& otherMap, SHAMapDiff& differences, int maxCount);
|
||||
|
||||
void armDirty();
|
||||
int flushDirty(int maxNodes, HashedObjectType t, uint32 seq);
|
||||
|
||||
@@ -91,7 +91,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxCount)
|
||||
bool SHAMap::compare(const SHAMap::pointer& otherMap, SHAMapDiff& differences, int maxCount)
|
||||
{ // compare two hash trees, add up to maxCount differences to the difference table
|
||||
// return value: true=complete table of differences given, false=too many differences
|
||||
// throws on corrupt tables or missing nodes
|
||||
|
||||
@@ -182,7 +182,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapN
|
||||
memcpy(mHashes, node.mHashes, sizeof(mHashes));
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::pointer item, TNType type, uint32 seq) :
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, const SHAMapItem::pointer& item, TNType type, uint32 seq) :
|
||||
SHAMapNode(node), mItem(item), mSeq(seq), mType(type), mFullBelow(true)
|
||||
{
|
||||
assert(item->peekData().size() >= 12);
|
||||
@@ -429,7 +429,7 @@ void SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
bool SHAMapTreeNode::setItem(SHAMapItem::pointer& i, TNType type)
|
||||
bool SHAMapTreeNode::setItem(const SHAMapItem::pointer& i, TNType type)
|
||||
{
|
||||
uint256 hash = getNodeHash();
|
||||
mType = type;
|
||||
|
||||
@@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test )
|
||||
Log(lsFATAL) << "GetNodeFat(root) fails";
|
||||
BOOST_FAIL("GetNodeFat");
|
||||
}
|
||||
if (gotNodes.size() != 1)
|
||||
if (gotNodes.size() < 1)
|
||||
{
|
||||
Log(lsFATAL) << "Didn't get root node " << gotNodes.size();
|
||||
BOOST_FAIL("NodeSize");
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "SerializedTypes.h"
|
||||
#include "SerializedObject.h"
|
||||
#include "TransactionFormats.h"
|
||||
#include "Log.h"
|
||||
#include "NewcoinAddress.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -308,7 +309,11 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name)
|
||||
if (iType == STPathElement::typeEnd || iType == STPathElement::typeBoundary)
|
||||
{
|
||||
if (path.empty())
|
||||
{
|
||||
Log(lsINFO) << "STPathSet: Empty path.";
|
||||
|
||||
throw std::runtime_error("empty path");
|
||||
}
|
||||
|
||||
paths.push_back(path);
|
||||
path.clear();
|
||||
@@ -320,13 +325,17 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name)
|
||||
}
|
||||
else if (iType & ~STPathElement::typeValidBits)
|
||||
{
|
||||
Log(lsINFO) << "STPathSet: Bad path element: " << iType;
|
||||
|
||||
throw std::runtime_error("bad path element");
|
||||
}
|
||||
else
|
||||
{
|
||||
bool bAccount = !!(iType & STPathElement::typeAccount);
|
||||
bool bCurrency = !!(iType & STPathElement::typeCurrency);
|
||||
bool bIssuer = !!(iType & STPathElement::typeIssuer);
|
||||
const bool bAccount = !!(iType & STPathElement::typeAccount);
|
||||
const bool bRedeem = !!(iType & STPathElement::typeRedeem);
|
||||
const bool bIssue = !!(iType & STPathElement::typeIssue);
|
||||
const bool bCurrency = !!(iType & STPathElement::typeCurrency);
|
||||
const bool bIssuer = !!(iType & STPathElement::typeIssuer);
|
||||
|
||||
uint160 uAccountID;
|
||||
uint160 uCurrency;
|
||||
@@ -341,7 +350,7 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name)
|
||||
if (bIssuer)
|
||||
uIssuerID = s.get160();
|
||||
|
||||
path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID));
|
||||
path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID, bRedeem, bIssue));
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
@@ -354,6 +363,8 @@ bool STPathSet::isEquivalent(const SerializedType& t) const
|
||||
|
||||
int STPathSet::getLength() const
|
||||
{
|
||||
// XXX This code is broken?
|
||||
assert(false);
|
||||
int ret = 0;
|
||||
|
||||
for (std::vector<STPath>::const_iterator it = value.begin(), end = value.end(); it != end; ++it)
|
||||
|
||||
@@ -91,6 +91,8 @@ public:
|
||||
virtual bool isEquivalent(const SerializedType& t) const
|
||||
{ assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; }
|
||||
|
||||
SerializedType& operator=(const SerializedType& t)
|
||||
{ name = (name == NULL) ? t.name : name; return *this; }
|
||||
bool operator==(const SerializedType& t) const
|
||||
{ return (getSType() == t.getSType()) && isEquivalent(t); }
|
||||
bool operator!=(const SerializedType& t) const
|
||||
@@ -124,7 +126,6 @@ public:
|
||||
void setValue(unsigned char v) { value=v; }
|
||||
|
||||
operator unsigned char() const { return value; }
|
||||
STUInt8& operator=(unsigned char v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -152,7 +153,6 @@ public:
|
||||
void setValue(uint16 v) { value=v; }
|
||||
|
||||
operator uint16() const { return value; }
|
||||
STUInt16& operator=(uint16 v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -180,7 +180,6 @@ public:
|
||||
void setValue(uint32 v) { value=v; }
|
||||
|
||||
operator uint32() const { return value; }
|
||||
STUInt32& operator=(uint32 v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -208,7 +207,6 @@ public:
|
||||
void setValue(uint64 v) { value=v; }
|
||||
|
||||
operator uint64() const { return value; }
|
||||
STUInt64& operator=(uint64 v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -335,7 +333,6 @@ public:
|
||||
|
||||
STAmount& operator+=(const STAmount&);
|
||||
STAmount& operator-=(const STAmount&);
|
||||
STAmount& operator=(const STAmount&);
|
||||
STAmount& operator+=(uint64);
|
||||
STAmount& operator-=(uint64);
|
||||
STAmount& operator=(uint64);
|
||||
@@ -402,7 +399,6 @@ public:
|
||||
void setValue(const uint128& v) { value=v; }
|
||||
|
||||
operator uint128() const { return value; }
|
||||
STHash128& operator=(const uint128& v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -432,7 +428,6 @@ public:
|
||||
void setValue(const uint160& v) { value=v; }
|
||||
|
||||
operator uint160() const { return value; }
|
||||
STHash160& operator=(const uint160& v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -462,7 +457,6 @@ public:
|
||||
void setValue(const uint256& v) { value=v; }
|
||||
|
||||
operator uint256() const { return value; }
|
||||
STHash256& operator=(const uint256& v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -495,7 +489,6 @@ public:
|
||||
void setValue(const std::vector<unsigned char>& v) { value=v; }
|
||||
|
||||
operator std::vector<unsigned char>() const { return value; }
|
||||
STVariableLength& operator=(const std::vector<unsigned char>& v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
@@ -747,7 +740,6 @@ public:
|
||||
void addItem(const TaggedListItem& v) { value.push_back(v); }
|
||||
|
||||
operator std::vector<TaggedListItem>() const { return value; }
|
||||
STTaggedList& operator=(const std::vector<TaggedListItem>& v) { value=v; return *this; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "SerializedTransaction.h"
|
||||
#include "Log.h"
|
||||
|
||||
Transaction::Transaction(const SerializedTransaction::pointer sit, bool bValidate)
|
||||
Transaction::Transaction(const SerializedTransaction::pointer& sit, bool bValidate)
|
||||
: mInLedger(0), mStatus(INVALID), mTransaction(sit)
|
||||
{
|
||||
try
|
||||
@@ -584,7 +584,7 @@ void Transaction::setStatus(TransStatus ts, uint32 lseq)
|
||||
mInLedger = lseq;
|
||||
}
|
||||
|
||||
void Transaction::saveTransaction(Transaction::pointer txn)
|
||||
void Transaction::saveTransaction(const Transaction::pointer& txn)
|
||||
{
|
||||
txn->save();
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ private:
|
||||
const std::vector<unsigned char>& vucSignature);
|
||||
|
||||
public:
|
||||
Transaction(const SerializedTransaction::pointer st, bool bValidate);
|
||||
Transaction(const SerializedTransaction::pointer& st, bool bValidate);
|
||||
|
||||
static Transaction::pointer sharedTransaction(const std::vector<unsigned char>&vucTransaction, bool bValidate);
|
||||
|
||||
@@ -288,7 +288,7 @@ public:
|
||||
void setLedger(uint32 ledger) { mInLedger = ledger; }
|
||||
|
||||
// database functions
|
||||
static void saveTransaction(Transaction::pointer);
|
||||
static void saveTransaction(const Transaction::pointer&);
|
||||
bool save();
|
||||
static Transaction::pointer load(const uint256& id);
|
||||
static Transaction::pointer findFrom(const NewcoinAddress& fromID, uint32 seq);
|
||||
|
||||
@@ -366,8 +366,8 @@ void TransactionEngine::rippleCredit(const uint160& uSenderID, const uint160& uR
|
||||
// <-- saActual: Amount actually sent. Sender pay's fees.
|
||||
STAmount TransactionEngine::rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount)
|
||||
{
|
||||
STAmount saActual;
|
||||
uint160 uIssuerID = saAmount.getIssuer();
|
||||
STAmount saActual;
|
||||
const uint160 uIssuerID = saAmount.getIssuer();
|
||||
|
||||
if (uSenderID == uIssuerID || uReceiverID == uIssuerID)
|
||||
{
|
||||
@@ -1504,15 +1504,14 @@ TransactionEngineResult TransactionEngine::doCreditSet(const SerializedTransacti
|
||||
return terNO_DST;
|
||||
}
|
||||
|
||||
bool bFlipped = mTxnAccountID > uDstAccountID; // true, iff current is not lowest.
|
||||
bool bLimitAmount = txn.getITFieldPresent(sfLimitAmount);
|
||||
STAmount saLimitAmount = bLimitAmount ? txn.getITFieldAmount(sfLimitAmount) : STAmount();
|
||||
bool bQualityIn = txn.getITFieldPresent(sfQualityIn);
|
||||
uint32 uQualityIn = bQualityIn ? txn.getITFieldU32(sfQualityIn) : 0;
|
||||
bool bQualityOut = txn.getITFieldPresent(sfQualityOut);
|
||||
uint32 uQualityOut = bQualityIn ? txn.getITFieldU32(sfQualityOut) : 0;
|
||||
uint160 uCurrencyID = saLimitAmount.getCurrency();
|
||||
STAmount saBalance(uCurrencyID);
|
||||
const bool bFlipped = mTxnAccountID > uDstAccountID; // true, iff current is not lowest.
|
||||
const bool bLimitAmount = txn.getITFieldPresent(sfLimitAmount);
|
||||
const STAmount saLimitAmount = bLimitAmount ? txn.getITFieldAmount(sfLimitAmount) : STAmount();
|
||||
const bool bQualityIn = txn.getITFieldPresent(sfQualityIn);
|
||||
const uint32 uQualityIn = bQualityIn ? txn.getITFieldU32(sfQualityIn) : 0;
|
||||
const bool bQualityOut = txn.getITFieldPresent(sfQualityOut);
|
||||
const uint32 uQualityOut = bQualityIn ? txn.getITFieldU32(sfQualityOut) : 0;
|
||||
const uint160 uCurrencyID = saLimitAmount.getCurrency();
|
||||
bool bDelIndex = false;
|
||||
|
||||
SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, Ledger::getRippleStateIndex(mTxnAccountID, uDstAccountID, uCurrencyID));
|
||||
@@ -1620,9 +1619,9 @@ TransactionEngineResult TransactionEngine::doNicknameSet(const SerializedTransac
|
||||
{
|
||||
std::cerr << "doNicknameSet>" << std::endl;
|
||||
|
||||
uint256 uNickname = txn.getITFieldH256(sfNickname);
|
||||
bool bMinOffer = txn.getITFieldPresent(sfMinimumOffer);
|
||||
STAmount saMinOffer = bMinOffer ? txn.getITFieldAmount(sfAmount) : STAmount();
|
||||
const uint256 uNickname = txn.getITFieldH256(sfNickname);
|
||||
const bool bMinOffer = txn.getITFieldPresent(sfMinimumOffer);
|
||||
const STAmount saMinOffer = bMinOffer ? txn.getITFieldAmount(sfAmount) : STAmount();
|
||||
|
||||
SLE::pointer sleNickname = entryCache(ltNICKNAME, uNickname);
|
||||
|
||||
@@ -1631,7 +1630,7 @@ TransactionEngineResult TransactionEngine::doNicknameSet(const SerializedTransac
|
||||
// Edit old entry.
|
||||
sleNickname->setIFieldAccount(sfAccount, mTxnAccountID);
|
||||
|
||||
if (bMinOffer && !saMinOffer.isZero())
|
||||
if (bMinOffer && !!saMinOffer)
|
||||
{
|
||||
sleNickname->setIFieldAmount(sfMinimumOffer, saMinOffer);
|
||||
}
|
||||
@@ -1653,7 +1652,7 @@ TransactionEngineResult TransactionEngine::doNicknameSet(const SerializedTransac
|
||||
|
||||
sleNickname->setIFieldAccount(sfAccount, mTxnAccountID);
|
||||
|
||||
if (bMinOffer && !saMinOffer.isZero())
|
||||
if (bMinOffer && !!saMinOffer)
|
||||
sleNickname->setIFieldAmount(sfMinimumOffer, saMinOffer);
|
||||
}
|
||||
|
||||
@@ -1666,7 +1665,7 @@ TransactionEngineResult TransactionEngine::doPasswordFund(const SerializedTransa
|
||||
{
|
||||
std::cerr << "doPasswordFund>" << std::endl;
|
||||
|
||||
uint160 uDstAccountID = txn.getITFieldAccount(sfDestination);
|
||||
const uint160 uDstAccountID = txn.getITFieldAccount(sfDestination);
|
||||
SLE::pointer sleDst = mTxnAccountID == uDstAccountID
|
||||
? mTxnAccount
|
||||
: entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uDstAccountID));
|
||||
@@ -1903,28 +1902,28 @@ bool TransactionEngine::calcNodeOfferRev(
|
||||
{
|
||||
bool bSuccess = false;
|
||||
|
||||
paymentNode& prvPN = pspCur->vpnNodes[uIndex-1];
|
||||
paymentNode& curPN = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& nxtPN = pspCur->vpnNodes[uIndex+1];
|
||||
paymentNode& pnPrv = pspCur->vpnNodes[uIndex-1];
|
||||
paymentNode& pnCur = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& pnNxt = pspCur->vpnNodes[uIndex+1];
|
||||
|
||||
uint160& uPrvCurrencyID = prvPN.uCurrencyID;
|
||||
uint160& uPrvIssuerID = prvPN.uIssuerID;
|
||||
uint160& uCurCurrencyID = curPN.uCurrencyID;
|
||||
uint160& uCurIssuerID = curPN.uIssuerID;
|
||||
uint160& uNxtCurrencyID = nxtPN.uCurrencyID;
|
||||
uint160& uNxtIssuerID = nxtPN.uIssuerID;
|
||||
uint160& uNxtAccountID = nxtPN.uAccountID;
|
||||
const uint160& uPrvCurrencyID = pnPrv.uCurrencyID;
|
||||
const uint160& uPrvIssuerID = pnPrv.uIssuerID;
|
||||
const uint160& uCurCurrencyID = pnCur.uCurrencyID;
|
||||
const uint160& uCurIssuerID = pnCur.uIssuerID;
|
||||
const uint160& uNxtCurrencyID = pnNxt.uCurrencyID;
|
||||
const uint160& uNxtIssuerID = pnNxt.uIssuerID;
|
||||
const uint160& uNxtAccountID = pnNxt.uAccountID;
|
||||
|
||||
STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9);
|
||||
const STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9);
|
||||
|
||||
uint256 uDirectTip = Ledger::getBookBase(uPrvCurrencyID, uPrvIssuerID, uCurCurrencyID, uCurIssuerID);
|
||||
uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip);
|
||||
const uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip);
|
||||
bool bAdvance = !entryCache(ltDIR_NODE, uDirectTip);
|
||||
|
||||
STAmount& saPrvDlvReq = prvPN.saRevDeliver; // To be adjusted.
|
||||
STAmount& saPrvDlvReq = pnPrv.saRevDeliver; // To be adjusted.
|
||||
STAmount saPrvDlvAct;
|
||||
|
||||
const STAmount& saCurDlvReq = curPN.saRevDeliver; // Reverse driver.
|
||||
const STAmount& saCurDlvReq = pnCur.saRevDeliver; // Reverse driver.
|
||||
STAmount saCurDlvAct;
|
||||
|
||||
while (!!uDirectTip // Have a quality.
|
||||
@@ -1944,6 +1943,7 @@ bool TransactionEngine::calcNodeOfferRev(
|
||||
{
|
||||
// Do a directory.
|
||||
// - Drive on computing saCurDlvAct to derive saPrvDlvAct.
|
||||
// XXX Behave well, if entry type is wrong (someone beat us to using the hash)
|
||||
SLE::pointer sleDirectDir = entryCache(ltDIR_NODE, uDirectTip);
|
||||
STAmount saOfrRate = STAmount::setRate(Ledger::getQuality(uDirectTip), uCurCurrencyID); // For correct ratio
|
||||
unsigned int uEntry = 0;
|
||||
@@ -1969,14 +1969,14 @@ bool TransactionEngine::calcNodeOfferRev(
|
||||
if (!saCurOfrFunds)
|
||||
{
|
||||
// Offer is unfunded.
|
||||
Log(lsINFO) << "calcNodeOffer: encountered unfunded offer";
|
||||
Log(lsINFO) << "calcNodeOfferRev: encountered unfunded offer";
|
||||
|
||||
// XXX Mark unfunded.
|
||||
}
|
||||
else if (sleCurOfr->getIFieldPresent(sfExpiration) && sleCurOfr->getIFieldU32(sfExpiration) <= mLedger->getParentCloseTimeNC())
|
||||
{
|
||||
// Offer is expired.
|
||||
Log(lsINFO) << "calcNodeOffer: encountered expired offer";
|
||||
Log(lsINFO) << "calcNodeOfferRev: encountered expired offer";
|
||||
|
||||
// XXX Mark unfunded.
|
||||
}
|
||||
@@ -2095,28 +2095,28 @@ bool TransactionEngine::calcNodeOfferFwd(
|
||||
{
|
||||
bool bSuccess = false;
|
||||
|
||||
paymentNode& prvPN = pspCur->vpnNodes[uIndex-1];
|
||||
paymentNode& curPN = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& nxtPN = pspCur->vpnNodes[uIndex+1];
|
||||
paymentNode& pnPrv = pspCur->vpnNodes[uIndex-1];
|
||||
paymentNode& pnCur = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& pnNxt = pspCur->vpnNodes[uIndex+1];
|
||||
|
||||
uint160& uPrvCurrencyID = prvPN.uCurrencyID;
|
||||
uint160& uPrvIssuerID = prvPN.uIssuerID;
|
||||
uint160& uCurCurrencyID = curPN.uCurrencyID;
|
||||
uint160& uCurIssuerID = curPN.uIssuerID;
|
||||
uint160& uNxtCurrencyID = nxtPN.uCurrencyID;
|
||||
uint160& uNxtIssuerID = nxtPN.uIssuerID;
|
||||
const uint160& uPrvCurrencyID = pnPrv.uCurrencyID;
|
||||
const uint160& uPrvIssuerID = pnPrv.uIssuerID;
|
||||
const uint160& uCurCurrencyID = pnCur.uCurrencyID;
|
||||
const uint160& uCurIssuerID = pnCur.uIssuerID;
|
||||
const uint160& uNxtCurrencyID = pnNxt.uCurrencyID;
|
||||
const uint160& uNxtIssuerID = pnNxt.uIssuerID;
|
||||
|
||||
uint160& uNxtAccountID = nxtPN.uAccountID;
|
||||
STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9);
|
||||
const uint160& uNxtAccountID = pnNxt.uAccountID;
|
||||
const STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9);
|
||||
|
||||
uint256 uDirectTip = Ledger::getBookBase(uPrvCurrencyID, uPrvIssuerID, uCurCurrencyID, uCurIssuerID);
|
||||
uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip);
|
||||
const uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip);
|
||||
bool bAdvance = !entryCache(ltDIR_NODE, uDirectTip);
|
||||
|
||||
STAmount& saPrvDlvReq = prvPN.saFwdDeliver; // Forward driver.
|
||||
const STAmount& saPrvDlvReq = pnPrv.saFwdDeliver; // Forward driver.
|
||||
STAmount saPrvDlvAct;
|
||||
|
||||
STAmount& saCurDlvReq = curPN.saFwdDeliver;
|
||||
STAmount& saCurDlvReq = pnCur.saFwdDeliver;
|
||||
STAmount saCurDlvAct;
|
||||
|
||||
while (!!uDirectTip // Have a quality.
|
||||
@@ -2163,22 +2163,22 @@ bool TransactionEngine::calcNodeOfferFwd(
|
||||
{
|
||||
// Next is an account.
|
||||
|
||||
STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtAccountID == uCurIssuerID
|
||||
? saOne
|
||||
: saTransferRate;
|
||||
bool bFee = saFeeRate != saOne;
|
||||
const STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtAccountID == uCurIssuerID
|
||||
? saOne
|
||||
: saTransferRate;
|
||||
const bool bFee = saFeeRate != saOne;
|
||||
|
||||
STAmount saOutPass = STAmount::divide(saCurOfrInReq, saOfrRate, uCurCurrencyID);
|
||||
STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed.
|
||||
STAmount saOutCost = MIN(
|
||||
bFee
|
||||
? STAmount::multiply(saOutBase, saFeeRate, uCurCurrencyID)
|
||||
: saOutBase,
|
||||
saCurOfrFunds); // Limit cost by fees & funds.
|
||||
STAmount saOutDlvAct = bFee
|
||||
? STAmount::divide(saOutCost, saFeeRate, uCurCurrencyID)
|
||||
: saOutCost; // Out amount after fees.
|
||||
STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uCurCurrencyID); // Compute input w/o fees required.
|
||||
const STAmount saOutPass = STAmount::divide(saCurOfrInReq, saOfrRate, uCurCurrencyID);
|
||||
const STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed.
|
||||
const STAmount saOutCost = MIN(
|
||||
bFee
|
||||
? STAmount::multiply(saOutBase, saFeeRate, uCurCurrencyID)
|
||||
: saOutBase,
|
||||
saCurOfrFunds); // Limit cost by fees & funds.
|
||||
const STAmount saOutDlvAct = bFee
|
||||
? STAmount::divide(saOutCost, saFeeRate, uCurCurrencyID)
|
||||
: saOutCost; // Out amount after fees.
|
||||
const STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uCurCurrencyID); // Compute input w/o fees required.
|
||||
|
||||
saCurDlvAct += saOutDlvAct; // Portion of driver served.
|
||||
saPrvDlvAct += saInDlvAct; // Portion needed in previous.
|
||||
@@ -2188,7 +2188,7 @@ bool TransactionEngine::calcNodeOfferFwd(
|
||||
// Next is an offer.
|
||||
|
||||
uint256 uNxtTip = Ledger::getBookBase(uCurCurrencyID, uCurIssuerID, uNxtCurrencyID, uNxtIssuerID);
|
||||
uint256 uNxtEnd = Ledger::getQualityNext(uNxtTip);
|
||||
const uint256 uNxtEnd = Ledger::getQualityNext(uNxtTip);
|
||||
bool bNxtAdvance = !entryCache(ltDIR_NODE, uNxtTip);
|
||||
|
||||
while (!!uNxtTip // Have a quality.
|
||||
@@ -2217,30 +2217,30 @@ bool TransactionEngine::calcNodeOfferFwd(
|
||||
{
|
||||
// YYY This could combine offers with the same fee before doing math.
|
||||
SLE::pointer sleNxtOfr = entryCache(ltOFFER, uNxtIndex);
|
||||
uint160 uNxtOfrAccountID = sleNxtOfr->getIValueFieldAccount(sfAccount).getAccountID();
|
||||
const uint160 uNxtOfrAccountID = sleNxtOfr->getIValueFieldAccount(sfAccount).getAccountID();
|
||||
STAmount saNxtOfrIn = sleNxtOfr->getIValueFieldAmount(sfTakerPays);
|
||||
// XXX Move issuer into STAmount
|
||||
if (sleNxtOfr->getIFieldPresent(sfPaysIssuer))
|
||||
saNxtOfrIn.setIssuer(sleCurOfr->getIValueFieldAccount(sfPaysIssuer).getAccountID());
|
||||
|
||||
STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtOfrAccountID == uCurIssuerID
|
||||
? saOne
|
||||
: saTransferRate;
|
||||
bool bFee = saFeeRate != saOne;
|
||||
const STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtOfrAccountID == uCurIssuerID
|
||||
? saOne
|
||||
: saTransferRate;
|
||||
const bool bFee = saFeeRate != saOne;
|
||||
|
||||
STAmount saInBase = saCurOfrInReq-saCurOfrInAct;
|
||||
STAmount saOutPass = STAmount::divide(saInBase, saOfrRate, uCurCurrencyID);
|
||||
STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed.
|
||||
saOutBase = MIN(saOutBase, saNxtOfrIn); // Limit offer out by supplying offer.
|
||||
STAmount saOutCost = MIN(
|
||||
const STAmount saInBase = saCurOfrInReq-saCurOfrInAct;
|
||||
const STAmount saOutPass = STAmount::divide(saInBase, saOfrRate, uCurCurrencyID);
|
||||
STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed.
|
||||
saOutBase = MIN(saOutBase, saNxtOfrIn); // Limit offer out by supplying offer.
|
||||
const STAmount saOutCost = MIN(
|
||||
bFee
|
||||
? STAmount::multiply(saOutBase, saFeeRate, uCurCurrencyID)
|
||||
: saOutBase,
|
||||
saCurOfrFunds); // Limit cost by fees & funds.
|
||||
STAmount saOutDlvAct = bFee
|
||||
const STAmount saOutDlvAct = bFee
|
||||
? STAmount::divide(saOutCost, saFeeRate, uCurCurrencyID)
|
||||
: saOutCost; // Out amount after fees.
|
||||
STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uPrvCurrencyID); // Compute input w/o fees required.
|
||||
const STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uPrvCurrencyID); // Compute input w/o fees required.
|
||||
|
||||
saCurOfrInAct += saOutDlvAct; // Portion of driver served.
|
||||
saPrvDlvAct += saOutDlvAct; // Portion needed in previous.
|
||||
@@ -2525,9 +2525,9 @@ void TransactionEngine::calcNodeRipple(
|
||||
|
||||
assert(saPrvReq.getCurrency() == saCurReq.getCurrency());
|
||||
|
||||
bool bPrvUnlimited = saPrvReq.isNegative();
|
||||
STAmount saPrv = bPrvUnlimited ? STAmount(saPrvReq) : saPrvReq-saPrvAct;
|
||||
STAmount saCur = saCurReq-saCurAct;
|
||||
const bool bPrvUnlimited = saPrvReq.isNegative();
|
||||
const STAmount saPrv = bPrvUnlimited ? STAmount(saPrvReq) : saPrvReq-saPrvAct;
|
||||
const STAmount saCur = saCurReq-saCurAct;
|
||||
|
||||
#if 0
|
||||
Log(lsINFO) << str(boost::format("calcNodeRipple: bPrvUnlimited=%d saPrv=%s saCur=%s")
|
||||
@@ -2587,24 +2587,24 @@ Log(lsINFO) << str(boost::format("calcNodeRipple:4: saCurReq=%s") % saCurReq.get
|
||||
bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality)
|
||||
{
|
||||
bool bSuccess = true;
|
||||
unsigned int uLast = pspCur->vpnNodes.size() - 1;
|
||||
const unsigned int uLast = pspCur->vpnNodes.size() - 1;
|
||||
|
||||
paymentNode& prvPN = pspCur->vpnNodes[uIndex ? uIndex-1 : 0];
|
||||
paymentNode& curPN = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& nxtPN = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1];
|
||||
paymentNode& pnPrv = pspCur->vpnNodes[uIndex ? uIndex-1 : 0];
|
||||
paymentNode& pnCur = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& pnNxt = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1];
|
||||
|
||||
bool bRedeem = !!(curPN.uFlags & STPathElement::typeRedeem);
|
||||
bool bPrvRedeem = !!(prvPN.uFlags & STPathElement::typeRedeem);
|
||||
bool bIssue = !!(curPN.uFlags & STPathElement::typeIssue);
|
||||
bool bPrvIssue = !!(prvPN.uFlags & STPathElement::typeIssue);
|
||||
bool bPrvAccount = !uIndex || !!(prvPN.uFlags & STPathElement::typeAccount);
|
||||
bool bNxtAccount = uIndex == uLast || !!(nxtPN.uFlags & STPathElement::typeAccount);
|
||||
const bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem);
|
||||
const bool bPrvRedeem = !!(pnPrv.uFlags & STPathElement::typeRedeem);
|
||||
const bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue);
|
||||
const bool bPrvIssue = !!(pnPrv.uFlags & STPathElement::typeIssue);
|
||||
const bool bPrvAccount = !uIndex || !!(pnPrv.uFlags & STPathElement::typeAccount);
|
||||
const bool bNxtAccount = uIndex == uLast || !!(pnNxt.uFlags & STPathElement::typeAccount);
|
||||
|
||||
const uint160& uPrvAccountID = prvPN.uAccountID;
|
||||
const uint160& uCurAccountID = curPN.uAccountID;
|
||||
const uint160& uNxtAccountID = bNxtAccount ? nxtPN.uAccountID : uCurAccountID; // Offers are always issue.
|
||||
const uint160& uPrvAccountID = pnPrv.uAccountID;
|
||||
const uint160& uCurAccountID = pnCur.uAccountID;
|
||||
const uint160& uNxtAccountID = bNxtAccount ? pnNxt.uAccountID : uCurAccountID; // Offers are always issue.
|
||||
|
||||
const uint160& uCurrencyID = curPN.uCurrencyID;
|
||||
const uint160& uCurrencyID = pnCur.uCurrencyID;
|
||||
|
||||
const uint32 uQualityIn = uIndex ? rippleQualityIn(uCurAccountID, uPrvAccountID, uCurrencyID) : 1;
|
||||
const uint32 uQualityOut = uIndex != uLast ? rippleQualityOut(uCurAccountID, uNxtAccountID, uCurrencyID) : 1;
|
||||
@@ -2614,24 +2614,24 @@ bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::point
|
||||
const STAmount saPrvLimit = uIndex && bPrvAccount ? rippleLimit(uCurAccountID, uPrvAccountID, uCurrencyID) : STAmount(uCurrencyID);
|
||||
|
||||
const STAmount saPrvRedeemReq = bPrvRedeem && saPrvBalance.isNegative() ? -saPrvBalance : STAmount(uCurrencyID, 0);
|
||||
STAmount& saPrvRedeemAct = prvPN.saRevRedeem;
|
||||
STAmount& saPrvRedeemAct = pnPrv.saRevRedeem;
|
||||
|
||||
const STAmount saPrvIssueReq = bPrvIssue ? saPrvLimit - saPrvBalance : STAmount(uCurrencyID);
|
||||
STAmount& saPrvIssueAct = prvPN.saRevIssue;
|
||||
STAmount& saPrvIssueAct = pnPrv.saRevIssue;
|
||||
|
||||
// For !bPrvAccount
|
||||
const STAmount saPrvDeliverReq = STAmount(uCurrencyID, -1); // Unlimited.
|
||||
STAmount& saPrvDeliverAct = prvPN.saRevDeliver;
|
||||
STAmount& saPrvDeliverAct = pnPrv.saRevDeliver;
|
||||
|
||||
// For bNxtAccount
|
||||
const STAmount& saCurRedeemReq = curPN.saRevRedeem;
|
||||
const STAmount& saCurRedeemReq = pnCur.saRevRedeem;
|
||||
STAmount saCurRedeemAct(saCurRedeemReq.getCurrency());
|
||||
|
||||
const STAmount& saCurIssueReq = curPN.saRevIssue;
|
||||
const STAmount& saCurIssueReq = pnCur.saRevIssue;
|
||||
STAmount saCurIssueAct(saCurIssueReq.getCurrency()); // Track progress.
|
||||
|
||||
// For !bNxtAccount
|
||||
const STAmount& saCurDeliverReq = curPN.saRevDeliver;
|
||||
const STAmount& saCurDeliverReq = pnCur.saRevDeliver;
|
||||
STAmount saCurDeliverAct(saCurDeliverReq.getCurrency());
|
||||
|
||||
// For uIndex == uLast
|
||||
@@ -2881,47 +2881,47 @@ bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::point
|
||||
bool TransactionEngine::calcNodeAccountFwd(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality)
|
||||
{
|
||||
bool bSuccess = true;
|
||||
unsigned int uLast = pspCur->vpnNodes.size() - 1;
|
||||
const unsigned int uLast = pspCur->vpnNodes.size() - 1;
|
||||
|
||||
paymentNode& prvPN = pspCur->vpnNodes[uIndex ? uIndex-1 : 0];
|
||||
paymentNode& curPN = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& nxtPN = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1];
|
||||
paymentNode& pnPrv = pspCur->vpnNodes[uIndex ? uIndex-1 : 0];
|
||||
paymentNode& pnCur = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& pnNxt = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1];
|
||||
|
||||
bool bRedeem = !!(curPN.uFlags & STPathElement::typeRedeem);
|
||||
bool bIssue = !!(curPN.uFlags & STPathElement::typeIssue);
|
||||
bool bPrvAccount = !!(prvPN.uFlags & STPathElement::typeAccount);
|
||||
bool bNxtAccount = !!(nxtPN.uFlags & STPathElement::typeAccount);
|
||||
const bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem);
|
||||
const bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue);
|
||||
const bool bPrvAccount = !!(pnPrv.uFlags & STPathElement::typeAccount);
|
||||
const bool bNxtAccount = !!(pnNxt.uFlags & STPathElement::typeAccount);
|
||||
|
||||
uint160& uPrvAccountID = prvPN.uAccountID;
|
||||
uint160& uCurAccountID = curPN.uAccountID;
|
||||
uint160& uNxtAccountID = bNxtAccount ? nxtPN.uAccountID : uCurAccountID; // Offers are always issue.
|
||||
const uint160& uPrvAccountID = pnPrv.uAccountID;
|
||||
const uint160& uCurAccountID = pnCur.uAccountID;
|
||||
const uint160& uNxtAccountID = bNxtAccount ? pnNxt.uAccountID : uCurAccountID; // Offers are always issue.
|
||||
|
||||
uint160& uCurrencyID = curPN.uCurrencyID;
|
||||
const uint160& uCurrencyID = pnCur.uCurrencyID;
|
||||
|
||||
uint32 uQualityIn = rippleQualityIn(uCurAccountID, uPrvAccountID, uCurrencyID);
|
||||
uint32 uQualityOut = rippleQualityOut(uCurAccountID, uNxtAccountID, uCurrencyID);
|
||||
|
||||
// For bNxtAccount
|
||||
const STAmount& saPrvRedeemReq = prvPN.saFwdRedeem;
|
||||
const STAmount& saPrvRedeemReq = pnPrv.saFwdRedeem;
|
||||
STAmount saPrvRedeemAct(saPrvRedeemReq.getCurrency());
|
||||
|
||||
const STAmount& saPrvIssueReq = prvPN.saFwdIssue;
|
||||
const STAmount& saPrvIssueReq = pnPrv.saFwdIssue;
|
||||
STAmount saPrvIssueAct(saPrvIssueReq.getCurrency());
|
||||
|
||||
// For !bPrvAccount
|
||||
const STAmount& saPrvDeliverReq = prvPN.saRevDeliver;
|
||||
const STAmount& saPrvDeliverReq = pnPrv.saRevDeliver;
|
||||
STAmount saPrvDeliverAct(saPrvDeliverReq.getCurrency());
|
||||
|
||||
// For bNxtAccount
|
||||
const STAmount& saCurRedeemReq = curPN.saRevRedeem;
|
||||
STAmount& saCurRedeemAct = curPN.saFwdRedeem;
|
||||
const STAmount& saCurRedeemReq = pnCur.saRevRedeem;
|
||||
STAmount& saCurRedeemAct = pnCur.saFwdRedeem;
|
||||
|
||||
const STAmount& saCurIssueReq = curPN.saRevIssue;
|
||||
STAmount& saCurIssueAct = curPN.saFwdIssue;
|
||||
const STAmount& saCurIssueReq = pnCur.saRevIssue;
|
||||
STAmount& saCurIssueAct = pnCur.saFwdIssue;
|
||||
|
||||
// For !bNxtAccount
|
||||
const STAmount& saCurDeliverReq = curPN.saRevDeliver;
|
||||
STAmount& saCurDeliverAct = curPN.saFwdDeliver;
|
||||
const STAmount& saCurDeliverReq = pnCur.saRevDeliver;
|
||||
STAmount& saCurDeliverAct = pnCur.saFwdDeliver;
|
||||
|
||||
STAmount& saCurReceive = pspCur->saOutAct;
|
||||
|
||||
@@ -2945,14 +2945,14 @@ bool TransactionEngine::calcNodeAccountFwd(unsigned int uIndex, PathState::point
|
||||
|
||||
// First node, calculate amount to send.
|
||||
// XXX Use stamp/ripple balance
|
||||
paymentNode& curPN = pspCur->vpnNodes[uIndex];
|
||||
paymentNode& pnCur = pspCur->vpnNodes[uIndex];
|
||||
|
||||
STAmount& saCurRedeemReq = curPN.saRevRedeem;
|
||||
STAmount& saCurRedeemAct = curPN.saFwdRedeem;
|
||||
STAmount& saCurIssueReq = curPN.saRevIssue;
|
||||
STAmount& saCurIssueAct = curPN.saFwdIssue;
|
||||
const STAmount& saCurRedeemReq = pnCur.saRevRedeem;
|
||||
STAmount& saCurRedeemAct = pnCur.saFwdRedeem;
|
||||
const STAmount& saCurIssueReq = pnCur.saRevIssue;
|
||||
STAmount& saCurIssueAct = pnCur.saFwdIssue;
|
||||
|
||||
STAmount& saCurSendMaxReq = pspCur->saInReq; // Negative for no limit, doing a calculation.
|
||||
const STAmount& saCurSendMaxReq = pspCur->saInReq; // Negative for no limit, doing a calculation.
|
||||
STAmount& saCurSendMaxAct = pspCur->saInAct; // Report to user how much this sends.
|
||||
|
||||
if (saCurRedeemReq)
|
||||
@@ -3223,20 +3223,20 @@ bool PathState::pushNode(int iType, uint160 uAccountID, uint160 uCurrencyID, uin
|
||||
<< NewcoinAddress::createHumanAccountID(uAccountID)
|
||||
<< " " << STAmount::createHumanCurrency(uCurrencyID)
|
||||
<< " " << NewcoinAddress::createHumanAccountID(uIssuerID);
|
||||
paymentNode pnCur;
|
||||
bool bFirst = vpnNodes.empty();
|
||||
const paymentNode& pnPrv = bFirst ? paymentNode() : vpnNodes.back();
|
||||
// true, iff node is a ripple account. false, iff node is an offer node.
|
||||
bool bAccount = !!(iType & STPathElement::typeAccount);
|
||||
// true, iff currency supplied.
|
||||
// Currency is specified for the output of the current node.
|
||||
bool bCurrency = !!(iType & STPathElement::typeCurrency);
|
||||
// Issuer is specified for the output of the current node.
|
||||
bool bIssuer = !!(iType & STPathElement::typeIssuer);
|
||||
// true, iff account is allowed to redeem it's IOUs to next node.
|
||||
bool bRedeem = !!(iType & STPathElement::typeRedeem);
|
||||
bool bIssue = !!(iType & STPathElement::typeIssue);
|
||||
bool bValid = true;
|
||||
paymentNode pnCur;
|
||||
const bool bFirst = vpnNodes.empty();
|
||||
const paymentNode& pnPrv = bFirst ? paymentNode() : vpnNodes.back();
|
||||
// true, iff node is a ripple account. false, iff node is an offer node.
|
||||
const bool bAccount = !!(iType & STPathElement::typeAccount);
|
||||
// true, iff currency supplied.
|
||||
// Currency is specified for the output of the current node.
|
||||
const bool bCurrency = !!(iType & STPathElement::typeCurrency);
|
||||
// Issuer is specified for the output of the current node.
|
||||
const bool bIssuer = !!(iType & STPathElement::typeIssuer);
|
||||
// true, iff account is allowed to redeem it's IOUs to next node.
|
||||
const bool bRedeem = !!(iType & STPathElement::typeRedeem);
|
||||
const bool bIssue = !!(iType & STPathElement::typeIssue);
|
||||
bool bValid = true;
|
||||
|
||||
pnCur.uFlags = iType;
|
||||
|
||||
@@ -3379,10 +3379,10 @@ PathState::PathState(
|
||||
)
|
||||
: mLedger(lpLedger), mIndex(iIndex), uQuality(0)
|
||||
{
|
||||
uint160 uInCurrencyID = saSendMax.getCurrency();
|
||||
uint160 uOutCurrencyID = saSend.getCurrency();
|
||||
uint160 uInIssuerID = !!uInCurrencyID ? uSenderID : ACCOUNT_XNS;
|
||||
uint160 uOutIssuerID = !!uOutCurrencyID ? uReceiverID : ACCOUNT_XNS;
|
||||
const uint160 uInCurrencyID = saSendMax.getCurrency();
|
||||
const uint160 uOutCurrencyID = saSend.getCurrency();
|
||||
const uint160 uInIssuerID = !!uInCurrencyID ? uSenderID : ACCOUNT_XNS;
|
||||
const uint160 uOutIssuerID = !!uOutCurrencyID ? uReceiverID : ACCOUNT_XNS;
|
||||
|
||||
lesEntries = lesSource.duplicate();
|
||||
|
||||
@@ -3512,9 +3512,9 @@ Json::Value PathState::getJson() const
|
||||
// XXX Disallow looping.
|
||||
bool TransactionEngine::calcNode(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality)
|
||||
{
|
||||
paymentNode& curPN = pspCur->vpnNodes[uIndex];
|
||||
bool bCurAccount = !!(curPN.uFlags & STPathElement::typeAccount);
|
||||
bool bValid;
|
||||
const paymentNode& pnCur = pspCur->vpnNodes[uIndex];
|
||||
const bool bCurAccount = !!(pnCur.uFlags & STPathElement::typeAccount);
|
||||
bool bValid;
|
||||
|
||||
// Do current node reverse.
|
||||
bValid = bCurAccount
|
||||
@@ -3570,17 +3570,17 @@ void TransactionEngine::pathNext(PathState::pointer pspCur, int iPaths)
|
||||
TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction& txn)
|
||||
{
|
||||
// Ripple if source or destination is non-native or if there are paths.
|
||||
uint32 uTxFlags = txn.getFlags();
|
||||
bool bCreate = !!(uTxFlags & tfCreateAccount);
|
||||
bool bNoRippleDirect = !!(uTxFlags & tfNoRippleDirect);
|
||||
bool bPartialPayment = !!(uTxFlags & tfPartialPayment);
|
||||
bool bPaths = txn.getITFieldPresent(sfPaths);
|
||||
bool bMax = txn.getITFieldPresent(sfSendMax);
|
||||
uint160 uDstAccountID = txn.getITFieldAccount(sfDestination);
|
||||
STAmount saDstAmount = txn.getITFieldAmount(sfAmount);
|
||||
STAmount saMaxAmount = bMax ? txn.getITFieldAmount(sfSendMax) : saDstAmount;
|
||||
uint160 uSrcCurrency = saMaxAmount.getCurrency();
|
||||
uint160 uDstCurrency = saDstAmount.getCurrency();
|
||||
const uint32 uTxFlags = txn.getFlags();
|
||||
const bool bCreate = !!(uTxFlags & tfCreateAccount);
|
||||
const bool bNoRippleDirect = !!(uTxFlags & tfNoRippleDirect);
|
||||
const bool bPartialPayment = !!(uTxFlags & tfPartialPayment);
|
||||
const bool bPaths = txn.getITFieldPresent(sfPaths);
|
||||
const bool bMax = txn.getITFieldPresent(sfSendMax);
|
||||
const uint160 uDstAccountID = txn.getITFieldAccount(sfDestination);
|
||||
const STAmount saDstAmount = txn.getITFieldAmount(sfAmount);
|
||||
const STAmount saMaxAmount = bMax ? txn.getITFieldAmount(sfSendMax) : saDstAmount;
|
||||
const uint160 uSrcCurrency = saMaxAmount.getCurrency();
|
||||
const uint160 uDstCurrency = saDstAmount.getCurrency();
|
||||
|
||||
if (!uDstAccountID)
|
||||
{
|
||||
@@ -3774,8 +3774,10 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction
|
||||
if (!bNoRippleDirect)
|
||||
{
|
||||
// Direct path.
|
||||
// XXX Might also make a stamp bridge by default.
|
||||
Log(lsINFO) << "doPayment: Build direct:";
|
||||
vpsPaths.push_back(PathState::createPathState(
|
||||
|
||||
PathState::pointer pspDirect = PathState::createPathState(
|
||||
mLedger,
|
||||
vpsPaths.size(),
|
||||
mNodes,
|
||||
@@ -3784,14 +3786,19 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction
|
||||
mTxnAccountID,
|
||||
saDstAmount,
|
||||
saMaxAmount,
|
||||
bPartialPayment
|
||||
));
|
||||
bPartialPayment);
|
||||
|
||||
if (pspDirect)
|
||||
vpsPaths.push_back(pspDirect);
|
||||
}
|
||||
|
||||
Log(lsINFO) << "doPayment: Paths: " << spsPaths.getPathCount();
|
||||
|
||||
BOOST_FOREACH(const STPath& spPath, spsPaths)
|
||||
{
|
||||
Log(lsINFO) << "doPayment: Build path:";
|
||||
vpsPaths.push_back(PathState::createPathState(
|
||||
|
||||
PathState::pointer pspExpanded = PathState::createPathState(
|
||||
mLedger,
|
||||
vpsPaths.size(),
|
||||
mNodes,
|
||||
@@ -3800,8 +3807,10 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction
|
||||
mTxnAccountID,
|
||||
saDstAmount,
|
||||
saMaxAmount,
|
||||
bPartialPayment
|
||||
));
|
||||
bPartialPayment);
|
||||
|
||||
if (pspExpanded)
|
||||
vpsPaths.push_back(pspExpanded);
|
||||
}
|
||||
|
||||
TransactionEngineResult terResult;
|
||||
@@ -3877,15 +3886,15 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti
|
||||
{
|
||||
std::cerr << "WalletAdd>" << std::endl;
|
||||
|
||||
std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
|
||||
std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
|
||||
uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey);
|
||||
NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey);
|
||||
uint160 uDstAccountID = naMasterPubKey.getAccountID();
|
||||
const std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
|
||||
const std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
|
||||
const uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey);
|
||||
const NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey);
|
||||
const uint160 uDstAccountID = naMasterPubKey.getAccountID();
|
||||
|
||||
if (!naMasterPubKey.accountPublicVerify(Serializer::getSHA512Half(uAuthKeyID.begin(), uAuthKeyID.size()), vucSignature))
|
||||
{
|
||||
std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl;
|
||||
std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl;
|
||||
|
||||
return tenBAD_ADD_AUTH;
|
||||
}
|
||||
@@ -3957,12 +3966,12 @@ TransactionEngineResult TransactionEngine::takeOffers(
|
||||
Log(lsINFO) << "takeOffers: against book: " << uBookBase.ToString();
|
||||
|
||||
uint256 uTipIndex = uBookBase;
|
||||
uint256 uBookEnd = Ledger::getQualityNext(uBookBase);
|
||||
uint64 uTakeQuality = STAmount::getRate(saTakerGets, saTakerPays);
|
||||
uint160 uTakerPaysAccountID = saTakerPays.getIssuer();
|
||||
uint160 uTakerPaysCurrency = saTakerPays.getCurrency();
|
||||
uint160 uTakerGetsAccountID = saTakerGets.getIssuer();
|
||||
uint160 uTakerGetsCurrency = saTakerGets.getCurrency();
|
||||
const uint256 uBookEnd = Ledger::getQualityNext(uBookBase);
|
||||
const uint64 uTakeQuality = STAmount::getRate(saTakerGets, saTakerPays);
|
||||
const uint160 uTakerPaysAccountID = saTakerPays.getIssuer();
|
||||
const uint160 uTakerPaysCurrency = saTakerPays.getCurrency();
|
||||
const uint160 uTakerGetsAccountID = saTakerGets.getIssuer();
|
||||
const uint160 uTakerGetsCurrency = saTakerGets.getCurrency();
|
||||
TransactionEngineResult terResult = tenUNKNOWN;
|
||||
|
||||
saTakerPaid = 0;
|
||||
@@ -4017,7 +4026,7 @@ TransactionEngineResult TransactionEngine::takeOffers(
|
||||
|
||||
Log(lsINFO) << "takeOffers: considering offer : " << sleOffer->getJson(0);
|
||||
|
||||
uint160 uOfferOwnerID = sleOffer->getIValueFieldAccount(sfAccount).getAccountID();
|
||||
const uint160 uOfferOwnerID = sleOffer->getIValueFieldAccount(sfAccount).getAccountID();
|
||||
STAmount saOfferPays = sleOffer->getIValueFieldAmount(sfTakerGets);
|
||||
STAmount saOfferGets = sleOffer->getIValueFieldAmount(sfTakerPays);
|
||||
|
||||
@@ -4138,28 +4147,28 @@ TransactionEngineResult TransactionEngine::takeOffers(
|
||||
TransactionEngineResult TransactionEngine::doOfferCreate(const SerializedTransaction& txn)
|
||||
{
|
||||
Log(lsWARNING) << "doOfferCreate> " << txn.getJson(0);
|
||||
uint32 txFlags = txn.getFlags();
|
||||
bool bPassive = !!(txFlags & tfPassive);
|
||||
uint160 uPaysIssuerID = txn.getITFieldAccount(sfPaysIssuer);
|
||||
uint160 uGetsIssuerID = txn.getITFieldAccount(sfGetsIssuer);
|
||||
STAmount saTakerPays = txn.getITFieldAmount(sfTakerPays);
|
||||
const uint32 txFlags = txn.getFlags();
|
||||
const bool bPassive = !!(txFlags & tfPassive);
|
||||
const uint160 uPaysIssuerID = txn.getITFieldAccount(sfPaysIssuer);
|
||||
const uint160 uGetsIssuerID = txn.getITFieldAccount(sfGetsIssuer);
|
||||
STAmount saTakerPays = txn.getITFieldAmount(sfTakerPays);
|
||||
saTakerPays.setIssuer(uPaysIssuerID);
|
||||
Log(lsWARNING) << "doOfferCreate: saTakerPays=" << saTakerPays.getFullText();
|
||||
STAmount saTakerGets = txn.getITFieldAmount(sfTakerGets);
|
||||
saTakerGets.setIssuer(uGetsIssuerID);
|
||||
Log(lsWARNING) << "doOfferCreate: saTakerGets=" << saTakerGets.getFullText();
|
||||
uint32 uExpiration = txn.getITFieldU32(sfExpiration);
|
||||
bool bHaveExpiration = txn.getITFieldPresent(sfExpiration);
|
||||
uint32 uSequence = txn.getSequence();
|
||||
const uint32 uExpiration = txn.getITFieldU32(sfExpiration);
|
||||
const bool bHaveExpiration = txn.getITFieldPresent(sfExpiration);
|
||||
const uint32 uSequence = txn.getSequence();
|
||||
|
||||
uint256 uLedgerIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence);
|
||||
const uint256 uLedgerIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence);
|
||||
SLE::pointer sleOffer = entryCreate(ltOFFER, uLedgerIndex);
|
||||
|
||||
Log(lsINFO) << "doOfferCreate: Creating offer node: " << uLedgerIndex.ToString() << " uSequence=" << uSequence;
|
||||
|
||||
uint160 uPaysCurrency = saTakerPays.getCurrency();
|
||||
uint160 uGetsCurrency = saTakerGets.getCurrency();
|
||||
uint64 uRate = STAmount::getRate(saTakerGets, saTakerPays);
|
||||
const uint160 uPaysCurrency = saTakerPays.getCurrency();
|
||||
const uint160 uGetsCurrency = saTakerGets.getCurrency();
|
||||
const uint64 uRate = STAmount::getRate(saTakerGets, saTakerPays);
|
||||
|
||||
TransactionEngineResult terResult = terSUCCESS;
|
||||
uint256 uDirectory; // Delete hints.
|
||||
@@ -4225,7 +4234,7 @@ Log(lsWARNING) << "doOfferCreate: saTakerGets=" << saTakerGets.getFullText();
|
||||
{
|
||||
STAmount saOfferPaid;
|
||||
STAmount saOfferGot;
|
||||
uint256 uTakeBookBase = Ledger::getBookBase(uGetsCurrency, uGetsIssuerID, uPaysCurrency, uPaysIssuerID);
|
||||
const uint256 uTakeBookBase = Ledger::getBookBase(uGetsCurrency, uGetsIssuerID, uPaysCurrency, uPaysIssuerID);
|
||||
|
||||
Log(lsINFO) << str(boost::format("doOfferCreate: take against book: %s : %s/%s -> %s/%s")
|
||||
% uTakeBookBase.ToString()
|
||||
@@ -4332,8 +4341,8 @@ Log(lsWARNING) << "doOfferCreate: saTakerGets=" << saTakerGets.getFullText();
|
||||
TransactionEngineResult TransactionEngine::doOfferCancel(const SerializedTransaction& txn)
|
||||
{
|
||||
TransactionEngineResult terResult;
|
||||
uint32 uSequence = txn.getITFieldU32(sfOfferSequence);
|
||||
uint256 uOfferIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence);
|
||||
const uint32 uSequence = txn.getITFieldU32(sfOfferSequence);
|
||||
const uint256 uOfferIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence);
|
||||
SLE::pointer sleOffer = entryCache(ltOFFER, uOfferIndex);
|
||||
|
||||
if (sleOffer)
|
||||
|
||||
@@ -169,7 +169,11 @@ public:
|
||||
STAmount saSendMax,
|
||||
bool bPartialPayment
|
||||
)
|
||||
{ return boost::make_shared<PathState>(lpLedger, iIndex, lesSource, spSourcePath, uReceiverID, uSenderID, saSend, saSendMax, bPartialPayment); };
|
||||
{
|
||||
PathState::pointer pspNew = boost::make_shared<PathState>(lpLedger, iIndex, lesSource, spSourcePath, uReceiverID, uSenderID, saSend, saSendMax, bPartialPayment);
|
||||
|
||||
return pspNew && pspNew->bValid ? pspNew : PathState::pointer();
|
||||
}
|
||||
|
||||
static bool lessPriority(const PathState::pointer& lhs, const PathState::pointer& rhs);
|
||||
};
|
||||
@@ -268,10 +272,10 @@ protected:
|
||||
|
||||
public:
|
||||
TransactionEngine() { ; }
|
||||
TransactionEngine(Ledger::pointer ledger) : mLedger(ledger) { ; }
|
||||
TransactionEngine(const Ledger::pointer& ledger) : mLedger(ledger) { ; }
|
||||
|
||||
Ledger::pointer getLedger() { return mLedger; }
|
||||
void setLedger(Ledger::pointer ledger) { assert(ledger); mLedger = ledger; }
|
||||
void setLedger(const Ledger::pointer& ledger) { assert(ledger); mLedger = ledger; }
|
||||
|
||||
TransactionEngineResult applyTransaction(const SerializedTransaction&, TransactionEngineParams);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user