Skip to content

Commit

Permalink
Cautiously use RecordWildCards to simplify verification functions.
Browse files Browse the repository at this point in the history
Use of the `RecordWildCards` extension can lead to less readable code,
since it becomes harder for a reader to determine which fields have been
"absorbed" into a record value at the point of construction.

However, in the case of the post-condition verification functions
affected by this commit, it's relatively easy to tell which fields are
picked up, as the definition of each failure is always next to the
function that fails.

Therefore, we can safely use `RecordWildCards` to remove a bit of
verbosity.
  • Loading branch information
jonathanknowles committed Oct 26, 2021
1 parent 0b465ad commit ad613fa
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lib/core/src/Cardano/Wallet/Primitive/CoinSelection.hs
Expand Up @@ -454,9 +454,7 @@ verifySelectionCollateralSufficient cs ps selection
| collateralSelected >= collateralRequired =
VerificationSuccess
| otherwise =
verificationFailure
FailureToVerifySelectionCollateralSufficient
{collateralSelected, collateralRequired}
verificationFailure FailureToVerifySelectionCollateralSufficient {..}
where
collateralSelected = selectionCollateral selection
collateralRequired = selectionMinimumCollateral cs ps selection
Expand All @@ -479,9 +477,7 @@ verifySelectionCollateralSuitable cs _ps selection
| null collateralSelectedButUnsuitable =
VerificationSuccess
| otherwise =
verificationFailure
FailureToVerifySelectionCollateralSuitable
{collateralSelected, collateralSelectedButUnsuitable}
verificationFailure FailureToVerifySelectionCollateralSuitable {..}
where
collateralSelected =
selection ^. #collateral
Expand Down Expand Up @@ -510,8 +506,7 @@ verifySelectionDeltaValid cs ps selection
| selectionHasValidSurplus cs ps selection =
VerificationSuccess
| otherwise =
verificationFailure
FailureToVerifySelectionDeltaValid {..}
verificationFailure FailureToVerifySelectionDeltaValid {..}
where
delta = selectionDeltaAllAssets selection
minimumCost = selectionMinimumCost cs ps selection
Expand Down Expand Up @@ -539,8 +534,7 @@ verifySelectionInputCountWithinLimit cs _ps selection
| Balance.MaximumInputLimit totalInputCount <= selectionLimit =
VerificationSuccess
| otherwise =
verificationFailure
FailureToVerifySelectionInputCountWithinLimit {..}
verificationFailure FailureToVerifySelectionInputCountWithinLimit {..}
where
collateralInputCount = length (selection ^. #collateral)
ordinaryInputCount = length (selection ^. #inputs)
Expand Down Expand Up @@ -705,13 +699,7 @@ verifySelectionLimitReachedError cs ps e
| Balance.MaximumInputLimit selectedInputCount >= selectionLimitAdjusted =
VerificationSuccess
| otherwise =
verificationFailure
FailureToVerifySelectionLimitReachedError
{ selectedInputs
, selectedInputCount
, selectionLimitAdjusted
, selectionLimitOriginal
}
verificationFailure FailureToVerifySelectionLimitReachedError {..}
where
selectedInputs :: [(TxIn, TxOut)]
selectedInputs = e ^. #inputsSelected
Expand Down Expand Up @@ -777,8 +765,7 @@ verifySelectionCollateralError cs ps e
VerificationSuccess
where
reportFailure =
verificationFailure
FailureToVerifySelectionCollateralError {..}
verificationFailure FailureToVerifySelectionCollateralError {..}

largestCombination :: Map TxIn Coin
largestCombination = e ^. #largestCombinationAvailable
Expand Down Expand Up @@ -834,7 +821,7 @@ verifySelectionOutputSizeExceedsLimitError
:: VerifySelectionError SelectionOutputSizeExceedsLimitError
verifySelectionOutputSizeExceedsLimitError cs _ps e
| isWithinLimit =
verificationFailure $
verificationFailure
FailureToVerifySelectionOutputSizeExceedsLimitError {..}
| otherwise =
VerificationSuccess
Expand Down

0 comments on commit ad613fa

Please sign in to comment.