2014-08-23 03:35:51 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
2014-09-09 10:00:42 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-08-23 03:35:51 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2023-08-09 07:36:08 -04:00
|
|
|
// The Solver functions are used by policy and the wallet, but not consensus.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_SCRIPT_SOLVER_H
|
|
|
|
#define BITCOIN_SCRIPT_SOLVER_H
|
2014-08-23 03:35:51 +02:00
|
|
|
|
2022-05-21 13:54:14 -05:00
|
|
|
#include <attributes.h>
|
2023-08-09 07:28:55 -04:00
|
|
|
#include <script/script.h>
|
2014-08-23 03:35:51 +02:00
|
|
|
|
2020-05-18 17:14:10 +09:00
|
|
|
#include <string>
|
2023-08-09 07:28:55 -04:00
|
|
|
#include <optional>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-08-23 03:35:51 +02:00
|
|
|
|
2023-08-09 07:28:55 -04:00
|
|
|
class CPubKey;
|
|
|
|
template <typename C> class Span;
|
2014-08-23 03:35:51 +02:00
|
|
|
|
2020-05-30 09:16:05 -04:00
|
|
|
enum class TxoutType {
|
|
|
|
NONSTANDARD,
|
2014-08-23 03:35:51 +02:00
|
|
|
// 'standard' transaction types:
|
2020-05-30 09:16:05 -04:00
|
|
|
PUBKEY,
|
|
|
|
PUBKEYHASH,
|
|
|
|
SCRIPTHASH,
|
|
|
|
MULTISIG,
|
|
|
|
NULL_DATA, //!< unspendable OP_RETURN script that carries data
|
|
|
|
WITNESS_V0_SCRIPTHASH,
|
|
|
|
WITNESS_V0_KEYHASH,
|
2020-09-11 14:34:10 -07:00
|
|
|
WITNESS_V1_TAPROOT,
|
2020-05-30 09:16:05 -04:00
|
|
|
WITNESS_UNKNOWN, //!< Only for Witness versions not already defined above
|
2014-08-23 03:35:51 +02:00
|
|
|
};
|
|
|
|
|
2020-05-30 09:16:05 -04:00
|
|
|
/** Get the name of a TxoutType as a string */
|
|
|
|
std::string GetTxnOutputType(TxoutType t);
|
2014-08-23 03:35:51 +02:00
|
|
|
|
2021-09-25 15:21:57 +02:00
|
|
|
constexpr bool IsPushdataOp(opcodetype opcode)
|
|
|
|
{
|
|
|
|
return opcode > OP_FALSE && opcode <= OP_PUSHDATA4;
|
|
|
|
}
|
|
|
|
|
2017-08-15 17:55:26 -07:00
|
|
|
/**
|
|
|
|
* Parse a scriptPubKey and identify script type for standard scripts. If
|
|
|
|
* successful, returns script type and parsed pubkeys or hashes, depending on
|
|
|
|
* the type. For example, for a P2SH script, vSolutionsRet will contain the
|
|
|
|
* script hash, for P2PKH it will contain the key hash, etc.
|
|
|
|
*
|
|
|
|
* @param[in] scriptPubKey Script to parse
|
|
|
|
* @param[out] vSolutionsRet Vector of parsed pubkeys and hashes
|
2020-05-30 09:16:05 -04:00
|
|
|
* @return The script type. TxoutType::NONSTANDARD represents a failed solve.
|
2017-08-15 17:55:26 -07:00
|
|
|
*/
|
2020-05-30 09:16:05 -04:00
|
|
|
TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet);
|
2017-08-15 17:55:26 -07:00
|
|
|
|
|
|
|
/** Generate a P2PK script for the given pubkey. */
|
2015-06-10 00:03:08 -07:00
|
|
|
CScript GetScriptForRawPubKey(const CPubKey& pubkey);
|
2017-08-15 17:55:26 -07:00
|
|
|
|
2022-01-10 13:45:03 -05:00
|
|
|
/** Determine if script is a "multi_a" script. Returns (threshold, keyspans) if so, and nullopt otherwise.
|
|
|
|
* The keyspans refer to bytes in the passed script. */
|
|
|
|
std::optional<std::pair<int, std::vector<Span<const unsigned char>>>> MatchMultiA(const CScript& script LIFETIMEBOUND);
|
|
|
|
|
2017-08-15 17:55:26 -07:00
|
|
|
/** Generate a multisig script. */
|
2014-09-11 19:15:29 +02:00
|
|
|
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
|
2017-08-15 17:55:26 -07:00
|
|
|
|
2023-08-09 07:36:08 -04:00
|
|
|
#endif // BITCOIN_SCRIPT_SOLVER_H
|