{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Allegra.UTxO () where

import Cardano.Ledger.Allegra.Core
import Cardano.Ledger.Allegra.Era (AllegraEra)
import Cardano.Ledger.Shelley.UTxO (
  ShelleyScriptsNeeded (..),
  getConsumedCoin,
  getShelleyMinFeeTxUtxo,
  getShelleyScriptsNeeded,
  getShelleyWitsVKeyNeeded,
  shelleyProducedValue,
 )
import Cardano.Ledger.UTxO (EraUTxO (..), ScriptsProvided (..))
import Lens.Micro

instance EraUTxO AllegraEra where
  type ScriptsNeeded AllegraEra = ShelleyScriptsNeeded AllegraEra

  getConsumedValue :: PParams AllegraEra
-> (Credential 'Staking -> Maybe Coin)
-> (Credential 'DRepRole -> Maybe Coin)
-> UTxO AllegraEra
-> TxBody AllegraEra
-> Value AllegraEra
getConsumedValue PParams AllegraEra
pp Credential 'Staking -> Maybe Coin
lookupKeyDeposit Credential 'DRepRole -> Maybe Coin
_ = forall era.
EraTxBody era =>
PParams era
-> (Credential 'Staking -> Maybe Coin)
-> UTxO era
-> TxBody era
-> Coin
getConsumedCoin PParams AllegraEra
pp Credential 'Staking -> Maybe Coin
lookupKeyDeposit

  getProducedValue :: PParams AllegraEra
-> (KeyHash 'StakePool -> Bool)
-> TxBody AllegraEra
-> Value AllegraEra
getProducedValue = forall era.
EraTxBody era =>
PParams era
-> (KeyHash 'StakePool -> Bool) -> TxBody era -> Value era
shelleyProducedValue

  getScriptsProvided :: UTxO AllegraEra -> Tx AllegraEra -> ScriptsProvided AllegraEra
getScriptsProvided UTxO AllegraEra
_ Tx AllegraEra
tx = forall era. Map ScriptHash (Script era) -> ScriptsProvided era
ScriptsProvided (Tx AllegraEra
tx forall s a. s -> Getting a s a -> a
^. forall era. EraTx era => Lens' (Tx era) (TxWits era)
witsTxL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era.
EraTxWits era =>
Lens' (TxWits era) (Map ScriptHash (Script era))
scriptTxWitsL)

  getScriptsNeeded :: UTxO AllegraEra -> TxBody AllegraEra -> ScriptsNeeded AllegraEra
getScriptsNeeded = forall era.
EraTxBody era =>
UTxO era -> TxBody era -> ShelleyScriptsNeeded era
getShelleyScriptsNeeded

  getScriptsHashesNeeded :: ScriptsNeeded AllegraEra -> Set ScriptHash
getScriptsHashesNeeded (ShelleyScriptsNeeded Set ScriptHash
scriptHashes) = Set ScriptHash
scriptHashes

  getWitsVKeyNeeded :: CertState AllegraEra
-> UTxO AllegraEra -> TxBody AllegraEra -> Set (KeyHash 'Witness)
getWitsVKeyNeeded = forall era.
(EraTx era, ShelleyEraTxBody era) =>
CertState era -> UTxO era -> TxBody era -> Set (KeyHash 'Witness)
getShelleyWitsVKeyNeeded

  getMinFeeTxUtxo :: PParams AllegraEra -> Tx AllegraEra -> UTxO AllegraEra -> Coin
getMinFeeTxUtxo PParams AllegraEra
pp Tx AllegraEra
tx UTxO AllegraEra
_ = forall era. EraTx era => PParams era -> Tx era -> Coin
getShelleyMinFeeTxUtxo PParams AllegraEra
pp Tx AllegraEra
tx