Make this code work.

This commit is contained in:
JoelKatz
2012-06-18 17:01:35 -07:00
parent 74766e8884
commit d57236599e
2 changed files with 50 additions and 254 deletions

View File

@@ -1,56 +1,28 @@
#ifndef __VALIDATION_COLLECTION__
#define __VALIDATION_COLLECTION__
#include "../obj/src/newcoin.pb.h"
#include <boost/unordered_map.hpp>
#include <boost/thread/mutex.hpp>
#include "uint256.h"
#include "types.h"
#include "Ledger.h"
#include <list>
#include "SerializedValidation.h"
typedef boost::unordered_map<uint160, SerializedValidation::pointer> ValidationSet;
class ValidationCollection
{
protected:
// from ledger hash to the validation
//std::map<uint256, std::vector<newcoin::Validation> > mValidations;
//std::map<uint256, std::vector<newcoin::Validation> > mIgnoredValidations;
boost::mutex mValidationLock;
boost::unordered_map<uint256, ValidationSet> mValidations;
// this maps ledgerIndex to an array of groups. Each group is a list of validations.
// a validation can be in multiple groups since compatibility isn't transitive
//
class Group
{
public:
std::vector<newcoin::Validation> mValidations;
Ledger::pointer mSuperLedger;
bool addIfCompatible(Ledger::pointer ledger,newcoin::Validation& valid);
};
std::map<uint32, std::vector< Group > > mIndexGroups; // all the groups at each index
//std::map<uint32, std::vector< newcoin::Validation > > mIndexValidations; // all the validations at each index
bool hasValidation(uint32 ledgerIndex,uint160& hanko,uint32 seqnum);
void addToGroup(newcoin::Validation& valid);
void addToDB(newcoin::Validation& valid,int weCare);
public:
ValidationCollection();
ValidationCollection() { ; }
void save();
void load();
void addValidation(newcoin::Validation& valid);
void getValidations(uint32 ledgerIndex,std::vector<newcoin::Validation>& retVec);
// It can miss some compatible ledgers of course if you don't know them
// fills out retLedger if there is a consensusLedger you can check
// fills out retHash if there isn't a consensusLedger to check. We need to fetch this ledger
// returns false if there isn't a consensus yet or we are in the consensus
bool getConsensusLedger(uint32 ledgerIndex, uint256& ourHash, Ledger::pointer& retLedger, uint256& retHash);
int getSeqNum(uint32 ledgerIndex);
bool addValidation(SerializedValidation::pointer);
ValidationSet getValidations(const uint256& ledger);
void getValidationCount(const uint256& ledger, int& trusted, int& untrusted);
};
#endif