parent
2f50c55f79
commit
24f67d2a85
@ -1241,6 +1241,7 @@ pub struct ImportDescriptor {
|
|||||||
change_network: bool,
|
change_network: bool,
|
||||||
data_dir: Option<PathBuf>,
|
data_dir: Option<PathBuf>,
|
||||||
imported_descriptor: form::Value<String>,
|
imported_descriptor: form::Value<String>,
|
||||||
|
wrong_network: bool,
|
||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1252,21 +1253,35 @@ impl ImportDescriptor {
|
|||||||
network_valid: true,
|
network_valid: true,
|
||||||
data_dir: None,
|
data_dir: None,
|
||||||
imported_descriptor: form::Value::default(),
|
imported_descriptor: form::Value::default(),
|
||||||
|
wrong_network: false,
|
||||||
error: None,
|
error: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_descriptor(&mut self) {
|
fn check_descriptor(&mut self, network: Network) -> Option<LianaDescriptor> {
|
||||||
if !self.imported_descriptor.value.is_empty() {
|
if !self.imported_descriptor.value.is_empty() {
|
||||||
if let Ok(desc) = LianaDescriptor::from_str(&self.imported_descriptor.value) {
|
if let Ok(desc) = LianaDescriptor::from_str(&self.imported_descriptor.value) {
|
||||||
if self.network == Network::Bitcoin {
|
if network == Network::Bitcoin {
|
||||||
self.imported_descriptor.valid = desc.all_xpubs_net_is(self.network);
|
self.imported_descriptor.valid = desc.all_xpubs_net_is(network);
|
||||||
} else {
|
} else {
|
||||||
self.imported_descriptor.valid = desc.all_xpubs_net_is(Network::Testnet);
|
self.imported_descriptor.valid = desc.all_xpubs_net_is(Network::Testnet);
|
||||||
}
|
}
|
||||||
|
if self.imported_descriptor.valid {
|
||||||
|
self.wrong_network = false;
|
||||||
|
Some(desc)
|
||||||
|
} else {
|
||||||
|
self.wrong_network = true;
|
||||||
|
None
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.imported_descriptor.valid = false;
|
self.imported_descriptor.valid = false;
|
||||||
|
self.wrong_network = false;
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.wrong_network = false;
|
||||||
|
self.imported_descriptor.valid = true;
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1281,11 +1296,11 @@ impl Step for ImportDescriptor {
|
|||||||
let mut network_datadir = self.data_dir.clone().unwrap();
|
let mut network_datadir = self.data_dir.clone().unwrap();
|
||||||
network_datadir.push(self.network.to_string());
|
network_datadir.push(self.network.to_string());
|
||||||
self.network_valid = !network_datadir.exists();
|
self.network_valid = !network_datadir.exists();
|
||||||
self.check_descriptor();
|
self.check_descriptor(self.network);
|
||||||
}
|
}
|
||||||
Message::DefineDescriptor(message::DefineDescriptor::ImportDescriptor(desc)) => {
|
Message::DefineDescriptor(message::DefineDescriptor::ImportDescriptor(desc)) => {
|
||||||
self.imported_descriptor.value = desc;
|
self.imported_descriptor.value = desc;
|
||||||
self.check_descriptor();
|
self.check_descriptor(self.network);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
@ -1293,6 +1308,9 @@ impl Step for ImportDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_context(&mut self, ctx: &Context) {
|
fn load_context(&mut self, ctx: &Context) {
|
||||||
|
if ctx.bitcoin_config.network != self.network {
|
||||||
|
self.check_descriptor(ctx.bitcoin_config.network);
|
||||||
|
}
|
||||||
self.network = ctx.bitcoin_config.network;
|
self.network = ctx.bitcoin_config.network;
|
||||||
self.data_dir = Some(ctx.data_dir.clone());
|
self.data_dir = Some(ctx.data_dir.clone());
|
||||||
let mut network_datadir = ctx.data_dir.clone();
|
let mut network_datadir = ctx.data_dir.clone();
|
||||||
@ -1305,23 +1323,9 @@ impl Step for ImportDescriptor {
|
|||||||
// Set to true in order to force the registration process to be shown to user.
|
// Set to true in order to force the registration process to be shown to user.
|
||||||
ctx.hw_is_used = true;
|
ctx.hw_is_used = true;
|
||||||
// descriptor forms for import or creation cannot be both empty or filled.
|
// descriptor forms for import or creation cannot be both empty or filled.
|
||||||
if !self.imported_descriptor.value.is_empty() {
|
if let Some(desc) = self.check_descriptor(self.network) {
|
||||||
if let Ok(desc) = LianaDescriptor::from_str(&self.imported_descriptor.value) {
|
ctx.descriptor = Some(desc);
|
||||||
if self.network == Network::Bitcoin {
|
true
|
||||||
self.imported_descriptor.valid = desc.all_xpubs_net_is(self.network);
|
|
||||||
} else {
|
|
||||||
self.imported_descriptor.valid = desc.all_xpubs_net_is(Network::Testnet);
|
|
||||||
}
|
|
||||||
if self.imported_descriptor.valid {
|
|
||||||
ctx.descriptor = Some(desc);
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.imported_descriptor.valid = false;
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@ -1334,6 +1338,7 @@ impl Step for ImportDescriptor {
|
|||||||
self.network,
|
self.network,
|
||||||
self.network_valid,
|
self.network_valid,
|
||||||
&self.imported_descriptor,
|
&self.imported_descriptor,
|
||||||
|
self.wrong_network,
|
||||||
self.error.as_ref(),
|
self.error.as_ref(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -364,6 +364,7 @@ pub fn import_descriptor<'a>(
|
|||||||
network: bitcoin::Network,
|
network: bitcoin::Network,
|
||||||
network_valid: bool,
|
network_valid: bool,
|
||||||
imported_descriptor: &form::Value<String>,
|
imported_descriptor: &form::Value<String>,
|
||||||
|
wrong_network: bool,
|
||||||
error: Option<&String>,
|
error: Option<&String>,
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
let row_network = Row::new()
|
let row_network = Row::new()
|
||||||
@ -392,7 +393,11 @@ pub fn import_descriptor<'a>(
|
|||||||
form::Form::new_trimmed("Descriptor", imported_descriptor, |msg| {
|
form::Form::new_trimmed("Descriptor", imported_descriptor, |msg| {
|
||||||
Message::DefineDescriptor(message::DefineDescriptor::ImportDescriptor(msg))
|
Message::DefineDescriptor(message::DefineDescriptor::ImportDescriptor(msg))
|
||||||
})
|
})
|
||||||
.warning("Incompatible descriptor.")
|
.warning(if wrong_network {
|
||||||
|
"The descriptor is for another network"
|
||||||
|
} else {
|
||||||
|
"Failed to read the descriptor"
|
||||||
|
})
|
||||||
.size(20)
|
.size(20)
|
||||||
.padding(10),
|
.padding(10),
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user