Skip to content

Commit

Permalink
Merge pull request #20 from get10101/fix/settle-tx-input
Browse files Browse the repository at this point in the history
Use correct input in settle claim transaction
  • Loading branch information
luckysori authored Oct 23, 2024
2 parents 8f65a0b + 41f34a3 commit 81090c4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 0 additions & 2 deletions dlc-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,6 @@ pub fn finalize_unilateral_close_settled_channel<S: Deref>(
destination_address: &Address,
fee_rate_per_vb: u64,
signer: &S,
is_offer: bool,
is_initiator: bool,
) -> Result<(Transaction, Channel), Error>
where
Expand Down Expand Up @@ -2892,7 +2891,6 @@ where
CET_NSEQUENCE,
0,
fee_rate_per_vb,
is_offer,
)?;

let closing_channel = SettledClosingChannel {
Expand Down
8 changes: 2 additions & 6 deletions dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,11 +1298,10 @@ where
&self,
signed_channel: SignedChannel,
) -> Result<(), Error> {
let (settle_tx, &is_offer, &is_initiator) = get_signed_channel_state!(
let (settle_tx, &is_initiator) = get_signed_channel_state!(
signed_channel,
SettledClosing,
settle_transaction,
is_offer,
is_initiator
)?;

Expand All @@ -1312,11 +1311,9 @@ where
>= CET_NSEQUENCE
{
log::info!(
"Settle transaction {} for channel {} has enough confirmations to spend from it. is_offer={}, is_initiator={}",
"Settle transaction {} for channel {} has enough confirmations to spend from it",
settle_tx.txid(),
serialize_hex(&signed_channel.channel_id),
is_offer,
is_initiator
);

let fee_rate_per_vb: u64 = {
Expand All @@ -1338,7 +1335,6 @@ where
&self.wallet.get_new_address()?,
fee_rate_per_vb,
&self.wallet,
is_offer,
is_initiator,
)?;

Expand Down
18 changes: 11 additions & 7 deletions dlc/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,27 +415,31 @@ pub fn create_and_sign_claim_settle_transaction<C: Signing>(
csv_timelock: u32,
lock_time: u32,
fee_rate_per_vb: u64,
is_offer: bool,
) -> Result<Transaction, Error> {
let own_descriptor = settle_descriptor(own_params, &counter_params.own_pk, csv_timelock);

let vout = if is_offer {
0
} else {
1
let output = settle_tx.output.iter().enumerate().find(|(_, output)| {
output.script_pubkey == own_descriptor.script_pubkey()
});

let (vout, output) = match output {
Some((vout, output)) => (vout, output),
None => {
return Err(Error::InvalidArgument("No claimable output found on settle transaction".to_string()));
},
};

let tx_in = TxIn {
previous_output: OutPoint {
txid: settle_tx.txid(),
vout,
vout: vout as u32,
},
sequence: Sequence::from_height(csv_timelock as u16),
script_sig: Script::default(),
witness: Witness::default(),
};

let input_value = settle_tx.output[vout as usize].value;
let input_value = output.value;

let dest_script_pk_len = dest_address.script_pubkey().len();
let var_int_prefix_len = crate::util::compute_var_int_prefix_size(dest_script_pk_len);
Expand Down

0 comments on commit 81090c4

Please sign in to comment.