From 99bc44d2b17264e87d80ccada51a4568efbcba3e Mon Sep 17 00:00:00 2001 From: edouardparis Date: Thu, 11 Jan 2024 15:49:49 +0100 Subject: [PATCH] gui: remove base64 dep --- gui/Cargo.lock | 11 +++++------ gui/Cargo.toml | 1 - gui/src/app/state/psbt.rs | 14 ++++---------- gui/src/app/state/psbts.rs | 11 +++-------- gui/src/daemon/client/mod.rs | 2 +- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/gui/Cargo.lock b/gui/Cargo.lock index 0d738567e..4a5c116aa 100644 --- a/gui/Cargo.lock +++ b/gui/Cargo.lock @@ -282,9 +282,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.0" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" [[package]] name = "base64-compat" @@ -2642,7 +2642,6 @@ version = "4.0.0" dependencies = [ "async-hwi", "backtrace", - "base64 0.13.1", "bitcoin_hashes 0.12.0", "chrono", "dirs 3.0.2", @@ -3932,7 +3931,7 @@ version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.0", + "base64 0.21.6", "bytes", "encoding_rs", "futures-core", @@ -4118,7 +4117,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.0", + "base64 0.21.6", ] [[package]] @@ -5056,7 +5055,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b6bb4e62619d9f68aa2d8a823fea2bff302340a1f2d45c264d5b0be170832e" dependencies = [ - "base64 0.21.0", + "base64 0.21.6", "data-url", "flate2", "imagesize", diff --git a/gui/Cargo.toml b/gui/Cargo.toml index b21bf3813..f0c025c2f 100644 --- a/gui/Cargo.toml +++ b/gui/Cargo.toml @@ -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"] } diff --git a/gui/src/app/state/psbt.rs b/gui/src/app/state/psbt.rs index 623a3a728..9e8632ed9 100644 --- a/gui/src/app/state/psbt.rs +++ b/gui/src/app/state/psbt.rs @@ -1,5 +1,6 @@ use std::collections::{HashMap, HashSet}; use std::path::PathBuf; +use std::str::FromStr; use std::sync::Arc; use iced::Subscription; @@ -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 @@ -688,10 +688,7 @@ 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(); } } @@ -699,10 +696,7 @@ impl Action for UpdateAction { 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, diff --git a/gui/src/app/state/psbts.rs b/gui/src/app/state/psbts.rs index 04458271e..943eb6b2b 100644 --- a/gui/src/app/state/psbts.rs +++ b/gui/src/app/state/psbts.rs @@ -1,3 +1,4 @@ +use std::str::FromStr; use std::sync::Arc; use iced::{Command, Subscription}; @@ -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, diff --git a/gui/src/daemon/client/mod.rs b/gui/src/daemon/client/mod.rs index e34f8ed5c..7f7670bcd 100644 --- a/gui/src/daemon/client/mod.rs +++ b/gui/src/daemon/client/mod.rs @@ -110,7 +110,7 @@ impl Daemon for Lianad { } 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(()) }