1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use serde_json::Value;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClientRequest {
    id: u32,
    jsonrpc: String,
    method: String,
    params: Option<Value>,
}

impl ClientRequest {
    pub fn new(method: &str) -> Self {
        Self {
            id: 0,
            jsonrpc: "2.0".to_owned(),
            method: method.to_owned(),
            params: None,
        }
    }
    pub fn id(&mut self, id: u32) -> &mut ClientRequest {
        self.id = id;
        self
    }

    pub fn jsonrpc(&mut self, jsonrpc: &str) -> &mut ClientRequest {
        self.jsonrpc = jsonrpc.to_owned();
        self
    }

    pub fn params(&mut self, params: Value) -> &mut ClientRequest {
        self.params = Some(params);
        self
    }
}