diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2018-04-04 09:02:24 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-04-13 09:07:27 -0700 |
commit | 6a7456ad6072f405e8b02bffa0fb4e9f0cfe71e0 (patch) | |
tree | 90162c46919ee3d6ce683f5ff575fec5f917e5ae /src/script/interpreter.cpp | |
parent | 33a8ecfbce9c108f0a945dcce479e87c8a2714dc (diff) |
[MOVEONLY] Move CSCript::FindAndDelete to interpreter
Diffstat (limited to 'src/script/interpreter.cpp')
-rw-r--r-- | src/script/interpreter.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 338e07e24e..e0d193fa38 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -250,6 +250,34 @@ bool static CheckMinimalPush(const valtype& data, opcodetype opcode) { return true; } +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; +} + bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror) { static const CScriptNum bnZero(0); @@ -891,7 +919,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& // Drop the signature in pre-segwit scripts but not segwit scripts if (sigversion == SigVersion::BASE) { - scriptCode.FindAndDelete(CScript(vchSig)); + FindAndDelete(scriptCode, CScript(vchSig)); } if (!CheckSignatureEncoding(vchSig, flags, serror) || !CheckPubKeyEncoding(vchPubKey, flags, sigversion, serror)) { @@ -955,7 +983,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& { valtype& vchSig = stacktop(-isig-k); if (sigversion == SigVersion::BASE) { - scriptCode.FindAndDelete(CScript(vchSig)); + FindAndDelete(scriptCode, CScript(vchSig)); } } |