Skip to content

Commit

Permalink
Add wallet store util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
karbyshev committed Apr 25, 2024
1 parent 06ad240 commit b16a38a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/sdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,41 @@ impl<U: WalletStorage> Wallet<U> {
self.utils.clone().load_in_mem(self)
}

fn into_store(self) -> Result<Store, LoadStoreError> {
if let Some(store) = self.store_in_mem {
// return in-memory wallet store
Ok(store)
} else {
// read wallet storage
self.utils.load_store_read_only()
}
}

fn get_store(&self) -> Result<Store, LoadStoreError> {
if let Some(ref store) = self.store_in_mem {
// return in-memory wallet store
Ok(store.clone())
} else {
// read wallet storage
self.utils.load_store_read_only()
}
}

fn update_store(
&mut self,
update: impl FnOnce(&mut Store),
) -> Result<(), LoadStoreError> {
if let Some(store) = &mut self.store_in_mem {
// update in-memory wallet store (e.g., for dry-run tx
// executions)
update(store);
Ok(())
} else {
// update wallet storage
self.utils.update_store(update)
}
}

/// Add validator data to the store
pub fn add_validator_data_atomic(
&mut self,
Expand Down

0 comments on commit b16a38a

Please sign in to comment.