mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Tie in transaction master. Some performance improvements and const fixes.
This commit is contained in:
31
Ledger.cpp
31
Ledger.cpp
@@ -82,7 +82,7 @@ AccountState::pointer Ledger::getAccountState(const uint160& accountID)
|
|||||||
return AccountState::pointer(new AccountState(item->getData()));
|
return AccountState::pointer(new AccountState(item->getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 Ledger::getBalance(const uint160& accountID)
|
uint64 Ledger::getBalance(const uint160& accountID) const
|
||||||
{
|
{
|
||||||
ScopedLock l(mTransactionMap->Lock());
|
ScopedLock l(mTransactionMap->Lock());
|
||||||
SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.to256());
|
SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.to256());
|
||||||
@@ -119,14 +119,24 @@ bool Ledger::delTransaction(const uint256& transID)
|
|||||||
return mTransactionMap->delItem(transID);
|
return mTransactionMap->delItem(transID);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction::pointer Ledger::getTransaction(const uint256& transID)
|
bool Ledger::hasTransaction(const uint256& transID) const
|
||||||
|
{
|
||||||
|
return mTransactionMap->hasItem(transID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction::pointer Ledger::getTransaction(const uint256& transID) const
|
||||||
{
|
{
|
||||||
ScopedLock l(mTransactionMap->Lock());
|
|
||||||
SHAMapItem::pointer item=mTransactionMap->peekItem(transID);
|
SHAMapItem::pointer item=mTransactionMap->peekItem(transID);
|
||||||
if(!item) return Transaction::pointer();
|
if(!item) return Transaction::pointer();
|
||||||
Transaction::pointer trans(new Transaction(item->getData(), true));
|
|
||||||
if(trans->getStatus()==NEW) trans->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
Transaction::pointer txn=theApp->getMasterTransaction().fetch(transID, false);
|
||||||
return trans;
|
if(txn) return txn;
|
||||||
|
|
||||||
|
txn=Transaction::pointer(new Transaction(item->getData(), true));
|
||||||
|
if(txn->getStatus()==NEW) txn->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
||||||
|
|
||||||
|
theApp->getMasterTransaction().canonicalize(txn, false);
|
||||||
|
return txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::TransResult Ledger::applyTransaction(Transaction::pointer trans)
|
Ledger::TransResult Ledger::applyTransaction(Transaction::pointer trans)
|
||||||
@@ -479,12 +489,17 @@ Ledger::pointer Ledger::switchPreviousLedger(Ledger::pointer oldPrevious, Ledger
|
|||||||
// WRITEME: Handle rejected transactions left in TxnDiff
|
// WRITEME: Handle rejected transactions left in TxnDiff
|
||||||
|
|
||||||
// 5) Try to add transactions from this ledger to the new ledger.
|
// 5) Try to add transactions from this ledger to the new ledger.
|
||||||
// OPTIMIZME: This should use the transaction canonicalizer, rather than creating transactions
|
|
||||||
std::map<uint256, Transaction::pointer> txnMap;
|
std::map<uint256, Transaction::pointer> txnMap;
|
||||||
for(SHAMapItem::pointer mit=peekTransactionMap()->peekFirstItem();
|
for(SHAMapItem::pointer mit=peekTransactionMap()->peekFirstItem();
|
||||||
!!mit;
|
!!mit;
|
||||||
mit=peekTransactionMap()->peekNextItem(mit->getTag()))
|
mit=peekTransactionMap()->peekNextItem(mit->getTag()))
|
||||||
txnMap.insert(std::make_pair(mit->getTag(), Transaction::pointer(new Transaction(mit->peekData(), false))));
|
{
|
||||||
|
uint256 txnID=mit->getTag();
|
||||||
|
Transaction::pointer tx=theApp->getMasterTransaction().fetch(txnID, false);
|
||||||
|
if(!tx) tx=Transaction::pointer(new Transaction(mit->peekData(), false));
|
||||||
|
txnMap.insert(std::make_pair(txnID, tx));
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
count=0;
|
count=0;
|
||||||
|
|||||||
5
Ledger.h
5
Ledger.h
@@ -88,9 +88,10 @@ public:
|
|||||||
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
||||||
|
|
||||||
// mid level functions
|
// mid level functions
|
||||||
|
bool hasTransaction(const uint256& TransID) const;
|
||||||
AccountState::pointer getAccountState(const uint160& acctID);
|
AccountState::pointer getAccountState(const uint160& acctID);
|
||||||
Transaction::pointer getTransaction(const uint256& transID);
|
Transaction::pointer getTransaction(const uint256& transID) const;
|
||||||
uint64 getBalance(const uint160& acctID);
|
uint64 getBalance(const uint160& acctID) const;
|
||||||
|
|
||||||
// high level functions
|
// high level functions
|
||||||
TransResult applyTransaction(Transaction::pointer trans);
|
TransResult applyTransaction(Transaction::pointer trans);
|
||||||
|
|||||||
Reference in New Issue
Block a user