Skip to content

Commit

Permalink
Extract out new module AssetId.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Dec 5, 2023
1 parent 5cbf93f commit 4fc00f9
Show file tree
Hide file tree
Showing 45 changed files with 189 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ import qualified Cardano.Wallet.Primitive.Ledger.Convert as Convert
import qualified Cardano.Wallet.Primitive.Types.Address as W
( Address
)
import qualified Cardano.Wallet.Primitive.Types.AssetId as W
( AssetId (..)
)
import qualified Cardano.Wallet.Primitive.Types.Coin as W.Coin
import qualified Cardano.Wallet.Primitive.Types.Coin as W
( Coin (..)
Expand All @@ -293,9 +296,6 @@ import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W
( TokenBundle (..)
)
import qualified Cardano.Wallet.Primitive.Types.TokenMap as W.TokenMap
import qualified Cardano.Wallet.Primitive.Types.TokenMap as W
( AssetId (..)
)
import qualified Cardano.Wallet.Primitive.Types.TokenQuantity as W
( TokenQuantity (..)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ import qualified Cardano.CoinSelection.Context as SC
import qualified Cardano.Wallet.Primitive.Types.Address as W
( Address (..)
)
import qualified Cardano.Wallet.Primitive.Types.AssetId as W
( AssetId
)
import qualified Cardano.Wallet.Primitive.Types.Coin as W
( Coin
)
Expand All @@ -133,8 +136,7 @@ import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W
( TokenBundle (..)
)
import qualified Cardano.Wallet.Primitive.Types.TokenMap as W
( AssetId
, TokenMap
( TokenMap
)
import qualified Cardano.Wallet.Primitive.Types.Tx.Constraints as W
( txOutMaxCoin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ import qualified Cardano.Address.Script as CA
import qualified Cardano.Wallet.Primitive.Types.Address as W
( Address (..)
)
import qualified Cardano.Wallet.Primitive.Types.AssetId as W
( AssetId (..)
)
import qualified Cardano.Wallet.Primitive.Types.Coin as W
( Coin (..)
)
import qualified Cardano.Wallet.Primitive.Types.Coin as W.Coin
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W.TokenBundle
import qualified Cardano.Wallet.Primitive.Types.TokenMap as W
( AssetId (..)
)
import qualified Cardano.Wallet.Primitive.Types.TokenName as W
import qualified Cardano.Wallet.Primitive.Types.Tx.Constraints as W
( TxSize (..)
Expand Down
6 changes: 4 additions & 2 deletions lib/coin-selection/bench/UTxOIndexBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module Main where

import Prelude

import Cardano.Wallet.Primitive.Types.AssetId
( AssetId (..)
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
Expand All @@ -22,8 +25,7 @@ import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle (..)
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId (..)
, TokenMap
( TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenName
( TokenName (..)
Expand Down
6 changes: 4 additions & 2 deletions lib/coin-selection/lib/Cardano/CoinSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ import Cardano.CoinSelection.Size
import Cardano.CoinSelection.UTxOSelection
( UTxOSelection
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId
, TokenMap
( TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenQuantity
( TokenQuantity
Expand Down
6 changes: 4 additions & 2 deletions lib/coin-selection/lib/Cardano/CoinSelection/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ import Cardano.CoinSelection.UTxOSelection
import Cardano.Numeric.Util
( padCoalesce
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle (..)
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId
, Lexicographic (..)
( Lexicographic (..)
, TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenQuantity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ import GHC.Generics
( Generic
)

import qualified Cardano.Wallet.Primitive.Types.AssetId as W
( AssetId
)
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W.TokenBundle
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W
( TokenBundle
)
import qualified Cardano.Wallet.Primitive.Types.TokenMap as W.TokenMap
import qualified Cardano.Wallet.Primitive.Types.TokenMap as W
( AssetId
)
import qualified Data.Foldable as F
import qualified Data.List as L
import qualified Data.List.NonEmpty as NE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ import Cardano.CoinSelection.UTxOSelection.Gen
import Cardano.Numeric.Util
( inAscendingPartialOrder
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId (..)
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
Expand All @@ -149,8 +152,7 @@ import Cardano.Wallet.Primitive.Types.TokenBundle.Gen
, shrinkTokenBundleSmallRangePositive
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId (..)
, TokenMap
( TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenMap.Gen
( genAssetId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ import Cardano.CoinSelection.UTxOIndex.Internal
, categorizeTokenBundle
, checkInvariant
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId
)
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle
)
import Cardano.Wallet.Primitive.Types.TokenBundle.Gen
( genTokenBundleSmallRangePositive
, shrinkTokenBundleSmallRangePositive
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId
)
import Cardano.Wallet.Primitive.Types.TokenMap.Gen
( genAssetId
, shrinkAssetId
Expand Down
6 changes: 4 additions & 2 deletions lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ import Cardano.Startup
import Cardano.Wallet.Network.Ports
( randomUnusedTCPPorts
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId (..)
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.TokenBundle
( AssetId (..)
, TokenBundle (..)
( TokenBundle (..)
)
import Cardano.Wallet.Primitive.Types.TokenName
( TokenName (..)
Expand Down
1 change: 1 addition & 0 deletions lib/primitive/cardano-wallet-primitive.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ library
Cardano.Wallet.Primitive.Types.Address
Cardano.Wallet.Primitive.Types.Address.Gen
Cardano.Wallet.Primitive.Types.AnyExplicitScripts
Cardano.Wallet.Primitive.Types.AssetId
Cardano.Wallet.Primitive.Types.Block
Cardano.Wallet.Primitive.Types.Block.Gen
Cardano.Wallet.Primitive.Types.BlockSummary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import qualified Cardano.Ledger.Crypto as SL
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Wallet.Primitive.Ledger.Convert as Ledger
import qualified Cardano.Wallet.Primitive.Types.Address as W
import qualified Cardano.Wallet.Primitive.Types.AssetId as W
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Cardano.Wallet.Primitive.Types.Coin as W
import qualified Cardano.Wallet.Primitive.Types.Hash as W
Expand Down Expand Up @@ -156,7 +157,7 @@ fromCardanoValue = uncurry TokenBundle.fromFlatList . extract
| otherwise = internalError "negative token quantity"

mkBundle assets =
[ (TokenBundle.AssetId (mkPolicyId p) (mkTokenName n) , mkQuantity q)
[ (W.AssetId (mkPolicyId p) (mkTokenName n), mkQuantity q)
| (Cardano.AssetId p n, Cardano.Quantity q) <- assets
]

Expand Down
3 changes: 2 additions & 1 deletion lib/primitive/lib/Cardano/Wallet/Primitive/Ledger/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ import qualified Cardano.Slotting.Slot as Slotting
import qualified Cardano.Wallet.Primitive.Ledger.Convert as Ledger
import qualified Cardano.Wallet.Primitive.Slotting as W
import qualified Cardano.Wallet.Primitive.Types.Address as W
import qualified Cardano.Wallet.Primitive.Types.AssetId as W
import qualified Cardano.Wallet.Primitive.Types.Block as W
import qualified Cardano.Wallet.Primitive.Types.Certificates as W
import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
Expand Down Expand Up @@ -1253,7 +1254,7 @@ toCardanoValue tb = Cardano.valueFromList $
map (bimap toCardanoAssetId toQuantity) bundle
where
(coin, bundle) = TokenBundle.toFlatList tb
toCardanoAssetId (TokenBundle.AssetId pid name) =
toCardanoAssetId (W.AssetId pid name) =
Cardano.AssetId (toCardanoPolicyId pid) (toCardanoAssetName name)

toCardanoAssetName (W.UnsafeTokenName name) =
Expand Down
34 changes: 34 additions & 0 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/AssetId.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}

module Cardano.Wallet.Primitive.Types.AssetId
( AssetId (..)
) where

import Prelude

import Cardano.Wallet.Primitive.Types.TokenName
( TokenName
)
import Cardano.Wallet.Primitive.Types.TokenPolicyId
( TokenPolicyId
)
import Control.DeepSeq
( NFData
)
import GHC.Generics
( Generic
)

-- | A combination of a token policy identifier and a token name that can be
-- used as a compound identifier.
--
data AssetId = AssetId
{ tokenPolicyId
:: !TokenPolicyId
, tokenName
:: !TokenName
}
deriving stock (Eq, Generic, Ord, Read, Show)

instance NFData AssetId
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
--
module Cardano.Wallet.Primitive.Types.TokenBundle
(
-- * Types
-- * Type
TokenBundle (..)
, AssetId (..)

-- * Construction
, empty
Expand Down Expand Up @@ -79,12 +78,14 @@ import Prelude hiding
import Algebra.PartialOrd
( PartialOrd (..)
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId (..)
, Flat (..)
( Flat (..)
, Lexicographic (..)
, Nested (..)
, TokenMap
Expand Down
19 changes: 4 additions & 15 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/TokenMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
--
module Cardano.Wallet.Primitive.Types.TokenMap
(
-- * Types
-- * Type
TokenMap
, AssetId (..)

-- * Construction
, empty
Expand Down Expand Up @@ -94,6 +93,9 @@ import Algebra.PartialOrd
import Cardano.Numeric.Util
( equipartitionNatural
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId (AssetId)
)
import Cardano.Wallet.Primitive.Types.TokenName
( TokenName
)
Expand Down Expand Up @@ -244,19 +246,6 @@ instance NFData TokenMap
instance Hashable TokenMap where
hashWithSalt = hashUsing toNestedList

-- | A combination of a token policy identifier and a token name that can be
-- used as a compound identifier.
--
data AssetId = AssetId
{ tokenPolicyId
:: !TokenPolicyId
, tokenName
:: !TokenName
}
deriving stock (Eq, Generic, Ord, Read, Show)

instance NFData AssetId

--------------------------------------------------------------------------------
-- Ordering
--------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ module Cardano.Wallet.Primitive.Types.TokenMap.Gen

import Prelude

import Cardano.Wallet.Primitive.Types.TokenMap
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId (..)
, TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenMap
( TokenMap
)
import Cardano.Wallet.Primitive.Types.TokenName.Gen
( genTokenName
Expand Down
6 changes: 3 additions & 3 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/Tx/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ import Cardano.Api
)
import Cardano.Wallet.Orphans
()
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
Expand All @@ -58,9 +61,6 @@ import Cardano.Wallet.Primitive.Types.Hash
import Cardano.Wallet.Primitive.Types.RewardAccount
( RewardAccount (..)
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId
)
import Cardano.Wallet.Primitive.Types.Tx.TxIn
( TxIn (..)
)
Expand Down
6 changes: 4 additions & 2 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/Tx/TxOut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ import Prelude
import Cardano.Wallet.Primitive.Types.Address
( Address (..)
)
import Cardano.Wallet.Primitive.Types.AssetId
( AssetId (..)
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Cardano.Wallet.Primitive.Types.TokenBundle
( TokenBundle
)
import Cardano.Wallet.Primitive.Types.TokenMap
( AssetId
, Lexicographic (..)
( Lexicographic (..)
)
import Control.DeepSeq
( NFData (..)
Expand Down
Loading

0 comments on commit 4fc00f9

Please sign in to comment.