Skip to content

Commit

Permalink
fix trezor feature compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Jul 31, 2024
1 parent 484b20c commit 626b7d1
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 58 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,3 @@ lto = "off"

[features]
trezor = []

default = ["trezor"]
3 changes: 3 additions & 0 deletions node-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ rfd = { workspace = true, features = ["xdg-portal", "tokio"] }
thiserror.workspace = true
tokio.workspace = true
variant_count.workspace = true

[features]
trezor = ["wallet-controller/trezor", "wallet-types/trezor", "wallet-rpc-lib/trezor"]
2 changes: 2 additions & 0 deletions node-gui/src/backend/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl Backend {

(wallet_data, accounts_info, best_block)
}
#[cfg(feature = "trezor")]
(WalletType::Trezor, _) => {
let client = make_cold_wallet_rpc_client(Arc::clone(&self.chain_config));

Expand Down Expand Up @@ -508,6 +509,7 @@ impl Backend {

(wallet_data, accounts_info, best_block, encryption_state)
}
#[cfg(feature = "trezor")]
(WalletType::Trezor, _) => {
let client = make_cold_wallet_rpc_client(Arc::clone(&self.chain_config));

Expand Down
83 changes: 54 additions & 29 deletions node-gui/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,35 +153,23 @@ pub async fn node_initialize(
});
(chain_config, chain_info)
}
WalletMode::Trezor | WalletMode::Cold => {
let chain_config = Arc::new(match network {
InitNetwork::Mainnet => common::chain::config::create_mainnet(),
InitNetwork::Testnet => common::chain::config::create_testnet(),
});
let chain_info = ChainInfo {
best_block_id: chain_config.genesis_block_id(),
best_block_height: BlockHeight::zero(),
median_time: chain_config.genesis_block().timestamp(),
best_block_timestamp: chain_config.genesis_block().timestamp(),
is_initial_block_download: false,
};

let manager_join_handle = tokio::spawn(async move {});

let backend = backend_impl::Backend::new_cold(
chain_config.clone(),
event_tx,
low_priority_event_tx,
wallet_updated_tx,
manager_join_handle,
);

tokio::spawn(async move {
backend_impl::run_cold(backend, request_rx, wallet_updated_rx).await;
});

(chain_config, chain_info)
}
#[cfg(feature = "trezor")]
WalletMode::Trezor => spawn_cold_backend(
network,
event_tx,
request_rx,
low_priority_event_tx,
wallet_updated_tx,
wallet_updated_rx,
),
WalletMode::Cold => spawn_cold_backend(
network,
event_tx,
request_rx,
low_priority_event_tx,
wallet_updated_tx,
wallet_updated_rx,
),
};

let initialized_node = InitializedNode {
Expand All @@ -198,3 +186,40 @@ pub async fn node_initialize(

Ok(backend_controls)
}

fn spawn_cold_backend(
network: InitNetwork,
event_tx: UnboundedSender<BackendEvent>,
request_rx: UnboundedReceiver<BackendRequest>,
low_priority_event_tx: UnboundedSender<BackendEvent>,
wallet_updated_tx: UnboundedSender<messages::WalletId>,
wallet_updated_rx: UnboundedReceiver<messages::WalletId>,
) -> (Arc<ChainConfig>, ChainInfo) {
let chain_config = Arc::new(match network {
InitNetwork::Mainnet => common::chain::config::create_mainnet(),
InitNetwork::Testnet => common::chain::config::create_testnet(),
});
let chain_info = ChainInfo {
best_block_id: chain_config.genesis_block_id(),
best_block_height: BlockHeight::zero(),
median_time: chain_config.genesis_block().timestamp(),
best_block_timestamp: chain_config.genesis_block().timestamp(),
is_initial_block_download: false,
};

let manager_join_handle = tokio::spawn(async move {});

let backend = backend_impl::Backend::new_cold(
chain_config.clone(),
event_tx,
low_priority_event_tx,
wallet_updated_tx,
manager_join_handle,
);

tokio::spawn(async move {
backend_impl::run_cold(backend, request_rx, wallet_updated_rx).await;
});

(chain_config, chain_info)
}
17 changes: 12 additions & 5 deletions node-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use tokio::sync::mpsc::UnboundedReceiver;
const COLD_WALLET_TOOLTIP_TEXT: &str =
"Start the wallet in Cold mode without connecting to the network or any nodes. The Cold mode is made to run the wallet on an air-gapped machine without internet connection for storage of keys of high-value. For example, pool decommission keys.";
const HOT_WALLET_TOOLTIP_TEXT: &str = "Start the wallet in Hot mode and connect to the network.";
#[cfg(feature = "trezor")]
const TREZOR_WALLET_TOOLTIP_TEXT: &str =
"Start the wallet in Trezor mode and connect to a Trezor hardware wallet.";

Expand Down Expand Up @@ -72,6 +73,7 @@ pub enum InitNetwork {
pub enum WalletMode {
Cold,
Hot,
#[cfg(feature = "trezor")]
Trezor,
}

Expand Down Expand Up @@ -359,7 +361,13 @@ impl Application for MintlayerNodeGUI {
.gap(10)
.style(iced::theme::Container::Box)
],
row![
]
.align_items(iced::Alignment::Center)
.spacing(5);

#[cfg(feature = "trezor")]
let error_box = {
let trezor_row = row![
iced::widget::button(text("Trezor")).on_press(WalletMode::Trezor),
tooltip(
Text::new(iced_aw::Bootstrap::Question.to_string())
Expand All @@ -369,10 +377,9 @@ impl Application for MintlayerNodeGUI {
)
.gap(10)
.style(iced::theme::Container::Box)
],
]
.align_items(iced::Alignment::Center)
.spacing(5);
];
error_box.push(trezor_row)
};

let res: Element<WalletMode> = container(error_box)
.width(Length::Fill)
Expand Down
1 change: 1 addition & 0 deletions node-gui/src/main_window/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fn make_menu_file<'a>(wallet_mode: WalletMode) -> Item<'a, MenuMessage, Theme, i
menu_item("Exit", MenuMessage::Exit),
]
}
#[cfg(feature = "trezor")]
WalletMode::Trezor => {
vec![
menu_item(
Expand Down
1 change: 1 addition & 0 deletions node-gui/src/main_window/main_widget/tabs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl TabsWidget {
self.cold_wallet_tab.tab_label(),
self.cold_wallet_tab.view(node_state),
),
#[cfg(feature = "trezor")]
WalletMode::Trezor => tabs.push(
TabIndex::Summary as usize,
self.cold_wallet_tab.tab_label(),
Expand Down
20 changes: 19 additions & 1 deletion node-gui/src/main_window/main_widget/tabs/wallet/left_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub fn view_left_panel(

// `next_height` is used to prevent flickering when a new block is found
let show_scan_progress = match wallet_info.wallet_type {
#[cfg(feature = "trezor")]
WalletType::Trezor => false,
WalletType::Cold => false,
WalletType::Hot => {
Expand Down Expand Up @@ -176,7 +177,24 @@ pub fn view_left_panel(
.spacing(10)
.padding(10),
match wallet_info.wallet_type {
WalletType::Trezor | WalletType::Cold => {
#[cfg(feature = "trezor")]
WalletType::Trezor => {
column![
panel_button(
"Addresses",
SelectedPanel::Addresses,
selected_panel,
ADDRESSES_TOOLTIP_TEXT
),
panel_button(
"Console",
SelectedPanel::Console,
selected_panel,
CONSOLE_TOOLTIP_TEXT,
)
]
}
WalletType::Cold => {
column![
panel_button(
"Addresses",
Expand Down
2 changes: 2 additions & 0 deletions node-gui/src/main_window/main_widget/tabs/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl WalletTab {
let selected_panel = match wallet_type {
WalletType::Hot => SelectedPanel::Transactions,
WalletType::Cold => SelectedPanel::Addresses,
#[cfg(feature = "trezor")]
WalletType::Trezor => SelectedPanel::Addresses,
};

Expand Down Expand Up @@ -484,6 +485,7 @@ impl Tab for WalletTab {

let still_syncing = match wallet_info.wallet_type {
WalletType::Cold => false,
#[cfg(feature = "trezor")]
WalletType::Trezor => false,
WalletType::Hot => {
wallet_info.best_block.1.next_height() < node_state.chain_info.best_block_height
Expand Down
10 changes: 8 additions & 2 deletions node-gui/src/main_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use wallet_cli_commands::ConsoleCommand;
use wallet_controller::types::WalletTypeArgs;
use wallet_types::{seed_phrase::StoreSeedPhrase, wallet_type::WalletType};

#[cfg(feature = "trezor")]
use crate::widgets::create_hw_wallet::hw_wallet_create_dialog;
use crate::{
backend::{
messages::{
Expand All @@ -39,7 +41,6 @@ use crate::{
main_window::{main_menu::MenuMessage, main_widget::MainWidgetMessage},
widgets::{
confirm_broadcast::new_confirm_broadcast,
create_hw_wallet::hw_wallet_create_dialog,
new_wallet_account::new_wallet_account,
popup_dialog::{popup_dialog, Popup},
wallet_mnemonic::wallet_mnemonic_dialog,
Expand Down Expand Up @@ -164,8 +165,11 @@ impl ImportOrCreate {

#[derive(Debug, Clone)]
pub enum WalletArgs {
Software {
mnemonic: String,
},
#[cfg(feature = "trezor")]
Trezor,
Software { mnemonic: String },
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -686,6 +690,7 @@ impl MainWindow {
}
}
}
#[cfg(feature = "trezor")]
WalletArgs::Trezor => WalletTypeArgs::Trezor,
};

Expand Down Expand Up @@ -811,6 +816,7 @@ impl MainWindow {
Box::new(|| MainWindowMessage::CloseDialog),
)
.into(),
#[cfg(feature = "trezor")]
WalletType::Trezor => hw_wallet_create_dialog(
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Trezor,
Expand Down
1 change: 1 addition & 0 deletions node-gui/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

pub mod confirm_broadcast;
#[cfg(feature = "trezor")]
pub mod create_hw_wallet;
pub mod new_wallet_account;
pub mod popup_dialog;
Expand Down
4 changes: 1 addition & 3 deletions wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@ rstest.workspace = true
tempfile.workspace = true

[features]
trezor = ["trezor-client"]

default = ["trezor"]
trezor = ["dep:trezor-client", "wallet-types/trezor"]
6 changes: 4 additions & 2 deletions wallet/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ use crate::{
Account, WalletResult,
};

use self::trezor_signer::TrezorError;

pub mod software_signer;
#[cfg(feature = "trezor")]
pub mod trezor_signer;

#[cfg(feature = "trezor")]
use self::trezor_signer::TrezorError;

/// Signer errors
#[derive(thiserror::Error, Debug, Eq, PartialEq)]
pub enum SignerError {
Expand All @@ -64,6 +65,7 @@ pub enum SignerError {
MultisigError(#[from] PartiallySignedMultisigStructureError),
#[error("{0}")]
SerializationError(#[from] serialization::Error),
#[cfg(feature = "trezor")]
#[error("Trezor error: {0}")]
TrezorError(#[from] TrezorError),
#[error("Partially signed tx is missing input's destination")]
Expand Down
1 change: 1 addition & 0 deletions wallet/src/signer/trezor_signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,5 +1109,6 @@ impl SignerProvider for TrezorSignerProvider {
}
}

#[cfg(feature = "trezor-emulator")]
#[cfg(test)]
mod tests;
2 changes: 2 additions & 0 deletions wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,14 @@ where
(WalletType::Hot, WalletType::Cold) => {
Self::migrate_hot_to_cold_wallet(db, chain_config, signer_provider)?
}
#[cfg(feature = "trezor")]
(WalletType::Cold | WalletType::Hot, WalletType::Trezor)
| (WalletType::Trezor, WalletType::Hot | WalletType::Cold) => {
return Err(WalletError::CannotChangeTrezorWalletType)
}
(WalletType::Cold, WalletType::Cold) => {}
(WalletType::Hot, WalletType::Hot) => {}
#[cfg(feature = "trezor")]
(WalletType::Trezor, WalletType::Trezor) => {}
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions wallet/trezor-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub fn unique(debug: bool) -> Result<Trezor> {
}
}

#[cfg(feature = "trezor-emulator")]
#[cfg(test)]
mod tests {
use serial_test::serial;
Expand Down
3 changes: 3 additions & 0 deletions wallet/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ zeroize.workspace = true
test-utils = { path = "../../test-utils" }

rstest.workspace = true

[features]
trezor = []
2 changes: 2 additions & 0 deletions wallet/types/src/wallet_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum WalletType {
Cold,
#[codec(index = 1)]
Hot,
#[cfg(feature = "trezor")]
#[codec(index = 2)]
Trezor,
}
Expand All @@ -31,6 +32,7 @@ impl Display for WalletType {
match self {
Self::Hot => write!(f, "Hot"),
Self::Cold => write!(f, "Cold"),
#[cfg(feature = "trezor")]
Self::Trezor => write!(f, "Trezor"),
}
}
Expand Down
4 changes: 1 addition & 3 deletions wallet/wallet-cli-commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@ wallet-test-node = { path = "../wallet-test-node" }
rstest.workspace = true

[features]
trezor = []

default = ["trezor"]
trezor = ["wallet-types/trezor", "wallet-rpc-lib/trezor"]
2 changes: 1 addition & 1 deletion wallet/wallet-cli-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ wallet-test-node = { path = "../wallet-test-node" }
rstest.workspace = true

[features]
trezor = []
trezor = ["wallet/trezor", "wallet-cli-commands/trezor", "wallet-types/trezor", "wallet-rpc-lib/trezor", "wallet-rpc-client/trezor"]
3 changes: 3 additions & 0 deletions wallet/wallet-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ wallet-cli-lib = { path = "../wallet-cli-lib" }

clap = { workspace = true, features = ["derive"] }
tokio = { workspace = true, default-features = false, features = ["io-util", "macros", "net", "rt", "sync"] }

[features]
trezor = ["wallet-cli-lib/trezor"]
Loading

0 comments on commit 626b7d1

Please sign in to comment.