1use fedimint_core::core::ModuleInstanceId;
2use fedimint_core::db::DatabaseTransaction;
34/// A transaction that acts as isolated for module code but can be accessed as a
5/// normal transaction in this crate.
6pub struct ClientSMDatabaseTransaction<'inner, 'parent> {
7 dbtx: &'inner mut DatabaseTransaction<'parent>,
8 module_instance: ModuleInstanceId,
9}
1011impl<'inner, 'parent> ClientSMDatabaseTransaction<'inner, 'parent> {
12pub fn new(
13 dbtx: &'inner mut DatabaseTransaction<'parent>,
14 module_instance: ModuleInstanceId,
15 ) -> Self {
16Self {
17 dbtx,
18 module_instance,
19 }
20 }
2122/// Returns the isolated database transaction for the module.
23pub fn module_tx(&mut self) -> DatabaseTransaction<'_> {
24self.dbtx
25 .to_ref_with_prefix_module_id(self.module_instance)
26 .0
27.into_nc()
28 }
2930/// Returns the non-isolated database transaction only accessible to the
31 /// client internal code. This is useful for submitting Fedimint
32 /// transactions from within state transitions.
33// TODO: We don't want the client module to call this directly, ideally this
34 // would be private, but after we've split fedimint-client-module and fedimint-client
35 // we need to make it public.
36#[doc(hidden)]
37pub fn global_tx(&mut self) -> &mut DatabaseTransaction<'parent> {
38self.dbtx
39 }
4041pub(crate) fn module_id(&self) -> ModuleInstanceId {
42self.module_instance
43 }
44}