From dcfe935e96a5ae02b841c9f08636949ae3a192f5 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Thu, 7 Sep 2023 17:48:01 +0200 Subject: [PATCH] wip on RBF --- src/view/wallet/component.rs | 30 +++++++++++++++++++++++++++++- src/view/wallet/mod.rs | 2 ++ src/view/wallet/wallet.glade | 14 ++++++++++++++ src/view/wallet/widget.rs | 12 ++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/view/wallet/component.rs b/src/view/wallet/component.rs index 47ce2e0..0e4bc8a 100644 --- a/src/view/wallet/component.rs +++ b/src/view/wallet/component.rs @@ -17,7 +17,7 @@ use ::wallet::descriptors::InputDescriptor; use ::wallet::psbt::Psbt; use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR; use bitcoin::policy::DUST_RELAY_TX_FEE; -use bitcoin::{EcdsaSighashType, Sequence, Transaction, TxIn, TxOut}; +use bitcoin::{EcdsaSighashType, Sequence, Transaction, TxIn, TxOut, Witness}; use bitcoin_blockchain::locks::{LockTime, SeqNo}; use bitcoin_scripts::PubkeyScript; use bpro::psbt::McKeys; @@ -28,6 +28,7 @@ use gtk::{ApplicationWindow, ResponseType}; use relm::{init, Channel, Relm, StreamHandle, Update, Widget}; use wallet::hd::{SegmentIndexes, UnhardenedIndex}; use wallet::lex_order::lex_order::LexOrder; +use wallet::psbt::PsbtVersion; use super::pay::beneficiary_row::Beneficiary; use super::pay::FeeRate; @@ -359,6 +360,33 @@ impl Update for Component { .map(|stream| stream.emit(launch::Msg::About)); } Msg::Pay(msg) => self.update_pay(msg), + Msg::Rbf(txid) => { + let Some(entry) = self + .model + .wallet() + .history() + .iter() + .find(|entry| entry.tx.txid() == txid).cloned() + else { + return; + }; + let mut tx = entry.tx; + for input in &mut tx.input { + input.witness = Witness::new(); + } + let mut psbt = Psbt::with(tx, PsbtVersion::V0).unwrap(); + for (no, input) in psbt.inputs.iter_mut().enumerate() { + if let Some(info) = entry.debit.get(&(no as u32)) { + input. + } + } + self.launcher_stream.as_ref().map(|stream| { + stream.emit(launch::Msg::CreatePsbt( + psbt, + self.model.as_settings().network(), + )) + }); + } Msg::Settings => self.settings.emit(settings::Msg::View( self.model.to_settings(), self.model.path().clone(), diff --git a/src/view/wallet/mod.rs b/src/view/wallet/mod.rs index 9919816..625f387 100644 --- a/src/view/wallet/mod.rs +++ b/src/view/wallet/mod.rs @@ -16,6 +16,7 @@ mod widget; use std::collections::BTreeSet; +use bitcoin::Txid; use bpro::{ElectrumSec, ElectrumServer, Signer}; use relm::StreamHandle; pub(super) use view_model::ViewModel; @@ -39,6 +40,7 @@ pub enum Msg { Settings, Update(Vec, BTreeSet, ElectrumServer), Pay(pay::Msg), + Rbf(Txid), Fiat(Fiat), Refresh, InvoiceAmountToggle(bool), diff --git a/src/view/wallet/wallet.glade b/src/view/wallet/wallet.glade index 8278613..77a2a71 100644 --- a/src/view/wallet/wallet.glade +++ b/src/view/wallet/wallet.glade @@ -193,6 +193,20 @@ True + + + True + False + + + + + True + False + _Replace by fee + True + + diff --git a/src/view/wallet/widget.rs b/src/view/wallet/widget.rs index 69d6429..99a2350 100644 --- a/src/view/wallet/widget.rs +++ b/src/view/wallet/widget.rs @@ -13,7 +13,9 @@ use std::collections::BTreeSet; use std::ffi::OsStr; use baid58::Baid58; +use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::Hash; +use bitcoin::Txid; use bpro::{ AddressSummary, ElectrumSec, ElectrumServer, HistoryEntry, OnchainStatus, UtxoTxid, WalletState, }; @@ -108,6 +110,7 @@ pub struct Widgets { hist_copy_amount_mi: MenuItem, hist_copy_balance_mi: MenuItem, hist_copy_height_mi: MenuItem, + rbf_mi: MenuItem, address_menu: Menu, addr_copy_mi: MenuItem, @@ -253,6 +256,15 @@ impl Widgets { .set_text(&val.get::().unwrap().to_string()); } }); + let list = self.history_list.clone(); + let relm2 = relm.clone(); + self.rbf_mi.connect_activate(move |_| { + if let Some(iter) = list.selection().selected().map(|(_, iter)| iter) { + let val = list.model().unwrap().value(&iter, 1); + let txid = Txid::from_hex(val.get::<&str>().unwrap()).unwrap(); + relm2.stream().emit(Msg::Rbf(txid)); + } + }); let list = self.utxo_list.clone(); self.coin_copy_txid_mi.connect_activate(move |_| {