Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Dec 4, 2024
1 parent 0801329 commit b3bd09f
Show file tree
Hide file tree
Showing 32 changed files with 314 additions and 354 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions common/src/chain/tokens/tokens_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ pub fn is_token_or_nft_issuance(output: &TxOutput) -> bool {
}
}

/// Get any referenced token by this output
/// Get any token referenced by this output
/// ignore tokens V0
pub fn get_referenced_token_ids(output: &TxOutput) -> BTreeSet<TokenId> {
match output {
TxOutput::Transfer(v, _)
| TxOutput::LockThenTransfer(v, _, _)
| TxOutput::Burn(v)
| TxOutput::Htlc(v, _) => referenced_token_id(v),
| TxOutput::Htlc(v, _) => referenced_token_id(v).into_iter().collect(),
| TxOutput::CreateOrder(data) => {
let mut tokens = referenced_token_id(data.ask());
let mut tokens: BTreeSet<_> = referenced_token_id(data.ask()).into_iter().collect();
tokens.extend(referenced_token_id(data.give()));
tokens
}
Expand All @@ -114,9 +114,9 @@ pub fn get_referenced_token_ids(output: &TxOutput) -> BTreeSet<TokenId> {
}
}

fn referenced_token_id(v: &OutputValue) -> BTreeSet<TokenId> {
fn referenced_token_id(v: &OutputValue) -> Option<TokenId> {
match v {
OutputValue::Coin(_) | OutputValue::TokenV0(_) => BTreeSet::new(),
OutputValue::TokenV1(token_id, _) => BTreeSet::from_iter([*token_id]),
OutputValue::Coin(_) | OutputValue::TokenV0(_) => None,
OutputValue::TokenV1(token_id, _) => Some(*token_id),
}
}
8 changes: 8 additions & 0 deletions crypto/src/key/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::io::BufWriter;
use num_derive::FromPrimitive;
use serialization::{hex_encoded::HexEncoded, Decode, DecodeAll, Encode};

use super::SignatureError;

#[derive(FromPrimitive)]
pub enum SignatureKind {
Secp256k1Schnorr = 0,
Expand Down Expand Up @@ -77,6 +79,12 @@ impl Signature {
Ok(decoded_sig)
}

pub fn from_raw_data<T: AsRef<[u8]>>(data: T) -> Result<Self, SignatureError> {
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
.map_err(|_| SignatureError::SignatureConstructionError)?;
Ok(Self::Secp256k1Schnorr(decoded_sig))
}

pub fn is_aggregable(&self) -> bool {
match self {
Self::Secp256k1Schnorr(_) => false,
Expand Down
48 changes: 2 additions & 46 deletions node-gui/src/backend/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,26 +351,7 @@ impl Backend {
}
#[cfg(feature = "trezor")]
(WalletType::Trezor, ColdHotNodeController::Cold) => {
let client = make_cold_wallet_rpc_client(Arc::clone(&self.chain_config));

let (wallet_rpc, command_handler, best_block, accounts_info, accounts_data) = self
.create_wallet(
client,
file_path.clone(),
wallet_args,
import,
wallet_events,
)
.await?;

let wallet_data = WalletData {
controller: GuiHotColdController::Cold(wallet_rpc, command_handler),
accounts: accounts_data,
best_block,
updated: false,
};

(wallet_data, accounts_info, best_block)
return Err(BackendError::ColdTrezorNotSupported)
}
(WalletType::Hot, ColdHotNodeController::Cold) => {
return Err(BackendError::HotNotSupported)
Expand Down Expand Up @@ -577,32 +558,7 @@ impl Backend {
}
#[cfg(feature = "trezor")]
(WalletType::Trezor, ColdHotNodeController::Cold) => {
let client = make_cold_wallet_rpc_client(Arc::clone(&self.chain_config));

let (
wallet_rpc,
command_handler,
encryption_state,
best_block,
accounts_info,
accounts_data,
) = self
.open_wallet(
client,
file_path.clone(),
wallet_events,
Some(HardwareWalletType::Trezor),
)
.await?;

let wallet_data = WalletData {
controller: GuiHotColdController::Cold(wallet_rpc, command_handler),
accounts: accounts_data,
best_block,
updated: false,
};

(wallet_data, accounts_info, best_block, encryption_state)
return Err(BackendError::ColdTrezorNotSupported)
}
(WalletType::Hot, ColdHotNodeController::Cold) => {
return Err(BackendError::HotNotSupported)
Expand Down
2 changes: 2 additions & 0 deletions node-gui/src/backend/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum BackendError {
ColdWallet,
#[error("Cannot interact with a hot wallet when in Cold wallet mode")]
HotNotSupported,
#[error("Cannot use a Trezor wallet in a Cold wallet mode")]
ColdTrezorNotSupported,
#[error("Invalid console command: {0}")]
InvalidConsoleCommand(String),
#[error("Empty console command")]
Expand Down
6 changes: 3 additions & 3 deletions node-gui/src/main_window/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ fn make_menu_file<'a>(wallet_mode: WalletMode) -> Item<'a, MenuMessage, Theme, i
WalletMode::Hot => {
let menu = vec![
menu_item(
"Create new Hot wallet",
"Create new Software wallet",
MenuMessage::CreateNewWallet {
wallet_type: WalletType::Hot,
},
),
menu_item(
"Recover Hot wallet",
"Recover Software wallet",
MenuMessage::RecoverWallet {
wallet_type: WalletType::Hot,
},
),
menu_item(
"Open Hot wallet",
"Open Software wallet",
MenuMessage::OpenWallet {
wallet_type: WalletType::Hot,
},
Expand Down
29 changes: 19 additions & 10 deletions node-gui/src/main_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod main_widget;
enum ActiveDialog {
None,
WalletCreate {
generated_mnemonic: wallet_controller::mnemonic::Mnemonic,
wallet_args: WalletArgs,
wallet_type: WalletType,
},
WalletRecover {
Expand Down Expand Up @@ -163,7 +163,7 @@ impl ImportOrCreate {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WalletArgs {
Software {
mnemonic: String,
Expand Down Expand Up @@ -276,11 +276,20 @@ impl MainWindow {
MainWindowMessage::MenuMessage(menu_message) => match menu_message {
MenuMessage::NoOp => Command::none(),
MenuMessage::CreateNewWallet { wallet_type } => {
let generated_mnemonic =
wallet_controller::mnemonic::generate_new_mnemonic(self.language);
let wallet_args = match wallet_type {
WalletType::Hot | WalletType::Cold => WalletArgs::Software {
mnemonic: wallet_controller::mnemonic::generate_new_mnemonic(
self.language,
)
.to_string(),
},
#[cfg(feature = "trezor")]
WalletType::Trezor => WalletArgs::Trezor,
};

self.active_dialog = ActiveDialog::WalletCreate {
generated_mnemonic,
wallet_type,
wallet_args,
};
Command::none()
}
Expand Down Expand Up @@ -801,13 +810,13 @@ impl MainWindow {
ActiveDialog::None => Text::new("Nothing to show").into(),

ActiveDialog::WalletCreate {
generated_mnemonic,
wallet_type,
wallet_args,
} => {
let wallet_type = *wallet_type;
match wallet_type {
WalletType::Hot | WalletType::Cold => wallet_mnemonic_dialog(
Some(generated_mnemonic.clone()),
match wallet_args {
WalletArgs::Software { mnemonic } => wallet_mnemonic_dialog(
Some(mnemonic.clone()),
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Software { mnemonic },
import: ImportOrCreate::Create,
Expand All @@ -817,7 +826,7 @@ impl MainWindow {
)
.into(),
#[cfg(feature = "trezor")]
WalletType::Trezor => hw_wallet_create_dialog(
WalletArgs::Trezor => hw_wallet_create_dialog(
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Trezor,
import: ImportOrCreate::Create,
Expand Down
8 changes: 4 additions & 4 deletions node-gui/src/widgets/wallet_mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use iced::{
use iced_aw::Card;

pub struct WalletMnemonicDialog<Message> {
generated_mnemonic_opt: Option<wallet_controller::mnemonic::Mnemonic>,
generated_mnemonic_opt: Option<String>,
on_import: Box<dyn Fn(String) -> Message>,
on_close: Box<dyn Fn() -> Message>,
}

pub fn wallet_mnemonic_dialog<Message>(
generated_mnemonic_opt: Option<wallet_controller::mnemonic::Mnemonic>,
generated_mnemonic_opt: Option<String>,
on_import: Box<dyn Fn(String) -> Message>,
on_close: Box<dyn Fn() -> Message>,
) -> WalletMnemonicDialog<Message> {
Expand Down Expand Up @@ -67,7 +67,7 @@ impl<Message> Component<Message, Theme, iced::Renderer> for WalletMnemonicDialog
ImportEvent::Ok => {
state.importing = true;
let mnemonic = match &self.generated_mnemonic_opt {
Some(generated_mnemonic) => generated_mnemonic.to_string(),
Some(generated_mnemonic) => generated_mnemonic.clone(),
None => state.entered_mnemonic.clone(),
};
Some((self.on_import)(mnemonic))
Expand All @@ -78,7 +78,7 @@ impl<Message> Component<Message, Theme, iced::Renderer> for WalletMnemonicDialog

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

Expand Down
4 changes: 2 additions & 2 deletions wallet/src/send_request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl SendRequest {
}
}

/// Find aditional data for TxOutput, mainly for UI purposes
/// Find additional data for TxOutput, mainly for UI purposes
fn find_additional_info(
utxo: &TxOutput,
additional_info: &BTreeMap<PoolOrTokenId, UtxoAdditionalInfo>,
Expand Down Expand Up @@ -388,7 +388,7 @@ fn find_token_additional_info(
UtxoAdditionalInfo::TokenInfo(data) => Ok(Some(data.clone())),
UtxoAdditionalInfo::PoolInfo { staker_balance: _ }
| UtxoAdditionalInfo::CreateOrder { ask: _, give: _ } => {
Err(WalletError::MissmatchedTokenAdditionalData(*token_id))
Err(WalletError::MismatchedTokenAdditionalData(*token_id))
}
})?,
}
Expand Down
26 changes: 18 additions & 8 deletions wallet/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@

use std::sync::Arc;

use common::chain::{
signature::{
inputsig::{
arbitrary_message::{ArbitraryMessageSignature, SignArbitraryMessageError},
classical_multisig::multisig_partial_signature::PartiallySignedMultisigStructureError,
use common::{
address::AddressError,
chain::{
signature::{
inputsig::{
arbitrary_message::{ArbitraryMessageSignature, SignArbitraryMessageError},
classical_multisig::multisig_partial_signature::PartiallySignedMultisigStructureError,
},
DestinationSigError,
},
DestinationSigError,
ChainConfig, Destination,
},
ChainConfig, Destination,
};
use crypto::key::hdkd::{derivable::DerivationError, u31::U31};
use crypto::key::{
hdkd::{derivable::DerivationError, u31::U31},
SignatureError,
};
use wallet_storage::{
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
};
Expand Down Expand Up @@ -80,6 +86,10 @@ pub enum SignerError {
UnsupportedTokensV0,
#[error("Invalid TxOutput type as UTXO, cannot be spent")]
InvalidUtxo,
#[error("Address error: {0}")]
AddressError(#[from] AddressError),
#[error("Signature error: {0}")]
SignatureError(#[from] SignatureError),
}

type SignerResult<T> = Result<T, SignerError>;
Expand Down
Loading

0 comments on commit b3bd09f

Please sign in to comment.