@@ -138,40 +138,41 @@ std::optional<std::pair<int, std::vector<std::span<const unsigned char>>>> Match
138138 return std::pair{*threshold, std::move (keyspans)};
139139}
140140
141- TxoutType Solver (const CScript& scriptPubKey, std::vector<std::vector<unsigned char >>& vSolutionsRet)
141+ TxoutType Solver (const CScript& scriptPubKey, std::vector<std::vector<unsigned char >>* vSolutionsRet)
142142{
143- vSolutionsRet. clear ();
143+ if ( vSolutionsRet) vSolutionsRet-> clear ();
144144
145145 // Shortcut for pay-to-script-hash, which are more constrained than the other types:
146146 // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
147- if (scriptPubKey.IsPayToScriptHash ())
148- {
147+ if (scriptPubKey.IsPayToScriptHash ()) {
149148 std::vector<unsigned char > hashBytes (scriptPubKey.begin ()+2 , scriptPubKey.begin ()+22 );
150- vSolutionsRet. push_back (hashBytes);
149+ if ( vSolutionsRet) vSolutionsRet-> push_back (hashBytes);
151150 return TxoutType::SCRIPTHASH;
152151 }
153152
154153 int witnessversion;
155154 std::vector<unsigned char > witnessprogram;
156155 if (scriptPubKey.IsWitnessProgram (witnessversion, witnessprogram)) {
157156 if (witnessversion == 0 && witnessprogram.size () == WITNESS_V0_KEYHASH_SIZE) {
158- vSolutionsRet. push_back (std::move (witnessprogram));
157+ if ( vSolutionsRet) vSolutionsRet-> push_back (std::move (witnessprogram));
159158 return TxoutType::WITNESS_V0_KEYHASH;
160159 }
161160 if (witnessversion == 0 && witnessprogram.size () == WITNESS_V0_SCRIPTHASH_SIZE) {
162- vSolutionsRet. push_back (std::move (witnessprogram));
161+ if ( vSolutionsRet) vSolutionsRet-> push_back (std::move (witnessprogram));
163162 return TxoutType::WITNESS_V0_SCRIPTHASH;
164163 }
165164 if (witnessversion == 1 && witnessprogram.size () == WITNESS_V1_TAPROOT_SIZE) {
166- vSolutionsRet. push_back (std::move (witnessprogram));
165+ if ( vSolutionsRet) vSolutionsRet-> push_back (std::move (witnessprogram));
167166 return TxoutType::WITNESS_V1_TAPROOT;
168167 }
169168 if (scriptPubKey.IsPayToAnchor ()) {
170169 return TxoutType::ANCHOR;
171170 }
172171 if (witnessversion != 0 ) {
173- vSolutionsRet.push_back (std::vector<unsigned char >{(unsigned char )witnessversion});
174- vSolutionsRet.push_back (std::move (witnessprogram));
172+ if (vSolutionsRet) {
173+ vSolutionsRet->push_back (std::vector<unsigned char >{(unsigned char )witnessversion});
174+ vSolutionsRet->push_back (std::move (witnessprogram));
175+ }
175176 return TxoutType::WITNESS_UNKNOWN;
176177 }
177178 return TxoutType::NONSTANDARD;
@@ -188,25 +189,27 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
188189
189190 std::vector<unsigned char > data;
190191 if (MatchPayToPubkey (scriptPubKey, data)) {
191- vSolutionsRet. push_back (std::move (data));
192+ if ( vSolutionsRet) vSolutionsRet-> push_back (std::move (data));
192193 return TxoutType::PUBKEY;
193194 }
194195
195196 if (MatchPayToPubkeyHash (scriptPubKey, data)) {
196- vSolutionsRet. push_back (std::move (data));
197+ if ( vSolutionsRet) vSolutionsRet-> push_back (std::move (data));
197198 return TxoutType::PUBKEYHASH;
198199 }
199200
200201 int required;
201202 std::vector<std::vector<unsigned char >> keys;
202203 if (MatchMultisig (scriptPubKey, required, keys)) {
203- vSolutionsRet.push_back ({static_cast <unsigned char >(required)}); // safe as required is in range 1..20
204- vSolutionsRet.insert (vSolutionsRet.end (), keys.begin (), keys.end ());
205- vSolutionsRet.push_back ({static_cast <unsigned char >(keys.size ())}); // safe as size is in range 1..20
204+ if (vSolutionsRet) {
205+ vSolutionsRet->push_back ({static_cast <unsigned char >(required)}); // safe as required is in range 1..20
206+ vSolutionsRet->insert (vSolutionsRet->end (), keys.begin (), keys.end ());
207+ vSolutionsRet->push_back ({static_cast <unsigned char >(keys.size ())}); // safe as size is in range 1..20
208+ }
206209 return TxoutType::MULTISIG;
207210 }
208211
209- vSolutionsRet. clear ();
212+ if ( vSolutionsRet) vSolutionsRet-> clear ();
210213 return TxoutType::NONSTANDARD;
211214}
212215
0 commit comments