Changeset View
Changeset View
Standalone View
Standalone View
src/script/descriptor.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | protected: | ||||
* This function is invoked once for every CScript produced by evaluating | * This function is invoked once for every CScript produced by evaluating | ||||
* m_script_arg, or just once in case m_script_arg is nullptr. | * m_script_arg, or just once in case m_script_arg is nullptr. | ||||
* @param pubkeys The evaluations of the m_pubkey_args field. | * @param pubkeys The evaluations of the m_pubkey_args field. | ||||
* @param script The evaluation of m_script_arg (or nullptr when | * @param script The evaluation of m_script_arg (or nullptr when | ||||
m_script_arg is nullptr). | m_script_arg is nullptr). | ||||
* @param out A FlatSigningProvider to put scripts or public keys in that | * @param out A FlatSigningProvider to put scripts or public keys in that | ||||
are necessary to the solver. | are necessary to the solver. | ||||
* The script and pubkeys argument to this function are | * The script arguments to this function are automatically | ||||
automatically added. | added, as is the origin info of the provided pubkeys. | ||||
* @return A vector with scriptPubKeys for this descriptor. | * @return A vector with scriptPubKeys for this descriptor. | ||||
*/ | */ | ||||
virtual std::vector<CScript> | virtual std::vector<CScript> | ||||
MakeScripts(const std::vector<CPubKey> &pubkeys, const CScript *script, | MakeScripts(const std::vector<CPubKey> &pubkeys, const CScript *script, | ||||
FlatSigningProvider &out) const = 0; | FlatSigningProvider &out) const = 0; | ||||
public: | public: | ||||
DescriptorImpl(std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, | DescriptorImpl(std::vector<std::unique_ptr<PubkeyProvider>> pubkeys, | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | bool ExpandHelper(int pos, const SigningProvider &arg, | ||||
out = Merge(out, subprovider); | out = Merge(out, subprovider); | ||||
} | } | ||||
std::vector<CPubKey> pubkeys; | std::vector<CPubKey> pubkeys; | ||||
pubkeys.reserve(entries.size()); | pubkeys.reserve(entries.size()); | ||||
for (auto &entry : entries) { | for (auto &entry : entries) { | ||||
pubkeys.push_back(entry.first); | pubkeys.push_back(entry.first); | ||||
out.origins.emplace(entry.first.GetID(), std::move(entry.second)); | out.origins.emplace(entry.first.GetID(), std::move(entry.second)); | ||||
out.pubkeys.emplace(entry.first.GetID(), entry.first); | |||||
} | } | ||||
if (m_script_arg) { | if (m_script_arg) { | ||||
for (const auto &subscript : subscripts) { | for (const auto &subscript : subscripts) { | ||||
out.scripts.emplace(CScriptID(subscript), subscript); | out.scripts.emplace(CScriptID(subscript), subscript); | ||||
std::vector<CScript> addscripts = | std::vector<CScript> addscripts = | ||||
MakeScripts(pubkeys, &subscript, out); | MakeScripts(pubkeys, &subscript, out); | ||||
for (auto &addscript : addscripts) { | for (auto &addscript : addscripts) { | ||||
output_scripts.push_back(std::move(addscript)); | output_scripts.push_back(std::move(addscript)); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | PKDescriptor(std::unique_ptr<PubkeyProvider> prov) | ||||
: DescriptorImpl(Singleton(std::move(prov)), {}, "pk") {} | : DescriptorImpl(Singleton(std::move(prov)), {}, "pk") {} | ||||
}; | }; | ||||
/** A parsed pkh(P) descriptor. */ | /** A parsed pkh(P) descriptor. */ | ||||
class PKHDescriptor final : public DescriptorImpl { | class PKHDescriptor final : public DescriptorImpl { | ||||
protected: | protected: | ||||
std::vector<CScript> MakeScripts(const std::vector<CPubKey> &keys, | std::vector<CScript> MakeScripts(const std::vector<CPubKey> &keys, | ||||
const CScript *, | const CScript *, | ||||
FlatSigningProvider &) const override { | FlatSigningProvider &out) const override { | ||||
return Singleton(GetScriptForDestination(keys[0].GetID())); | CKeyID id = keys[0].GetID(); | ||||
out.pubkeys.emplace(id, keys[0]); | |||||
return Singleton(GetScriptForDestination(id)); | |||||
} | } | ||||
public: | public: | ||||
PKHDescriptor(std::unique_ptr<PubkeyProvider> prov) | PKHDescriptor(std::unique_ptr<PubkeyProvider> prov) | ||||
: DescriptorImpl(Singleton(std::move(prov)), {}, "pkh") {} | : DescriptorImpl(Singleton(std::move(prov)), {}, "pkh") {} | ||||
}; | }; | ||||
/** A parsed combo(P) descriptor. */ | /** A parsed combo(P) descriptor. */ | ||||
class ComboDescriptor final : public DescriptorImpl { | class ComboDescriptor final : public DescriptorImpl { | ||||
protected: | protected: | ||||
std::vector<CScript> MakeScripts(const std::vector<CPubKey> &keys, | std::vector<CScript> MakeScripts(const std::vector<CPubKey> &keys, | ||||
const CScript *, | const CScript *, | ||||
FlatSigningProvider &out) const override { | FlatSigningProvider &out) const override { | ||||
std::vector<CScript> ret; | std::vector<CScript> ret; | ||||
CKeyID id = keys[0].GetID(); | CKeyID id = keys[0].GetID(); | ||||
out.pubkeys.emplace(id, keys[0]); | |||||
// P2PK | // P2PK | ||||
ret.emplace_back(GetScriptForRawPubKey(keys[0])); | ret.emplace_back(GetScriptForRawPubKey(keys[0])); | ||||
// P2PKH | // P2PKH | ||||
ret.emplace_back(GetScriptForDestination(id)); | ret.emplace_back(GetScriptForDestination(id)); | ||||
return ret; | return ret; | ||||
} | } | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 393 Lines • Show Last 20 Lines |