def insert_waiting_message(self, message: DeferableMessage) -> None: self.insert( "waiting_message", dict( token_network_address=to_checksum_address( message.canonical_identifier.token_network_address ), channel_id=hex256(message.canonical_identifier.channel_identifier), message=JSONSerializer.serialize(message), ), )
def pop_waiting_messages( self, token_network_address: TokenNetworkAddress, channel_id: ChannelID ) -> Iterator[DeferableMessage]: """Return all waiting messages for the given channel and delete them from the db""" # Return messages for row in self.conn.execute( """ SELECT message FROM waiting_message WHERE token_network_address = ? AND channel_id = ? """, [to_checksum_address(token_network_address), hex256(channel_id)], ): yield JSONSerializer.deserialize(row["message"]) # Delete returned messages self.conn.execute( "DELETE FROM waiting_message WHERE token_network_address = ? AND channel_id = ?", [to_checksum_address(token_network_address), hex256(channel_id)], )