refactor: Fix Sonar rule cpp:S4998 - avoid unique_ptr const& as parameter

Changed `FindChallenges()` parameter from `const std::unique_ptr<const Node<Key>>&` to const `Node*`.

Sonar rule `cpp:S4998` - https://sonarcloud.io/project/issues?issueStatuses=OPEN%2CCONFIRMED&branch=32351-8c0e673c4ac31c1c04750756de749fb813b2c33f&id=aureleoules_bitcoin&open=AZZ2q88IvFhp-eMuMy96:
> Replace this use of "unique_ptr" by a raw pointer or a reference (possibly const).
> Function parameters should not be of type "std::unique_ptr<T> const &" cpp:S4998
> Software qualities impacted: Maintainability
This commit is contained in:
Lőrinc 2025-04-28 16:08:51 +02:00
parent e400ac5352
commit 7e8ef959d0

View file

@ -297,12 +297,12 @@ using miniscript::operator""_mst;
using Node = miniscript::Node<CPubKey>;
/** Compute all challenges (pubkeys, hashes, timelocks) that occur in a given Miniscript. */
std::set<Challenge> FindChallenges(const NodeRef& root)
std::set<Challenge> FindChallenges(const Node* root)
{
std::set<Challenge> chal;
for (std::vector stack{root.get()}; !stack.empty();) {
const Node* ref{stack.back()};
for (std::vector stack{root}; !stack.empty();) {
const auto* ref{stack.back()};
stack.pop_back();
for (const auto& key : ref->keys) {
@ -348,7 +348,7 @@ struct MiniScriptTest : BasicTestingSetup {
/** Run random satisfaction tests. */
void TestSatisfy(const KeyConverter& converter, const std::string& testcase, const NodeRef& node) {
auto script = node->ToScript(converter);
const auto challenges{FindChallenges(node)}; // Find all challenges in the generated miniscript.
const auto challenges{FindChallenges(node.get())}; // Find all challenges in the generated miniscript.
std::vector<Challenge> challist(challenges.begin(), challenges.end());
for (int iter = 0; iter < 3; ++iter) {
std::shuffle(challist.begin(), challist.end(), m_rng);