Skip to content

ws_receive/3 with format(json) sometimes does not yield JSON #84

@triska

Description

@triska

To reproduce with SWI-Prolog 7.5.1, please run the following query:

?- use_module(library(http/websocket)).
true.

Followed by:

?- http_open_websocket('wss://ws.blockchain.info/inv', WS, []),
   ws_send(WS, json(_{op: "unconfirmed_sub"})),
   length(_, L),
      portray_clause(L),
      ws_receive(WS, Msg, [format(json)]),
      \+ is_dict(Msg.data).

The output from this may vary between runs, but inevitably starts and ends like this:

0.
1.
2.
3.
4.
5.
...
53.
54.
WS = (0x7f801a8270d0,0x7f801a825620),
L = 54,
Msg = websocket{data:"{\n  \"op\" : \"utx\",\n  \"x\" : {\n    \"lock_time\" : 0,\n    \"ver\" : 1,\n    \"size\" : 226,\n    \"inputs\" : [ {\n      \"sequence\" : 4294967295,\n      \"prev_out\" : {\n        \"spent\" : true,\n        \"tx_index\" : 234701988,\n        \"type\" : 0,\n        \"addr\" : \"14Wa44aAqRGpcgv1dgCU1fRHvrqW9eMZ4m\",\n        \"value\" : 25000000,\n        \"n\" : 0,\n        \"script\" : \"76a914268008048d14e5e40f1cd819a3c11add1e6c408588ac\"\n      },\n      \"script\" : \"483045022100d48db67257037add65f06729de36e15e79994d69e2376b8cb1e1ae378fc67dde0220094681ac5415d359e87b8bdbd2ea188dd508a6c76553420d7f11601a9d3861e701210255b7e52913a13df6cdbe16ba8e3ed88a90511c25ac98a84ebdca00d11ab6c41a\"\n    } ],\n    \"time\" : 1490116499,\n    \"tx_index\" : 234709729,\n    \"vin_sz\" : 1,\n    \"hash\" : \"8576815930dcea2c67c8b1e8bdc0fab59f947605ffe6bc9163c35d699b3ede2a\",\n    \"vout_sz\" : 2,\n    \"relayed_by\" : \"217.111.66.79\",\n    \"out\" : [ {\n      \"spent\" : false,\n      \"tx_index\" : 234709729,\n      \"type\" : 0,\n      \"addr\" : \"12BLZjSiPxNcU6dfJNjrvT3YyJcRBBJL76\",\n      \"value\" : 12000000,\n      \"n\" : 0,\n      \"script\" : \"76a9140cec9dec93f2faa73fe1ed83329a1c5d080c5f9c88ac\"\n    }, {\n      \"spent\" : false,\n      \"tx_index\" : 234709729,\n      \"type\" : 0,\n      \"addr\" : \"15n13xT3vobHAWkm8hVuJrRby6qqqjRSK6\",\n      \"value\" : 12950300,\n      \"n\" : 1,\n      \"script\" : \"76a91434634392de4cbee99ff98d641ef8fcbfb721a57a88ac\"\n    } ]\n  }\n}", format:string, opcode:text} 

This shows that ws_receive/3 sometimes does not yield a JSON dict, even if format(json) is specified.

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