module Hydra.Tx.Environment where

import Hydra.Prelude

import Hydra.Tx.ContestationPeriod (ContestationPeriod)
import Hydra.Tx.Crypto (HydraKey, SigningKey)
import Hydra.Tx.OnChainId (OnChainId)
import Hydra.Tx.Party (HasParty (..), Party, deriveParty)

data Environment = Environment
  { Environment -> Party
party :: Party
  -- ^ This is the p_i from the paper
  , -- XXX: In the long run we would not want to keep the signing key in memory,
    -- i.e. have an 'Effect' for signing or so.
    Environment -> SigningKey HydraKey
signingKey :: SigningKey HydraKey
  , Environment -> [Party]
otherParties :: [Party]
  , -- XXX: Improve naming
    Environment -> [OnChainId]
participants :: [OnChainId]
  , Environment -> ContestationPeriod
contestationPeriod :: ContestationPeriod
  }
  deriving stock (Int -> Environment -> ShowS
[Environment] -> ShowS
Environment -> String
(Int -> Environment -> ShowS)
-> (Environment -> String)
-> ([Environment] -> ShowS)
-> Show Environment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Environment -> ShowS
showsPrec :: Int -> Environment -> ShowS
$cshow :: Environment -> String
show :: Environment -> String
$cshowList :: [Environment] -> ShowS
showList :: [Environment] -> ShowS
Show, Environment -> Environment -> Bool
(Environment -> Environment -> Bool)
-> (Environment -> Environment -> Bool) -> Eq Environment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Environment -> Environment -> Bool
== :: Environment -> Environment -> Bool
$c/= :: Environment -> Environment -> Bool
/= :: Environment -> Environment -> Bool
Eq)

instance Arbitrary Environment where
  arbitrary :: Gen Environment
arbitrary = do
    SigningKey HydraKey
signingKey <- Gen (SigningKey HydraKey)
forall a. Arbitrary a => Gen a
arbitrary
    [Party]
otherParties <- Gen [Party]
forall a. Arbitrary a => Gen a
arbitrary
    [OnChainId]
participants <- Gen [OnChainId]
forall a. Arbitrary a => Gen a
arbitrary
    ContestationPeriod
contestationPeriod <- Gen ContestationPeriod
forall a. Arbitrary a => Gen a
arbitrary
    Environment -> Gen Environment
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Environment -> Gen Environment) -> Environment -> Gen Environment
forall a b. (a -> b) -> a -> b
$
      Environment
        { SigningKey HydraKey
$sel:signingKey:Environment :: SigningKey HydraKey
signingKey :: SigningKey HydraKey
signingKey
        , $sel:party:Environment :: Party
party = SigningKey HydraKey -> Party
deriveParty SigningKey HydraKey
signingKey
        , [Party]
$sel:otherParties:Environment :: [Party]
otherParties :: [Party]
otherParties
        , ContestationPeriod
$sel:contestationPeriod:Environment :: ContestationPeriod
contestationPeriod :: ContestationPeriod
contestationPeriod
        , [OnChainId]
$sel:participants:Environment :: [OnChainId]
participants :: [OnChainId]
participants
        }

instance HasParty Environment where
  getParty :: Environment -> Party
getParty = Environment -> Party
party