Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui/Cargo.lock

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

3 changes: 2 additions & 1 deletion gui/src/app/state/settings/bitcoind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
18 changes: 2 additions & 16 deletions gui/src/installer/step/node/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
};
Expand Down
19 changes: 19 additions & 0 deletions gui/src/node/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Loading