Skip to content

Commit

Permalink
Add currencyValueOf
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEichmann committed Nov 30, 2021
1 parent cbabb1d commit d659990
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions plutus-ledger-api/plutus-ledger-api.cabal
Expand Up @@ -59,6 +59,7 @@ library

Plutus.V2.Ledger.Api
Plutus.V2.Ledger.Contexts
Plutus.V2.Ledger.Value
build-depends:
base >=4.9 && <5,
aeson -any,
Expand Down
53 changes: 53 additions & 0 deletions plutus-ledger-api/src/Plutus/V2/Ledger/Value.hs
@@ -0,0 +1,53 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- Prevent unboxing, which the plugin can't deal with
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
{-# OPTIONS_GHC -fno-spec-constr #-}
{-# OPTIONS_GHC -fno-specialise #-}

-- | Functions for working with 'Value'.
module Plutus.V2.Ledger.Value(
-- ** Currency symbols
CurrencySymbol(..)
, currencySymbol
, mpsSymbol
, currencyMPSHash
-- ** Token names
, TokenName(..)
, tokenName
, toString
-- * Asset classes
, AssetClass(..)
, assetClass
, assetClassValue
, assetClassValueOf
-- ** Value
, Value(..)
, singleton
, valueOf
, currencyValueOf
, scale
, symbols
-- * Partial order operations
, geq
, gt
, leq
, lt
-- * Etc.
, isZero
, split
, unionWith
, flattenValue
) where

import Plutus.V1.Ledger.Value
import PlutusTx.AssocMap qualified as Map
import PlutusTx.Maybe
import PlutusTx.Monoid

{-# INLINABLE currencyValueOf #-}
-- | Get the quantities of just the given 'CurrencySymbol' in the 'Value'.
currencyValueOf :: Value -> CurrencySymbol -> Value
currencyValueOf (Value m) c = case Map.lookup c m of
Nothing -> mempty
Just t -> Value (Map.singleton c t)

0 comments on commit d659990

Please sign in to comment.