diff --git a/src/Ledger.h b/src/Ledger.h index 255af429a..668ef93c0 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -15,6 +15,7 @@ #include "Hanko.h" #include "AccountState.h" #include "SHAMap.h" +#include "SerializedLedger.h" class Ledger : public boost::enable_shared_from_this @@ -37,6 +38,10 @@ public: TR_TOOSMALL =9, // amount is less than Tx fee }; + enum LedgerStateParms + { + lepCREATE = 1, // Create if not present + }; private: uint256 mHash, mParentHash, mTransHash, mAccountHash; @@ -95,23 +100,34 @@ public: bool isAcquiringTx(void); bool isAcquiringAS(void); - // mid level functions + // Transaction Functions bool hasTransaction(const uint256& TransID) const; - AccountState::pointer getAccountState(const NewcoinAddress& acctID); Transaction::pointer getTransaction(const uint256& transID) const; - uint64 getBalance(const NewcoinAddress& acctID) const; - // high level functions + // OLD high level functions + uint64 getBalance(const NewcoinAddress& acctID) const; + AccountState::pointer getAccountState(const NewcoinAddress& acctID); TransResult applyTransaction(Transaction::pointer trans); TransResult removeTransaction(Transaction::pointer trans); TransResult hasTransaction(Transaction::pointer trans); Ledger::pointer switchPreviousLedger(Ledger::pointer oldPrevious, Ledger::pointer newPrevious, int limit); + // high-level functions + SerializedLedgerEntry::pointer getAccountRoot(LedgerStateParms parms, const uint160& accountID); + SerializedLedgerEntry::pointer getNickname(LedgerStateParms parms, const std::string& nickname); + SerializedLedgerEntry::pointer getNickname(LedgerStateParms parms, const uint256& nickHash); +// SerializedLedgerEntry::pointer getRippleState(LedgerStateParms parms, const uint160& offeror, +// const uint160& borrower, const Currency& currency); + // database functions static void saveAcceptedLedger(Ledger::pointer); static Ledger::pointer loadByIndex(uint32 ledgerIndex); static Ledger::pointer loadByHash(const uint256& ledgerHash); + // index calculation functions + static uint256 getAccountRootIndex(const uint160& account); + static uint256 getRippleIndex(const uint160& account, const uint160& extendTo, const uint160& currency); + Ledger::pointer closeLedger(uint64 timestamp); bool isCompatible(boost::shared_ptr other); bool signLedger(std::vector &signature, const LocalHanko &hanko); diff --git a/src/LedgerIndex.cpp b/src/LedgerIndex.cpp new file mode 100644 index 000000000..f058cc1dd --- /dev/null +++ b/src/LedgerIndex.cpp @@ -0,0 +1,14 @@ + +#include "Ledger.h" + +uint256 Ledger::getAccountRootIndex(const uint160& accountID) +{ // Index is accountID extended to 256 bits + return accountID.to256(); +} + +uint256 Ledger::getRippleIndex(const uint160& accountID, const uint160& extendTo, const uint160& currency) +{ // Index is 160-bit account credit extended to, 96-bit XOR of extending account and currency + uint256 base=getAccountRootIndex(extendTo); + memcpy(base.begin() + (160/8), (accountID^currency).begin(), (256/8)-(160/8)); + return base; +} diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index f8320c70a..b454c20f0 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -2,7 +2,7 @@ #define __TRANSACTIONENGINE__ #include "Ledger.h" -#include "LedgerEngine.h" +#include "Ledger.h" #include "Currency.h" #include "SerializedTransaction.h" #include "SerializedLedger.h" @@ -34,7 +34,7 @@ enum TransactionEngineParams class TransactionEngine { protected: - LedgerEngine::pointer mTxnEngine; + Ledger::pointer mLedger; TransactionEngineResult doPayment(const SerializedTransaction&, SerializedLedgerEntry& source); TransactionEngineResult doInvoice(const SerializedTransaction&, SerializedLedgerEntry& source); @@ -46,10 +46,10 @@ protected: public: TransactionEngine() { ; } - TransactionEngine(LedgerEngine::pointer txnEngine) : mTxnEngine(txnEngine) { ; } + TransactionEngine(Ledger::pointer ledger) : mLedger(ledger) { ; } - LedgerEngine::pointer getLedgerEngine() { return mTxnEngine; } - void setLedgerEngine(LedgerEngine::pointer engine) { mTxnEngine = engine; } + Ledger::pointer getLedger() { return mLedger; } + void setLedger(Ledger::pointer ledger) { mLedger = ledger; } TransactionEngineResult applyTransaction(const SerializedTransaction&, TransactionEngineParams); };