Merge #266: Check the address network during spend creation
9e1c16bc3fef5aa01a62cb34304cc161d4623468 Check the address network during spend creation (edouard)
Pull request description:
ACKs for top commit:
darosior:
utACK 9e1c16bc3fef5aa01a62cb34304cc161d4623468 check looks good to me
Tree-SHA512: 638d9d461230f487e8a150d02814baaa2a9c93ad2de339aa7f3f2436431276f41b4b833b7d5f2abdc505004fefd962d54596e581bfe732613f2765ef6d61260d
This commit is contained in:
commit
9f5308395c
@ -5,7 +5,9 @@ use std::sync::Arc;
|
||||
use iced::{Command, Element};
|
||||
use liana::{
|
||||
config::Config as DaemonConfig,
|
||||
miniscript::bitcoin::{self, util::psbt::Psbt, Address, Amount, Denomination, OutPoint},
|
||||
miniscript::bitcoin::{
|
||||
self, util::psbt::Psbt, Address, Amount, Denomination, Network, OutPoint,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -75,7 +77,7 @@ impl ChooseRecipients {
|
||||
impl Step for ChooseRecipients {
|
||||
fn update(
|
||||
&mut self,
|
||||
_daemon: Arc<dyn Daemon + Sync + Send>,
|
||||
daemon: Arc<dyn Daemon + Sync + Send>,
|
||||
_cache: &Cache,
|
||||
_draft: &TransactionDraft,
|
||||
message: Message,
|
||||
@ -89,7 +91,10 @@ impl Step for ChooseRecipients {
|
||||
self.recipients.remove(*i);
|
||||
}
|
||||
view::CreateSpendMessage::RecipientEdited(i, _, _) => {
|
||||
self.recipients.get_mut(*i).unwrap().update(msg);
|
||||
self.recipients
|
||||
.get_mut(*i)
|
||||
.unwrap()
|
||||
.update(daemon.config().bitcoin_config.network, msg);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -166,18 +171,20 @@ impl Recipient {
|
||||
&& self.amount.valid
|
||||
}
|
||||
|
||||
fn update(&mut self, message: view::CreateSpendMessage) {
|
||||
fn update(&mut self, network: Network, message: view::CreateSpendMessage) {
|
||||
match message {
|
||||
view::CreateSpendMessage::RecipientEdited(_, "address", address) => {
|
||||
self.address.value = address;
|
||||
if self.address.value.is_empty() {
|
||||
// Make the error disappear if we deleted the invalid address
|
||||
self.address.valid = true;
|
||||
} else if Address::from_str(&self.address.value).is_ok() {
|
||||
self.address.valid = true;
|
||||
if let Ok(address) = Address::from_str(&self.address.value) {
|
||||
self.address.valid = address.network == network
|
||||
|| (address.network == bitcoin::Network::Testnet
|
||||
&& network == bitcoin::Network::Signet);
|
||||
if !self.amount.value.is_empty() {
|
||||
self.amount.valid = self.amount().is_ok();
|
||||
}
|
||||
} else if self.address.value.is_empty() {
|
||||
// Make the error disappear if we deleted the invalid address
|
||||
self.address.valid = true;
|
||||
} else {
|
||||
self.address.valid = false;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ pub fn recipient_view<'a>(
|
||||
form::Form::new("Address", address, move |msg| {
|
||||
CreateSpendMessage::RecipientEdited(index, "address", msg)
|
||||
})
|
||||
.warning("Please enter correct bitcoin address")
|
||||
.warning("Please enter correct bitcoin address for the current network")
|
||||
.size(20)
|
||||
.padding(10),
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user