Bitcoin ABC  0.29.4
P2P Digital Currency
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 
17 static const bool DEFAULT_ACCEPT_DATACARRIER = true;
18 
19 class CKeyID;
20 class CScript;
21 struct ScriptHash;
22 
24 class CScriptID : public BaseHash<uint160> {
25 public:
27  explicit CScriptID(const CScript &in);
28  explicit CScriptID(const uint160 &in) : BaseHash(in) {}
29  explicit CScriptID(const ScriptHash &in);
30 };
31 
36 static const unsigned int MAX_OP_RETURN_RELAY = 223;
37 
38 enum class TxoutType {
40  // 'standard' transaction types:
41  PUBKEY,
42  PUBKEYHASH,
43  SCRIPTHASH,
44  MULTISIG,
45  // unspendable OP_RETURN script that carries data
46  NULL_DATA,
47 };
48 
50 public:
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 
59 struct PKHash : public BaseHash<uint160> {
60  PKHash() : BaseHash() {}
61  explicit PKHash(const uint160 &hash) : BaseHash(hash) {}
62  explicit PKHash(const CPubKey &pubkey);
63  explicit PKHash(const CKeyID &pubkey_id);
64 };
65 CKeyID ToKeyID(const PKHash &key_hash);
66 
67 struct 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 
85 using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash>;
86 
88 bool IsValidDestination(const CTxDestination &dest);
89 
91 std::string GetTxnOutputType(TxoutType t);
92 
104 TxoutType Solver(const CScript &scriptPubKey,
105  std::vector<std::vector<uint8_t>> &vSolutionsRet);
106 
113 bool ExtractDestination(const CScript &scriptPubKey,
114  CTxDestination &addressRet);
115 
127 bool ExtractDestinations(const CScript &scriptPubKey, TxoutType &typeRet,
128  std::vector<CTxDestination> &addressRet,
129  int &nRequiredRet);
130 
137 
139 CScript GetScriptForRawPubKey(const CPubKey &pubkey);
140 
142 CScript 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
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
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Definition: standard.cpp:29
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
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()
Definition: standard.h:68
ScriptHash(const PKHash &hash)=delete