Skip to content

Commit b3bd09f

Browse files
committed
fix comments
1 parent 0801329 commit b3bd09f

File tree

32 files changed

+314
-354
lines changed

32 files changed

+314
-354
lines changed

Cargo.lock

+1-3
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

+6-6
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/signature/mod.rs

+8
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/src/backend/backend_impl.rs

+2-46
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/src/backend/error.rs

+2
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

+3-3
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

+19-10
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 {
@@ -163,7 +163,7 @@ impl ImportOrCreate {
163163
}
164164
}
165165

166-
#[derive(Debug, Clone)]
166+
#[derive(Debug, Clone, PartialEq, Eq)]
167167
pub enum WalletArgs {
168168
Software {
169169
mnemonic: String,
@@ -276,11 +276,20 @@ impl MainWindow {
276276
MainWindowMessage::MenuMessage(menu_message) => match menu_message {
277277
MenuMessage::NoOp => Command::none(),
278278
MenuMessage::CreateNewWallet { wallet_type } => {
279-
let generated_mnemonic =
280-
wallet_controller::mnemonic::generate_new_mnemonic(self.language);
279+
let wallet_args = match wallet_type {
280+
WalletType::Hot | WalletType::Cold => WalletArgs::Software {
281+
mnemonic: wallet_controller::mnemonic::generate_new_mnemonic(
282+
self.language,
283+
)
284+
.to_string(),
285+
},
286+
#[cfg(feature = "trezor")]
287+
WalletType::Trezor => WalletArgs::Trezor,
288+
};
289+
281290
self.active_dialog = ActiveDialog::WalletCreate {
282-
generated_mnemonic,
283291
wallet_type,
292+
wallet_args,
284293
};
285294
Command::none()
286295
}
@@ -801,13 +810,13 @@ impl MainWindow {
801810
ActiveDialog::None => Text::new("Nothing to show").into(),
802811

803812
ActiveDialog::WalletCreate {
804-
generated_mnemonic,
805813
wallet_type,
814+
wallet_args,
806815
} => {
807816
let wallet_type = *wallet_type;
808-
match wallet_type {
809-
WalletType::Hot | WalletType::Cold => wallet_mnemonic_dialog(
810-
Some(generated_mnemonic.clone()),
817+
match wallet_args {
818+
WalletArgs::Software { mnemonic } => wallet_mnemonic_dialog(
819+
Some(mnemonic.clone()),
811820
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
812821
args: WalletArgs::Software { mnemonic },
813822
import: ImportOrCreate::Create,
@@ -817,7 +826,7 @@ impl MainWindow {
817826
)
818827
.into(),
819828
#[cfg(feature = "trezor")]
820-
WalletType::Trezor => hw_wallet_create_dialog(
829+
WalletArgs::Trezor => hw_wallet_create_dialog(
821830
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
822831
args: WalletArgs::Trezor,
823832
import: ImportOrCreate::Create,

node-gui/src/widgets/wallet_mnemonic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ use iced::{
2121
use iced_aw::Card;
2222

2323
pub struct WalletMnemonicDialog<Message> {
24-
generated_mnemonic_opt: Option<wallet_controller::mnemonic::Mnemonic>,
24+
generated_mnemonic_opt: Option<String>,
2525
on_import: Box<dyn Fn(String) -> Message>,
2626
on_close: Box<dyn Fn() -> Message>,
2727
}
2828

2929
pub fn wallet_mnemonic_dialog<Message>(
30-
generated_mnemonic_opt: Option<wallet_controller::mnemonic::Mnemonic>,
30+
generated_mnemonic_opt: Option<String>,
3131
on_import: Box<dyn Fn(String) -> Message>,
3232
on_close: Box<dyn Fn() -> Message>,
3333
) -> WalletMnemonicDialog<Message> {
@@ -67,7 +67,7 @@ impl<Message> Component<Message, Theme, iced::Renderer> for WalletMnemonicDialog
6767
ImportEvent::Ok => {
6868
state.importing = true;
6969
let mnemonic = match &self.generated_mnemonic_opt {
70-
Some(generated_mnemonic) => generated_mnemonic.to_string(),
70+
Some(generated_mnemonic) => generated_mnemonic.clone(),
7171
None => state.entered_mnemonic.clone(),
7272
};
7373
Some((self.on_import)(mnemonic))
@@ -78,7 +78,7 @@ impl<Message> Component<Message, Theme, iced::Renderer> for WalletMnemonicDialog
7878

7979
fn view(&self, state: &Self::State) -> Element<Self::Event, Theme, iced::Renderer> {
8080
let (mnemonic, action_text) = match &self.generated_mnemonic_opt {
81-
Some(generated_mnemonic) => (generated_mnemonic.to_string(), "Create"),
81+
Some(generated_mnemonic) => (generated_mnemonic.clone(), "Create"),
8282
None => (state.entered_mnemonic.clone(), "Recover"),
8383
};
8484

wallet/src/send_request/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl SendRequest {
332332
}
333333
}
334334

335-
/// Find aditional data for TxOutput, mainly for UI purposes
335+
/// Find additional data for TxOutput, mainly for UI purposes
336336
fn find_additional_info(
337337
utxo: &TxOutput,
338338
additional_info: &BTreeMap<PoolOrTokenId, UtxoAdditionalInfo>,
@@ -388,7 +388,7 @@ fn find_token_additional_info(
388388
UtxoAdditionalInfo::TokenInfo(data) => Ok(Some(data.clone())),
389389
UtxoAdditionalInfo::PoolInfo { staker_balance: _ }
390390
| UtxoAdditionalInfo::CreateOrder { ask: _, give: _ } => {
391-
Err(WalletError::MissmatchedTokenAdditionalData(*token_id))
391+
Err(WalletError::MismatchedTokenAdditionalData(*token_id))
392392
}
393393
})?,
394394
}

wallet/src/signer/mod.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@
1515

1616
use std::sync::Arc;
1717

18-
use common::chain::{
19-
signature::{
20-
inputsig::{
21-
arbitrary_message::{ArbitraryMessageSignature, SignArbitraryMessageError},
22-
classical_multisig::multisig_partial_signature::PartiallySignedMultisigStructureError,
18+
use common::{
19+
address::AddressError,
20+
chain::{
21+
signature::{
22+
inputsig::{
23+
arbitrary_message::{ArbitraryMessageSignature, SignArbitraryMessageError},
24+
classical_multisig::multisig_partial_signature::PartiallySignedMultisigStructureError,
25+
},
26+
DestinationSigError,
2327
},
24-
DestinationSigError,
28+
ChainConfig, Destination,
2529
},
26-
ChainConfig, Destination,
2730
};
28-
use crypto::key::hdkd::{derivable::DerivationError, u31::U31};
31+
use crypto::key::{
32+
hdkd::{derivable::DerivationError, u31::U31},
33+
SignatureError,
34+
};
2935
use wallet_storage::{
3036
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
3137
};
@@ -80,6 +86,10 @@ pub enum SignerError {
8086
UnsupportedTokensV0,
8187
#[error("Invalid TxOutput type as UTXO, cannot be spent")]
8288
InvalidUtxo,
89+
#[error("Address error: {0}")]
90+
AddressError(#[from] AddressError),
91+
#[error("Signature error: {0}")]
92+
SignatureError(#[from] SignatureError),
8393
}
8494

8595
type SignerResult<T> = Result<T, SignerError>;

0 commit comments

Comments
 (0)