Update BP fee_weight

Closes https://github.com/serai-dex/serai/issues/8.
This commit is contained in:
Luke Parker
2022-08-21 10:35:10 -04:00
parent 755d021f8e
commit 60d93c4b2d
5 changed files with 37 additions and 33 deletions

View File

@@ -212,12 +212,8 @@ impl SignableTransaction {
let extra = Extra::fee_weight(outputs);
// Calculate the fee.
let mut fee = fee_rate.calculate(Transaction::fee_weight(
protocol.ring_len(),
inputs.len(),
outputs,
extra,
));
let mut fee =
fee_rate.calculate(Transaction::fee_weight(protocol, inputs.len(), outputs, extra));
// Make sure we have enough funds
let in_amount = inputs.iter().map(|input| input.commitment.amount).sum::<u64>();
@@ -229,12 +225,9 @@ impl SignableTransaction {
// If we have yet to add a change output, do so if it's economically viable
if (!change) && change_address.is_some() && (in_amount != out_amount) {
// Check even with the new fee, there's remaining funds
let change_fee = fee_rate.calculate(Transaction::fee_weight(
protocol.ring_len(),
inputs.len(),
outputs + 1,
extra,
)) - fee;
let change_fee =
fee_rate.calculate(Transaction::fee_weight(protocol, inputs.len(), outputs + 1, extra)) -
fee;
if (out_amount + change_fee) < in_amount {
change = true;
out_amount += change_fee;