pallet_sidechain_rpc/types/
sidechain.rs

1//! Response types returned by RPC endpoints for Sidechain pallet
2
3use jsonrpsee::types::{ErrorObject, ErrorObjectOwned};
4use serde::{Deserialize, Serialize};
5use sp_core::offchain::Timestamp;
6use std::fmt::Debug;
7
8/// Response type of [crate::SidechainRpcApiServer::get_status]
9#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
10#[serde(rename_all = "camelCase")]
11pub struct GetStatusResponse {
12	/// Partner Chain epoch and slot information
13	pub sidechain: SidechainData,
14	/// Cardano main chain epoch and slot information
15	pub mainchain: MainchainData,
16}
17
18/// Data about current Partner Chain epoch and slot
19#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
20#[serde(rename_all = "camelCase")]
21pub struct SidechainData {
22	/// Current Partner Chain epoch number
23	pub epoch: u64,
24	/// Current Partner Chain slot number
25	#[cfg(feature = "legacy-slotapi-compat")]
26	pub slot: Option<u64>,
27	/// Timestamp of the next Partner Chain epoch start
28	pub next_epoch_timestamp: Timestamp,
29}
30
31/// Data about current Cardano main chain epoch and slot
32#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
33#[serde(rename_all = "camelCase")]
34pub struct MainchainData {
35	/// Current Cardano main chain epoch number
36	pub epoch: u32,
37	/// Current Cardano main chain slot number
38	pub slot: u64,
39	/// Timestamp of the next Cardano main chain epoch start
40	pub next_epoch_timestamp: Timestamp,
41}
42
43/// Error type returned by [crate::SidechainRpcApiServer::get_status]
44#[derive(Debug)]
45pub enum GetStatusRpcError {
46	/// Signals that the server could not convert Partner Chain slot number to timestamp
47	CannotConvertSidechainSlotToTimestamp,
48	/// Signals that the server could not convert a timestamp to Cardano main chain
49	CannotConvertTimestampToMainchainData,
50}
51
52impl From<GetStatusRpcError> for ErrorObjectOwned {
53	fn from(e: GetStatusRpcError) -> Self {
54		ErrorObject::owned::<u8>(-1, format!("{e:?}"), None)
55	}
56}