Skip to content

Commit

Permalink
Simplify implementation of TokenBundle.unsafeSubtract.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jun 2, 2023
1 parent f605008 commit 5935662
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -107,6 +107,8 @@ import GHC.Generics
( Generic )
import GHC.TypeLits
( ErrorMessage (..), TypeError )
import Safe
( fromJustNote )

import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Cardano.Wallet.Primitive.Types.TokenMap as TokenMap
Expand Down Expand Up @@ -413,5 +415,5 @@ mapAssetIds f (TokenBundle c m) = TokenBundle c (TokenMap.mapAssetIds f m)
-- Throws a run-time exception if the pre-condition is violated.
--
unsafeSubtract :: TokenBundle -> TokenBundle -> TokenBundle
unsafeSubtract (TokenBundle (Coin c1) m1) (TokenBundle (Coin c2) m2) =
TokenBundle (Coin $ c1 - c2) (TokenMap.unsafeSubtract m1 m2)
unsafeSubtract b1 b2 = fromJustNote "TokenBundle.unsafeSubtract" $
b1 `subtract` b2

0 comments on commit 5935662

Please sign in to comment.