Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP on RBF #107

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/view/wallet/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/view/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +40,7 @@ pub enum Msg {
Settings,
Update(Vec<Signer>, BTreeSet<DescriptorClass>, ElectrumServer),
Pay(pay::Msg),
Rbf(Txid),
Fiat(Fiat),
Refresh,
InvoiceAmountToggle(bool),
Expand Down
14 changes: 14 additions & 0 deletions src/view/wallet/wallet.glade
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="rbf_mi">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_Replace by fee</property>
<property name="use-underline">True</property>
</object>
</child>
</object>
<object class="GtkListStore" id="history_store">
<columns>
Expand Down
12 changes: 12 additions & 0 deletions src/view/wallet/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -253,6 +256,15 @@ impl Widgets {
.set_text(&val.get::<u32>().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 |_| {
Expand Down