{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}

module Convex.TestingInterface.Trace (
  -- * Test run trace
  TestRunTrace (..),
  TestCategory (..),

  -- * Iteration trace
  IterationTrace (..),
  IterationStatus (..),

  -- * State transitions
  Transition (..),
  TransitionResult (..),

  -- * Transaction summary
  TxSummary (..),
  TxInputSummary (..),
  TxOutputSummary (..),
  TxWithdrawalSummary (..),

  -- * Value representation
  ValueSummary (..),
  AssetSummary (..),

  -- * Threat model trace
  ThreatModelTrace (..),
  ThreatModelTraceOutcome (..),
  ThreatModelValidation (..),

  -- * Redeemer tagging (Tier 2)
  RedeemerTag (..),
  RedeemerTagger (..),

  -- * Address labeling
  AddressType (..),
  AddressLabeler (..),
) where

import Control.Applicative ((<|>))
import Convex.Tasty.Streaming.SrcLoc (SrcLocRange, groupRanges)
import Convex.Tasty.Streaming.TMSummary (ThreatModelCategory)
import Data.Aeson (ToJSON (..), Value, object, (.=))
import Data.Text (Text)
import GHC.Generics (Generic)
import PlutusTx (Data)

{- | Complete trace of a test run (one QuickCheck property execution = N iterations).
Links to the Tasty test tree via 'trtTestId'.
-}
data TestRunTrace = TestRunTrace
  { TestRunTrace -> Int
trtTestId :: !Int
  -- ^ Tasty test ID (links to the @test_done@ event in the NDJSON stream)
  , TestRunTrace -> Text
trtTestName :: !Text
  -- ^ e.g. "Positive tests"
  , TestRunTrace -> [Text]
trtPath :: ![Text]
  -- ^ Tasty test path, e.g. @["MyContract", "Positive tests"]@
  , TestRunTrace -> TestCategory
trtCategory :: !TestCategory
  , TestRunTrace -> [IterationTrace]
trtIterations :: ![IterationTrace]
  }
  deriving (TestRunTrace -> TestRunTrace -> Bool
(TestRunTrace -> TestRunTrace -> Bool)
-> (TestRunTrace -> TestRunTrace -> Bool) -> Eq TestRunTrace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestRunTrace -> TestRunTrace -> Bool
== :: TestRunTrace -> TestRunTrace -> Bool
$c/= :: TestRunTrace -> TestRunTrace -> Bool
/= :: TestRunTrace -> TestRunTrace -> Bool
Eq, Int -> TestRunTrace -> ShowS
[TestRunTrace] -> ShowS
TestRunTrace -> String
(Int -> TestRunTrace -> ShowS)
-> (TestRunTrace -> String)
-> ([TestRunTrace] -> ShowS)
-> Show TestRunTrace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestRunTrace -> ShowS
showsPrec :: Int -> TestRunTrace -> ShowS
$cshow :: TestRunTrace -> String
show :: TestRunTrace -> String
$cshowList :: [TestRunTrace] -> ShowS
showList :: [TestRunTrace] -> ShowS
Show, (forall x. TestRunTrace -> Rep TestRunTrace x)
-> (forall x. Rep TestRunTrace x -> TestRunTrace)
-> Generic TestRunTrace
forall x. Rep TestRunTrace x -> TestRunTrace
forall x. TestRunTrace -> Rep TestRunTrace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TestRunTrace -> Rep TestRunTrace x
from :: forall x. TestRunTrace -> Rep TestRunTrace x
$cto :: forall x. Rep TestRunTrace x -> TestRunTrace
to :: forall x. Rep TestRunTrace x -> TestRunTrace
Generic)

-- | Whether this test run is a positive or negative test property.
data TestCategory
  = Positive
  | Negative
  deriving (TestCategory -> TestCategory -> Bool
(TestCategory -> TestCategory -> Bool)
-> (TestCategory -> TestCategory -> Bool) -> Eq TestCategory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TestCategory -> TestCategory -> Bool
== :: TestCategory -> TestCategory -> Bool
$c/= :: TestCategory -> TestCategory -> Bool
/= :: TestCategory -> TestCategory -> Bool
Eq, Int -> TestCategory -> ShowS
[TestCategory] -> ShowS
TestCategory -> String
(Int -> TestCategory -> ShowS)
-> (TestCategory -> String)
-> ([TestCategory] -> ShowS)
-> Show TestCategory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TestCategory -> ShowS
showsPrec :: Int -> TestCategory -> ShowS
$cshow :: TestCategory -> String
show :: TestCategory -> String
$cshowList :: [TestCategory] -> ShowS
showList :: [TestCategory] -> ShowS
Show, (forall x. TestCategory -> Rep TestCategory x)
-> (forall x. Rep TestCategory x -> TestCategory)
-> Generic TestCategory
forall x. Rep TestCategory x -> TestCategory
forall x. TestCategory -> Rep TestCategory x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TestCategory -> Rep TestCategory x
from :: forall x. TestCategory -> Rep TestCategory x
$cto :: forall x. Rep TestCategory x -> TestCategory
to :: forall x. Rep TestCategory x -> TestCategory
Generic)

instance ToJSON TestCategory where
  toJSON :: TestCategory -> Value
toJSON TestCategory
Positive = Value
"positive"
  toJSON TestCategory
Negative = Value
"negative"

-- | Trace of a single QuickCheck iteration within a test run.
data IterationTrace = IterationTrace
  { IterationTrace -> Int
itIndex :: !Int
  -- ^ 0-based iteration number
  , IterationTrace -> IterationStatus
itStatus :: !IterationStatus
  , IterationTrace -> [Transition]
itTransitions :: ![Transition]
  -- ^ Ordered sequence of actions performed
  , IterationTrace -> [ThreatModelTrace]
itThreatModels :: ![ThreatModelTrace]
  {- ^ Threat model results applied to this iteration's transactions.
  Only populated for positive tests.
  -}
  }
  deriving (IterationTrace -> IterationTrace -> Bool
(IterationTrace -> IterationTrace -> Bool)
-> (IterationTrace -> IterationTrace -> Bool) -> Eq IterationTrace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IterationTrace -> IterationTrace -> Bool
== :: IterationTrace -> IterationTrace -> Bool
$c/= :: IterationTrace -> IterationTrace -> Bool
/= :: IterationTrace -> IterationTrace -> Bool
Eq, Int -> IterationTrace -> ShowS
[IterationTrace] -> ShowS
IterationTrace -> String
(Int -> IterationTrace -> ShowS)
-> (IterationTrace -> String)
-> ([IterationTrace] -> ShowS)
-> Show IterationTrace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IterationTrace -> ShowS
showsPrec :: Int -> IterationTrace -> ShowS
$cshow :: IterationTrace -> String
show :: IterationTrace -> String
$cshowList :: [IterationTrace] -> ShowS
showList :: [IterationTrace] -> ShowS
Show, (forall x. IterationTrace -> Rep IterationTrace x)
-> (forall x. Rep IterationTrace x -> IterationTrace)
-> Generic IterationTrace
forall x. Rep IterationTrace x -> IterationTrace
forall x. IterationTrace -> Rep IterationTrace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IterationTrace -> Rep IterationTrace x
from :: forall x. IterationTrace -> Rep IterationTrace x
$cto :: forall x. Rep IterationTrace x -> IterationTrace
to :: forall x. Rep IterationTrace x -> IterationTrace
Generic)

-- | Outcome of a single iteration.
data IterationStatus
  = IterationSuccess
  | IterationFailure !Text
  | IterationDiscarded !Text
  deriving (IterationStatus -> IterationStatus -> Bool
(IterationStatus -> IterationStatus -> Bool)
-> (IterationStatus -> IterationStatus -> Bool)
-> Eq IterationStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IterationStatus -> IterationStatus -> Bool
== :: IterationStatus -> IterationStatus -> Bool
$c/= :: IterationStatus -> IterationStatus -> Bool
/= :: IterationStatus -> IterationStatus -> Bool
Eq, Int -> IterationStatus -> ShowS
[IterationStatus] -> ShowS
IterationStatus -> String
(Int -> IterationStatus -> ShowS)
-> (IterationStatus -> String)
-> ([IterationStatus] -> ShowS)
-> Show IterationStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IterationStatus -> ShowS
showsPrec :: Int -> IterationStatus -> ShowS
$cshow :: IterationStatus -> String
show :: IterationStatus -> String
$cshowList :: [IterationStatus] -> ShowS
showList :: [IterationStatus] -> ShowS
Show, (forall x. IterationStatus -> Rep IterationStatus x)
-> (forall x. Rep IterationStatus x -> IterationStatus)
-> Generic IterationStatus
forall x. Rep IterationStatus x -> IterationStatus
forall x. IterationStatus -> Rep IterationStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IterationStatus -> Rep IterationStatus x
from :: forall x. IterationStatus -> Rep IterationStatus x
$cto :: forall x. Rep IterationStatus x -> IterationStatus
to :: forall x. Rep IterationStatus x -> IterationStatus
Generic)

{- | One step in an iteration: an action was performed, the model state changed,
and a transaction was (possibly) submitted.
-}
data Transition = Transition
  { Transition -> Int
trStepIndex :: !Int
  -- ^ 0-based index within the iteration
  , Transition -> Text
trAction :: !Text
  -- ^ @show@ of the @Action state@ value
  , Transition -> Value
trStateBefore :: !Value
  -- ^ @toJSON@ of the model state before @perform@
  , Transition -> Value
trStateAfter :: !Value
  -- ^ @toJSON@ of the model state after @perform@
  , Transition -> Maybe TxSummary
trTransaction :: !(Maybe TxSummary)
  {- ^ The transaction produced, if any. @Nothing@ if @perform@ failed
  before building a transaction.
  -}
  , Transition -> TransitionResult
trResult :: !TransitionResult
  }
  deriving (Transition -> Transition -> Bool
(Transition -> Transition -> Bool)
-> (Transition -> Transition -> Bool) -> Eq Transition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Transition -> Transition -> Bool
== :: Transition -> Transition -> Bool
$c/= :: Transition -> Transition -> Bool
/= :: Transition -> Transition -> Bool
Eq, Int -> Transition -> ShowS
[Transition] -> ShowS
Transition -> String
(Int -> Transition -> ShowS)
-> (Transition -> String)
-> ([Transition] -> ShowS)
-> Show Transition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Transition -> ShowS
showsPrec :: Int -> Transition -> ShowS
$cshow :: Transition -> String
show :: Transition -> String
$cshowList :: [Transition] -> ShowS
showList :: [Transition] -> ShowS
Show, (forall x. Transition -> Rep Transition x)
-> (forall x. Rep Transition x -> Transition) -> Generic Transition
forall x. Rep Transition x -> Transition
forall x. Transition -> Rep Transition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Transition -> Rep Transition x
from :: forall x. Transition -> Rep Transition x
$cto :: forall x. Rep Transition x -> Transition
to :: forall x. Rep Transition x -> Transition
Generic)

-- | Whether the transaction was successfully submitted to the mockchain.
data TransitionResult
  = -- | TxId as text
    TransitionSuccess !Text
  | -- | Error description
    TransitionFailure !Text
  deriving (TransitionResult -> TransitionResult -> Bool
(TransitionResult -> TransitionResult -> Bool)
-> (TransitionResult -> TransitionResult -> Bool)
-> Eq TransitionResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TransitionResult -> TransitionResult -> Bool
== :: TransitionResult -> TransitionResult -> Bool
$c/= :: TransitionResult -> TransitionResult -> Bool
/= :: TransitionResult -> TransitionResult -> Bool
Eq, Int -> TransitionResult -> ShowS
[TransitionResult] -> ShowS
TransitionResult -> String
(Int -> TransitionResult -> ShowS)
-> (TransitionResult -> String)
-> ([TransitionResult] -> ShowS)
-> Show TransitionResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TransitionResult -> ShowS
showsPrec :: Int -> TransitionResult -> ShowS
$cshow :: TransitionResult -> String
show :: TransitionResult -> String
$cshowList :: [TransitionResult] -> ShowS
showList :: [TransitionResult] -> ShowS
Show, (forall x. TransitionResult -> Rep TransitionResult x)
-> (forall x. Rep TransitionResult x -> TransitionResult)
-> Generic TransitionResult
forall x. Rep TransitionResult x -> TransitionResult
forall x. TransitionResult -> Rep TransitionResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TransitionResult -> Rep TransitionResult x
from :: forall x. TransitionResult -> Rep TransitionResult x
$cto :: forall x. Rep TransitionResult x -> TransitionResult
to :: forall x. Rep TransitionResult x -> TransitionResult
Generic)

{- | Compact representation of a transaction for visualization.
Values are structured JSON for full fidelity.
-}
data TxSummary = TxSummary
  { TxSummary -> Maybe Text
txsId :: !(Maybe Text)
  -- ^ TxId if submitted successfully, @Nothing@ otherwise
  , TxSummary -> [TxInputSummary]
txsInputs :: ![TxInputSummary]
  , TxSummary -> [TxOutputSummary]
txsOutputs :: ![TxOutputSummary]
  , TxSummary -> Maybe ValueSummary
txsMint :: !(Maybe ValueSummary)
  -- ^ Structured mint value, @Nothing@ if no minting
  , TxSummary -> Integer
txsFee :: !Integer
  -- ^ Fee in lovelace
  , TxSummary -> [Text]
txsSigners :: ![Text]
  -- ^ Required signer key hashes
  , TxSummary -> Maybe Text
txsValidRange :: !(Maybe Text)
  -- ^ Rendered validity interval
  , TxSummary -> [TxWithdrawalSummary]
txsWithdrawals :: ![TxWithdrawalSummary]
  -- ^ Stake-reward withdrawals, including zero-lovelace ones (the "withdraw zero trick")
  }
  deriving (TxSummary -> TxSummary -> Bool
(TxSummary -> TxSummary -> Bool)
-> (TxSummary -> TxSummary -> Bool) -> Eq TxSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxSummary -> TxSummary -> Bool
== :: TxSummary -> TxSummary -> Bool
$c/= :: TxSummary -> TxSummary -> Bool
/= :: TxSummary -> TxSummary -> Bool
Eq, Int -> TxSummary -> ShowS
[TxSummary] -> ShowS
TxSummary -> String
(Int -> TxSummary -> ShowS)
-> (TxSummary -> String)
-> ([TxSummary] -> ShowS)
-> Show TxSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxSummary -> ShowS
showsPrec :: Int -> TxSummary -> ShowS
$cshow :: TxSummary -> String
show :: TxSummary -> String
$cshowList :: [TxSummary] -> ShowS
showList :: [TxSummary] -> ShowS
Show, (forall x. TxSummary -> Rep TxSummary x)
-> (forall x. Rep TxSummary x -> TxSummary) -> Generic TxSummary
forall x. Rep TxSummary x -> TxSummary
forall x. TxSummary -> Rep TxSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxSummary -> Rep TxSummary x
from :: forall x. TxSummary -> Rep TxSummary x
$cto :: forall x. Rep TxSummary x -> TxSummary
to :: forall x. Rep TxSummary x -> TxSummary
Generic)

-- | Summary of a transaction input.
data TxInputSummary = TxInputSummary
  { TxInputSummary -> Text
tisUtxo :: !Text
  -- ^ @"txid#index"@
  , TxInputSummary -> Text
tisAddress :: !Text
  -- ^ Bech32 or hex address
  , TxInputSummary -> AddressType
tisAddressType :: !AddressType
  -- ^ Whether 'tisAddress' is a public-key or a script address
  , TxInputSummary -> Maybe Text
tisAddressLabel :: !(Maybe Text)
  {- ^ Friendly label for the address's credential (e.g. @"Wallet 1"@), from the
  implementor's 'AddressLabeler'. @Nothing@ when unrecognised.
  -}
  , TxInputSummary -> ValueSummary
tisValue :: ValueSummary
  -- ^ Structured value (ada + tokens)
  , TxInputSummary -> Maybe Text
tisRedeemerRaw :: !(Maybe Text)
  {- ^ Hex (CBOR) of the spend redeemer's 'C.ScriptData', @Nothing@ for
  non-script inputs (no redeemer in the witness set).
  -}
  , TxInputSummary -> Maybe Integer
tisRedeemerConstr :: !(Maybe Integer)
  {- ^ Constr index when the parsed redeemer 'Data' is @Constr n _@;
  @Nothing@ for non-Constr redeemers or non-script inputs.
  -}
  , TxInputSummary -> Maybe Text
tisRedeemerKind :: !(Maybe Text)
  {- ^ Tier 2: human-readable redeemer label (e.g. @"Pong"@) produced by
  the implementor's 'RedeemerTagger'. @Nothing@ when no tagger is
  supplied or the tagger declines to label this redeemer.
  -}
  , TxInputSummary -> Maybe Value
tisRedeemerPayload :: !(Maybe Value)
  {- ^ Tier 2: optional JSON payload accompanying 'tisRedeemerKind'.
  @Nothing@ unless the tagger explicitly returns one.
  -}
  }
  deriving (TxInputSummary -> TxInputSummary -> Bool
(TxInputSummary -> TxInputSummary -> Bool)
-> (TxInputSummary -> TxInputSummary -> Bool) -> Eq TxInputSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxInputSummary -> TxInputSummary -> Bool
== :: TxInputSummary -> TxInputSummary -> Bool
$c/= :: TxInputSummary -> TxInputSummary -> Bool
/= :: TxInputSummary -> TxInputSummary -> Bool
Eq, Int -> TxInputSummary -> ShowS
[TxInputSummary] -> ShowS
TxInputSummary -> String
(Int -> TxInputSummary -> ShowS)
-> (TxInputSummary -> String)
-> ([TxInputSummary] -> ShowS)
-> Show TxInputSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxInputSummary -> ShowS
showsPrec :: Int -> TxInputSummary -> ShowS
$cshow :: TxInputSummary -> String
show :: TxInputSummary -> String
$cshowList :: [TxInputSummary] -> ShowS
showList :: [TxInputSummary] -> ShowS
Show, (forall x. TxInputSummary -> Rep TxInputSummary x)
-> (forall x. Rep TxInputSummary x -> TxInputSummary)
-> Generic TxInputSummary
forall x. Rep TxInputSummary x -> TxInputSummary
forall x. TxInputSummary -> Rep TxInputSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxInputSummary -> Rep TxInputSummary x
from :: forall x. TxInputSummary -> Rep TxInputSummary x
$cto :: forall x. Rep TxInputSummary x -> TxInputSummary
to :: forall x. Rep TxInputSummary x -> TxInputSummary
Generic)

-- | Summary of a transaction output.
data TxOutputSummary = TxOutputSummary
  { TxOutputSummary -> Text
tosUtxo :: !Text
  -- ^ @"txid#index"@ – the UTxO reference for this output
  , TxOutputSummary -> Text
tosAddress :: !Text
  , TxOutputSummary -> AddressType
tosAddressType :: !AddressType
  -- ^ Whether 'tosAddress' is a public-key or a script address
  , TxOutputSummary -> Maybe Text
tosAddressLabel :: !(Maybe Text)
  {- ^ Friendly label for the address's credential (e.g. @"Wallet 1"@), from the
  implementor's 'AddressLabeler'. @Nothing@ when unrecognised.
  -}
  , TxOutputSummary -> ValueSummary
tosValue :: !ValueSummary
  , TxOutputSummary -> Maybe Text
tosDatum :: !(Maybe Text)
  -- ^ @"inline:\<hash\>"@, @"hash:\<hash\>"@, or @Nothing@
  }
  deriving (TxOutputSummary -> TxOutputSummary -> Bool
(TxOutputSummary -> TxOutputSummary -> Bool)
-> (TxOutputSummary -> TxOutputSummary -> Bool)
-> Eq TxOutputSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxOutputSummary -> TxOutputSummary -> Bool
== :: TxOutputSummary -> TxOutputSummary -> Bool
$c/= :: TxOutputSummary -> TxOutputSummary -> Bool
/= :: TxOutputSummary -> TxOutputSummary -> Bool
Eq, Int -> TxOutputSummary -> ShowS
[TxOutputSummary] -> ShowS
TxOutputSummary -> String
(Int -> TxOutputSummary -> ShowS)
-> (TxOutputSummary -> String)
-> ([TxOutputSummary] -> ShowS)
-> Show TxOutputSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxOutputSummary -> ShowS
showsPrec :: Int -> TxOutputSummary -> ShowS
$cshow :: TxOutputSummary -> String
show :: TxOutputSummary -> String
$cshowList :: [TxOutputSummary] -> ShowS
showList :: [TxOutputSummary] -> ShowS
Show, (forall x. TxOutputSummary -> Rep TxOutputSummary x)
-> (forall x. Rep TxOutputSummary x -> TxOutputSummary)
-> Generic TxOutputSummary
forall x. Rep TxOutputSummary x -> TxOutputSummary
forall x. TxOutputSummary -> Rep TxOutputSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxOutputSummary -> Rep TxOutputSummary x
from :: forall x. TxOutputSummary -> Rep TxOutputSummary x
$cto :: forall x. Rep TxOutputSummary x -> TxOutputSummary
to :: forall x. Rep TxOutputSummary x -> TxOutputSummary
Generic)

{- | Whether an address's credential is a public key or a script, so a client
doesn't have to parse the address itself to find out.
-}
data AddressType
  = PublicKey
  | Script
  deriving (AddressType -> AddressType -> Bool
(AddressType -> AddressType -> Bool)
-> (AddressType -> AddressType -> Bool) -> Eq AddressType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddressType -> AddressType -> Bool
== :: AddressType -> AddressType -> Bool
$c/= :: AddressType -> AddressType -> Bool
/= :: AddressType -> AddressType -> Bool
Eq, Int -> AddressType -> ShowS
[AddressType] -> ShowS
AddressType -> String
(Int -> AddressType -> ShowS)
-> (AddressType -> String)
-> ([AddressType] -> ShowS)
-> Show AddressType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddressType -> ShowS
showsPrec :: Int -> AddressType -> ShowS
$cshow :: AddressType -> String
show :: AddressType -> String
$cshowList :: [AddressType] -> ShowS
showList :: [AddressType] -> ShowS
Show, (forall x. AddressType -> Rep AddressType x)
-> (forall x. Rep AddressType x -> AddressType)
-> Generic AddressType
forall x. Rep AddressType x -> AddressType
forall x. AddressType -> Rep AddressType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AddressType -> Rep AddressType x
from :: forall x. AddressType -> Rep AddressType x
$cto :: forall x. Rep AddressType x -> AddressType
to :: forall x. Rep AddressType x -> AddressType
Generic)

instance ToJSON AddressType where
  toJSON :: AddressType -> Value
toJSON AddressType
PublicKey = Value
"public-key"
  toJSON AddressType
Script = Value
"script"

{- | Summary of a stake-reward withdrawal. Includes zero-lovelace withdrawals,
which are how a script attached to a stake credential can be triggered to run
its logic without spending or creating any UTxO (the "withdraw zero trick").
-}
data TxWithdrawalSummary = TxWithdrawalSummary
  { TxWithdrawalSummary -> Text
twsStakeAddress :: !Text
  -- ^ Bech32 stake address the withdrawal is drawn from
  , TxWithdrawalSummary -> AddressType
twsAddressType :: !AddressType
  -- ^ Whether 'twsStakeAddress' is a public-key or a script stake credential
  , TxWithdrawalSummary -> Maybe Text
twsAddressLabel :: !(Maybe Text)
  {- ^ Friendly label for the stake credential (e.g. @"Wallet 1"@), from the
  implementor's 'AddressLabeler'. @Nothing@ when unrecognised.
  -}
  , TxWithdrawalSummary -> Integer
twsAmount :: !Integer
  -- ^ Withdrawn amount in lovelace (0 for the "withdraw zero trick")
  , TxWithdrawalSummary -> Maybe Text
twsRedeemerRaw :: !(Maybe Text)
  {- ^ Hex (CBOR) of the withdrawal redeemer's 'C.ScriptData', @Nothing@ for
  key-witnessed (non-script) withdrawals.
  -}
  , TxWithdrawalSummary -> Maybe Integer
twsRedeemerConstr :: !(Maybe Integer)
  {- ^ Constr index when the parsed redeemer 'Data' is @Constr n _@;
  @Nothing@ for non-Constr redeemers or non-script withdrawals.
  -}
  , TxWithdrawalSummary -> Maybe Text
twsRedeemerKind :: !(Maybe Text)
  {- ^ Tier 2: human-readable redeemer label produced by the implementor's
  'RedeemerTagger'. @Nothing@ when no tagger is supplied or the tagger
  declines to label this redeemer.
  -}
  , TxWithdrawalSummary -> Maybe Value
twsRedeemerPayload :: !(Maybe Value)
  {- ^ Tier 2: optional JSON payload accompanying 'twsRedeemerKind'.
  @Nothing@ unless the tagger explicitly returns one.
  -}
  }
  deriving (TxWithdrawalSummary -> TxWithdrawalSummary -> Bool
(TxWithdrawalSummary -> TxWithdrawalSummary -> Bool)
-> (TxWithdrawalSummary -> TxWithdrawalSummary -> Bool)
-> Eq TxWithdrawalSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxWithdrawalSummary -> TxWithdrawalSummary -> Bool
== :: TxWithdrawalSummary -> TxWithdrawalSummary -> Bool
$c/= :: TxWithdrawalSummary -> TxWithdrawalSummary -> Bool
/= :: TxWithdrawalSummary -> TxWithdrawalSummary -> Bool
Eq, Int -> TxWithdrawalSummary -> ShowS
[TxWithdrawalSummary] -> ShowS
TxWithdrawalSummary -> String
(Int -> TxWithdrawalSummary -> ShowS)
-> (TxWithdrawalSummary -> String)
-> ([TxWithdrawalSummary] -> ShowS)
-> Show TxWithdrawalSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxWithdrawalSummary -> ShowS
showsPrec :: Int -> TxWithdrawalSummary -> ShowS
$cshow :: TxWithdrawalSummary -> String
show :: TxWithdrawalSummary -> String
$cshowList :: [TxWithdrawalSummary] -> ShowS
showList :: [TxWithdrawalSummary] -> ShowS
Show, (forall x. TxWithdrawalSummary -> Rep TxWithdrawalSummary x)
-> (forall x. Rep TxWithdrawalSummary x -> TxWithdrawalSummary)
-> Generic TxWithdrawalSummary
forall x. Rep TxWithdrawalSummary x -> TxWithdrawalSummary
forall x. TxWithdrawalSummary -> Rep TxWithdrawalSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxWithdrawalSummary -> Rep TxWithdrawalSummary x
from :: forall x. TxWithdrawalSummary -> Rep TxWithdrawalSummary x
$cto :: forall x. Rep TxWithdrawalSummary x -> TxWithdrawalSummary
to :: forall x. Rep TxWithdrawalSummary x -> TxWithdrawalSummary
Generic)

-- | Structured representation of a Cardano value for JSON serialization.
data ValueSummary = ValueSummary
  { ValueSummary -> Integer
vsLovelace :: !Integer
  , ValueSummary -> [AssetSummary]
vsAssets :: ![AssetSummary]
  }
  deriving (ValueSummary -> ValueSummary -> Bool
(ValueSummary -> ValueSummary -> Bool)
-> (ValueSummary -> ValueSummary -> Bool) -> Eq ValueSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ValueSummary -> ValueSummary -> Bool
== :: ValueSummary -> ValueSummary -> Bool
$c/= :: ValueSummary -> ValueSummary -> Bool
/= :: ValueSummary -> ValueSummary -> Bool
Eq, Int -> ValueSummary -> ShowS
[ValueSummary] -> ShowS
ValueSummary -> String
(Int -> ValueSummary -> ShowS)
-> (ValueSummary -> String)
-> ([ValueSummary] -> ShowS)
-> Show ValueSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ValueSummary -> ShowS
showsPrec :: Int -> ValueSummary -> ShowS
$cshow :: ValueSummary -> String
show :: ValueSummary -> String
$cshowList :: [ValueSummary] -> ShowS
showList :: [ValueSummary] -> ShowS
Show, (forall x. ValueSummary -> Rep ValueSummary x)
-> (forall x. Rep ValueSummary x -> ValueSummary)
-> Generic ValueSummary
forall x. Rep ValueSummary x -> ValueSummary
forall x. ValueSummary -> Rep ValueSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ValueSummary -> Rep ValueSummary x
from :: forall x. ValueSummary -> Rep ValueSummary x
$cto :: forall x. Rep ValueSummary x -> ValueSummary
to :: forall x. Rep ValueSummary x -> ValueSummary
Generic)

data AssetSummary = AssetSummary
  { AssetSummary -> Text
asPolicyId :: !Text
  , AssetSummary -> Text
asName :: !Text
  , AssetSummary -> Integer
asQuantity :: !Integer
  }
  deriving (AssetSummary -> AssetSummary -> Bool
(AssetSummary -> AssetSummary -> Bool)
-> (AssetSummary -> AssetSummary -> Bool) -> Eq AssetSummary
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AssetSummary -> AssetSummary -> Bool
== :: AssetSummary -> AssetSummary -> Bool
$c/= :: AssetSummary -> AssetSummary -> Bool
/= :: AssetSummary -> AssetSummary -> Bool
Eq, Int -> AssetSummary -> ShowS
[AssetSummary] -> ShowS
AssetSummary -> String
(Int -> AssetSummary -> ShowS)
-> (AssetSummary -> String)
-> ([AssetSummary] -> ShowS)
-> Show AssetSummary
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AssetSummary -> ShowS
showsPrec :: Int -> AssetSummary -> ShowS
$cshow :: AssetSummary -> String
show :: AssetSummary -> String
$cshowList :: [AssetSummary] -> ShowS
showList :: [AssetSummary] -> ShowS
Show, (forall x. AssetSummary -> Rep AssetSummary x)
-> (forall x. Rep AssetSummary x -> AssetSummary)
-> Generic AssetSummary
forall x. Rep AssetSummary x -> AssetSummary
forall x. AssetSummary -> Rep AssetSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. AssetSummary -> Rep AssetSummary x
from :: forall x. AssetSummary -> Rep AssetSummary x
$cto :: forall x. Rep AssetSummary x -> AssetSummary
to :: forall x. Rep AssetSummary x -> AssetSummary
Generic)

{- | A human-readable label for a redeemer, produced by a 'RedeemerTagger'
supplied by the implementor (Tier 2). When no tagger matches, both
'tisRedeemerKind' and 'tisRedeemerPayload' stay @Nothing@ and only Tier 1
('tisRedeemerRaw' / 'tisRedeemerConstr') is streamed.
-}
data RedeemerTag = RedeemerTag
  { RedeemerTag -> Text
rtKind :: !Text
  -- ^ Discriminator such as @"Ping"@ / @"Pong"@.
  , RedeemerTag -> Maybe Value
rtPayload :: !(Maybe Value)
  -- ^ Optional JSON payload for richer UI columns.
  }

{- | An opt-in function from a parsed Plutus 'Data' (the redeemer of a script
input) to an optional 'RedeemerTag'. The 'Monoid' instance picks the first
'Just' result, enabling composition of per-validator taggers.
-}
newtype RedeemerTagger = RedeemerTagger
  { RedeemerTagger -> Data -> Maybe RedeemerTag
applyRedeemerTagger :: Data -> Maybe RedeemerTag
  }

instance Semigroup RedeemerTagger where
  RedeemerTagger Data -> Maybe RedeemerTag
f <> :: RedeemerTagger -> RedeemerTagger -> RedeemerTagger
<> RedeemerTagger Data -> Maybe RedeemerTag
g =
    (Data -> Maybe RedeemerTag) -> RedeemerTagger
RedeemerTagger (\Data
d -> Data -> Maybe RedeemerTag
f Data
d Maybe RedeemerTag -> Maybe RedeemerTag -> Maybe RedeemerTag
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Data -> Maybe RedeemerTag
g Data
d)

instance Monoid RedeemerTagger where
  mempty :: RedeemerTagger
mempty = (Data -> Maybe RedeemerTag) -> RedeemerTagger
RedeemerTagger (Maybe RedeemerTag -> Data -> Maybe RedeemerTag
forall a b. a -> b -> a
const Maybe RedeemerTag
forall a. Maybe a
Nothing)

{- | An opt-in function from the hex-encoded hash of an address's payment or
stake credential (key hash or script hash) to a human-readable label, so a
client doesn't need to recognise raw hashes to tell wallets and scripts
apart. The 'TestingInterface' default ('Convex.TestingInterface.mockWalletAddressLabeler')
labels the standard mock wallets as @"Wallet 1".."Wallet 10"@; override or extend it
(via the 'Monoid' instance, which picks the first 'Just' result) to label a
model's own script hashes or additional keys.
-}
newtype AddressLabeler = AddressLabeler
  { AddressLabeler -> Text -> Maybe Text
applyAddressLabeler :: Text -> Maybe Text
  }

instance Semigroup AddressLabeler where
  AddressLabeler Text -> Maybe Text
f <> :: AddressLabeler -> AddressLabeler -> AddressLabeler
<> AddressLabeler Text -> Maybe Text
g =
    (Text -> Maybe Text) -> AddressLabeler
AddressLabeler (\Text
h -> Text -> Maybe Text
f Text
h Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Maybe Text
g Text
h)

instance Monoid AddressLabeler where
  mempty :: AddressLabeler
mempty = (Text -> Maybe Text) -> AddressLabeler
AddressLabeler (Maybe Text -> Text -> Maybe Text
forall a b. a -> b -> a
const Maybe Text
forall a. Maybe a
Nothing)

instance ToJSON ValueSummary where
  toJSON :: ValueSummary -> Value
toJSON ValueSummary
v =
    [Pair] -> Value
object
      [ Key
"lovelace" Key -> Integer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ValueSummary -> Integer
vsLovelace ValueSummary
v
      , Key
"assets" Key -> [AssetSummary] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ValueSummary -> [AssetSummary]
vsAssets ValueSummary
v
      ]

instance ToJSON AssetSummary where
  toJSON :: AssetSummary -> Value
toJSON AssetSummary
a =
    [Pair] -> Value
object
      [ Key
"policyId" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AssetSummary -> Text
asPolicyId AssetSummary
a
      , Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AssetSummary -> Text
asName AssetSummary
a
      , Key
"quantity" Key -> Integer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= AssetSummary -> Integer
asQuantity AssetSummary
a
      ]

{- | What happened when a threat model was applied to a specific transaction
in this iteration.
-}
data ThreatModelTrace = ThreatModelTrace
  { ThreatModelTrace -> Text
tmtName :: !Text
  -- ^ Name of the threat model (e.g. "unprotectedScriptOutput")
  , ThreatModelTrace -> ThreatModelCategory
tmtCategory :: !ThreatModelCategory
  {- ^ Which @ThreatModelsFor@ list the model came from, i.e. how a 'TMTOFailed'
  outcome is to be read. Repeated on every entry so that a consumer of the
  @test_trace@ stream can tell a vulnerability from an expected or accepted
  finding without waiting for the @test_done@ event that carries the
  run-level 'Convex.Tasty.Streaming.TMSummary.ThreatModelSummary'.
  -}
  , ThreatModelTrace -> Int
tmtTestId :: !Int
  -- ^ Test id of the threat model
  , ThreatModelTrace -> Int
tmtTargetTxIndex :: !Int
  -- ^ Index into 'itTransitions' identifying which transaction was targeted
  , ThreatModelTrace -> [Value]
tmtModifications :: ![Value]
  -- ^ Structured JSON descriptions of each modification applied
  , ThreatModelTrace -> TxSummary
tmtOriginalTx :: !TxSummary
  -- ^ The original transaction before modification
  , ThreatModelTrace -> Maybe TxSummary
tmtModifiedTx :: !(Maybe TxSummary)
  -- ^ The modified transaction, @Nothing@ if the modification couldn't produce a valid tx body
  , ThreatModelTrace -> Maybe ThreatModelValidation
tmtValidation :: !(Maybe ThreatModelValidation)
  {- ^ How the ledger judged /this/ modified transaction. @Nothing@ when there is
  no verdict to report: the lightweight trace emitted when the threat model made
  no 'Validate' call at all, or a 'Validate' call that recorded neither a
  validity report nor a rebalancing error (not expected).
  Unlike 'tmtOutcome', which is the verdict of the whole threat model run and is
  repeated on every entry of that run, this is specific to the entry.
  -}
  , ThreatModelTrace -> ThreatModelTraceOutcome
tmtOutcome :: !ThreatModelTraceOutcome
  -- ^ The outcome of running the threat model
  , ThreatModelTrace -> [SrcLocRange]
tmtCovered :: ![SrcLocRange]
  -- ^ The code ranges covered by running this threat model
  }
  deriving (ThreatModelTrace -> ThreatModelTrace -> Bool
(ThreatModelTrace -> ThreatModelTrace -> Bool)
-> (ThreatModelTrace -> ThreatModelTrace -> Bool)
-> Eq ThreatModelTrace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ThreatModelTrace -> ThreatModelTrace -> Bool
== :: ThreatModelTrace -> ThreatModelTrace -> Bool
$c/= :: ThreatModelTrace -> ThreatModelTrace -> Bool
/= :: ThreatModelTrace -> ThreatModelTrace -> Bool
Eq, Int -> ThreatModelTrace -> ShowS
[ThreatModelTrace] -> ShowS
ThreatModelTrace -> String
(Int -> ThreatModelTrace -> ShowS)
-> (ThreatModelTrace -> String)
-> ([ThreatModelTrace] -> ShowS)
-> Show ThreatModelTrace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThreatModelTrace -> ShowS
showsPrec :: Int -> ThreatModelTrace -> ShowS
$cshow :: ThreatModelTrace -> String
show :: ThreatModelTrace -> String
$cshowList :: [ThreatModelTrace] -> ShowS
showList :: [ThreatModelTrace] -> ShowS
Show, (forall x. ThreatModelTrace -> Rep ThreatModelTrace x)
-> (forall x. Rep ThreatModelTrace x -> ThreatModelTrace)
-> Generic ThreatModelTrace
forall x. Rep ThreatModelTrace x -> ThreatModelTrace
forall x. ThreatModelTrace -> Rep ThreatModelTrace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ThreatModelTrace -> Rep ThreatModelTrace x
from :: forall x. ThreatModelTrace -> Rep ThreatModelTrace x
$cto :: forall x. Rep ThreatModelTrace x -> ThreatModelTrace
to :: forall x. Rep ThreatModelTrace x -> ThreatModelTrace
Generic)

-- | Outcome of applying a threat model to a transaction.
data ThreatModelTraceOutcome
  = -- | Modified tx was correctly rejected by the ledger (good!)
    TMTOPassed
  | -- | Modified tx was ACCEPTED by the ledger (vulnerability found!)
    TMTOFailed !Text
  | -- | Couldn't test: rebalancing failed or precondition not met
    TMTOSkipped !Text
  | -- | Skipped: modified tx hit Phase 1 invalidation
    TMTOSkippedPhase1 !Text
  | -- | Unexpected error during threat model execution
    TMTOError !Text
  deriving (ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool
(ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool)
-> (ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool)
-> Eq ThreatModelTraceOutcome
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool
== :: ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool
$c/= :: ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool
/= :: ThreatModelTraceOutcome -> ThreatModelTraceOutcome -> Bool
Eq, Int -> ThreatModelTraceOutcome -> ShowS
[ThreatModelTraceOutcome] -> ShowS
ThreatModelTraceOutcome -> String
(Int -> ThreatModelTraceOutcome -> ShowS)
-> (ThreatModelTraceOutcome -> String)
-> ([ThreatModelTraceOutcome] -> ShowS)
-> Show ThreatModelTraceOutcome
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThreatModelTraceOutcome -> ShowS
showsPrec :: Int -> ThreatModelTraceOutcome -> ShowS
$cshow :: ThreatModelTraceOutcome -> String
show :: ThreatModelTraceOutcome -> String
$cshowList :: [ThreatModelTraceOutcome] -> ShowS
showList :: [ThreatModelTraceOutcome] -> ShowS
Show, (forall x.
 ThreatModelTraceOutcome -> Rep ThreatModelTraceOutcome x)
-> (forall x.
    Rep ThreatModelTraceOutcome x -> ThreatModelTraceOutcome)
-> Generic ThreatModelTraceOutcome
forall x. Rep ThreatModelTraceOutcome x -> ThreatModelTraceOutcome
forall x. ThreatModelTraceOutcome -> Rep ThreatModelTraceOutcome x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ThreatModelTraceOutcome -> Rep ThreatModelTraceOutcome x
from :: forall x. ThreatModelTraceOutcome -> Rep ThreatModelTraceOutcome x
$cto :: forall x. Rep ThreatModelTraceOutcome x -> ThreatModelTraceOutcome
to :: forall x. Rep ThreatModelTraceOutcome x -> ThreatModelTraceOutcome
Generic)

-- | The ledger's verdict on a single modified transaction produced by a 'Validate' call.
data ThreatModelValidation
  = -- | Phase 1 and Phase 2 both passed: the ledger accepted the modified tx
    TMVValid
  | -- | Rejected by Phase 1 ledger rules; scripts never ran. Carries the error messages.
    TMVPhase1Invalid ![Text]
  | -- | Phase 1 passed but a script rejected the tx. Carries the script error messages.
    TMVPhase2Invalid ![Text]
  | -- | The modified tx could not be rebalanced and signed, so it was never validated
    TMVRebalanceFailed !Text
  deriving (ThreatModelValidation -> ThreatModelValidation -> Bool
(ThreatModelValidation -> ThreatModelValidation -> Bool)
-> (ThreatModelValidation -> ThreatModelValidation -> Bool)
-> Eq ThreatModelValidation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ThreatModelValidation -> ThreatModelValidation -> Bool
== :: ThreatModelValidation -> ThreatModelValidation -> Bool
$c/= :: ThreatModelValidation -> ThreatModelValidation -> Bool
/= :: ThreatModelValidation -> ThreatModelValidation -> Bool
Eq, Int -> ThreatModelValidation -> ShowS
[ThreatModelValidation] -> ShowS
ThreatModelValidation -> String
(Int -> ThreatModelValidation -> ShowS)
-> (ThreatModelValidation -> String)
-> ([ThreatModelValidation] -> ShowS)
-> Show ThreatModelValidation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThreatModelValidation -> ShowS
showsPrec :: Int -> ThreatModelValidation -> ShowS
$cshow :: ThreatModelValidation -> String
show :: ThreatModelValidation -> String
$cshowList :: [ThreatModelValidation] -> ShowS
showList :: [ThreatModelValidation] -> ShowS
Show, (forall x. ThreatModelValidation -> Rep ThreatModelValidation x)
-> (forall x. Rep ThreatModelValidation x -> ThreatModelValidation)
-> Generic ThreatModelValidation
forall x. Rep ThreatModelValidation x -> ThreatModelValidation
forall x. ThreatModelValidation -> Rep ThreatModelValidation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ThreatModelValidation -> Rep ThreatModelValidation x
from :: forall x. ThreatModelValidation -> Rep ThreatModelValidation x
$cto :: forall x. Rep ThreatModelValidation x -> ThreatModelValidation
to :: forall x. Rep ThreatModelValidation x -> ThreatModelValidation
Generic)

-- ---------------------------------------------------------------------
-- ToJSON instances
-- ---------------------------------------------------------------------

instance ToJSON TestRunTrace where
  toJSON :: TestRunTrace -> Value
toJSON TestRunTrace
t =
    [Pair] -> Value
object
      [ Key
"testId" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TestRunTrace -> Int
trtTestId TestRunTrace
t
      , Key
"testName" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TestRunTrace -> Text
trtTestName TestRunTrace
t
      , Key
"path" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TestRunTrace -> [Text]
trtPath TestRunTrace
t
      , Key
"category" Key -> TestCategory -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TestRunTrace -> TestCategory
trtCategory TestRunTrace
t
      , Key
"iterations" Key -> [IterationTrace] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TestRunTrace -> [IterationTrace]
trtIterations TestRunTrace
t
      ]

instance ToJSON IterationTrace where
  toJSON :: IterationTrace -> Value
toJSON IterationTrace
t =
    [Pair] -> Value
object
      [ Key
"index" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= IterationTrace -> Int
itIndex IterationTrace
t
      , Key
"status" Key -> IterationStatus -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= IterationTrace -> IterationStatus
itStatus IterationTrace
t
      , Key
"transitions" Key -> [Transition] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= IterationTrace -> [Transition]
itTransitions IterationTrace
t
      , Key
"threatModels" Key -> [ThreatModelTrace] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= IterationTrace -> [ThreatModelTrace]
itThreatModels IterationTrace
t
      ]

instance ToJSON IterationStatus where
  toJSON :: IterationStatus -> Value
toJSON IterationStatus
IterationSuccess =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"success" :: Text)]
  toJSON (IterationFailure Text
msg) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"failure" :: Text), Key
"message" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
msg]
  toJSON (IterationDiscarded Text
msg) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"discarded" :: Text), Key
"message" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
msg]

instance ToJSON Transition where
  toJSON :: Transition -> Value
toJSON Transition
t =
    [Pair] -> Value
object
      [ Key
"stepIndex" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Transition -> Int
trStepIndex Transition
t
      , Key
"action" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Transition -> Text
trAction Transition
t
      , Key
"stateBefore" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Transition -> Value
trStateBefore Transition
t
      , Key
"stateAfter" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Transition -> Value
trStateAfter Transition
t
      , Key
"transaction" Key -> Maybe TxSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Transition -> Maybe TxSummary
trTransaction Transition
t
      , Key
"result" Key -> TransitionResult -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Transition -> TransitionResult
trResult Transition
t
      ]

instance ToJSON TransitionResult where
  toJSON :: TransitionResult -> Value
toJSON (TransitionSuccess Text
txId) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"success" :: Text), Key
"txId" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
txId]
  toJSON (TransitionFailure Text
err) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"failure" :: Text), Key
"error" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
err]

instance ToJSON TxSummary where
  toJSON :: TxSummary -> Value
toJSON TxSummary
t =
    [Pair] -> Value
object
      [ Key
"id" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> Maybe Text
txsId TxSummary
t
      , Key
"inputs" Key -> [TxInputSummary] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> [TxInputSummary]
txsInputs TxSummary
t
      , Key
"outputs" Key -> [TxOutputSummary] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> [TxOutputSummary]
txsOutputs TxSummary
t
      , Key
"mint" Key -> Maybe ValueSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> Maybe ValueSummary
txsMint TxSummary
t
      , Key
"fee" Key -> Integer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> Integer
txsFee TxSummary
t
      , Key
"signers" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> [Text]
txsSigners TxSummary
t
      , Key
"validRange" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> Maybe Text
txsValidRange TxSummary
t
      , Key
"withdrawals" Key -> [TxWithdrawalSummary] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxSummary -> [TxWithdrawalSummary]
txsWithdrawals TxSummary
t
      ]

instance ToJSON TxWithdrawalSummary where
  toJSON :: TxWithdrawalSummary -> Value
toJSON TxWithdrawalSummary
t =
    [Pair] -> Value
object
      [ Key
"stakeAddress" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Text
twsStakeAddress TxWithdrawalSummary
t
      , Key
"addressType" Key -> AddressType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> AddressType
twsAddressType TxWithdrawalSummary
t
      , Key
"addressLabel" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Maybe Text
twsAddressLabel TxWithdrawalSummary
t
      , Key
"amount" Key -> Integer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Integer
twsAmount TxWithdrawalSummary
t
      , Key
"redeemerRaw" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Maybe Text
twsRedeemerRaw TxWithdrawalSummary
t
      , Key
"redeemerConstr" Key -> Maybe Integer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Maybe Integer
twsRedeemerConstr TxWithdrawalSummary
t
      , Key
"redeemerKind" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Maybe Text
twsRedeemerKind TxWithdrawalSummary
t
      , Key
"redeemerPayload" Key -> Maybe Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxWithdrawalSummary -> Maybe Value
twsRedeemerPayload TxWithdrawalSummary
t
      ]

instance ToJSON TxInputSummary where
  toJSON :: TxInputSummary -> Value
toJSON TxInputSummary
t =
    [Pair] -> Value
object
      [ Key
"utxo" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Text
tisUtxo TxInputSummary
t
      , Key
"address" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Text
tisAddress TxInputSummary
t
      , Key
"addressType" Key -> AddressType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> AddressType
tisAddressType TxInputSummary
t
      , Key
"addressLabel" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Maybe Text
tisAddressLabel TxInputSummary
t
      , Key
"value" Key -> ValueSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> ValueSummary
tisValue TxInputSummary
t
      , Key
"redeemerRaw" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Maybe Text
tisRedeemerRaw TxInputSummary
t
      , Key
"redeemerConstr" Key -> Maybe Integer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Maybe Integer
tisRedeemerConstr TxInputSummary
t
      , Key
"redeemerKind" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Maybe Text
tisRedeemerKind TxInputSummary
t
      , Key
"redeemerPayload" Key -> Maybe Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxInputSummary -> Maybe Value
tisRedeemerPayload TxInputSummary
t
      ]

instance ToJSON TxOutputSummary where
  toJSON :: TxOutputSummary -> Value
toJSON TxOutputSummary
t =
    [Pair] -> Value
object
      [ Key
"utxo" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxOutputSummary -> Text
tosUtxo TxOutputSummary
t
      , Key
"address" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxOutputSummary -> Text
tosAddress TxOutputSummary
t
      , Key
"addressType" Key -> AddressType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxOutputSummary -> AddressType
tosAddressType TxOutputSummary
t
      , Key
"addressLabel" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxOutputSummary -> Maybe Text
tosAddressLabel TxOutputSummary
t
      , Key
"value" Key -> ValueSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxOutputSummary -> ValueSummary
tosValue TxOutputSummary
t
      , Key
"datum" Key -> Maybe Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= TxOutputSummary -> Maybe Text
tosDatum TxOutputSummary
t
      ]

instance ToJSON ThreatModelTrace where
  toJSON :: ThreatModelTrace -> Value
toJSON ThreatModelTrace
t =
    [Pair] -> Value
object
      [ Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> Text
tmtName ThreatModelTrace
t
      , Key
"category" Key -> ThreatModelCategory -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> ThreatModelCategory
tmtCategory ThreatModelTrace
t
      , Key
"testId" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> Int
tmtTestId ThreatModelTrace
t
      , Key
"targetTxIndex" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> Int
tmtTargetTxIndex ThreatModelTrace
t
      , Key
"modifications" Key -> [Value] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> [Value]
tmtModifications ThreatModelTrace
t
      , Key
"originalTx" Key -> TxSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> TxSummary
tmtOriginalTx ThreatModelTrace
t
      , Key
"modifiedTx" Key -> Maybe TxSummary -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> Maybe TxSummary
tmtModifiedTx ThreatModelTrace
t
      , Key
"validation" Key -> Maybe ThreatModelValidation -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> Maybe ThreatModelValidation
tmtValidation ThreatModelTrace
t
      , Key
"outcome" Key -> ThreatModelTraceOutcome -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ThreatModelTrace -> ThreatModelTraceOutcome
tmtOutcome ThreatModelTrace
t
      , Key
"covered" Key -> [SrcLocRanges] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [SrcLocRange] -> [SrcLocRanges]
groupRanges (ThreatModelTrace -> [SrcLocRange]
tmtCovered ThreatModelTrace
t)
      ]

instance ToJSON ThreatModelTraceOutcome where
  toJSON :: ThreatModelTraceOutcome -> Value
toJSON ThreatModelTraceOutcome
TMTOPassed =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"passed" :: Text)]
  toJSON (TMTOFailed Text
reason) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"failed" :: Text), Key
"reason" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
reason]
  toJSON (TMTOSkipped Text
reason) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"skipped" :: Text), Key
"reason" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
reason]
  toJSON (TMTOSkippedPhase1 Text
reason) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"skipped_phase1" :: Text), Key
"reason" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
reason]
  toJSON (TMTOError Text
msg) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"error" :: Text), Key
"message" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
msg]

instance ToJSON ThreatModelValidation where
  toJSON :: ThreatModelValidation -> Value
toJSON ThreatModelValidation
TMVValid =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"valid" :: Text)]
  toJSON (TMVPhase1Invalid [Text]
errs) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"phase1_invalid" :: Text), Key
"errors" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Text]
errs]
  toJSON (TMVPhase2Invalid [Text]
errs) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"phase2_invalid" :: Text), Key
"errors" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Text]
errs]
  toJSON (TMVRebalanceFailed Text
reason) =
    [Pair] -> Value
object [Key
"status" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"rebalance_failed" :: Text), Key
"reason" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
reason]