if benefit > deficit {
tprintln!("added {value} sat input to cover {deficit} sat deficit");
deficit = Amount::ZERO;
} else {
tprintln!("added {value} sat input to reduce {deficit} sat deficit by {benefit} sat");
deficit -= benefit;
}
}
}
Ok(self)
}
fn strip_value(mut self) -> Self {
let sat_offset = self.calculate_sat_offset();
let total_output_amount = self
.outputs
.iter()
.map(|(_address, amount)| *amount)
.sum::<Amount>();
self
.outputs
.iter()
.find(|(address, _amount)| address == &self.recipient)
.expect("couldn't find output that contains the index");
let value = total_output_amount - Amount::from_sat(sat_offset);
if let Some(excess) = value.checked_sub(self.fee_rate.fee(self.estimate_vbytes())) {
let (max, target) = match self.target {
Target::ExactPostage(postage) => (postage, postage),
Target::Postage => (Self::MAX_POSTAGE, Self::TARGET_POSTAGE),