Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
Show All 38 Lines | |||||
#define altstacktop(i) (altstack.at(altstack.size() + (i))) | #define altstacktop(i) (altstack.at(altstack.size() + (i))) | ||||
static inline void popstack(std::vector<valtype> &stack) { | static inline void popstack(std::vector<valtype> &stack) { | ||||
if (stack.empty()) { | if (stack.empty()) { | ||||
throw std::runtime_error("popstack(): stack empty"); | throw std::runtime_error("popstack(): stack empty"); | ||||
} | } | ||||
stack.pop_back(); | stack.pop_back(); | ||||
} | } | ||||
int FindAndDelete(CScript &script, const CScript &b) { | |||||
int nFound = 0; | |||||
if (b.empty()) { | |||||
return nFound; | |||||
} | |||||
CScript result; | |||||
CScript::const_iterator pc = script.begin(), pc2 = script.begin(), | |||||
end = script.end(); | |||||
opcodetype opcode; | |||||
do { | |||||
result.insert(result.end(), pc2, pc); | |||||
while (static_cast<size_t>(end - pc) >= b.size() && | |||||
std::equal(b.begin(), b.end(), pc)) { | |||||
pc = pc + b.size(); | |||||
++nFound; | |||||
} | |||||
pc2 = pc; | |||||
} while (script.GetOp(pc, opcode)); | |||||
if (nFound > 0) { | |||||
result.insert(result.end(), pc2, end); | |||||
script = std::move(result); | |||||
} | |||||
return nFound; | |||||
} | |||||
static void CleanupScriptCode(CScript &scriptCode, | static void CleanupScriptCode(CScript &scriptCode, | ||||
const std::vector<uint8_t> &vchSig, | const std::vector<uint8_t> &vchSig, | ||||
uint32_t flags) { | uint32_t flags) { | ||||
// Drop the signature in scripts when SIGHASH_FORKID is not used. | // Drop the signature in scripts when SIGHASH_FORKID is not used. | ||||
SigHashType sigHashType = GetHashType(vchSig); | SigHashType sigHashType = GetHashType(vchSig); | ||||
if (!(flags & SCRIPT_ENABLE_SIGHASH_FORKID) || !sigHashType.hasForkId()) { | if (!(flags & SCRIPT_ENABLE_SIGHASH_FORKID) || !sigHashType.hasForkId()) { | ||||
scriptCode.FindAndDelete(CScript(vchSig)); | FindAndDelete(scriptCode, CScript(vchSig)); | ||||
} | } | ||||
} | } | ||||
static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags) { | static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags) { | ||||
switch (opcode) { | switch (opcode) { | ||||
case OP_INVERT: | case OP_INVERT: | ||||
case OP_2MUL: | case OP_2MUL: | ||||
case OP_2DIV: | case OP_2DIV: | ||||
▲ Show 20 Lines • Show All 1,682 Lines • Show Last 20 Lines |