2014-08-23 03:35:51 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2014-09-09 10:00:42 +02:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-08-23 03:35:51 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef H_BITCOIN_SCRIPT_STANDARD
|
|
|
|
#define H_BITCOIN_SCRIPT_STANDARD
|
|
|
|
|
2014-09-25 05:32:36 +02:00
|
|
|
#include "key.h"
|
2014-08-23 03:35:51 +02:00
|
|
|
#include "script/script.h"
|
|
|
|
#include "script/interpreter.h"
|
|
|
|
|
2014-09-25 05:32:36 +02:00
|
|
|
#include <boost/variant.hpp>
|
|
|
|
|
2014-08-23 03:35:51 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
class CScript;
|
|
|
|
|
2014-09-25 04:24:46 +02:00
|
|
|
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
|
|
|
|
class CScriptID : public uint160
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CScriptID() : uint160(0) {}
|
|
|
|
CScriptID(const CScript& in);
|
|
|
|
CScriptID(const uint160& in) : uint160(in) {}
|
|
|
|
};
|
|
|
|
|
2014-08-23 03:35:51 +02:00
|
|
|
static const unsigned int MAX_OP_RETURN_RELAY = 40; // bytes
|
|
|
|
|
|
|
|
// Mandatory script verification flags that all new blocks must comply with for
|
|
|
|
// them to be valid. (but old blocks may not comply with) Currently just P2SH,
|
|
|
|
// but in the future other flags may be added, such as a soft-fork to enforce
|
|
|
|
// strict DER encoding.
|
|
|
|
//
|
|
|
|
// Failing one of these tests may trigger a DoS ban - see CheckInputs() for
|
|
|
|
// details.
|
|
|
|
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
|
|
|
|
|
|
|
|
// Standard script verification flags that standard transactions will comply
|
|
|
|
// with. However scripts violating these flags may still be present in valid
|
|
|
|
// blocks and we must accept those blocks.
|
|
|
|
static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
|
|
|
|
SCRIPT_VERIFY_STRICTENC |
|
2014-10-09 03:48:59 +02:00
|
|
|
SCRIPT_VERIFY_MINIMALDATA |
|
2014-08-23 03:35:51 +02:00
|
|
|
SCRIPT_VERIFY_NULLDUMMY;
|
|
|
|
|
|
|
|
// For convenience, standard but not mandatory verify flags.
|
|
|
|
static const unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
|
|
|
|
|
|
|
|
enum txnouttype
|
|
|
|
{
|
|
|
|
TX_NONSTANDARD,
|
|
|
|
// 'standard' transaction types:
|
|
|
|
TX_PUBKEY,
|
|
|
|
TX_PUBKEYHASH,
|
|
|
|
TX_SCRIPTHASH,
|
|
|
|
TX_MULTISIG,
|
|
|
|
TX_NULL_DATA,
|
|
|
|
};
|
|
|
|
|
2014-09-11 19:15:29 +02:00
|
|
|
class CNoDestination {
|
|
|
|
public:
|
|
|
|
friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
|
|
|
|
friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A txout script template with a specific destination. It is either:
|
|
|
|
* * CNoDestination: no destination set
|
|
|
|
* * CKeyID: TX_PUBKEYHASH destination
|
|
|
|
* * CScriptID: TX_SCRIPTHASH destination
|
|
|
|
* A CTxDestination is the internal data type encoded in a CBitcoinAddress
|
|
|
|
*/
|
|
|
|
typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
|
|
|
|
|
2014-08-23 03:35:51 +02:00
|
|
|
const char* GetTxnOutputType(txnouttype t);
|
|
|
|
|
|
|
|
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
|
|
|
|
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
|
|
|
|
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
|
|
|
|
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
|
|
|
|
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
|
|
|
|
|
2014-09-11 19:15:29 +02:00
|
|
|
CScript GetScriptForDestination(const CTxDestination& dest);
|
|
|
|
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
|
|
|
|
|
2014-09-09 10:00:42 +02:00
|
|
|
#endif // H_BITCOIN_SCRIPT_STANDARD
|