Browse Source

Subtract minimal fee from punish tx

bdk-0.11
Philipp Hoenisch 3 years ago
committed by Lucas Soriano del Pino
parent
commit
9910a732ca
No known key found for this signature in database GPG Key ID: EE611E973A1530E7
  1. 10
      cfd_protocol/src/lib.rs

10
cfd_protocol/src/lib.rs

@ -271,7 +271,6 @@ pub fn punish_transaction(
.expect("to find commit output in commit tx"); .expect("to find commit output in commit tx");
let commit_amount = revoked_commit_tx.output[commit_vout].value; let commit_amount = revoked_commit_tx.output[commit_vout].value;
// Fixme: need to subtract tx fee otherwise we won't be able to publish this transaction.
let mut punish_tx = { let mut punish_tx = {
let txid = revoked_commit_tx.txid(); let txid = revoked_commit_tx.txid();
@ -284,7 +283,7 @@ pub fn punish_transaction(
value: commit_amount, value: commit_amount,
script_pubkey: address.script_pubkey(), script_pubkey: address.script_pubkey(),
}; };
Transaction { let mut tx = Transaction {
version: 2, version: 2,
lock_time: 0, lock_time: 0,
input: vec![TxIn { input: vec![TxIn {
@ -292,7 +291,12 @@ pub fn punish_transaction(
..Default::default() ..Default::default()
}], }],
output: vec![output], output: vec![output],
} };
let fee = tx.get_size() * MIN_RELAY_FEE as usize;
tx.output[0].value = commit_amount - fee as u64;
tx
}; };
let digest = SigHashCache::new(&punish_tx).signature_hash( let digest = SigHashCache::new(&punish_tx).signature_hash(

Loading…
Cancel
Save