mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
[MOVEONLY] Turn CScript::GetOp2 into a function and move to cpp
This commit is contained in:
parent
6a7456ad60
commit
54a5a21158
3 changed files with 57 additions and 54 deletions
|
|
@ -280,3 +280,55 @@ bool CScript::HasValidOps() const
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue