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

Method raw_iter

test/functional/test_framework/script.py:443–498  ·  view source on GitHub ↗

Raw iteration Yields tuples of (opcode, data, sop_idx) so that the different possible PUSHDATA encodings can be accurately distinguished, as well as determining the exact opcode byte indexes. (sop_idx)

(self)

Source from the content-addressed store, hash-verified

441 return super(CScript, cls).__new__(cls, b''.join(coerce_iterable(value)))
442
443 def raw_iter(self):
444 """Raw iteration
445
446 Yields tuples of (opcode, data, sop_idx) so that the different possible
447 PUSHDATA encodings can be accurately distinguished, as well as
448 determining the exact opcode byte indexes. (sop_idx)
449 """
450 i = 0
451 while i < len(self):
452 sop_idx = i
453 opcode = self[i]
454 i += 1
455
456 if opcode > OP_PUSHDATA4:
457 yield (opcode, None, sop_idx)
458 else:
459 datasize = None
460 pushdata_type = None
461 if opcode < OP_PUSHDATA1:
462 pushdata_type = 'PUSHDATA(%d)' % opcode
463 datasize = opcode
464
465 elif opcode == OP_PUSHDATA1:
466 pushdata_type = 'PUSHDATA1'
467 if i >= len(self):
468 raise CScriptInvalidError('PUSHDATA1: missing data length')
469 datasize = self[i]
470 i += 1
471
472 elif opcode == OP_PUSHDATA2:
473 pushdata_type = 'PUSHDATA2'
474 if i + 1 >= len(self):
475 raise CScriptInvalidError('PUSHDATA2: missing data length')
476 datasize = self[i] + (self[i+1] << 8)
477 i += 2
478
479 elif opcode == OP_PUSHDATA4:
480 pushdata_type = 'PUSHDATA4'
481 if i + 3 >= len(self):
482 raise CScriptInvalidError('PUSHDATA4: missing data length')
483 datasize = self[i] + (self[i+1] << 8) + (self[i+2] << 16) + (self[i+3] << 24)
484 i += 4
485
486 else:
487 assert False # shouldn't happen
488
489
490 data = bytes(self[i:i+datasize])
491
492 # Check for truncation
493 if len(data) < datasize:
494 raise CScriptTruncatedPushDataError('%s: truncated data' % pushdata_type, data)
495
496 i += datasize
497
498 yield (opcode, data, sop_idx)
499
500 def __iter__(self):

Callers 3

__iter__Method · 0.95
GetSigOpCountMethod · 0.95
FindAndDeleteFunction · 0.80

Calls 2

CScriptInvalidErrorClass · 0.85

Tested by

no test coverage detected