From 680a1618d3cf3b2d3dec3090bad559a2c438e57e Mon Sep 17 00:00:00 2001 From: buck54321 Date: Tue, 2 Feb 2021 14:58:26 -0600 Subject: [PATCH] fix math --- client/asset/btc/btc.go | 8 ++++---- client/asset/dcr/dcr.go | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/client/asset/btc/btc.go b/client/asset/btc/btc.go index fb5de38d71..c431ee2ea7 100644 --- a/client/asset/btc/btc.go +++ b/client/asset/btc/btc.go @@ -826,17 +826,17 @@ func (btc *ExchangeWallet) estimateSwap(lots, lotSize, networkFeeRate uint64, ut func (btc *ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error) { feeRate := btc.feeRateWithFallback(btc.redeemConfTarget) // Best is one transaction with req.Lots inputs and 1 output. - var best uint64 = dexbtc.MinimumTxOverhead + dexbtc.TxInOverhead + dexbtc.TxOutOverhead + var best uint64 = dexbtc.MinimumTxOverhead // Worst is req.Lots transactions, each with one input and one output. - var worst uint64 = best * req.Lots + var worst uint64 = dexbtc.MinimumTxOverhead * req.Lots var inputSize, outputSize uint64 if btc.segwit { // Add the marker and flag weight here. - inputSize = (dexbtc.RedeemSwapSigScriptSize + 2 + 3) / 4 + inputSize = dexbtc.TxInOverhead + (dexbtc.RedeemSwapSigScriptSize+2+3)/4 outputSize = dexbtc.P2WPKHOutputSize } else { - inputSize = dexbtc.RedeemSwapSigScriptSize + inputSize = dexbtc.TxInOverhead + dexbtc.RedeemSwapSigScriptSize outputSize = dexbtc.P2PKHOutputSize } best += inputSize*req.Lots + outputSize diff --git a/client/asset/dcr/dcr.go b/client/asset/dcr/dcr.go index 20c0d86111..bc68154235 100644 --- a/client/asset/dcr/dcr.go +++ b/client/asset/dcr/dcr.go @@ -810,11 +810,13 @@ func (dcr *ExchangeWallet) PreSwap(req *asset.PreSwapForm) (*asset.PreSwap, erro func (dcr *ExchangeWallet) PreRedeem(req *asset.PreRedeemForm) (*asset.PreRedeem, error) { feeRate := dcr.feeRateWithFallback(dcr.redeemConfTarget) // Best is one transaction with req.Lots inputs and 1 output. - var best uint64 = dexdcr.MsgTxOverhead + dexdcr.TxInOverhead + dexdcr.TxOutOverhead + var best uint64 = dexdcr.MsgTxOverhead // Worst is req.Lots transactions, each with one input and one output. - var worst uint64 = best * req.Lots - best += dexdcr.RedeemSwapSigScriptSize*req.Lots + dexdcr.P2PKHOutputSize - worst += (dexdcr.RedeemSwapSigScriptSize + dexdcr.P2PKHOutputSize) * req.Lots + var worst uint64 = dexdcr.MsgTxOverhead * req.Lots + var inputSize uint64 = dexdcr.TxInOverhead + dexdcr.RedeemSwapSigScriptSize + var outputSize uint64 = dexdcr.P2PKHOutputSize + best += inputSize*req.Lots + outputSize + worst += (inputSize + outputSize) * req.Lots return &asset.PreRedeem{ Estimate: &asset.RedeemEstimate{