mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-01 17:01:10 +03:00
Deprecate HTTP(S) (#532)
* Deprecate HTTP(S) * Remove http support altogether
This commit is contained in:
parent
de6a6ad19f
commit
429db61bb7
7 changed files with 11 additions and 139 deletions
|
@ -2324,7 +2324,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// attempt to send slate synchronously, starting with TOR and downgrading to HTTP
|
/// attempt to send slate synchronously with TOR
|
||||||
pub fn try_slatepack_sync_workflow(
|
pub fn try_slatepack_sync_workflow(
|
||||||
slate: &Slate,
|
slate: &Slate,
|
||||||
dest: &str,
|
dest: &str,
|
||||||
|
@ -2355,7 +2355,7 @@ pub fn try_slatepack_sync_workflow(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// First, try TOR
|
// Try parsing Slatepack address
|
||||||
match SlatepackAddress::try_from(dest) {
|
match SlatepackAddress::try_from(dest) {
|
||||||
Ok(address) => {
|
Ok(address) => {
|
||||||
let tor_addr = OnionV3Address::try_from(&address).unwrap();
|
let tor_addr = OnionV3Address::try_from(&address).unwrap();
|
||||||
|
@ -2392,34 +2392,18 @@ pub fn try_slatepack_sync_workflow(
|
||||||
Ok(_) => return Ok(Some(ret_slate)),
|
Ok(_) => return Ok(Some(ret_slate)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("Unable to send via TOR: {}", e);
|
debug!("Unable to send via TOR: {}", e);
|
||||||
warn!("Unable to send transaction via TOR. Attempting alternate methods.");
|
warn!("Unable to send transaction via TOR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("Send (TOR): Destination is not SlatepackAddress {:?}", e);
|
debug!("Send (TOR): Destination is not SlatepackAddress {:?}", e);
|
||||||
|
warn!("Destination is not a valid Slatepack address. Will output Slatepack.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try Fallback to HTTP for deprecation period
|
Ok(None)
|
||||||
match HttpSlateSender::new(&dest) {
|
|
||||||
Ok(sender) => {
|
|
||||||
println!("Attempting to send transaction via HTTP (deprecated)");
|
|
||||||
match send_sync(sender, "HTTP") {
|
|
||||||
Ok(_) => return Ok(Some(ret_slate)),
|
|
||||||
Err(e) => {
|
|
||||||
debug!("Unable to send via HTTP: {}", e);
|
|
||||||
warn!("Unable to send transaction via HTTP. Will output Slatepack.");
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
debug!("Send (HTTP): Cannot create HTTP Slate sender {:?}", e);
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|
|
@ -26,9 +26,6 @@ use crate::util::logger::LoggingConfig;
|
||||||
pub struct WalletConfig {
|
pub struct WalletConfig {
|
||||||
/// Chain parameters (default to Mainnet if none at the moment)
|
/// Chain parameters (default to Mainnet if none at the moment)
|
||||||
pub chain_type: Option<ChainTypes>,
|
pub chain_type: Option<ChainTypes>,
|
||||||
/// The api interface/ip_address that this api server (i.e. this wallet) will run
|
|
||||||
/// by default this is 127.0.0.1 (and will not accept connections from external clients)
|
|
||||||
pub api_listen_interface: String,
|
|
||||||
/// The port this wallet will run on
|
/// The port this wallet will run on
|
||||||
pub api_listen_port: u16,
|
pub api_listen_port: u16,
|
||||||
/// The port this wallet's owner API will run on
|
/// The port this wallet's owner API will run on
|
||||||
|
@ -62,7 +59,6 @@ impl Default for WalletConfig {
|
||||||
fn default() -> WalletConfig {
|
fn default() -> WalletConfig {
|
||||||
WalletConfig {
|
WalletConfig {
|
||||||
chain_type: Some(ChainTypes::Mainnet),
|
chain_type: Some(ChainTypes::Mainnet),
|
||||||
api_listen_interface: "127.0.0.1".to_string(),
|
|
||||||
api_listen_port: 3415,
|
api_listen_port: 3415,
|
||||||
owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()),
|
owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()),
|
||||||
api_secret_path: Some(".owner_api_secret".to_string()),
|
api_secret_path: Some(".owner_api_secret".to_string()),
|
||||||
|
@ -82,7 +78,7 @@ impl Default for WalletConfig {
|
||||||
impl WalletConfig {
|
impl WalletConfig {
|
||||||
/// API Listen address
|
/// API Listen address
|
||||||
pub fn api_listen_addr(&self) -> String {
|
pub fn api_listen_addr(&self) -> String {
|
||||||
format!("{}:{}", self.api_listen_interface, self.api_listen_port)
|
format!("127.0.0.1:{}", self.api_listen_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default listener port
|
/// Default listener port
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub struct HttpSlateSender {
|
||||||
|
|
||||||
impl HttpSlateSender {
|
impl HttpSlateSender {
|
||||||
/// Create, return Err if scheme is not "http"
|
/// Create, return Err if scheme is not "http"
|
||||||
pub fn new(base_url: &str) -> Result<HttpSlateSender, SchemeNotHttp> {
|
fn new(base_url: &str) -> Result<HttpSlateSender, SchemeNotHttp> {
|
||||||
if !base_url.starts_with("http") && !base_url.starts_with("https") {
|
if !base_url.starts_with("http") && !base_url.starts_with("https") {
|
||||||
Err(SchemeNotHttp)
|
Err(SchemeNotHttp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,9 +22,8 @@ pub use self::http::{HttpSlateSender, SchemeNotHttp};
|
||||||
pub use self::keybase::{KeybaseAllChannels, KeybaseChannel};
|
pub use self::keybase::{KeybaseAllChannels, KeybaseChannel};
|
||||||
pub use self::slatepack::PathToSlatepack;
|
pub use self::slatepack::PathToSlatepack;
|
||||||
|
|
||||||
use crate::config::{TorConfig, WalletConfig};
|
use crate::config::WalletConfig;
|
||||||
use crate::libwallet::{Error, ErrorKind, Slate};
|
use crate::libwallet::{Error, Slate};
|
||||||
use crate::tor::config::complete_tor_address;
|
|
||||||
use crate::util::ZeroingString;
|
use crate::util::ZeroingString;
|
||||||
|
|
||||||
/// Sends transactions to a corresponding SlateReceiver
|
/// Sends transactions to a corresponding SlateReceiver
|
||||||
|
@ -59,64 +58,3 @@ pub trait SlateGetter {
|
||||||
/// Returns (Slate, whether it was in binary form)
|
/// Returns (Slate, whether it was in binary form)
|
||||||
fn get_tx(&self) -> Result<(Slate, bool), Error>;
|
fn get_tx(&self) -> Result<(Slate, bool), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// select a SlateSender based on method and dest fields from, e.g., SendArgs
|
|
||||||
pub fn create_sender(
|
|
||||||
method: &str,
|
|
||||||
dest: &str,
|
|
||||||
tor_config: Option<TorConfig>,
|
|
||||||
) -> Result<Box<dyn SlateSender>, Error> {
|
|
||||||
let invalid = || {
|
|
||||||
ErrorKind::WalletComms(format!(
|
|
||||||
"Invalid wallet comm type and destination. method: {}, dest: {}",
|
|
||||||
method, dest
|
|
||||||
))
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut method = method;
|
|
||||||
|
|
||||||
// will test if this is a tor address and fill out
|
|
||||||
// the http://[].onion if missing
|
|
||||||
let dest = match complete_tor_address(dest) {
|
|
||||||
Ok(d) => {
|
|
||||||
method = "tor";
|
|
||||||
d
|
|
||||||
}
|
|
||||||
Err(_) => dest.into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(match method {
|
|
||||||
"http" => Box::new(HttpSlateSender::new(&dest).map_err(|_| invalid())?),
|
|
||||||
"tor" => match tor_config {
|
|
||||||
None => {
|
|
||||||
return Err(
|
|
||||||
ErrorKind::WalletComms("Tor Configuration required".to_string()).into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Some(tc) => Box::new(
|
|
||||||
HttpSlateSender::with_socks_proxy(&dest, &tc.socks_proxy_addr, &tc.send_config_dir)
|
|
||||||
.map_err(|_| invalid())?,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"keybase" => Box::new(KeybaseChannel::new(dest)?),
|
|
||||||
"self" => {
|
|
||||||
return Err(ErrorKind::WalletComms(
|
|
||||||
"No sender implementation for \"self\".".to_string(),
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
"file" => {
|
|
||||||
return Err(ErrorKind::WalletComms(
|
|
||||||
"File based transactions must be performed asynchronously.".to_string(),
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(ErrorKind::WalletComms(format!(
|
|
||||||
"Wallet comm method \"{}\" does not exist.",
|
|
||||||
method
|
|
||||||
))
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ pub mod test_framework;
|
||||||
pub mod tor;
|
pub mod tor;
|
||||||
|
|
||||||
pub use crate::adapters::{
|
pub use crate::adapters::{
|
||||||
create_sender, HttpSlateSender, KeybaseAllChannels, KeybaseChannel, PathToSlate,
|
HttpSlateSender, KeybaseAllChannels, KeybaseChannel, PathToSlate, PathToSlatepack, SlateGetter,
|
||||||
PathToSlatepack, SlateGetter, SlatePutter, SlateReceiver, SlateSender,
|
SlatePutter, SlateReceiver, SlateSender,
|
||||||
};
|
};
|
||||||
pub use crate::backends::{wallet_db_exists, LMDBBackend};
|
pub use crate::backends::{wallet_db_exists, LMDBBackend};
|
||||||
pub use crate::error::{Error, ErrorKind};
|
pub use crate::error::{Error, ErrorKind};
|
||||||
|
|
|
@ -27,11 +27,6 @@ args:
|
||||||
short: t
|
short: t
|
||||||
long: top_level_dir
|
long: top_level_dir
|
||||||
takes_value: true
|
takes_value: true
|
||||||
- external:
|
|
||||||
help: Listen on 0.0.0.0 interface to allow external connections (default is 127.0.0.1)
|
|
||||||
short: e
|
|
||||||
long: external
|
|
||||||
takes_value: false
|
|
||||||
- show_spent:
|
- show_spent:
|
||||||
help: Show spent outputs on wallet output commands
|
help: Show spent outputs on wallet output commands
|
||||||
short: s
|
short: s
|
||||||
|
|
|
@ -219,39 +219,6 @@ fn prompt_pay_invoice(slate: &Slate, dest: &str) -> Result<bool, ParseError> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prompt_deprecate_http() -> Result<bool, ParseError> {
|
|
||||||
let interface = Arc::new(Interface::new("http")?);
|
|
||||||
interface.set_report_signal(Signal::Interrupt, true);
|
|
||||||
interface.set_prompt("To proceed, type 'UNDERSTOOD' > ")?;
|
|
||||||
println!();
|
|
||||||
println!("Http(s) is being deprecated in favour of the Slatepack Workflow");
|
|
||||||
println!("This sending method is planned for removal as of the last scheduled Hardfork in Grin 5.0.0");
|
|
||||||
println!("Please see https://github.com/mimblewimble/grin-rfcs/pull/55 for details");
|
|
||||||
loop {
|
|
||||||
let res = interface.read_line()?;
|
|
||||||
match res {
|
|
||||||
ReadResult::Eof => return Ok(false),
|
|
||||||
ReadResult::Signal(sig) => {
|
|
||||||
if sig == Signal::Interrupt {
|
|
||||||
interface.cancel_read_line()?;
|
|
||||||
return Err(ParseError::CancelledError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ReadResult::Input(line) => match line.trim() {
|
|
||||||
"Q" | "q" => return Err(ParseError::CancelledError),
|
|
||||||
result => {
|
|
||||||
if result == "UNDERSTOOD" {
|
|
||||||
return Ok(true);
|
|
||||||
} else {
|
|
||||||
println!("Please enter the phrase 'UNDERSTOOD' (without quotes) to continue or Q to quit");
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// instantiate wallet (needed by most functions)
|
// instantiate wallet (needed by most functions)
|
||||||
|
|
||||||
pub fn inst_wallet<L, C, K>(
|
pub fn inst_wallet<L, C, K>(
|
||||||
|
@ -487,10 +454,6 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
|
||||||
None => "default",
|
None => "default",
|
||||||
};
|
};
|
||||||
|
|
||||||
if dest.to_uppercase().starts_with("HTTP") {
|
|
||||||
prompt_deprecate_http()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// change_outputs
|
// change_outputs
|
||||||
let change_outputs = parse_required(args, "change_outputs")?;
|
let change_outputs = parse_required(args, "change_outputs")?;
|
||||||
let change_outputs = parse_u64(change_outputs, "change_outputs")? as usize;
|
let change_outputs = parse_u64(change_outputs, "change_outputs")? as usize;
|
||||||
|
@ -962,10 +925,6 @@ where
|
||||||
>,
|
>,
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
if wallet_args.is_present("external") {
|
|
||||||
wallet_config.api_listen_interface = "0.0.0.0".to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(dir) = wallet_args.value_of("top_level_dir") {
|
if let Some(dir) = wallet_args.value_of("top_level_dir") {
|
||||||
wallet_config.data_file_dir = dir.to_string().clone();
|
wallet_config.data_file_dir = dir.to_string().clone();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue