mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Construct the next ledger from the existing ledger.
Close ledger logic.
This commit is contained in:
20
Ledger.cpp
20
Ledger.cpp
@@ -12,7 +12,7 @@ using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
|
||||
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0), mCurrent(true)
|
||||
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0), mClosed(false)
|
||||
{
|
||||
mTransactionMap=SHAMap::pointer(new SHAMap());
|
||||
mAccountStateMap=SHAMap::pointer(new SHAMap());
|
||||
@@ -25,11 +25,18 @@ Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
|
||||
Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq)
|
||||
: mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash),
|
||||
mFeeHeld(feeHeld), mTimeStamp(timeStamp), mLedgerSeq(ledgerSeq), mCurrent(false)
|
||||
mFeeHeld(feeHeld), mTimeStamp(timeStamp), mLedgerSeq(ledgerSeq), mClosed(false)
|
||||
{
|
||||
updateHash();
|
||||
}
|
||||
|
||||
Ledger::Ledger(Ledger &prevLedger, uint64 ts) : mTimeStamp(ts), mClosed(false)
|
||||
{
|
||||
prevLedger.updateHash();
|
||||
mParentHash=prevLedger.mHash;
|
||||
mLedgerSeq=prevLedger.mLedgerSeq+1;
|
||||
}
|
||||
|
||||
void Ledger::updateHash()
|
||||
{
|
||||
Serializer s(116);
|
||||
@@ -84,7 +91,7 @@ Transaction::pointer Ledger::getTransaction(const uint256& transID)
|
||||
SHAMapItem::pointer item=mTransactionMap->peekItem(transID);
|
||||
if(!item) return Transaction::pointer();
|
||||
Transaction *t=new Transaction(item->getData(), true);
|
||||
if(t->getStatus()==NEW) t->setStatus(mCurrent ? INCLUDED : COMMITTED, mLedgerSeq);
|
||||
if(t->getStatus()==NEW) t->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
||||
return Transaction::pointer(t);
|
||||
}
|
||||
|
||||
@@ -192,6 +199,13 @@ Ledger::TransResult Ledger::hasTransaction(Transaction::pointer trans)
|
||||
}
|
||||
}
|
||||
|
||||
Ledger::pointer Ledger::closeLedger(uint64 timeStamp)
|
||||
{ // close this ledger, return a pointer to the next ledger
|
||||
// CAUTION: New ledger needs its SHAMap's connected to storage
|
||||
setClosed();
|
||||
return Ledger::pointer(new Ledger(*this, timeStamp));
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TODO: we should probably make a shared pointer type for each of these PB types
|
||||
newcoin::FullLedger* Ledger::createFullLedger()
|
||||
|
||||
14
Ledger.h
14
Ledger.h
@@ -41,13 +41,17 @@ private:
|
||||
uint256 mHash, mParentHash, mTransHash, mAccountHash;
|
||||
uint64 mFeeHeld, mTimeStamp;
|
||||
uint32 mLedgerSeq;
|
||||
bool mCurrent;
|
||||
bool mClosed;
|
||||
|
||||
SHAMap::pointer mTransactionMap, mAccountStateMap;
|
||||
|
||||
mutable boost::recursive_mutex mLock;
|
||||
|
||||
Ledger(const Ledger&); // no implementation
|
||||
Ledger& operator=(const Ledger&); // no implementation
|
||||
|
||||
protected:
|
||||
Ledger(Ledger&, uint64 timestamp); // ledger after this one
|
||||
void updateHash();
|
||||
|
||||
bool addAccountState(AccountState::pointer);
|
||||
@@ -57,13 +61,11 @@ protected:
|
||||
|
||||
public:
|
||||
Ledger(const uint160& masterID, uint64 startAmount); // used for the starting bootstrap ledger
|
||||
Ledger(const Ledger &ledger);
|
||||
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers
|
||||
|
||||
void setCurrent(void) { mCurrent=true; }
|
||||
void clearCurrent(void) { mCurrent=false; }
|
||||
bool isCurrent(void) { return mCurrent; }
|
||||
void setClosed(void) { mClosed=true; }
|
||||
bool isClosed(void) { return mClosed; }
|
||||
|
||||
// ledger signature operations
|
||||
void addRaw(Serializer &s);
|
||||
@@ -89,7 +91,7 @@ public:
|
||||
TransResult removeTransaction(Transaction::pointer trans);
|
||||
TransResult hasTransaction(Transaction::pointer trans);
|
||||
|
||||
bool closeLedger();
|
||||
Ledger::pointer closeLedger(uint64 timestamp);
|
||||
bool isCompatible(boost::shared_ptr<Ledger> other);
|
||||
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko, int32 confidence);
|
||||
};
|
||||
|
||||
@@ -20,9 +20,8 @@ public:
|
||||
bool SetPubKey(const std::vector<unsigned char>& vchPubKey);
|
||||
|
||||
bool IsValid();
|
||||
|
||||
uint160 GetHash160();
|
||||
std::string GetString();
|
||||
uint160 GetHash160() const;
|
||||
std::string GetString() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user