Changeset View
Changeset View
Standalone View
Standalone View
src/script/script_flags.h
- This file was copied from src/script/interpreter.h.
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2018 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_SCRIPT_INTERPRETER_H | #ifndef BITCOIN_SCRIPT_SCRIPTFLAGS_H | ||||
#define BITCOIN_SCRIPT_INTERPRETER_H | #define BITCOIN_SCRIPT_SCRIPTFLAGS_H | ||||
#include "primitives/transaction.h" | |||||
#include "script_error.h" | |||||
#include "sighashtype.h" | |||||
#include <cstdint> | |||||
#include <string> | |||||
#include <vector> | |||||
class CPubKey; | |||||
class CScript; | |||||
class CTransaction; | |||||
class uint256; | |||||
/** Script verification flags */ | /** Script verification flags */ | ||||
enum { | enum { | ||||
SCRIPT_VERIFY_NONE = 0, | SCRIPT_VERIFY_NONE = 0, | ||||
// Evaluate P2SH subscripts (softfork safe, BIP16). | // Evaluate P2SH subscripts (softfork safe, BIP16). | ||||
SCRIPT_VERIFY_P2SH = (1U << 0), | SCRIPT_VERIFY_P2SH = (1U << 0), | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | enum { | ||||
// | // | ||||
SCRIPT_ENABLE_SIGHASH_FORKID = (1U << 16), | SCRIPT_ENABLE_SIGHASH_FORKID = (1U << 16), | ||||
// Do we accept activate replay protection using a different fork id. | // Do we accept activate replay protection using a different fork id. | ||||
// | // | ||||
SCRIPT_ENABLE_REPLAY_PROTECTION = (1U << 17), | SCRIPT_ENABLE_REPLAY_PROTECTION = (1U << 17), | ||||
}; | }; | ||||
bool CheckSignatureEncoding(const std::vector<uint8_t> &vchSig, uint32_t flags, | #endif // BITCOIN_SCRIPT_SCRIPTFLAGS_H | ||||
ScriptError *serror); | |||||
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, | |||||
unsigned int nIn, SigHashType sigHashType, | |||||
const Amount amount, | |||||
const PrecomputedTransactionData *cache = nullptr, | |||||
uint32_t flags = SCRIPT_ENABLE_SIGHASH_FORKID); | |||||
class BaseSignatureChecker { | |||||
public: | |||||
virtual bool CheckSig(const std::vector<uint8_t> &scriptSig, | |||||
const std::vector<uint8_t> &vchPubKey, | |||||
const CScript &scriptCode, uint32_t flags) const { | |||||
return false; | |||||
} | |||||
virtual bool CheckLockTime(const CScriptNum &nLockTime) const { | |||||
return false; | |||||
} | |||||
virtual bool CheckSequence(const CScriptNum &nSequence) const { | |||||
return false; | |||||
} | |||||
virtual ~BaseSignatureChecker() {} | |||||
}; | |||||
class TransactionSignatureChecker : public BaseSignatureChecker { | |||||
private: | |||||
const CTransaction *txTo; | |||||
unsigned int nIn; | |||||
const Amount amount; | |||||
const PrecomputedTransactionData *txdata; | |||||
protected: | |||||
virtual bool VerifySignature(const std::vector<uint8_t> &vchSig, | |||||
const CPubKey &vchPubKey, | |||||
const uint256 &sighash) const; | |||||
public: | |||||
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, | |||||
const Amount amountIn) | |||||
: txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(nullptr) {} | |||||
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, | |||||
const Amount amountIn, | |||||
const PrecomputedTransactionData &txdataIn) | |||||
: txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {} | |||||
bool CheckSig(const std::vector<uint8_t> &scriptSig, | |||||
const std::vector<uint8_t> &vchPubKey, | |||||
const CScript &scriptCode, uint32_t flags) const override; | |||||
bool CheckLockTime(const CScriptNum &nLockTime) const override; | |||||
bool CheckSequence(const CScriptNum &nSequence) const override; | |||||
}; | |||||
class MutableTransactionSignatureChecker : public TransactionSignatureChecker { | |||||
private: | |||||
const CTransaction txTo; | |||||
public: | |||||
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, | |||||
unsigned int nInIn, const Amount amount) | |||||
: TransactionSignatureChecker(&txTo, nInIn, amount), txTo(*txToIn) {} | |||||
}; | |||||
bool EvalScript(std::vector<std::vector<uint8_t>> &stack, const CScript &script, | |||||
uint32_t flags, const BaseSignatureChecker &checker, | |||||
ScriptError *error = nullptr); | |||||
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, | |||||
uint32_t flags, const BaseSignatureChecker &checker, | |||||
ScriptError *serror = nullptr); | |||||
#endif // BITCOIN_SCRIPT_INTERPRETER_H |