Construct the next ledger from the existing ledger.

Close ledger logic.
This commit is contained in:
JoelKatz
2011-11-28 19:34:16 -08:00
parent 75f1eb80a4
commit 11f9e111de
3 changed files with 27 additions and 12 deletions

View File

@@ -12,7 +12,7 @@ using namespace boost;
using namespace std; using namespace std;
Ledger::Ledger(const uint160& masterID, uint64 startAmount) : 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()); mTransactionMap=SHAMap::pointer(new SHAMap());
mAccountStateMap=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, Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq) uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq)
: mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash), : mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash),
mFeeHeld(feeHeld), mTimeStamp(timeStamp), mLedgerSeq(ledgerSeq), mCurrent(false) mFeeHeld(feeHeld), mTimeStamp(timeStamp), mLedgerSeq(ledgerSeq), mClosed(false)
{ {
updateHash(); updateHash();
} }
Ledger::Ledger(Ledger &prevLedger, uint64 ts) : mTimeStamp(ts), mClosed(false)
{
prevLedger.updateHash();
mParentHash=prevLedger.mHash;
mLedgerSeq=prevLedger.mLedgerSeq+1;
}
void Ledger::updateHash() void Ledger::updateHash()
{ {
Serializer s(116); Serializer s(116);
@@ -84,7 +91,7 @@ Transaction::pointer Ledger::getTransaction(const uint256& transID)
SHAMapItem::pointer item=mTransactionMap->peekItem(transID); SHAMapItem::pointer item=mTransactionMap->peekItem(transID);
if(!item) return Transaction::pointer(); if(!item) return Transaction::pointer();
Transaction *t=new Transaction(item->getData(), true); 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); 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 #if 0
// TODO: we should probably make a shared pointer type for each of these PB types // TODO: we should probably make a shared pointer type for each of these PB types
newcoin::FullLedger* Ledger::createFullLedger() newcoin::FullLedger* Ledger::createFullLedger()

View File

@@ -41,13 +41,17 @@ private:
uint256 mHash, mParentHash, mTransHash, mAccountHash; uint256 mHash, mParentHash, mTransHash, mAccountHash;
uint64 mFeeHeld, mTimeStamp; uint64 mFeeHeld, mTimeStamp;
uint32 mLedgerSeq; uint32 mLedgerSeq;
bool mCurrent; bool mClosed;
SHAMap::pointer mTransactionMap, mAccountStateMap; SHAMap::pointer mTransactionMap, mAccountStateMap;
mutable boost::recursive_mutex mLock; mutable boost::recursive_mutex mLock;
Ledger(const Ledger&); // no implementation
Ledger& operator=(const Ledger&); // no implementation
protected: protected:
Ledger(Ledger&, uint64 timestamp); // ledger after this one
void updateHash(); void updateHash();
bool addAccountState(AccountState::pointer); bool addAccountState(AccountState::pointer);
@@ -57,13 +61,11 @@ protected:
public: public:
Ledger(const uint160& masterID, uint64 startAmount); // used for the starting bootstrap ledger 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, Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers
void setCurrent(void) { mCurrent=true; } void setClosed(void) { mClosed=true; }
void clearCurrent(void) { mCurrent=false; } bool isClosed(void) { return mClosed; }
bool isCurrent(void) { return mCurrent; }
// ledger signature operations // ledger signature operations
void addRaw(Serializer &s); void addRaw(Serializer &s);
@@ -89,7 +91,7 @@ public:
TransResult removeTransaction(Transaction::pointer trans); TransResult removeTransaction(Transaction::pointer trans);
TransResult hasTransaction(Transaction::pointer trans); TransResult hasTransaction(Transaction::pointer trans);
bool closeLedger(); Ledger::pointer closeLedger(uint64 timestamp);
bool isCompatible(boost::shared_ptr<Ledger> other); bool isCompatible(boost::shared_ptr<Ledger> other);
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko, int32 confidence); bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko, int32 confidence);
}; };

View File

@@ -20,9 +20,8 @@ public:
bool SetPubKey(const std::vector<unsigned char>& vchPubKey); bool SetPubKey(const std::vector<unsigned char>& vchPubKey);
bool IsValid(); bool IsValid();
uint160 GetHash160() const;
uint160 GetHash160(); std::string GetString() const;
std::string GetString();
}; };
#endif #endif