Skip to content

Commit

Permalink
fix gui wallet recover walllet scan waiting
Browse files Browse the repository at this point in the history
- make the gui wallet not block on scanning the blokchain when
  recovering a wallet from a seed phrase
  • Loading branch information
OBorce committed Jan 22, 2025
1 parent 448adef commit eff8579
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 26 deletions.
2 changes: 1 addition & 1 deletion node-gui/backend/src/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl Backend {
StoreSeedPhrase::Store,
Some(mnemonic.to_string()),
None,
import.skip_syncing(),
import.scan_blockchain(),
)
.await
.map_err(|err| BackendError::WalletError(err.to_string()))?;
Expand Down
7 changes: 4 additions & 3 deletions node-gui/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod wallet_events;

mod account_id;
pub use account_id::AccountId;
use wallet_types::scan_blockchain::ScanBlockchain;

use std::fmt::Debug;
use std::sync::Arc;
Expand Down Expand Up @@ -56,10 +57,10 @@ pub enum ImportOrCreate {
}

impl ImportOrCreate {
pub fn skip_syncing(&self) -> bool {
pub fn scan_blockchain(&self) -> ScanBlockchain {
match self {
Self::Create => true,
Self::Import => false,
Self::Create => ScanBlockchain::SkipScanning,
Self::Import => ScanBlockchain::ScanNoWait,
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions node-gui/src/widgets/wallet_mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ where
.push(
Button::new(
Text::new(iced_fonts::Bootstrap::ClipboardCheck.to_string())
.font(iced_fonts::BOOTSTRAP_FONT),
.font(iced_fonts::BOOTSTRAP_FONT)
.size(30),
)
.style(iced::widget::button::text)
// .width(20)
// .height(20)
.on_press(on_copy_to_clipboard),
)
.spacing(10)
Expand Down
1 change: 1 addition & 0 deletions wallet/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod account_info;
pub mod chain_info;
pub mod currency;
pub mod keys;
pub mod scan_blockchain;
pub mod seed_phrase;
pub mod signature_status;
pub mod utxo_types;
Expand Down
40 changes: 40 additions & 0 deletions wallet/types/src/scan_blockchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2025 RBB S.r.l
// [email protected]
// SPDX-License-Identifier: MIT
// Licensed under the MIT License;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub enum ScanBlockchain {
/// Skips the scanning of the blokchain, used when creating a wallet from a brand new seed
/// phrase never used before
SkipScanning,
/// Scans the blokchain and waits for the scanning to complete before returning
ScanAndWait,
/// Scans the blokchain in the background
ScanNoWait,
}

impl ScanBlockchain {
pub fn skip_syncing(&self) -> bool {
match self {
Self::SkipScanning => true,
Self::ScanNoWait | Self::ScanAndWait => false,
}
}

pub fn wait_for_sync(&self) -> bool {
match self {
Self::ScanAndWait => true,
Self::SkipScanning | Self::ScanNoWait => false,
}
}
}
6 changes: 3 additions & 3 deletions wallet/wallet-rpc-client/src/handles_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use wallet_rpc_lib::{
RpcError, WalletRpc,
};
use wallet_types::{
seed_phrase::StoreSeedPhrase, signature_status::SignatureStatus, utxo_types::UtxoTypes,
with_locked::WithLocked,
scan_blockchain::ScanBlockchain, seed_phrase::StoreSeedPhrase,
signature_status::SignatureStatus, utxo_types::UtxoTypes, with_locked::WithLocked,
};

use crate::wallet_rpc_traits::{
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<N: NodeInterface + Clone + Send + Sync + Debug + 'static> WalletInterface
whether_to_store_seed_phrase,
mnemonic,
passphrase,
false,
ScanBlockchain::ScanAndWait,
)
.await
.map(Into::into)
Expand Down
15 changes: 11 additions & 4 deletions wallet/wallet-rpc-lib/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ use wallet_controller::{
UtxoType, UtxoTypes, DEFAULT_ACCOUNT_INDEX,
};
use wallet_types::{
account_info::StandaloneAddressDetails, seed_phrase::StoreSeedPhrase,
signature_status::SignatureStatus, wallet_tx::TxData, with_locked::WithLocked, Currency,
account_info::StandaloneAddressDetails, scan_blockchain::ScanBlockchain,
seed_phrase::StoreSeedPhrase, signature_status::SignatureStatus, wallet_tx::TxData,
with_locked::WithLocked, Currency,
};

use crate::{
Expand Down Expand Up @@ -129,13 +130,19 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static> WalletRpc<N> {
store_seed_phrase: StoreSeedPhrase,
mnemonic: Option<String>,
passphrase: Option<String>,
skip_syncing: bool,
scan_blockchain: ScanBlockchain,
) -> WRpcResult<CreatedWallet, N> {
self.wallet
.manage_async(move |wallet_manager| {
Box::pin(async move {
wallet_manager
.create_wallet(path, store_seed_phrase, mnemonic, passphrase, skip_syncing)
.create_wallet(
path,
store_seed_phrase,
mnemonic,
passphrase,
scan_blockchain,
)
.await
})
})
Expand Down
5 changes: 3 additions & 2 deletions wallet/wallet-rpc-lib/src/rpc/server_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ use wallet_controller::{
ConnectedPeer, ControllerConfig, NodeInterface, UtxoState, UtxoStates, UtxoType, UtxoTypes,
};
use wallet_types::{
seed_phrase::StoreSeedPhrase, signature_status::SignatureStatus, with_locked::WithLocked,
scan_blockchain::ScanBlockchain, seed_phrase::StoreSeedPhrase,
signature_status::SignatureStatus, with_locked::WithLocked,
};

use crate::{
Expand Down Expand Up @@ -100,7 +101,7 @@ impl<N: NodeInterface + Clone + Send + Sync + Debug + 'static> ColdWalletRpcServ
whether_to_store_seed_phrase,
mnemonic,
passphrase,
false,
ScanBlockchain::ScanAndWait,
)
.await
.map(Into::<CreatedWallet>::into),
Expand Down
30 changes: 20 additions & 10 deletions wallet/wallet-rpc-lib/src/service/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use logging::log;
use utils_networking::broadcaster::Broadcaster;
use wallet::wallet::Mnemonic;
use wallet_controller::{ControllerError, NodeInterface};
use wallet_types::scan_blockchain::ScanBlockchain;
use wallet_types::seed_phrase::StoreSeedPhrase;

use crate::types::RpcError;
Expand Down Expand Up @@ -205,7 +206,7 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static> WalletWorker<N> {
whether_to_store_seed_phrase: StoreSeedPhrase,
mnemonic: Option<String>,
passphrase: Option<String>,
skip_syncing: bool,
scan_blockchain: ScanBlockchain,
) -> Result<CreatedWallet, RpcError<N>> {
utils::ensure!(
self.controller.is_none(),
Expand All @@ -221,7 +222,7 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static> WalletWorker<N> {
};
let passphrase_ref = passphrase.as_ref().map(|x| x.as_ref());

let wallet = if newly_generated_mnemonic || skip_syncing {
let wallet = if newly_generated_mnemonic || scan_blockchain.skip_syncing() {
let info = self.node_rpc.chainstate_info().await.map_err(RpcError::RpcError)?;
WalletController::create_wallet(
self.chain_config.clone(),
Expand All @@ -244,14 +245,23 @@ impl<N: NodeInterface + Clone + Send + Sync + 'static> WalletWorker<N> {
}
.map_err(RpcError::Controller)?;

let controller = WalletController::new(
self.chain_config.clone(),
self.node_rpc.clone(),
wallet,
self.wallet_events.clone(),
)
.await
.map_err(RpcError::Controller)?;
let controller = if scan_blockchain.wait_for_sync() {
WalletController::new(
self.chain_config.clone(),
self.node_rpc.clone(),
wallet,
self.wallet_events.clone(),
)
.await
.map_err(RpcError::Controller)?
} else {
WalletController::new_unsynced(
self.chain_config.clone(),
self.node_rpc.clone(),
wallet,
self.wallet_events.clone(),
)
};

self.controller.replace(controller);

Expand Down

0 comments on commit eff8579

Please sign in to comment.