From 939f42ea56f50f82a87c35e4cf890aabfe920748 Mon Sep 17 00:00:00 2001 From: Gary Yu Date: Thu, 3 Jan 2019 19:01:31 +0800 Subject: [PATCH] a bit refactoring on wallet controller for issue_send_tx (#2280) * a bit refactoring on wallet controller for issue_send_tx --- src/bin/cmd/wallet.rs | 1 - util/src/types.rs | 1 + wallet/src/controller.rs | 30 ++++++++++++++---------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/bin/cmd/wallet.rs b/src/bin/cmd/wallet.rs index dd21bdd66..069ae817a 100644 --- a/src/bin/cmd/wallet.rs +++ b/src/bin/cmd/wallet.rs @@ -14,7 +14,6 @@ use crate::cmd::wallet_args; use crate::config::GlobalWalletConfig; -use crate::servers::start_webwallet_server; use clap::ArgMatches; use grin_wallet::{self, HTTPNodeClient, WalletConfig, WalletSeed}; use std::path::PathBuf; diff --git a/util/src/types.rs b/util/src/types.rs index b0f78cef2..b5c792fef 100644 --- a/util/src/types.rs +++ b/util/src/types.rs @@ -67,6 +67,7 @@ impl Default for LoggingConfig { use std::ops::Deref; use zeroize::Zeroize; +/// Zeroing string, mainly useful for password pub struct ZeroingString(String); impl Drop for ZeroingString { diff --git a/wallet/src/controller.rs b/wallet/src/controller.rs index 4f9ea2667..c100c634a 100644 --- a/wallet/src/controller.rs +++ b/wallet/src/controller.rs @@ -343,23 +343,21 @@ where return Err(e); } }; - if args.method == "http" { - let adapter = HTTPWalletCommAdapter::new(); - slate = adapter.send_tx_sync(&args.dest, &slate)?; - api.tx_lock_outputs(&slate, lock_fn)?; + let adapter = match args.method.as_ref() { + "http" => HTTPWalletCommAdapter::new(), + "file" => FileWalletCommAdapter::new(), + "keybase" => KeybaseWalletCommAdapter::new(), + _ => { + error!("unsupported payment method: {}", args.method); + return Err(ErrorKind::ClientCallback("unsupported payment method"))?; + } + }; + // TODO: improve it: + // in case of keybase, the response might take 60s and leave the service hanging + slate = adapter.send_tx_sync(&args.dest, &slate)?; + api.tx_lock_outputs(&slate, lock_fn)?; + if args.method != "file" { api.finalize_tx(&mut slate)?; - } else if args.method == "file" { - let adapter = FileWalletCommAdapter::new(); - adapter.send_tx_async(&args.dest, &slate)?; - api.tx_lock_outputs(&slate, lock_fn)?; - } else if args.method == "keybase" { - let adapter = KeybaseWalletCommAdapter::new(); - slate = adapter.send_tx_sync(&args.dest, &slate)?; - api.tx_lock_outputs(&slate, lock_fn)?; - api.finalize_tx(&mut slate)?; - } else { - error!("unsupported payment method: {}", args.method); - return Err(ErrorKind::ClientCallback("unsupported payment method"))?; } Ok(slate) }))