def __init__(self, magic: int = None, block_hash: BtcObjectHash = None, transactions: List[memoryview] = None, # pyre-fixme[9]: buf has type `memoryview`; used as `None`. buf: memoryview = None): if buf is None: total_tx_size = sum(len(tx) for tx in transactions) # pyre-fixme[9]: buf has type `memoryview`; used as `bytearray`. buf = bytearray(BTC_HDR_COMMON_OFF + BTC_SHA_HASH_LEN + BTC_VARINT_MIN_SIZE + total_tx_size) off = BTC_HDR_COMMON_OFF buf[off:off + BTC_SHA_HASH_LEN] = block_hash.get_big_endian() off += BTC_SHA_HASH_LEN off += pack_int_to_btc_varint(len(transactions), buf, off) for tx in transactions: buf[off:off + len(tx)] = tx off += len(tx) self.buf = buf super(BlockTransactionsBtcMessage, self).__init__(magic, self.MESSAGE_TYPE, off - BTC_HDR_COMMON_OFF, buf) else: self.buf = buf self._memoryview = memoryview(buf) self._magic = self._command = self._payload_len = self._checksum = None self._payload = None self._block_hash = None # pyre-fixme[8]: Attribute has type `List[int]`; used as `None`. self._transactions: List[int] = None
def __init__( self, magic: int = None, block_hash: BtcObjectHash = None, indices: List[int] = None, # pyre-fixme[9]: buf has type `memoryview`; used as `None`. buf: memoryview = None): if buf is None: # pyre-fixme[9]: buf has type `memoryview`; used as `bytearray`. buf = bytearray(BTC_HDR_COMMON_OFF + BTC_SHA_HASH_LEN + BTC_VARINT_MIN_SIZE + BTC_VARINT_MIN_SIZE * len(indices)) off = BTC_HDR_COMMON_OFF buf[off:off + BTC_SHA_HASH_LEN] = block_hash.get_big_endian() off += BTC_SHA_HASH_LEN off += pack_int_to_btc_varint(len(indices), buf, off) last_real_index = -1 for real_index in indices: diff = real_index - last_real_index - 1 last_real_index = real_index off += pack_int_to_btc_varint(diff, buf, off) self.buf = buf super(GetBlockTransactionsBtcMessage, self).__init__(magic, self.MESSAGE_TYPE, off - BTC_HDR_COMMON_OFF, buf) else: self.buf = buf self._memoryview = memoryview(buf) self._magic = self._command = self._payload_len = self._checksum = None self._payload = None self._block_hash = None # pyre-fixme[8]: Attribute has type `List[int]`; used as `None`. self._indices: List[int] = None