Bitcoin ABC  0.26.3
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 <consensus/amount.h>
10 #include <pubkey.h>
11 #include <script/script_flags.h>
12 #include <uint256.h>
13 #include <util/hash_type.h>
14 
15 #include <boost/variant.hpp>
16 
17 #include <string>
18 
19 static const bool DEFAULT_ACCEPT_DATACARRIER = true;
20 
21 class CKeyID;
22 class CScript;
23 struct ScriptHash;
24 
26 class CScriptID : public BaseHash<uint160> {
27 public:
29  explicit CScriptID(const CScript &in);
30  explicit CScriptID(const uint160 &in) : BaseHash(in) {}
31  explicit CScriptID(const ScriptHash &in);
32 };
33 
38 static const unsigned int MAX_OP_RETURN_RELAY = 223;
39 
44 extern bool fAcceptDatacarrier;
45 
46 enum class TxoutType {
48  // 'standard' transaction types:
49  PUBKEY,
50  PUBKEYHASH,
51  SCRIPTHASH,
52  MULTISIG,
53  // unspendable OP_RETURN script that carries data
54  NULL_DATA,
55 };
56 
58 public:
59  friend bool operator==(const CNoDestination &a, const CNoDestination &b) {
60  return true;
61  }
62  friend bool operator<(const CNoDestination &a, const CNoDestination &b) {
63  return true;
64  }
65 };
66 
67 struct PKHash : public BaseHash<uint160> {
68  PKHash() : BaseHash() {}
69  explicit PKHash(const uint160 &hash) : BaseHash(hash) {}
70  explicit PKHash(const CPubKey &pubkey);
71  explicit PKHash(const CKeyID &pubkey_id);
72 };
73 CKeyID ToKeyID(const PKHash &key_hash);
74 
75 struct ScriptHash : public BaseHash<uint160> {
77  // This doesn't do what you'd expect.
78  // Use ScriptHash(GetScriptForDestination(...)) instead.
79  explicit ScriptHash(const PKHash &hash) = delete;
80 
81  explicit ScriptHash(const uint160 &hash) : BaseHash(hash) {}
82  explicit ScriptHash(const CScript &script);
83  explicit ScriptHash(const CScriptID &script);
84 };
85 
93 typedef boost::variant<CNoDestination, PKHash, ScriptHash> CTxDestination;
94 
96 bool IsValidDestination(const CTxDestination &dest);
97 
99 std::string GetTxnOutputType(TxoutType t);
100 
112 TxoutType Solver(const CScript &scriptPubKey,
113  std::vector<std::vector<uint8_t>> &vSolutionsRet);
114 
121 bool ExtractDestination(const CScript &scriptPubKey,
122  CTxDestination &addressRet);
123 
135 bool ExtractDestinations(const CScript &scriptPubKey, TxoutType &typeRet,
136  std::vector<CTxDestination> &addressRet,
137  int &nRequiredRet);
138 
145 
147 CScript GetScriptForRawPubKey(const CPubKey &pubkey);
148 
150 CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey> &keys);
151 
152 #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:62
friend bool operator==(const CNoDestination &a, const CNoDestination &b)
Definition: standard.h:59
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:26
CScriptID()
Definition: standard.h:28
CScriptID(const uint160 &in)
Definition: standard.h:30
160-bit opaque blob.
Definition: uint256.h:115
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
Definition: standard.h:38
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:93
bool fAcceptDatacarrier
A data carrying output is an unspendable output containing data.
Definition: standard.cpp:15
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:252
CScript GetScriptForRawPubKey(const CPubKey &pubkey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:247
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:161
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
Definition: standard.cpp:32
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:111
TxoutType
Definition: standard.h:46
static const bool DEFAULT_ACCEPT_DATACARRIER
Definition: standard.h:19
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:187
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:263
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:243
CKeyID ToKeyID(const PKHash &key_hash)
Definition: standard.cpp:28
PKHash(const uint160 &hash)
Definition: standard.h:69
PKHash()
Definition: standard.h:68
ScriptHash(const uint160 &hash)
Definition: standard.h:81
ScriptHash()
Definition: standard.h:76
ScriptHash(const PKHash &hash)=delete