Fabcoin Core  0.16.2
P2P Digital Currency
sign.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 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 FABCOIN_SCRIPT_SIGN_H
7 #define FABCOIN_SCRIPT_SIGN_H
8 
9 #include "script/interpreter.h"
10 #include "coins.h"
11 
12 class CKeyID;
13 class CKeyStore;
14 class CScript;
15 class CTransaction;
16 
17 struct CMutableTransaction;
18 
21 protected:
23 
24 public:
25  BaseSignatureCreator(const CKeyStore* keystoreIn) : keystore(keystoreIn) {}
26  const CKeyStore& KeyStore() const { return *keystore; };
27  virtual ~BaseSignatureCreator() {}
28  virtual const BaseSignatureChecker& Checker() const =0;
29 
31  virtual bool CreateSig(std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const =0;
32 };
33 
37  unsigned int nIn;
38  int nHashType;
41 
42 public:
43  TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn=SIGHASH_ALL);
44  const BaseSignatureChecker& Checker() const override { return checker; }
45  bool CreateSig(std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
46 };
47 
50 
51 public:
52  MutableTransactionSignatureCreator(const CKeyStore* keystoreIn, const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amountIn, nHashTypeIn), tx(*txToIn) {}
53 };
54 
57 public:
58  DummySignatureCreator(const CKeyStore* keystoreIn) : BaseSignatureCreator(keystoreIn) {}
59  const BaseSignatureChecker& Checker() const override;
60  bool CreateSig(std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
61 };
62 
63 struct SignatureData {
66 
68  explicit SignatureData(const CScript& script) : scriptSig(script) {}
69 };
70 
72 bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata);
73 
75 bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType);
76 bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
77 bool VerifySignature(const Coin& coin, uint256 txFromHash, const CTransaction& txTo, unsigned int nIn, unsigned int flags);
78 
80 SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, const SignatureData& scriptSig1, const SignatureData& scriptSig2);
81 
83 SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn);
84 void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const SignatureData& data);
85 
86 #endif // FABCOIN_SCRIPT_SIGN_H
const BaseSignatureChecker & Checker() const override
Definition: sign.h:44
bool VerifySignature(const Coin &coin, uint256 txFromHash, const CTransaction &txTo, unsigned int nIn, unsigned int flags)
Definition: sign.cpp:228
A UTXO entry.
Definition: coins.h:29
const CKeyStore & KeyStore() const
Definition: sign.h:26
CScript scriptSig
Definition: sign.h:64
Virtual base class for signature creators.
Definition: sign.h:20
A signature creator for transactions.
Definition: sign.h:35
SignatureData CombineSignatures(const CScript &scriptPubKey, const BaseSignatureChecker &checker, const SignatureData &scriptSig1, const SignatureData &scriptSig2)
Combine two script signatures using a generic signature checker, intelligently, possibly with OP_0 pl...
Definition: sign.cpp:395
unsigned int nIn
Definition: sign.h:37
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
SignatureData(const CScript &script)
Definition: sign.h:68
const CKeyStore * keystore
Definition: sign.h:22
virtual bool CreateSig(std::vector< unsigned char > &vchSig, const CKeyID &keyid, const CScript &scriptCode, SigVersion sigversion) const =0
Create a singular (non-script) signature.
BaseSignatureCreator(const CKeyStore *keystoreIn)
Definition: sign.h:25
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType)
Produce a script signature for a transaction.
Definition: sign.cpp:205
CScriptWitness scriptWitness
Definition: sign.h:65
const TransactionSignatureChecker checker
Definition: sign.h:40
256-bit opaque blob.
Definition: uint256.h:132
virtual ~BaseSignatureCreator()
Definition: sign.h:27
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:417
A virtual base class for key stores.
Definition: keystore.h:18
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:29
SignatureData()
Definition: sign.h:67
A mutable version of CTransaction.
Definition: transaction.h:390
DummySignatureCreator(const CKeyStore *keystoreIn)
Definition: sign.h:58
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:275
const CTransaction * txTo
Definition: sign.h:36
MutableTransactionSignatureCreator(const CKeyStore *keystoreIn, const CMutableTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn, int nHashTypeIn)
Definition: sign.h:52
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &scriptPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:141
uint8_t const * data
Definition: sha3.h:19
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
Definition: sign.cpp:198
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn)
Extract signature data from a transaction, and insert it.
Definition: sign.cpp:189
A signature creator that just produces 72-byte empty signatures.
Definition: sign.h:56
virtual const BaseSignatureChecker & Checker() const =0
SigVersion
Definition: interpreter.h:124