scripted-diff: rename assert_raises_jsonrpc to assert_raises_rpc error
[bitcoinplatinum.git] / src / script / sign.h
bloba0d8ee4ff9f0538b48f2a357f82aac0224f02229
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.
6 #ifndef BITCOIN_SCRIPT_SIGN_H
7 #define BITCOIN_SCRIPT_SIGN_H
9 #include "script/interpreter.h"
11 class CKeyID;
12 class CKeyStore;
13 class CScript;
14 class CTransaction;
16 struct CMutableTransaction;
18 /** Virtual base class for signature creators. */
19 class BaseSignatureCreator {
20 protected:
21 const CKeyStore* keystore;
23 public:
24 explicit BaseSignatureCreator(const CKeyStore* keystoreIn) : keystore(keystoreIn) {}
25 const CKeyStore& KeyStore() const { return *keystore; };
26 virtual ~BaseSignatureCreator() {}
27 virtual const BaseSignatureChecker& Checker() const =0;
29 /** Create a singular (non-script) signature. */
30 virtual bool CreateSig(std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const =0;
33 /** A signature creator for transactions. */
34 class TransactionSignatureCreator : public BaseSignatureCreator {
35 const CTransaction* txTo;
36 unsigned int nIn;
37 int nHashType;
38 CAmount amount;
39 const TransactionSignatureChecker checker;
41 public:
42 TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn=SIGHASH_ALL);
43 const BaseSignatureChecker& Checker() const override { return checker; }
44 bool CreateSig(std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
47 class MutableTransactionSignatureCreator : public TransactionSignatureCreator {
48 CTransaction tx;
50 public:
51 MutableTransactionSignatureCreator(const CKeyStore* keystoreIn, const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amountIn, nHashTypeIn), tx(*txToIn) {}
54 /** A signature creator that just produces 72-byte empty signatures. */
55 class DummySignatureCreator : public BaseSignatureCreator {
56 public:
57 explicit DummySignatureCreator(const CKeyStore* keystoreIn) : BaseSignatureCreator(keystoreIn) {}
58 const BaseSignatureChecker& Checker() const override;
59 bool CreateSig(std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
62 struct SignatureData {
63 CScript scriptSig;
64 CScriptWitness scriptWitness;
66 SignatureData() {}
67 explicit SignatureData(const CScript& script) : scriptSig(script) {}
70 /** Produce a script signature using a generic signature creator. */
71 bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata);
73 /** Produce a script signature for a transaction. */
74 bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType);
75 bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
77 /** Combine two script signatures using a generic signature checker, intelligently, possibly with OP_0 placeholders. */
78 SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, const SignatureData& scriptSig1, const SignatureData& scriptSig2);
80 /** Extract signature data from a transaction, and insert it. */
81 SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn);
82 void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const SignatureData& data);
84 #endif // BITCOIN_SCRIPT_SIGN_H