Changeset View
Changeset View
Standalone View
Standalone View
src/script/standard.h
Show All 30 Lines | |||||
/** | /** | ||||
* Default setting for nMaxDatacarrierBytes. 220 bytes of data, +1 for | * Default setting for nMaxDatacarrierBytes. 220 bytes of data, +1 for | ||||
* OP_RETURN, +2 for the pushdata opcodes. | * OP_RETURN, +2 for the pushdata opcodes. | ||||
*/ | */ | ||||
static const unsigned int MAX_OP_RETURN_RELAY = 223; | static const unsigned int MAX_OP_RETURN_RELAY = 223; | ||||
/** | /** | ||||
* A data carrying output is an unspendable output containing data. The script | * A data carrying output is an unspendable output containing data. The script | ||||
* type is designated as TX_NULL_DATA. | * type is designated as TxoutType::NULL_DATA. | ||||
*/ | */ | ||||
extern bool fAcceptDatacarrier; | extern bool fAcceptDatacarrier; | ||||
enum txnouttype { | enum class TxoutType { | ||||
TX_NONSTANDARD, | NONSTANDARD, | ||||
// 'standard' transaction types: | // 'standard' transaction types: | ||||
TX_PUBKEY, | PUBKEY, | ||||
TX_PUBKEYHASH, | PUBKEYHASH, | ||||
TX_SCRIPTHASH, | SCRIPTHASH, | ||||
TX_MULTISIG, | MULTISIG, | ||||
// unspendable OP_RETURN script that carries data | // unspendable OP_RETURN script that carries data | ||||
TX_NULL_DATA, | NULL_DATA, | ||||
}; | }; | ||||
class CNoDestination { | class CNoDestination { | ||||
public: | public: | ||||
friend bool operator==(const CNoDestination &a, const CNoDestination &b) { | friend bool operator==(const CNoDestination &a, const CNoDestination &b) { | ||||
return true; | return true; | ||||
} | } | ||||
friend bool operator<(const CNoDestination &a, const CNoDestination &b) { | friend bool operator<(const CNoDestination &a, const CNoDestination &b) { | ||||
Show All 17 Lines | struct ScriptHash : public uint160 { | ||||
explicit ScriptHash(const uint160 &hash) : uint160(hash) {} | explicit ScriptHash(const uint160 &hash) : uint160(hash) {} | ||||
explicit ScriptHash(const CScript &script); | explicit ScriptHash(const CScript &script); | ||||
using uint160::uint160; | using uint160::uint160; | ||||
}; | }; | ||||
/** | /** | ||||
* A txout script template with a specific destination. It is either: | * A txout script template with a specific destination. It is either: | ||||
* * CNoDestination: no destination set | * * CNoDestination: no destination set | ||||
* * PKHash: TX_PUBKEYHASH destination (P2PKH) | * * PKHash: TxoutType::PUBKEYHASH destination (P2PKH) | ||||
* * ScriptHash: TX_SCRIPTHASH destination (P2SH) | * * ScriptHash: TxoutType::SCRIPTHASH destination (P2SH) | ||||
* A CTxDestination is the internal data type encoded in a bitcoin address | * A CTxDestination is the internal data type encoded in a bitcoin address | ||||
*/ | */ | ||||
typedef boost::variant<CNoDestination, PKHash, ScriptHash> CTxDestination; | typedef boost::variant<CNoDestination, PKHash, ScriptHash> CTxDestination; | ||||
/** Check whether a CTxDestination is a CNoDestination. */ | /** Check whether a CTxDestination is a CNoDestination. */ | ||||
bool IsValidDestination(const CTxDestination &dest); | bool IsValidDestination(const CTxDestination &dest); | ||||
/** Get the name of a txnouttype as a C string, or nullptr if unknown. */ | /** Get the name of a TxoutType as a string */ | ||||
std::string GetTxnOutputType(txnouttype t); | std::string GetTxnOutputType(TxoutType t); | ||||
/** | /** | ||||
* Parse a scriptPubKey and identify script type for standard scripts. If | * Parse a scriptPubKey and identify script type for standard scripts. If | ||||
* successful, returns script type and parsed pubkeys or hashes, depending on | * successful, returns script type and parsed pubkeys or hashes, depending on | ||||
* the type. For example, for a P2SH script, vSolutionsRet will contain the | * the type. For example, for a P2SH script, vSolutionsRet will contain the | ||||
* script hash, for P2PKH it will contain the key hash, etc. | * script hash, for P2PKH it will contain the key hash, etc. | ||||
* | * | ||||
* @param[in] scriptPubKey Script to parse | * @param[in] scriptPubKey Script to parse | ||||
* @param[out] vSolutionsRet Vector of parsed pubkeys and hashes | * @param[out] vSolutionsRet Vector of parsed pubkeys and hashes | ||||
* @return The script type. TX_NONSTANDARD represents a | * @return The script type. TxoutType::NONSTANDARD | ||||
* failed solve. | * represents a failed solve. | ||||
*/ | */ | ||||
txnouttype Solver(const CScript &scriptPubKey, | TxoutType Solver(const CScript &scriptPubKey, | ||||
std::vector<std::vector<uint8_t>> &vSolutionsRet); | std::vector<std::vector<uint8_t>> &vSolutionsRet); | ||||
/** | /** | ||||
* Parse a standard scriptPubKey for the destination address. Assigns result to | * Parse a standard scriptPubKey for the destination address. Assigns result to | ||||
* the addressRet parameter and returns true if successful. For multisig | * the addressRet parameter and returns true if successful. For multisig | ||||
* scripts, instead use ExtractDestinations. Currently only works for P2PK, | * scripts, instead use ExtractDestinations. Currently only works for P2PK, | ||||
* P2PKH, and P2SH scripts. | * P2PKH, and P2SH scripts. | ||||
*/ | */ | ||||
bool ExtractDestination(const CScript &scriptPubKey, | bool ExtractDestination(const CScript &scriptPubKey, | ||||
CTxDestination &addressRet); | CTxDestination &addressRet); | ||||
/** | /** | ||||
* Parse a standard scriptPubKey with one or more destination addresses. For | * Parse a standard scriptPubKey with one or more destination addresses. For | ||||
* multisig scripts, this populates the addressRet vector with the pubkey IDs | * multisig scripts, this populates the addressRet vector with the pubkey IDs | ||||
* and nRequiredRet with the n required to spend. For other destinations, | * and nRequiredRet with the n required to spend. For other destinations, | ||||
* addressRet is populated with a single value and nRequiredRet is set to 1. | * addressRet is populated with a single value and nRequiredRet is set to 1. | ||||
* Returns true if successful. | * Returns true if successful. | ||||
* | * | ||||
* Note: this function confuses destinations (a subset of CScripts that are | * Note: this function confuses destinations (a subset of CScripts that are | ||||
* encodable as an address) with key identifiers (of keys involved in a | * encodable as an address) with key identifiers (of keys involved in a | ||||
* CScript), and its use should be phased out. | * CScript), and its use should be phased out. | ||||
*/ | */ | ||||
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, | bool ExtractDestinations(const CScript &scriptPubKey, TxoutType &typeRet, | ||||
std::vector<CTxDestination> &addressRet, | std::vector<CTxDestination> &addressRet, | ||||
int &nRequiredRet); | int &nRequiredRet); | ||||
/** | /** | ||||
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH | * Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH | ||||
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty | * script for a CKeyID destination, a P2SH script for a CScriptID, and an empty | ||||
* script for CNoDestination. | * script for CNoDestination. | ||||
*/ | */ | ||||
Show All 9 Lines |