Bitcoin ABC  0.22.13
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 <amount.h>
10 #include <pubkey.h>
11 #include <script/script_flags.h>
12 #include <uint256.h>
13 
14 #include <boost/variant.hpp>
15 
16 static const bool DEFAULT_ACCEPT_DATACARRIER = true;
17 
18 class CKeyID;
19 class CScript;
20 
22 class CScriptID : public uint160 {
23 public:
24  CScriptID() : uint160() {}
25  explicit CScriptID(const CScript &in);
26  CScriptID(const uint160 &in) : uint160(in) {}
27 };
28 
33 static const unsigned int MAX_OP_RETURN_RELAY = 223;
34 
39 extern bool fAcceptDatacarrier;
40 
41 enum txnouttype {
43  // 'standard' transaction types:
48  // unspendable OP_RETURN script that carries data
50 };
51 
53 public:
54  friend bool operator==(const CNoDestination &a, const CNoDestination &b) {
55  return true;
56  }
57  friend bool operator<(const CNoDestination &a, const CNoDestination &b) {
58  return true;
59  }
60 };
61 
62 struct PKHash : public uint160 {
63  PKHash() : uint160() {}
64  explicit PKHash(const uint160 &hash) : uint160(hash) {}
65  explicit PKHash(const CPubKey &pubkey);
66  using uint160::uint160;
67 };
68 
69 struct ScriptHash : public uint160 {
71  // This doesn't do what you'd expect.
72  // Use ScriptHash(GetScriptForDestination(...)) instead.
73  explicit ScriptHash(const PKHash &hash) = delete;
74 
75  explicit ScriptHash(const uint160 &hash) : uint160(hash) {}
76  explicit ScriptHash(const CScript &script);
77  using uint160::uint160;
78 };
79 
87 typedef boost::variant<CNoDestination, PKHash, ScriptHash> CTxDestination;
88 
90 bool IsValidDestination(const CTxDestination &dest);
91 
93 const char *GetTxnOutputType(txnouttype t);
94 
106 txnouttype Solver(const CScript &scriptPubKey,
107  std::vector<std::vector<uint8_t>> &vSolutionsRet);
108 
115 bool ExtractDestination(const CScript &scriptPubKey,
116  CTxDestination &addressRet);
117 
129 bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet,
130  std::vector<CTxDestination> &addressRet,
131  int &nRequiredRet);
132 
139 
141 CScript GetScriptForRawPubKey(const CPubKey &pubkey);
142 
144 CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey> &keys);
145 
146 #endif // BITCOIN_SCRIPT_STANDARD_H
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:269
CScript GetScriptForRawPubKey(const CPubKey &pubkey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:253
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
Definition: standard.h:33
ScriptHash()
Definition: standard.h:70
txnouttype Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: standard.cpp:102
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:152
friend bool operator==(const CNoDestination &a, const CNoDestination &b)
Definition: standard.h:54
CScriptID()
Definition: standard.h:24
uint160()
Definition: uint256.h:110
friend bool operator<(const CNoDestination &a, const CNoDestination &b)
Definition: standard.h:57
An encapsulated public key.
Definition: pubkey.h:31
PKHash(const uint160 &hash)
Definition: standard.h:64
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:258
bool fAcceptDatacarrier
A data carrying output is an unspendable output containing data.
Definition: standard.cpp:13
CScriptID(const uint160 &in)
Definition: standard.h:26
txnouttype
Definition: standard.h:41
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:246
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
160-bit opaque blob.
Definition: uint256.h:108
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:23
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:178
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:87
ScriptHash(const uint160 &hash)
Definition: standard.h:75
PKHash()
Definition: standard.h:63