From 110a4a47f15736165427509ee6c83c1132749819 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 27 Jan 2012 11:34:41 -0800 Subject: [PATCH] Use the transaction master. --- NetworkOPs.cpp | 5 +++-- RPCServer.cpp | 4 +--- TransactionMaster.h | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 TransactionMaster.h diff --git a/NetworkOPs.cpp b/NetworkOPs.cpp index 3e080d72bd..82949ae5d6 100644 --- a/NetworkOPs.cpp +++ b/NetworkOPs.cpp @@ -26,7 +26,7 @@ uint32 NetworkOPs::getCurrentLedgerID() Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, Peer* source) { - Transaction::pointer dbtx=Transaction::load(trans->getID()); + Transaction::pointer dbtx=theApp->getMasterTransaction().fetch(trans->getID(), true); if(dbtx) return dbtx; if(!trans->checkSign()) @@ -47,7 +47,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, std::cerr << "Transaction should be held" << std::endl; #endif trans->setStatus(HELD); - trans->save(); + theApp->getMasterTransaction().canonicalize(trans, true); theApp->getMasterLedger().addHeldTransaction(trans); return trans; } @@ -66,6 +66,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, std::cerr << "Transaction is now included, synching to wallet" << std::endl; #endif trans->setStatus(INCLUDED); + theApp->getMasterTransaction().canonicalize(trans, true); theApp->getWallet().applyTransaction(trans); newcoin::TMTransaction *tx=new newcoin::TMTransaction(); diff --git a/RPCServer.cpp b/RPCServer.cpp index ae20a0d02d..abe10c7314 100644 --- a/RPCServer.cpp +++ b/RPCServer.cpp @@ -428,9 +428,7 @@ Json::Value RPCServer::doTx(Json::Value& params) if(theApp->getWallet().getTxJson(txid, ret)) return ret; - Transaction::pointer txn=theApp->getMasterLedger().getCurrentLedger()->getTransaction(txid); - if(!txn) txn=theApp->getMasterLedger().getClosingLedger()->getTransaction(txid); - if(!txn) txn=Transaction::load(txid); + Transaction::pointer txn=theApp->getMasterTransaction().fetch(txid, true); if(!txn) return JSONRPCError(500, "Transaction not found"); return txn->getJson(true); } diff --git a/TransactionMaster.h b/TransactionMaster.h new file mode 100644 index 0000000000..cdf02d8163 --- /dev/null +++ b/TransactionMaster.h @@ -0,0 +1,24 @@ +#ifndef __TRANSACTIONMASTER__ +#define __TRANSACTIONMASTER__ + +#include "Transaction.h" +#include "TaggedCache.h" + +// Tracks all transactions in memory + +class TransactionMaster +{ +protected: + TaggedCache mCache; + +public: + + TransactionMaster(); + + Transaction::pointer fetch(const uint256&, bool checkDisk); + + // return value: true = we had the transaction already + bool canonicalize(Transaction::pointer& txn, bool maybeNew); +}; + +#endif