Bitcoin Core  0.18.99
P2P Digital Currency
standard.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 <script/interpreter.h>
10 #include <uint256.h>
11 
12 #include <boost/variant.hpp>
13 
14 #include <stdint.h>
15 
16 static const bool DEFAULT_ACCEPT_DATACARRIER = true;
17 
18 class CKeyID;
19 class CScript;
20 
22 class CScriptID : public uint160
23 {
24 public:
25  CScriptID() : uint160() {}
26  explicit CScriptID(const CScript& in);
27  CScriptID(const uint160& in) : uint160(in) {}
28 };
29 
34 static const unsigned int MAX_OP_RETURN_RELAY = 83;
35 
40 extern bool fAcceptDatacarrier;
41 
43 extern unsigned nMaxDatacarrierBytes;
44 
55 
57 {
59  // 'standard' transaction types:
68 };
69 
71 public:
72  friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
73  friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
74 };
75 
76 struct PKHash : public uint160
77 {
78  PKHash() : uint160() {}
79  explicit PKHash(const uint160& hash) : uint160(hash) {}
80  explicit PKHash(const CPubKey& pubkey);
81  using uint160::uint160;
82 };
83 
84 struct ScriptHash : public uint160
85 {
87  explicit ScriptHash(const uint160& hash) : uint160(hash) {}
88  explicit ScriptHash(const CScript& script);
89  using uint160::uint160;
90 };
91 
93 {
95  explicit WitnessV0ScriptHash(const uint256& hash) : uint256(hash) {}
96  explicit WitnessV0ScriptHash(const CScript& script);
97  using uint256::uint256;
98 };
99 
100 struct WitnessV0KeyHash : public uint160
101 {
103  explicit WitnessV0KeyHash(const uint160& hash) : uint160(hash) {}
104  using uint160::uint160;
105 };
106 
109 {
110  unsigned int version;
111  unsigned int length;
112  unsigned char program[40];
113 
114  friend bool operator==(const WitnessUnknown& w1, const WitnessUnknown& w2) {
115  if (w1.version != w2.version) return false;
116  if (w1.length != w2.length) return false;
117  return std::equal(w1.program, w1.program + w1.length, w2.program);
118  }
119 
120  friend bool operator<(const WitnessUnknown& w1, const WitnessUnknown& w2) {
121  if (w1.version < w2.version) return true;
122  if (w1.version > w2.version) return false;
123  if (w1.length < w2.length) return true;
124  if (w1.length > w2.length) return false;
125  return std::lexicographical_compare(w1.program, w1.program + w1.length, w2.program, w2.program + w2.length);
126  }
127 };
128 
139 typedef boost::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown> CTxDestination;
140 
142 bool IsValidDestination(const CTxDestination& dest);
143 
145 const char* GetTxnOutputType(txnouttype t);
146 
157 txnouttype Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet);
158 
165 bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
166 
178 bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
179 
186 
188 CScript GetScriptForRawPubKey(const CPubKey& pubkey);
189 
191 CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
192 
201 CScript GetScriptForWitness(const CScript& redeemscript);
202 
203 #endif // BITCOIN_SCRIPT_STANDARD_H
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:325
WitnessV0KeyHash(const uint160 &hash)
Definition: standard.h:103
unspendable OP_RETURN script that carries data
Definition: standard.h:64
CScript GetScriptForRawPubKey(const CPubKey &pubkey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:297
unsigned char program[40]
Definition: standard.h:112
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
Definition: standard.h:34
ScriptHash()
Definition: standard.h:86
static const bool DEFAULT_ACCEPT_DATACARRIER
Definition: standard.h:16
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:156
friend bool operator==(const CNoDestination &a, const CNoDestination &b)
Definition: standard.h:72
unsigned int version
Definition: standard.h:110
CScriptID()
Definition: standard.h:25
unsigned int length
Definition: standard.h:111
uint160()
Definition: uint256.h:112
friend bool operator<(const CNoDestination &a, const CNoDestination &b)
Definition: standard.h:73
CScript GetScriptForWitness(const CScript &redeemscript)
Generate a pay-to-witness script for the given redeem script.
Definition: standard.cpp:313
Only for Witness versions not already defined above.
Definition: standard.h:67
CTxDestination subtype to encode any future Witness version.
Definition: standard.h:108
An encapsulated public key.
Definition: pubkey.h:30
PKHash(const uint160 &hash)
Definition: standard.h:79
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:302
bool fAcceptDatacarrier
A data carrying output is an unspendable output containing data.
Definition: standard.cpp:14
uint256()
Definition: uint256.h:123
CScriptID(const uint160 &in)
Definition: standard.h:27
WitnessV0ScriptHash(const uint256 &hash)
Definition: standard.h:95
txnouttype
Definition: standard.h:56
256-bit opaque blob.
Definition: uint256.h:121
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:289
friend bool operator==(const WitnessUnknown &w1, const WitnessUnknown &w2)
Definition: standard.h:114
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:390
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
160-bit opaque blob.
Definition: uint256.h:110
friend bool operator<(const WitnessUnknown &w1, const WitnessUnknown &w2)
Definition: standard.h:120
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
const char * GetTxnOutputType(txnouttype t)
Get the name of a txnouttype as a C string, or nullptr if unknown.
Definition: standard.cpp:28
unsigned nMaxDatacarrierBytes
Maximum size of TX_NULL_DATA scripts that this node considers standard.
Definition: standard.cpp:15
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
Definition: standard.cpp:200
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:139
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS
Mandatory script verification flags that all new blocks must comply with for them to be valid...
Definition: standard.h:54
txnouttype Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: standard.cpp:91
ScriptHash(const uint160 &hash)
Definition: standard.h:87
PKHash()
Definition: standard.h:78