コード例 #1
0
    def convert_from_older_version(
            self, msg: AbstractInternalMessage) -> AbstractInternalMessage:
        msg_type = msg.MESSAGE_TYPE

        if msg_type not in self._MSG_TYPE_TO_OLD_MSG_CLASS_MAPPING:
            raise ValueError(f"Tried to convert unexpected new "
                             f"message type to v17: {msg_type}")

        msg = cast(TxMessageV17, msg)

        tx_hash = msg.tx_hash()
        network_num = msg.network_num()
        source_id = msg.source_id()
        short_id = msg.short_id()
        tx_val = msg.tx_val()
        transaction_flag = msg.transaction_flag()
        ts = msg.timestamp()

        return TxMessage(message_hash=tx_hash,
                         network_num=network_num,
                         source_id=source_id,
                         short_id=short_id,
                         tx_val=tx_val,
                         transaction_flag=transaction_flag,
                         timestamp=ts)
コード例 #2
0
    def convert_from_older_version(
        self, msg: AbstractInternalMessage
    ) -> AbstractInternalMessage:
        msg_type = msg.MESSAGE_TYPE

        if msg_type not in self._MSG_TYPE_TO_NEW_MSG_CLASS_MAPPING:
            raise ValueError(
                f"Tried to convert unexpected old message type to "
                f"v15: {msg_type}"
            )

        msg = cast(TxMessageV15, msg)

        tx_hash = msg.tx_hash()
        network_num = msg.network_num()
        source_id = msg.source_id()
        short_id = msg.short_id()
        tx_val = msg.tx_val()
        quota_type = msg.quota_type()
        ts = msg.timestamp()

        if QuotaType.FREE_DAILY_QUOTA in quota_type:
            tx_flag = TransactionFlag.NO_FLAGS
        else:
            tx_flag = TransactionFlag.PAID_TX

        return TxMessage(
            message_hash=tx_hash,
            network_num=network_num,
            source_id=source_id,
            short_id=short_id,
            tx_val=tx_val,
            transaction_flag=tx_flag,
            timestamp=ts
        )
コード例 #3
0
    def convert_to_older_version(
        self, msg: AbstractInternalMessage
    ) -> AbstractInternalMessage:
        msg_type = msg.MESSAGE_TYPE

        if msg_type != TxMessage.MESSAGE_TYPE:
            raise ValueError(
                f"Tried to convert unexpected new "
                f"message type to v17: {msg_type}"
            )

        msg = cast(TxMessage, msg)
        transaction_flag = msg.transaction_flag()

        if self.UNKNOWN_TRANSACTION_FLAGS & transaction_flag:
            transaction_flag &= self.INVERTED_UNKNOWN_TRANSACTION_FLAGS

        return TxMessageV17(
            msg.message_hash(),
            msg.network_num(),
            msg.source_id(),
            msg.short_id(),
            msg.tx_val(),
            transaction_flag,
            int(msg.timestamp())
        )
コード例 #4
0
    def convert_to_older_version(
            self, msg: AbstractInternalMessage) -> AbstractInternalMessage:
        msg_type = msg.MESSAGE_TYPE
        if msg_type not in self._MSG_TYPE_TO_OLD_MSG_CLASS_MAPPING:
            raise ValueError(
                f"Tried to convert unexpected new message type to v6: {msg_type}"
            )
        msg = cast(TxServiceSyncTxsMessage, msg)

        txs_content_short_ids = msg.txs_content_short_ids()
        txs_content_short_ids_v6 = [
            TxContentShortIdsV6(item.tx_hash, item.tx_content, item.short_ids)
            for item in txs_content_short_ids
        ]
        network_num = msg.network_num()

        return TxServiceSyncTxsMessageV6(network_num, txs_content_short_ids_v6)
コード例 #5
0
    def convert_from_older_version(
            self, msg: AbstractInternalMessage) -> AbstractInternalMessage:
        msg_type = msg.MESSAGE_TYPE

        if msg_type not in self._MSG_TYPE_TO_NEW_MSG_CLASS_MAPPING:
            raise ValueError(
                f"Tried to convert unexpected old message type to v6: {msg_type}"
            )
        msg = cast(TxServiceSyncTxsMessageV6, msg)

        txs_content_short_ids_v6 = msg.txs_content_short_ids()
        txs_content_short_ids = [
            TxContentShortIds(
                item.tx_hash, item.tx_content, item.short_ids,
                [TransactionFlag.NO_FLAGS for _ in item.short_ids])
            for item in txs_content_short_ids_v6
        ]
        network_num = msg.network_num()

        return TxServiceSyncTxsMessage(network_num, txs_content_short_ids)