Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.cpp
Show First 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
unsigned int CScript::GetSigOpCount(bool fAccurate) const { | unsigned int CScript::GetSigOpCount(bool fAccurate) const { | ||||
unsigned int n = 0; | unsigned int 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)) break; | if (!GetOp(pc, opcode)) { | ||||
if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY) | break; | ||||
} | |||||
switch (opcode) { | |||||
case OP_CHECKSIG: | |||||
case OP_CHECKSIGVERIFY: | |||||
n++; | n++; | ||||
else if (opcode == OP_CHECKMULTISIG || | break; | ||||
opcode == OP_CHECKMULTISIGVERIFY) { | |||||
if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16) | case OP_CHECKMULTISIG: | ||||
case OP_CHECKMULTISIGVERIFY: | |||||
if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16) { | |||||
n += DecodeOP_N(lastOpcode); | n += DecodeOP_N(lastOpcode); | ||||
else | } else { | ||||
n += MAX_PUBKEYS_PER_MULTISIG; | n += MAX_PUBKEYS_PER_MULTISIG; | ||||
} | } | ||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
lastOpcode = opcode; | lastOpcode = opcode; | ||||
} | } | ||||
return n; | return n; | ||||
} | } | ||||
unsigned int CScript::GetSigOpCount(const CScript &scriptSig) const { | unsigned int CScript::GetSigOpCount(const CScript &scriptSig) const { | ||||
if (!IsPayToScriptHash()) return GetSigOpCount(true); | if (!IsPayToScriptHash()) { | ||||
return GetSigOpCount(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)) return 0; | if (!scriptSig.GetOp(pc, opcode, data)) { | ||||
if (opcode > OP_16) return 0; | return 0; | ||||
} | |||||
if (opcode > OP_16) { | |||||
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(true); | ||||
} | } | ||||
bool CScript::IsPayToScriptHash() const { | bool CScript::IsPayToScriptHash() const { | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |