Skip to content

Commit 32f5d6e

Browse files
committed
Group up Software and Trezor args in separate subcommands
1 parent 4c742da commit 32f5d6e

File tree

17 files changed

+294
-263
lines changed

17 files changed

+294
-263
lines changed

node-gui/backend/src/backend_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl Backend {
550550
handles_client,
551551
file_path.clone(),
552552
wallet_events,
553-
Some(HardwareWalletType::Trezor),
553+
Some(HardwareWalletType::Trezor { device_id: None }),
554554
)
555555
.await?;
556556

@@ -626,7 +626,6 @@ impl Backend {
626626
false,
627627
ScanBlockchain::ScanNoWait,
628628
hardware_wallet,
629-
None,
630629
)
631630
.await
632631
.map_err(|err| BackendError::WalletError(err.to_string()))?;

test/functional/test_framework/wallet_cli_controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ async def _write_command(self, cmd: str, can_be_empty: bool = False) -> str:
166166
async def create_wallet(self, name: str = "wallet", mnemonic: Optional[str] = None) -> str:
167167
wallet_file = os.path.join(self.node.datadir, name)
168168
mnemonic_str = "" if mnemonic is None else f'"{mnemonic}"'
169-
return await self._write_command(f"wallet-create \"{wallet_file}\" store-seed-phrase {mnemonic_str}\n")
169+
return await self._write_command(f"wallet-create software \"{wallet_file}\" store-seed-phrase {mnemonic_str}\n")
170170

171171
async def open_wallet(self, name: str, password: Optional[str] = None, force_change_wallet_type: bool = False) -> str:
172172
password_str = password if password else ""
173173
force_change_wallet_type_str = "--force-change-wallet-type" if force_change_wallet_type else ""
174174
wallet_file = os.path.join(self.node.datadir, name)
175-
return await self._write_command(f"wallet-open \"{wallet_file}\" {password_str} {force_change_wallet_type_str}\n")
175+
return await self._write_command(f"wallet-open software \"{wallet_file}\" {password_str} {force_change_wallet_type_str}\n")
176176

177177
async def recover_wallet(self, mnemonic: str, name: str = "recovered_wallet") -> str:
178178
wallet_file = os.path.join(self.node.datadir, name)
179-
return await self._write_command(f"wallet-recover \"{wallet_file}\" store-seed-phrase \"{mnemonic}\"\n")
179+
return await self._write_command(f"wallet-recover software \"{wallet_file}\" store-seed-phrase \"{mnemonic}\"\n")
180180

181181
async def close_wallet(self) -> str:
182182
return await self._write_command("wallet-close\n")

wallet/wallet-cli-commands/src/command_handler/mod.rs

Lines changed: 43 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,20 @@ use node_comm::node_traits::NodeInterface;
3333
use serialization::{hex::HexEncode, hex_encoded::HexEncoded};
3434
use utils::qrcode::{QrCode, QrCodeError};
3535
use wallet::version::get_version;
36-
use wallet_controller::types::{GenericTokenTransfer, WalletTypeArgs};
36+
use wallet_controller::types::GenericTokenTransfer;
3737
use wallet_rpc_client::wallet_rpc_traits::{PartialOrSignedTx, WalletInterface};
38-
use wallet_rpc_lib::{
39-
cmdline::CliHardwareWalletType,
40-
types::{
41-
Balances, ComposedTransaction, ControllerConfig, MnemonicInfo, NewTransaction, NftMetadata,
42-
RpcInspectTransaction, RpcSignatureStats, RpcSignatureStatus, RpcStandaloneAddressDetails,
43-
RpcValidatedSignatures, TokenMetadata,
44-
},
38+
use wallet_rpc_lib::types::{
39+
Balances, ComposedTransaction, ControllerConfig, HardwareWalletType, MnemonicInfo,
40+
NewTransaction, NftMetadata, RpcInspectTransaction, RpcSignatureStats, RpcSignatureStatus,
41+
RpcStandaloneAddressDetails, RpcValidatedSignatures, TokenMetadata,
4542
};
4643

47-
use wallet_types::{
48-
partially_signed_transaction::PartiallySignedTransaction, seed_phrase::StoreSeedPhrase,
49-
};
44+
use wallet_types::partially_signed_transaction::PartiallySignedTransaction;
5045

5146
use crate::{
5247
errors::WalletCliCommandError, helper_types::parse_generic_token_transfer,
5348
CreateWalletDeviceSelectMenu, ManageableWalletCommand, OpenWalletDeviceSelectMenu,
54-
WalletManagementCommand,
49+
OpenWalletSubCommand, WalletManagementCommand,
5550
};
5651

5752
use self::local_state::WalletWithState;
@@ -150,36 +145,17 @@ where
150145
WalletCliCommandError<N>: From<E>,
151146
{
152147
match command {
153-
WalletManagementCommand::CreateWallet {
154-
wallet_path,
155-
mnemonic,
156-
whether_to_store_seed_phrase,
157-
passphrase,
158-
hardware_wallet,
159-
trezor_device_id,
160-
} => {
161-
let store_seed_phrase =
162-
whether_to_store_seed_phrase.map_or(StoreSeedPhrase::DoNotStore, Into::into);
163-
let wallet_args = hardware_wallet.map_or(
164-
WalletTypeArgs::Software {
165-
mnemonic,
166-
passphrase,
167-
store_seed_phrase,
168-
},
169-
|h| h.into_wallet_args(trezor_device_id),
170-
);
148+
WalletManagementCommand::CreateWallet { wallet } => {
149+
let (wallet_path, wallet_args) = wallet.into_path_and_wallet_args();
150+
171151
let response =
172152
self.wallet().await?.create_wallet(wallet_path.clone(), wallet_args).await?;
173153

174154
if let Some(devices) = response.multiple_devices_available {
175155
match devices {
176156
wallet_rpc_lib::types::MultipleDevicesAvailable::Trezor { devices } => {
177-
let choices = CreateWalletDeviceSelectMenu::new(
178-
devices,
179-
wallet_path,
180-
CliHardwareWalletType::Trezor,
181-
false,
182-
);
157+
let choices =
158+
CreateWalletDeviceSelectMenu::new(devices, wallet_path, false);
183159
return Ok(ConsoleCommand::ChoiceMenu(Box::new(choices)));
184160
}
185161
}
@@ -208,38 +184,17 @@ where
208184
})
209185
}
210186

211-
WalletManagementCommand::RecoverWallet {
212-
wallet_path,
213-
mnemonic,
214-
whether_to_store_seed_phrase,
215-
passphrase,
216-
hardware_wallet,
217-
trezor_device_id,
218-
} => {
219-
let hardware_wallet = hardware_wallet.map(Into::into);
187+
WalletManagementCommand::RecoverWallet { wallet } => {
188+
let (wallet_path, wallet_args) = wallet.into_path_and_wallet_args();
220189

221-
let response = self
222-
.wallet()
223-
.await?
224-
.recover_wallet(
225-
wallet_path.clone(),
226-
whether_to_store_seed_phrase.is_some_and(|x| x.to_bool()),
227-
mnemonic,
228-
passphrase,
229-
hardware_wallet,
230-
trezor_device_id,
231-
)
232-
.await?;
190+
let response =
191+
self.wallet().await?.recover_wallet(wallet_path.clone(), wallet_args).await?;
233192

234193
if let Some(devices) = response.multiple_devices_available {
235194
match devices {
236195
wallet_rpc_lib::types::MultipleDevicesAvailable::Trezor { devices } => {
237-
let choices = CreateWalletDeviceSelectMenu::new(
238-
devices,
239-
wallet_path,
240-
CliHardwareWalletType::Trezor,
241-
true,
242-
);
196+
let choices =
197+
CreateWalletDeviceSelectMenu::new(devices, wallet_path, true);
243198
return Ok(ConsoleCommand::ChoiceMenu(Box::new(choices)));
244199
}
245200
}
@@ -255,14 +210,31 @@ where
255210
})
256211
}
257212

258-
WalletManagementCommand::OpenWallet {
259-
wallet_path,
260-
encryption_password,
261-
force_change_wallet_type,
262-
hardware_wallet,
263-
trezor_device_id,
264-
} => {
265-
let hardware_wallet = hardware_wallet.map(Into::into);
213+
WalletManagementCommand::OpenWallet { wallet } => {
214+
let (wallet_path, encryption_password, force_change_wallet_type, hardware_wallet) =
215+
match wallet {
216+
OpenWalletSubCommand::Software {
217+
wallet_path,
218+
encryption_password,
219+
force_change_wallet_type,
220+
} => (
221+
wallet_path,
222+
encryption_password,
223+
force_change_wallet_type,
224+
None,
225+
),
226+
OpenWalletSubCommand::Trezor {
227+
wallet_path,
228+
encryption_password,
229+
device_id,
230+
} => (
231+
wallet_path,
232+
encryption_password,
233+
false,
234+
Some(HardwareWalletType::Trezor { device_id }),
235+
),
236+
};
237+
266238
let response = self
267239
.wallet()
268240
.await?
@@ -271,7 +243,6 @@ where
271243
encryption_password.clone(),
272244
Some(force_change_wallet_type),
273245
hardware_wallet,
274-
trezor_device_id,
275246
)
276247
.await?;
277248

@@ -288,8 +259,6 @@ where
288259
devices,
289260
wallet_path,
290261
encryption_password,
291-
force_change_wallet_type,
292-
CliHardwareWalletType::Trezor,
293262
);
294263
return Ok(ConsoleCommand::ChoiceMenu(Box::new(choices)));
295264
}

0 commit comments

Comments
 (0)