MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / GetScriptOp

Function GetScriptOp

src/script/script.cpp:279–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277}
278
279bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet)
280{
281 opcodeRet = OP_INVALIDOPCODE;
282 if (pvchRet)
283 pvchRet->clear();
284 if (pc >= end)
285 return false;
286
287 // Read instruction
288 if (end - pc < 1)
289 return false;
290 unsigned int opcode = *pc++;
291
292 // Immediate operand
293 if (opcode <= OP_PUSHDATA4)
294 {
295 unsigned int nSize = 0;
296 if (opcode < OP_PUSHDATA1)
297 {
298 nSize = opcode;
299 }
300 else if (opcode == OP_PUSHDATA1)
301 {
302 if (end - pc < 1)
303 return false;
304 nSize = *pc++;
305 }
306 else if (opcode == OP_PUSHDATA2)
307 {
308 if (end - pc < 2)
309 return false;
310 nSize = ReadLE16(&pc[0]);
311 pc += 2;
312 }
313 else if (opcode == OP_PUSHDATA4)
314 {
315 if (end - pc < 4)
316 return false;
317 nSize = ReadLE32(&pc[0]);
318 pc += 4;
319 }
320 if (end - pc < 0 || (unsigned int)(end - pc) < nSize)
321 return false;
322 if (pvchRet)
323 pvchRet->assign(pc, pc + nSize);
324 pc += nSize;
325 }
326
327 opcodeRet = static_cast<opcodetype>(opcode);
328 return true;
329}

Callers 1

GetOpMethod · 0.85

Calls 4

ReadLE16Function · 0.85
ReadLE32Function · 0.85
clearMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected