Skip to content

Commit

Permalink
refactor: new method listMNCollaterials() for chain interface
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Nov 29, 2023
1 parent 221dc4a commit 1609dba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class Chain
//! Check if block is chainlocked.
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
//! or contents.
virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,22 @@ class ChainImpl : public Chain
if (m_node.llmq_ctx == nullptr || m_node.llmq_ctx->clhandler == nullptr) return false;
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
{
WAIT_LOCK(cs_main, lock);
Expand Down
9 changes: 4 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4302,18 +4302,17 @@ void CWallet::ListLockedCoins(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);
for (const auto &o : setWalletUTXO) {
auto it = mapWallet.find(o.hash);
if (it != mapWallet.end()) {
const auto &p = it->second;
if (CDeterministicMNManager::IsProTxWithCollateral(p.tx, o.n) || mnList.HasMNByCollateral(o)) {
vOutpts.emplace_back(o);
}
const auto &ptx = it->second;
outputs.emplace_back(ptx.tx, o.n);
}
}
vOutpts = m_chain->listMNCollaterials(outputs);
}

/** @} */ // end of Actions
Expand Down

0 comments on commit 1609dba

Please sign in to comment.