mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Build the LedgerEngine logic into the Ledger class.
Add index rules for account state and ripple nodes.
This commit is contained in:
24
src/Ledger.h
24
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<Ledger>
|
||||
@@ -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<Ledger> other);
|
||||
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko);
|
||||
|
||||
14
src/LedgerIndex.cpp
Normal file
14
src/LedgerIndex.cpp
Normal 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;
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user