mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Cleanups.
This commit is contained in:
45
Ledger.cpp
45
Ledger.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Ledger.h"
|
#include "Ledger.h"
|
||||||
@@ -18,10 +19,10 @@ Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
|
|||||||
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0),
|
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0),
|
||||||
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false)
|
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false)
|
||||||
{
|
{
|
||||||
mTransactionMap=SHAMap::pointer(new SHAMap());
|
mTransactionMap=boost::make_shared<SHAMap>();
|
||||||
mAccountStateMap=SHAMap::pointer(new SHAMap(0));
|
mAccountStateMap=boost::make_shared<SHAMap>();
|
||||||
|
|
||||||
AccountState::pointer startAccount=AccountState::pointer(new AccountState(masterID));
|
AccountState::pointer startAccount=boost::make_shared<AccountState>(masterID);
|
||||||
startAccount->credit(startAmount);
|
startAccount->credit(startAmount);
|
||||||
if(!addAccountState(startAccount))
|
if(!addAccountState(startAccount))
|
||||||
assert(false);
|
assert(false);
|
||||||
@@ -59,8 +60,8 @@ Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mFeeHeld(0), mTime
|
|||||||
updateHash();
|
updateHash();
|
||||||
if(mValidHash)
|
if(mValidHash)
|
||||||
{
|
{
|
||||||
mTransactionMap=SHAMap::pointer(new SHAMap());
|
mTransactionMap=boost::make_shared<SHAMap>();
|
||||||
mAccountStateMap=SHAMap::pointer(new SHAMap(mLedgerSeq));
|
mAccountStateMap=boost::make_shared<SHAMap>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +70,9 @@ void Ledger::updateHash()
|
|||||||
if(!mImmutable)
|
if(!mImmutable)
|
||||||
{
|
{
|
||||||
if(mTransactionMap) mTransHash=mTransactionMap->getHash();
|
if(mTransactionMap) mTransHash=mTransactionMap->getHash();
|
||||||
else mTransHash=0;
|
else mTransHash.zero();
|
||||||
if(mAccountStateMap) mAccountHash=mAccountStateMap->getHash();
|
if(mAccountStateMap) mAccountHash=mAccountStateMap->getHash();
|
||||||
else mAccountHash=0;
|
else mAccountHash.zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
Serializer s(116);
|
Serializer s(116);
|
||||||
@@ -104,7 +105,7 @@ AccountState::pointer Ledger::getAccountState(const uint160& accountID)
|
|||||||
#endif
|
#endif
|
||||||
return AccountState::pointer();
|
return AccountState::pointer();
|
||||||
}
|
}
|
||||||
return AccountState::pointer(new AccountState(item->getData()));
|
return boost::make_shared<AccountState>(item->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 Ledger::getBalance(const uint160& accountID) const
|
uint64 Ledger::getBalance(const uint160& accountID) const
|
||||||
@@ -118,24 +119,24 @@ uint64 Ledger::getBalance(const uint160& accountID) const
|
|||||||
bool Ledger::updateAccountState(AccountState::pointer state)
|
bool Ledger::updateAccountState(AccountState::pointer state)
|
||||||
{
|
{
|
||||||
assert(!mAccepted);
|
assert(!mAccepted);
|
||||||
SHAMapItem::pointer item(new SHAMapItem(state->getAccountID(), state->getRaw()));
|
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID(), state->getRaw());
|
||||||
return mAccountStateMap->updateGiveItem(item);
|
return mAccountStateMap->updateGiveItem(item, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ledger::addAccountState(AccountState::pointer state)
|
bool Ledger::addAccountState(AccountState::pointer state)
|
||||||
{
|
{
|
||||||
assert(!mAccepted);
|
assert(!mAccepted);
|
||||||
assert( (state->getBalance()==0) || (state->getSeq()>0) );
|
assert( (state->getBalance()==0) || (state->getSeq()>0) );
|
||||||
SHAMapItem::pointer item(new SHAMapItem(state->getAccountID(), state->getRaw()));
|
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID(), state->getRaw());
|
||||||
return mAccountStateMap->addGiveItem(item);
|
return mAccountStateMap->addGiveItem(item, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ledger::addTransaction(Transaction::pointer trans)
|
bool Ledger::addTransaction(Transaction::pointer trans)
|
||||||
{ // low-level - just add to table
|
{ // low-level - just add to table
|
||||||
assert(!mAccepted);
|
assert(!mAccepted);
|
||||||
assert(!!trans->getID());
|
assert(!!trans->getID());
|
||||||
SHAMapItem::pointer item(new SHAMapItem(trans->getID(), trans->getSigned()->getData()));
|
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(trans->getID(), trans->getSigned()->getData());
|
||||||
return mTransactionMap->addGiveItem(item);
|
return mTransactionMap->addGiveItem(item, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ledger::delTransaction(const uint256& transID)
|
bool Ledger::delTransaction(const uint256& transID)
|
||||||
@@ -157,7 +158,7 @@ Transaction::pointer Ledger::getTransaction(const uint256& transID) const
|
|||||||
Transaction::pointer txn=theApp->getMasterTransaction().fetch(transID, false);
|
Transaction::pointer txn=theApp->getMasterTransaction().fetch(transID, false);
|
||||||
if(txn) return txn;
|
if(txn) return txn;
|
||||||
|
|
||||||
txn=Transaction::pointer(new Transaction(item->getData(), true));
|
txn=boost::make_shared<Transaction>(item->getData(), true);
|
||||||
if(txn->getStatus()==NEW) txn->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
if(txn->getStatus()==NEW) txn->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
||||||
|
|
||||||
theApp->getMasterTransaction().canonicalize(txn, false);
|
theApp->getMasterTransaction().canonicalize(txn, false);
|
||||||
@@ -193,7 +194,7 @@ Ledger::TransResult Ledger::applyTransaction(Transaction::pointer trans)
|
|||||||
// temporary code -- if toAccount doesn't exist but fromAccount does, create it
|
// temporary code -- if toAccount doesn't exist but fromAccount does, create it
|
||||||
if(!!fromAccount && !toAccount)
|
if(!!fromAccount && !toAccount)
|
||||||
{
|
{
|
||||||
toAccount=AccountState::pointer(new AccountState(trans->getToAccount()));
|
toAccount=boost::make_shared<AccountState>(trans->getToAccount());
|
||||||
toAccount->incSeq(); // an account in a ledger has a sequence of 1
|
toAccount->incSeq(); // an account in a ledger has a sequence of 1
|
||||||
updateAccountState(toAccount);
|
updateAccountState(toAccount);
|
||||||
}
|
}
|
||||||
@@ -308,7 +309,7 @@ Ledger::pointer Ledger::closeLedger(uint64 timeStamp)
|
|||||||
// CAUTION: New ledger needs its SHAMap's connected to storage
|
// CAUTION: New ledger needs its SHAMap's connected to storage
|
||||||
updateHash();
|
updateHash();
|
||||||
setClosed();
|
setClosed();
|
||||||
return Ledger::pointer(new Ledger(*this, timeStamp));
|
return Ledger::pointer(new Ledger(*this, timeStamp)); // can't use make_shared
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalAccount::syncLedger()
|
void LocalAccount::syncLedger()
|
||||||
@@ -338,9 +339,9 @@ bool Ledger::unitTest()
|
|||||||
std::cerr << "Account2: " << la2.GetHex() << std::endl;
|
std::cerr << "Account2: " << la2.GetHex() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Ledger::pointer ledger(new Ledger(la1, 100000));
|
Ledger::pointer ledger=boost::make_shared<Ledger>(la1, 100000);
|
||||||
|
|
||||||
ledger=Ledger::pointer(new Ledger(*ledger, 0));
|
ledger=Ledger::pointer(new Ledger(*ledger, 0)); // can't use make_shared
|
||||||
|
|
||||||
AccountState::pointer as=ledger->getAccountState(la1);
|
AccountState::pointer as=ledger->getAccountState(la1);
|
||||||
assert(as);
|
assert(as);
|
||||||
@@ -349,7 +350,7 @@ bool Ledger::unitTest()
|
|||||||
as=ledger->getAccountState(la2);
|
as=ledger->getAccountState(la2);
|
||||||
assert(!as);
|
assert(!as);
|
||||||
|
|
||||||
Transaction::pointer t(new Transaction(l1, l2->getAddress(), 2500, 0, 1));
|
Transaction::pointer t=boost::make_shared<Transaction>(l1, l2->getAddress(), 2500, 0, 1);
|
||||||
assert(!!t->getID());
|
assert(!!t->getID());
|
||||||
|
|
||||||
Ledger::TransResult tr=ledger->applyTransaction(t);
|
Ledger::TransResult tr=ledger->applyTransaction(t);
|
||||||
@@ -425,7 +426,7 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
|||||||
db->endIterRows();
|
db->endIterRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::pointer ret(new Ledger(prevHash, transHash, accountHash, feeHeld, closingTime, ledgerSeq));
|
Ledger::pointer ret=boost::make_shared<Ledger>(prevHash, transHash, accountHash, feeHeld, closingTime, ledgerSeq);
|
||||||
if(ret->getHash()!=ledgerHash)
|
if(ret->getHash()!=ledgerHash)
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
@@ -519,7 +520,7 @@ Ledger::pointer Ledger::switchPreviousLedger(Ledger::pointer oldPrevious, Ledger
|
|||||||
{
|
{
|
||||||
uint256 txnID=mit->getTag();
|
uint256 txnID=mit->getTag();
|
||||||
Transaction::pointer tx=theApp->getMasterTransaction().fetch(txnID, false);
|
Transaction::pointer tx=theApp->getMasterTransaction().fetch(txnID, false);
|
||||||
if(!tx) tx=Transaction::pointer(new Transaction(mit->peekData(), false));
|
if(!tx) tx=boost::make_shared<Transaction>(mit->peekData(), false);
|
||||||
txnMap.insert(std::make_pair(txnID, tx));
|
txnMap.insert(std::make_pair(txnID, tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
Ledger.h
2
Ledger.h
@@ -52,7 +52,7 @@ private:
|
|||||||
Ledger& operator=(const Ledger&); // no implementation
|
Ledger& operator=(const Ledger&); // no implementation
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Ledger(Ledger&, uint64 timestamp); // ledger after this one
|
Ledger(Ledger& previous, uint64 timestamp); // ledger after this one
|
||||||
void updateHash();
|
void updateHash();
|
||||||
|
|
||||||
bool addAccountState(AccountState::pointer);
|
bool addAccountState(AccountState::pointer);
|
||||||
|
|||||||
Reference in New Issue
Block a user