Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.cpp
// 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 | ||||
// 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. | ||||
#include "script.h" | #include "script.h" | ||||
#include "script/script_flags.h" | |||||
#include "tinyformat.h" | #include "tinyformat.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
const char *GetOpName(opcodetype opcode) { | const char *GetOpName(opcodetype opcode) { | ||||
switch (opcode) { | switch (opcode) { | ||||
// push value | // push value | ||||
▲ Show 20 Lines • Show All 321 Lines • ▼ Show 20 Lines | for (size_t i = data.size() - 1; i > 0; i--) { | ||||
} | } | ||||
} | } | ||||
// If we the whole thing is zeros, then we have a zero. | // If we the whole thing is zeros, then we have a zero. | ||||
data = {}; | data = {}; | ||||
return true; | return true; | ||||
} | } | ||||
unsigned int CScript::GetSigOpCount(bool fAccurate) const { | uint32_t CScript::GetSigOpCount(uint32_t flags, bool fAccurate) const { | ||||
unsigned int n = 0; | uint32_t n = 0; | ||||
const_iterator pc = begin(); | const_iterator pc = begin(); | ||||
opcodetype lastOpcode = OP_INVALIDOPCODE; | opcodetype lastOpcode = OP_INVALIDOPCODE; | ||||
while (pc < end()) { | while (pc < end()) { | ||||
opcodetype opcode; | opcodetype opcode; | ||||
if (!GetOp(pc, opcode)) { | if (!GetOp(pc, opcode)) { | ||||
break; | break; | ||||
} | } | ||||
Show All 16 Lines | while (pc < end()) { | ||||
} | } | ||||
lastOpcode = opcode; | lastOpcode = opcode; | ||||
} | } | ||||
return n; | return n; | ||||
} | } | ||||
unsigned int CScript::GetSigOpCount(const CScript &scriptSig) const { | uint32_t CScript::GetSigOpCount(uint32_t flags, | ||||
if (!IsPayToScriptHash()) { | const CScript &scriptSig) const { | ||||
return GetSigOpCount(true); | if ((flags & SCRIPT_VERIFY_P2SH) == 0 || !IsPayToScriptHash()) { | ||||
return GetSigOpCount(flags, true); | |||||
} | } | ||||
// This is a pay-to-script-hash scriptPubKey; | // This is a pay-to-script-hash scriptPubKey; | ||||
// get the last item that the scriptSig | // get the last item that the scriptSig | ||||
// pushes onto the stack: | // pushes onto the stack: | ||||
const_iterator pc = scriptSig.begin(); | const_iterator pc = scriptSig.begin(); | ||||
std::vector<uint8_t> data; | std::vector<uint8_t> data; | ||||
while (pc < scriptSig.end()) { | while (pc < scriptSig.end()) { | ||||
opcodetype opcode; | opcodetype opcode; | ||||
if (!scriptSig.GetOp(pc, opcode, data)) { | if (!scriptSig.GetOp(pc, opcode, data)) { | ||||
return 0; | return 0; | ||||
} | } | ||||
if (opcode > OP_16) { | if (opcode > OP_16) { | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } | ||||
/// ... and return its opcount: | /// ... and return its opcount: | ||||
CScript subscript(data.begin(), data.end()); | CScript subscript(data.begin(), data.end()); | ||||
return subscript.GetSigOpCount(true); | return subscript.GetSigOpCount(flags, true); | ||||
} | } | ||||
bool CScript::IsPayToScriptHash() const { | bool CScript::IsPayToScriptHash() const { | ||||
// Extra-fast test for pay-to-script-hash CScripts: | // Extra-fast test for pay-to-script-hash CScripts: | ||||
return (this->size() == 23 && (*this)[0] == OP_HASH160 && | return (this->size() == 23 && (*this)[0] == OP_HASH160 && | ||||
(*this)[1] == 0x14 && (*this)[22] == OP_EQUAL); | (*this)[1] == 0x14 && (*this)[22] == OP_EQUAL); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |