mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
More TransactionMetadata work.
This commit is contained in:
70
src/TransactionMeta.cpp
Normal file
70
src/TransactionMeta.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "TransactionMeta.h"
|
||||
|
||||
bool TransactionMetaNodeEntry::operator<(const TransactionMetaNodeEntry& e) const
|
||||
{
|
||||
if (mType < e.mType) return true;
|
||||
if (mType > e.mType) return false;
|
||||
return compare(e) < 0;
|
||||
}
|
||||
|
||||
bool TransactionMetaNodeEntry::operator<=(const TransactionMetaNodeEntry& e) const
|
||||
{
|
||||
if (mType < e.mType) return true;
|
||||
if (mType > e.mType) return false;
|
||||
return compare(e) <= 0;
|
||||
}
|
||||
|
||||
bool TransactionMetaNodeEntry::operator>(const TransactionMetaNodeEntry& e) const
|
||||
{
|
||||
if (mType > e.mType) return true;
|
||||
if (mType < e.mType) return false;
|
||||
return compare(e) > 0;
|
||||
}
|
||||
|
||||
bool TransactionMetaNodeEntry::operator>=(const TransactionMetaNodeEntry& e) const
|
||||
{
|
||||
if (mType > e.mType) return true;
|
||||
if (mType < e.mType) return false;
|
||||
return compare(e) >= 0;
|
||||
}
|
||||
|
||||
void TMNEBalance::adjustFirstAmount(const STAmount& a)
|
||||
{
|
||||
mFirstAmount += a;
|
||||
}
|
||||
|
||||
void TMNEBalance::adjustSecondAmount(const STAmount& a)
|
||||
{
|
||||
mSecondAmount += a;
|
||||
mFlags |= TMBTwoAmounts;
|
||||
}
|
||||
|
||||
int TMNEBalance::compare(const TransactionMetaNodeEntry&) const
|
||||
{
|
||||
assert(false); // should never be two TMNEBalance entries for the same node (as of now)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Json::Value TMNEBalance::getJson(int p) const
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
|
||||
if ((mFlags & TMBDestroyed) != 0)
|
||||
ret["destroyed"] = "true";
|
||||
if ((mFlags & TMBPaidFee) != 0)
|
||||
ret["transaction_fee"] = "true";
|
||||
|
||||
if ((mFlags & TMBRipple) != 0)
|
||||
ret["type"] = "ripple";
|
||||
else if ((mFlags & TMBOffer) != 0)
|
||||
ret["type"] = "offer";
|
||||
else
|
||||
ret["type"] = "account";
|
||||
|
||||
if (!mFirstAmount.isZero())
|
||||
ret["amount"] = mFirstAmount.getJson(p);
|
||||
if (!mSecondAmount.isZero())
|
||||
ret["second_amount"] = mSecondAmount.getJson(p);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
int getType() const { return mType; }
|
||||
virtual Json::Value getJson(int) const = 0;
|
||||
virtual int compare(const TransactionMetaNodeEntry&) = 0;
|
||||
virtual int compare(const TransactionMetaNodeEntry&) const = 0;
|
||||
|
||||
bool operator<(const TransactionMetaNodeEntry&) const;
|
||||
bool operator<=(const TransactionMetaNodeEntry&) const;
|
||||
@@ -40,9 +40,8 @@ class TMNEBalance : public TransactionMetaNodeEntry
|
||||
public:
|
||||
|
||||
static const int TMBTwoAmounts = 0x001;
|
||||
static const int TMBReverse = 0x010;
|
||||
static const int TMBDestroyed = 0x020;
|
||||
static const int TMBPaidFee = 0x040;
|
||||
static const int TMBDestroyed = 0x010;
|
||||
static const int TMBPaidFee = 0x020;
|
||||
static const int TMBRipple = 0x100;
|
||||
static const int TMBOffer = 0x200;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user