// open a wallet based on wallet storage strategy
open a wallet based on wallet storage strategy
open a wallet based on wallet storage strategy
fn open_wallet(&self, id: &str, config: &PostgresConfig, credentials: &PostgresCredentials) -> Result<Box<PostgresStorage>, WalletStorageError> {
        // look to see if there is a specified db to use.  If not, use the default name
        let wallet_db_name: &str = get_multi_database_name(config);
        debug!("wallet_db_name: {:?}", wallet_db_name);
        let url = PostgresStorageType::_postgres_url(wallet_db_name, &config, &credentials);
        // don't need a connection, but connect just to verify we can
        let conn = match postgres::Connection::connect(&url[..], config.tls()) {
            Ok(conn) => conn,
            Err(_) => return Err(WalletStorageError::NotFound)
        };
        // select metadata for this wallet to ensure it exists
        let res: Result<Vec<u8>, WalletStorageError> = {
            let mut rows = conn.query(
                "SELECT value FROM metadata WHERE wallet_id = $1",
                &[&id]);
            match rows.as_mut().unwrap().iter().next() {
                Some(row) => Ok(row.get(0)),
                None => Err(WalletStorageError::ItemNotFound)
            }
        };
        match res {
            Ok(_entity) => (),
            Err(_) => return Err(WalletStorageError::NotFound)
        };
        // TODO close conn
        let manager = match PostgresConnectionManager::new(&url[..], config.r2d2_tls()) {
            Ok(manager) => manager,
            Err(_) => return Err(WalletStorageError::NotFound)
        };
        let pool = match r2d2::Pool::builder()
            .min_idle(Some(config.min_idle_count()))
            .max_size(config.max_connections())
            .idle_timeout(Some(Duration::new(config.connection_timeout(), 0)))
            .build(manager) {
            Ok(pool) => pool,
            Err(_) => return Err(WalletStorageError::NotFound)
        };
        Ok(Box::new(PostgresStorage {
            pool: pool,
            wallet_id: id.to_string(),
        }))
    }
fn open_wallet ( & self , id : & str , config : & PostgresConfig , credentials : & PostgresCredentials ) -> Result < Box < PostgresStorage > , WalletStorageError > { // look to see if there is a specified db to use.  If not, use the default name let wallet_db_name : & str = get_multi_database_name ( config ) ; debug ! ( " " wallet_db_name ) ; let url = PostgresStorageType :: _postgres_url ( wallet_db_name , & config , & credentials ) ; // don't need a connection, but connect just to verify we can let conn = match postgres :: Connection :: connect ( & url [ .. ] , config . tls ( ) ) { Ok ( conn ) => conn , Err ( _ ) => return Err ( WalletStorageError :: NotFound ) } ; // select metadata for this wallet to ensure it exists let res : Result < Vec < u8 > , WalletStorageError > = { let mut rows = conn . query ( " " , & [ & id ] ) ; match rows . as_mut ( ) . unwrap ( ) . iter ( ) . next ( ) { Some ( row ) => Ok ( row . get ( 0 ) ) , None => Err ( WalletStorageError :: ItemNotFound ) } } ; match res { Ok ( _entity ) => ( ) , Err ( _ ) => return Err ( WalletStorageError :: NotFound ) } ; // TODO close conn let manager = match PostgresConnectionManager :: new ( & url [ .. ] , config . r2d2_tls ( ) ) { Ok ( manager ) => manager , Err ( _ ) => return Err ( WalletStorageError :: NotFound ) } ; let pool = match r2d2 :: Pool :: builder ( ) . min_idle ( Some ( config . min_idle_count ( ) ) ) . max_size ( config . max_connections ( ) ) . idle_timeout ( Some ( Duration :: new ( config . connection_timeout ( ) , 0 ) ) ) . build ( manager ) { Ok ( pool ) => pool , Err ( _ ) => return Err ( WalletStorageError :: NotFound ) } ; Ok ( Box :: new ( PostgresStorage { pool : pool , wallet_id : id . to_string ( ) , } ) ) }
open a wallet based on wallet storage strategy
open a wallet based on wallet storage strategy
&self
id
&str
config
&PostgresConfig
credentials
&PostgresCredentials