mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 06:25:51 +00:00
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:
35
src/cpp/ripple/AcceptedLedger.cpp
Normal file
35
src/cpp/ripple/AcceptedLedger.cpp
Normal 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;
|
||||||
|
}
|
||||||
52
src/cpp/ripple/AcceptedLedger.h
Normal file
52
src/cpp/ripple/AcceptedLedger.h
Normal 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
|
||||||
Reference in New Issue
Block a user