![]() |
Master Core
v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
|
#include "script.h"
#include "core.h"
#include "hash.h"
#include "key.h"
#include "keystore.h"
#include "sync.h"
#include "uint256.h"
#include "util.h"
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
Go to the source code of this file.
Classes | |
class | CSignatureCache |
class | CKeyStoreIsMineVisitor |
class | CAffectedKeysVisitor |
class | CScriptVisitor |
Macros | |
#define | stacktop(i) (stack.at(stack.size()+(i))) |
#define | altstacktop(i) (altstack.at(altstack.size()+(i))) |
Typedefs | |
typedef vector< unsigned char > | valtype |
Functions | |
static const valtype | vchFalse (0) |
static const valtype | vchZero (0) |
static const valtype | vchTrue (1, 1) |
bool | CheckSig (vector< unsigned char > vchSig, const vector< unsigned char > &vchPubKey, const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, int flags) |
bool | CastToBool (const valtype &vch) |
static void | popstack (vector< valtype > &stack) |
const char * | GetTxnOutputType (txnouttype t) |
const char * | GetOpName (opcodetype opcode) |
bool | IsCanonicalPubKey (const valtype &vchPubKey, unsigned int flags) |
bool | IsCanonicalSignature (const valtype &vchSig, unsigned int flags) |
bool | EvalScript (vector< vector< unsigned char > > &stack, const CScript &script, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType) |
uint256 | SignatureHash (const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType) |
bool | Solver (const CScript &scriptPubKey, txnouttype &typeRet, vector< vector< unsigned char > > &vSolutionsRet) |
bool | Sign1 (const CKeyID &address, const CKeyStore &keystore, uint256 hash, int nHashType, CScript &scriptSigRet) |
bool | SignN (const vector< valtype > &multisigdata, const CKeyStore &keystore, uint256 hash, int nHashType, CScript &scriptSigRet) |
bool | Solver (const CKeyStore &keystore, const CScript &scriptPubKey, uint256 hash, int nHashType, CScript &scriptSigRet, txnouttype &whichTypeRet) |
int | ScriptSigArgsExpected (txnouttype t, const std::vector< std::vector< unsigned char > > &vSolutions) |
bool | IsStandard (const CScript &scriptPubKey, txnouttype &whichType) |
unsigned int | HaveKeys (const vector< valtype > &pubkeys, const CKeyStore &keystore) |
bool | IsMine (const CKeyStore &keystore, const CTxDestination &dest) |
bool | IsMine (const CKeyStore &keystore, const CScript &scriptPubKey) |
bool | ExtractDestination (const CScript &scriptPubKey, CTxDestination &addressRet) |
bool | ExtractDestinations (const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet) |
void | ExtractAffectedKeys (const CKeyStore &keystore, const CScript &scriptPubKey, std::vector< CKeyID > &vKeys) |
bool | VerifyScript (const CScript &scriptSig, const CScript &scriptPubKey, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType) |
bool | SignSignature (const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType) |
bool | SignSignature (const CKeyStore &keystore, const CTransaction &txFrom, CTransaction &txTo, unsigned int nIn, int nHashType) |
static CScript | PushAll (const vector< valtype > &values) |
static CScript | CombineMultisig (CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const vector< valtype > &vSolutions, vector< valtype > &sigs1, vector< valtype > &sigs2) |
static CScript | CombineSignatures (CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const txnouttype txType, const vector< valtype > &vSolutions, vector< valtype > &sigs1, vector< valtype > &sigs2) |
CScript | CombineSignatures (CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const CScript &scriptSig1, const CScript &scriptSig2) |
Variables | |
static const CScriptNum | bnZero (0) |
static const CScriptNum | bnOne (1) |
static const CScriptNum | bnFalse (0) |
static const CScriptNum | bnTrue (1) |
#define altstacktop | ( | i | ) | (altstack.at(altstack.size()+(i))) |
Definition at line 56 of file script.cpp.
Referenced by EvalScript().
#define stacktop | ( | i | ) | (stack.at(stack.size()+(i))) |
Definition at line 55 of file script.cpp.
Referenced by EvalScript().
typedef vector<unsigned char> valtype |
Definition at line 23 of file script.cpp.
bool CastToBool | ( | const valtype & | vch | ) |
Definition at line 34 of file script.cpp.
Referenced by EvalScript(), and VerifyScript().
bool CheckSig | ( | vector< unsigned char > | vchSig, |
const vector< unsigned char > & | vchPubKey, | ||
const CScript & | scriptCode, | ||
const CTransaction & | txTo, | ||
unsigned int | nIn, | ||
int | nHashType, | ||
int | flags | ||
) |
Definition at line 1143 of file script.cpp.
References CSignatureCache::Get(), CPubKey::IsValid(), SCRIPT_VERIFY_NOCACHE, CSignatureCache::Set(), SignatureHash(), and CPubKey::Verify().
Referenced by CombineMultisig(), and EvalScript().
|
static |
Definition at line 1683 of file script.cpp.
References CheckSig(), and OP_0.
Referenced by CombineSignatures().
|
static |
Definition at line 1738 of file script.cpp.
References CombineMultisig(), PushAll(), Solver(), TX_MULTISIG, TX_NONSTANDARD, TX_NULL_DATA, TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
Referenced by CombineSignatures(), and signrawtransaction().
CScript CombineSignatures | ( | CScript | scriptPubKey, |
const CTransaction & | txTo, | ||
unsigned int | nIn, | ||
const CScript & | scriptSig1, | ||
const CScript & | scriptSig2 | ||
) |
Definition at line 1783 of file script.cpp.
References CombineSignatures(), EvalScript(), SCRIPT_VERIFY_STRICTENC, and Solver().
bool EvalScript | ( | vector< vector< unsigned char > > & | stack, |
const CScript & | script, | ||
const CTransaction & | txTo, | ||
unsigned int | nIn, | ||
unsigned int | flags, | ||
int | nHashType | ||
) |
Definition at line 297 of file script.cpp.
References altstacktop, bnOne, bnZero, CastToBool(), CheckSig(), CScript::FindAndDelete(), CScriptNum::getint(), CScript::GetOp(), CScriptNum::getvch(), Hash(), Hash160(), IsCanonicalPubKey(), IsCanonicalSignature(), MAX_SCRIPT_ELEMENT_SIZE, memcpy(), OP_0NOTEQUAL, OP_1, OP_10, OP_11, OP_12, OP_13, OP_14, OP_15, OP_16, OP_1ADD, OP_1NEGATE, OP_1SUB, OP_2, OP_2DIV, OP_2DROP, OP_2DUP, OP_2MUL, OP_2OVER, OP_2ROT, OP_2SWAP, OP_3, OP_3DUP, OP_4, OP_5, OP_6, OP_7, OP_8, OP_9, OP_ABS, OP_ADD, OP_AND, OP_BOOLAND, OP_BOOLOR, OP_CAT, OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY, OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CODESEPARATOR, OP_DEPTH, OP_DIV, OP_DROP, OP_DUP, OP_ELSE, OP_ENDIF, OP_EQUAL, OP_EQUALVERIFY, OP_FROMALTSTACK, OP_GREATERTHAN, OP_GREATERTHANOREQUAL, OP_HASH160, OP_HASH256, OP_IF, OP_IFDUP, OP_INVERT, OP_LEFT, OP_LESSTHAN, OP_LESSTHANOREQUAL, OP_LSHIFT, OP_MAX, OP_MIN, OP_MOD, OP_MUL, OP_NEGATE, OP_NIP, OP_NOP, OP_NOP1, OP_NOP10, OP_NOP2, OP_NOP3, OP_NOP4, OP_NOP5, OP_NOP6, OP_NOP7, OP_NOP8, OP_NOP9, OP_NOT, OP_NOTIF, OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_OR, OP_OVER, OP_PICK, OP_PUSHDATA4, OP_RETURN, OP_RIGHT, OP_RIPEMD160, OP_ROLL, OP_ROT, OP_RSHIFT, OP_SHA1, OP_SHA256, OP_SIZE, OP_SUB, OP_SUBSTR, OP_SWAP, OP_TOALTSTACK, OP_TUCK, OP_VERIFY, OP_WITHIN, OP_XOR, popstack(), stacktop, vchFalse(), and vchTrue().
Referenced by AreInputsStandard(), CombineSignatures(), and VerifyScript().
void ExtractAffectedKeys | ( | const CKeyStore & | keystore, |
const CScript & | scriptPubKey, | ||
std::vector< CKeyID > & | vKeys | ||
) |
Definition at line 1584 of file script.cpp.
References CAffectedKeysVisitor::Process().
Referenced by CWallet::GetKeyBirthTimes().
bool ExtractDestination | ( | const CScript & | scriptPubKey, |
CTxDestination & | addressRet | ||
) |
Definition at line 1493 of file script.cpp.
References CPubKey::GetID(), Solver(), TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
Referenced by TransactionRecord::decomposeTransaction(), ExtractDestinations(), CWallet::GetAddressBalances(), CWallet::GetAddressGroupings(), CWalletTx::GetAmounts(), getreceivedbyaccount(), CWallet::IsChange(), WalletModel::listCoins(), ListReceived(), parseTransaction(), PaymentServer::processPaymentRequest(), selectCoins(), TransactionDesc::toHTML(), CoinControlDialog::updateLabels(), and CoinControlDialog::updateView().
bool ExtractDestinations | ( | const CScript & | scriptPubKey, |
txnouttype & | typeRet, | ||
vector< CTxDestination > & | addressRet, | ||
int & | nRequiredRet | ||
) |
Definition at line 1519 of file script.cpp.
References ExtractDestination(), CPubKey::GetID(), Solver(), TX_MULTISIG, TX_NONSTANDARD, and TX_NULL_DATA.
Referenced by parseTransaction(), CAffectedKeysVisitor::Process(), and ScriptPubKeyToJSON().
const char* GetOpName | ( | opcodetype | opcode | ) |
Definition at line 80 of file script.cpp.
References OP_0, OP_0NOTEQUAL, OP_1, OP_10, OP_11, OP_12, OP_13, OP_14, OP_15, OP_16, OP_1ADD, OP_1NEGATE, OP_1SUB, OP_2, OP_2DIV, OP_2DROP, OP_2DUP, OP_2MUL, OP_2OVER, OP_2ROT, OP_2SWAP, OP_3, OP_3DUP, OP_4, OP_5, OP_6, OP_7, OP_8, OP_9, OP_ABS, OP_ADD, OP_AND, OP_BOOLAND, OP_BOOLOR, OP_CAT, OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY, OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CODESEPARATOR, OP_DEPTH, OP_DIV, OP_DROP, OP_DUP, OP_ELSE, OP_ENDIF, OP_EQUAL, OP_EQUALVERIFY, OP_FROMALTSTACK, OP_GREATERTHAN, OP_GREATERTHANOREQUAL, OP_HASH160, OP_HASH256, OP_IF, OP_IFDUP, OP_INVALIDOPCODE, OP_INVERT, OP_LEFT, OP_LESSTHAN, OP_LESSTHANOREQUAL, OP_LSHIFT, OP_MAX, OP_MIN, OP_MOD, OP_MUL, OP_NEGATE, OP_NIP, OP_NOP, OP_NOP1, OP_NOP10, OP_NOP2, OP_NOP3, OP_NOP4, OP_NOP5, OP_NOP6, OP_NOP7, OP_NOP8, OP_NOP9, OP_NOT, OP_NOTIF, OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_OR, OP_OVER, OP_PICK, OP_PUBKEY, OP_PUBKEYHASH, OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4, OP_RESERVED, OP_RESERVED1, OP_RESERVED2, OP_RETURN, OP_RIGHT, OP_RIPEMD160, OP_ROLL, OP_ROT, OP_RSHIFT, OP_SHA1, OP_SHA256, OP_SIZE, OP_SMALLDATA, OP_SUB, OP_SUBSTR, OP_SWAP, OP_TOALTSTACK, OP_TUCK, OP_VER, OP_VERIF, OP_VERIFY, OP_VERNOTIF, OP_WITHIN, and OP_XOR.
Referenced by CScript::mscore_parse(), and CScript::ToString().
const char* GetTxnOutputType | ( | txnouttype | t | ) |
Definition at line 65 of file script.cpp.
References TX_MULTISIG, TX_NONSTANDARD, TX_NULL_DATA, TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
Referenced by ScriptPubKeyToJSON().
Definition at line 1424 of file script.cpp.
References CPubKey::GetID(), and CKeyStore::HaveKey().
Referenced by IsMine().
Definition at line 224 of file script.cpp.
References error(), and SCRIPT_VERIFY_STRICTENC.
Referenced by EvalScript().
Definition at line 242 of file script.cpp.
References error(), SCRIPT_VERIFY_EVEN_S, SCRIPT_VERIFY_STRICTENC, SIGHASH_ANYONECANPAY, and SIGHASH_SINGLE.
Referenced by EvalScript().
bool IsMine | ( | const CKeyStore & | keystore, |
const CTxDestination & | dest | ||
) |
Definition at line 1448 of file script.cpp.
Referenced by CWallet::AddToWalletIfInvolvingMe(), CWallet::AvailableCoins(), TransactionRecord::decomposeTransaction(), CWallet::DelAddressBook(), CWallet::GetAddressBalances(), CWallet::GetAddressGroupings(), CWallet::GetCredit(), CWallet::GetDebit(), getreceivedbyaccount(), getreceivedbyaddress(), CWallet::IsChange(), CWallet::IsMine(), IsMine(), IsMyAddress(), listaccounts(), ListReceived(), AddressTablePriv::refreshAddressTable(), selectCoins(), CWallet::SetAddressBook(), TransactionDesc::toHTML(), and validateaddress().
Definition at line 1453 of file script.cpp.
References CKeyStore::GetCScript(), CPubKey::GetID(), CKeyStore::HaveKey(), HaveKeys(), IsMine(), Solver(), TX_MULTISIG, TX_NONSTANDARD, TX_NULL_DATA, TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
bool IsStandard | ( | const CScript & | scriptPubKey, |
txnouttype & | whichType | ||
) |
Definition at line 1403 of file script.cpp.
References Solver(), TX_MULTISIG, and TX_NONSTANDARD.
Referenced by IsStandardTx().
|
inlinestatic |
Definition at line 57 of file script.cpp.
Referenced by EvalScript(), and VerifyScript().
Definition at line 1675 of file script.cpp.
Referenced by CombineSignatures().
int ScriptSigArgsExpected | ( | txnouttype | t, |
const std::vector< std::vector< unsigned char > > & | vSolutions | ||
) |
Definition at line 1382 of file script.cpp.
References TX_MULTISIG, TX_NONSTANDARD, TX_NULL_DATA, TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
Referenced by AreInputsStandard().
bool Sign1 | ( | const CKeyID & | address, |
const CKeyStore & | keystore, | ||
uint256 | hash, | ||
int | nHashType, | ||
CScript & | scriptSigRet | ||
) |
Definition at line 1308 of file script.cpp.
References CKeyStore::GetKey(), and CKey::Sign().
Referenced by SignN(), and Solver().
uint256 SignatureHash | ( | const CScript & | scriptCode, |
const CTransaction & | txTo, | ||
unsigned int | nIn, | ||
int | nHashType | ||
) |
Definition at line 1062 of file script.cpp.
References CHashWriter::GetHash(), LogPrintf, SER_GETHASH, SIGHASH_SINGLE, CTransaction::vin, and CTransaction::vout.
Referenced by CheckSig(), and SignSignature().
bool SignN | ( | const vector< valtype > & | multisigdata, |
const CKeyStore & | keystore, | ||
uint256 | hash, | ||
int | nHashType, | ||
CScript & | scriptSigRet | ||
) |
Definition at line 1323 of file script.cpp.
References CPubKey::GetID(), and Sign1().
Referenced by Solver().
bool SignSignature | ( | const CKeyStore & | keystore, |
const CScript & | fromPubKey, | ||
CTransaction & | txTo, | ||
unsigned int | nIn, | ||
int | nHashType | ||
) |
Definition at line 1630 of file script.cpp.
References SCRIPT_VERIFY_P2SH, SCRIPT_VERIFY_STRICTENC, SignatureHash(), Solver(), TX_SCRIPTHASH, VerifyScript(), and CTransaction::vin.
Referenced by signrawtransaction(), and SignSignature().
bool SignSignature | ( | const CKeyStore & | keystore, |
const CTransaction & | txFrom, | ||
CTransaction & | txTo, | ||
unsigned int | nIn, | ||
int | nHashType | ||
) |
Definition at line 1665 of file script.cpp.
References SignSignature(), CTransaction::vin, and CTransaction::vout.
bool Solver | ( | const CScript & | scriptPubKey, |
txnouttype & | typeRet, | ||
vector< vector< unsigned char > > & | vSolutionsRet | ||
) |
Definition at line 1186 of file script.cpp.
References CScript::DecodeOP_N(), CScript::GetOp(), CScript::IsPayToScriptHash(), MAX_OP_RETURN_RELAY, OP_0, OP_1, OP_16, OP_CHECKMULTISIG, OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, OP_PUBKEY, OP_PUBKEYHASH, OP_PUBKEYS, OP_RETURN, OP_SMALLDATA, OP_SMALLINTEGER, PAIRTYPE, TX_MULTISIG, TX_NONSTANDARD, TX_NULL_DATA, TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
Referenced by AreInputsStandard(), CombineSignatures(), ExtractDestination(), ExtractDestinations(), getOutputType(), IsMine(), CBloomFilter::IsRelevantAndUpdate(), IsStandard(), SignSignature(), and Solver().
bool Solver | ( | const CKeyStore & | keystore, |
const CScript & | scriptPubKey, | ||
uint256 | hash, | ||
int | nHashType, | ||
CScript & | scriptSigRet, | ||
txnouttype & | whichTypeRet | ||
) |
Definition at line 1343 of file script.cpp.
References CKeyStore::GetCScript(), CPubKey::GetID(), CKeyStore::GetPubKey(), OP_0, Sign1(), SignN(), Solver(), TX_MULTISIG, TX_NONSTANDARD, TX_NULL_DATA, TX_PUBKEY, TX_PUBKEYHASH, and TX_SCRIPTHASH.
|
static |
|
static |
|
static |
bool VerifyScript | ( | const CScript & | scriptSig, |
const CScript & | scriptPubKey, | ||
const CTransaction & | txTo, | ||
unsigned int | nIn, | ||
unsigned int | flags, | ||
int | nHashType | ||
) |
Definition at line 1588 of file script.cpp.
References CastToBool(), EvalScript(), CScript::IsPayToScriptHash(), CScript::IsPushOnly(), popstack(), and SCRIPT_VERIFY_P2SH.
Referenced by CScriptCheck::operator()(), signrawtransaction(), and SignSignature().
|
static |
|
static |
Referenced by EvalScript().
|
static |
|
static |
Referenced by EvalScript().