mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-29 18:05:58 +02:00
[MOVEONLY] Move CSCript::FindAndDelete to interpreter
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,4 +189,6 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
|
||||
|
||||
size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags);
|
||||
|
||||
int FindAndDelete(CScript& script, const CScript& b);
|
||||
|
||||
#endif // BITCOIN_SCRIPT_INTERPRETER_H
|
||||
|
||||
@@ -571,34 +571,6 @@ public:
|
||||
return (opcodetype)(OP_1+n-1);
|
||||
}
|
||||
|
||||
int FindAndDelete(const CScript& b)
|
||||
{
|
||||
int nFound = 0;
|
||||
if (b.empty())
|
||||
return nFound;
|
||||
CScript result;
|
||||
const_iterator pc = begin(), pc2 = begin(), end = this->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 (GetOp(pc, opcode));
|
||||
|
||||
if (nFound > 0) {
|
||||
result.insert(result.end(), pc2, end);
|
||||
*this = result;
|
||||
}
|
||||
|
||||
return nFound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs
|
||||
* as 20 sigops. With pay-to-script-hash, that changed:
|
||||
|
||||
Reference in New Issue
Block a user