Wallet Interactive-mode, Part 1 (#295)

* cli addition to yml

* first experiments with CLI mode

* rustfmt

* modify owner_single_use to take optional instantiated API

* refactor command functions to take owner api instance

* modify commands to use single owner api instance

* add ability to pass customised message handler to API

* prevent update wallet attempt if wallet hasn't been opened

* fix output when internal updater is running

* add termion, use cli for status updates, remove logging output from CLI

* some attempts to clean up the command prompt and accomodate scanning intervals

* rework listener slightly to allow for cli mode, add close command

* remove termion dependency
This commit is contained in:
Yeastplume
2020-02-06 09:08:24 +00:00
committed by GitHub
parent 0ae921461c
commit 2d264db91a
28 changed files with 929 additions and 314 deletions
+73 -43
View File
@@ -151,10 +151,15 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
let (wallet1, mask1_i) =
instantiate_wallet(wallet_config1, client1.clone(), "password", "default")?;
let mask1 = (&mask1_i).as_ref();
grin_wallet_controller::controller::owner_single_use(wallet1.clone(), mask1, |api, m| {
api.set_active_account(m, "mining")?;
Ok(())
})?;
grin_wallet_controller::controller::owner_single_use(
Some(wallet1.clone()),
mask1,
None,
|api, m| {
api.set_active_account(m, "mining")?;
Ok(())
},
)?;
let mut bh = 10u64;
let _ =
@@ -234,16 +239,21 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
let mask1 = (&mask1_i).as_ref();
// Check our transaction log, should have 10 entries
grin_wallet_controller::controller::owner_single_use(wallet1.clone(), mask1, |api, m| {
api.set_active_account(m, "mining")?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
assert!(refreshed);
assert_eq!(txs.len(), bh as usize);
for t in txs {
assert!(t.kernel_excess.is_some());
}
Ok(())
})?;
grin_wallet_controller::controller::owner_single_use(
Some(wallet1.clone()),
mask1,
None,
|api, m| {
api.set_active_account(m, "mining")?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
assert!(refreshed);
assert_eq!(txs.len(), bh as usize);
for t in txs {
assert!(t.kernel_excess.is_some());
}
Ok(())
},
)?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 10, false);
bh += 10;
@@ -265,13 +275,18 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
)?;
let mask2 = (&mask2_i).as_ref();
grin_wallet_controller::controller::owner_single_use(wallet2.clone(), mask2, |api, m| {
api.set_active_account(m, "account_1")?;
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.amount_currently_spendable, 10_000_000_000);
Ok(())
})?;
grin_wallet_controller::controller::owner_single_use(
Some(wallet2.clone()),
mask2,
None,
|api, m| {
api.set_active_account(m, "account_1")?;
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.amount_currently_spendable, 10_000_000_000);
Ok(())
},
)?;
// Self-send to same account, using smallest strategy
let arg_vec = vec![
@@ -330,13 +345,18 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
)?;
let mask1 = (&mask1_i).as_ref();
grin_wallet_controller::controller::owner_single_use(wallet1.clone(), mask1, |api, m| {
api.set_active_account(m, "mining")?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
assert!(refreshed);
assert_eq!(txs.len(), bh as usize + 1);
Ok(())
})?;
grin_wallet_controller::controller::owner_single_use(
Some(wallet1.clone()),
mask1,
None,
|api, m| {
api.set_active_account(m, "mining")?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
assert!(refreshed);
assert_eq!(txs.len(), bh as usize + 1);
Ok(())
},
)?;
// Try using the self-send method, splitting up outputs for the fun of it
let arg_vec = vec![
@@ -371,13 +391,18 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
)?;
let mask1 = (&mask1_i).as_ref();
grin_wallet_controller::controller::owner_single_use(wallet1.clone(), mask1, |api, m| {
api.set_active_account(m, "mining")?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
assert!(refreshed);
assert_eq!(txs.len(), bh as usize + 2);
Ok(())
})?;
grin_wallet_controller::controller::owner_single_use(
Some(wallet1.clone()),
mask1,
None,
|api, m| {
api.set_active_account(m, "mining")?;
let (refreshed, txs) = api.retrieve_txs(m, true, None, None)?;
assert!(refreshed);
assert_eq!(txs.len(), bh as usize + 2);
Ok(())
},
)?;
// Another file exchange, don't send, but unlock with repair command
let arg_vec = vec![
@@ -507,14 +532,19 @@ fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::
// get tx output via -tx parameter
let mut tx_id = "".to_string();
grin_wallet_controller::controller::owner_single_use(wallet2.clone(), mask2, |api, m| {
api.set_active_account(m, "default")?;
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let some_tx_id = txs[0].tx_slate_id.clone();
assert!(some_tx_id.is_some());
tx_id = some_tx_id.unwrap().to_hyphenated().to_string().clone();
Ok(())
})?;
grin_wallet_controller::controller::owner_single_use(
Some(wallet2.clone()),
mask2,
None,
|api, m| {
api.set_active_account(m, "default")?;
let (_, txs) = api.retrieve_txs(m, true, None, None)?;
let some_tx_id = txs[0].tx_slate_id.clone();
assert!(some_tx_id.is_some());
tx_id = some_tx_id.unwrap().to_hyphenated().to_string().clone();
Ok(())
},
)?;
let arg_vec = vec!["grin-wallet", "-p", "password", "txs", "-t", &tx_id[..]];
execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?;