1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 
21 /** A reference to a CScript: the Hash160 of its serialization (see script.h) */
22 class CScriptID : public uint160
23 {
24 public:
CScriptID()25     CScriptID() : uint160() {}
26     CScriptID(const CScript& in);
CScriptID(const uint160 & in)27     CScriptID(const uint160& in) : uint160(in) {}
28 };
29 
30 static const unsigned int MAX_OP_RETURN_RELAY = 83; //!< bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
31 extern bool fAcceptDatacarrier;
32 extern unsigned nMaxDatacarrierBytes;
33 
34 /**
35  * Mandatory script verification flags that all new blocks must comply with for
36  * them to be valid. (but old blocks may not comply with) Currently just P2SH,
37  * but in the future other flags may be added, such as a soft-fork to enforce
38  * strict DER encoding.
39  *
40  * Failing one of these tests may trigger a DoS ban - see CheckInputs() for
41  * details.
42  */
43 static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
44 
45 enum txnouttype
46 {
47     TX_NONSTANDARD,
48     // 'standard' transaction types:
49     TX_PUBKEY,
50     TX_PUBKEYHASH,
51     TX_SCRIPTHASH,
52     TX_MULTISIG,
53     TX_NULL_DATA,
54     TX_WITNESS_V0_SCRIPTHASH,
55     TX_WITNESS_V0_KEYHASH,
56 };
57 
58 class CNoDestination {
59 public:
60     friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
61     friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
62 };
63 
64 /**
65  * A txout script template with a specific destination. It is either:
66  *  * CNoDestination: no destination set
67  *  * CKeyID: TX_PUBKEYHASH destination
68  *  * CScriptID: TX_SCRIPTHASH destination
69  *  A CTxDestination is the internal data type encoded in a CBitcoinAddress
70  */
71 typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
72 
73 const char* GetTxnOutputType(txnouttype t);
74 
75 bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
76 bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
77 bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
78 
79 CScript GetScriptForDestination(const CTxDestination& dest);
80 CScript GetScriptForRawPubKey(const CPubKey& pubkey);
81 CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
82 CScript GetScriptForWitness(const CScript& redeemscript);
83 
84 #endif // BITCOIN_SCRIPT_STANDARD_H
85