LCOV - code coverage report
Current view: top level - src/script - standard.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 2 4 50.0 %
Date: 2025-02-23 09:33:43 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2014 The Bitcoin developers
       3             : // Copyright (c) 2017-2021 The PIVX Core developers
       4             : // Distributed under the MIT software license, see the accompanying
       5             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       6             : 
       7             : #ifndef PIVX_SCRIPT_STANDARD_H
       8             : #define PIVX_SCRIPT_STANDARD_H
       9             : 
      10             : #include "script/interpreter.h"
      11             : #include "uint256.h"
      12             : 
      13             : #include <boost/variant.hpp>
      14             : 
      15             : #include <stdint.h>
      16             : 
      17             : static const bool DEFAULT_ACCEPT_DATACARRIER = true;
      18             : 
      19             : class CKeyID;
      20             : class CScript;
      21             : 
      22             : /** A reference to a CScript: the Hash160 of its serialization (see script.h) */
      23             : class CScriptID : public uint160
      24             : {
      25             : public:
      26      551278 :     CScriptID() : uint160() {}
      27             :     CScriptID(const CScript& in);
      28       85719 :     CScriptID(const uint160& in) : uint160(in) {}
      29             : };
      30             : 
      31             : static const unsigned int MAX_OP_RETURN_RELAY = 83;      //!< bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
      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_COLDSTAKE,
      55             :     TX_EXCHANGEADDR
      56             : };
      57             : 
      58             : class CNoDestination {
      59             : public:
      60           0 :     friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
      61           0 :     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             :  *  * CExchangeKeyID: CKeyID for exchange key
      69             :  *  * CScriptID: TX_SCRIPTHASH destination
      70             :  *  A CTxDestination is the internal data type encoded in a PIVX address
      71             :  */
      72             : typedef boost::variant<CNoDestination, CKeyID, CScriptID, CExchangeKeyID> CTxDestination;
      73             : 
      74             : /** Check whether a CTxDestination is a CNoDestination. */
      75             : bool IsValidDestination(const CTxDestination& dest);
      76             : 
      77             : const char* GetTxnOutputType(txnouttype t);
      78             : 
      79             : /**
      80             :  * Parse a scriptPubKey and identify script type for standard scripts. If
      81             :  * successful, returns script type and parsed pubkeys or hashes, depending on
      82             :  * the type. For example, for a P2SH script, vSolutionsRet will contain the
      83             :  * script hash, for P2PKH it will contain the key hash, etc.
      84             :  *
      85             :  * @param[in]   scriptPubKey   Script to parse
      86             :  * @param[out]  typeRet        The script type
      87             :  * @param[out]  vSolutionsRet  Vector of parsed pubkeys and hashes
      88             :  * @return                     True if script matches standard template
      89             :  */
      90             : bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
      91             : 
      92             : /**
      93             :  * Parse a standard scriptPubKey for the destination address. Assigns result to
      94             :  * the addressRet parameter and returns true if successful. For multisig
      95             :  * scripts, instead use ExtractDestinations. Currently only works for P2PK,
      96             :  * P2PKH, P2SH and P2CS scripts.
      97             :  */
      98             : bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet, bool fColdStake = false);
      99             : 
     100             : /**
     101             :  * Parse a standard scriptPubKey with one or more destination addresses. For
     102             :  * multisig scripts, this populates the addressRet vector with the pubkey IDs
     103             :  * and nRequiredRet with the n required to spend.
     104             :  * For P2CS addressRet is populated with the staker and owner IDs and nRequiredRet
     105             :  * is set to 2.
     106             :  * For other destinations, addressRet is populated with a single value and
     107             :  * nRequiredRet is set to 1.
     108             :  * Returns true if successful.
     109             :  */
     110             : bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
     111             : 
     112             : /**
     113             :  * Generate a PIVX scriptPubKey for the given CTxDestination. Returns a P2PKH
     114             :  * script for a CKeyID destination, a P2SH script for a CScriptID, and an empty
     115             :  * script for CNoDestination.
     116             :  */
     117             : CScript GetScriptForDestination(const CTxDestination& dest);
     118             : 
     119             : /** Generate a P2PK script for the given pubkey. */
     120             : CScript GetScriptForRawPubKey(const CPubKey& pubkey);
     121             : 
     122             : /** Generate a multisig script. */
     123             : CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
     124             : 
     125             : /** Generate a P2CS script for the given staker and owner keys. */
     126             : CScript GetScriptForStakeDelegation(const CKeyID& stakingKey, const CKeyID& spendingKey);
     127             : CScript GetScriptForStakeDelegationLOF(const CKeyID& stakingKey, const CKeyID& spendingKey);
     128             : 
     129             : /** Generate an OP_RETURN output script with the given data. */
     130             : CScript GetScriptForOpReturn(const uint256& message);
     131             : 
     132             : #endif // PIVX_SCRIPT_STANDARD_H

Generated by: LCOV version 1.14