Files
rippled/LedgerMaster.h
JoelKatz 639ba9dfcb NetworkOPs layer
Begin coding the 'NetworkOPs' layer. This will provide most of the
functions 'client' code will want to call such as functions to lookup
transactions, check on their status, get balances, and so on. Much of the
RPC layer will be a thin wrapper over these functions.

The purpose of this layer is to permit the node to support these functions
regardless of its operating mode or available data, as long as it's
connected to the network. If synchronized and tracking the current ledger,
it can do most functions locally. If not, it can ask for help from other
nodes. If hopeless, it can return an error code.
2011-12-15 01:19:50 -08:00

66 lines
1.8 KiB
C++

#ifndef __LEDGERMASTER__
#define __LEDGERMASTER__
#include "Ledger.h"
#include "LedgerHistory.h"
#include "Peer.h"
#include "types.h"
#include "Transaction.h"
// Tracks the current ledger and any ledgers in the process of closing
// Tracks ledger history
// Tracks held transactions
class LedgerMaster
{
boost::recursive_mutex mLock;
bool mIsSynced;
Ledger::pointer mCurrentLedger;
Ledger::pointer mFinalizingLedger;
LedgerHistory mLedgerHistory;
std::map<uint256, Transaction::pointer> mHeldTransactionsByID;
void applyFutureTransactions(uint32 ledgerIndex);
bool isValidTransaction(Transaction::pointer trans);
bool isTransactionOnFutureList(Transaction::pointer trans);
public:
LedgerMaster();
uint32 getCurrentLedgerIndex();
bool isSynced() { return mIsSynced; }
void setSynced() { mIsSynced=true; }
Ledger::pointer getCurrentLedger() { return mCurrentLedger; }
Ledger::pointer getClosingLedger() { return mFinalizingLedger; }
void pushLedger(Ledger::pointer newLedger);
Ledger::pointer getLedgerBySeq(uint32 index)
{
if(mCurrentLedger && (mCurrentLedger->getLedgerSeq()==index)) return mCurrentLedger;
if(mFinalizingLedger && (mFinalizingLedger->getLedgerSeq()==index)) return mFinalizingLedger;
return mLedgerHistory.getLedgerBySeq(index);
}
Ledger::pointer getLedgerByHash(const uint256& hash)
{
if(mCurrentLedger && (mCurrentLedger->getHash()==hash)) return mCurrentLedger;
if(mFinalizingLedger && (mFinalizingLedger->getHash()==hash)) return mFinalizingLedger;
return mLedgerHistory.getLedgerByHash(hash);
}
uint64 getBalance(std::string& addr);
uint64 getBalance(const uint160& addr);
AccountState::pointer getAccountState(const uint160& addr)
{ return mCurrentLedger->getAccountState(addr); }
bool addHeldTransaction(Transaction::pointer trans);
};
#endif