// initialize a single wallet based on wallet storage strategy
initialize a single wallet based on wallet storage strategy
initialize a single wallet based on wallet storage strategy
fn create_wallet(&self, id: &str, config: &PostgresConfig, credentials: &PostgresCredentials, metadata: &[u8]) -> Result<(), 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);
        // insert metadata
        let url = PostgresStorageType::_postgres_url(wallet_db_name, &config, &credentials);
        let conn = match postgres::Connection::connect(&url[..], config.tls()) {
            Ok(conn) => conn,
            Err(error) => {
                return Err(WalletStorageError::IOError(format!("Error occurred while connecting to wallet schema: {}", error)));
            }
        };
        // We allow error on conflict since this indicates AlreadyExists error
        let ret = match conn.execute("INSERT INTO metadata(wallet_id, value) VALUES($1, $2)", &[&id, &metadata]) {
            Ok(_) => Ok(()),
            Err(error) => {
                if error.code() == Some(&postgres::error::UNIQUE_VIOLATION) {
                    Err(WalletStorageError::AlreadyExists)
                } else {
                    Err(WalletStorageError::IOError(format!("Error occurred while inserting into metadata: {}", error)))
                }
            }
        };
        conn.finish()?;
        ret
    }
fn create_wallet ( & self , id : & str , config : & PostgresConfig , credentials : & PostgresCredentials , metadata : & [ u8 ] ) -> Result < ( ) , 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 ) ; // insert metadata let url = PostgresStorageType :: _postgres_url ( wallet_db_name , & config , & credentials ) ; let conn = match postgres :: Connection :: connect ( & url [ .. ] , config . tls ( ) ) { Ok ( conn ) => conn , Err ( error ) => { return Err ( WalletStorageError :: IOError ( format ! ( " " error ) ) ) ; } } ; // We allow error on conflict since this indicates AlreadyExists error let ret = match conn . execute ( " " , & [ & id , & metadata ] ) { Ok ( _ ) => Ok ( ( ) ) , Err ( error ) => { if error . code ( ) == Some ( & postgres :: error :: UNIQUE_VIOLATION ) { Err ( WalletStorageError :: AlreadyExists ) } else { Err ( WalletStorageError :: IOError ( format ! ( " " error ) ) ) } } } ; conn . finish ( ) ? ; ret }
initialize a single wallet based on wallet storage strategy
initialize a single wallet based on wallet storage strategy
&self
id
&str
config
&PostgresConfig
credentials
&PostgresCredentials
metadata
&[u8]