1#![deny(clippy::pedantic)]
2#![allow(clippy::module_name_repetitions)]
3#![allow(clippy::must_use_candidate)]
4
5use std::collections::BTreeMap;
6
7use anyhow::bail;
8use async_trait::async_trait;
9use fedimint_core::config::{
10 ConfigGenModuleParams, ServerModuleConfig, ServerModuleConsensusConfig,
11 TypedServerModuleConfig, TypedServerModuleConsensusConfig,
12};
13use fedimint_core::core::ModuleInstanceId;
14use fedimint_core::db::{DatabaseTransaction, DatabaseVersion};
15use fedimint_core::module::audit::Audit;
16use fedimint_core::module::{
17 ApiEndpoint, CORE_CONSENSUS_VERSION, CoreConsensusVersion, InputMeta, ModuleConsensusVersion,
18 ModuleInit, SupportedModuleApiVersions, TransactionItemAmount,
19};
20use fedimint_core::{InPoint, OutPoint, PeerId};
21use fedimint_server_core::config::PeerHandleOps;
22use fedimint_server_core::migration::ServerModuleDbMigrationFn;
23use fedimint_server_core::{ServerModule, ServerModuleInit, ServerModuleInitArgs};
24pub use fedimint_unknown_common as common;
25use fedimint_unknown_common::config::{
26 UnknownClientConfig, UnknownConfig, UnknownConfigConsensus, UnknownConfigPrivate,
27 UnknownGenParams,
28};
29use fedimint_unknown_common::{
30 MODULE_CONSENSUS_VERSION, UnknownCommonInit, UnknownConsensusItem, UnknownInput,
31 UnknownInputError, UnknownModuleTypes, UnknownOutput, UnknownOutputError, UnknownOutputOutcome,
32};
33pub mod db;
34
35#[derive(Debug, Clone)]
37pub struct UnknownInit;
38
39impl ModuleInit for UnknownInit {
41 type Common = UnknownCommonInit;
42
43 async fn dump_database(
45 &self,
46 _dbtx: &mut DatabaseTransaction<'_>,
47 _prefix_names: Vec<String>,
48 ) -> Box<dyn Iterator<Item = (String, Box<dyn erased_serde::Serialize + Send>)> + '_> {
49 Box::new(vec![].into_iter())
50 }
51}
52
53#[async_trait]
55impl ServerModuleInit for UnknownInit {
56 type Module = Unknown;
57 type Params = UnknownGenParams;
58
59 fn versions(&self, _core: CoreConsensusVersion) -> &[ModuleConsensusVersion] {
61 &[MODULE_CONSENSUS_VERSION]
62 }
63
64 fn supported_api_versions(&self) -> SupportedModuleApiVersions {
65 SupportedModuleApiVersions::from_raw(
66 (CORE_CONSENSUS_VERSION.major, CORE_CONSENSUS_VERSION.minor),
67 (
68 MODULE_CONSENSUS_VERSION.major,
69 MODULE_CONSENSUS_VERSION.minor,
70 ),
71 &[(0, 0)],
72 )
73 }
74
75 async fn init(&self, args: &ServerModuleInitArgs<Self>) -> anyhow::Result<Self::Module> {
77 Ok(Unknown::new(args.cfg().to_typed()?))
78 }
79
80 fn trusted_dealer_gen(
82 &self,
83 peers: &[PeerId],
84 params: &ConfigGenModuleParams,
85 ) -> BTreeMap<PeerId, ServerModuleConfig> {
86 let _params = self.parse_params(params).unwrap();
87 peers
89 .iter()
90 .map(|&peer| {
91 let config = UnknownConfig {
92 private: UnknownConfigPrivate,
93 consensus: UnknownConfigConsensus {},
94 };
95 (peer, config.to_erased())
96 })
97 .collect()
98 }
99
100 async fn distributed_gen(
102 &self,
103 _peers: &(dyn PeerHandleOps + Send + Sync),
104 params: &ConfigGenModuleParams,
105 ) -> anyhow::Result<ServerModuleConfig> {
106 let _params = self.parse_params(params).unwrap();
107
108 Ok(UnknownConfig {
109 private: UnknownConfigPrivate,
110 consensus: UnknownConfigConsensus {},
111 }
112 .to_erased())
113 }
114
115 fn get_client_config(
117 &self,
118 config: &ServerModuleConsensusConfig,
119 ) -> anyhow::Result<UnknownClientConfig> {
120 let _config = UnknownConfigConsensus::from_erased(config)?;
121 Ok(UnknownClientConfig {})
122 }
123
124 fn validate_config(
125 &self,
126 _identity: &PeerId,
127 _config: ServerModuleConfig,
128 ) -> anyhow::Result<()> {
129 Ok(())
130 }
131
132 fn get_database_migrations(
134 &self,
135 ) -> BTreeMap<DatabaseVersion, ServerModuleDbMigrationFn<Unknown>> {
136 let mut migrations: BTreeMap<DatabaseVersion, ServerModuleDbMigrationFn<_>> =
137 BTreeMap::new();
138 migrations.insert(DatabaseVersion(0), Box::new(|_| Box::pin(async { Ok(()) })));
141 migrations
142 }
143}
144
145#[derive(Debug)]
147pub struct Unknown {
148 pub cfg: UnknownConfig,
149}
150
151#[async_trait]
153impl ServerModule for Unknown {
154 type Common = UnknownModuleTypes;
156 type Init = UnknownInit;
157
158 async fn consensus_proposal(
159 &self,
160 _dbtx: &mut DatabaseTransaction<'_>,
161 ) -> Vec<UnknownConsensusItem> {
162 Vec::new()
163 }
164
165 async fn process_consensus_item<'a, 'b>(
166 &'a self,
167 _dbtx: &mut DatabaseTransaction<'b>,
168 _consensus_item: UnknownConsensusItem,
169 _peer_id: PeerId,
170 ) -> anyhow::Result<()> {
171 bail!("The unknown module does not use consensus items");
177 }
178
179 async fn process_input<'a, 'b, 'c>(
180 &'a self,
181 _dbtx: &mut DatabaseTransaction<'c>,
182 _input: &'b UnknownInput,
183 _in_point: InPoint,
184 ) -> Result<InputMeta, UnknownInputError> {
185 unreachable!();
186 }
187
188 async fn process_output<'a, 'b>(
189 &'a self,
190 _dbtx: &mut DatabaseTransaction<'b>,
191 _output: &'a UnknownOutput,
192 _out_point: OutPoint,
193 ) -> Result<TransactionItemAmount, UnknownOutputError> {
194 unreachable!();
195 }
196
197 async fn output_status(
198 &self,
199 _dbtx: &mut DatabaseTransaction<'_>,
200 _out_point: OutPoint,
201 ) -> Option<UnknownOutputOutcome> {
202 unreachable!()
203 }
204
205 async fn audit(
206 &self,
207 _dbtx: &mut DatabaseTransaction<'_>,
208 _audit: &mut Audit,
209 _module_instance_id: ModuleInstanceId,
210 ) {
211 }
212
213 fn api_endpoints(&self) -> Vec<ApiEndpoint<Self>> {
214 Vec::new()
215 }
216}
217
218impl Unknown {
219 pub fn new(cfg: UnknownConfig) -> Unknown {
221 Unknown { cfg }
222 }
223}