MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetScriptOp

Function GetScriptOp

src/script/script.cpp:399–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet)
400{
401 opcodeRet = OP_INVALIDOPCODE;
402 if (pvchRet)
403 pvchRet->clear();
404 if (pc >= end)
405 return false;
406
407 // Read instruction
408 if (end - pc < 1)
409 return false;
410 unsigned int opcode = *pc++;
411
412 // Immediate operand
413 if (opcode <= OP_PUSHDATA4)
414 {
415 unsigned int nSize = 0;
416 if (opcode < OP_PUSHDATA1)
417 {
418 nSize = opcode;
419 }
420 else if (opcode == OP_PUSHDATA1)
421 {
422 if (end - pc < 1)
423 return false;
424 nSize = *pc++;
425 }
426 else if (opcode == OP_PUSHDATA2)
427 {
428 if (end - pc < 2)
429 return false;
430 nSize = ReadLE16(&pc[0]);
431 pc += 2;
432 }
433 else if (opcode == OP_PUSHDATA4)
434 {
435 if (end - pc < 4)
436 return false;
437 nSize = ReadLE32(&pc[0]);
438 pc += 4;
439 }
440 if (end - pc < 0 || (unsigned int)(end - pc) < nSize)
441 return false;
442 if (pvchRet)
443 pvchRet->assign(pc, pc + nSize);
444 pc += nSize;
445 }
446
447 opcodeRet = static_cast<opcodetype>(opcode);
448 return true;
449}
450
451bool IsOpSuccess(const opcodetype& opcode)
452{

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