{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | Empty Peras support for Byron.
--
-- NOTE: this module exists solely because the orphan module
-- 'Ouroboros.Consensus.Byron.Node.Serialisation' needs some of these instances,
-- but defining them there would be too confusing.
module Ouroboros.Consensus.Byron.Node.Peras () where

import Ouroboros.Consensus.Block.SupportsPeras
  ( BlockSupportsPeras (..)
  , VoidPerasCert
  , VoidPerasCrypto
  , VoidPerasError
  , VoidPerasVote
  , VoidPerasVotingCommitteeScheme
  , defaultForgePerasCert
  , defaultForgePerasVoteIfEligible
  , defaultVerifyPerasCert
  , defaultVerifyPerasVote
  )
import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)

{-------------------------------------------------------------------------------
  BlockSupportsPeras
-------------------------------------------------------------------------------}

instance BlockSupportsPeras ByronBlock where
  type PerasVote ByronBlock = VoidPerasVote ByronBlock
  type PerasCert ByronBlock = VoidPerasCert ByronBlock
  type PerasError ByronBlock = VoidPerasError ByronBlock
  type PerasCrypto ByronBlock = VoidPerasCrypto ByronBlock
  type PerasVotingCommitteeScheme ByronBlock = VoidPerasVotingCommitteeScheme
  forgePerasVoteIfEligible :: PerasEpochContext ByronBlock
-> PoolId
-> PrivateKey (PerasCrypto ByronBlock)
-> PerasRoundNo
-> Point ByronBlock
-> Either
     (PerasError ByronBlock) (Maybe (ValidatedPerasVote ByronBlock))
forgePerasVoteIfEligible = PerasEpochContext ByronBlock
-> PoolId
-> PrivateKey (PerasCrypto ByronBlock)
-> PerasRoundNo
-> Point ByronBlock
-> Either
     (PerasError ByronBlock) (Maybe (ValidatedPerasVote ByronBlock))
forall blk.
(BlockSupportsPeras blk,
 CryptoSupportsVotingCommittee
   (PerasCrypto blk) (PerasVotingCommitteeScheme blk),
 PerasVoteCompatibleWithVotingCommittee
   (PerasVote blk)
   (PerasCrypto blk)
   (PerasVotingCommitteeScheme blk)) =>
PerasEpochContext blk
-> PoolId
-> PrivateKey (PerasCrypto blk)
-> PerasRoundNo
-> Point blk
-> Either (PerasError blk) (Maybe (ValidatedPerasVote blk))
defaultForgePerasVoteIfEligible
  verifyPerasVote :: PerasEpochContext ByronBlock
-> PerasVote ByronBlock
-> Either (PerasError ByronBlock) (ValidatedPerasVote ByronBlock)
verifyPerasVote = PerasEpochContext ByronBlock
-> PerasVote ByronBlock
-> Either (PerasError ByronBlock) (ValidatedPerasVote ByronBlock)
forall blk.
(BlockSupportsPeras blk,
 CryptoSupportsVotingCommittee
   (PerasCrypto blk) (PerasVotingCommitteeScheme blk),
 PerasVoteCompatibleWithVotingCommittee
   (PerasVote blk)
   (PerasCrypto blk)
   (PerasVotingCommitteeScheme blk)) =>
PerasEpochContext blk
-> PerasVote blk
-> Either (PerasError blk) (ValidatedPerasVote blk)
defaultVerifyPerasVote
  forgePerasCert :: PerasEpochContext ByronBlock
-> PerasVoteCollectionWithQuorum ByronBlock
-> Either (PerasError ByronBlock) (ValidatedPerasCert ByronBlock)
forgePerasCert = PerasEpochContext ByronBlock
-> PerasVoteCollectionWithQuorum ByronBlock
-> Either (PerasError ByronBlock) (ValidatedPerasCert ByronBlock)
forall blk.
(BlockSupportsPeras blk,
 CryptoSupportsVotingCommittee
   (PerasCrypto blk) (PerasVotingCommitteeScheme blk),
 PerasVoteCompatibleWithVotingCommittee
   (PerasVote blk) (PerasCrypto blk) (PerasVotingCommitteeScheme blk),
 PerasCertCompatibleWithVotingCommittee
   (PerasCert blk)
   (PerasCrypto blk)
   (PerasVotingCommitteeScheme blk)) =>
PerasEpochContext blk
-> PerasVoteCollectionWithQuorum blk
-> Either (PerasError blk) (ValidatedPerasCert blk)
defaultForgePerasCert
  verifyPerasCert :: PerasEpochContext ByronBlock
-> PerasCert ByronBlock
-> Either (PerasError ByronBlock) (ValidatedPerasCert ByronBlock)
verifyPerasCert = PerasEpochContext ByronBlock
-> PerasCert ByronBlock
-> Either (PerasError ByronBlock) (ValidatedPerasCert ByronBlock)
forall blk.
(BlockSupportsPeras blk,
 CryptoSupportsVotingCommittee
   (PerasCrypto blk) (PerasVotingCommitteeScheme blk),
 PerasCertCompatibleWithVotingCommittee
   (PerasCert blk)
   (PerasCrypto blk)
   (PerasVotingCommitteeScheme blk)) =>
PerasEpochContext blk
-> PerasCert blk
-> Either (PerasError blk) (ValidatedPerasCert blk)
defaultVerifyPerasCert
  getPerasCertInBlock :: ByronBlock
-> Either (PerasError ByronBlock) (Maybe (PerasCert ByronBlock))
getPerasCertInBlock ByronBlock
_ = Maybe (VoidPerasCert ByronBlock)
-> Either
     (VoidPerasError ByronBlock) (Maybe (VoidPerasCert ByronBlock))
forall a b. b -> Either a b
Right Maybe (VoidPerasCert ByronBlock)
forall a. Maybe a
Nothing