Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Sep 13, 2023
1 parent 9f1c9ad commit eb98b16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 6 additions & 10 deletions lib/wallet/src/Cardano/Wallet/Write/Tx/Balance/TokenBundleSize.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE TypeApplications #-}

-- | Assessing sizes of token bundles
module Cardano.Wallet.Write.Tx.Balance.TokenBundleSize
( TokenBundleSizeAssessor (..)
Expand Down Expand Up @@ -35,18 +33,16 @@ import qualified Data.ByteString.Lazy as BL
-- | Assesses a token bundle size in relation to the maximum size that can be
-- included in a transaction output.
--
-- See 'W.TokenBundleSizeAssessor' for the expected properties of this function.
-- See 'TokenBundleSizeAssessor' for the expected properties of this function.
--
mkTokenBundleSizeAssessor
:: RecentEra era
-> PParams (ShelleyLedgerEra era)
-> TokenBundleSizeAssessor
mkTokenBundleSizeAssessor era pp = TokenBundleSizeAssessor $ \tb ->
let
in
if computeTokenBundleSerializedLengthBytes tb ver > maxValSize
then TokenBundleSizeExceedsLimit
else TokenBundleSizeWithinLimit
if computeTokenBundleSerializedLengthBytes tb ver > maxValSize
then TokenBundleSizeExceedsLimit
else TokenBundleSizeWithinLimit
where
maxValSize :: TxSize
maxValSize = TxSize $ withConstraints era $ pp ^. ppMaxValSizeL
Expand All @@ -61,9 +57,9 @@ computeTokenBundleSerializedLengthBytes
computeTokenBundleSerializedLengthBytes tb ver = serSize (toLedger tb)
where
serSize :: Value StandardCrypto -> TxSize
serSize v = maybe err TxSize $ intCastMaybe
serSize v = maybe err TxSize
. intCastMaybe
. BL.length
$ serialize ver v
where
err = error $ "negative serialized size of value: " <> show v

Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ instance Arbitrary PParamsInRecentEra where
ver <- arbitrary
maxSize <- genMaxSize
return $ def
& ppProtocolVersionL .~ (ProtVer ver 0) -- minor ver doesn't matter
& ppProtocolVersionL .~ (ProtVer ver 0)
-- minor version doesn't matter
& ppMaxValSizeL .~ maxSize
where
genMaxSize :: Gen Natural
Expand All @@ -287,7 +288,7 @@ babbageTokenBundleSizeAssessor :: TokenBundleSizeAssessor
babbageTokenBundleSizeAssessor = mkTokenBundleSizeAssessor RecentEraBabbage
$ def
& ppProtocolVersionL .~ (ProtVer (eraProtVerLow @StandardBabbage) 0)
& ppMaxValSizeL .~ maryTokenBundleMaxSize
& ppMaxValSizeL .~ maryTokenBundleMaxSize
where
maryTokenBundleMaxSize = 4000

Expand All @@ -298,4 +299,3 @@ mkAssessorFromPParamsInRecentEra (PParamsInBabbage pp) =
mkTokenBundleSizeAssessor RecentEraBabbage pp
mkAssessorFromPParamsInRecentEra (PParamsInConway pp) =
mkTokenBundleSizeAssessor RecentEraConway pp

0 comments on commit eb98b16

Please sign in to comment.