mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 15:21:39 +02:00
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:
+73
-43
@@ -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)?;
|
||||
|
||||
|
||||
+21
-16
@@ -339,23 +339,28 @@ fn owner_v3_lifecycle() -> Result<(), grin_wallet_controller::Error> {
|
||||
let mut slate: Slate = res.unwrap().into();
|
||||
|
||||
// give this slate over to wallet 2 manually
|
||||
grin_wallet_controller::controller::owner_single_use(wallet2.clone(), mask2, |api, m| {
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let res = api.process_invoice_tx(m, &slate, args);
|
||||
assert!(res.is_ok());
|
||||
slate = res.unwrap();
|
||||
api.tx_lock_outputs(m, &slate, 0)?;
|
||||
grin_wallet_controller::controller::owner_single_use(
|
||||
Some(wallet2.clone()),
|
||||
mask2,
|
||||
None,
|
||||
|api, m| {
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let res = api.process_invoice_tx(m, &slate, args);
|
||||
assert!(res.is_ok());
|
||||
slate = res.unwrap();
|
||||
api.tx_lock_outputs(m, &slate, 0)?;
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
//16) Finalize the invoice tx (to foreign api)
|
||||
// (Tests that foreign API on same port also has its stored mask updated)
|
||||
|
||||
Reference in New Issue
Block a user