Skip to content

Commit

Permalink
mwc-wallet cli mode doesn't respect global account argument. Fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Aug 30, 2024
1 parent 99ec6b4 commit af379e8
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 41 deletions.
4 changes: 2 additions & 2 deletions api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ where
///
/// // . . .
/// // Obtain a sent slate somehow
/// let result = api_foreign.receive_tx(&slate, None, None, None);
/// let result = api_foreign.receive_tx(&slate, None, &None, None);
///
/// if let Ok(slate) = result {
/// // Send back to recipient somehow
Expand All @@ -402,7 +402,7 @@ where
&self,
slate: &Slate,
address: Option<String>,
dest_acct_name: Option<&str>,
dest_acct_name: &Option<String>,
message: Option<String>,
) -> Result<Slate, Error> {
let mut w_lock = self.wallet_inst.lock();
Expand Down
2 changes: 1 addition & 1 deletion api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ where
self,
&slate_from,
sender.map(|p| ProvableAddress::from_tor_pub_key(&p).public_key), // We don't want to change RPC. New fields required new version
dest_acct_name.as_ref().map(String::as_str),
&dest_acct_name,
message,
)?;

Expand Down
2 changes: 1 addition & 1 deletion api/src/owner_rpc_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3375,7 +3375,7 @@ pub fn run_doctest_owner(
Some(String::from("testW1")),
None,
None,
None,
&None,
None,
true,
false,
Expand Down
6 changes: 3 additions & 3 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ lazy_static! {
/// Arguments common to all wallet commands
#[derive(Clone)]
pub struct GlobalArgs {
pub account: String,
pub account: Option<String>,
pub api_secret: Option<String>,
pub node_api_secret: Option<String>,
pub show_spent: bool,
Expand Down Expand Up @@ -650,7 +650,7 @@ where
slate = api.receive_tx(
&slate,
Some(String::from("self")),
Some(&args.dest),
&Some(args.dest.clone()),
None,
)?;
Ok(())
Expand Down Expand Up @@ -863,7 +863,7 @@ where
slate = api.receive_tx(
&slate,
Some(String::from("file")),
Some(&g_args.account),
&g_args.account,
args.message.clone(),
)?;

Expand Down
4 changes: 2 additions & 2 deletions controller/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ where
&self,
from: &dyn Address,
slate: &mut Slate,
dest_acct_name: Option<&str>,
dest_acct_name: &Option<String>,
secp: &Secp256k1,
) -> Result<(), Error> {
let owner_api = Owner::new(self.wallet.clone(), None, None);
Expand Down Expand Up @@ -620,7 +620,7 @@ where
secp
};

let result = self.process_incoming_slate(from, slate, None, &secp);
let result = self.process_incoming_slate(from, slate, &None, &secp);

//send the message back
match result {
Expand Down
15 changes: 9 additions & 6 deletions controller/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use prettytable;

/// Display outputs in a pretty way
pub fn outputs(
account: &str,
account: &Option<String>,
cur_height: u64,
validated: bool,
outputs: Vec<OutputCommitMapping>,
Expand All @@ -43,7 +43,8 @@ pub fn outputs(
"{}",
format!(
"Wallet Outputs - Account '{}' - Block Height: {}",
account, cur_height
account.as_deref().unwrap_or("default"),
cur_height
)
.magenta()
);
Expand Down Expand Up @@ -128,7 +129,7 @@ pub fn outputs(

/// Display transaction log in a pretty way
pub fn txs(
account: &str,
account: &Option<String>,
cur_height: u64,
validated: bool,
txs: &[TxLogEntry],
Expand All @@ -142,7 +143,8 @@ pub fn txs(
"{}",
format!(
"Transaction Log - Account '{}' - Block Height: {}",
account, cur_height
account.as_deref().unwrap_or("default"),
cur_height
)
.magenta()
);
Expand Down Expand Up @@ -437,14 +439,15 @@ pub fn view_wallet_output(

/// Display summary info in a pretty way
pub fn info(
account: &str,
account: &Option<String>,
wallet_info: &WalletInfo,
validated: bool,
dark_background_color_scheme: bool,
) {
println!(
"\n____ Wallet Summary Info - Account '{}' as of height {} ____\n",
account, wallet_info.last_confirmed_height,
account.as_deref().unwrap_or("default"),
wallet_info.last_confirmed_height,
);

let mut table = table!();
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn file_exchange_test_impl(test_dir: &'static str) -> Result<(), wallet::Error>

// wallet 2 receives file, completes, sends file back
wallet::controller::foreign_single_use(wallet2.clone(), mask2_i.clone(), |api| {
slate = api.receive_tx(&slate, None, None, Some(sender2_message.clone()))?;
slate = api.receive_tx(&slate, None, &None, Some(sender2_message.clone()))?;
PathToSlatePutter::build_plain(Some((&receive_file).into()))
.put_tx(&slate, None, true, &secp)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/repost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), wallet::Error> {
.get_tx(None, height, &secp)?
.to_slate()?
.0;
slate = api.receive_tx(&slate, None, None, None)?;
slate = api.receive_tx(&slate, None, &None, None)?;
PathToSlatePutter::build_plain(Some((&receive_file).into()))
.put_tx(&slate, None, true, &secp)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion controller/tests/self_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), wallet::Error> {
api.tx_lock_outputs(m, &slate, None, 0)?;
// Send directly to self
wallet::controller::foreign_single_use(wallet1.clone(), mask1_i.clone(), |api| {
slate = api.receive_tx(&slate, None, Some("listener"), None)?;
slate = api.receive_tx(&slate, None, &Some("listener".to_string()), None)?;
Ok(())
})?;
slate = api.finalize_tx(m, &slate)?;
Expand Down
4 changes: 2 additions & 2 deletions controller/tests/slatepack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn slatepack_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet:

// wallet 2 receives file, completes, sends file back
wallet::controller::foreign_single_use(wallet2.clone(), mask2_i.clone(), |api| {
let slate = api.receive_tx(&receive_slate, None, None, None)?;
let slate = api.receive_tx(&receive_slate, None, &None, None)?;
println!("receive_tx write slate: {:?}", slate);
output_slatepack(
&slate,
Expand Down Expand Up @@ -446,7 +446,7 @@ fn slatepack_exchange_test_impl(test_dir: &'static str) -> Result<(), libwallet:
let sender = res.get_sender();
assert!(sender.is_some());
let slate = res.to_result_slate();
let slate = api.receive_tx(&slate, None, None, None)?;
let slate = api.receive_tx(&slate, None, &None, None)?;
output_slatepack(
&slate,
SlatePurpose::SendResponse,
Expand Down
2 changes: 1 addition & 1 deletion impls/src/test_framework/testclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
Some(String::from(m.dest.clone())),
None,
None,
None,
&None,
None,
false,
false,
Expand Down
4 changes: 2 additions & 2 deletions libwallet/src/api_impl/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn receive_tx<'a, T: ?Sized, C, K>(
address: Option<String>,
key_id_opt: Option<&str>,
output_amounts: Option<Vec<u64>>,
dest_acct_name: Option<&str>,
dest_acct_name: &Option<String>,
message: Option<String>,
use_test_rng: bool,
refresh_from_node: bool,
Expand Down Expand Up @@ -150,7 +150,7 @@ where
let mut ret_slate = slate.clone();
check_ttl(w, &ret_slate, refresh_from_node)?;

let mut dest_acct_name = dest_acct_name.map(|s| s.to_string());
let mut dest_acct_name = dest_acct_name.clone();
if dest_acct_name.is_none() {
dest_acct_name = get_receive_account();
}
Expand Down
4 changes: 2 additions & 2 deletions libwallet/src/api_impl/owner_libp2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ where
args.address.clone(),
None,
None,
Some(INTEGRITY_ACCOUNT_NAME),
&Some(INTEGRITY_ACCOUNT_NAME.into()),
None,
false,
false,
Expand Down Expand Up @@ -474,7 +474,7 @@ where
args.address.clone(),
None,
None,
Some(account_withdraw_to),
&Some(account_withdraw_to.clone()),
None,
false,
false,
Expand Down
6 changes: 3 additions & 3 deletions libwallet/src/internal/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2299,11 +2299,11 @@ where
//send
slate = owner::init_send_tx(&mut **w, keychain_mask, &args, false, 1)?;
//receiver
let mut dest_account_name = None;
let mut dest_account_name: Option<String> = None;
let address_string;
if address.is_some() {
address_string = address.clone().unwrap();
dest_account_name = Option::from(&*(address_string));
dest_account_name = Some(address_string);
}
slate = foreign::receive_tx(
&mut **w,
Expand All @@ -2312,7 +2312,7 @@ where
address.clone(),
None,
None,
dest_account_name,
&dest_account_name,
None,
false,
false,
Expand Down
8 changes: 6 additions & 2 deletions src/bin/mwc-wallet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ args:
short: a
long: account
takes_value: true
default_value: default
- top_level_dir:
help: Top directory in which wallet files are stored (location of 'mwc-wallet.toml')
short: t
Expand Down Expand Up @@ -178,7 +177,7 @@ subcommands:
default_value: http
takes_value: true
- dest:
help: Send the transaction to the provided server (start with http://) or save as file.
help: Send the transaction to the provided server (start with http://) or save as file. For method self, dest can point to account name to move
short: d
long: dest
takes_value: true
Expand Down Expand Up @@ -526,6 +525,11 @@ subcommands:
takes_value: false
- open:
about: Opens a wallet (interactive mode only)
args:
- account:
help: Wallet account to use for this session
long: account
takes_value: true
- close:
about: Closes the wallet (interactive mode only)
- recover:
Expand Down
21 changes: 14 additions & 7 deletions src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn command_loop<L, C, K>(
wallet_config: &WalletConfig,
tor_config: &TorConfig,
mqs_config: &MQSConfig,
global_wallet_args: &GlobalArgs,
global_wallet_args: &mut GlobalArgs,
test_mode: bool,
) -> Result<(), Error>
where
Expand Down Expand Up @@ -162,7 +162,7 @@ where
Ok(args) => {
// handle opening /closing separately
keychain_mask = match args.subcommand() {
("open", Some(_)) => {
("open", Some(args)) => {
let mut wallet_lock = owner_api.wallet_inst.lock();
let lc = wallet_lock.lc_provider().unwrap();

Expand Down Expand Up @@ -193,11 +193,18 @@ where
&wallet_config.eth_infura_project_id,
);

if let Some(account) = args.value_of("account") {
if wallet_opened {
let wallet_inst = lc.wallet_inst()?;
wallet_inst.set_parent_key_id_by_name(account)?;
}
if wallet_opened {
let wallet_inst = lc.wallet_inst()?;
// Account name comes from open argument, next from global param, next 'default'
let account_name: String = match args.value_of("account") {
Some(account) => account.to_string(),
None => match &global_wallet_args.account {
Some(account) => account.clone(),
None => "default".to_string(),
},
};
wallet_inst.set_parent_key_id_by_name(account_name.as_str())?;
global_wallet_args.account = Some(account_name);
}
mask
}
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/wallet_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn parse_global_args(
config: &WalletConfig,
args: &ArgMatches,
) -> Result<command::GlobalArgs, ParseError> {
let account = parse_required(args, "account")?;
let account = args.value_of("account").map(|s| s.to_string());
let mut show_spent = false;
if args.is_present("show_spent") {
show_spent = true;
Expand All @@ -319,7 +319,7 @@ pub fn parse_global_args(
};

Ok(command::GlobalArgs {
account: account.to_owned(),
account: account,
show_spent: show_spent,
api_secret: api_secret,
node_api_secret: node_api_secret,
Expand Down Expand Up @@ -1488,7 +1488,7 @@ where
wallet_config.check_node_api_http_addr = sa.to_string().clone();
}

let global_wallet_args = arg_parse!(parse_global_args(&wallet_config, &wallet_args));
let mut global_wallet_args = arg_parse!(parse_global_args(&wallet_config, &wallet_args));

//parse the nodes address and put them in a vec
let node_list = parse_node_address_string(wallet_config.check_node_api_http_addr.clone());
Expand Down Expand Up @@ -1628,7 +1628,7 @@ where
&wallet_config,
&tor_config,
&mqs_config,
&global_wallet_args,
&mut global_wallet_args,
test_mode,
),
_ => {
Expand Down

0 comments on commit af379e8

Please sign in to comment.