Build the LedgerEngine logic into the Ledger class.

Add index rules for account state and ripple nodes.
This commit is contained in:
JoelKatz
2012-04-16 11:39:29 -07:00
parent 7ab3da2f76
commit cc4b350eb7
3 changed files with 39 additions and 9 deletions

View File

@@ -15,6 +15,7 @@
#include "Hanko.h" #include "Hanko.h"
#include "AccountState.h" #include "AccountState.h"
#include "SHAMap.h" #include "SHAMap.h"
#include "SerializedLedger.h"
class Ledger : public boost::enable_shared_from_this<Ledger> class Ledger : public boost::enable_shared_from_this<Ledger>
@@ -37,6 +38,10 @@ public:
TR_TOOSMALL =9, // amount is less than Tx fee TR_TOOSMALL =9, // amount is less than Tx fee
}; };
enum LedgerStateParms
{
lepCREATE = 1, // Create if not present
};
private: private:
uint256 mHash, mParentHash, mTransHash, mAccountHash; uint256 mHash, mParentHash, mTransHash, mAccountHash;
@@ -95,23 +100,34 @@ public:
bool isAcquiringTx(void); bool isAcquiringTx(void);
bool isAcquiringAS(void); bool isAcquiringAS(void);
// mid level functions // Transaction Functions
bool hasTransaction(const uint256& TransID) const; bool hasTransaction(const uint256& TransID) const;
AccountState::pointer getAccountState(const NewcoinAddress& acctID);
Transaction::pointer getTransaction(const uint256& transID) const; 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 applyTransaction(Transaction::pointer trans);
TransResult removeTransaction(Transaction::pointer trans); TransResult removeTransaction(Transaction::pointer trans);
TransResult hasTransaction(Transaction::pointer trans); TransResult hasTransaction(Transaction::pointer trans);
Ledger::pointer switchPreviousLedger(Ledger::pointer oldPrevious, Ledger::pointer newPrevious, int limit); 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 // database functions
static void saveAcceptedLedger(Ledger::pointer); static void saveAcceptedLedger(Ledger::pointer);
static Ledger::pointer loadByIndex(uint32 ledgerIndex); static Ledger::pointer loadByIndex(uint32 ledgerIndex);
static Ledger::pointer loadByHash(const uint256& ledgerHash); 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); 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); bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko);

14
src/LedgerIndex.cpp Normal file
View File

@@ -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;
}

View File

@@ -2,7 +2,7 @@
#define __TRANSACTIONENGINE__ #define __TRANSACTIONENGINE__
#include "Ledger.h" #include "Ledger.h"
#include "LedgerEngine.h" #include "Ledger.h"
#include "Currency.h" #include "Currency.h"
#include "SerializedTransaction.h" #include "SerializedTransaction.h"
#include "SerializedLedger.h" #include "SerializedLedger.h"
@@ -34,7 +34,7 @@ enum TransactionEngineParams
class TransactionEngine class TransactionEngine
{ {
protected: protected:
LedgerEngine::pointer mTxnEngine; Ledger::pointer mLedger;
TransactionEngineResult doPayment(const SerializedTransaction&, SerializedLedgerEntry& source); TransactionEngineResult doPayment(const SerializedTransaction&, SerializedLedgerEntry& source);
TransactionEngineResult doInvoice(const SerializedTransaction&, SerializedLedgerEntry& source); TransactionEngineResult doInvoice(const SerializedTransaction&, SerializedLedgerEntry& source);
@@ -46,10 +46,10 @@ protected:
public: public:
TransactionEngine() { ; } TransactionEngine() { ; }
TransactionEngine(LedgerEngine::pointer txnEngine) : mTxnEngine(txnEngine) { ; } TransactionEngine(Ledger::pointer ledger) : mLedger(ledger) { ; }
LedgerEngine::pointer getLedgerEngine() { return mTxnEngine; } Ledger::pointer getLedger() { return mLedger; }
void setLedgerEngine(LedgerEngine::pointer engine) { mTxnEngine = engine; } void setLedger(Ledger::pointer ledger) { mLedger = ledger; }
TransactionEngineResult applyTransaction(const SerializedTransaction&, TransactionEngineParams); TransactionEngineResult applyTransaction(const SerializedTransaction&, TransactionEngineParams);
}; };