def __repr__(self): result = '' for instruction in self.instructions: if type(instruction) == int: if OP_CODE_NAMES.get(instruction): name = OP_CODE_NAMES.get(instruction) else: name = 'OP_[{}]'.format(instruction) result += '{} '.format(name) else: result += '{} '.format(instruction.hex()) return result
def __repr__(self): result = [] for cmd in self.cmds: if type(cmd) == int: if OP_CODE_NAMES.get(cmd): name = OP_CODE_NAMES.get(cmd) else: name = 'OP_[{}]'.format(cmd) result.append(name) else: result.append(cmd.hex()) return ' '.join(result)
def __repr__(self): result = [] for instruction in self.instructions: if type(instruction) == int: if OP_CODE_NAMES.get(instruction): name = OP_CODE_NAMES.get(instruction) else: name = 'OP_[{}]'.format(instruction) result.append(name) else: result.append(instruction.hex()) return ' '.join(result)
def __repr__(self): result = '' for command in self.commands: if type(command) == int: if OP_CODE_NAMES.get(command): name = OP_CODE_NAMES.get(command) else: name = 'OP_[{}]'.format(command) result += '{} '.format(name) else: result += '{} '.format(command.hex()) return result
def print_state(instructions, instruction, stack, altstack): LOGGER.info('-' * 78) print_altstack = len(altstack) > 0 if print_altstack: column_width = 18 in_between = 2 else: column_width = 24 in_between = 3 format_str = '{0: <' + str(column_width) + '}' total_height = max(len(instructions), 1, len(stack)) for i in range(total_height): to_print = '' if len(instructions) >= total_height - i: current = instructions[len(instructions) - (total_height - i)] if type(current) == int: current = OP_CODE_NAMES.get(current) or '<unknown>' else: current = current.hex()[:column_width] to_print += format_str.format(current) else: to_print += ' ' * column_width to_print += ' ' * in_between if i == total_height - 1: current = instruction if type(current) == int: current = OP_CODE_NAMES.get(current) or '<unknown>' else: current = current.hex()[:column_width] to_print += format_str.format(current) else: to_print += ' ' * column_width to_print += ' ' * in_between if len(stack) >= total_height - i: current = stack[total_height - i - 1] if len(current) == 0: current = '0' else: current = current.hex()[:column_width] to_print += format_str.format(current) if print_altstack: to_print += ' ' * in_between if len(stack) >= total_height - i: current = stack[total_height - i - 1] if len(current) == 0: current = '0' else: current = current.hex()[:column_width] to_print += format_str.format(current) LOGGER.info(to_print)
def raw_serialize(self) -> bytes: # initialize what we'll send back result = b'' # go through each command for current in self: if current == OP_0: result += int_to_byte(0) elif OP_CODE_NAMES.get(current) is None: # this is an element # get the length in bytes length = len(current) # for large lengths, we have to use a pushdata op code if length < 75: # turn the length into a single byte integer result += int_to_byte(length) elif length > 75 and length < 0x100: # 76 is pushdata1 result += OP_PUSHDATA1 result += int_to_byte(length) elif length >= 0x100 and length <= 520: # 77 is pushdata2 result += OP_PUSHDATA2 result += int_to_little_endian(length, 2) else: raise ValueError('too long a command') result += current return result
def __repr__(self) -> str: result = '' for current in self: if OP_CODE_NAMES.get(current): result += f'{OP_CODE_NAMES[current]} ' elif type(current) == str: result += f'<{current}> ' else: result += f'{current.hex()} ' return result