Skip to main content

hotmint_api/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// JSON-RPC request
4#[derive(Debug, Deserialize)]
5pub struct RpcRequest {
6    pub method: String,
7    pub params: serde_json::Value,
8    pub id: u64,
9}
10
11/// JSON-RPC response
12#[derive(Debug, Serialize, Deserialize)]
13pub struct RpcResponse {
14    pub result: Option<serde_json::Value>,
15    pub error: Option<RpcError>,
16    pub id: u64,
17}
18
19#[derive(Debug, Serialize, Deserialize)]
20pub struct RpcError {
21    pub code: i32,
22    pub message: String,
23}
24
25impl RpcResponse {
26    pub fn ok(id: u64, result: serde_json::Value) -> Self {
27        Self {
28            result: Some(result),
29            error: None,
30            id,
31        }
32    }
33
34    pub fn err(id: u64, code: i32, message: String) -> Self {
35        Self {
36            result: None,
37            error: Some(RpcError { code, message }),
38            id,
39        }
40    }
41}
42
43/// Consensus status info
44#[derive(Debug, Clone, Serialize)]
45pub struct StatusInfo {
46    pub validator_id: u64,
47    pub current_view: u64,
48    pub last_committed_height: u64,
49    pub epoch: u64,
50    pub validator_count: usize,
51    pub mempool_size: usize,
52}
53
54/// Block info returned by get_block / get_block_by_hash
55#[derive(Debug, Serialize)]
56pub struct BlockInfo {
57    pub height: u64,
58    pub hash: String,
59    pub parent_hash: String,
60    pub view: u64,
61    pub proposer: u64,
62    pub payload_size: usize,
63}
64
65/// Validator info returned by get_validators
66#[derive(Debug, Serialize)]
67pub struct ValidatorInfoResponse {
68    pub id: u64,
69    pub power: u64,
70    pub public_key: String,
71}
72
73/// Epoch info returned by get_epoch
74#[derive(Debug, Serialize)]
75pub struct EpochInfo {
76    pub number: u64,
77    pub start_view: u64,
78    pub validator_count: usize,
79}
80
81/// Transaction submission result
82#[derive(Debug, Serialize)]
83pub struct TxResult {
84    pub accepted: bool,
85}