Skip to content

Commit

Permalink
Replace fromIntegral with intCastMaybe in `posAndNegFromCardanoVa…
Browse files Browse the repository at this point in the history
…lue`.

This allows us to replace the pattern guard and the unsafe conversion
with a single checked conversion.
  • Loading branch information
jonathanknowles committed Mar 23, 2022
1 parent 80f346c commit 0b57295
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ import Data.Generics.Labels
import Data.Generics.Product.Typed
( HasType, typed )
import Data.IntCast
( intCast )
( intCast, intCastMaybe )
import Data.Kind
( Type )
import Data.List
Expand Down Expand Up @@ -3858,10 +3858,12 @@ posAndNegFromCardanoValue = foldMap go . Cardano.valueToList
:: Cardano.Quantity
-> (Natural -> TokenBundle.TokenBundle)
-> (TokenBundle.TokenBundle, TokenBundle.TokenBundle)
partition (Cardano.Quantity q) f
| q > 0 = (f $ fromIntegral q, mempty)
| q < 0 = (mempty, f $ fromIntegral $ abs q)
partition (Cardano.Quantity i) f
| Just n <- maybeIntegerToNatural i = (f n, mempty)
| Just n <- maybeIntegerToNatural (abs i) = (mempty, f n)
| otherwise = (mempty, mempty)

maybeIntegerToNatural = intCastMaybe @Integer @Natural

mkPolicyId = UnsafeTokenPolicyId . Hash . Cardano.serialiseToRawBytes
mkTokenName = UnsafeTokenName . Cardano.serialiseToRawBytes

0 comments on commit 0b57295

Please sign in to comment.