refactor: new method listMNCollaterials() for chain interface

This commit is contained in:
Konstantin Akimov 2023-11-28 18:47:59 +07:00 committed by PastaPastaPasta
parent 4966bf7582
commit 2c61d842a9
3 changed files with 22 additions and 5 deletions

View File

@ -141,6 +141,8 @@ public:
//! Check if block is chainlocked. //! Check if block is chainlocked.
virtual bool hasChainLock(int height, const uint256& hash) = 0; virtual bool hasChainLock(int height, const uint256& hash) = 0;
//! Return list of MN Collateral from outputs
virtual std::vector<COutPoint> listMNCollaterials(const std::vector<std::pair<const CTransactionRef&, unsigned int>>& outputs) = 0;
//! Return whether node has the block and optionally return block metadata //! Return whether node has the block and optionally return block metadata
//! or contents. //! or contents.
virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0; virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0;

View File

@ -727,6 +727,22 @@ public:
if (m_node.llmq_ctx == nullptr || m_node.llmq_ctx->clhandler == nullptr) return false; if (m_node.llmq_ctx == nullptr || m_node.llmq_ctx->clhandler == nullptr) return false;
return m_node.llmq_ctx->clhandler->HasChainLock(height, hash); return m_node.llmq_ctx->clhandler->HasChainLock(height, hash);
} }
std::vector<COutPoint> listMNCollaterials(const std::vector<std::pair<const CTransactionRef&, unsigned int>>& outputs) override
{
const CBlockIndex *tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip());
CDeterministicMNList mnList{};
if (tip != nullptr && deterministicMNManager != nullptr) {
mnList = deterministicMNManager->GetListForBlock(tip);
}
std::vector<COutPoint> listRet;
for (const auto& [tx, index]: outputs) {
COutPoint nextOut{tx->GetHash(), index};
if (CDeterministicMNManager::IsProTxWithCollateral(tx, index) || mnList.HasMNByCollateral(nextOut)) {
listRet.emplace_back(nextOut);
}
}
return listRet;
}
bool findBlock(const uint256& hash, const FoundBlock& block) override bool findBlock(const uint256& hash, const FoundBlock& block) override
{ {
WAIT_LOCK(cs_main, lock); WAIT_LOCK(cs_main, lock);

View File

@ -4299,18 +4299,17 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
void CWallet::ListProTxCoins(std::vector<COutPoint>& vOutpts) const void CWallet::ListProTxCoins(std::vector<COutPoint>& vOutpts) const
{ {
auto mnList = deterministicMNManager->GetListAtChainTip(); std::vector<std::pair<const CTransactionRef&, unsigned int>> outputs;
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
for (const auto &o : setWalletUTXO) { for (const auto &o : setWalletUTXO) {
auto it = mapWallet.find(o.hash); auto it = mapWallet.find(o.hash);
if (it != mapWallet.end()) { if (it != mapWallet.end()) {
const auto &p = it->second; const auto &ptx = it->second;
if (CDeterministicMNManager::IsProTxWithCollateral(p.tx, o.n) || mnList.HasMNByCollateral(o)) { outputs.emplace_back(ptx.tx, o.n);
vOutpts.emplace_back(o);
}
} }
} }
vOutpts = m_chain->listMNCollaterials(outputs);
} }
/** @} */ // end of Actions /** @} */ // end of Actions