a bit refactoring on wallet controller for issue_send_tx (#2280)

* a bit refactoring on wallet controller for issue_send_tx
This commit is contained in:
Gary Yu 2019-01-03 19:01:31 +08:00 committed by GitHub
parent 3092221997
commit 939f42ea56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 17 deletions

View file

@ -14,7 +14,6 @@
use crate::cmd::wallet_args; use crate::cmd::wallet_args;
use crate::config::GlobalWalletConfig; use crate::config::GlobalWalletConfig;
use crate::servers::start_webwallet_server;
use clap::ArgMatches; use clap::ArgMatches;
use grin_wallet::{self, HTTPNodeClient, WalletConfig, WalletSeed}; use grin_wallet::{self, HTTPNodeClient, WalletConfig, WalletSeed};
use std::path::PathBuf; use std::path::PathBuf;

View file

@ -67,6 +67,7 @@ impl Default for LoggingConfig {
use std::ops::Deref; use std::ops::Deref;
use zeroize::Zeroize; use zeroize::Zeroize;
/// Zeroing string, mainly useful for password
pub struct ZeroingString(String); pub struct ZeroingString(String);
impl Drop for ZeroingString { impl Drop for ZeroingString {

View file

@ -343,24 +343,22 @@ where
return Err(e); return Err(e);
} }
}; };
if args.method == "http" { let adapter = match args.method.as_ref() {
let adapter = HTTPWalletCommAdapter::new(); "http" => HTTPWalletCommAdapter::new(),
slate = adapter.send_tx_sync(&args.dest, &slate)?; "file" => FileWalletCommAdapter::new(),
api.tx_lock_outputs(&slate, lock_fn)?; "keybase" => KeybaseWalletCommAdapter::new(),
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); error!("unsupported payment method: {}", args.method);
return Err(ErrorKind::ClientCallback("unsupported payment 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)?;
}
Ok(slate) Ok(slate)
})) }))
} }