def to_dict(self): """Serialize the header to a readable dictionary.""" d = {} for field in ('mixhash', 'nonce', 'state_branch_node', 'source_block_hash'): d[field] = encode_hex(getattr(self, field)) for field in ('prev_state_root', 'tx_list_root', 'post_state_root', 'receipt_root', 'coinbase'): d[field] = encode_hex(getattr(self, field)) # [TODO] decode_int256 is unsigned or signed? for field in ('shard_id', 'source_block_numeber'): d[field] = utils.decode_int256(getattr(self, field)) encode_hex(getattr(self, field)) d['children'] = [ b'0x' + encode_hex(child) for child in getattr(self, 'children') ] d['signatures'] = [ b'0x' + encode_hex(sig) for sig in getattr(self, 'signatures') ] assert len(d) == len(CollationHeader.fields) return d
def to_dict(self): """Serialize the header to a readable dictionary.""" d = {} for field in ('mixhash', 'nonce', 'state_branch_node', 'source_block_hash'): d[field] = encode_hex(getattr(self, field)) for field in ('prev_state_root', 'tx_list_root', 'post_state_root', 'receipt_root', 'coinbase'): d[field] = encode_hex(getattr(self, field)) # [TODO] decode_int256 is unsigned or signed? for field in ('shard_id', 'source_block_numeber'): d[field] = utils.decode_int256(getattr(self, field)) encode_hex(getattr(self, field)) d['children'] = [b'0x' + encode_hex(child) for child in getattr(self, 'children')] d['signatures'] = [b'0x' + encode_hex(sig) for sig in getattr(self, 'signatures')] assert len(d) == len(CollationHeader.fields) return d