-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
757b53e cargo update -p liana (edouard) aeff735 fix unconfirmed payments layouts with labels (edouard) dbb9146 fix update labels for pending_txs (edouard) 9edcdd9 Add labels to change outputs according to main label (edouard) 2354ac9 cargo clippy --fix --lib -p liana_gui (edouard) 9db4541 Add labels support to gui (edouard) Pull request description: This PR use the lianad update_labels and get_labels commands. It also introduce new concepts from talks with Kevin and Antoine: - User spending is creating a payment, when he does not add multiple recipients anymore, he is doing multiple payment in one bitcoin transaction. - a transaction that have multiple outgoing outputs (multiple payment) is tagged as a 'Batch'. ACKs for top commit: edouardparis: Self-ACK 757b53e Tree-SHA512: 2208009fcc0ab8f587929a347d191d428156984e87b732fb6efa5f08a3962c85510c82fcdeba687a6d2bd2fa45f5a17384d8a9b709e1407ebbbe0f451fe69e90
- Loading branch information
Showing
28 changed files
with
1,591 additions
and
375 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use liana::miniscript::bitcoin; | ||
use std::str::FromStr; | ||
use std::{collections::HashMap, iter::IntoIterator, sync::Arc}; | ||
|
||
use crate::{ | ||
app::{error::Error, message::Message, view}, | ||
daemon::{ | ||
model::{LabelItem, Labelled}, | ||
Daemon, | ||
}, | ||
}; | ||
use iced::Command; | ||
use liana_ui::component::form; | ||
|
||
#[derive(Default)] | ||
pub struct LabelsEdited(HashMap<String, form::Value<String>>); | ||
|
||
impl LabelsEdited { | ||
pub fn cache(&self) -> &HashMap<String, form::Value<String>> { | ||
&self.0 | ||
} | ||
pub fn update<'a, T: IntoIterator<Item = &'a mut dyn Labelled>>( | ||
&mut self, | ||
daemon: Arc<dyn Daemon + Sync + Send>, | ||
message: Message, | ||
targets: T, | ||
) -> Result<Command<Message>, Error> { | ||
match message { | ||
Message::View(view::Message::Label(labelled, msg)) => match msg { | ||
view::LabelMessage::Edited(value) => { | ||
let valid = value.len() <= 100; | ||
if let Some(label) = self.0.get_mut(&labelled) { | ||
label.valid = valid; | ||
label.value = value; | ||
} else { | ||
self.0.insert(labelled, form::Value { valid, value }); | ||
} | ||
} | ||
view::LabelMessage::Cancel => { | ||
self.0.remove(&labelled); | ||
} | ||
view::LabelMessage::Confirm => { | ||
if let Some(label) = self.0.get(&labelled).cloned() { | ||
return Ok(Command::perform( | ||
async move { | ||
if let Some(item) = label_item_from_str(&labelled) { | ||
daemon.update_labels(&HashMap::from([( | ||
item, | ||
label.value.clone(), | ||
)]))?; | ||
} | ||
Ok(HashMap::from([(labelled, label.value)])) | ||
}, | ||
Message::LabelsUpdated, | ||
)); | ||
} | ||
} | ||
}, | ||
Message::LabelsUpdated(res) => match res { | ||
Ok(new_labels) => { | ||
for target in targets { | ||
target.load_labels(&new_labels); | ||
} | ||
for (labelled, _) in new_labels { | ||
self.0.remove(&labelled); | ||
} | ||
} | ||
Err(e) => { | ||
return Err(e); | ||
} | ||
}, | ||
_ => {} | ||
}; | ||
Ok(Command::none()) | ||
} | ||
} | ||
|
||
pub fn label_item_from_str(s: &str) -> Option<LabelItem> { | ||
if let Ok(addr) = bitcoin::Address::from_str(s) { | ||
Some(LabelItem::Address(addr.assume_checked())) | ||
} else if let Ok(txid) = bitcoin::Txid::from_str(s) { | ||
Some(LabelItem::Txid(txid)) | ||
} else if let Ok(outpoint) = bitcoin::OutPoint::from_str(s) { | ||
Some(LabelItem::OutPoint(outpoint)) | ||
} else { | ||
None | ||
} | ||
} |
Oops, something went wrong.