Esempio n. 1
0
 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()
Esempio n. 2
0
 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()
Esempio n. 3
0
    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()