ckb_jsonrpc_types/terminal.rs
1use crate::{Capacity, Timestamp, Uint64};
2use ckb_types::U256;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Overview data structure aggregating system and mining information
7/// for the CKB-TUI Terminal module.
8#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
9pub struct Overview {
10 /// System information, including hardware and OS metrics.
11 pub sys: SysInfo,
12 /// Mining information, covering hash power, difficulty.
13 pub mining: MiningInfo,
14 /// Transaction pool information.
15 pub pool: TerminalPoolInfo,
16 /// Cells information.
17 pub cells: CellsInfo,
18 /// Network peer latency information.
19 pub network: NetworkInfo,
20 /// CKB node version.
21 ///
22 /// Example: "version": "0.34.0 (f37f598 2020-07-17)"
23 pub version: String,
24}
25
26/// System’s information.
27#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
28pub struct SysInfo {
29 /// global system information
30 pub global: Global,
31 /// Returns the total ckb CPU usage (in %).
32 /// Notice that it might be bigger than 100 if run on a multi-core machine.
33 pub cpu_usage: f32,
34 /// Returns number of bytes ckb read and written to disk.
35 pub disk_usage: DiskUsage,
36 /// Returns the memory ckb usage (in bytes).
37 pub memory: u64,
38 /// Returns the virtual memory usage (in bytes).
39 pub virtual_memory: u64,
40}
41
42/// Global system information
43#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
44pub struct Global {
45 /// Returns the RAM size in bytes.
46 pub total_memory: u64,
47 /// Returns the amount of used RAM in bytes.
48 pub used_memory: u64,
49 /// Returns “global” CPUs usage (aka the addition of all the CPUs).
50 pub global_cpu_usage: f32,
51 /// Returns disks information.
52 pub disks: Vec<Disk>,
53 /// Returns networks information.
54 pub networks: Vec<Network>,
55}
56
57/// Struct containing a disk information.
58#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
59pub struct Disk {
60 /// Returns the total disk size, in bytes.
61 pub total_space: u64,
62 /// Returns the available disk size, in bytes.
63 pub available_space: u64,
64 /// Returns true if the disk is removable.
65 pub is_removable: bool,
66}
67
68/// Struct containing read and written bytes.
69#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Default)]
70pub struct DiskUsage {
71 /// Total number of written bytes.
72 pub total_written_bytes: u64,
73 /// Number of written bytes since the last refresh.
74 pub written_bytes: u64,
75 /// Total number of read bytes.
76 pub total_read_bytes: u64,
77 /// Number of read bytes since the last refresh.
78 pub read_bytes: u64,
79}
80
81/// Getting volume of received and transmitted data.
82#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
83pub struct Network {
84 /// Returns network interface name
85 pub interface_name: String,
86 /// Returns the number of received bytes since the last refresh.
87 pub received: u64,
88 /// Returns the total number of received bytes.
89 pub total_received: u64,
90 /// Returns the number of transmitted bytes since the last refresh.
91 pub transmitted: u64,
92 /// Returns the total number of transmitted bytes.
93 pub total_transmitted: u64,
94}
95
96/// Mining information structure for the CKB-TUI Terminal module.
97#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
98pub struct MiningInfo {
99 /// Current network difficulty, represented as a U256 integer.
100 #[schemars(schema_with = "crate::json_schema::u256_json_schema")]
101 pub difficulty: U256,
102 /// Current network hash rate, represented as a U256 integer (in hashes per second).
103 /// This approximates the total computational power of the mining network.
104 #[schemars(schema_with = "crate::json_schema::u256_json_schema")]
105 pub hash_rate: U256,
106}
107
108/// Transaction pool information.
109#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
110pub struct TerminalPoolInfo {
111 /// Count of transactions in the pending state.
112 ///
113 /// The pending transactions must be proposed in a new block first.
114 pub pending: Uint64,
115 /// Count of transactions in the proposed state.
116 ///
117 /// The proposed transactions are ready to be committed in the new block after the block
118 /// `tip_hash`.
119 pub proposed: Uint64,
120 /// Count of orphan transactions.
121 ///
122 /// An orphan transaction has an input cell from the transaction which is neither in the chain
123 /// nor in the transaction pool.
124 pub orphan: Uint64,
125 /// Count of committing transactions.
126 ///
127 /// The Committing transactions refer to transactions that have been packaged into the
128 /// block_template and are awaiting mining into a block.
129 pub committing: Uint64,
130 /// Total count of recent reject transactions by pool
131 pub total_recent_reject_num: Uint64,
132 /// Total size of transactions bytes in the pool of all the different kinds of states (excluding orphan transactions).
133 pub total_tx_size: Uint64,
134 /// Total consumed VM cycles of all the transactions in the pool (excluding orphan transactions).
135 pub total_tx_cycles: Uint64,
136 /// Total limit on the size of transactions in the tx-pool
137 pub max_tx_pool_size: Uint64,
138 /// Last updated time. This is the Unix timestamp in milliseconds.
139 pub last_txs_updated_at: Timestamp,
140}
141
142/// Individual peer connection information.
143#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
144pub struct PeerInfo {
145 /// Unique identifier for peer
146 pub peer_id: usize,
147 /// Whether this is an outbound connection
148 pub is_outbound: bool,
149 /// Round-trip time in milliseconds for this peer (0 if not available)
150 pub latency_ms: Uint64,
151 /// Peer address
152 pub address: String,
153}
154
155/// Network peer latency information.
156#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
157pub struct NetworkInfo {
158 /// Total number of connected peers
159 pub connected_peers: Uint64,
160 /// Number of outbound connections
161 pub outbound_peers: Uint64,
162 /// Number of inbound connections
163 pub inbound_peers: Uint64,
164 /// List of individual peer information with their latencies
165 pub peers: Vec<PeerInfo>,
166}
167
168/// Cells information.
169#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
170pub struct CellsInfo {
171 /// estimate live cells total num
172 pub estimate_live_cells_num: Uint64,
173 /// The total occupied capacities currently in the CKB
174 pub total_occupied_capacities: Capacity,
175}
176
177impl Default for CellsInfo {
178 fn default() -> Self {
179 Self {
180 estimate_live_cells_num: 0u64.into(),
181 total_occupied_capacities: 0u64.into(),
182 }
183 }
184}
185
186impl Default for TerminalPoolInfo {
187 fn default() -> Self {
188 Self {
189 pending: 0u64.into(),
190 proposed: 0u64.into(),
191 orphan: 0u64.into(),
192 committing: 0u64.into(),
193 total_recent_reject_num: 0u64.into(),
194 total_tx_size: 0u64.into(),
195 total_tx_cycles: 0u64.into(),
196 max_tx_pool_size: 0u64.into(),
197 last_txs_updated_at: 0u64.into(),
198 }
199 }
200}
201
202impl Default for MiningInfo {
203 fn default() -> Self {
204 Self {
205 difficulty: U256::zero(),
206 hash_rate: U256::zero(),
207 }
208 }
209}
210
211impl Default for SysInfo {
212 fn default() -> Self {
213 Self {
214 global: Global::default(),
215 cpu_usage: 0.0,
216 memory: 0,
217 virtual_memory: 0,
218 disk_usage: DiskUsage::default(),
219 }
220 }
221}
222
223impl Default for Global {
224 fn default() -> Self {
225 Self {
226 total_memory: 0,
227 used_memory: 0,
228 global_cpu_usage: 0.0,
229 disks: Vec::new(),
230 networks: Vec::new(),
231 }
232 }
233}
234
235impl Default for PeerInfo {
236 fn default() -> Self {
237 Self {
238 peer_id: 0,
239 is_outbound: false,
240 latency_ms: 0u64.into(),
241 address: String::new(),
242 }
243 }
244}
245
246impl Default for NetworkInfo {
247 fn default() -> Self {
248 Self {
249 connected_peers: 0u64.into(),
250 outbound_peers: 0u64.into(),
251 inbound_peers: 0u64.into(),
252 peers: Vec::new(),
253 }
254 }
255}