You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

standard.h 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.
  5. #ifndef H_BITCOIN_SCRIPT_STANDARD
  6. #define H_BITCOIN_SCRIPT_STANDARD
  7. #include "key.h"
  8. #include "script/script.h"
  9. #include "script/interpreter.h"
  10. #include <boost/variant.hpp>
  11. #include <stdint.h>
  12. class CScript;
  13. /** A reference to a CScript: the Hash160 of its serialization (see script.h) */
  14. class CScriptID : public uint160
  15. {
  16. public:
  17. CScriptID() : uint160(0) {}
  18. CScriptID(const CScript& in);
  19. CScriptID(const uint160& in) : uint160(in) {}
  20. };
  21. static const unsigned int MAX_OP_RETURN_RELAY = 40; // bytes
  22. // Mandatory script verification flags that all new blocks must comply with for
  23. // them to be valid. (but old blocks may not comply with) Currently just P2SH,
  24. // but in the future other flags may be added, such as a soft-fork to enforce
  25. // strict DER encoding.
  26. //
  27. // Failing one of these tests may trigger a DoS ban - see CheckInputs() for
  28. // details.
  29. static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
  30. // Standard script verification flags that standard transactions will comply
  31. // with. However scripts violating these flags may still be present in valid
  32. // blocks and we must accept those blocks.
  33. static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
  34. SCRIPT_VERIFY_STRICTENC |
  35. SCRIPT_VERIFY_NULLDUMMY;
  36. // For convenience, standard but not mandatory verify flags.
  37. static const unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
  38. enum txnouttype
  39. {
  40. TX_NONSTANDARD,
  41. // 'standard' transaction types:
  42. TX_PUBKEY,
  43. TX_PUBKEYHASH,
  44. TX_SCRIPTHASH,
  45. TX_MULTISIG,
  46. TX_NULL_DATA,
  47. };
  48. class CNoDestination {
  49. public:
  50. friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
  51. friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
  52. };
  53. /** A txout script template with a specific destination. It is either:
  54. * * CNoDestination: no destination set
  55. * * CKeyID: TX_PUBKEYHASH destination
  56. * * CScriptID: TX_SCRIPTHASH destination
  57. * A CTxDestination is the internal data type encoded in a CBitcoinAddress
  58. */
  59. typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
  60. const char* GetTxnOutputType(txnouttype t);
  61. bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
  62. int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
  63. bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
  64. bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
  65. bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
  66. CScript GetScriptForDestination(const CTxDestination& dest);
  67. CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
  68. #endif // H_BITCOIN_SCRIPT_STANDARD