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::config::GlobalWalletConfig;
use crate::servers::start_webwallet_server;
use clap::ArgMatches;
use grin_wallet::{self, HTTPNodeClient, WalletConfig, WalletSeed};
use std::path::PathBuf;

View file

@ -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 {

View file

@ -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)
}))