From 5fc9233fb5b9cd3b060a78f2fadb7559a500d5f3 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 23 Nov 2011 12:50:51 -0800 Subject: [PATCH] More ledger functions, updateAccountState/addTransaction. --- Ledger.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Ledger.cpp b/Ledger.cpp index ee8ded7141..3db5ba4d31 100644 --- a/Ledger.cpp +++ b/Ledger.cpp @@ -43,15 +43,27 @@ void Ledger::addRaw(Serializer &s) AccountState::pointer Ledger::getAccountState(const uint160& accountID) { ScopedLock l(mTransactionMap->Lock()); - SHAMapItem::pointer item=mTransactionMap->getItem(uint160to256(accountID)); + SHAMapItem::pointer item=mTransactionMap->peekItem(uint160to256(accountID)); if(item==NULL) return AccountState::pointer(); return AccountState::pointer(new AccountState(item->getData())); } +bool Ledger::updateAccountState(AccountState::pointer state) +{ + SHAMapItem::pointer item(new SHAMapItem(state->getAccountID(), state->getRaw())); + return mAccountStateMap->updateGiveItem(item); +} + +bool Ledger::addTransaction(Transaction::pointer trans) +{ // low-level - just add to table + SHAMapItem::pointer item(new SHAMapItem(trans->getID(), trans->getSigned()->getData())); + return mTransactionMap->addGiveItem(item); +} + Transaction::pointer Ledger::getTransaction(const uint256& transID) { ScopedLock l(mTransactionMap->Lock()); - SHAMapItem::pointer item=mTransactionMap->getItem(transID); + SHAMapItem::pointer item=mTransactionMap->peekItem(transID); if(item==NULL) return Transaction::pointer(); Transaction *t=new Transaction(item->getData(), true); if(t->getStatus()==NEW) t->setStatus(mCurrent ? INCLUDED : COMMITTED, mLedgerSeq); @@ -100,7 +112,7 @@ Ledger::TransResult Ledger::applyTransaction(Transaction::pointer trans) } Ledger::TransResult Ledger::removeTransaction(Transaction::pointer trans) -{ +{ // high-level - reverse application of transaction } Ledger::TransResult Ledger::hasTransaction(Transaction::pointer trans)