예제 #1
0
    def deserialize(self, raw):
        """Deserialize hex-encoded block/block header.

        Returns:
            Two-tuple of (block, block_header)
        """
        raw = x(raw)
        try:
            if len(raw) == BlockHeader.header_length():
                block_header = BlockHeader.deserialize(raw)
                return (None, block_header)
            else:
                # We don't use block.get_header() in case the header is
                # correct but the rest of the block isn't.
                block_header = BlockHeader.deserialize(raw[0:BlockHeader.header_length()])
                block = Block.deserialize(raw)
                return (block, block_header)
        except Exception as e:
            return (None, None)
예제 #2
0
    def deserialize(self, raw):
        """Deserialize hex-encoded block/block header.

        Returns:
            Two-tuple of (block, block_header)
        """
        raw = x(raw)
        try:
            if len(raw) == BlockHeader.header_length():
                block_header = BlockHeader.deserialize(raw)
                return (None, block_header)
            else:
                # We don't use block.get_header() in case the header is
                # correct but the rest of the block isn't.
                block_header = BlockHeader.deserialize(
                    raw[0:BlockHeader.header_length()])
                block = Block.deserialize(raw)
                return (block, block_header)
        except Exception as e:
            return (None, None)
예제 #3
0
    def select_block_field(self, selected, deselected):
        if len(self.raw_block_edit.toPlainText()) < BlockHeader.header_length() * 2:
            return
        if not len(selected.indexes()):
            return
        index = selected.indexes()[0]
        row = index.row()
        header = [i[2] * 2 for i in self.header.fields]

        start = sum(header[0:row])
        length = header[row]

        cursor = QTextCursor(self.raw_block_edit.document())
        cursor.setPosition(start)
        cursor.setPosition(start + length, QTextCursor.KeepAnchor)
        self.raw_block_edit.setTextCursor(cursor)
예제 #4
0
    def select_block_field(self, selected, deselected):
        if len(self.raw_block_edit.toPlainText()
               ) < BlockHeader.header_length() * 2:
            return
        if not len(selected.indexes()):
            return
        index = selected.indexes()[0]
        row = index.row()
        header = [i[2] * 2 for i in self.header.fields]

        start = sum(header[0:row])
        length = header[row]

        cursor = QTextCursor(self.raw_block_edit.document())
        cursor.setPosition(start)
        cursor.setPosition(start + length, QTextCursor.KeepAnchor)
        self.raw_block_edit.setTextCursor(cursor)
예제 #5
0
    def on_tx_selection(self, selected, deselected):
        if not self.block or not len(selected.indexes()):
            return
        index = selected.indexes()[0]
        row = index.row()

        def tx_len(i):
            return len(self.block.vtx[i].serialize()) * 2

        start = BlockHeader.header_length() * 2 + sum(tx_len(i) for i in range(row))
        # Account for VarInt.
        _buf = BytesIO()
        VarIntSerializer.stream_serialize(len(self.block.vtx), _buf)
        start += len(_buf.getvalue()) * 2

        length = len(self.block.vtx[row].serialize()) * 2
        self.select_block_text(start, length)
예제 #6
0
    def on_tx_selection(self, selected, deselected):
        if not self.block or not len(selected.indexes()):
            return
        index = selected.indexes()[0]
        row = index.row()

        def tx_len(i):
            return len(self.block.vtx[i].serialize()) * 2

        start = BlockHeader.header_length() * 2 + sum(
            tx_len(i) for i in range(row))
        # Account for VarInt.
        _buf = BytesIO()
        VarIntSerializer.stream_serialize(len(self.block.vtx), _buf)
        start += len(_buf.getvalue()) * 2

        length = len(self.block.vtx[row].serialize()) * 2
        self.select_block_text(start, length)
예제 #7
0
 def test_bitcoin_fields(self):
     self.assertEqual(BlockHeader.header_length(), 80)
     header = BlockHeader.deserialize(bitcoin_raw_header)
     self.assertEqual(bitcoin_header_fields, header.fields)
예제 #8
0
 def test_bitcoin_fields(self):
     self.assertEqual(BlockHeader.header_length(), 80)
     header = BlockHeader.deserialize(bitcoin_raw_header)
     self.assertEqual(bitcoin_header_fields, header.fields)