MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ScriptMaker

Class ScriptMaker

src/script/descriptor.cpp:1594–1626  ·  view source on GitHub ↗

* The context for converting a Miniscript descriptor into a Script. */

Source from the content-addressed store, hash-verified

1592 * The context for converting a Miniscript descriptor into a Script.
1593 */
1594class ScriptMaker {
1595 //! Keys contained in the Miniscript (the evaluation of DescriptorImpl::m_pubkey_args).
1596 const std::vector<CPubKey>& m_keys;
1597 //! The script context we're operating within (Tapscript or P2WSH).
1598 const miniscript::MiniscriptContext m_script_ctx;
1599
1600 //! Get the ripemd160(sha256()) hash of this key.
1601 //! Any key that is valid in a descriptor serializes as 32 bytes within a Tapscript context. So we
1602 //! must not hash the sign-bit byte in this case.
1603 uint160 GetHash160(uint32_t key) const {
1604 if (miniscript::IsTapscript(m_script_ctx)) {
1605 return Hash160(XOnlyPubKey{m_keys[key]});
1606 }
1607 return m_keys[key].GetID();
1608 }
1609
1610public:
1611 ScriptMaker(const std::vector<CPubKey>& keys LIFETIMEBOUND, const miniscript::MiniscriptContext script_ctx) : m_keys(keys), m_script_ctx{script_ctx} {}
1612
1613 std::vector<unsigned char> ToPKBytes(uint32_t key) const {
1614 // In Tapscript keys always serialize as x-only, whether an x-only key was used in the descriptor or not.
1615 if (!miniscript::IsTapscript(m_script_ctx)) {
1616 return {m_keys[key].begin(), m_keys[key].end()};
1617 }
1618 const XOnlyPubKey xonly_pubkey{m_keys[key]};
1619 return {xonly_pubkey.begin(), xonly_pubkey.end()};
1620 }
1621
1622 std::vector<unsigned char> ToPKHBytes(uint32_t key) const {
1623 auto id = GetHash160(key);
1624 return {id.begin(), id.end()};
1625 }
1626};
1627
1628/**
1629 * The context for converting a Miniscript descriptor to its textual form.

Callers 1

MakeScriptsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected