mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add callback support.
This commit is contained in:
@@ -1,10 +1,30 @@
|
||||
#include "TransactionQueue.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
void TXQEntry::addCallbacks(const TXQEntry& otherEntry)
|
||||
{
|
||||
BOOST_FOREACH(const stCallback& callback, otherEntry.mCallbacks)
|
||||
mCallbacks.push_back(callback);
|
||||
}
|
||||
|
||||
void TXQEntry::doCallbacks(TER result)
|
||||
{
|
||||
BOOST_FOREACH(const stCallback& callback, mCallbacks)
|
||||
callback(mTxn, result);
|
||||
}
|
||||
|
||||
bool TXQueue::addEntryForSigCheck(TXQEntry::ref entry)
|
||||
{ // we always dispatch a thread to check the signature
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
return mTxMap.insert(valueType(entry->getID(), entry)).second;
|
||||
if (!mTxMap.insert(valueType(entry->getID(), entry)).second)
|
||||
{
|
||||
if (!entry->mCallbacks.empty())
|
||||
mTxMap.left.find(entry->getID())->second->addCallbacks(*entry);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TXQueue::addEntryForExecution(TXQEntry::ref entry)
|
||||
@@ -12,8 +32,14 @@ bool TXQueue::addEntryForExecution(TXQEntry::ref entry)
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
entry->mSigChecked = true;
|
||||
if (!mTxMap.insert(valueType(entry->getID(), entry)).second)
|
||||
mTxMap.left.find(entry->getID())->second->mSigChecked = true;
|
||||
|
||||
std::pair<mapType::iterator, bool> it = mTxMap.insert(valueType(entry->getID(), entry));
|
||||
if (!it.second)
|
||||
{ // There was an existing entry
|
||||
it.first->right->mSigChecked = true;
|
||||
if (!entry->mCallbacks.empty())
|
||||
it.first->right->addCallbacks(*entry);
|
||||
}
|
||||
|
||||
if (mRunning)
|
||||
return false;
|
||||
@@ -22,11 +48,20 @@ bool TXQueue::addEntryForExecution(TXQEntry::ref entry)
|
||||
return true; // A thread needs to handle this account
|
||||
}
|
||||
|
||||
void TXQueue::removeEntry(const uint256& id)
|
||||
TXQEntry::pointer TXQueue::removeEntry(const uint256& id)
|
||||
{
|
||||
TXQEntry::pointer ret;
|
||||
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
mTxMap.left.erase(id);
|
||||
mapType::left_map::iterator it = mTxMap.left.find(id);
|
||||
if (it != mTxMap.left.end())
|
||||
{
|
||||
ret = it->second;
|
||||
mTxMap.left.erase(it);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TXQueue::getJob(TXQEntry::pointer &job)
|
||||
|
||||
Reference in New Issue
Block a user