From b575e72093666a2db570ba2de4c1f48727935ba1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 25 Jul 2012 18:40:08 -0700 Subject: [PATCH] Metadata structures for deletion of unfunded offers. --- src/TransactionMeta.cpp | 18 ++++++++++++++++++ src/TransactionMeta.h | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/TransactionMeta.cpp b/src/TransactionMeta.cpp index 40af484b2b..fac9798f26 100644 --- a/src/TransactionMeta.cpp +++ b/src/TransactionMeta.cpp @@ -89,6 +89,22 @@ Json::Value TMNEBalance::getJson(int p) const return ret; } +void TMNEUnfunded::addRaw(Serializer& sit) const +{ + sit.add8(mType); +} + +Json::Value TMNEUnfunded::getJson(int) const +{ + return Json::Value("delete_unfunded"); +} + +int TMNEUnfunded::compare(const TransactionMetaNodeEntry&) const +{ + assert(false); // Can't be two deletes for same node + return 0; +} + TransactionMetaNode::TransactionMetaNode(const uint256& node, SerializerIterator& sit) : mNode(node) { mNode = sit.get256(); @@ -100,6 +116,8 @@ TransactionMetaNode::TransactionMetaNode(const uint256& node, SerializerIterator type = sit.get8(); if (type == TransactionMetaNodeEntry::TMNChangedBalance) mEntries.insert(boost::shared_ptr(new TMNEBalance(sit))); + if (type == TransactionMetaNodeEntry::TMNDeleteUnfunded) + mEntries.insert(boost::shared_ptr(new TMNEUnfunded())); else if (type != TransactionMetaNodeEntry::TMNEndOfMetadata) throw std::runtime_error("Unparseable metadata"); } while (type != TransactionMetaNodeEntry::TMNEndOfMetadata); diff --git a/src/TransactionMeta.h b/src/TransactionMeta.h index c87ed0bb82..5dc4ecccc4 100644 --- a/src/TransactionMeta.h +++ b/src/TransactionMeta.h @@ -21,6 +21,7 @@ public: static const int TMNEndOfMetadata = 0; static const int TMNChangedBalance = 1; + static const int TMNDeleteUnfunded = 2; int mType; TransactionMetaNodeEntry(int type) : mType(type) { ; } @@ -68,6 +69,15 @@ public: virtual int compare(const TransactionMetaNodeEntry&) const; }; +class TMNEUnfunded : public TransactionMetaNodeEntry +{ // node was deleted because it was unfunded +public: + TMNEUnfunded() : TransactionMetaNodeEntry(TMNDeleteUnfunded) { ; } + virtual void addRaw(Serializer&) const; + virtual Json::Value getJson(int) const; + virtual int compare(const TransactionMetaNodeEntry&) const; +}; + class TransactionMetaNode { // a node that has been affected by a transaction public: @@ -118,6 +128,7 @@ public: void threadNode(const uint256& node, const uint256& previousTransaction, uint32 previousLedger); bool signedBy(const uint256& node, const STAmount& fee); + bool deleteUnfunded(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); };