def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None) -> bytes: page = OutputsMessage() page.offset = offset page.total = total or len(txo_rows) for row in txo_rows: cls.row_to_message(row, page.txos.add()) for row in extra_txo_rows: cls.row_to_message(row, page.extra_txos.add()) return page.SerializeToString()
def from_bytes(cls, data: bytes) -> 'Outputs': outputs = OutputsMessage() outputs.ParseFromString(data) txs = set() for txo_message in chain(outputs.txos, outputs.extra_txos): if txo_message.WhichOneof('meta') == 'error': continue txs.add((hexlify(txo_message.tx_hash[::-1]).decode(), txo_message.height)) return cls(outputs.txos, outputs.extra_txos, txs, outputs.offset, outputs.total)
def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None, blocked: Censor = None) -> bytes: page = OutputsMessage() page.offset = offset if total is not None: page.total = total if blocked is not None: blocked.to_message(page) for row in txo_rows: cls.row_to_message(row, page.txos.add(), extra_txo_rows) for row in extra_txo_rows: cls.row_to_message(row, page.extra_txos.add(), extra_txo_rows) return page.SerializeToString()
def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None, blocked: Censor = None) -> bytes: page = OutputsMessage() page.offset = offset if total is not None: page.total = total if blocked is not None: blocked.to_message(page, extra_txo_rows) for row in extra_txo_rows: txo_message: 'OutputsMessage' = page.extra_txos.add() if not isinstance(row, Exception): if row.channel_hash: set_reference(txo_message.claim.channel, row.channel_hash, extra_txo_rows) if row.reposted_claim_hash: set_reference(txo_message.claim.repost, row.reposted_claim_hash, extra_txo_rows) cls.encode_txo(txo_message, row) for row in txo_rows: # cls.row_to_message(row, page.txos.add(), extra_txo_rows) txo_message: 'OutputsMessage' = page.txos.add() cls.encode_txo(txo_message, row) if not isinstance(row, Exception): if row.channel_hash: set_reference(txo_message.claim.channel, row.channel_hash, extra_txo_rows) if row.reposted_claim_hash: set_reference(txo_message.claim.repost, row.reposted_claim_hash, extra_txo_rows) elif isinstance(row, ResolveCensoredError): set_reference(txo_message.error.blocked.channel, row.censor_id, extra_txo_rows) return page.SerializeToString()