Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofpool.h
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | struct ProofPoolEntryProofIdKeyExtractor { | ||||
} | } | ||||
}; | }; | ||||
namespace bmi = boost::multi_index; | namespace bmi = boost::multi_index; | ||||
/** | /** | ||||
* Map a proof to each utxo. A proof can be mapped with several utxos. | * Map a proof to each utxo. A proof can be mapped with several utxos. | ||||
*/ | */ | ||||
struct ProofPool { | class ProofPool { | ||||
boost::multi_index_container< | boost::multi_index_container< | ||||
ProofPoolEntry, | ProofPoolEntry, | ||||
bmi::indexed_by< | bmi::indexed_by< | ||||
// index by utxo | // index by utxo | ||||
bmi::hashed_unique< | bmi::hashed_unique< | ||||
bmi::tag<by_utxo>, | bmi::tag<by_utxo>, | ||||
bmi::const_mem_fun<ProofPoolEntry, const COutPoint &, | bmi::const_mem_fun<ProofPoolEntry, const COutPoint &, | ||||
&ProofPoolEntry::getUTXO>, | &ProofPoolEntry::getUTXO>, | ||||
SaltedOutpointHasher>, | SaltedOutpointHasher>, | ||||
// index by proofid | // index by proofid | ||||
bmi::hashed_non_unique<bmi::tag<by_proofid>, | bmi::hashed_non_unique<bmi::tag<by_proofid>, | ||||
ProofPoolEntryProofIdKeyExtractor, | ProofPoolEntryProofIdKeyExtractor, | ||||
SaltedProofIdHasher>>> | SaltedProofIdHasher>>> | ||||
pool; | pool; | ||||
public: | |||||
enum AddProofStatus { | enum AddProofStatus { | ||||
REJECTED = 0, //!< Rejected due to conflicts | REJECTED = 0, //!< Rejected due to conflicts | ||||
SUCCEED = 1, //!< Added successfully | SUCCEED = 1, //!< Added successfully | ||||
DUPLICATED = 2, //!< Already in pool | DUPLICATED = 2, //!< Already in pool | ||||
}; | }; | ||||
AddProofStatus addProof(const ProofRef &proof); | AddProofStatus addProof(const ProofRef &proof); | ||||
bool removeProof(ProofRef proof); | bool removeProof(ProofRef proof); | ||||
void rescan(PeerManager &peerManager); | void rescan(PeerManager &peerManager); | ||||
ProofRef getProof(const ProofId &proofid) const; | ProofRef getProof(const ProofId &proofid) const; | ||||
ProofRef getProof(const COutPoint &outpoint) const; | |||||
size_t size() const { return pool.size(); } | |||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PROOFPOOL_H | #endif // BITCOIN_AVALANCHE_PROOFPOOL_H |