Skip to content

Commit 5f72ddb

Browse files
author
MarcoFalke
committed
Merge #18863: refactor: Make CScriptVisitor stateless
3351c91 refactor: Make CScriptVisitor stateless (João Barbosa) Pull request description: `CScriptVisitor` was added in 1025440 (#1357) and the visitor return type was never used. Now `CScriptVisitor` is stateless and `CScript` is the return type. ACKs for top commit: MarcoFalke: ACK 3351c91 🏤 sipa: utACK 3351c91 Tree-SHA512: d158ad2ebe8ea4dc8cc090b943dd66fa5421a84f9443e16ab2d661df38e1a85de16ff13cbaa56924489d8d43cba25fa3cd8b6904bbbcbf356b886ffe8ffba19a
2 parents 62948ca + 3351c91 commit 5f72ddb

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

src/script/standard.cpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -241,59 +241,47 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::
241241

242242
namespace
243243
{
244-
class CScriptVisitor : public boost::static_visitor<bool>
244+
class CScriptVisitor : public boost::static_visitor<CScript>
245245
{
246-
private:
247-
CScript *script;
248246
public:
249-
explicit CScriptVisitor(CScript *scriptin) { script = scriptin; }
250-
251-
bool operator()(const CNoDestination &dest) const {
252-
script->clear();
253-
return false;
247+
CScript operator()(const CNoDestination& dest) const
248+
{
249+
return CScript();
254250
}
255251

256-
bool operator()(const PKHash &keyID) const {
257-
script->clear();
258-
*script << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
259-
return true;
252+
CScript operator()(const PKHash& keyID) const
253+
{
254+
return CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
260255
}
261256

262-
bool operator()(const ScriptHash &scriptID) const {
263-
script->clear();
264-
*script << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
265-
return true;
257+
CScript operator()(const ScriptHash& scriptID) const
258+
{
259+
return CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
266260
}
267261

268-
bool operator()(const WitnessV0KeyHash& id) const
262+
CScript operator()(const WitnessV0KeyHash& id) const
269263
{
270-
script->clear();
271-
*script << OP_0 << ToByteVector(id);
272-
return true;
264+
return CScript() << OP_0 << ToByteVector(id);
273265
}
274266

275-
bool operator()(const WitnessV0ScriptHash& id) const
267+
CScript operator()(const WitnessV0ScriptHash& id) const
276268
{
277-
script->clear();
278-
*script << OP_0 << ToByteVector(id);
279-
return true;
269+
return CScript() << OP_0 << ToByteVector(id);
280270
}
281271

282-
bool operator()(const WitnessUnknown& id) const
272+
CScript operator()(const WitnessUnknown& id) const
283273
{
284-
script->clear();
285-
*script << CScript::EncodeOP_N(id.version) << std::vector<unsigned char>(id.program, id.program + id.length);
286-
return true;
274+
return CScript() << CScript::EncodeOP_N(id.version) << std::vector<unsigned char>(id.program, id.program + id.length);
287275
}
288276
};
277+
278+
const CScriptVisitor g_script_visitor;
279+
289280
} // namespace
290281

291282
CScript GetScriptForDestination(const CTxDestination& dest)
292283
{
293-
CScript script;
294-
295-
boost::apply_visitor(CScriptVisitor(&script), dest);
296-
return script;
284+
return boost::apply_visitor(::g_script_visitor, dest);
297285
}
298286

299287
CScript GetScriptForRawPubKey(const CPubKey& pubKey)

0 commit comments

Comments
 (0)