def forge_block_header(shell_header: Dict[str, Any]) -> bytes: res = forge_int_fixed(shell_header['level'], 4) res += forge_int_fixed(shell_header['proto'], 1) res += forge_base58(shell_header['predecessor']) res += forge_int_fixed(optimize_timestamp(shell_header['timestamp']), 8) res += forge_int_fixed(shell_header['validation_pass'], 1) res += forge_base58(shell_header['operations_hash']) res += forge_fitness(shell_header['fitness']) res += forge_base58(shell_header['context']) res += bytes.fromhex(shell_header['protocol_data']) return res
def binary_payload(self) -> bytes: """ Get binary payload used for injection/hash calculation. """ if not self.signature: raise ValueError('Not signed') return bytes.fromhex(self.forge()) + forge_base58(self.signature)
def forge_content(content: Dict[str, Any]) -> bytes: res = b'' res += forge_command(content['command']) res += forge_base58(content['hash']) res += forge_fitness(content['fitness']) res += bytes.fromhex(content['protocol_parameters']) return res
def to_micheline_value(self, mode='readable', lazy_diff=False): if mode in ['optimized', 'legacy_optimized']: return {'bytes': forge_base58(self.value).hex()} elif mode == 'readable': return {'string': self.value} else: assert False, f'unsupported mode {mode}'
def binary_payload(self) -> bytes: """Get binary payload used for injection/hash calculation.""" if self.contents[0]['kind'] == 'endorsement_with_slot': return bytes.fromhex(self.forge()) + b'\x00' * 64 if not self.signature: raise ValueError('Not signed') return bytes.fromhex(self.forge()) + forge_base58(self.signature)
def forge_operation_group(operation_group: Dict[str, Any]) -> bytes: """Forge operation group (locally). :param operation_group: {"branch": "B...", "contents": [], ...} """ res = forge_base58(operation_group['branch']) res += b''.join(map(forge_operation, operation_group['contents'])) return res
def forge_protocol_data(protocol_data: Dict[str, Any]) -> bytes: res = b'' if protocol_data.get('content'): res += forge_content(protocol_data['content']) else: res += forge_priority(protocol_data['priority']) res += bytes.fromhex(protocol_data['proof_of_work_nonce']) if protocol_data.get('seed_nonce_hash'): res += b'\xFF' res += forge_base58(protocol_data['seed_nonce_hash']) else: res += b'\x00' return res
def forge_activate_account(content: Dict[str, Any]) -> bytes: res = forge_nat(operation_tags[content['kind']]) res += forge_base58(content['pkh']) res += bytes.fromhex(content['secret']) return res
def forge_inline_endorsement(content: Dict[str, Any]) -> bytes: res = forge_base58(content['branch']) res += forge_nat(operation_tags[content['operations']['kind']]) res += forge_int32(int(content['operations']['level'])) res += forge_base58(content['signature']) return res