Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
standard.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2016 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_SCRIPT_STANDARD_H
7#define BITCOIN_SCRIPT_STANDARD_H
8
9#include <pubkey.h>
10#include <script/script_flags.h>
11#include <uint256.h>
12#include <util/hash_type.h>
13
14#include <string>
15#include <variant>
16
17static const bool DEFAULT_ACCEPT_DATACARRIER = true;
18
19class CKeyID;
20class CScript;
21struct ScriptHash;
22
24class CScriptID : public BaseHash<uint160> {
25public:
27 explicit CScriptID(const CScript &in);
28 explicit CScriptID(const uint160 &in) : BaseHash(in) {}
29 explicit CScriptID(const ScriptHash &in);
30};
31
36static const unsigned int MAX_OP_RETURN_RELAY = 223;
37
38enum class TxoutType {
40 // 'standard' transaction types:
41 PUBKEY,
45 // unspendable OP_RETURN script that carries data
47};
48
50public:
51 friend bool operator==(const CNoDestination &a, const CNoDestination &b) {
52 return true;
53 }
54 friend bool operator<(const CNoDestination &a, const CNoDestination &b) {
55 return true;
56 }
57};
58
59struct PKHash : public BaseHash<uint160> {
61 explicit PKHash(const uint160 &hash) : BaseHash(hash) {}
62 explicit PKHash(const CPubKey &pubkey);
63 explicit PKHash(const CKeyID &pubkey_id);
64};
66
67struct ScriptHash : public BaseHash<uint160> {
69 // This doesn't do what you'd expect.
70 // Use ScriptHash(GetScriptForDestination(...)) instead.
71 explicit ScriptHash(const PKHash &hash) = delete;
72
73 explicit ScriptHash(const uint160 &hash) : BaseHash(hash) {}
74 explicit ScriptHash(const CScript &script);
75 explicit ScriptHash(const CScriptID &script);
76};
77
85using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash>;
86
88bool IsValidDestination(const CTxDestination &dest);
89
91std::string GetTxnOutputType(TxoutType t);
92
104TxoutType Solver(const CScript &scriptPubKey,
105 std::vector<std::vector<uint8_t>> &vSolutionsRet);
106
113bool ExtractDestination(const CScript &scriptPubKey,
115
127bool ExtractDestinations(const CScript &scriptPubKey, TxoutType &typeRet,
128 std::vector<CTxDestination> &addressRet,
129 int &nRequiredRet);
130
137
140
142CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey> &keys);
143
144#endif // BITCOIN_SCRIPT_STANDARD_H
A reference to a CKey: the Hash160 of its serialized public key.
Definition pubkey.h:22
friend bool operator<(const CNoDestination &a, const CNoDestination &b)
Definition standard.h:54
friend bool operator==(const CNoDestination &a, const CNoDestination &b)
Definition standard.h:51
An encapsulated public key.
Definition pubkey.h:31
Serialized script, used inside transaction inputs and outputs.
Definition script.h:431
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition standard.h:24
CScriptID()
Definition standard.h:26
CScriptID(const uint160 &in)
Definition standard.h:28
160-bit opaque blob.
Definition uint256.h:117
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
Definition standard.h:36
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition standard.cpp:249
CScript GetScriptForRawPubKey(const CPubKey &pubkey)
Generate a P2PK script for the given pubkey.
Definition standard.cpp:244
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition standard.cpp:158
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition standard.cpp:108
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Definition standard.cpp:29
TxoutType
Definition standard.h:38
static const bool DEFAULT_ACCEPT_DATACARRIER
Definition standard.h:17
bool ExtractDestinations(const CScript &scriptPubKey, TxoutType &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
Definition standard.cpp:184
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition standard.cpp:260
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition standard.cpp:240
CKeyID ToKeyID(const PKHash &key_hash)
Definition standard.cpp:25
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition standard.h:85
PKHash(const uint160 &hash)
Definition standard.h:61
PKHash()
Definition standard.h:60
ScriptHash(const uint160 &hash)
Definition standard.h:73
ScriptHash(const PKHash &hash)=delete