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_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 " f"message type to v15: {msg_type}" ) msg = cast(TxMessage, 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() return TxMessageV15( message_hash=tx_hash, network_num=network_num, source_id=source_id, short_id=short_id, tx_val=tx_val, quota_type=quota_type, timestamp=ts )