Threading support for node deletion.

This commit is contained in:
JoelKatz
2012-08-17 16:18:22 -07:00
parent 50777639fb
commit 6bf10b1082
4 changed files with 50 additions and 8 deletions

View File

@@ -2,6 +2,8 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include "Ledger.h"
SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index)
: SerializedType("LedgerEntry"), mIndex(index) : SerializedType("LedgerEntry"), mIndex(index)
{ {
@@ -103,4 +105,30 @@ void SerializedLedgerEntry::thread(const uint256& txID, uint32 ledgerSeq, uint25
setIFieldU32(sfLastTxnSeq, ledgerSeq); setIFieldU32(sfLastTxnSeq, ledgerSeq);
} }
std::vector<uint256> SerializedLedgerEntry::getOwners()
{
std::vector<uint256> owners;
uint160 account;
for (int i = 0, fields = getIFieldCount(); i < fields; ++i)
{
switch (getIFieldSType(i))
{
case sfAccount:
case sfLowID:
case sfHighID:
{
const STAccount* entry = dynamic_cast<const STAccount *>(mObject.peekAtPIndex(i));
if ((entry != NULL) && entry->getValueH160(account))
owners.push_back(Ledger::getAccountRootIndex(account));
}
default:
nothing();
}
}
return owners;
}
// vim:ts=4 // vim:ts=4

View File

@@ -47,6 +47,7 @@ public:
int getIFieldCount() const { return mObject.getCount(); } int getIFieldCount() const { return mObject.getCount(); }
const SerializedType& peekIField(SOE_Field field) const { return mObject.peekAtField(field); } const SerializedType& peekIField(SOE_Field field) const { return mObject.peekAtField(field); }
SerializedType& getIField(SOE_Field field) { return mObject.getField(field); } SerializedType& getIField(SOE_Field field) { return mObject.getField(field); }
SOE_Field getIFieldSType(int index) { return mObject.getFieldSType(index); }
std::string getIFieldString(SOE_Field field) const { return mObject.getFieldString(field); } std::string getIFieldString(SOE_Field field) const { return mObject.getFieldString(field); }
unsigned char getIFieldU8(SOE_Field field) const { return mObject.getValueFieldU8(field); } unsigned char getIFieldU8(SOE_Field field) const { return mObject.getValueFieldU8(field); }
@@ -67,6 +68,7 @@ public:
uint256 getThreadedTransaction(); uint256 getThreadedTransaction();
uint32 getThreadedLedger(); uint32 getThreadedLedger();
void thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID); void thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID);
std::vector<uint256> getOwners(); // nodes notified if this node is deleted
void setIFieldU8(SOE_Field field, unsigned char v) { return mObject.setValueFieldU8(field, v); } void setIFieldU8(SOE_Field field, unsigned char v) { return mObject.setValueFieldU8(field, v); }
void setIFieldU16(SOE_Field field, uint16 v) { return mObject.setValueFieldU16(field, v); } void setIFieldU16(SOE_Field field, uint16 v) { return mObject.setValueFieldU16(field, v); }

View File

@@ -257,35 +257,45 @@ int STObject::getFieldIndex(SOE_Field field) const
const SerializedType& STObject::peekAtField(SOE_Field field) const const SerializedType& STObject::peekAtField(SOE_Field field) const
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index == -1) throw std::runtime_error("Field not found"); if (index == -1)
throw std::runtime_error("Field not found");
return peekAtIndex(index); return peekAtIndex(index);
} }
SerializedType& STObject::getField(SOE_Field field) SerializedType& STObject::getField(SOE_Field field)
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index==-1) throw std::runtime_error("Field not found"); if (index == -1)
throw std::runtime_error("Field not found");
return getIndex(index); return getIndex(index);
} }
SOE_Field STObject::getFieldSType(int index) const
{
return mType[index]->e_field;
}
const SerializedType* STObject::peekAtPField(SOE_Field field) const const SerializedType* STObject::peekAtPField(SOE_Field field) const
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index == -1) return NULL; if (index == -1)
return NULL;
return peekAtPIndex(index); return peekAtPIndex(index);
} }
SerializedType* STObject::getPField(SOE_Field field) SerializedType* STObject::getPField(SOE_Field field)
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index == -1) return NULL; if (index == -1)
return NULL;
return getPIndex(index); return getPIndex(index);
} }
bool STObject::isFieldPresent(SOE_Field field) const bool STObject::isFieldPresent(SOE_Field field) const
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index == -1) return false; if (index == -1)
return false;
return peekAtIndex(index).getSType() != STI_NOTPRESENT; return peekAtIndex(index).getSType() != STI_NOTPRESENT;
} }
@@ -318,7 +328,8 @@ uint32 STObject::getFlags(void) const
SerializedType* STObject::makeFieldPresent(SOE_Field field) SerializedType* STObject::makeFieldPresent(SOE_Field field)
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index == -1) throw std::runtime_error("Field not found"); if (index == -1)
throw std::runtime_error("Field not found");
if ((mType[index]->e_type != SOE_IFFLAG) && (mType[index]->e_type != SOE_IFNFLAG)) if ((mType[index]->e_type != SOE_IFFLAG) && (mType[index]->e_type != SOE_IFNFLAG))
throw std::runtime_error("field is not optional"); throw std::runtime_error("field is not optional");
@@ -338,7 +349,8 @@ SerializedType* STObject::makeFieldPresent(SOE_Field field)
void STObject::makeFieldAbsent(SOE_Field field) void STObject::makeFieldAbsent(SOE_Field field)
{ {
int index = getFieldIndex(field); int index = getFieldIndex(field);
if (index == -1) throw std::runtime_error("Field not found"); if (index == -1)
throw std::runtime_error("Field not found");
if ((mType[index]->e_type != SOE_IFFLAG) && (mType[index]->e_type != SOE_IFNFLAG)) if ((mType[index]->e_type != SOE_IFFLAG) && (mType[index]->e_type != SOE_IFNFLAG))
throw std::runtime_error("field is not optional"); throw std::runtime_error("field is not optional");

View File

@@ -28,7 +28,6 @@ enum SOE_Field
sfAcceptRate, sfAcceptRate,
sfAcceptStart, sfAcceptStart,
sfAccount, sfAccount,
sfAccountID,
sfAmount, sfAmount,
sfAuthorizedKey, sfAuthorizedKey,
sfBalance, sfBalance,
@@ -162,6 +161,7 @@ public:
SerializedType* getPIndex(int offset) { return &(mData[offset]); } SerializedType* getPIndex(int offset) { return &(mData[offset]); }
int getFieldIndex(SOE_Field field) const; int getFieldIndex(SOE_Field field) const;
SOE_Field getFieldSType(int index) const;
const SerializedType& peekAtField(SOE_Field field) const; const SerializedType& peekAtField(SOE_Field field) const;
SerializedType& getField(SOE_Field field); SerializedType& getField(SOE_Field field);