aboutsummaryrefslogtreecommitdiff
path: root/src/script/script.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/script.h')
-rw-r--r--src/script/script.h102
1 files changed, 4 insertions, 98 deletions
diff --git a/src/script/script.h b/src/script/script.h
index 59ceff247c..d8b7c06013 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -385,6 +385,8 @@ private:
*/
typedef prevector<28, unsigned char> CScriptBase;
+bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet);
+
/** Serialized script, used inside transaction inputs and outputs */
class CScript : public CScriptBase
{
@@ -493,84 +495,16 @@ public:
}
- bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
- {
- // Wrapper so it can be called with either iterator or const_iterator
- const_iterator pc2 = pc;
- bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
- pc = begin() + (pc2 - begin());
- return fRet;
- }
-
- bool GetOp(iterator& pc, opcodetype& opcodeRet)
- {
- const_iterator pc2 = pc;
- bool fRet = GetOp2(pc2, opcodeRet, nullptr);
- pc = begin() + (pc2 - begin());
- return fRet;
- }
-
bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
{
- return GetOp2(pc, opcodeRet, &vchRet);
+ return GetScriptOp(pc, end(), opcodeRet, &vchRet);
}
bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
{
- return GetOp2(pc, opcodeRet, nullptr);
+ return GetScriptOp(pc, end(), opcodeRet, nullptr);
}
- bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) const
- {
- opcodeRet = OP_INVALIDOPCODE;
- if (pvchRet)
- pvchRet->clear();
- if (pc >= end())
- return false;
-
- // Read instruction
- if (end() - pc < 1)
- return false;
- unsigned int opcode = *pc++;
-
- // Immediate operand
- if (opcode <= OP_PUSHDATA4)
- {
- unsigned int nSize = 0;
- if (opcode < OP_PUSHDATA1)
- {
- nSize = opcode;
- }
- else if (opcode == OP_PUSHDATA1)
- {
- if (end() - pc < 1)
- return false;
- nSize = *pc++;
- }
- else if (opcode == OP_PUSHDATA2)
- {
- if (end() - pc < 2)
- return false;
- nSize = ReadLE16(&pc[0]);
- pc += 2;
- }
- else if (opcode == OP_PUSHDATA4)
- {
- if (end() - pc < 4)
- return false;
- nSize = ReadLE32(&pc[0]);
- pc += 4;
- }
- if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize)
- return false;
- if (pvchRet)
- pvchRet->assign(pc, pc + nSize);
- pc += nSize;
- }
-
- opcodeRet = static_cast<opcodetype>(opcode);
- return true;
- }
/** Encode/decode small integers: */
static int DecodeOP_N(opcodetype opcode)
@@ -588,34 +522,6 @@ public:
return (opcodetype)(OP_1+n-1);
}
- int FindAndDelete(const CScript& b)
- {
- int nFound = 0;
- if (b.empty())
- return nFound;
- CScript result;
- iterator pc = begin(), pc2 = begin();
- 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: