Basic Taproot signing logic in script/sign.cpp

This commit is contained in:
Pieter Wuille
2021-02-27 20:33:22 -08:00
parent 49487bc3b6
commit a2380127e9
4 changed files with 166 additions and 4 deletions

View File

@@ -210,14 +210,26 @@ CScript GetScriptForRawPubKey(const CPubKey& pubkey);
/** Generate a multisig script. */
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
struct ShortestVectorFirstComparator
{
bool operator()(const std::vector<unsigned char>& a, const std::vector<unsigned char>& b) const
{
if (a.size() < b.size()) return true;
if (a.size() > b.size()) return false;
return a < b;
}
};
struct TaprootSpendData
{
/** The BIP341 internal key. */
XOnlyPubKey internal_key;
/** The Merkle root of the script tree (0 if no scripts). */
uint256 merkle_root;
/** Map from (script, leaf_version) to (sets of) control blocks. */
std::map<std::pair<CScript, int>, std::set<std::vector<unsigned char>>> scripts;
/** Map from (script, leaf_version) to (sets of) control blocks.
* The control blocks are sorted by size, so that the signing logic can
* easily prefer the cheapest one. */
std::map<std::pair<CScript, int>, std::set<std::vector<unsigned char>, ShortestVectorFirstComparator>> scripts;
/** Merge other TaprootSpendData (for the same scriptPubKey) into this. */
void Merge(TaprootSpendData other);
};