ogmios_client/
query_network.rs

1//! Queries that start with `queryNetwork/`.
2
3use crate::{OgmiosClient, OgmiosClientError, OgmiosParams, types::SlotLength};
4use fraction::Decimal;
5use serde::Deserialize;
6use serde_json::Value;
7use sidechain_domain::NetworkType;
8use std::collections::HashMap;
9
10/// Trait that defines the methods for querying the network.
11pub trait QueryNetwork {
12	#[allow(async_fn_in_trait)]
13	/// Returns the Shelley genesis configuration.
14	async fn shelley_genesis_configuration(
15		&self,
16	) -> Result<ShelleyGenesisConfigurationResponse, OgmiosClientError>;
17}
18
19impl<T: OgmiosClient> QueryNetwork for T {
20	async fn shelley_genesis_configuration(
21		&self,
22	) -> Result<ShelleyGenesisConfigurationResponse, OgmiosClientError> {
23		let mut params = HashMap::new();
24		params.insert("era", Value::String("shelley".to_string()));
25		self.request("queryNetwork/genesisConfiguration", OgmiosParams::ByName(params))
26			.await
27	}
28}
29
30#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
31#[serde(rename_all = "camelCase")]
32/// Represents the Shelley genesis configuration.
33pub struct ShelleyGenesisConfigurationResponse {
34	/// The network magic number.
35	pub network_magic: u32,
36	/// The network type.
37	pub network: NetworkType,
38	/// The security parameter.
39	pub security_parameter: u32,
40	/// The active slots coefficient.
41	#[serde(deserialize_with = "crate::types::parse_fraction_decimal")]
42	pub active_slots_coefficient: Decimal,
43	/// The epoch length.
44	pub epoch_length: u32,
45	/// The slot length.
46	pub slot_length: SlotLength,
47	/// The start time.
48	#[serde(deserialize_with = "time::serde::iso8601::deserialize")]
49	pub start_time: time::OffsetDateTime,
50}
51
52impl Default for ShelleyGenesisConfigurationResponse {
53	fn default() -> Self {
54		Self {
55			network_magic: Default::default(),
56			network: Default::default(),
57			security_parameter: Default::default(),
58			active_slots_coefficient: Default::default(),
59			epoch_length: Default::default(),
60			slot_length: Default::default(),
61			start_time: time::OffsetDateTime::from_unix_timestamp(0).unwrap(),
62		}
63	}
64}