mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +00:00
Obsolete code.# deleted: TransactionBundle.h
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
#include "TransactionBundle.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
// do we need to make sure this preserves the order you received the transactions? Otherwise when we run through it we can see invalid transactions that get funded later.
|
||||
// No we can just allow this. We just check when a transaction comes in and at ledger close.
|
||||
// There needs to be a predictable order or the hashes will all be different.
|
||||
//
|
||||
bool gTransactionSorter(const newcoin::Transaction& lhs, const newcoin::Transaction& rhs)
|
||||
{
|
||||
if(lhs.from() == rhs.from())
|
||||
{
|
||||
return(lhs.seqnum() < rhs.seqnum() );
|
||||
}else return lhs.from() < rhs.from();
|
||||
}
|
||||
|
||||
|
||||
TransactionBundle::TransactionBundle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool TransactionBundle::hasTransaction(TransactionPtr needle)
|
||||
{
|
||||
BOOST_FOREACH(TransactionPtr trans,mTransactions)
|
||||
{
|
||||
if( Transaction::isEqual(needle,trans) ) return(true);
|
||||
}
|
||||
|
||||
BOOST_FOREACH(TransactionPtr trans,mDisacrdedTransactions)
|
||||
{
|
||||
if( Transaction::isEqual(needle,trans) ) return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
void TransactionBundle::addTransactionsToPB(newcoin::FullLedger* ledger)
|
||||
{
|
||||
BOOST_FOREACH(TransactionPtr trans,mTransactions)
|
||||
{
|
||||
TransactionPtr newTrans=ledger->add_transactions();
|
||||
newTrans->operator=(trans);
|
||||
}
|
||||
}
|
||||
|
||||
void TransactionBundle::addDiscardedTransaction(TransactionPtr trans)
|
||||
{
|
||||
mDisacrdedTransactions.push_back(trans);
|
||||
//mDisacrdedTransactions.sort(gTransactionSorter);
|
||||
}
|
||||
|
||||
void TransactionBundle::addTransaction(const TransactionPtr trans)
|
||||
{
|
||||
mTransactions.push_back(trans);
|
||||
//mTransactions.sort(gTransactionSorter);
|
||||
}
|
||||
|
||||
|
||||
// determine if all the transactions until end time from this address are valid
|
||||
// return the amount left in this account
|
||||
uint64 TransactionBundle::checkValid(std::string address,
|
||||
uint64 startAmount,int startTime,int endTime)
|
||||
{
|
||||
// TODO: check that 2 transactions from the same address on the same second
|
||||
// that cause the amount to be < 0 both should be discarded.
|
||||
// TODO: do we need to do this:
|
||||
// it will also check if we can bring back discarded transactions
|
||||
// we can probably wait and do this at finalize
|
||||
bool sortDiscard=false;
|
||||
|
||||
for(list<newcoin::Transaction>::iterator iter=mTransactions.begin(); iter != mTransactions.end(); )
|
||||
{
|
||||
newcoin::Transaction& trans=(*iter);
|
||||
if(trans.seconds()>endTime) break;
|
||||
if(trans.seconds()>=startTime)
|
||||
{
|
||||
if(trans.dest()==address)
|
||||
{
|
||||
startAmount += getTotalTransAmount(trans);
|
||||
}else
|
||||
{ // check all the inputs to see if they are from this address
|
||||
int numInputs=trans.inputs_size();
|
||||
for(int n=0; n<numInputs; n++)
|
||||
{
|
||||
const newcoin::TransInput& input=trans.inputs(n);
|
||||
if(input.from()==address)
|
||||
{
|
||||
if(startAmount<input.amount())
|
||||
{ // this transaction is invalid
|
||||
sortDiscard=true;
|
||||
mDisacrdedTransactions.push_back(trans);
|
||||
mTransactions.erase(iter);
|
||||
continue;
|
||||
}else
|
||||
{
|
||||
startAmount -= input.amount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
if(sortDiscard)
|
||||
{
|
||||
mDisacrdedTransactions.sort(gTransactionSorter);
|
||||
}
|
||||
return(startAmount);
|
||||
}
|
||||
|
||||
|
||||
void TransactionBundle::updateMap(std::map<std::string,uint64>& moneyMap)
|
||||
{
|
||||
BOOST_FOREACH(newcoin::Transaction& trans, mTransactions)
|
||||
{
|
||||
uint64 total=0;
|
||||
int numInputs=trans.inputs_size();
|
||||
for(int n=0; n<numInputs; n++)
|
||||
{
|
||||
const newcoin::TransInput& input=trans.inputs(n);
|
||||
moneyMap[input.from()] -= input.amount();
|
||||
total += input.amount();
|
||||
}
|
||||
|
||||
moneyMap[trans.dest()] += total;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -1,45 +0,0 @@
|
||||
#ifndef __TRANSACTIONBUNDLE__
|
||||
#define __TRANSACTIONBUNDLE__
|
||||
|
||||
#include <list>
|
||||
#include "newcoin.pb.h"
|
||||
#include "types.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
|
||||
class TransactionBundle
|
||||
{
|
||||
// we have to order this before we hash so the hash will be consistent
|
||||
std::list<TransactionPtr> mTransactions;
|
||||
std::list<TransactionPtr> mDisacrdedTransactions;
|
||||
//std::list<newcoin::Transaction> mAllTransactions;
|
||||
public:
|
||||
TransactionBundle();
|
||||
|
||||
void clear(){ mTransactions.clear(); }
|
||||
|
||||
unsigned int size(){ return(mTransactions.size()); }
|
||||
|
||||
void addTransactionsToPB(newcoin::FullLedger* ledger);
|
||||
|
||||
bool hasTransaction(TransactionPtr trans);
|
||||
|
||||
// returns the amount of money this address holds at the end time
|
||||
// it will discard any transactions till endTime that bring amount held under 0
|
||||
uint64 checkValid(std::string address, uint64 startAmount,
|
||||
int startTime,int endTime);
|
||||
|
||||
void updateMap(std::map<std::string,uint64>& moneyMap);
|
||||
|
||||
// will check if all transactions after this are valid
|
||||
//void checkTransactions();
|
||||
void addTransaction(TransactionPtr trans);
|
||||
|
||||
// transaction is valid and signed except the guy didn't have the money
|
||||
void addDiscardedTransaction(TransactionPtr trans);
|
||||
|
||||
|
||||
//static uint64 getTotalTransAmount(TransactionPtr trans);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user