pub fn create_sender(
	method: &str,
	dest: &str,
	apisecret: &Option<String>,
	tor_config: Option<TorConfig>,
) -> Result<Box<dyn SlateSender>, Error> {
	let invalid = |e| {
		ErrorKind::WalletComms(format!(
			"Invalid wallet comm type and destination. method: {}, dest: {}, error: {}",
			method, dest, e
		))
	};

	let method = if method=="http" {
		// Url might be onion. In this case we can update method to tor
		if validate_tor_address(dest).is_ok() {
			"tor"
		} else {
			method
		}
	}
	else {
		method
	};

	Ok(match method {
		"http" => Box::new(
			HttpDataSender::new(&dest, apisecret.clone(), None, false).map_err(|e| invalid(e))?,
		),
		"tor" => match tor_config {
			None => {
				return Err(
					ErrorKind::WalletComms("Tor Configuration required".to_string()).into(),
				);
			}
			Some(tc) => {
				let dest = validate_tor_address(dest)?;
				Box::new(
					HttpDataSender::with_socks_proxy(
						&dest,
						apisecret.clone(),
						&tc.socks_proxy_addr,
						Some(tc.send_config_dir),
						tc.socks_running,
					)
					.map_err(|e| invalid(e))?,
				)
			}
		},
		"keybase" => Box::new(KeybaseChannel::new(dest.to_string())),
		"mwcmqs" => Box::new(MwcMqsChannel::new(dest.to_string())),
		_ => {
			return Err(handle_unsupported_types(method));
		}
	})
}
/// select a SlateSender based on method and dest fields from, e.g., SendArgs
select a SlateSender based on method and dest fields from, e.g., SendArgs
select a SlateSender based on method and dest fields from e . g . SendArgs
pub fn create_sender(
	method: &str,
	dest: &str,
	apisecret: &Option<String>,
	tor_config: Option<TorConfig>,
) -> Result<Box<dyn SlateSender>, Error> {
	let invalid = |e| {
		ErrorKind::WalletComms(format!(
			"Invalid wallet comm type and destination. method: {}, dest: {}, error: {}",
			method, dest, e
		))
	};
	let method = if method=="http" {
		// Url might be onion. In this case we can update method to tor
		if validate_tor_address(dest).is_ok() {
			"tor"
		} else {
			method
		}
	}
	else {
		method
	};
	Ok(match method {
		"http" => Box::new(
			HttpDataSender::new(&dest, apisecret.clone(), None, false).map_err(|e| invalid(e))?,
		),
		"tor" => match tor_config {
			None => {
				return Err(
					ErrorKind::WalletComms("Tor Configuration required".to_string()).into(),
				);
			}
			Some(tc) => {
				let dest = validate_tor_address(dest)?;
				Box::new(
					HttpDataSender::with_socks_proxy(
						&dest,
						apisecret.clone(),
						&tc.socks_proxy_addr,
						Some(tc.send_config_dir),
						tc.socks_running,
					)
					.map_err(|e| invalid(e))?,
				)
			}
		},
		"keybase" => Box::new(KeybaseChannel::new(dest.to_string())),
		"mwcmqs" => Box::new(MwcMqsChannel::new(dest.to_string())),
		_ => {
			return Err(handle_unsupported_types(method));
		}
	})
}
pub fn create_sender ( method : & str , dest : & str , apisecret : & Option < String > , tor_config : Option < TorConfig > , ) -> Result < Box < dyn SlateSender > , Error > { let invalid = | e | { ErrorKind :: WalletComms ( format ! ( " " method dest e ) ) } ; let method = if method == " " { // Url might be onion. In this case we can update method to tor if validate_tor_address ( dest ) . is_ok ( ) { " " } else { method } } else { method } ; Ok ( match method { " " => Box :: new ( HttpDataSender :: new ( & dest , apisecret . clone ( ) , None , false ) . map_err ( | e | invalid ( e ) ) ? , ) , " " => match tor_config { None => { return Err ( ErrorKind :: WalletComms ( " " . to_string ( ) ) . into ( ) , ) ; } Some ( tc ) => { let dest = validate_tor_address ( dest ) ? ; Box :: new ( HttpDataSender :: with_socks_proxy ( & dest , apisecret . clone ( ) , & tc . socks_proxy_addr , Some ( tc . send_config_dir ) , tc . socks_running , ) . map_err ( | e | invalid ( e ) ) ? , ) } } , " " => Box :: new ( KeybaseChannel :: new ( dest . to_string ( ) ) ) , " " => Box :: new ( MwcMqsChannel :: new ( dest . to_string ( ) ) ) , _ => { return Err ( handle_unsupported_types ( method ) ) ; } } ) }
select a SlateSender based on method and dest fields from, e.g., SendArgs
select a SlateSender based on method and dest fields from e . g . SendArgs
method
&str
dest
&str
apisecret
&Option<String>
tor_config
Option<TorConfig>
method
&str
dest
&str
apisecret
&Option<String>
tor_config
Option<TorConfig>