From 25d888ff48c0cb198f7cee98bdce8d8596885b19 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 16 Oct 2012 14:36:36 -0700 Subject: [PATCH] Include the transaction result in the metadata. --- src/LedgerEntrySet.cpp | 4 ++-- src/LedgerEntrySet.h | 2 +- src/TransactionEngine.cpp | 2 +- src/TransactionMeta.cpp | 35 +++++++++++++++++++++++++++++------ src/TransactionMeta.h | 14 +++++++++----- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/LedgerEntrySet.cpp b/src/LedgerEntrySet.cpp index 64321a271..d074f902d 100644 --- a/src/LedgerEntrySet.cpp +++ b/src/LedgerEntrySet.cpp @@ -348,7 +348,7 @@ bool LedgerEntrySet::threadOwners(SLE::ref node, Ledger::ref ledger, return false; } -void LedgerEntrySet::calcRawMeta(Serializer& s) +void LedgerEntrySet::calcRawMeta(Serializer& s, TER result) { // calculate the raw meta data and return it. This must be called before the set is committed // Entries modified only as a result of building the transaction metadata @@ -476,7 +476,7 @@ void LedgerEntrySet::calcRawMeta(Serializer& s) cLog(lsINFO) << "Metadata:" << mSet.getJson(0); #endif - mSet.addRaw(s); + mSet.addRaw(s, result); } // <-- uNodeDir: For deletion, present to make dirDelete efficient. diff --git a/src/LedgerEntrySet.h b/src/LedgerEntrySet.h index 11192c363..2558f1288 100644 --- a/src/LedgerEntrySet.h +++ b/src/LedgerEntrySet.h @@ -120,7 +120,7 @@ public: STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault); Json::Value getJson(int) const; - void calcRawMeta(Serializer&); + void calcRawMeta(Serializer&, TER result); // iterator functions bool isEmpty() const { return mEntries.empty(); } diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 36712c6a3..167b275ba 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -457,7 +457,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa { // Transaction succeeded fully or (retries are not allowed and the transaction succeeded partially). Serializer m; - mNodes.calcRawMeta(m); + mNodes.calcRawMeta(m, terResult); txnWrite(); diff --git a/src/TransactionMeta.cpp b/src/TransactionMeta.cpp index 33840cc10..213542dd0 100644 --- a/src/TransactionMeta.cpp +++ b/src/TransactionMeta.cpp @@ -7,13 +7,18 @@ #include TransactionMetaSet::TransactionMetaSet(const uint256& txid, uint32 ledger, const std::vector& vec) : - mTransactionID(txid), mLedger(ledger), mNodes(sfTransactionMetaData) + mTransactionID(txid), mLedger(ledger), mNodes(sfAffectedNodes) { Serializer s(vec); SerializerIterator sit(s); - std::auto_ptr obj = STArray::deserialize(sit, sfTransactionMetaData); - mNodes = * static_cast(obj.get()); + std::auto_ptr pobj = STObject::deserialize(sit, sfAffectedNodes); + STObject *obj = static_cast(pobj.get()); + if (!obj) + throw std::runtime_error("bad metadata"); + + mResult = obj->getFieldU8(sfTransactionResult); + mNodes = * dynamic_cast(&obj->getField(sfAffectedNodes)); } bool TransactionMetaSet::isNodeAffected(const uint256& node) const @@ -57,7 +62,7 @@ void TransactionMetaSet::init(const uint256& id, uint32 ledger) { mTransactionID = id; mLedger = ledger; - mNodes = STArray(sfTransactionMetaData); + mNodes = STArray(sfAffectedNodes); } void TransactionMetaSet::swap(TransactionMetaSet& s) @@ -85,10 +90,28 @@ static bool compare(const STObject& o1, const STObject& o2) return o1.getFieldH256(sfLedgerIndex) < o2.getFieldH256(sfLedgerIndex); } -void TransactionMetaSet::addRaw(Serializer& s) +STObject TransactionMetaSet::getAsObject() const { + STObject metaData(sfTransactionMetaData); + metaData.setFieldU8(sfTransactionResult, mResult); + metaData.addObject(mNodes); + return metaData; +} + +void TransactionMetaSet::addRaw(Serializer& s, TER result) +{ + mResult = 255; + + if (result == tesSUCCESS) + mResult = 0; + else if (result == tepPATH_DRY) + mResult = 1; + else if (result == tepPATH_PARTIAL) + mResult = 2; + mNodes.sort(compare); - mNodes.add(s); + + getAsObject().add(s); } // vim:ts=4 diff --git a/src/TransactionMeta.h b/src/TransactionMeta.h index 90623b8de..78f3378f5 100644 --- a/src/TransactionMeta.h +++ b/src/TransactionMeta.h @@ -12,6 +12,7 @@ #include "Serializer.h" #include "SerializedTypes.h" #include "SerializedObject.h" +#include "TransactionErr.h" class TransactionMetaSet { @@ -19,13 +20,14 @@ public: typedef boost::shared_ptr pointer; protected: - uint256 mTransactionID; - uint32 mLedger; + uint256 mTransactionID; + uint32 mLedger; + int mResult; STArray mNodes; public: - TransactionMetaSet() : mLedger(0) { ; } + TransactionMetaSet() : mLedger(0), mResult(255) { ; } TransactionMetaSet(const uint256& txID, uint32 ledger) : mTransactionID(txID), mLedger(ledger) { ; } TransactionMetaSet(const uint256& txID, uint32 ledger, const std::vector&); @@ -40,8 +42,10 @@ public: STObject& getAffectedNode(const uint256&, SField::ref type, bool overrideType); const STObject& peekAffectedNode(const uint256&) const; - Json::Value getJson(int p) const { return mNodes.getJson(p); } - void addRaw(Serializer&); + Json::Value getJson(int p) const { return getAsObject().getJson(p); } + void addRaw(Serializer&, TER); + + STObject getAsObject() const; static bool thread(STObject& node, const uint256& prevTxID, uint32 prevLgrID); };