LCOV - code coverage report
Current view: top level - src/script - sign.h (source / functions) Hit Total Coverage
Test: bitcoincash_test.info Lines: 9 9 100.0 %
Date: 2018-04-13 15:12:50 Functions: 3 6 50.0 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2016 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_SIGN_H
       7             : #define BITCOIN_SCRIPT_SIGN_H
       8             : 
       9             : #include "script/interpreter.h"
      10             : #include "script/sighashtype.h"
      11             : 
      12             : class CKeyID;
      13             : class CKeyStore;
      14             : class CMutableTransaction;
      15             : class CScript;
      16             : class CTransaction;
      17             : 
      18             : /** Virtual base class for signature creators. */
      19             : class BaseSignatureCreator {
      20             : protected:
      21             :     const CKeyStore *keystore;
      22             : 
      23             : public:
      24             :     BaseSignatureCreator(const CKeyStore *keystoreIn) : keystore(keystoreIn) {}
      25             :     const CKeyStore &KeyStore() const { return *keystore; };
      26           2 :     virtual ~BaseSignatureCreator() {}
      27             :     virtual const BaseSignatureChecker &Checker() const = 0;
      28             : 
      29             :     /** Create a singular (non-script) signature. */
      30             :     virtual bool CreateSig(std::vector<uint8_t> &vchSig, const CKeyID &keyid,
      31             :                            const CScript &scriptCode) const = 0;
      32             : };
      33             : 
      34             : /** A signature creator for transactions. */
      35           6 : class TransactionSignatureCreator : public BaseSignatureCreator {
      36             :     const CTransaction *txTo;
      37             :     unsigned int nIn;
      38             :     Amount amount;
      39             :     SigHashType sigHashType;
      40             :     const TransactionSignatureChecker checker;
      41             : 
      42             : public:
      43             :     TransactionSignatureCreator(const CKeyStore *keystoreIn,
      44             :                                 const CTransaction *txToIn, unsigned int nInIn,
      45             :                                 const Amount amountIn,
      46             :                                 SigHashType sigHashTypeIn = SigHashType());
      47          94 :     const BaseSignatureChecker &Checker() const override { return checker; }
      48             :     bool CreateSig(std::vector<uint8_t> &vchSig, const CKeyID &keyid,
      49             :                    const CScript &scriptCode) const override;
      50             : };
      51             : 
      52           6 : class MutableTransactionSignatureCreator : public TransactionSignatureCreator {
      53             :     CTransaction tx;
      54             : 
      55             : public:
      56           2 :     MutableTransactionSignatureCreator(const CKeyStore *keystoreIn,
      57             :                                        const CMutableTransaction *txToIn,
      58             :                                        unsigned int nInIn, const Amount amount,
      59             :                                        SigHashType sigHashTypeIn)
      60             :         : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amount,
      61             :                                       sigHashTypeIn),
      62           2 :           tx(*txToIn) {}
      63             : };
      64             : 
      65             : /** A signature creator that just produces 72-byte empty signatures. */
      66             : class DummySignatureCreator : public BaseSignatureCreator {
      67             : public:
      68             :     DummySignatureCreator(const CKeyStore *keystoreIn)
      69             :         : BaseSignatureCreator(keystoreIn) {}
      70             :     const BaseSignatureChecker &Checker() const override;
      71             :     bool CreateSig(std::vector<uint8_t> &vchSig, const CKeyID &keyid,
      72             :                    const CScript &scriptCode) const override;
      73             : };
      74             : 
      75         152 : struct SignatureData {
      76             :     CScript scriptSig;
      77             : 
      78           6 :     SignatureData() {}
      79          60 :     explicit SignatureData(const CScript &script) : scriptSig(script) {}
      80             : };
      81             : 
      82             : /** Produce a script signature using a generic signature creator. */
      83             : bool ProduceSignature(const BaseSignatureCreator &creator,
      84             :                       const CScript &scriptPubKey, SignatureData &sigdata);
      85             : 
      86             : /** Produce a script signature for a transaction. */
      87             : bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey,
      88             :                    CMutableTransaction &txTo, unsigned int nIn,
      89             :                    const Amount amount, SigHashType sigHashType);
      90             : bool SignSignature(const CKeyStore &keystore, const CTransaction &txFrom,
      91             :                    CMutableTransaction &txTo, unsigned int nIn,
      92             :                    SigHashType sigHashType);
      93             : 
      94             : /** Combine two script signatures using a generic signature checker,
      95             :  * intelligently, possibly with OP_0 placeholders. */
      96             : SignatureData CombineSignatures(const CScript &scriptPubKey,
      97             :                                 const BaseSignatureChecker &checker,
      98             :                                 const SignatureData &scriptSig1,
      99             :                                 const SignatureData &scriptSig2);
     100             : 
     101             : /** Extract signature data from a transaction, and insert it. */
     102             : SignatureData DataFromTransaction(const CMutableTransaction &tx,
     103             :                                   unsigned int nIn);
     104             : void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn,
     105             :                        const SignatureData &data);
     106             : 
     107             : #endif // BITCOIN_SCRIPT_SIGN_H

Generated by: LCOV version 1.12