Skip to content

Commit

Permalink
PLT-6070 Implemented binary instance for safety errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Jun 23, 2023
1 parent ca3da93 commit 6a3aa67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
18 changes: 16 additions & 2 deletions marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs
@@ -1,3 +1,5 @@
-- editorconfig-checker-disable-file

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs
Expand Up @@ -13,6 +13,7 @@
-----------------------------------------------------------------------------


{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

Expand All @@ -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)
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -258,7 +261,7 @@ data Transaction =
, txInput :: TransactionInput
, txOutput :: TransactionOutput
}
deriving (Eq, Show)
deriving (Eq, Generic, Show)

instance ToJSON Transaction where
toJSON Transaction{..} =
Expand Down
6 changes: 4 additions & 2 deletions marlowe/src/Language/Marlowe/Core/V1/Semantics.hs
@@ -1,3 +1,5 @@
-- editorconfig-checker-disable-file

-----------------------------------------------------------------------------
--
-- Module : $Headers
Expand Down Expand Up @@ -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) =
Expand Down Expand Up @@ -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{..} =
Expand Down

0 comments on commit 6a3aa67

Please sign in to comment.