Merge #1319: gui(settings): add sanity check on electrum wallet address

f67ee76f57b199b7b826348143e40cba61f81c8d gui: update liana dependency commit hash (Michael Mallan)
bf25103fadfdef7912b0ef4e155000d65acd3ccc gui(settings): add sanity check on electrum wallet address (pythcoiner)

Pull request description:

  This is the first commit from #1303.

ACKs for top commit:
  edouardparis:
    ACK f67ee76f57b199b7b826348143e40cba61f81c8d

Tree-SHA512: 02c52039c42af1fbae549862a3c8971b8561ce6285674461a40b04ede5d7704b001b93705874ea466b0176b6a43c849b6070be0dbb0d32205abc1389ccbd2b4e
This commit is contained in:
edouardparis 2024-09-11 11:12:29 +02:00
commit a0bafa4cdc
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
4 changed files with 24 additions and 18 deletions

2
gui/Cargo.lock generated
View File

@ -2624,7 +2624,7 @@ dependencies = [
[[package]]
name = "liana"
version = "6.0.0"
source = "git+https://github.com/wizardsardine/liana?branch=master#c6e3053edf353bd9e234fab6942d02d72b99e196"
source = "git+https://github.com/wizardsardine/liana?branch=master#4dd0fd369265f49284e4a9a1c83fe27cdda55b9a"
dependencies = [
"backtrace",
"bdk_coin_select",

View File

@ -453,7 +453,8 @@ impl ElectrumSettings {
}
view::SettingsEditMessage::FieldEdited(field, value) => {
if !self.processing && field == "address" {
self.addr.value = value
self.addr.valid = crate::node::electrum::is_electrum_address_valid(&value);
self.addr.value = value;
}
}
view::SettingsEditMessage::Confirm => {

View File

@ -35,23 +35,9 @@ impl DefineElectrum {
match msg {
message::DefineElectrum::ConfigFieldEdited(field, value) => match field {
ConfigField::Address => {
let value_noprefix = if value.starts_with("ssl://") {
value.replacen("ssl://", "", 1)
} else {
value.replacen("tcp://", "", 1)
};
let noprefix_parts: Vec<_> = value_noprefix.split(':').collect();
self.address.value.clone_from(&value); // save the value including any prefix
self.address.valid = noprefix_parts.len() == 2
&& !noprefix_parts
.first()
.expect("there are two parts")
.is_empty()
&& noprefix_parts
.last()
.expect("there are two parts")
.parse::<u16>() // check it is a port
.is_ok();
self.address.valid =
crate::node::electrum::is_electrum_address_valid(&value);
}
},
};

View File

@ -12,3 +12,22 @@ impl fmt::Display for ConfigField {
}
}
}
pub fn is_electrum_address_valid(value: &str) -> bool {
let value_noprefix = if value.starts_with("ssl://") {
value.replacen("ssl://", "", 1)
} else {
value.replacen("tcp://", "", 1)
};
let noprefix_parts: Vec<_> = value_noprefix.split(':').collect();
noprefix_parts.len() == 2
&& !noprefix_parts
.first()
.expect("there are two parts")
.is_empty()
&& noprefix_parts
.last()
.expect("there are two parts")
.parse::<u16>() // check it is a port
.is_ok()
}