Skip to content

Commit

Permalink
Use TokenName.maxLength instead of tokenNameMaxLength.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Dec 5, 2023
1 parent cd38236 commit de84d27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/TokenName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Cardano.Wallet.Primitive.Types.TokenName
( TokenName (..)
, empty
, fromByteString
, tokenNameMaxLength
, maxLength
) where

import Prelude
Expand Down Expand Up @@ -64,13 +64,13 @@ newtype TokenName =
deriving anyclass Hashable

-- | Construct a 'TokenName', validating that the length does not exceed
-- 'tokenNameMaxLength'.
-- 'maxLength'.
--
fromByteString :: ByteString -> Either String TokenName
fromByteString bs
| BS.length bs <= tokenNameMaxLength = Right $ UnsafeTokenName bs
| BS.length bs <= maxLength = Right $ UnsafeTokenName bs
| otherwise = Left $ "TokenName length " ++ show (BS.length bs)
++ " exceeds maximum of " ++ show tokenNameMaxLength
++ " exceeds maximum of " ++ show maxLength

-- | The empty asset name.
--
Expand All @@ -83,8 +83,8 @@ empty = UnsafeTokenName ""

-- | The maximum length of a valid token name.
--
tokenNameMaxLength :: Int
tokenNameMaxLength = 32
maxLength :: Int
maxLength = 32

instance NFData TokenName

Expand Down
5 changes: 2 additions & 3 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ import Cardano.Wallet.Primitive.Types.TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenName
( TokenName (..)
, tokenNameMaxLength
)
import Cardano.Wallet.Primitive.Types.TokenPolicyId
( TokenPolicyId (..)
Expand Down Expand Up @@ -2974,9 +2973,9 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
where
assetNameTooLong mb = case mb ^. #mintBurnData of
Left (ApiMintBurnDataFromScript _ (Just (ApiT (UnsafeTokenName bs))) _) ->
BS.length bs > tokenNameMaxLength
BS.length bs > TokenName.maxLength
Right (ApiMintBurnDataFromInput _ _ (Just (ApiT (UnsafeTokenName bs))) _) ->
BS.length bs > tokenNameMaxLength
BS.length bs > TokenName.maxLength
_ -> error "at this moment there should be asset name attributed"

guardAssetQuantityOutOfBounds
Expand Down

0 comments on commit de84d27

Please sign in to comment.