Skip to content

Commit

Permalink
Add function fromNestedMap to TokenBundle and TokenMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jan 26, 2021
1 parent 0e87431 commit fcf253e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle.hs
Expand Up @@ -24,6 +24,7 @@ module Cardano.Wallet.Primitive.Types.TokenBundle
, empty
, fromFlatList
, fromNestedList
, fromNestedMap
, fromTokenMap
, fromTokenQuantity

Expand Down Expand Up @@ -201,6 +202,11 @@ fromNestedList
-> TokenBundle
fromNestedList c = TokenBundle c . TokenMap.fromNestedList

fromNestedMap
:: (Coin, Map TokenPolicyId (NonEmptyMap TokenName TokenQuantity))
-> TokenBundle
fromNestedMap (c, m) = TokenBundle c (TokenMap.fromNestedMap m)

fromTokenMap :: TokenMap -> TokenBundle
fromTokenMap = TokenBundle (Coin 0)

Expand Down
8 changes: 8 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types/TokenMap.hs
Expand Up @@ -44,6 +44,7 @@ module Cardano.Wallet.Primitive.Types.TokenMap
, singleton
, fromFlatList
, fromNestedList
, fromNestedMap

-- * Deconstruction
, toFlatList
Expand Down Expand Up @@ -446,6 +447,13 @@ fromNestedList entries = fromFlatList
, (token, quantity) <- NE.toList tokenQuantities
]

-- | Creates a token map from a nested map.
--
fromNestedMap
:: Map TokenPolicyId (NonEmptyMap TokenName TokenQuantity)
-> TokenMap
fromNestedMap = fromNestedList . Map.toList . fmap NEMap.toList

--------------------------------------------------------------------------------
-- Deconstruction
--------------------------------------------------------------------------------
Expand Down

0 comments on commit fcf253e

Please sign in to comment.