Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions plutus-core/plutus-core/src/PlutusCore/Builtin/Result.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
-- editorconfig-checker-disable-file
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StrictData #-}

module PlutusCore.Builtin.Result
( EvaluationError (..)
Expand Down
2 changes: 1 addition & 1 deletion plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun where
(runCostingFunThreeArguments . unimplementedCostingFun)

toBuiltinMeaning _semvar UnionValue =
let unionValueDenotation :: Value -> Value -> Value
let unionValueDenotation :: Value -> Value -> BuiltinResult Value
unionValueDenotation = Value.unionValue
{-# INLINE unionValueDenotation #-}
in makeBuiltinMeaning
Expand Down
18 changes: 14 additions & 4 deletions plutus-core/plutus-core/src/PlutusCore/Parser/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module PlutusCore.Parser.Builtin where

import PlutusPrelude (Word8, reoption, void)

import PlutusCore.Builtin.Result qualified
import PlutusCore.Crypto.BLS12_381.G1 qualified as BLS12_381.G1
import PlutusCore.Crypto.BLS12_381.G2 qualified as BLS12_381.G2
import PlutusCore.Data
Expand Down Expand Up @@ -91,13 +92,22 @@ conArray uniA = Vector.fromList <$> conList uniA
-- | Parser for values.
conValue :: Parser PLC.Value
conValue = do
Value.fromList <$> (traverse validateKeys =<< conList knownUni)
keys <- traverse validateKeys =<< conList knownUni
case Value.fromList keys of
PlutusCore.Builtin.Result.BuiltinSuccess v -> pure v
PlutusCore.Builtin.Result.BuiltinSuccessWithLogs _logs v -> pure v
PlutusCore.Builtin.Result.BuiltinFailure logs _trace ->
fail $ "Failed to construct Value: " <> show logs
where
validateToken (token, amt) = do
tk <- maybe (fail $ "Invalid token: " <> show (unpack token)) pure (Value.k token)
pure (tk, amt)
tk <- maybe (fail $ "Token name exceeds maximum length of 32 bytes: " <> show (unpack token))
pure (Value.k token)
qty <- maybe (fail $ "Token quantity out of signed 128-bit integer bounds: " <> show amt)
pure (Value.quantity amt)
pure (tk, qty)
validateKeys (currency, tokens) = do
ck <- maybe (fail $ "Invalid currency: " <> show (unpack currency)) pure (Value.k currency)
ck <- maybe (fail $ "Currency symbol exceeds maximum length of 32 bytes: " <> show (unpack currency))
pure (Value.k currency)
tks <- traverse validateToken tokens
pure (ck, tks)

Expand Down
5 changes: 4 additions & 1 deletion plutus-core/plutus-core/src/PlutusCore/Pretty/PrettyConst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ instance NonDefaultPrettyBy ConstConfig T.Text where
nonDefaultPrettyListBy conf = Prettyprinter.list . Prelude.map (nonDefaultPrettyBy conf)
nonDefaultPrettyBy = inContextM $ \t -> pure $ pretty $ "\"" <> escape t <> "\""
where
escape t = T.foldr' prettyChar "" t
escape = T.foldr' prettyChar ""
prettyChar c acc
| c == '"' = "\\\"" <> acc -- Not handled by 'showLitChar'
| c == '\\' = "\\\\" <> acc -- Not handled by 'showLitChar'
Expand Down Expand Up @@ -162,6 +162,9 @@ instance PrettyBy ConstConfig Data where
instance PrettyBy ConstConfig Value.K where
prettyBy config = prettyBy config . Value.unK

instance PrettyBy ConstConfig Value.Quantity where
prettyBy config = prettyBy config . Value.unQuantity

instance PrettyBy ConstConfig Value where
prettyBy config = prettyBy config . Value.toList
Comment on lines 162 to 169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it matters much, but these should be newtype-derivable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would require data constructors to be in scope (they aren't).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Yeah I guess that makes sense.


Expand Down
Loading