wallet_adapter/
storage.rs1use std::{cell::RefCell, collections::HashMap, rc::Rc};
2
3use crate::Wallet;
4
5pub type StorageSchema = HashMap<blake3::Hash, Wallet>;
7
8pub type StorageType = Rc<RefCell<StorageSchema>>;
10
11#[derive(Default, PartialEq, Eq, Clone)]
13pub struct WalletStorage(StorageType);
14
15impl WalletStorage {
16 pub fn clone_inner(&self) -> StorageType {
18 Rc::clone(&self.0)
19 }
20
21 pub fn get_wallets(&self) -> Vec<Wallet> {
23 self.0.borrow().values().cloned().collect::<Vec<Wallet>>()
24 }
25
26 pub fn get_wallet(&self, wallet_name: &str) -> Option<Wallet> {
28 let storage_ref = self.0.borrow();
29 storage_ref
30 .get(&blake3::hash(wallet_name.to_lowercase().as_bytes()))
31 .cloned()
32 }
33}
34
35impl core::fmt::Debug for WalletStorage {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 write!(f, "{:?}", &*self.0.borrow())
38 }
39}