diff --git a/Ledger.h b/Ledger.h index 793fa1ab7d..61d05f1951 100644 --- a/Ledger.h +++ b/Ledger.h @@ -5,6 +5,8 @@ #include "types.h" #include "BitcoinUtil.h" #include "Hanko.h" +#include "AccountState.h" +#include "SHAMap.h" #include #include @@ -17,53 +19,66 @@ class Ledger : public boost::enable_shared_from_this { public: typedef boost::shared_ptr pointer; - typedef std::pair Account; + private: - bool mValidHash, mValidLedger, mOpen; uint256 mHash; uint256 mParentHash, mTransHash, mAccountHash; uint64 mFeeHeld, mTimeStamp; uint32 mLedgerSeq; +protected: + void updateHash(void); + public: - Ledger(); Ledger(uint32 index); + Ledger(const std::vector rawLedger); - std::vector Sign(uint64 timestamp, LocalHanko &Hanko); + // ledger signature operations + std::vector getRaw(); + std::vector getSigned(uint64 timestamp, LocalHanko &Hanko); + bool checkSignature(const std::vector signature, LocalHanko &Hanko); -#if 0 - void setTo(newcoin::FullLedger& ledger); - void mergeIn(Ledger::pointer other); - - void save(); - bool load(const uint256& hash); - - void recalculate(bool recursive=true); - - void publishValidation(); - - bool hasTransaction(TransactionPtr trans); - int64 getAmountHeld(const uint160& address); - void parentAddedTransaction(TransactionPtr cause); - bool addTransaction(TransactionPtr trans,bool checkDuplicate=true); - void addValidation(newcoin::Validation& valid); - void addIgnoredValidation(newcoin::Validation& valid); - - uint32 getIndex(){ return(mIndex); } - uint256& getHash(); - uint256& getSignature(); - uint32 getValidSeqNum(){ return(mValidationSeqNum); } - unsigned int getNumTransactions(){ return(mTransactions.size()); } - std::map& getAccounts(){ return(mAccounts); } - Account* getAccount(const uint160& address); - newcoin::FullLedger* createFullLedger(); - - Ledger::pointer getParent(); - Ledger::pointer getChild(); - bool isCompatible(Ledger::pointer other); -#endif + virtual uint256 getHash() const; + const uint256& getParentHash() const { return mParentHash; } + const uint256& getTransHash() const { return mTransHash; } + const uint256& getAccountHash() const { return mAccountHash; } + uint64 getFeeHeld() const { return mFeeHeld; } + uint64 getTimeStamp() const { return mTimeStamp; } + uint32 getLedgerSeq() const { return mLedgerSeq; } + virtual bool hasTransaction(TransactionPtr trans); + virtual bool hasTransaction(const uint256 &transID); + virtual AccountState::pointer getAccountState(const uint160 &account); }; -#endif \ No newline at end of file + +class OpenLedger : public Ledger +{ +public: + typedef boost::shared_ptr pointer; + +private: + std::map TransIDs; + std::map, TransactionPtr> TransAccts; + std::map AccountStates; + + std::map leaves; + std::map innerNodes; + +public: + OpenLedger(std::vector rawLedger); + OpenLedger(const Ledger &prevLedger); + + bool applyTransaction(TransactionPtr &trans); + bool removeTransaction(TransactionPtr &trans); + + virtual bool hasTransaction(TransactionPtr trans); + virtual bool hasTransaction(const uint256 &transID); + virtual AccountState::pointer getAccountState(const uint160 &account); + + bool isCompatible(Ledger::pointer other); + bool commit(void); +}; + +#endif