Use the transaction master.

This commit is contained in:
JoelKatz
2012-01-27 11:34:41 -08:00
parent 4f0a9a4ce5
commit 110a4a47f1
3 changed files with 28 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ uint32 NetworkOPs::getCurrentLedgerID()
Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, Peer* source) 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(dbtx) return dbtx;
if(!trans->checkSign()) if(!trans->checkSign())
@@ -47,7 +47,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans,
std::cerr << "Transaction should be held" << std::endl; std::cerr << "Transaction should be held" << std::endl;
#endif #endif
trans->setStatus(HELD); trans->setStatus(HELD);
trans->save(); theApp->getMasterTransaction().canonicalize(trans, true);
theApp->getMasterLedger().addHeldTransaction(trans); theApp->getMasterLedger().addHeldTransaction(trans);
return 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; std::cerr << "Transaction is now included, synching to wallet" << std::endl;
#endif #endif
trans->setStatus(INCLUDED); trans->setStatus(INCLUDED);
theApp->getMasterTransaction().canonicalize(trans, true);
theApp->getWallet().applyTransaction(trans); theApp->getWallet().applyTransaction(trans);
newcoin::TMTransaction *tx=new newcoin::TMTransaction(); newcoin::TMTransaction *tx=new newcoin::TMTransaction();

View File

@@ -428,9 +428,7 @@ Json::Value RPCServer::doTx(Json::Value& params)
if(theApp->getWallet().getTxJson(txid, ret)) if(theApp->getWallet().getTxJson(txid, ret))
return ret; return ret;
Transaction::pointer txn=theApp->getMasterLedger().getCurrentLedger()->getTransaction(txid); Transaction::pointer txn=theApp->getMasterTransaction().fetch(txid, true);
if(!txn) txn=theApp->getMasterLedger().getClosingLedger()->getTransaction(txid);
if(!txn) txn=Transaction::load(txid);
if(!txn) return JSONRPCError(500, "Transaction not found"); if(!txn) return JSONRPCError(500, "Transaction not found");
return txn->getJson(true); return txn->getJson(true);
} }

24
TransactionMaster.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef __TRANSACTIONMASTER__
#define __TRANSACTIONMASTER__
#include "Transaction.h"
#include "TaggedCache.h"
// Tracks all transactions in memory
class TransactionMaster
{
protected:
TaggedCache<uint256, Transaction> 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