jsonrpsee::rpc_api! {
Filecoin {
#[rpc(method = "Filecoin.ChainHead")]
fn chain_head() -> String;
}
}
fn main() {
let result : String = async_std::task::block_on(async move {
let transport =
jsonrpsee::transport::http::HttpTransportClient::new("http://lotus1:1234/rpc/v0");
let mut raw_client = jsonrpsee::raw::RawClient::new(transport);
let request_id = raw_client.start_request("Filecoin.ChainHead",
jsonrpsee::common::Params::None).await.unwrap();
println!("request_id={:?}",request_id);
let ret = jsonrpsee::common::from_value(
raw_client.request_by_id(request_id).unwrap().await.unwrap()
)
.unwrap();
println!("This line is never reached.");
return ret;
});
println!("result = {:?}", result); // also never reached
}
$ ./target/debug/indexer
request_id=RawClientRequestId(0)
Using tcpdump on the server, I can see that jsonrpsee is sending a correct query:
0x0030: 504f 5354 202f 7270 632f 7630 POST./rpc/v0
0x0040: 2048 5454 502f 312e 310d 0a63 6f6e 7465 .HTTP/1.1..conte
0x0050: 6e74 2d74 7970 653a 2061 7070 6c69 6361 nt-type:.applica
0x0060: 7469 6f6e 2f6a 736f 6e0d 0a68 6f73 743a tion/json..host:
0x0070: 206c 6f74 7573 313a 3132 3334 0d0a 636f .lotus1:1234..co
0x0080: 6e74 656e 742d 6c65 6e67 7468 3a20 3638 ntent-length:.68
0x0090: 0d0a 0d0a 7b22 6a73 6f6e 7270 6322 3a22 ....{"jsonrpc":"
0x00a0: 322e 3022 2c22 6d65 7468 6f64 223a 2246 2.0","method":"F
0x00b0: 696c 6563 6f69 6e2e 4368 6169 6e48 6561 ilecoin.ChainHea
0x00c0: 6422 2c22 7061 7261 6d73 223a 6e75 6c6c d","params":null
0x00d0: 2c22 6964 223a 307d ,"id":0}
4854 5450 2f31 2e31 2032 3030 HTTP/1.1.200
0x0040: 204f 4b0d 0a44 6174 653a 2053 6174 2c20 .OK..Date:.Sat,.
0x0050: 3131 204a 756c 2032 3032 3020 3034 3a35 11.Jul.2020.04:5
0x0060: 343a 3039 2047 4d54 0d0a 436f 6e74 656e 4:09.GMT..Conten
0x0070: 742d 5479 7065 3a20 7465 7874 2f70 6c61 t-Type:.text/pla
0x0080: 696e 3b20 6368 6172 7365 743d 7574 662d in;.charset=utf-
0x0090: 380d 0a54 7261 6e73 6665 722d 456e 636f 8..Transfer-Enco
0x00a0: 6469 6e67 3a20 6368 756e 6b65 640d 0a0d ding:.chunked...
0x00b0: 0a65 6264 0d0a 7b22 6a73 6f6e 7270 6322 .ebd..{"jsonrpc"
0x00c0: 3a22 322e 3022 2c22 7265 7375 6c74 223a :"2.0","result":
0x00d0: 7b22 4369 6473 223a 5b7b 222f 223a 2262 {"Cids":[{"/":"b
0x00e0: 6166 7932 627a 6163 6562 7733 6f37 6364 afy2bzacebw3o7cd
0x00f0: 3772 6373 6e66 6d6b 746e 6c76 6d6d 7468 7rcsnfmktnlvmmth
[...deleted...]
0x03c0: 6b37 5647 2b62 6b65 4d52 5847 6471 354c k7VG+bkeMRXGdq5L
0x03d0: 5472 4f36 5559 5369 4c32 7465 5237 5845 TrO6UYSiL2teR7XE
0x03e0: 3156 4943 6546 7a39 5732 6e56 3745 632b 1VICeFz9W2nV7Ec+
0x03f0: 5668 3739 227d 2c22 466f 726b 5369 676e Vh79"},"ForkSign
0x0400: 616c 696e 6722 3a30 7d5d 2c22 4865 6967 aling":0}],"Heig
0x0410: 6874 223a 3736 3733 377d 2c22 6964 223a ht":76737},"id":
0x0420: 307d 0}
I can't figure out why it's hanging. (The examples/polkadot.rs
and examples/http.rs
both work for me.)