Skip to content

Subscriptions just returns None (no error) - manual tokio_tungstenite works fine #1142

Open
@chikko80

Description

@chikko80

I am trying to connect to a jsonrpc websocket with your library but it doesn't work.
The strange thing is that every other library including manual implementation with tokio-tokio_tungstenite works absolutely fine.
Even a simple wscat via terminal works without any problems.

from stream.next().await i always get just a None - there is no error.
Seems like the connection gets successfully established but then there is just nothing to receive. Even if I loop the stream.next().await for 1 minute i never receive anything.
Super confused cause its just with jsonrpsee which would totally fit for my use case.

Is anyone familiar with that problem or has an idea how to solve that?

    #[tokio::test]
    async fn test_jsonrpsee() {
        let mut headers = HeaderMap::new();
        let bx_auth_header = "<bloxroute-auth-token>";
        headers.insert("Authorization", bx_auth_header.parse().unwrap());

        let ws_client = WsClientBuilder::default().set_headers(headers);

        let client = ws_client
            .build("wss://api.blxrbdn.com:443/ws")
            .await
            .unwrap();
        dbg!(&client);

        // let bx_params = BxParams::default();
        // dbg!(bx_params.clone().to_rpc_params());
        let params = rpc_params!["newTxs", doc! {"include": vec!["tx_hash"]}];

        let mut stream: Subscription<String> = client
            .subscribe("subscribe", params, "unsubscribe")
            .await
            .unwrap();

        tokio::time::sleep(Duration::from_secs(1)).await;

        dbg!(&stream);
        dbg!(stream.next().await);
    }

    #[tokio::test]
    async fn test_manual_impl() {
        let request_text = r#"{
            "jsonrpc": "2.0",
            "id": 0,
            "method": "subscribe",
            "params": ["newTxs", {"include": ["tx_hash"]}]
        }"#;

        // Generate a random Sec-WebSocket-Key
        let key = base64::encode("secret-key");

        let request = Request::get("wss://api.blxrbdn.com:443/ws")
            .header("Host", "api.blxrbdn.com:443")
            .header("Authorization", "<bloxroute-auth-token>")
            .header("Sec-WebSocket-Key", key)
            .header("Connection", "Upgrade")
            .header("Upgrade", "websocket")
            .header("Sec-WebSocket-Version", "13")
            .body(())
            .unwrap();

        let (mut ws_stream, _) = connect_async(request).await.expect("Failed to connect");

        ws_stream
            .send(Message::Text(request_text.to_string()))
            .await
            .expect("Failed to send a message");

        dbg!(ws_stream.next().await);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions