mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Header for classes to manipulate transaction metadata.
This commit is contained in:
116
src/TransactionMeta.h
Normal file
116
src/TransactionMeta.h
Normal file
@@ -0,0 +1,116 @@
|
||||
#ifndef __TRANSACTIONMETA__
|
||||
#define __TRANSACTIONMETA__
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "../json/value.h"
|
||||
|
||||
#include "uint256.h"
|
||||
#include "SerializedTypes.h"
|
||||
|
||||
|
||||
class TransactionMetaNodeEntry
|
||||
{ // a way that a transaction has affected a node
|
||||
public:
|
||||
|
||||
typedef boost::shared_ptr<TransactionMetaNodeEntry> pointer;
|
||||
|
||||
static const int TMNEndOfMetadata = 0;
|
||||
static const int TMNChangedBalance = 1;
|
||||
|
||||
int mType;
|
||||
TransactionMetaNodeEntry(int type) : mType(type) { ; }
|
||||
|
||||
int getType() const { return mType; }
|
||||
virtual Json::Value getJson(int) const = 0;
|
||||
virtual int compare(const TransactionMetaNodeEntry&) = 0;
|
||||
|
||||
bool operator<(const TransactionMetaNodeEntry&) const;
|
||||
bool operator<=(const TransactionMetaNodeEntry&) const;
|
||||
bool operator>(const TransactionMetaNodeEntry&) const;
|
||||
bool operator>=(const TransactionMetaNodeEntry&) const;
|
||||
};
|
||||
|
||||
class TMNEBalance : public TransactionMetaNodeEntry
|
||||
{ // a transaction affected the balance of a node
|
||||
public:
|
||||
|
||||
static const int TMBTwoAmounts = 0x001;
|
||||
static const int TMBReverse = 0x010;
|
||||
static const int TMBDestroyed = 0x020;
|
||||
static const int TMBPaidFee = 0x040;
|
||||
static const int TMBRipple = 0x100;
|
||||
static const int TMBOffer = 0x200;
|
||||
|
||||
protected:
|
||||
unsigned mFlags;
|
||||
STAmount mFirstAmount, mSecondAmount;
|
||||
|
||||
public:
|
||||
TMNEBalance() : TransactionMetaNodeEntry(TMNChangedBalance), mFlags(0) { ; }
|
||||
|
||||
unsigned getFlags() const { return mFlags; }
|
||||
const STAmount& getFirstAmount() const { return mFirstAmount; }
|
||||
const STAmount& getSecondAmount() const { return mSecondAmount; }
|
||||
|
||||
void adjustFirstAmount(const STAmount&);
|
||||
void adjustSecondAmount(const STAmount&);
|
||||
void setFlags(unsigned flags);
|
||||
|
||||
virtual Json::Value getJson(int) const;
|
||||
virtual int compare(const TransactionMetaNodeEntry&) const;
|
||||
};
|
||||
|
||||
class TransactionMetaNode
|
||||
{ // a node that has been affected by a transaction
|
||||
protected:
|
||||
uint256 mNode;
|
||||
uint256 mPreviousTransaction;
|
||||
uint32 mPreviousLedger;
|
||||
std::list<TransactionMetaNodeEntry::pointer> mEntries;
|
||||
|
||||
public:
|
||||
TransactionMetaNode(const uint256 &node) : mNode(node) { ; }
|
||||
|
||||
const uint256& getNode() const { return mNode; }
|
||||
const uint256& getPreviousTransaction() const { return mPreviousTransaction; }
|
||||
uint32 getPreviousLedger() const { return mPreviousLedger; }
|
||||
const std::list<TransactionMetaNodeEntry::pointer>& peekEntries() const { return mEntries; }
|
||||
|
||||
bool operator<(const TransactionMetaNode& n) const { return mNode < n.mNode; }
|
||||
bool operator<=(const TransactionMetaNode& n) const { return mNode <= n.mNode; }
|
||||
bool operator>(const TransactionMetaNode& n) const { return mNode > n.mNode; }
|
||||
bool operator>=(const TransactionMetaNode& n) const { return mNode >= n.mNode; }
|
||||
};
|
||||
|
||||
class TransactionMetaSet
|
||||
{
|
||||
protected:
|
||||
uint256 mTransactionID;
|
||||
uint32 mLedger;
|
||||
std::set<TransactionMetaNode> mEntries;
|
||||
|
||||
public:
|
||||
TransactionMetaSet(const uint256& txID, uint32 ledger) : mTransactionID(txID), mLedger(ledger)
|
||||
{ ; }
|
||||
TransactionMetaSet(uint32 ledger, const std::vector<unsigned char>&);
|
||||
|
||||
bool isNodeAffected(const uint256&) const;
|
||||
TransactionMetaNode getAffectedAccount(const uint256&) const;
|
||||
const TransactionMetaNode& peekAffectedAccount(const uint256&) const;
|
||||
|
||||
Json::Value getJson(int) const;
|
||||
void addRaw(Serializer&) const;
|
||||
|
||||
void threadNode(const uint256& node, const uint256& previousTransaction, uint32 previousLedger);
|
||||
bool signedBy(const uint256& node);
|
||||
bool adjustBalance(const uint256& node, unsigned flags, const STAmount &amount);
|
||||
bool adjustBalances(const uint256& node, unsigned flags, const STAmount &firstAmt, const STAmount &secondAmt);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user