Skip to content

Commit

Permalink
ValueParser: add new UTxO role
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 5, 2024
1 parent eba6903 commit 0459dab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ genValueForRole w =
genValueForMinting
RoleTxOut ->
fromLedgerValue sbe <$> genValueForTxOut sbe
RoleUTxO ->
fromLedgerValue sbe <$> genValueForTxOut sbe
where
sbe = maryEraOnwardsToShelleyBasedEra w

Expand Down
10 changes: 10 additions & 0 deletions cardano-api/internal/Cardano/Api/ValueParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Cardano.Api.ValueParser
( parseValue
, parseTxOutMultiAssetValue
, parseMintingMultiAssetValue
, parseUTxOValue
, assetName
, policyId
, ValueRole (..)
Expand Down Expand Up @@ -36,6 +37,8 @@ data ValueRole
RoleTxOut
| -- | The value is used as a minting policy.
RoleMint
| -- | The value is used as a utxo
RoleUTxO
deriving (Eq, Show, Enum, Bounded)

-- | Parse a 'Value' from its string representation. The @role@ argument for which purpose
Expand All @@ -53,6 +56,10 @@ parseValue role = do
unless (allPositive value) $
fail "Value must be positive in a transaction output"
return value
RoleUTxO -> do
unless (allPositive value) $
fail "Value must be positive in an UTxO"
return value
RoleMint -> do
let (Coin lovelace) = selectLovelace value
when (lovelace /= 0) $
Expand All @@ -65,6 +72,9 @@ parseTxOutMultiAssetValue = parseValue RoleTxOut
parseMintingMultiAssetValue :: Parser Value
parseMintingMultiAssetValue = parseValue RoleMint

parseUTxOValue :: Parser Value
parseUTxOValue = parseValue RoleUTxO

-- | Evaluate a 'ValueExpr' and construct a 'Value'.
evalValueExpr :: ValueExpr -> Value
evalValueExpr vExpr =
Expand Down

0 comments on commit 0459dab

Please sign in to comment.