merge #18863: Make CScriptVisitor stateless

This commit is contained in:
Kittywhiskers Van Gogh 2020-05-04 10:50:43 +01:00
parent dfea329f69
commit c60491eef1

View File

@ -202,38 +202,32 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::
namespace namespace
{ {
class CScriptVisitor : public boost::static_visitor<bool> class CScriptVisitor : public boost::static_visitor<CScript>
{ {
private:
CScript *script;
public: public:
explicit CScriptVisitor(CScript *scriptin) { script = scriptin; } CScript operator()(const CNoDestination& dest) const
{
bool operator()(const CNoDestination &dest) const { return CScript();
script->clear();
return false;
} }
bool operator()(const CKeyID &keyID) const { CScript operator()(const CKeyID& keyID) const
script->clear(); {
*script << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; return CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
return true;
} }
bool operator()(const CScriptID &scriptID) const { CScript operator()(const CScriptID& scriptID) const
script->clear(); {
*script << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL; return CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
return true;
} }
}; };
const CScriptVisitor g_script_visitor;
} // namespace } // namespace
CScript GetScriptForDestination(const CTxDestination& dest) CScript GetScriptForDestination(const CTxDestination& dest)
{ {
CScript script; return boost::apply_visitor(::g_script_visitor, dest);
boost::apply_visitor(CScriptVisitor(&script), dest);
return script;
} }
CScript GetScriptForRawPubKey(const CPubKey& pubKey) CScript GetScriptForRawPubKey(const CPubKey& pubKey)