diff --git a/src/SerializedLedger.cpp b/src/SerializedLedger.cpp index 33d42d46c1..3cc5c70dc0 100644 --- a/src/SerializedLedger.cpp +++ b/src/SerializedLedger.cpp @@ -2,6 +2,8 @@ #include +#include "Ledger.h" + SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) : SerializedType("LedgerEntry"), mIndex(index) { @@ -103,4 +105,30 @@ void SerializedLedgerEntry::thread(const uint256& txID, uint32 ledgerSeq, uint25 setIFieldU32(sfLastTxnSeq, ledgerSeq); } +std::vector SerializedLedgerEntry::getOwners() +{ + std::vector 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(mObject.peekAtPIndex(i)); + if ((entry != NULL) && entry->getValueH160(account)) + owners.push_back(Ledger::getAccountRootIndex(account)); + } + + default: + nothing(); + } + } + + return owners; +} + // vim:ts=4 diff --git a/src/SerializedLedger.h b/src/SerializedLedger.h index c629ddbbce..c8ac2d96e5 100644 --- a/src/SerializedLedger.h +++ b/src/SerializedLedger.h @@ -47,6 +47,7 @@ public: int getIFieldCount() const { return mObject.getCount(); } const SerializedType& peekIField(SOE_Field field) const { return mObject.peekAtField(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); } unsigned char getIFieldU8(SOE_Field field) const { return mObject.getValueFieldU8(field); } @@ -67,6 +68,7 @@ public: uint256 getThreadedTransaction(); uint32 getThreadedLedger(); void thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID); + std::vector getOwners(); // nodes notified if this node is deleted 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); } diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 6fbd45e63f..0f9af758e5 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -257,35 +257,45 @@ int STObject::getFieldIndex(SOE_Field field) const const SerializedType& STObject::peekAtField(SOE_Field field) const { 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); } SerializedType& STObject::getField(SOE_Field 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); } +SOE_Field STObject::getFieldSType(int index) const +{ + return mType[index]->e_field; +} + const SerializedType* STObject::peekAtPField(SOE_Field field) const { int index = getFieldIndex(field); - if (index == -1) return NULL; + if (index == -1) + return NULL; return peekAtPIndex(index); } SerializedType* STObject::getPField(SOE_Field field) { int index = getFieldIndex(field); - if (index == -1) return NULL; + if (index == -1) + return NULL; return getPIndex(index); } bool STObject::isFieldPresent(SOE_Field field) const { int index = getFieldIndex(field); - if (index == -1) return false; + if (index == -1) + return false; return peekAtIndex(index).getSType() != STI_NOTPRESENT; } @@ -318,7 +328,8 @@ uint32 STObject::getFlags(void) const SerializedType* STObject::makeFieldPresent(SOE_Field 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)) throw std::runtime_error("field is not optional"); @@ -338,7 +349,8 @@ SerializedType* STObject::makeFieldPresent(SOE_Field field) void STObject::makeFieldAbsent(SOE_Field 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)) throw std::runtime_error("field is not optional"); diff --git a/src/SerializedObject.h b/src/SerializedObject.h index e8df6729f4..5453a987b7 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -28,7 +28,6 @@ enum SOE_Field sfAcceptRate, sfAcceptStart, sfAccount, - sfAccountID, sfAmount, sfAuthorizedKey, sfBalance, @@ -162,6 +161,7 @@ public: SerializedType* getPIndex(int offset) { return &(mData[offset]); } int getFieldIndex(SOE_Field field) const; + SOE_Field getFieldSType(int index) const; const SerializedType& peekAtField(SOE_Field field) const; SerializedType& getField(SOE_Field field);