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 )
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)
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()) )