Skip to content

Commit 9b3c3e1

Browse files
committed
f - use bitcoin::Weight
1 parent 5562356 commit 9b3c3e1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ pub(crate) struct ConstructedTransaction {
220220
pub(crate) struct NegotiatedTxInput {
221221
serial_id: SerialId,
222222
txin: TxIn,
223-
/// The weight of the input (in WU's)
224-
weight: u64,
223+
// The weight of the input including an estimate of its witness weight.
224+
weight: Weight,
225225
}
226226

227227
impl_writeable_tlv_based!(NegotiatedTxInput, {
@@ -314,7 +314,7 @@ impl ConstructedTransaction {
314314

315315
pub fn weight(&self) -> Weight {
316316
let inputs_weight = self.inputs.iter().fold(Weight::from_wu(0), |weight, input| {
317-
weight.checked_add(Weight::from_wu(input.weight)).unwrap_or(Weight::MAX)
317+
weight.checked_add(input.weight).unwrap_or(Weight::MAX)
318318
});
319319
let outputs_weight = self.outputs.iter().fold(Weight::from_wu(0), |weight, output| {
320320
weight.checked_add(get_output_weight(output.script_pubkey())).unwrap_or(Weight::MAX)
@@ -1532,7 +1532,7 @@ impl InteractiveTxInput {
15321532
}
15331533

15341534
fn into_negotiated_input(self) -> NegotiatedTxInput {
1535-
let weight = self.input.estimate_input_weight().to_wu();
1535+
let weight = self.input.estimate_input_weight();
15361536
NegotiatedTxInput { serial_id: self.serial_id, txin: self.input.into_tx_in(), weight }
15371537
}
15381538
}

lightning/src/util/ser.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use bitcoin::secp256k1::ecdsa;
4141
use bitcoin::secp256k1::schnorr;
4242
use bitcoin::secp256k1::{PublicKey, SecretKey};
4343
use bitcoin::transaction::{OutPoint, Transaction, TxOut};
44-
use bitcoin::{consensus, TxIn, Witness};
44+
use bitcoin::{consensus, TxIn, Weight, Witness};
4545

4646
use dnssec_prover::rr::Name;
4747

@@ -1381,6 +1381,19 @@ impl Readable for Amount {
13811381
}
13821382
}
13831383

1384+
impl Writeable for Weight {
1385+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
1386+
self.to_wu().write(w)
1387+
}
1388+
}
1389+
1390+
impl Readable for Weight {
1391+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1392+
let wu: u64 = Readable::read(r)?;
1393+
Ok(Weight::from_wu(wu))
1394+
}
1395+
}
1396+
13841397
impl Writeable for Txid {
13851398
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
13861399
w.write_all(&self[..])

0 commit comments

Comments
 (0)