1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#![no_std]

#[cfg(feature = "mockall")]
#[cfg(not(target_arch = "wasm32"))]
extern crate std;

pub use hex::{self};
pub use prelude::*;
pub use spin::{self};

pub mod calls;
pub mod errors;
#[cfg(not(target_arch = "wasm32"))]
pub mod events;
#[cfg(not(target_arch = "wasm32"))]
pub mod gsdk;
pub mod gstd;
#[cfg(not(target_arch = "wasm32"))]
pub mod gtest;
#[cfg(feature = "mockall")]
#[cfg(not(target_arch = "wasm32"))]
pub mod mockall;
pub mod prelude;
mod types;

pub mod meta {
    use crate::Vec;
    use scale_info::MetaType;

    pub trait ServiceMeta {
        fn commands() -> MetaType;
        fn queries() -> MetaType;
        fn events() -> MetaType;
        fn base_services() -> impl Iterator<Item = AnyServiceMeta>;
    }

    pub struct AnyServiceMeta {
        commands: MetaType,
        queries: MetaType,
        events: MetaType,
        base_services: Vec<AnyServiceMeta>,
    }

    impl AnyServiceMeta {
        pub fn new<S: ServiceMeta>() -> Self {
            Self {
                commands: S::commands(),
                queries: S::queries(),
                events: S::events(),
                base_services: S::base_services().collect(),
            }
        }

        pub fn commands(&self) -> &MetaType {
            &self.commands
        }

        pub fn queries(&self) -> &MetaType {
            &self.queries
        }

        pub fn events(&self) -> &MetaType {
            &self.events
        }

        pub fn base_services(&self) -> impl Iterator<Item = &AnyServiceMeta> {
            self.base_services.iter()
        }
    }

    pub trait ProgramMeta {
        fn constructors() -> MetaType;
        fn services() -> impl Iterator<Item = (&'static str, AnyServiceMeta)>;
    }
}