blockchain_client/
client.rs1use serde::{Deserialize, Serialize};
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
5pub struct RpcConfig {
6 pub url: String,
7 pub username: String,
8 pub password: String,
9 pub timeout_secs: u64,
10}
11
12impl RpcConfig {
13 pub fn new(url: String, username: String, password: String) -> Self {
14 Self {
15 url,
16 username,
17 password,
18 timeout_secs: 30,
19 }
20 }
21
22 pub fn with_timeout(mut self, timeout_secs: u64) -> Self {
23 self.timeout_secs = timeout_secs;
24 self
25 }
26
27 pub fn timeout(&self) -> Duration {
28 Duration::from_secs(self.timeout_secs)
29 }
30}
31
32#[derive(Debug, Serialize)]
33pub struct JsonRpcRequest {
34 pub jsonrpc: String,
35 pub id: String,
36 pub method: String,
37 pub params: serde_json::Value,
38}
39
40impl JsonRpcRequest {
41 pub fn new(method: String, params: serde_json::Value) -> Self {
42 Self {
43 jsonrpc: "1.0".to_string(),
44 id: "blockchain-client".to_string(),
45 method,
46 params,
47 }
48 }
49}
50
51#[derive(Debug, Deserialize)]
52pub struct JsonRpcResponse<T> {
53 pub result: Option<T>,
54 pub error: Option<JsonRpcError>,
55 pub id: String,
56}
57
58#[derive(Debug, Deserialize)]
59pub struct JsonRpcError {
60 pub code: i32,
61 pub message: String,
62}