1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef H_BITCOIN_SCRIPT_STANDARD
7 #define H_BITCOIN_SCRIPT_STANDARD
10 #include "script/script.h"
11 #include "script/interpreter.h"
13 #include <boost/variant.hpp>
19 /** A reference to a CScript: the Hash160 of its serialization (see script.h) */
20 class CScriptID : public uint160
23 CScriptID() : uint160(0) {}
24 CScriptID(const CScript& in);
25 CScriptID(const uint160& in) : uint160(in) {}
28 static const unsigned int MAX_OP_RETURN_RELAY = 40; // bytes
29 extern unsigned nMaxDatacarrierBytes;
31 // Mandatory script verification flags that all new blocks must comply with for
32 // them to be valid. (but old blocks may not comply with) Currently just P2SH,
33 // but in the future other flags may be added, such as a soft-fork to enforce
34 // strict DER encoding.
36 // Failing one of these tests may trigger a DoS ban - see CheckInputs() for
38 static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
40 // Standard script verification flags that standard transactions will comply
41 // with. However scripts violating these flags may still be present in valid
42 // blocks and we must accept those blocks.
43 static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
44 SCRIPT_VERIFY_STRICTENC |
45 SCRIPT_VERIFY_MINIMALDATA |
46 SCRIPT_VERIFY_NULLDUMMY;
48 // For convenience, standard but not mandatory verify flags.
49 static const unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
54 // 'standard' transaction types:
62 class CNoDestination {
64 friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
65 friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
68 /** A txout script template with a specific destination. It is either:
69 * * CNoDestination: no destination set
70 * * CKeyID: TX_PUBKEYHASH destination
71 * * CScriptID: TX_SCRIPTHASH destination
72 * A CTxDestination is the internal data type encoded in a CBitcoinAddress
74 typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
76 const char* GetTxnOutputType(txnouttype t);
78 bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
79 int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
80 bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
81 bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
82 bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
84 CScript GetScriptForDestination(const CTxDestination& dest);
85 CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
87 #endif // H_BITCOIN_SCRIPT_STANDARD