Skip to content

Commit

Permalink
fix math
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Feb 2, 2021
1 parent b3bb6ff commit 680a161
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 680a161

Please sign in to comment.