avalanche_types/jsonrpc/
mod.rs1pub mod admin;
3pub mod avm;
4pub mod common;
5pub mod evm;
6pub mod health;
7pub mod info;
8pub mod platformvm;
9
10#[cfg(feature = "jsonrpc_client")]
11#[cfg_attr(docsrs, doc(cfg(feature = "jsonrpc_client")))]
12pub mod client;
13
14use std::{
15 collections::HashMap,
16 io::{self, Error, ErrorKind},
17};
18
19use serde::{Deserialize, Serialize};
20
21pub const DEFAULT_VERSION: &str = "2.0";
22pub const DEFAULT_ID: u32 = 1;
23
24#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
27pub struct Request {
28 pub jsonrpc: String,
29 pub id: u32,
30
31 pub method: String,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub params: Option<HashMap<String, String>>,
35}
36
37impl Default for Request {
38 fn default() -> Self {
39 Self {
40 jsonrpc: String::from(DEFAULT_VERSION),
41 id: DEFAULT_ID,
42 method: String::new(),
43 params: None,
44 }
45 }
46}
47
48impl Request {
49 pub fn encode_json(&self) -> io::Result<String> {
50 serde_json::to_string(&self)
51 .map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
52 }
53}
54
55#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
57pub struct RequestWithParamsArray {
58 pub jsonrpc: String,
59 pub id: u32,
60
61 pub method: String,
62
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub params: Option<Vec<String>>,
65}
66
67impl Default for RequestWithParamsArray {
68 fn default() -> Self {
69 Self {
70 jsonrpc: String::from(DEFAULT_VERSION),
71 id: DEFAULT_ID,
72 method: String::new(),
73 params: None,
74 }
75 }
76}
77
78impl RequestWithParamsArray {
79 pub fn encode_json(&self) -> io::Result<String> {
80 serde_json::to_string(&self)
81 .map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
82 }
83}
84
85#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
87pub struct RequestWithParamsHashMapArray {
88 pub jsonrpc: String,
89 pub id: u32,
90
91 pub method: String,
92
93 #[serde(skip_serializing_if = "Option::is_none")]
94 pub params: Option<Vec<HashMap<String, String>>>,
95}
96
97impl Default for RequestWithParamsHashMapArray {
98 fn default() -> Self {
99 Self {
100 jsonrpc: String::from(DEFAULT_VERSION),
101 id: DEFAULT_ID,
102 method: String::new(),
103 params: None,
104 }
105 }
106}
107
108impl RequestWithParamsHashMapArray {
109 pub fn encode_json(&self) -> io::Result<String> {
110 serde_json::to_string(&self)
111 .map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
112 }
113}
114
115#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
117pub struct RequestWithParamsHashMapToArray {
118 pub jsonrpc: String,
119 pub id: u32,
120
121 pub method: String,
122
123 #[serde(skip_serializing_if = "Option::is_none")]
124 pub params: Option<HashMap<String, Vec<String>>>,
125}
126
127impl Default for RequestWithParamsHashMapToArray {
128 fn default() -> Self {
129 Self {
130 jsonrpc: String::from(DEFAULT_VERSION),
131 id: DEFAULT_ID,
132 method: String::new(),
133 params: None,
134 }
135 }
136}
137
138impl RequestWithParamsHashMapToArray {
139 pub fn encode_json(&self) -> io::Result<String> {
140 serde_json::to_string(&self)
141 .map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
142 }
143}
144
145#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
148#[serde(rename_all = "camelCase")]
149pub struct EndIndex {
150 pub address: String,
151 pub utxo: String,
152}
153
154#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Default)]
157pub struct ResponseError {
158 pub code: i32,
159 pub message: String,
160
161 #[serde(skip_serializing_if = "Option::is_none")]
162 pub data: Option<String>,
163}