Skip to content

Commit

Permalink
Rename minimizeFee function family to distributeSurplus.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Apr 19, 2022
1 parent 85f1a06 commit 7064fe5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 86 deletions.
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,12 +1702,12 @@ balanceTransactionWithSelectionStrategy
(extraOutputs)
let feePolicy = view (#txParameters . #getFeePolicy) pp

-- @minimizeFee@ should never fail becase we have provided enough
-- @distributeSurplus@ should never fail becase we have provided enough
-- padding in @selectAssets'@.
TxFeeAndChange updatedFee updatedChange <- withExceptT
(\(ErrMoreSurplusNeeded c) ->
ErrBalanceTxNotYetSupported $ UnderestimatedFee c candidateTx)
(ExceptT . pure $ minimizeFee tl feePolicy surplus feeAndChange)
(ExceptT . pure $ distributeSurplus tl feePolicy surplus feeAndChange)

guardTxSize =<< guardTxBalanced =<< (assembleTransaction $ TxUpdate
{ extraInputs
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ data TransactionLayer k tx = TransactionLayer
--
-- Returns `Nothing` for ByronEra transactions.

, minimizeFee
, distributeSurplus
:: FeePolicy
-> Coin
-- ^ Surplus transaction balance to distribute.
Expand Down
22 changes: 11 additions & 11 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ module Cardano.Wallet.Shelley.Transaction
, mkUnsignedTx
, txConstraints
, costOfIncreasingCoin
, _minimizeFee
, minimizeFeeDelta
, _distributeSurplus
, distributeSurplusDelta
, sizeOfCoin
, maximumCostOfIncreasingCoin
) where
Expand Down Expand Up @@ -631,7 +631,7 @@ newTransactionLayer networkId = TransactionLayer
, maxScriptExecutionCost =
_maxScriptExecutionCost

, minimizeFee = _minimizeFee
, distributeSurplus = _distributeSurplus

, assignScriptRedeemers =
_assignScriptRedeemers
Expand Down Expand Up @@ -1495,29 +1495,29 @@ sizeOfCoin (Coin c)
| c >= 24 = TxSize 2
| otherwise = TxSize 1

_minimizeFee
_distributeSurplus
:: FeePolicy
-> Coin
-- ^ Surplus to distribute
-> TxFeeAndChange [TxOut]
-> Either ErrMoreSurplusNeeded (TxFeeAndChange [TxOut])
_minimizeFee feePolicy surplus fc@(TxFeeAndChange fee change) =
minimizeFeeDelta feePolicy surplus
_distributeSurplus feePolicy surplus fc@(TxFeeAndChange fee change) =
distributeSurplusDelta feePolicy surplus
(txFeeAndChange id (fmap txOutCoin) fc)
<&> txFeeAndChange
(fee <>)
(zipWith (flip txOutAddCoin) change)

minimizeFeeDelta
distributeSurplusDelta
:: FeePolicy
-> Coin
-- ^ Surplus to distribute
-> TxFeeAndChange [Coin]
-> Either ErrMoreSurplusNeeded (TxFeeAndChange [Coin])
minimizeFeeDelta feePolicy surplus (TxFeeAndChange fee change) =
distributeSurplusDelta feePolicy surplus (TxFeeAndChange fee change) =
case listToMaybe change of
Just firstChange ->
minimizeFeeDeltaWithSoloChangeCoin feePolicy surplus
distributeSurplusDeltaWithSoloChangeCoin feePolicy surplus
(TxFeeAndChange fee (Solo firstChange))
<&> txFeeAndChange id
((: replicate (length change - 1) (Coin 0)) . unSolo)
Expand All @@ -1527,12 +1527,12 @@ minimizeFeeDelta feePolicy surplus (TxFeeAndChange fee change) =
<&> txFeeAndChange id
(\Empty -> [])

minimizeFeeDeltaWithSoloChangeCoin
distributeSurplusDeltaWithSoloChangeCoin
:: FeePolicy
-> Coin -- ^ Surplus to distribute
-> TxFeeAndChange (Solo Coin)
-> Either ErrMoreSurplusNeeded (TxFeeAndChange (Solo Coin))
minimizeFeeDeltaWithSoloChangeCoin
distributeSurplusDeltaWithSoloChangeCoin
feePolicy surplus fc@(TxFeeAndChange fee0 (Solo change0)) =
let
-- We calculate the maximum possible fee increase, by assuming the
Expand Down
Loading

0 comments on commit 7064fe5

Please sign in to comment.