6 #ifndef BITCOIN_SCRIPT_STANDARD_H
7 #define BITCOIN_SCRIPT_STANDARD_H
149 using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown>;
200 bool operator()(
const std::vector<unsigned char>& a,
const std::vector<unsigned char>& b)
const
202 if (a.size() < b.size())
return true;
203 if (a.size() > b.size())
return false;
313 static bool ValidDepths(
const std::vector<int>& depths);
317 std::vector<std::tuple<uint8_t, uint8_t, std::vector<unsigned char>>>
GetTreeTuples()
const;
A reference to a CKey: the Hash160 of its serialized public key.
friend bool operator<(const CNoDestination &a, const CNoDestination &b)
friend bool operator==(const CNoDestination &a, const CNoDestination &b)
An encapsulated public key.
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
CScriptID(const uint160 &in)
Utility class to construct Taproot outputs from internal key and script tree.
WitnessV1Taproot GetOutput()
Compute scriptPubKey (after Finalize()).
static NodeInfo Combine(NodeInfo &&a, NodeInfo &&b)
Combine information about a parent Merkle tree node from its child nodes.
TaprootSpendData GetSpendData() const
Compute spending data (after Finalize()).
bool IsComplete() const
Return whether there were either no leaves, or the leaves form a Huffman tree.
bool HasScripts() const
Returns true if there are any tapscripts.
static bool ValidDepths(const std::vector< int > &depths)
Check if a list of depths is legal (will lead to IsComplete()).
void Insert(NodeInfo &&node, int depth)
Insert information about a node at a certain depth, and propagate information up.
XOnlyPubKey m_internal_key
The internal key, set when finalizing.
XOnlyPubKey m_output_key
The output key, computed when finalizing.
bool IsValid() const
Return true if so far all input was valid.
TaprootBuilder & Add(int depth, Span< const unsigned char > script, int leaf_version, bool track=true)
Add a new script at a certain depth in the tree.
std::vector< std::optional< NodeInfo > > m_branch
The current state of the builder.
TaprootBuilder & AddOmitted(int depth, const uint256 &hash)
Like Add(), but for a Merkle node with a given hash to the tree.
TaprootBuilder & Finalize(const XOnlyPubKey &internal_key)
Finalize the construction.
bool m_parity
The tweak parity, computed when finalizing.
std::vector< std::tuple< uint8_t, uint8_t, std::vector< unsigned char > > > GetTreeTuples() const
Returns a vector of tuples representing the depth, leaf version, and script.
bool m_valid
Whether the builder is in a valid state so far.
opcodetype
Script opcodes.
constexpr bool IsPushdataOp(opcodetype opcode)
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS
Mandatory script verification flags that all new blocks must comply with for them to be valid.
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for -datacarriersize.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
CScript GetScriptForRawPubKey(const CPubKey &pubkey)
Generate a P2PK script for the given pubkey.
std::optional< std::pair< int, std::vector< Span< const unsigned char > > > > MatchMultiA(const CScript &script LIFETIMEBOUND)
Determine if script is a "multi_a" script.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
std::optional< std::vector< std::tuple< int, std::vector< unsigned char >, int > > > InferTaprootTree(const TaprootSpendData &spenddata, const XOnlyPubKey &output)
Given a TaprootSpendData and the output key, reconstruct its script tree.
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
@ NULL_DATA
unspendable OP_RETURN script that carries data
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
static const bool DEFAULT_ACCEPT_DATACARRIER
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
CKeyID ToKeyID(const PKHash &key_hash)
PKHash(const uint160 &hash)
ScriptHash(const WitnessV0KeyHash &hash)=delete
ScriptHash(const uint160 &hash)
ScriptHash(const PKHash &hash)=delete
bool operator()(const std::vector< unsigned char > &a, const std::vector< unsigned char > &b) const
Information about a tracked leaf in the Merkle tree.
std::vector< uint256 > merkle_branch
The hashing partners above this leaf.
int leaf_version
The leaf version for that script.
std::vector< unsigned char > script
The script.
Information associated with a node in the Merkle tree.
uint256 hash
Merkle hash of this node.
std::vector< LeafInfo > leaves
Tracked leaves underneath this node (either from the node itself, or its children).
uint256 merkle_root
The Merkle root of the script tree (0 if no scripts).
std::map< std::pair< std::vector< unsigned char >, int >, std::set< std::vector< unsigned char >, ShortestVectorFirstComparator > > scripts
Map from (script, leaf_version) to (sets of) control blocks.
void Merge(TaprootSpendData other)
Merge other TaprootSpendData (for the same scriptPubKey) into this.
XOnlyPubKey internal_key
The BIP341 internal key.
CTxDestination subtype to encode any future Witness version.
friend bool operator<(const WitnessUnknown &w1, const WitnessUnknown &w2)
unsigned char program[40]
friend bool operator==(const WitnessUnknown &w1, const WitnessUnknown &w2)
WitnessV0KeyHash(const uint160 &hash)
WitnessV0ScriptHash(const uint256 &hash)
WitnessV1Taproot(const XOnlyPubKey &xpk)