Reorganized cheatcatcher for build issues
This commit is contained in:
74
src/cheatcatcher.h
Normal file
74
src/cheatcatcher.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/********************************************************************
|
||||
* (C) 2018 Michael Toutonghi
|
||||
*
|
||||
* Distributed under the MIT software license, see the accompanying
|
||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
*
|
||||
* This crypto-condition eval solves the problem of nothing-at-stake
|
||||
* in a proof of stake consensus system.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CHEATCATCHER_H
|
||||
#define CHEATCATCHER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "streams.h"
|
||||
#include "script/script.h"
|
||||
#include "uint256.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class CTxHolder
|
||||
{
|
||||
public:
|
||||
uint256 utxo;
|
||||
uint32_t height;
|
||||
CTransaction tx;
|
||||
CTxHolder(const CTransaction &_tx, uint32_t _height) : height(_height), tx(_tx) {
|
||||
CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
hw << tx.vin[0].prevout.hash;
|
||||
hw << tx.vin[0].prevout.n;
|
||||
utxo = hw.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CCheatList
|
||||
{
|
||||
private:
|
||||
std::multimap<const int32_t, CTxHolder> orderedCheatCandidates;
|
||||
std::multimap<const uint256, CTxHolder *> indexedCheatCandidates;
|
||||
CCriticalSection cs_cheat;
|
||||
|
||||
public:
|
||||
CCheatList() {}
|
||||
|
||||
// prune all transactions in the list below height
|
||||
uint32_t Prune(uint32_t height);
|
||||
|
||||
// check to see if a transaction that could be a cheat for the passed transaction is in our list
|
||||
bool IsCheatInList(const CTransaction &tx, CTransaction *pcheatTx);
|
||||
|
||||
// check to see if there are cheat candidates of the same or greater block height in list
|
||||
bool IsHeightOrGreaterInList(uint32_t height)
|
||||
{
|
||||
auto range = orderedCheatCandidates.equal_range(height);
|
||||
return (range.first == orderedCheatCandidates.end());
|
||||
}
|
||||
|
||||
// add a potential cheat transaction to the list. we do this for all stake transactions from orphaned stakes
|
||||
bool Add(CTxHolder &txh);
|
||||
|
||||
// remove a transaction from the the list
|
||||
void Remove(const CTxHolder &txh);
|
||||
};
|
||||
|
||||
|
||||
extern CCheatList cheatList;
|
||||
extern boost::optional<libzcash::SaplingPaymentAddress> cheatCatcher;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user