From fb60b99781c49afa81b60db06f29c222d3770fc8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 23 Jul 2012 01:55:20 -0700 Subject: [PATCH] Header for classes to manipulate transaction metadata. --- src/TransactionMeta.h | 116 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/TransactionMeta.h diff --git a/src/TransactionMeta.h b/src/TransactionMeta.h new file mode 100644 index 0000000000..4298304e09 --- /dev/null +++ b/src/TransactionMeta.h @@ -0,0 +1,116 @@ +#ifndef __TRANSACTIONMETA__ +#define __TRANSACTIONMETA__ + +#include +#include +#include + +#include + +#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 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 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& 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 mEntries; + +public: + TransactionMetaSet(const uint256& txID, uint32 ledger) : mTransactionID(txID), mLedger(ledger) + { ; } + TransactionMetaSet(uint32 ledger, const std::vector&); + + 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