7 releases

0.1.7 Aug 31, 2023
0.1.6 Aug 30, 2023

#62 in #json-rpc

MIT license

15KB
220 lines

ajsonrpc

Sssumes that the resp from the node is

  • valid json
  • has a id field
  • the id field is encoded as such: "1" (string)

You shouldn't have a problem with this as long as your doing things correctly

You also should not drop the oneshot Reciever if using the send() function.

example benchmark comparing ajsonrpc with the web3 library.
Ran on a Ryzen 5 26000x and geth was on a Ryzen 9 5950x. All requests were eth_syncing requests.

1 million requests were made concurrently.

ajsonrpc web3
36.1s 72.7s

ajsonrpc is 2.1x faster than web3 in this case.

100 concurrent requests:

ajsonrpc web3 http (reqwests)
3.1792ms 5.5222ms 20.674ms

"normal" http requests are 8x slower than ajsonrpc

Usage

Add this to your Cargo.toml:

[dependencies]
ajsonrpc = "0.1.0"

Example

use ajsonrpc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    
    let router = ajsonrpc::WsRouter::new("ws://192.168.86.109:8546".to_string()).await?;

    let id = 1;

    let resp = router.make_request(format!(r#"{{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":"{}"}}"#, id), id).await?;

    println!("Response: {:?}", resp);

    Ok(())
}

Dependencies

~9–23MB
~308K SLoC