Skip to content

Commit

Permalink
gui: remove base64 dep
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Jan 22, 2024
1 parent c9bb7b0 commit 99bc44d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
11 changes: 5 additions & 6 deletions gui/Cargo.lock

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

1 change: 0 additions & 1 deletion gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async-hwi = { git = "https://github.com/wizardsardine/async-hwi", branch = "mast
liana = { git = "https://github.com/wizardsardine/liana", branch = "master", default-features = false, features = ["nonblocking_shutdown"] }
liana_ui = { path = "ui" }
backtrace = "0.3"
base64 = "0.13"
hex = "0.4.3"

iced = { version = "0.9", default-features= false, features = ["tokio", "glow", "svg", "qr_code", "image"] }
Expand Down
14 changes: 4 additions & 10 deletions gui/src/app/state/psbt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;

use iced::Subscription;
Expand Down Expand Up @@ -654,8 +655,7 @@ impl Action for UpdateAction {
Ok(()) => {
self.success = true;
self.error = None;
let psbt = Psbt::deserialize(&base64::decode(&self.updated.value).unwrap())
.expect("Already checked");
let psbt = Psbt::from_str(&self.updated.value).expect("Already checked");
for (i, input) in tx.psbt.inputs.iter_mut().enumerate() {
if tx
.psbt
Expand Down Expand Up @@ -688,21 +688,15 @@ impl Action for UpdateAction {
}
Message::View(view::Message::ImportSpend(view::ImportSpendMessage::PsbtEdited(s))) => {
self.updated.value = s;
if let Some(psbt) = base64::decode(&self.updated.value)
.ok()
.and_then(|bytes| Psbt::deserialize(&bytes).ok())
{
if let Ok(psbt) = Psbt::from_str(&self.updated.value) {
self.updated.valid = tx.psbt.unsigned_tx.txid() == psbt.unsigned_tx.txid();
}
}
Message::View(view::Message::ImportSpend(view::ImportSpendMessage::Confirm)) => {
if self.updated.valid {
self.processing = true;
self.error = None;
let updated = Psbt::deserialize(
&base64::decode(&self.updated.value).expect("Already checked"),
)
.unwrap();
let updated = Psbt::from_str(&self.updated.value).expect("Already checked");
return Command::perform(
async move { daemon.update_spend_tx(&updated).map_err(|e| e.into()) },
Message::Updated,
Expand Down
11 changes: 3 additions & 8 deletions gui/src/app/state/psbts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::str::FromStr;
use std::sync::Arc;

use iced::{Command, Subscription};
Expand Down Expand Up @@ -190,19 +191,13 @@ impl ImportPsbtModal {
}
Message::View(view::Message::ImportSpend(view::ImportSpendMessage::PsbtEdited(s))) => {
self.imported.value = s;
self.imported.valid = base64::decode(&self.imported.value)
.ok()
.and_then(|bytes| Psbt::deserialize(&bytes).ok())
.is_some();
self.imported.valid = Psbt::from_str(&self.imported.value).ok().is_some();
}
Message::View(view::Message::ImportSpend(view::ImportSpendMessage::Confirm)) => {
if self.imported.valid {
self.processing = true;
self.error = None;
let imported = Psbt::deserialize(
&base64::decode(&self.imported.value).expect("Already checked"),
)
.unwrap();
let imported = Psbt::from_str(&self.imported.value).expect("Already checked");
return Command::perform(
async move { daemon.update_spend_tx(&imported).map_err(|e| e.into()) },
Message::Updated,
Expand Down
2 changes: 1 addition & 1 deletion gui/src/daemon/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<C: Client + Debug> Daemon for Lianad<C> {
}

fn update_spend_tx(&self, psbt: &Psbt) -> Result<(), DaemonError> {
let spend_tx = base64::encode(psbt.serialize());
let spend_tx = psbt.to_string();
let _res: serde_json::value::Value = self.call("updatespend", Some(vec![spend_tx]))?;
Ok(())
}
Expand Down

0 comments on commit 99bc44d

Please sign in to comment.