A structure for accepted ledgers that will allow us to do things like traverse the transactions

in applied order and get the affected accounts without rebuilding things several times.
This commit is contained in:
JoelKatz
2013-03-04 10:38:12 -08:00
parent c8813a01ce
commit 2a73ec7f22
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#include "AcceptedLedger.h"
ALTransaction::ALTransaction(uint32 seq, SerializerIterator& sit)
{
Serializer txnSer(sit.getVL());
SerializerIterator txnIt(txnSer);
mTxn = boost::make_shared<SerializedTransaction>(boost::ref(txnIt));
mMeta = boost::make_shared<TransactionMetaSet>(mTxn->getTransactionID(), seq, sit.getVL());
mAffected = mMeta->getAffectedAccounts();
}
AcceptedLedger::AcceptedLedger(Ledger::ref ledger) : mLedger(ledger)
{
SHAMap& txSet = *ledger->peekTransactionMap();
for (SHAMapItem::pointer item = txSet.peekFirstItem(); !!item; item = txSet.peekNextItem(item->getTag()))
{
SerializerIterator sit(item->peekSerializer());
insert(ALTransaction(ledger->getLedgerSeq(), sit));
}
}
void AcceptedLedger::insert(const ALTransaction& at)
{
assert(mMap.find(at.getIndex()) == mMap.end());
mMap.insert(std::make_pair(at.getIndex(), at));
}
const ALTransaction* AcceptedLedger::getTxn(int i) const
{
map_t::const_iterator it = mMap.find(i);
if (it == mMap.end())
return NULL;
return &it->second;
}

View File

@@ -0,0 +1,52 @@
#ifndef ACCEPTED_LEDGER__H
#define ACCEPTED_LEDGER__H
#include "SerializedTransaction.h"
#include "TransactionMeta.h"
#include "Ledger.h"
class ALTransaction
{
protected:
SerializedTransaction::pointer mTxn;
TransactionMetaSet::pointer mMeta;
std::vector<RippleAddress> mAffected;
public:
ALTransaction(uint32 ledgerSeq, SerializerIterator& sit);
SerializedTransaction::ref getTxn() const { return mTxn; }
TransactionMetaSet::ref getMeta() const { return mMeta; }
const std::vector<RippleAddress>& getAffected() const { return mAffected; }
int getIndex() const { return mMeta->getIndex(); }
TER getResult() const { return mMeta->getResultTER(); }
};
class AcceptedLedger
{
public:
typedef std::map<int, ALTransaction> map_t;
typedef map_t::value_type value_type;
typedef map_t::const_iterator const_iterator;
protected:
Ledger::pointer mLedger;
map_t mMap;
void insert(const ALTransaction&);
public:
AcceptedLedger(Ledger::ref ledger);
Ledger::ref getLedger() const { return mLedger; }
const map_t& getMap() const { return mMap; }
int getLedgerSeq() const { return mLedger->getLedgerSeq(); }
int getTxnCount() const { return mMap.size(); }
const ALTransaction* getTxn(int) const;
};
#endif