From 6a3aa6765b72fc5b095df7abade706ad96d77ad8 Mon Sep 17 00:00:00 2001 From: Brian W Bush Date: Mon, 19 Jun 2023 09:33:27 -0600 Subject: [PATCH] PLT-6070 Implemented binary instance for safety errors. --- .../src/Language/Marlowe/Runtime/Core/Api.hs | 18 ++++++++++++++++-- .../Language/Marlowe/Analysis/Safety/Types.hs | 7 +++++-- .../src/Language/Marlowe/Core/V1/Semantics.hs | 6 ++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs b/marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs index f0dd572176..799e54994c 100644 --- a/marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs +++ b/marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs @@ -1,3 +1,5 @@ +-- editorconfig-checker-disable-file + {-# LANGUAGE DataKinds #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE FlexibleInstances #-} @@ -34,6 +36,7 @@ import Data.Text.Encoding (encodeUtf8) import Data.Time (UTCTime) import Data.Type.Equality (TestEquality(..), type (:~:)(Refl)) import GHC.Generics (Generic, to) +import qualified Language.Marlowe.Analysis.Safety.Types as V1 import qualified Language.Marlowe.Core.V1.Semantics as V1 import qualified Language.Marlowe.Core.V1.Semantics.Types as V1 import Language.Marlowe.Runtime.ChainSync.Api @@ -513,8 +516,13 @@ fromChainDatum = \case instance Binary PV2.Address instance Binary PV2.Credential instance Binary PV2.CurrencySymbol +instance Binary PV2.DatumHash +instance Binary PV2.ExBudget +instance Binary PV2.ExCPU +instance Binary PV2.ExMemory instance Binary PV2.POSIXTime instance Binary PV2.PubKeyHash +instance Binary PV2.SatInt instance Binary PV2.StakingCredential where instance Binary PV2.TokenName instance Binary PV2.ValidatorHash @@ -524,16 +532,22 @@ instance Binary V1.ChoiceId instance Binary V1.Contract instance Binary V1.Input instance Binary V1.InputContent -instance Binary V1.TransactionInput +instance Binary V1.IntervalError instance Binary V1.MarloweData instance Binary V1.MarloweParams instance Binary V1.Observation instance Binary V1.Party instance Binary V1.Payee +instance Binary V1.Payment +instance Binary V1.SafetyError instance Binary V1.State instance Binary V1.Token +instance Binary V1.Transaction +instance Binary V1.TransactionError +instance Binary V1.TransactionInput +instance Binary V1.TransactionOutput +instance Binary V1.TransactionWarning instance Binary V1.ValueId -instance Binary V1.IntervalError instance Binary a => Binary (V1.Case a) instance Binary a => Binary (V1.Value a) instance Binary NetworkId where diff --git a/marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs b/marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs index aeea0d1825..387b052886 100644 --- a/marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs +++ b/marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs @@ -13,6 +13,7 @@ ----------------------------------------------------------------------------- +{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} @@ -27,6 +28,7 @@ module Language.Marlowe.Analysis.Safety.Types import Data.Aeson (ToJSON(..), Value(String), object, (.=)) import Data.ByteString.Base16.Aeson (EncodeBase16(EncodeBase16)) +import GHC.Generics (Generic) import Language.Marlowe.Core.V1.Semantics (TransactionInput, TransactionOutput) import Language.Marlowe.Core.V1.Semantics.Types (AccountId, ChoiceId, Contract, State, Token, ValueId) import Language.Marlowe.Core.V1.Semantics.Types.Address (Network) @@ -95,7 +97,8 @@ data SafetyError = | WrongNetwork -- | The contract contains an illegal ledger address. | IllegalAddress Ledger.Address - deriving (Eq, Show) + deriving (Eq, Generic, Show) + instance ToJSON SafetyError where toJSON MissingRolesCurrency = @@ -258,7 +261,7 @@ data Transaction = , txInput :: TransactionInput , txOutput :: TransactionOutput } - deriving (Eq, Show) + deriving (Eq, Generic, Show) instance ToJSON Transaction where toJSON Transaction{..} = diff --git a/marlowe/src/Language/Marlowe/Core/V1/Semantics.hs b/marlowe/src/Language/Marlowe/Core/V1/Semantics.hs index 75c423b8aa..f122726c80 100644 --- a/marlowe/src/Language/Marlowe/Core/V1/Semantics.hs +++ b/marlowe/src/Language/Marlowe/Core/V1/Semantics.hs @@ -1,3 +1,5 @@ +-- editorconfig-checker-disable-file + ----------------------------------------------------------------------------- -- -- Module : $Headers @@ -215,7 +217,7 @@ import Text.PrettyPrint.Leijen (comma, hang, lbrace, line, rbrace, space, text, when positive balances are payed out on contract closure. -} data Payment = Payment AccountId Payee Token Integer - deriving stock (Haskell.Eq, Haskell.Show) + deriving stock (Haskell.Eq, Generic, Haskell.Show) instance ToJSON Payment where toJSON (Payment accountId payee token amount) = @@ -358,7 +360,7 @@ data TransactionOutput = , txOutState :: State , txOutContract :: Contract } | Error TransactionError - deriving stock (Haskell.Eq, Haskell.Show) + deriving stock (Haskell.Eq, Generic, Haskell.Show) instance ToJSON TransactionOutput where toJSON TransactionOutput{..} =