Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofpool.h
- This file was added.
// Copyright (c) 2021 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | |||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
#ifndef BITCOIN_AVALANCHE_PROOFPOOL_H | |||||
#define BITCOIN_AVALANCHE_PROOFPOOL_H | |||||
#include <avalanche/proof.h> | |||||
#include <avalanche/proofid.h> | |||||
#include <coins.h> | |||||
#include <primitives/transaction.h> | |||||
#include <boost/multi_index/hashed_index.hpp> | |||||
#include <boost/multi_index/mem_fun.hpp> | |||||
#include <boost/multi_index_container.hpp> | |||||
#include <cstdint> | |||||
namespace avalanche { | |||||
struct ProofPoolEntry { | |||||
size_t utxoIndex; | |||||
ProofRef proof; | |||||
const COutPoint &getUTXO() const { | |||||
return proof->getStakes().at(utxoIndex).getStake().getUTXO(); | |||||
} | |||||
ProofPoolEntry(size_t _utxoIndex, const ProofRef &_proof) | |||||
deadalnix: I should have caught up on this, but because you are capturing this, you might as well take by… | |||||
: utxoIndex(_utxoIndex), proof(_proof) {} | |||||
deadalnixUnsubmitted Not Done Inline Actionsand move here. deadalnix: and move here. | |||||
}; | |||||
struct by_utxo; | |||||
struct by_proofid; | |||||
struct ProofPoolEntryProofIdKeyExtractor { | |||||
using result_type = ProofId; | |||||
result_type operator()(const ProofPoolEntry &entry) const { | |||||
return entry.proof->getId(); | |||||
} | |||||
}; | |||||
namespace bmi = boost::multi_index; | |||||
/** | |||||
* Map a proof to each utxo. A proof can be mapped with several utxos. | |||||
*/ | |||||
using ProofPool = boost::multi_index_container< | |||||
ProofPoolEntry, | |||||
bmi::indexed_by< | |||||
// index by utxo | |||||
bmi::hashed_unique<bmi::tag<by_utxo>, | |||||
bmi::const_mem_fun<ProofPoolEntry, const COutPoint &, | |||||
&ProofPoolEntry::getUTXO>, | |||||
SaltedOutpointHasher>, | |||||
// index by proofid | |||||
bmi::hashed_non_unique<bmi::tag<by_proofid>, | |||||
ProofPoolEntryProofIdKeyExtractor, | |||||
SaltedProofIdHasher>>>; | |||||
} // namespace avalanche | |||||
#endif // BITCOIN_AVALANCHE_PROOFPOOL_H |
I should have caught up on this, but because you are capturing this, you might as well take by value.