Skip to content

Commit 392cc14

Browse files
committed
fix comments
1 parent a24a11f commit 392cc14

File tree

12 files changed

+100
-63
lines changed

12 files changed

+100
-63
lines changed

Cargo.lock

Lines changed: 5 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-gui/backend/src/backend_impl.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use wallet_cli_commands::{
3737
};
3838
use wallet_controller::{
3939
make_cold_wallet_rpc_client,
40-
types::{Balances, WalletTypeArgs},
40+
types::{Balances, WalletCreationOptions, WalletTypeArgs},
4141
ControllerConfig, NodeInterface, UtxoState, WalletHandlesClient,
4242
};
4343
use wallet_rpc_client::handles_client::WalletRpcHandlesClient;
@@ -408,8 +408,13 @@ impl Backend {
408408
let chain_config = wallet_service.chain_config().clone();
409409
let wallet_rpc = WalletRpc::new(wallet_handle, node_rpc.clone(), chain_config.clone());
410410

411+
let options = WalletCreationOptions {
412+
overwrite_wallet_file: true,
413+
skip_syncing: true,
414+
scan_blockchain: import.should_scan_blokchain(),
415+
};
411416
wallet_rpc
412-
.create_wallet(file_path, wallet_args, true, !import.skip_syncing())
417+
.create_wallet(file_path, wallet_args, options)
413418
.await
414419
.map_err(|err| BackendError::WalletError(err.to_string()))?;
415420
tokio::spawn(forward_events(

node-gui/backend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ pub enum ImportOrCreate {
5656
}
5757

5858
impl ImportOrCreate {
59-
pub fn skip_syncing(&self) -> bool {
59+
pub fn should_scan_blokchain(&self) -> bool {
6060
match self {
61-
Self::Create => true,
62-
Self::Import => false,
61+
Self::Create => false,
62+
Self::Import => true,
6363
}
6464
}
6565
}

wallet/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ tempfile.workspace = true
4545
[features]
4646
trezor = ["dep:trezor-client", "wallet-types/trezor"]
4747
trezor-emulator = []
48+
49+
default = ["trezor"]

wallet/src/signer/trezor_signer/mod.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ use trezor_client::{
5959
client::mintlayer::MintlayerSignature,
6060
find_devices,
6161
protos::{
62-
MintlayerAccountCommandTxInput, MintlayerAccountSpendingDelegationBalance,
63-
MintlayerAccountTxInput, MintlayerAddressPath, MintlayerAddressType, MintlayerBurnTxOutput,
64-
MintlayerChainType, MintlayerChangeTokenAuthority, MintlayerChangeTokenMetadataUri,
65-
MintlayerConcludeOrder, MintlayerCreateDelegationIdTxOutput, MintlayerCreateOrderTxOutput,
62+
features::Capability, MintlayerAccountCommandTxInput,
63+
MintlayerAccountSpendingDelegationBalance, MintlayerAccountTxInput, MintlayerAddressPath,
64+
MintlayerAddressType, MintlayerBurnTxOutput, MintlayerChainType,
65+
MintlayerChangeTokenAuthority, MintlayerChangeTokenMetadataUri, MintlayerConcludeOrder,
66+
MintlayerCreateDelegationIdTxOutput, MintlayerCreateOrderTxOutput,
6667
MintlayerCreateStakePoolTxOutput, MintlayerDataDepositTxOutput,
6768
MintlayerDelegateStakingTxOutput, MintlayerFillOrder, MintlayerFreezeToken,
6869
MintlayerHtlcTxOutput, MintlayerIssueFungibleTokenTxOutput, MintlayerIssueNftTxOutput,
@@ -102,6 +103,12 @@ use super::{Signer, SignerError, SignerProvider, SignerResult};
102103
pub enum TrezorError {
103104
#[error("No connected Trezor device found")]
104105
NoDeviceFound,
106+
#[error("There are multiple connected Trezor devices found")]
107+
NoUniqueDeviceFound,
108+
#[error("Cannot get the supported features for the connected Trezor device")]
109+
CannotGetDeviceFeatures,
110+
#[error("The connected Trezor device does not support the Mintlayer capabilities, please install the correct firmware")]
111+
MintlayerFeaturesNotSupported,
105112
#[error("Trezor device error: {0}")]
106113
DeviceError(String),
107114
#[error("Invalid public key returned from trezor")]
@@ -1220,12 +1227,29 @@ fn check_public_keys(
12201227
}
12211228

12221229
fn find_trezor_device() -> Result<Trezor, TrezorError> {
1223-
let device = find_devices(false)
1230+
let mut devices = find_devices(false)
12241231
.into_iter()
1225-
.find(|device| device.model == Model::Trezor)
1226-
.ok_or(TrezorError::NoDeviceFound)?;
1232+
.filter(|device| device.model == Model::Trezor || device.model == Model::TrezorEmulator)
1233+
.collect_vec();
1234+
1235+
let device = match devices.len() {
1236+
0 => return Err(TrezorError::NoDeviceFound),
1237+
1 => devices.remove(0),
1238+
_ => return Err(TrezorError::NoUniqueDeviceFound),
1239+
};
12271240
let mut client = device.connect().map_err(|e| TrezorError::DeviceError(e.to_string()))?;
12281241
client.init_device(None).map_err(|e| TrezorError::DeviceError(e.to_string()))?;
1242+
1243+
let features = client.features().ok_or(TrezorError::CannotGetDeviceFeatures)?;
1244+
ensure!(
1245+
features
1246+
.capabilities
1247+
.iter()
1248+
.filter_map(|c| c.enum_value().ok())
1249+
.contains(&Capability::Capability_Mintlayer),
1250+
TrezorError::MintlayerFeaturesNotSupported
1251+
);
1252+
12291253
Ok(client)
12301254
}
12311255

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ where
217217
.await?
218218
.recover_wallet(
219219
wallet_path,
220-
whether_to_store_seed_phrase.map_or(false, |x| x.to_bool()),
220+
whether_to_store_seed_phrase.is_some_and(|x| x.to_bool()),
221221
mnemonic,
222222
passphrase,
223223
hardware_wallet,

wallet/wallet-controller/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ where
234234
args: WalletTypeArgsComputed,
235235
best_block: (BlockHeight, Id<GenBlock>),
236236
wallet_type: WalletType,
237+
overwrite_wallet_file: bool,
237238
) -> Result<RuntimeWallet<DefaultBackend>, ControllerError<T>> {
238239
utils::ensure!(
239-
!file_path.as_ref().exists(),
240+
overwrite_wallet_file || !file_path.as_ref().exists(),
240241
ControllerError::WalletFileError(
241242
file_path.as_ref().to_owned(),
242243
"File already exists".to_owned()

wallet/wallet-controller/src/types/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ pub enum WalletTypeArgs {
164164
Trezor,
165165
}
166166

167+
#[derive(Debug, Clone, Copy)]
168+
pub struct WalletCreationOptions {
169+
/// By default the controller will sync the wallet with the blokchain on creation, this can be
170+
/// used to avoid blocking on waiting for the sync and can sync in the background
171+
pub skip_syncing: bool,
172+
/// should scan the blokchain, can be set to false if we know the seedphrase has been created
173+
/// now and we don't need to scan the blokchain to find any used addresses
174+
pub scan_blockchain: bool,
175+
/// Can overwrite an existing wallet file if selected from the GUI wallet
176+
pub overwrite_wallet_file: bool,
177+
}
178+
167179
impl WalletTypeArgs {
168180
pub fn wallet_type(&self, controller_mode: WalletControllerMode) -> WalletType {
169181
match self {

wallet/wallet-rpc-client/src/handles_client/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ use utils_networking::IpOrSocketAddress;
3535
use wallet::{account::TxInfo, version::get_version};
3636
use wallet_controller::{
3737
types::{
38-
CreatedBlockInfo, GenericTokenTransfer, SeedWithPassPhrase, WalletInfo, WalletTypeArgs,
38+
CreatedBlockInfo, GenericTokenTransfer, SeedWithPassPhrase, WalletCreationOptions,
39+
WalletInfo, WalletTypeArgs,
3940
},
4041
ConnectedPeer, ControllerConfig, UtxoState, UtxoType,
4142
};
@@ -126,9 +127,13 @@ where
126127
path: PathBuf,
127128
wallet_args: WalletTypeArgs,
128129
) -> Result<CreatedWallet, Self::Error> {
129-
let scan_blockchain = false;
130+
let options = WalletCreationOptions {
131+
overwrite_wallet_file: false,
132+
scan_blockchain: false,
133+
skip_syncing: false,
134+
};
130135
self.wallet_rpc
131-
.create_wallet(path, wallet_args, false, scan_blockchain)
136+
.create_wallet(path, wallet_args, options)
132137
.await
133138
.map(Into::into)
134139
.map_err(WalletRpcHandlesClientError::WalletRpcError)
@@ -170,9 +175,13 @@ where
170175
}
171176
};
172177

173-
let scan_blockchain = true;
178+
let options = WalletCreationOptions {
179+
overwrite_wallet_file: false,
180+
scan_blockchain: true,
181+
skip_syncing: false,
182+
};
174183
self.wallet_rpc
175-
.create_wallet(path, args, false, scan_blockchain)
184+
.create_wallet(path, args, options)
176185
.await
177186
.map(Into::into)
178187
.map_err(WalletRpcHandlesClientError::WalletRpcError)

wallet/wallet-rpc-lib/src/rpc/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ pub use rpc::{rpc_creds::RpcCreds, Rpc};
7070
use wallet_controller::{
7171
types::{
7272
Balances, BlockInfo, CreatedBlockInfo, CreatedWallet, GenericTokenTransfer,
73-
InspectTransaction, SeedWithPassPhrase, TransactionToInspect, WalletInfo, WalletTypeArgs,
73+
InspectTransaction, SeedWithPassPhrase, TransactionToInspect, WalletCreationOptions,
74+
WalletInfo, WalletTypeArgs,
7475
},
7576
ConnectedPeer, ControllerConfig, ControllerError, NodeInterface, UtxoState, UtxoStates,
7677
UtxoType, UtxoTypes, DEFAULT_ACCOUNT_INDEX,
@@ -137,14 +138,11 @@ where
137138
&self,
138139
path: PathBuf,
139140
args: WalletTypeArgs,
140-
skip_syncing: bool,
141-
scan_blockchain: bool,
141+
options: WalletCreationOptions,
142142
) -> WRpcResult<CreatedWallet, N> {
143143
self.wallet
144144
.manage_async(move |wallet_manager| {
145-
Box::pin(async move {
146-
wallet_manager.create_wallet(path, args, skip_syncing, scan_blockchain).await
147-
})
145+
Box::pin(async move { wallet_manager.create_wallet(path, args, options).await })
148146
})
149147
.await?
150148
}

wallet/wallet-rpc-lib/src/rpc/server_impl.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use utils_networking::IpOrSocketAddress;
3434
use wallet::{account::TxInfo, version::get_version};
3535
use wallet_controller::{
3636
types::{
37-
BlockInfo, CreatedBlockInfo, GenericTokenTransfer, SeedWithPassPhrase, WalletInfo,
38-
WalletTypeArgs,
37+
BlockInfo, CreatedBlockInfo, GenericTokenTransfer, SeedWithPassPhrase,
38+
WalletCreationOptions, WalletInfo, WalletTypeArgs,
3939
},
4040
ConnectedPeer, ControllerConfig, NodeInterface, UtxoState, UtxoStates, UtxoType, UtxoTypes,
4141
};
@@ -124,9 +124,13 @@ where
124124
}
125125
};
126126

127-
let scan_blockchain = false;
127+
let options = WalletCreationOptions {
128+
overwrite_wallet_file: false,
129+
scan_blockchain: false,
130+
skip_syncing: false,
131+
};
128132
rpc::handle_result(
129-
self.create_wallet(path.into(), args, false, scan_blockchain)
133+
self.create_wallet(path.into(), args, options)
130134
.await
131135
.map(Into::<CreatedWallet>::into),
132136
)
@@ -171,9 +175,13 @@ where
171175
}
172176
};
173177

174-
let scan_blockchain = true;
178+
let options = WalletCreationOptions {
179+
overwrite_wallet_file: false,
180+
scan_blockchain: true,
181+
skip_syncing: false,
182+
};
175183
rpc::handle_result(
176-
self.create_wallet(path.into(), args, false, scan_blockchain)
184+
self.create_wallet(path.into(), args, options)
177185
.await
178186
.map(Into::<CreatedWallet>::into),
179187
)

wallet/wallet-rpc-lib/src/service/worker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tokio::{sync::mpsc, task::JoinHandle};
2121

2222
use logging::log;
2323
use utils_networking::broadcaster::Broadcaster;
24-
use wallet_controller::types::{CreatedWallet, WalletTypeArgs};
24+
use wallet_controller::types::{CreatedWallet, WalletCreationOptions, WalletTypeArgs};
2525
use wallet_controller::{ControllerError, NodeInterface};
2626
use wallet_types::wallet_type::WalletType;
2727

@@ -184,8 +184,7 @@ where
184184
&mut self,
185185
wallet_path: PathBuf,
186186
args: WalletTypeArgs,
187-
skip_syncing: bool,
188-
scan_blockchain: bool,
187+
options: WalletCreationOptions,
189188
) -> Result<CreatedWallet, RpcError<N>> {
190189
utils::ensure!(
191190
self.controller.is_none(),
@@ -195,7 +194,7 @@ where
195194
let (computed_args, wallet_created) =
196195
args.parse_or_generate_mnemonic_if_needed().map_err(RpcError::InvalidMnemonic)?;
197196

198-
let wallet = if scan_blockchain {
197+
let wallet = if options.scan_blockchain {
199198
WalletController::recover_wallet(
200199
self.chain_config.clone(),
201200
wallet_path,
@@ -210,11 +209,12 @@ where
210209
computed_args,
211210
(info.best_block_height, info.best_block_id),
212211
wallet_type,
212+
options.overwrite_wallet_file,
213213
)
214214
}
215215
.map_err(RpcError::Controller)?;
216216

217-
let controller = if skip_syncing {
217+
let controller = if options.skip_syncing {
218218
WalletController::new_unsynced(
219219
self.chain_config.clone(),
220220
self.node_rpc.clone(),

0 commit comments

Comments
 (0)