mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 18:45:52 +00:00
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.
66 lines
1.8 KiB
C++
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
|