From b96bbc6929584fc81604deccc77ff4db0a61e21b Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Mon, 26 Feb 2024 15:03:25 +0100 Subject: [PATCH 1/5] chore: Depend on rust-dlc update adding closing txid --- Cargo.lock | 55 ++++++++++++++----------- Cargo.toml | 11 ++--- coordinator/src/collaborative_revert.rs | 1 + mobile/native/src/ln_dlc/mod.rs | 6 ++- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a02b66a8..2613c8720 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1292,7 +1292,7 @@ dependencies = [ [[package]] name = "dlc" version = "0.4.0" -source = "git+https://github.com/get10101/rust-dlc?rev=aa487662a8af75174bf0e60f24e07e171820d0c3#aa487662a8af75174bf0e60f24e07e171820d0c3" +source = "git+https://github.com/get10101/rust-dlc?rev=bc31c6167e304d7886c328da91e8c17dad1afce5#bc31c6167e304d7886c328da91e8c17dad1afce5" dependencies = [ "bitcoin", "miniscript 8.0.2", @@ -1304,7 +1304,7 @@ dependencies = [ [[package]] name = "dlc-manager" version = "0.4.0" -source = "git+https://github.com/get10101/rust-dlc?rev=aa487662a8af75174bf0e60f24e07e171820d0c3#aa487662a8af75174bf0e60f24e07e171820d0c3" +source = "git+https://github.com/get10101/rust-dlc?rev=bc31c6167e304d7886c328da91e8c17dad1afce5#bc31c6167e304d7886c328da91e8c17dad1afce5" dependencies = [ "async-trait", "bitcoin", @@ -1320,7 +1320,7 @@ dependencies = [ [[package]] name = "dlc-messages" version = "0.4.0" -source = "git+https://github.com/get10101/rust-dlc?rev=aa487662a8af75174bf0e60f24e07e171820d0c3#aa487662a8af75174bf0e60f24e07e171820d0c3" +source = "git+https://github.com/get10101/rust-dlc?rev=bc31c6167e304d7886c328da91e8c17dad1afce5#bc31c6167e304d7886c328da91e8c17dad1afce5" dependencies = [ "bitcoin", "dlc", @@ -1333,7 +1333,7 @@ dependencies = [ [[package]] name = "dlc-trie" version = "0.4.0" -source = "git+https://github.com/get10101/rust-dlc?rev=aa487662a8af75174bf0e60f24e07e171820d0c3#aa487662a8af75174bf0e60f24e07e171820d0c3" +source = "git+https://github.com/get10101/rust-dlc?rev=bc31c6167e304d7886c328da91e8c17dad1afce5#bc31c6167e304d7886c328da91e8c17dad1afce5" dependencies = [ "bitcoin", "dlc", @@ -2039,9 +2039,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -2130,9 +2130,9 @@ checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -2831,7 +2831,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p2pd-oracle-client" version = "0.1.0" -source = "git+https://github.com/get10101/rust-dlc?rev=aa487662a8af75174bf0e60f24e07e171820d0c3#aa487662a8af75174bf0e60f24e07e171820d0c3" +source = "git+https://github.com/get10101/rust-dlc?rev=bc31c6167e304d7886c328da91e8c17dad1afce5#bc31c6167e304d7886c328da91e8c17dad1afce5" dependencies = [ "chrono", "dlc-manager", @@ -2909,9 +2909,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "percent-encoding-rfc3986" @@ -4717,9 +4717,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -4822,9 +4822,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -4832,16 +4832,16 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -4859,9 +4859,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4869,22 +4869,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-streams" @@ -5230,3 +5230,8 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" + +[[patch.unused]] +name = "lightning-net-tokio" +version = "0.0.117" +source = "git+https://github.com/bonomat/rust-lightning-p2p-derivatives?rev=e49030e#e49030e785408f0fd4da077f63f8101cc0b2436e" diff --git a/Cargo.toml b/Cargo.toml index a6b5c037f..7af34d96a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,17 +20,18 @@ resolver = "2" # We are using our own fork of `rust-dlc` at least until we can drop all the LN-DLC features. Also, # `p2pderivatives/rust-dlc#master` is missing certain patches that can only be found in the LN-DLC # branch. -dlc-manager = { git = "https://github.com/get10101/rust-dlc", rev = "aa487662a8af75174bf0e60f24e07e171820d0c3" } -dlc-messages = { git = "https://github.com/get10101/rust-dlc", rev = "aa487662a8af75174bf0e60f24e07e171820d0c3" } -dlc = { git = "https://github.com/get10101/rust-dlc", rev = "aa487662a8af75174bf0e60f24e07e171820d0c3" } -p2pd-oracle-client = { git = "https://github.com/get10101/rust-dlc", rev = "aa487662a8af75174bf0e60f24e07e171820d0c3" } -dlc-trie = { git = "https://github.com/get10101/rust-dlc", rev = "aa487662a8af75174bf0e60f24e07e171820d0c3" } +dlc-manager = { git = "https://github.com/get10101/rust-dlc", rev = "bc31c6167e304d7886c328da91e8c17dad1afce5" } +dlc-messages = { git = "https://github.com/get10101/rust-dlc", rev = "bc31c6167e304d7886c328da91e8c17dad1afce5" } +dlc = { git = "https://github.com/get10101/rust-dlc", rev = "bc31c6167e304d7886c328da91e8c17dad1afce5" } +p2pd-oracle-client = { git = "https://github.com/get10101/rust-dlc", rev = "bc31c6167e304d7886c328da91e8c17dad1afce5" } +dlc-trie = { git = "https://github.com/get10101/rust-dlc", rev = "bc31c6167e304d7886c328da91e8c17dad1afce5" } # We should usually track the `p2pderivatives/split-tx-experiment[-10101]` branch. For now we depend # on a special fork which removes a panic in `rust-lightning`. lightning = { git = "https://github.com/bonomat/rust-lightning-p2p-derivatives", rev = "e49030e" } lightning-background-processor = { git = "https://github.com/bonomat/rust-lightning-p2p-derivatives", rev = "e49030e" } lightning-transaction-sync = { git = "https://github.com/bonomat/rust-lightning-p2p-derivatives", rev = "e49030e" } +lightning-net-tokio = { git = "https://github.com/bonomat/rust-lightning-p2p-derivatives", rev = "e49030e" } lightning-persister = { git = "https://github.com/bonomat/rust-lightning-p2p-derivatives", rev = "e49030e" } lightning-rapid-gossip-sync = { git = "https://github.com/bonomat/rust-lightning-p2p-derivatives", rev = "e49030e" } diff --git a/coordinator/src/collaborative_revert.rs b/coordinator/src/collaborative_revert.rs index 2ee9ee170..647631136 100644 --- a/coordinator/src/collaborative_revert.rs +++ b/coordinator/src/collaborative_revert.rs @@ -240,6 +240,7 @@ pub fn confirm_collaborative_revert( temporary_channel_id: signed_channel.temporary_channel_id, channel_id: signed_channel.channel_id, reference_id: None, + closing_txid: revert_transaction.txid(), }), // The contract doesn't matter anymore. None, diff --git a/mobile/native/src/ln_dlc/mod.rs b/mobile/native/src/ln_dlc/mod.rs index 2412fe250..e7f79abce 100644 --- a/mobile/native/src/ln_dlc/mod.rs +++ b/mobile/native/src/ln_dlc/mod.rs @@ -806,7 +806,7 @@ pub fn collaborative_revert_channel( let data = CollaborativeRevertTraderResponse { channel_id: channel_id_hex, - transaction: close_tx, + transaction: close_tx.clone(), signature: close_signature, }; @@ -831,7 +831,7 @@ pub fn collaborative_revert_channel( "Received response from confirming reverting a channel" ); if let Err(e) = - update_state_after_collab_revert(&signed_channel, execution_price) + update_state_after_collab_revert(&signed_channel, execution_price, close_tx.txid()) { tracing::error!( "Failed to update state after collaborative revert confirmation: {e:#}" @@ -857,6 +857,7 @@ pub fn collaborative_revert_channel( fn update_state_after_collab_revert( signed_channel: &SignedChannel, execution_price: Decimal, + closing_txid: Txid, ) -> Result<()> { let node = state::try_get_node().context("failed to get ln dlc node")?; let positions = db::get_positions()?; @@ -927,6 +928,7 @@ fn update_state_after_collab_revert( temporary_channel_id: signed_channel.temporary_channel_id, channel_id: signed_channel.channel_id, reference_id: None, + closing_txid, }), // The contract doesn't matter anymore None, From a17bd2051359638a5e46744fdb675de8111076ff Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Mon, 26 Feb 2024 15:04:09 +0100 Subject: [PATCH 2/5] feat: Add closing txid to dlc channels api --- .../ln-dlc-node/src/ln/dlc_channel_details.rs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/crates/ln-dlc-node/src/ln/dlc_channel_details.rs b/crates/ln-dlc-node/src/ln/dlc_channel_details.rs index 0d2352d5f..ddb0b1b53 100644 --- a/crates/ln-dlc-node/src/ln/dlc_channel_details.rs +++ b/crates/ln-dlc-node/src/ln/dlc_channel_details.rs @@ -1,5 +1,6 @@ use bitcoin::hashes::hex::ToHex; use bitcoin::secp256k1::PublicKey; +use dlc_manager::channel::signed_channel::SignedChannel; use dlc_manager::channel::Channel; use dlc_manager::DlcChannelId; use serde::Serialize; @@ -17,6 +18,7 @@ pub struct DlcChannelDetails { pub fee_rate_per_vb: Option, pub funding_txid: Option, pub funding_tx_vout: Option, + pub closing_txid: Option, } #[derive(Serialize, Debug, Ord, PartialOrd, Eq, PartialEq)] @@ -52,16 +54,52 @@ pub enum ChannelState { impl From for DlcChannelDetails { fn from(channel: Channel) -> Self { - let (update_idx, state, fee_rate_per_vb, funding_txid, funding_tx_vout) = + let (update_idx, state, fee_rate_per_vb, funding_txid, funding_tx_vout, closing_txid) = match channel.clone() { + Channel::Signed(SignedChannel { + update_idx, + fee_rate_per_vb, + fund_tx, + fund_output_index, + state: dlc_manager::channel::signed_channel::SignedChannelState::CollaborativeCloseOffered { + close_tx, + .. + }, + .. + }) => ( + Some(update_idx), + Some(SignedChannelState::CollaborativeCloseOffered), + Some(fee_rate_per_vb), + Some(fund_tx.txid().to_string()), + Some(fund_output_index), + Some(close_tx.txid().to_string())), Channel::Signed(signed_channel) => ( Some(signed_channel.update_idx), Some(SignedChannelState::from(signed_channel.state)), Some(signed_channel.fee_rate_per_vb), - Some(signed_channel.fund_tx.txid().to_hex()), + Some(signed_channel.fund_tx.txid().to_string()), Some(signed_channel.fund_output_index), + None, ), - _ => (None, None, None, None, None), + Channel::CollaborativelyClosed(closed_channel) + | Channel::Closed(closed_channel) + | Channel::CounterClosed(closed_channel) => ( + None, + None, + None, + None, + None, + Some(closed_channel.closing_txid.to_string()), + ), + Channel::Closing(closing_channel) => ( + None, + None, + None, + None, + None, + Some(closing_channel.buffer_transaction.txid().to_string()), + ), + _ => (None, None, None, None, None, None), }; DlcChannelDetails { @@ -73,6 +111,7 @@ impl From for DlcChannelDetails { fee_rate_per_vb, funding_txid, funding_tx_vout, + closing_txid, } } } From 3f5399a17a2cd05bd4b3799018b950b04c80967d Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Mon, 26 Feb 2024 15:06:03 +0100 Subject: [PATCH 3/5] feat(settings): Display closing txid in channels screen --- CHANGELOG.md | 3 +- .../common/dlc_channel_change_notifier.dart | 12 +++++- mobile/lib/common/domain/dlc_channel.dart | 37 ++++++++++++++----- .../lib/common/settings/channel_screen.dart | 14 ++++++- mobile/native/src/dlc_channel.rs | 33 ++++++++++++++--- 5 files changed, 79 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac21111c1..75f3f5230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Fix(wallet): Gracefully handle an error during the wallet sync. Fixes an issue where the app was not able to start because of an inconsistent state. +- Fix(wallet): Gracefully handle an error during the wallet sync. Fixes an issue where the app was not able to start because of an inconsistent state.ยด +- Feat: Show closing txid on closing and closed channels. ## [1.9.0] - 2024-02-26 diff --git a/mobile/lib/common/dlc_channel_change_notifier.dart b/mobile/lib/common/dlc_channel_change_notifier.dart index 2ade71742..31856b69a 100644 --- a/mobile/lib/common/dlc_channel_change_notifier.dart +++ b/mobile/lib/common/dlc_channel_change_notifier.dart @@ -64,13 +64,21 @@ class DlcChannelChangeNotifier extends ChangeNotifier { .toList(); } - List getAllOtherDlcChannels() { + List getAllClosedDlcChannels() { return channels .where((channel) => [ ChannelState.closed, ChannelState.counterClosed, - ChannelState.closedPunished, ChannelState.collaborativelyClosed, + ].contains(channel.state)) + .map((channel) => channel as ClosedDlcChannel) + .toList(); + } + + List getAllOtherDlcChannels() { + return channels + .where((channel) => [ + ChannelState.closedPunished, ChannelState.failedAccept, ChannelState.failedSign, ].contains(channel.state)) diff --git a/mobile/lib/common/domain/dlc_channel.dart b/mobile/lib/common/domain/dlc_channel.dart index 31c70c96c..1e873bc96 100644 --- a/mobile/lib/common/domain/dlc_channel.dart +++ b/mobile/lib/common/domain/dlc_channel.dart @@ -19,6 +19,7 @@ class DlcChannel { state: ChannelState.signed, contractId: signed.contractId, fundingTxid: signed.fundingTxid, + closingTxid: signed.closingTxid, signedState: SignedChannelState.fromApi(signed.state)); } case (bridge.ChannelState_Offered offered): @@ -39,26 +40,34 @@ class DlcChannel { case (bridge.ChannelState_Closing closing): { return ClosingDlcChannel( - id: dlcChannel.dlcChannelId, - state: ChannelState.closing, - contractId: closing.contractId, - bufferTxid: closing.bufferTxid); + id: dlcChannel.dlcChannelId, + state: ChannelState.closing, + contractId: closing.contractId, + bufferTxid: closing.bufferTxid, + ); } - case (bridge.ChannelState_Closed _): + case (bridge.ChannelState_Closed c): { - return DlcChannel(id: dlcChannel.dlcChannelId, state: ChannelState.closed); + return ClosedDlcChannel( + id: dlcChannel.dlcChannelId, state: ChannelState.closed, closingTxid: c.closingTxid); } - case (bridge.ChannelState_CounterClosed _): + case (bridge.ChannelState_CounterClosed c): { - return DlcChannel(id: dlcChannel.dlcChannelId, state: ChannelState.counterClosed); + return ClosedDlcChannel( + id: dlcChannel.dlcChannelId, + state: ChannelState.counterClosed, + closingTxid: c.closingTxid); } case (bridge.ChannelState_ClosedPunished _): { return DlcChannel(id: dlcChannel.dlcChannelId, state: ChannelState.closedPunished); } - case (bridge.ChannelState_CollaborativelyClosed _): + case (bridge.ChannelState_CollaborativelyClosed c): { - return DlcChannel(id: dlcChannel.dlcChannelId, state: ChannelState.collaborativelyClosed); + return ClosedDlcChannel( + id: dlcChannel.dlcChannelId, + state: ChannelState.collaborativelyClosed, + closingTxid: c.closingTxid); } case (bridge.ChannelState_FailedAccept _): { @@ -104,6 +113,7 @@ class AcceptedDlcChannel extends DlcChannel { class SignedDlcChannel extends DlcChannel { String? contractId; String fundingTxid; + String? closingTxid; SignedChannelState signedState; SignedDlcChannel( @@ -111,6 +121,7 @@ class SignedDlcChannel extends DlcChannel { required super.state, required this.contractId, required this.fundingTxid, + required this.closingTxid, required this.signedState}); @override @@ -135,6 +146,12 @@ class ClosingDlcChannel extends DlcChannel { } } +class ClosedDlcChannel extends DlcChannel { + String closingTxid; + + ClosedDlcChannel({required super.id, required super.state, required this.closingTxid}); +} + class CancelledDlcChannel extends DlcChannel { String contractId; diff --git a/mobile/lib/common/settings/channel_screen.dart b/mobile/lib/common/settings/channel_screen.dart index 8bb917327..c363c642e 100644 --- a/mobile/lib/common/settings/channel_screen.dart +++ b/mobile/lib/common/settings/channel_screen.dart @@ -46,6 +46,7 @@ class _ChannelScreenState extends State { ...dlcChannelChangeNotifier.getAllAcceptedDlcChannels(), ...dlcChannelChangeNotifier.getAllCancelledDlcChannels(), ...dlcChannelChangeNotifier.getAllClosingDlcChannels(), + ...dlcChannelChangeNotifier.getAllClosedDlcChannels(), ...dlcChannelChangeNotifier.getAllOtherDlcChannels() ]; @@ -147,6 +148,12 @@ class _ChannelScreenState extends State { style: TextStyle(fontSize: 17)), title: TransactionIdText(channel.fundingTxid), ), + channel.closingTxid != null + ? ListTile( + leading: const Text('Closing TxId', + style: TextStyle(fontSize: 17)), + title: TransactionIdText(channel.closingTxid!)) + : Container(), ], ); }).toList()), @@ -215,7 +222,12 @@ class ChannelsTile extends StatelessWidget { ? ListTile( leading: const Text('Buffer TxId', style: TextStyle(fontSize: 17)), title: TransactionIdText(channel.bufferTxid)) - : Container() + : Container(), + channel is ClosedDlcChannel + ? ListTile( + leading: const Text('Closing TxId', style: TextStyle(fontSize: 17)), + title: TransactionIdText(channel.closingTxid)) + : Container(), ], ); }).toList()), diff --git a/mobile/native/src/dlc_channel.rs b/mobile/native/src/dlc_channel.rs index df7905a0c..70f980574 100644 --- a/mobile/native/src/dlc_channel.rs +++ b/mobile/native/src/dlc_channel.rs @@ -1,4 +1,5 @@ use bitcoin::hashes::hex::ToHex; +use dlc_manager::channel::signed_channel::SignedChannel; use dlc_manager::channel::Channel; use flutter_rust_bridge::frb; @@ -17,20 +18,33 @@ impl From<&Channel> for DlcChannel { Channel::Accepted(a) => ChannelState::Accepted { contract_id: a.accepted_contract_id.to_hex(), }, + s @ Channel::Signed(SignedChannel { + state: dlc_manager::channel::signed_channel::SignedChannelState::CollaborativeCloseOffered { close_tx, .. }, + fund_tx, + fund_output_index, + .. + }) => ChannelState::Signed { + contract_id: s.get_contract_id().map(|c| c.to_hex()), + funding_txid: fund_tx.txid().to_hex(), + funding_tx_vout: *fund_output_index, + closing_txid: Some(close_tx.txid().to_hex()), + state: SignedChannelState::CollaborativeCloseOffered, + }, Channel::Signed(s) => ChannelState::Signed { contract_id: s.get_contract_id().map(|c| c.to_hex()), funding_txid: s.fund_tx.txid().to_hex(), funding_tx_vout: s.fund_output_index, + closing_txid: None, state: SignedChannelState::from(&s.state), }, Channel::Closing(c) => ChannelState::Closing { buffer_txid: c.buffer_transaction.txid().to_hex(), contract_id: c.contract_id.to_hex(), }, - Channel::Closed(_) => ChannelState::Closed, - Channel::CounterClosed(_) => ChannelState::CounterClosed, + Channel::Closed(c) => ChannelState::Closed{closing_txid: c.closing_txid.to_hex()}, + Channel::CounterClosed(c) => ChannelState::CounterClosed{closing_txid: c.closing_txid.to_hex()}, Channel::ClosedPunished(_) => ChannelState::ClosedPunished, - Channel::CollaborativelyClosed(_) => ChannelState::CollaborativelyClosed, + Channel::CollaborativelyClosed(c) => ChannelState::CollaborativelyClosed{closing_txid: c.closing_txid.to_hex()}, Channel::FailedAccept(_) => ChannelState::FailedAccept, Channel::FailedSign(_) => ChannelState::FailedSign, Channel::Cancelled(o) => ChannelState::Cancelled { @@ -76,16 +90,23 @@ pub enum ChannelState { contract_id: Option, funding_txid: String, funding_tx_vout: usize, + closing_txid: Option, state: SignedChannelState, }, Closing { contract_id: String, buffer_txid: String, }, - Closed, - CounterClosed, + Closed { + closing_txid: String, + }, + CounterClosed { + closing_txid: String, + }, ClosedPunished, - CollaborativelyClosed, + CollaborativelyClosed { + closing_txid: String, + }, FailedAccept, FailedSign, Cancelled { From e94d1c5d3b989c91a41174735f95fec53f6fc80a Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Tue, 27 Feb 2024 16:20:01 +0100 Subject: [PATCH 4/5] chore(settings): Formatted dlc and txid text. --- mobile/lib/common/settings/channel_screen.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mobile/lib/common/settings/channel_screen.dart b/mobile/lib/common/settings/channel_screen.dart index c363c642e..70513e17a 100644 --- a/mobile/lib/common/settings/channel_screen.dart +++ b/mobile/lib/common/settings/channel_screen.dart @@ -135,7 +135,7 @@ class _ChannelScreenState extends State { ), children: [ ListTile( - leading: const Text('Dlc Channel Id', + leading: const Text('DLC Channel Id', style: TextStyle(fontSize: 17)), title: IdText(id: channel.id, length: 8), ), @@ -144,13 +144,13 @@ class _ChannelScreenState extends State { style: TextStyle(fontSize: 17)), title: IdText(id: channel.contractId ?? "n/a")), ListTile( - leading: const Text('Funding TxId', + leading: const Text('Funding TXID', style: TextStyle(fontSize: 17)), title: TransactionIdText(channel.fundingTxid), ), channel.closingTxid != null ? ListTile( - leading: const Text('Closing TxId', + leading: const Text('Closing TXID', style: TextStyle(fontSize: 17)), title: TransactionIdText(channel.closingTxid!)) : Container(), @@ -210,7 +210,7 @@ class ChannelsTile extends StatelessWidget { title: Text(channel.state.toString()), children: [ ListTile( - leading: const Text('Dlc Channel Id', style: TextStyle(fontSize: 17)), + leading: const Text('DLC Channel Id', style: TextStyle(fontSize: 17)), title: IdText(id: channel.id)), Visibility( visible: channel.getContractId() != null, @@ -220,12 +220,12 @@ class ChannelsTile extends StatelessWidget { ), channel is ClosingDlcChannel ? ListTile( - leading: const Text('Buffer TxId', style: TextStyle(fontSize: 17)), + leading: const Text('Buffer TXID', style: TextStyle(fontSize: 17)), title: TransactionIdText(channel.bufferTxid)) : Container(), channel is ClosedDlcChannel ? ListTile( - leading: const Text('Closing TxId', style: TextStyle(fontSize: 17)), + leading: const Text('Closing TXID', style: TextStyle(fontSize: 17)), title: TransactionIdText(channel.closingTxid)) : Container(), ], From 0f03bd112cd22426e69cd68879071f1efb30f30b Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Wed, 28 Feb 2024 13:52:43 +0100 Subject: [PATCH 5/5] feat(webapp): Add close txid on closed channels --- webapp/src/api.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webapp/src/api.rs b/webapp/src/api.rs index 0dbb79940..bd1e9cf77 100644 --- a/webapp/src/api.rs +++ b/webapp/src/api.rs @@ -645,16 +645,17 @@ impl From<&dlc_manager::channel::Channel> for DlcChannel { dlc_manager::channel::Channel::Closed(c) => DlcChannel { dlc_channel_id: Some(c.channel_id.to_hex()), channel_state: Some(ChannelState::Closed), + close_txid: Some(c.closing_txid.to_hex()), ..DlcChannel::default() }, dlc_manager::channel::Channel::CounterClosed(c) => DlcChannel { dlc_channel_id: Some(c.channel_id.to_hex()), channel_state: Some(ChannelState::CounterClosed), + close_txid: Some(c.closing_txid.to_hex()), ..DlcChannel::default() }, dlc_manager::channel::Channel::ClosedPunished(c) => DlcChannel { dlc_channel_id: Some(c.channel_id.to_hex()), - channel_state: Some(ChannelState::ClosedPunished), punnish_txid: Some(c.punish_txid.to_hex()), ..DlcChannel::default() @@ -662,6 +663,7 @@ impl From<&dlc_manager::channel::Channel> for DlcChannel { dlc_manager::channel::Channel::CollaborativelyClosed(c) => DlcChannel { dlc_channel_id: Some(c.channel_id.to_hex()), channel_state: Some(ChannelState::CollaborativelyClosed), + close_txid: Some(c.closing_txid.to_hex()), ..DlcChannel::default() }, dlc_manager::channel::Channel::FailedAccept(_) => DlcChannel {