Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Macros | Typedefs | Functions | Variables
script.cpp File Reference
#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>
+ Include dependency graph for script.cpp:

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)
 

Macro Definition Documentation

#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 Documentation

typedef vector<unsigned char> valtype

Definition at line 23 of file script.cpp.

Function Documentation

bool CastToBool ( const valtype vch)

Definition at line 34 of file script.cpp.

Referenced by EvalScript(), and VerifyScript().

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static CScript CombineMultisig ( CScript  scriptPubKey,
const CTransaction txTo,
unsigned int  nIn,
const vector< valtype > &  vSolutions,
vector< valtype > &  sigs1,
vector< valtype > &  sigs2 
)
static

Definition at line 1683 of file script.cpp.

References CheckSig(), and OP_0.

Referenced by CombineSignatures().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static CScript CombineSignatures ( CScript  scriptPubKey,
const CTransaction txTo,
unsigned int  nIn,
const txnouttype  txType,
const vector< valtype > &  vSolutions,
vector< valtype > &  sigs1,
vector< valtype > &  sigs2 
)
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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const char* GetOpName ( opcodetype  opcode)
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().

+ Here is the caller graph for this function:

unsigned int HaveKeys ( const vector< valtype > &  pubkeys,
const CKeyStore keystore 
)

Definition at line 1424 of file script.cpp.

References CPubKey::GetID(), and CKeyStore::HaveKey().

Referenced by IsMine().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool IsCanonicalPubKey ( const valtype vchPubKey,
unsigned int  flags 
)

Definition at line 224 of file script.cpp.

References error(), and SCRIPT_VERIFY_STRICTENC.

Referenced by EvalScript().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool IsCanonicalSignature ( const valtype vchSig,
unsigned int  flags 
)

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool IsMine ( const CKeyStore keystore,
const CTxDestination dest 
)
bool IsMine ( const CKeyStore keystore,
const CScript scriptPubKey 
)

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.

+ Here is the call graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void popstack ( vector< valtype > &  stack)
inlinestatic

Definition at line 57 of file script.cpp.

Referenced by EvalScript(), and VerifyScript().

+ Here is the caller graph for this function:

static CScript PushAll ( const vector< valtype > &  values)
static

Definition at line 1675 of file script.cpp.

Referenced by CombineSignatures().

+ Here is the caller graph for this function:

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().

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

static const valtype vchFalse ( )
static

Referenced by EvalScript().

+ Here is the caller graph for this function:

static const valtype vchTrue ( ,
 
)
static

Referenced by EvalScript().

+ Here is the caller graph for this function:

static const valtype vchZero ( )
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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const CScriptNum bnFalse(0)
static
const CScriptNum bnOne(1)
static

Referenced by EvalScript().

const CScriptNum bnTrue(1)
static
const CScriptNum bnZero(0)
static

Referenced by EvalScript().