diff --git a/src/script/standard.cpp b/src/script/standard.cpp --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -225,38 +225,26 @@ } namespace { -class CScriptVisitor : public boost::static_visitor { -private: - CScript *script; - +class CScriptVisitor : public boost::static_visitor { public: - explicit CScriptVisitor(CScript *scriptin) { script = scriptin; } - - bool operator()(const CNoDestination &dest) const { - script->clear(); - return false; - } + CScript operator()(const CNoDestination &dest) const { return CScript(); } - bool operator()(const PKHash &keyID) const { - script->clear(); - *script << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY - << OP_CHECKSIG; - return true; + CScript operator()(const PKHash &keyID) const { + return CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) + << OP_EQUALVERIFY << OP_CHECKSIG; } - bool operator()(const ScriptHash &scriptID) const { - script->clear(); - *script << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL; - return true; + CScript operator()(const ScriptHash &scriptID) const { + return CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL; } }; + +const CScriptVisitor g_script_visitor; + } // namespace CScript GetScriptForDestination(const CTxDestination &dest) { - CScript script; - - boost::apply_visitor(CScriptVisitor(&script), dest); - return script; + return boost::apply_visitor(::g_script_visitor, dest); } CScript GetScriptForRawPubKey(const CPubKey &pubKey) {