Skip to content

Commit 7e0f2c8

Browse files
committed
fix comments
1 parent 04420de commit 7e0f2c8

File tree

35 files changed

+323
-356
lines changed

35 files changed

+323
-356
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/chain/tokens/tokens_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ pub fn is_token_or_nft_issuance(output: &TxOutput) -> bool {
9191
}
9292
}
9393

94-
/// Get any referenced token by this output
94+
/// Get any token referenced by this output
9595
/// ignore tokens V0
9696
pub fn get_referenced_token_ids(output: &TxOutput) -> BTreeSet<TokenId> {
9797
match output {
9898
TxOutput::Transfer(v, _)
9999
| TxOutput::LockThenTransfer(v, _, _)
100100
| TxOutput::Burn(v)
101-
| TxOutput::Htlc(v, _) => referenced_token_id(v),
101+
| TxOutput::Htlc(v, _) => referenced_token_id(v).into_iter().collect(),
102102
| TxOutput::CreateOrder(data) => {
103-
let mut tokens = referenced_token_id(data.ask());
103+
let mut tokens: BTreeSet<_> = referenced_token_id(data.ask()).into_iter().collect();
104104
tokens.extend(referenced_token_id(data.give()));
105105
tokens
106106
}
@@ -114,9 +114,9 @@ pub fn get_referenced_token_ids(output: &TxOutput) -> BTreeSet<TokenId> {
114114
}
115115
}
116116

117-
fn referenced_token_id(v: &OutputValue) -> BTreeSet<TokenId> {
117+
fn referenced_token_id(v: &OutputValue) -> Option<TokenId> {
118118
match v {
119-
OutputValue::Coin(_) | OutputValue::TokenV0(_) => BTreeSet::new(),
120-
OutputValue::TokenV1(token_id, _) => BTreeSet::from_iter([*token_id]),
119+
OutputValue::Coin(_) | OutputValue::TokenV0(_) => None,
120+
OutputValue::TokenV1(token_id, _) => Some(*token_id),
121121
}
122122
}

crypto/src/key/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ pub use signature::Signature;
3030
use self::key_holder::{PrivateKeyHolder, PublicKeyHolder};
3131

3232
#[derive(thiserror::Error, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
33-
pub enum SignatureError {}
33+
pub enum SignatureError {
34+
#[error("Failed to construct a valid signature")]
35+
SignatureConstructionError,
36+
}
3437

3538
#[must_use]
3639
#[derive(Debug, PartialEq, Eq, Clone, Decode, Encode)]

crypto/src/key/signature/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use std::io::BufWriter;
1919
use num_derive::FromPrimitive;
2020
use serialization::{hex_encoded::HexEncoded, Decode, DecodeAll, Encode};
2121

22+
use super::SignatureError;
23+
2224
#[derive(FromPrimitive)]
2325
pub enum SignatureKind {
2426
Secp256k1Schnorr = 0,
@@ -77,6 +79,12 @@ impl Signature {
7779
Ok(decoded_sig)
7880
}
7981

82+
pub fn from_raw_data<T: AsRef<[u8]>>(data: T) -> Result<Self, SignatureError> {
83+
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
84+
.map_err(|_| SignatureError::SignatureConstructionError)?;
85+
Ok(Self::Secp256k1Schnorr(decoded_sig))
86+
}
87+
8088
pub fn is_aggregable(&self) -> bool {
8189
match self {
8290
Self::Secp256k1Schnorr(_) => false,

node-gui/backend/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ test-utils = { path = "../../test-utils" }
4141

4242
rstest.workspace = true
4343
serde_json.workspace = true
44+
45+
[features]
46+
trezor = ["wallet/trezor", "wallet-controller/trezor", "wallet-types/trezor", "wallet-rpc-lib/trezor", "wallet-rpc-client/trezor"]

node-gui/backend/src/backend_impl.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -351,26 +351,7 @@ impl Backend {
351351
}
352352
#[cfg(feature = "trezor")]
353353
(WalletType::Trezor, ColdHotNodeController::Cold) => {
354-
let client = make_cold_wallet_rpc_client(Arc::clone(&self.chain_config));
355-
356-
let (wallet_rpc, command_handler, best_block, accounts_info, accounts_data) = self
357-
.create_wallet(
358-
client,
359-
file_path.clone(),
360-
wallet_args,
361-
import,
362-
wallet_events,
363-
)
364-
.await?;
365-
366-
let wallet_data = WalletData {
367-
controller: GuiHotColdController::Cold(wallet_rpc, command_handler),
368-
accounts: accounts_data,
369-
best_block,
370-
updated: false,
371-
};
372-
373-
(wallet_data, accounts_info, best_block)
354+
return Err(BackendError::ColdTrezorNotSupported)
374355
}
375356
(WalletType::Hot, ColdHotNodeController::Cold) => {
376357
return Err(BackendError::HotNotSupported)
@@ -577,32 +558,7 @@ impl Backend {
577558
}
578559
#[cfg(feature = "trezor")]
579560
(WalletType::Trezor, ColdHotNodeController::Cold) => {
580-
let client = make_cold_wallet_rpc_client(Arc::clone(&self.chain_config));
581-
582-
let (
583-
wallet_rpc,
584-
command_handler,
585-
encryption_state,
586-
best_block,
587-
accounts_info,
588-
accounts_data,
589-
) = self
590-
.open_wallet(
591-
client,
592-
file_path.clone(),
593-
wallet_events,
594-
Some(HardwareWalletType::Trezor),
595-
)
596-
.await?;
597-
598-
let wallet_data = WalletData {
599-
controller: GuiHotColdController::Cold(wallet_rpc, command_handler),
600-
accounts: accounts_data,
601-
best_block,
602-
updated: false,
603-
};
604-
605-
(wallet_data, accounts_info, best_block, encryption_state)
561+
return Err(BackendError::ColdTrezorNotSupported)
606562
}
607563
(WalletType::Hot, ColdHotNodeController::Cold) => {
608564
return Err(BackendError::HotNotSupported)

node-gui/backend/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub enum BackendError {
4141
ColdWallet,
4242
#[error("Cannot interact with a hot wallet when in Cold wallet mode")]
4343
HotNotSupported,
44+
#[error("Cannot use a Trezor wallet in a Cold wallet mode")]
45+
ColdTrezorNotSupported,
4446
#[error("Invalid console command: {0}")]
4547
InvalidConsoleCommand(String),
4648
#[error("Empty console command")]

node-gui/src/main_window/main_menu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,19 @@ fn make_menu_file<'a>(wallet_mode: WalletMode) -> Item<'a, MenuMessage, Theme, i
110110
WalletMode::Hot => {
111111
let menu = vec![
112112
menu_item(
113-
"Create new Hot wallet",
113+
"Create new Software wallet",
114114
MenuMessage::CreateNewWallet {
115115
wallet_type: WalletType::Hot,
116116
},
117117
),
118118
menu_item(
119-
"Recover Hot wallet",
119+
"Recover Software wallet",
120120
MenuMessage::RecoverWallet {
121121
wallet_type: WalletType::Hot,
122122
},
123123
),
124124
menu_item(
125-
"Open Hot wallet",
125+
"Open Software wallet",
126126
MenuMessage::OpenWallet {
127127
wallet_type: WalletType::Hot,
128128
},

node-gui/src/main_window/mod.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod main_widget;
5959
enum ActiveDialog {
6060
None,
6161
WalletCreate {
62-
generated_mnemonic: wallet_controller::mnemonic::Mnemonic,
62+
wallet_args: WalletArgs,
6363
wallet_type: WalletType,
6464
},
6565
WalletRecover {
@@ -148,7 +148,7 @@ pub struct MainWindow {
148148
wallet_msg: Option<WalletMessage>,
149149
}
150150

151-
#[derive(Debug, Clone)]
151+
#[derive(Debug, Clone, PartialEq, Eq)]
152152
pub enum WalletArgs {
153153
Software {
154154
mnemonic: String,
@@ -261,11 +261,20 @@ impl MainWindow {
261261
MainWindowMessage::MenuMessage(menu_message) => match menu_message {
262262
MenuMessage::NoOp => Command::none(),
263263
MenuMessage::CreateNewWallet { wallet_type } => {
264-
let generated_mnemonic =
265-
wallet_controller::mnemonic::generate_new_mnemonic(self.language);
264+
let wallet_args = match wallet_type {
265+
WalletType::Hot | WalletType::Cold => WalletArgs::Software {
266+
mnemonic: wallet_controller::mnemonic::generate_new_mnemonic(
267+
self.language,
268+
)
269+
.to_string(),
270+
},
271+
#[cfg(feature = "trezor")]
272+
WalletType::Trezor => WalletArgs::Trezor,
273+
};
274+
266275
self.active_dialog = ActiveDialog::WalletCreate {
267-
generated_mnemonic,
268276
wallet_type,
277+
wallet_args,
269278
};
270279
Command::none()
271280
}
@@ -786,13 +795,13 @@ impl MainWindow {
786795
ActiveDialog::None => Text::new("Nothing to show").into(),
787796

788797
ActiveDialog::WalletCreate {
789-
generated_mnemonic,
790798
wallet_type,
799+
wallet_args,
791800
} => {
792801
let wallet_type = *wallet_type;
793-
match wallet_type {
794-
WalletType::Hot | WalletType::Cold => wallet_mnemonic_dialog(
795-
Some(generated_mnemonic.clone()),
802+
match wallet_args {
803+
WalletArgs::Software { mnemonic } => wallet_mnemonic_dialog(
804+
Some(mnemonic.clone()),
796805
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
797806
args: WalletArgs::Software { mnemonic },
798807
import: ImportOrCreate::Create,
@@ -802,7 +811,7 @@ impl MainWindow {
802811
)
803812
.into(),
804813
#[cfg(feature = "trezor")]
805-
WalletType::Trezor => hw_wallet_create_dialog(
814+
WalletArgs::Trezor => hw_wallet_create_dialog(
806815
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
807816
args: WalletArgs::Trezor,
808817
import: ImportOrCreate::Create,

node-gui/src/widgets/create_hw_wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use crate::main_window::ImportOrCreate;
1716
use iced::{
1817
alignment::Horizontal,
1918
widget::{self, container, text, Button, Component, Text},
2019
Element, Length, Theme,
2120
};
2221
use iced_aw::Card;
22+
use node_gui_backend::ImportOrCreate;
2323

2424
pub struct CreateHwWalletDialog<Message> {
2525
on_import: Box<dyn Fn() -> Message>,

0 commit comments

Comments
 (0)