// initialize storage based on wallet storage strategy
initialize storage based on wallet storage strategy
initialize storage based on wallet storage strategy
fn init_storage(&self, config: &PostgresConfig, credentials: &PostgresCredentials) -> Result<(), WalletStorageError> {
        debug!("Entering init_storage");
        // create database and tables for storage
        // if admin user and password aren't provided then bail
        debug!("Initializing storage strategy MultiWalletSingleTableStrategy.");
        if credentials.admin_account == None || credentials.admin_password == None {
            return Ok(());
        }
        debug!("setting up the admin_postgres_url");
        // 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_base = PostgresStorageType::_admin_postgres_url(&config, &credentials);
        let url = PostgresStorageType::_postgres_url(wallet_db_name, &config, &credentials);
        debug!("postgres_url: {:?}", url);
        debug!("connecting to postgres, url_base: {:?}", url_base);
        let conn = postgres::Connection::connect(&url_base[..], config.tls())?;
        debug!("creating wallets DB");
        let create_db_sql: String = str::replace(_CREATE_WALLET_DATABASE, "$1", wallet_db_name);
        debug!("create_db_sql: {:?}", create_db_sql);
        if let Err(error) = conn.execute(&create_db_sql, &[]) {
            if error.code() != Some(&postgres::error::DUPLICATE_DATABASE) {
                debug!("error creating database, Error: {}", error);
                conn.finish()?;
                return Err(WalletStorageError::IOError(format!("Error occurred while creating the database: {}", error)));
            } else {
                // if database already exists, assume tables are created already and return
                debug!("database already exists");
                conn.finish()?;
                return Ok(());
            }
        }
        conn.finish()?;
        debug!("connecting to wallet storage");
        let conn = match postgres::Connection::connect(&url[..], config.tls()) {
            Ok(conn) => conn,
            Err(error) => {
                debug!("error connecting to wallet storage, Error: {}", error);
                return Err(WalletStorageError::IOError(format!("Error occurred while connecting to wallet schema: {}", error)));
            }
        };
        debug!("setting up multi schema");
        for sql in &_CREATE_SCHEMA_MULTI {
            if let Err(error) = conn.execute(sql, &[]) {
                debug!("error creating wallet schema, Error: {}", error);
                conn.finish()?;
                return Err(WalletStorageError::IOError(format!("Error occurred while creating wallet schema: {}", error)));
            }
        }
        conn.finish()?;
        Ok(())
    }
fn init_storage ( & self , config : & PostgresConfig , credentials : & PostgresCredentials ) -> Result < ( ) , WalletStorageError > { debug ! ( " " ) ; // create database and tables for storage // if admin user and password aren't provided then bail debug ! ( " " ) ; if credentials . admin_account == None || credentials . admin_password == None { return Ok ( ( ) ) ; } debug ! ( " " ) ; // 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_base = PostgresStorageType :: _admin_postgres_url ( & config , & credentials ) ; let url = PostgresStorageType :: _postgres_url ( wallet_db_name , & config , & credentials ) ; debug ! ( " " url ) ; debug ! ( " " url_base ) ; let conn = postgres :: Connection :: connect ( & url_base [ .. ] , config . tls ( ) ) ? ; debug ! ( " " ) ; let create_db_sql : String = str :: replace ( _CREATE_WALLET_DATABASE , " " , wallet_db_name ) ; debug ! ( " " create_db_sql ) ; if let Err ( error ) = conn . execute ( & create_db_sql , & [ ] ) { if error . code ( ) != Some ( & postgres :: error :: DUPLICATE_DATABASE ) { debug ! ( " " error ) ; conn . finish ( ) ? ; return Err ( WalletStorageError :: IOError ( format ! ( " " error ) ) ) ; } else { // if database already exists, assume tables are created already and return debug ! ( " " ) ; conn . finish ( ) ? ; return Ok ( ( ) ) ; } } conn . finish ( ) ? ; debug ! ( " " ) ; let conn = match postgres :: Connection :: connect ( & url [ .. ] , config . tls ( ) ) { Ok ( conn ) => conn , Err ( error ) => { debug ! ( " " error ) ; return Err ( WalletStorageError :: IOError ( format ! ( " " error ) ) ) ; } } ; debug ! ( " " ) ; for sql in & _CREATE_SCHEMA_MULTI { if let Err ( error ) = conn . execute ( sql , & [ ] ) { debug ! ( " " error ) ; conn . finish ( ) ? ; return Err ( WalletStorageError :: IOError ( format ! ( " " error ) ) ) ; } } conn . finish ( ) ? ; Ok ( ( ) ) }
initialize storage based on wallet storage strategy
initialize storage based on wallet storage strategy
&self
config
&PostgresConfig
credentials
&PostgresCredentials