mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cleanups.
This commit is contained in:
50
src/SHAMap.h
50
src/SHAMap.h
@@ -166,16 +166,16 @@ public:
|
||||
|
||||
// node functions
|
||||
uint32 getSeq() const { return mSeq; }
|
||||
void setSeq(uint32 s) { mSeq=s; }
|
||||
void setSeq(uint32 s) { mSeq = s; }
|
||||
const uint256& getNodeHash() const { return mHash; }
|
||||
TNType getType() const { return mType; }
|
||||
|
||||
// type functions
|
||||
bool isLeaf() const { return (mType==tnTRANSACTION) || (mType==tnACCOUNT_STATE); }
|
||||
bool isInner() const { return mType==tnINNER; }
|
||||
bool isValid() const { return mType!=tnERROR; }
|
||||
bool isTransaction() const { return mType!=tnTRANSACTION; }
|
||||
bool isAccountState() const { return mType!=tnACCOUNT_STATE; }
|
||||
bool isLeaf() const { return (mType == tnTRANSACTION) || (mType == tnACCOUNT_STATE); }
|
||||
bool isInner() const { return mType == tnINNER; }
|
||||
bool isValid() const { return mType != tnERROR; }
|
||||
bool isTransaction() const { return mType != tnTRANSACTION; }
|
||||
bool isAccountState() const { return mType != tnACCOUNT_STATE; }
|
||||
|
||||
// inner node functions
|
||||
bool isInnerNode() const { return !mItem; }
|
||||
@@ -196,7 +196,7 @@ public:
|
||||
|
||||
// sync functions
|
||||
bool isFullBelow(void) const { return mFullBelow; }
|
||||
void setFullBelow(void) { mFullBelow=true; }
|
||||
void setFullBelow(void) { mFullBelow = true; }
|
||||
|
||||
virtual void dump();
|
||||
virtual std::string getString() const;
|
||||
@@ -204,18 +204,18 @@ public:
|
||||
|
||||
enum SHAMapException
|
||||
{
|
||||
MissingNode=1,
|
||||
InvalidNode=2,
|
||||
InvalidMap=3,
|
||||
MissingNode = 1,
|
||||
InvalidNode = 2,
|
||||
InvalidMap = 3,
|
||||
};
|
||||
|
||||
enum SHAMapState
|
||||
{
|
||||
Modifying=0, // Objects can be added and removed (like an open ledger)
|
||||
Immutable=1, // Map cannot be changed (like a closed ledger)
|
||||
Synching=2, // Map's hash is locked in, valid nodes can be added (like a peer's closing ledger)
|
||||
Floating=3, // Map is free to change hash (like a synching open ledger)
|
||||
Invalid=4, // Map is known not to be valid (usually synching a corrupt ledger)
|
||||
Modifying = 0, // Objects can be added and removed (like an open ledger)
|
||||
Immutable = 1, // Map cannot be changed (like a closed ledger)
|
||||
Synching = 2, // Map's hash is locked in, valid nodes can be added (like a peer's closing ledger)
|
||||
Floating = 3, // Map is free to change hash (like a synching open ledger)
|
||||
Invalid = 4, // Map is known not to be valid (usually synching a corrupt ledger)
|
||||
};
|
||||
|
||||
class SHAMap
|
||||
@@ -298,13 +298,13 @@ public:
|
||||
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
||||
|
||||
// status functions
|
||||
void setImmutable(void) { assert(mState!=Invalid); mState=Immutable; }
|
||||
void clearImmutable(void) { mState=Modifying; }
|
||||
bool isSynching(void) const { return mState==Floating || mState==Synching; }
|
||||
void setSynching(void) { mState=Synching; }
|
||||
void setFloating(void) { mState=Floating; }
|
||||
void clearSynching(void) { mState=Modifying; }
|
||||
bool isValid(void) { return mState!=Invalid; }
|
||||
void setImmutable(void) { assert(mState != Invalid); mState = Immutable; }
|
||||
void clearImmutable(void) { mState = Modifying; }
|
||||
bool isSynching(void) const { return mState == Floating || mState == Synching; }
|
||||
void setSynching(void) { mState = Synching; }
|
||||
void setFloating(void) { mState = Floating; }
|
||||
void clearSynching(void) { mState = Modifying; }
|
||||
bool isValid(void) { return mState != Invalid; }
|
||||
|
||||
// caution: otherMap must be accessed only by this function
|
||||
// return value: true=successfully completed, false=too different
|
||||
@@ -312,18 +312,18 @@ public:
|
||||
|
||||
int flushDirty(int maxNodes, HashedObjectType t, uint32 seq);
|
||||
|
||||
void setSeq(uint32 seq) { mSeq=seq; }
|
||||
void setSeq(uint32 seq) { mSeq = seq; }
|
||||
uint32 getSeq() { return mSeq; }
|
||||
|
||||
// overloads for backed maps
|
||||
bool fetchNode(const uint256& hash, std::vector<unsigned char>& rawNode);
|
||||
|
||||
bool operator==(const SHAMap& s) { return getHash()==s.getHash(); }
|
||||
bool operator==(const SHAMap& s) { return getHash() == s.getHash(); }
|
||||
|
||||
static bool TestSHAMap();
|
||||
static bool syncTest();
|
||||
bool deepCompare(SHAMap& other);
|
||||
virtual void dump(bool withHashes=false);
|
||||
virtual void dump(bool withHashes = false);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
std::string SerializedType::getFullText() const
|
||||
{
|
||||
std::string ret;
|
||||
if(getSType()!=STI_NOTPRESENT)
|
||||
if (getSType() != STI_NOTPRESENT)
|
||||
{
|
||||
if(name!=NULL)
|
||||
if(name != NULL)
|
||||
{
|
||||
ret=name;
|
||||
ret+=" = ";
|
||||
ret = name;
|
||||
ret += " = ";
|
||||
}
|
||||
ret+=getText();
|
||||
ret += getText();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -33,8 +33,8 @@ std::string STUInt8::getText() const
|
||||
|
||||
bool STUInt8::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STUInt8* v=dynamic_cast<const STUInt8*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STUInt8* v = dynamic_cast<const STUInt8*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
STUInt16* STUInt16::construct(SerializerIterator& u, const char *name)
|
||||
@@ -49,8 +49,8 @@ std::string STUInt16::getText() const
|
||||
|
||||
bool STUInt16::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STUInt16* v=dynamic_cast<const STUInt16*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STUInt16* v = dynamic_cast<const STUInt16*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
STUInt32* STUInt32::construct(SerializerIterator& u, const char *name)
|
||||
@@ -65,8 +65,8 @@ std::string STUInt32::getText() const
|
||||
|
||||
bool STUInt32::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STUInt32* v=dynamic_cast<const STUInt32*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STUInt32* v = dynamic_cast<const STUInt32*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
STUInt64* STUInt64::construct(SerializerIterator& u, const char *name)
|
||||
@@ -81,8 +81,8 @@ std::string STUInt64::getText() const
|
||||
|
||||
bool STUInt64::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STUInt64* v=dynamic_cast<const STUInt64*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STUInt64* v = dynamic_cast<const STUInt64*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
STHash128* STHash128::construct(SerializerIterator& u, const char *name)
|
||||
@@ -97,8 +97,8 @@ std::string STHash128::getText() const
|
||||
|
||||
bool STHash128::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STHash128* v=dynamic_cast<const STHash128*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STHash128* v = dynamic_cast<const STHash128*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
STHash160* STHash160::construct(SerializerIterator& u, const char *name)
|
||||
@@ -113,8 +113,8 @@ std::string STHash160::getText() const
|
||||
|
||||
bool STHash160::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STHash160* v=dynamic_cast<const STHash160*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STHash160* v = dynamic_cast<const STHash160*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
STHash256* STHash256::construct(SerializerIterator& u, const char *name)
|
||||
@@ -129,8 +129,8 @@ std::string STHash256::getText() const
|
||||
|
||||
bool STHash256::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STHash256* v=dynamic_cast<const STHash256*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STHash256* v = dynamic_cast<const STHash256*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
static std::string hex(const std::vector<unsigned char>& value)
|
||||
@@ -159,26 +159,28 @@ int STVariableLength::getLength() const
|
||||
|
||||
bool STVariableLength::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STVariableLength* v=dynamic_cast<const STVariableLength*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STVariableLength* v = dynamic_cast<const STVariableLength*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
std::string STAccount::getText() const
|
||||
{
|
||||
uint160 u;
|
||||
NewcoinAddress a;
|
||||
if(!getValueH160(u)) return STVariableLength::getText();
|
||||
|
||||
if (!getValueH160(u))
|
||||
return STVariableLength::getText();
|
||||
a.setAccountID(u);
|
||||
return a.humanAccountPublic();
|
||||
}
|
||||
|
||||
STAccount* STAccount::construct(SerializerIterator& u, const char *name)
|
||||
{
|
||||
STAccount *ret=new STAccount(u.getVL());
|
||||
if(!ret->isValueH160())
|
||||
STAccount *ret = new STAccount(u.getVL());
|
||||
if (!ret->isValueH160())
|
||||
{
|
||||
delete ret;
|
||||
throw(std::runtime_error("invalid account in transaction"));
|
||||
throw std::runtime_error("invalid account in transaction");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -196,7 +198,7 @@ void STAccount::setValueH160(const uint160& v)
|
||||
|
||||
bool STAccount::getValueH160(uint160& v) const
|
||||
{
|
||||
if(!isValueH160()) return false;
|
||||
if (!isValueH160()) return false;
|
||||
memcpy(v.begin(), &(peekValue().front()), 32);
|
||||
return true;
|
||||
}
|
||||
@@ -204,11 +206,11 @@ bool STAccount::getValueH160(uint160& v) const
|
||||
std::string STTaggedList::getText() const
|
||||
{
|
||||
std::string ret;
|
||||
for(std::vector<TaggedListItem>::const_iterator it=value.begin(); it!=value.end(); ++it)
|
||||
for (std::vector<TaggedListItem>::const_iterator it=value.begin(); it!=value.end(); ++it)
|
||||
{
|
||||
ret+=boost::lexical_cast<std::string>(it->first);
|
||||
ret+=",";
|
||||
ret+=hex(it->second);
|
||||
ret += boost::lexical_cast<std::string>(it->first);
|
||||
ret += ",";
|
||||
ret += hex(it->second);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -220,13 +222,13 @@ STTaggedList* STTaggedList::construct(SerializerIterator& u, const char *name)
|
||||
|
||||
int STTaggedList::getLength() const
|
||||
{
|
||||
int ret=Serializer::getTaggedListLength(value);
|
||||
if(ret<0) throw(std::overflow_error("bad TL length"));
|
||||
int ret = Serializer::getTaggedListLength(value);
|
||||
if (ret<0) throw std::overflow_error("bad TL length");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool STTaggedList::isEquivalent(const SerializedType& t) const
|
||||
{
|
||||
const STTaggedList* v=dynamic_cast<const STTaggedList*>(&t);
|
||||
return v && (value==v->value);
|
||||
const STTaggedList* v = dynamic_cast<const STTaggedList*>(&t);
|
||||
return v && (value == v->value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user