1#![cfg_attr(not(feature = "std"), no_std)]
3#![deny(missing_docs)]
4
5use frame_support::pallet_prelude::Weight;
6use parity_scale_codec::{Decode, Encode};
7use scale_info::TypeInfo;
8use sidechain_domain::{ScEpochNumber, ScSlotNumber, UtxoId};
9
10#[cfg(test)]
11mod tests;
12
13#[deprecated(since = "1.7.0", note = "See deprecation notes for [GetSidechainStatus]")]
15#[derive(TypeInfo, Clone, Encode, Decode)]
16pub struct SidechainStatus {
17 pub epoch: ScEpochNumber,
19 pub slot: ScSlotNumber,
21 pub slots_per_epoch: u32,
23}
24
25pub trait OnNewEpoch {
29 fn on_new_epoch(old_epoch: ScEpochNumber, new_epoch: ScEpochNumber) -> Weight;
31}
32
33impl OnNewEpoch for () {
34 fn on_new_epoch(_old_epoch: ScEpochNumber, _new_epoch: ScEpochNumber) -> Weight {
35 Weight::zero()
36 }
37}
38
39macro_rules! on_new_epoch_tuple_impl {
40 ($first:ident, $($rest:ident),+) => {
41 impl<$first, $($rest),+> OnNewEpoch for ($first, $($rest),+)
42 where
43 $first: OnNewEpoch,
44 $($rest: OnNewEpoch),+
45 {
46 fn on_new_epoch(old_epoch: ScEpochNumber, new_epoch: ScEpochNumber) -> Weight {
47 <$first as OnNewEpoch>::on_new_epoch(old_epoch, new_epoch)
48 $(.saturating_add(<$rest as OnNewEpoch>::on_new_epoch(old_epoch, new_epoch)))+
49 }
50 }
51 };
52}
53on_new_epoch_tuple_impl!(A, B);
54on_new_epoch_tuple_impl!(A, B, C);
55on_new_epoch_tuple_impl!(A, B, C, D);
56
57#[allow(deprecated)]
58mod api_declarations {
59 use super::*;
60 sp_api::decl_runtime_apis! {
61 pub trait GetGenesisUtxo {
63 fn genesis_utxo() -> UtxoId;
65 }
66
67 #[deprecated(since = "1.7.0", note = "Code that needs this data should define its own runtime API instead.")]
69 pub trait GetSidechainStatus {
70 fn get_sidechain_status() -> SidechainStatus;
72 }
73 }
74}
75pub use api_declarations::*;
76
77#[cfg(feature = "std")]
79pub fn read_genesis_utxo_from_env_with_defaults() -> Result<UtxoId, envy::Error> {
80 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83 struct GenesisUtxoEnvConfiguration {
84 pub genesis_utxo: UtxoId,
85 }
86 let raw = envy::from_env::<GenesisUtxoEnvConfiguration>()?;
87 Ok(raw.genesis_utxo)
88}