28 if (!provider.
GetKey(address, key)) {
59 const auto it = sigdata.
signatures.find(address);
61 pubkey = it->second.first;
67 pubkey =
pk_it->second.first;
71 return provider.
GetPubKey(address, pubkey);
87 std::make_pair(pubkey, std::move(info)));
108 const CScript &scriptPubKey, std::vector<valtype> &
ret,
113 std::vector<uint8_t>
sig;
127 ret.push_back(std::move(
sig));
141 ret.push_back(std::move(
sig));
159 for (
size_t i = 1; i <
vSolutions.size() - 1; ++i) {
168 ret.push_back(std::move(
sig));
173 for (
size_t i = 0; i +
ret.size() <
required + 1; ++i) {
185 for (
const valtype &v : values) {
188 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
205 std::vector<valtype> result;
245 bool CheckSig(
const std::vector<uint8_t> &scriptSig,
246 const std::vector<uint8_t> &vchPubKey,
248 if (checker.
CheckSig(scriptSig, vchPubKey, scriptCode,
flags)) {
260 std::vector<valtype> script;
263 Stacks(
const Stacks &) =
delete;
276 unsigned int nIn,
const CTxOut &txout) {
292 std::vector<std::vector<uint8_t>>
solutions;
297 !stack.script.back().empty()) {
299 CScript redeem_script(stack.script.back().begin(),
300 stack.script.back().end());
306 stack.script.pop_back();
340 *
this = std::move(sigdata);
347 std::make_move_iterator(sigdata.
signatures.end()));
379 DummySignatureChecker() {}
380 bool CheckSig(
const std::vector<uint8_t> &scriptSig,
381 const std::vector<uint8_t> &vchPubKey,
401 const CScript &scriptCode)
const override {
403 vchSig.assign(m_r_len + m_s_len + 7,
'\000');
405 vchSig[1] = m_r_len + m_s_len + 4;
409 vchSig[4 + m_r_len] = 0x02;
410 vchSig[5 + m_r_len] = m_s_len;
411 vchSig[6 + m_r_len] = 0x01;
420 DummySignatureCreator(32, 32);
422 DummySignatureCreator(33, 32);
442 const std::map<COutPoint, Coin> &coins,
449 for (
size_t i = 0; i <
mtx.vin.size(); i++) {
451 auto coin = coins.find(
txin.prevout);
452 if (coin == coins.end() || coin->second.IsSpent()) {
457 const Amount amount = coin->second.GetTxOut().nValue;
463 (i <
mtx.vout.size())) {
485 input_errors[i] =
"Unable to sign input, invalid stack size "
486 "(possibly missing key)";
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
virtual bool CheckSig(const std::vector< uint8_t > &vchSigIn, const std::vector< uint8_t > &vchPubKey, const CScript &scriptCode, uint32_t flags) const
Interface for signature creators.
virtual bool CreateSig(const SigningProvider &provider, std::vector< uint8_t > &vchSig, const CKeyID &keyid, const CScript &scriptCode) const =0
Create a singular (non-script) signature.
virtual const BaseSignatureChecker & Checker() const =0
An encapsulated secp256k1 private key.
bool SignECDSA(const uint256 &hash, std::vector< uint8_t > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized ECDSA signature.
A reference to a CKey: the Hash160 of its serialized public key.
A mutable version of CTransaction.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
static opcodetype EncodeOP_N(int n)
A reference to a CScript: the Hash160 of its serialization (see script.h)
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
An output of a transaction.
A signature creator for transactions.
MutableTransactionSignatureCreator(const CMutableTransaction *txToIn, unsigned int nInIn, const Amount &amountIn, SigHashType sigHashTypeIn=SigHashType())
bool CreateSig(const SigningProvider &provider, std::vector< uint8_t > &vchSig, const CKeyID &keyid, const CScript &scriptCode) const override
Create a singular (non-script) signature.
const CMutableTransaction * txTo
Signature hash type wrapper class.
uint32_t getRawSigHashType() const
BaseSigHashType getBaseType() const
An interface to be implemented by keystores that support signing.
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
virtual bool GetKey(const CKeyID &address, CKey &key) const
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
iterator insert(iterator pos, const T &value)
void push_back(const T &value)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, SigHashType sigHashType, const Amount amount, const PrecomputedTransactionData *cache, uint32_t flags)
bool EvalScript(std::vector< valtype > &stack, const CScript &script, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics, ScriptError *serror)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metricsOut, ScriptError *serror)
Execute an unlocking and locking script together.
static constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::vector< uint8_t > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
@ INVALID_STACK_OPERATION
std::vector< uint8_t > valtype
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
std::vector< uint8_t > valtype
void UpdateInput(CTxIn &input, const SignatureData &data)
static bool CreateSig(const BaseSignatureCreator &creator, SignatureData &sigdata, const SigningProvider &provider, std::vector< uint8_t > &sig_out, const CPubKey &pubkey, const CScript &scriptcode)
static bool SignStep(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &scriptPubKey, std::vector< valtype > &ret, TxoutType &whichTypeRet, SignatureData &sigdata)
Sign scriptPubKey using signature made with creator.
bool IsSolvable(const SigningProvider &provider, const CScript &script)
Check whether we know how to sign for an output like this, assuming we have all private keys.
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
bool SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, SigHashType sigHashType, std::map< int, std::string > &input_errors)
Sign the CMutableTransaction.
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
static CScript PushAll(const std::vector< valtype > &values)
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const Amount amount, SigHashType sigHashType)
Produce a script signature for a transaction.
static bool GetCScript(const SigningProvider &provider, const SignatureData &sigdata, const CScriptID &scriptid, CScript &script)
std::pair< CPubKey, std::vector< uint8_t > > SigPair
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
void MergeSignatureData(SignatureData sigdata)
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input.
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
CScript scriptSig
The scriptSig of an input.
CScript redeem_script
The redeemScript (if any) for the input.
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
bool complete
Stores whether the scriptSig are complete.