From 0459dab6b925a3c3d93b93c1f8edefb5450f9e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 5 Nov 2024 10:33:13 +0100 Subject: [PATCH] ValueParser: add new UTxO role --- cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs | 2 ++ cardano-api/internal/Cardano/Api/ValueParser.hs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs index ec45f2e79..8fd4d3a40 100644 --- a/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs @@ -399,6 +399,8 @@ genValueForRole w = genValueForMinting RoleTxOut -> fromLedgerValue sbe <$> genValueForTxOut sbe + RoleUTxO -> + fromLedgerValue sbe <$> genValueForTxOut sbe where sbe = maryEraOnwardsToShelleyBasedEra w diff --git a/cardano-api/internal/Cardano/Api/ValueParser.hs b/cardano-api/internal/Cardano/Api/ValueParser.hs index fff180850..fe8fcf847 100644 --- a/cardano-api/internal/Cardano/Api/ValueParser.hs +++ b/cardano-api/internal/Cardano/Api/ValueParser.hs @@ -4,6 +4,7 @@ module Cardano.Api.ValueParser ( parseValue , parseTxOutMultiAssetValue , parseMintingMultiAssetValue + , parseUTxOValue , assetName , policyId , ValueRole (..) @@ -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 @@ -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) $ @@ -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 =