{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Shelley.TxBody (
  TxBody (
    ShelleyTxBody,
    MkShelleyTxBody,
    stbInputs,
    stbOutputs,
    stbCerts,
    stbWithdrawals,
    stbTxFee,
    stbTTL,
    stbUpdate,
    stbMDHash
  ),
  ShelleyEraTxBody (..),
  ShelleyTxBodyRaw (..),
  EraIndependentTxBody,
  RewardAccount (..),
  Withdrawals (..),
  getShelleyGenesisKeyHashCountTxBody,
) where

import Cardano.Ledger.Address (RewardAccount (..), Withdrawals (..))
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
import Cardano.Ledger.Binary (
  DecCBOR (decCBOR),
  EncCBOR (..),
  ToCBOR (..),
 )
import Cardano.Ledger.Binary.Coders (
  Decode (..),
  Density (..),
  Encode (..),
  Field,
  Wrapped (..),
  decode,
  encode,
  encodeKeyedStrictMaybe,
  field,
  invalidField,
  ofield,
  (!>),
 )
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Core
import Cardano.Ledger.MemoBytes (
  EqRaw (..),
  MemoBytes,
  MemoHashIndex,
  Memoized (..),
  getMemoRawType,
  getMemoSafeHash,
  lensMemoRawType,
  mkMemoizedEra,
 )
import Cardano.Ledger.Shelley.Era (ShelleyEra)
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates (..), Update (..))
import Cardano.Ledger.Shelley.TxCert (ShelleyEraTxCert (..))
import Cardano.Ledger.Shelley.TxOut ()
import Cardano.Ledger.Slot (SlotNo (..))
import Cardano.Ledger.TxIn (TxIn)
import Control.DeepSeq (NFData)
import qualified Data.Map.Strict as Map
import Data.Sequence.Strict (StrictSeq)
import qualified Data.Sequence.Strict as StrictSeq
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks (..))

class (ShelleyEraTxCert era, EraTxBody era, ProtVerAtMost era 8) => ShelleyEraTxBody era where
  ttlTxBodyL :: ExactEra ShelleyEra era => Lens' (TxBody era) SlotNo

  updateTxBodyL :: Lens' (TxBody era) (StrictMaybe (Update era))

-- ==============================
-- The underlying type for TxBody

data ShelleyTxBodyRaw = ShelleyTxBodyRaw
  { ShelleyTxBodyRaw -> Set TxIn
stbrInputs :: !(Set TxIn)
  , ShelleyTxBodyRaw -> StrictSeq (TxOut ShelleyEra)
stbrOutputs :: !(StrictSeq (TxOut ShelleyEra))
  , ShelleyTxBodyRaw -> StrictSeq (TxCert ShelleyEra)
stbrCerts :: !(StrictSeq (TxCert ShelleyEra))
  , ShelleyTxBodyRaw -> Withdrawals
stbrWithdrawals :: !Withdrawals
  , ShelleyTxBodyRaw -> Coin
stbrFee :: !Coin
  , ShelleyTxBodyRaw -> SlotNo
stbrTtl :: !SlotNo
  , ShelleyTxBodyRaw -> StrictMaybe (Update ShelleyEra)
stbrUpdate :: !(StrictMaybe (Update ShelleyEra))
  , ShelleyTxBodyRaw -> StrictMaybe TxAuxDataHash
stbrAuxDataHash :: !(StrictMaybe TxAuxDataHash)
  }
  deriving ((forall x. ShelleyTxBodyRaw -> Rep ShelleyTxBodyRaw x)
-> (forall x. Rep ShelleyTxBodyRaw x -> ShelleyTxBodyRaw)
-> Generic ShelleyTxBodyRaw
forall x. Rep ShelleyTxBodyRaw x -> ShelleyTxBodyRaw
forall x. ShelleyTxBodyRaw -> Rep ShelleyTxBodyRaw x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ShelleyTxBodyRaw -> Rep ShelleyTxBodyRaw x
from :: forall x. ShelleyTxBodyRaw -> Rep ShelleyTxBodyRaw x
$cto :: forall x. Rep ShelleyTxBodyRaw x -> ShelleyTxBodyRaw
to :: forall x. Rep ShelleyTxBodyRaw x -> ShelleyTxBodyRaw
Generic)

deriving instance NoThunks ShelleyTxBodyRaw

deriving instance NFData ShelleyTxBodyRaw

deriving instance Eq ShelleyTxBodyRaw

deriving instance Show ShelleyTxBodyRaw

-- | Encodes memoized bytes created upon construction.
instance EncCBOR (TxBody ShelleyEra)

instance DecCBOR ShelleyTxBodyRaw where
  decCBOR :: forall s. Decoder s ShelleyTxBodyRaw
decCBOR =
    Decode ('Closed 'Dense) ShelleyTxBodyRaw
-> Decoder s ShelleyTxBodyRaw
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode
      ( String
-> ShelleyTxBodyRaw
-> (Word -> Field ShelleyTxBodyRaw)
-> [(Word, String)]
-> Decode ('Closed 'Dense) ShelleyTxBodyRaw
forall t.
Typeable t =>
String
-> t
-> (Word -> Field t)
-> [(Word, String)]
-> Decode ('Closed 'Dense) t
SparseKeyed
          String
"TxBody"
          ShelleyTxBodyRaw
basicShelleyTxBodyRaw
          Word -> Field ShelleyTxBodyRaw
boxBody
          [(Word
0, String
"inputs"), (Word
1, String
"outputs"), (Word
2, String
"fee"), (Word
3, String
"ttl")]
      )

-- =================================================================
-- Composable components for building TxBody optional sparse serialisers.
-- The order of serializing optional fields, and their key values is
-- demanded by backward compatibility concerns.

-- | Choose a de-serialiser when given the key (of type Word).
--   Wrap it in a Field which pairs it with its update function which
--   changes only the field being deserialised.
boxBody :: Word -> Field ShelleyTxBodyRaw
boxBody :: Word -> Field ShelleyTxBodyRaw
boxBody Word
0 = (Set TxIn -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) (Set TxIn) -> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (\Set TxIn
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrInputs = x}) Decode ('Closed Any) (Set TxIn)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
1 = (StrictSeq (ShelleyTxOut ShelleyEra)
 -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) (StrictSeq (ShelleyTxOut ShelleyEra))
-> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (\StrictSeq (ShelleyTxOut ShelleyEra)
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrOutputs = x}) Decode ('Closed Any) (StrictSeq (ShelleyTxOut ShelleyEra))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
4 = (StrictSeq (ShelleyTxCert ShelleyEra)
 -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) (StrictSeq (ShelleyTxCert ShelleyEra))
-> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (\StrictSeq (ShelleyTxCert ShelleyEra)
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrCerts = x}) Decode ('Closed Any) (StrictSeq (ShelleyTxCert ShelleyEra))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
5 = (Withdrawals -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) Withdrawals -> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (\Withdrawals
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrWithdrawals = x}) Decode ('Closed Any) Withdrawals
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
2 = (Coin -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) Coin -> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (\Coin
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrFee = x}) Decode ('Closed Any) Coin
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
3 = (SlotNo -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) SlotNo -> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (\SlotNo
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrTtl = x}) Decode ('Closed Any) SlotNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
6 = (StrictMaybe (Update ShelleyEra)
 -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) (Update ShelleyEra)
-> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(StrictMaybe x -> t -> t) -> Decode ('Closed d) x -> Field t
ofield (\StrictMaybe (Update ShelleyEra)
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrUpdate = x}) Decode ('Closed Any) (Update ShelleyEra)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
7 = (StrictMaybe TxAuxDataHash -> ShelleyTxBodyRaw -> ShelleyTxBodyRaw)
-> Decode ('Closed Any) TxAuxDataHash -> Field ShelleyTxBodyRaw
forall x t (d :: Density).
Typeable x =>
(StrictMaybe x -> t -> t) -> Decode ('Closed d) x -> Field t
ofield (\StrictMaybe TxAuxDataHash
x ShelleyTxBodyRaw
tx -> ShelleyTxBodyRaw
tx {stbrAuxDataHash = x}) Decode ('Closed Any) TxAuxDataHash
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
boxBody Word
n = Word -> Field ShelleyTxBodyRaw
forall t. Word -> Field t
invalidField Word
n

-- | Tells how to serialise each field, and what tag to label it with in the
--   serialisation. boxBody and txSparse should be Duals, visually inspect
--   The key order looks strange but was choosen for backward compatibility.
txSparse :: ShelleyTxBodyRaw -> Encode ('Closed 'Sparse) ShelleyTxBodyRaw
txSparse :: ShelleyTxBodyRaw -> Encode ('Closed 'Sparse) ShelleyTxBodyRaw
txSparse (ShelleyTxBodyRaw Set TxIn
input StrictSeq (TxOut ShelleyEra)
output StrictSeq (TxCert ShelleyEra)
cert Withdrawals
wdrl Coin
fee SlotNo
ttl StrictMaybe (Update ShelleyEra)
update StrictMaybe TxAuxDataHash
hash) =
  (Set TxIn
 -> StrictSeq (ShelleyTxOut ShelleyEra)
 -> Coin
 -> SlotNo
 -> StrictSeq (ShelleyTxCert ShelleyEra)
 -> Withdrawals
 -> StrictMaybe (Update ShelleyEra)
 -> StrictMaybe TxAuxDataHash
 -> ShelleyTxBodyRaw)
-> Encode
     ('Closed 'Sparse)
     (Set TxIn
      -> StrictSeq (ShelleyTxOut ShelleyEra)
      -> Coin
      -> SlotNo
      -> StrictSeq (ShelleyTxCert ShelleyEra)
      -> Withdrawals
      -> StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash
      -> ShelleyTxBodyRaw)
forall t. t -> Encode ('Closed 'Sparse) t
Keyed (\Set TxIn
i StrictSeq (ShelleyTxOut ShelleyEra)
o Coin
f SlotNo
t StrictSeq (ShelleyTxCert ShelleyEra)
c Withdrawals
w StrictMaybe (Update ShelleyEra)
u StrictMaybe TxAuxDataHash
h -> Set TxIn
-> StrictSeq (TxOut ShelleyEra)
-> StrictSeq (TxCert ShelleyEra)
-> Withdrawals
-> Coin
-> SlotNo
-> StrictMaybe (Update ShelleyEra)
-> StrictMaybe TxAuxDataHash
-> ShelleyTxBodyRaw
ShelleyTxBodyRaw Set TxIn
i StrictSeq (TxOut ShelleyEra)
StrictSeq (ShelleyTxOut ShelleyEra)
o StrictSeq (TxCert ShelleyEra)
StrictSeq (ShelleyTxCert ShelleyEra)
c Withdrawals
w Coin
f SlotNo
t StrictMaybe (Update ShelleyEra)
u StrictMaybe TxAuxDataHash
h)
    Encode
  ('Closed 'Sparse)
  (Set TxIn
   -> StrictSeq (ShelleyTxOut ShelleyEra)
   -> Coin
   -> SlotNo
   -> StrictSeq (ShelleyTxCert ShelleyEra)
   -> Withdrawals
   -> StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash
   -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) (Set TxIn)
-> Encode
     ('Closed 'Sparse)
     (StrictSeq (ShelleyTxOut ShelleyEra)
      -> Coin
      -> SlotNo
      -> StrictSeq (ShelleyTxCert ShelleyEra)
      -> Withdrawals
      -> StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash
      -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Word
-> Encode ('Closed 'Dense) (Set TxIn)
-> Encode ('Closed 'Sparse) (Set TxIn)
forall t.
Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t
Key Word
0 (Set TxIn -> Encode ('Closed 'Dense) (Set TxIn)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Set TxIn
input) -- We don't have to send these in ShelleyTxBodyRaw order
    Encode
  ('Closed 'Sparse)
  (StrictSeq (ShelleyTxOut ShelleyEra)
   -> Coin
   -> SlotNo
   -> StrictSeq (ShelleyTxCert ShelleyEra)
   -> Withdrawals
   -> StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash
   -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) (StrictSeq (ShelleyTxOut ShelleyEra))
-> Encode
     ('Closed 'Sparse)
     (Coin
      -> SlotNo
      -> StrictSeq (ShelleyTxCert ShelleyEra)
      -> Withdrawals
      -> StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash
      -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Word
-> Encode ('Closed 'Dense) (StrictSeq (ShelleyTxOut ShelleyEra))
-> Encode ('Closed 'Sparse) (StrictSeq (ShelleyTxOut ShelleyEra))
forall t.
Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t
Key Word
1 (StrictSeq (ShelleyTxOut ShelleyEra)
-> Encode ('Closed 'Dense) (StrictSeq (ShelleyTxOut ShelleyEra))
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To StrictSeq (TxOut ShelleyEra)
StrictSeq (ShelleyTxOut ShelleyEra)
output) -- Just hack up a fake constructor with the lambda.
    Encode
  ('Closed 'Sparse)
  (Coin
   -> SlotNo
   -> StrictSeq (ShelleyTxCert ShelleyEra)
   -> Withdrawals
   -> StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash
   -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) Coin
-> Encode
     ('Closed 'Sparse)
     (SlotNo
      -> StrictSeq (ShelleyTxCert ShelleyEra)
      -> Withdrawals
      -> StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash
      -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Word
-> Encode ('Closed 'Dense) Coin -> Encode ('Closed 'Sparse) Coin
forall t.
Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t
Key Word
2 (Coin -> Encode ('Closed 'Dense) Coin
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Coin
fee)
    Encode
  ('Closed 'Sparse)
  (SlotNo
   -> StrictSeq (ShelleyTxCert ShelleyEra)
   -> Withdrawals
   -> StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash
   -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) SlotNo
-> Encode
     ('Closed 'Sparse)
     (StrictSeq (ShelleyTxCert ShelleyEra)
      -> Withdrawals
      -> StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash
      -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Word
-> Encode ('Closed 'Dense) SlotNo
-> Encode ('Closed 'Sparse) SlotNo
forall t.
Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t
Key Word
3 (SlotNo -> Encode ('Closed 'Dense) SlotNo
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To SlotNo
ttl)
    Encode
  ('Closed 'Sparse)
  (StrictSeq (ShelleyTxCert ShelleyEra)
   -> Withdrawals
   -> StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash
   -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) (StrictSeq (ShelleyTxCert ShelleyEra))
-> Encode
     ('Closed 'Sparse)
     (Withdrawals
      -> StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash
      -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> (StrictSeq (ShelleyTxCert ShelleyEra) -> Bool)
-> Encode ('Closed 'Sparse) (StrictSeq (ShelleyTxCert ShelleyEra))
-> Encode ('Closed 'Sparse) (StrictSeq (ShelleyTxCert ShelleyEra))
forall t.
(t -> Bool)
-> Encode ('Closed 'Sparse) t -> Encode ('Closed 'Sparse) t
Omit StrictSeq (ShelleyTxCert ShelleyEra) -> Bool
forall a. StrictSeq a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Word
-> Encode ('Closed 'Dense) (StrictSeq (ShelleyTxCert ShelleyEra))
-> Encode ('Closed 'Sparse) (StrictSeq (ShelleyTxCert ShelleyEra))
forall t.
Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t
Key Word
4 (StrictSeq (ShelleyTxCert ShelleyEra)
-> Encode ('Closed 'Dense) (StrictSeq (ShelleyTxCert ShelleyEra))
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To StrictSeq (TxCert ShelleyEra)
StrictSeq (ShelleyTxCert ShelleyEra)
cert))
    Encode
  ('Closed 'Sparse)
  (Withdrawals
   -> StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash
   -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) Withdrawals
-> Encode
     ('Closed 'Sparse)
     (StrictMaybe (Update ShelleyEra)
      -> StrictMaybe TxAuxDataHash -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> (Withdrawals -> Bool)
-> Encode ('Closed 'Sparse) Withdrawals
-> Encode ('Closed 'Sparse) Withdrawals
forall t.
(t -> Bool)
-> Encode ('Closed 'Sparse) t -> Encode ('Closed 'Sparse) t
Omit (Map RewardAccount Coin -> Bool
forall a. Map RewardAccount a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Map RewardAccount Coin -> Bool)
-> (Withdrawals -> Map RewardAccount Coin) -> Withdrawals -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Withdrawals -> Map RewardAccount Coin
unWithdrawals) (Word
-> Encode ('Closed 'Dense) Withdrawals
-> Encode ('Closed 'Sparse) Withdrawals
forall t.
Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t
Key Word
5 (Withdrawals -> Encode ('Closed 'Dense) Withdrawals
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Withdrawals
wdrl))
    Encode
  ('Closed 'Sparse)
  (StrictMaybe (Update ShelleyEra)
   -> StrictMaybe TxAuxDataHash -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) (StrictMaybe (Update ShelleyEra))
-> Encode
     ('Closed 'Sparse) (StrictMaybe TxAuxDataHash -> ShelleyTxBodyRaw)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Word
-> StrictMaybe (Update ShelleyEra)
-> Encode ('Closed 'Sparse) (StrictMaybe (Update ShelleyEra))
forall a.
EncCBOR a =>
Word -> StrictMaybe a -> Encode ('Closed 'Sparse) (StrictMaybe a)
encodeKeyedStrictMaybe Word
6 StrictMaybe (Update ShelleyEra)
update
    Encode
  ('Closed 'Sparse) (StrictMaybe TxAuxDataHash -> ShelleyTxBodyRaw)
-> Encode ('Closed 'Sparse) (StrictMaybe TxAuxDataHash)
-> Encode ('Closed 'Sparse) ShelleyTxBodyRaw
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Word
-> StrictMaybe TxAuxDataHash
-> Encode ('Closed 'Sparse) (StrictMaybe TxAuxDataHash)
forall a.
EncCBOR a =>
Word -> StrictMaybe a -> Encode ('Closed 'Sparse) (StrictMaybe a)
encodeKeyedStrictMaybe Word
7 StrictMaybe TxAuxDataHash
hash

-- The initial TxBody. We will overide some of these fields as we build a TxBody,
-- adding one field at a time, using optional serialisers, inside the Pattern.
basicShelleyTxBodyRaw :: ShelleyTxBodyRaw
basicShelleyTxBodyRaw :: ShelleyTxBodyRaw
basicShelleyTxBodyRaw =
  ShelleyTxBodyRaw
    { stbrInputs :: Set TxIn
stbrInputs = Set TxIn
forall a. Set a
Set.empty
    , stbrOutputs :: StrictSeq (TxOut ShelleyEra)
stbrOutputs = StrictSeq (TxOut ShelleyEra)
StrictSeq (ShelleyTxOut ShelleyEra)
forall a. StrictSeq a
StrictSeq.empty
    , stbrFee :: Coin
stbrFee = Integer -> Coin
Coin Integer
0
    , stbrTtl :: SlotNo
stbrTtl = Word64 -> SlotNo
SlotNo Word64
forall a. Bounded a => a
maxBound -- transaction is eternally valid by default
    , stbrCerts :: StrictSeq (TxCert ShelleyEra)
stbrCerts = StrictSeq (TxCert ShelleyEra)
StrictSeq (ShelleyTxCert ShelleyEra)
forall a. StrictSeq a
StrictSeq.empty
    , stbrWithdrawals :: Withdrawals
stbrWithdrawals = Map RewardAccount Coin -> Withdrawals
Withdrawals Map RewardAccount Coin
forall k a. Map k a
Map.empty
    , stbrUpdate :: StrictMaybe (Update ShelleyEra)
stbrUpdate = StrictMaybe (Update ShelleyEra)
forall a. StrictMaybe a
SNothing
    , stbrAuxDataHash :: StrictMaybe TxAuxDataHash
stbrAuxDataHash = StrictMaybe TxAuxDataHash
forall a. StrictMaybe a
SNothing
    }

instance EncCBOR ShelleyTxBodyRaw where
  encCBOR :: ShelleyTxBodyRaw -> Encoding
encCBOR = Encode ('Closed 'Sparse) ShelleyTxBodyRaw -> Encoding
forall (w :: Wrapped) t. Encode w t -> Encoding
encode (Encode ('Closed 'Sparse) ShelleyTxBodyRaw -> Encoding)
-> (ShelleyTxBodyRaw -> Encode ('Closed 'Sparse) ShelleyTxBodyRaw)
-> ShelleyTxBodyRaw
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyTxBodyRaw -> Encode ('Closed 'Sparse) ShelleyTxBodyRaw
txSparse

instance Memoized (TxBody ShelleyEra) where
  type RawType (TxBody ShelleyEra) = ShelleyTxBodyRaw

instance EqRaw (TxBody ShelleyEra)

instance EraTxBody ShelleyEra where
  newtype TxBody ShelleyEra = MkShelleyTxBody (MemoBytes ShelleyTxBodyRaw)
    deriving ((forall x. TxBody ShelleyEra -> Rep (TxBody ShelleyEra) x)
-> (forall x. Rep (TxBody ShelleyEra) x -> TxBody ShelleyEra)
-> Generic (TxBody ShelleyEra)
forall x. Rep (TxBody ShelleyEra) x -> TxBody ShelleyEra
forall x. TxBody ShelleyEra -> Rep (TxBody ShelleyEra) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TxBody ShelleyEra -> Rep (TxBody ShelleyEra) x
from :: forall x. TxBody ShelleyEra -> Rep (TxBody ShelleyEra) x
$cto :: forall x. Rep (TxBody ShelleyEra) x -> TxBody ShelleyEra
to :: forall x. Rep (TxBody ShelleyEra) x -> TxBody ShelleyEra
Generic)
    deriving newtype (TxBody ShelleyEra -> Int
TxBody ShelleyEra -> ByteString
(TxBody ShelleyEra -> ByteString)
-> (TxBody ShelleyEra -> Int)
-> (forall i. Proxy i -> TxBody ShelleyEra -> SafeHash i)
-> SafeToHash (TxBody ShelleyEra)
forall i. Proxy i -> TxBody ShelleyEra -> SafeHash i
forall t.
(t -> ByteString)
-> (t -> Int)
-> (forall i. Proxy i -> t -> SafeHash i)
-> SafeToHash t
$coriginalBytes :: TxBody ShelleyEra -> ByteString
originalBytes :: TxBody ShelleyEra -> ByteString
$coriginalBytesSize :: TxBody ShelleyEra -> Int
originalBytesSize :: TxBody ShelleyEra -> Int
$cmakeHashWithExplicitProxys :: forall i. Proxy i -> TxBody ShelleyEra -> SafeHash i
makeHashWithExplicitProxys :: forall i. Proxy i -> TxBody ShelleyEra -> SafeHash i
SafeToHash, Typeable (TxBody ShelleyEra)
Typeable (TxBody ShelleyEra) =>
(TxBody ShelleyEra -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (TxBody ShelleyEra) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [TxBody ShelleyEra] -> Size)
-> ToCBOR (TxBody ShelleyEra)
TxBody ShelleyEra -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [TxBody ShelleyEra] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (TxBody ShelleyEra) -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
$ctoCBOR :: TxBody ShelleyEra -> Encoding
toCBOR :: TxBody ShelleyEra -> Encoding
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (TxBody ShelleyEra) -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (TxBody ShelleyEra) -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [TxBody ShelleyEra] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [TxBody ShelleyEra] -> Size
ToCBOR)

  mkBasicTxBody :: TxBody ShelleyEra
mkBasicTxBody = forall era t.
(Era era, EncCBOR (RawType t), Memoized t) =>
RawType t -> t
mkMemoizedEra @ShelleyEra RawType (TxBody ShelleyEra)
ShelleyTxBodyRaw
basicShelleyTxBodyRaw

  spendableInputsTxBodyF :: SimpleGetter (TxBody ShelleyEra) (Set TxIn)
spendableInputsTxBodyF = (Set TxIn -> Const r (Set TxIn))
-> TxBody ShelleyEra -> Const r (TxBody ShelleyEra)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody ShelleyEra) (Set TxIn)
inputsTxBodyL
  {-# INLINE spendableInputsTxBodyF #-}

  allInputsTxBodyF :: SimpleGetter (TxBody ShelleyEra) (Set TxIn)
allInputsTxBodyF = (Set TxIn -> Const r (Set TxIn))
-> TxBody ShelleyEra -> Const r (TxBody ShelleyEra)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody ShelleyEra) (Set TxIn)
inputsTxBodyL
  {-# INLINE allInputsTxBodyF #-}

  inputsTxBodyL :: Lens' (TxBody ShelleyEra) (Set TxIn)
inputsTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> Set TxIn
ShelleyTxBodyRaw -> Set TxIn
stbrInputs ((RawType (TxBody ShelleyEra)
  -> Set TxIn -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) (Set TxIn))
-> (RawType (TxBody ShelleyEra)
    -> Set TxIn -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) (Set TxIn)
forall a b. (a -> b) -> a -> b
$
      \RawType (TxBody ShelleyEra)
txBodyRaw Set TxIn
inputs -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrInputs = inputs}
  {-# INLINEABLE inputsTxBodyL #-}

  outputsTxBodyL :: Lens' (TxBody ShelleyEra) (StrictSeq (TxOut ShelleyEra))
outputsTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> StrictSeq (TxOut ShelleyEra)
ShelleyTxBodyRaw -> StrictSeq (TxOut ShelleyEra)
stbrOutputs ((RawType (TxBody ShelleyEra)
  -> StrictSeq (TxOut ShelleyEra) -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) (StrictSeq (TxOut ShelleyEra)))
-> (RawType (TxBody ShelleyEra)
    -> StrictSeq (TxOut ShelleyEra) -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) (StrictSeq (TxOut ShelleyEra))
forall a b. (a -> b) -> a -> b
$
      \RawType (TxBody ShelleyEra)
txBodyRaw StrictSeq (TxOut ShelleyEra)
outputs -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrOutputs = outputs}
  {-# INLINEABLE outputsTxBodyL #-}

  feeTxBodyL :: Lens' (TxBody ShelleyEra) Coin
feeTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> Coin
ShelleyTxBodyRaw -> Coin
stbrFee ((RawType (TxBody ShelleyEra)
  -> Coin -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) Coin)
-> (RawType (TxBody ShelleyEra)
    -> Coin -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) Coin
forall a b. (a -> b) -> a -> b
$
      \RawType (TxBody ShelleyEra)
txBodyRaw Coin
fee -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrFee = fee}
  {-# INLINEABLE feeTxBodyL #-}

  auxDataHashTxBodyL :: Lens' (TxBody ShelleyEra) (StrictMaybe TxAuxDataHash)
auxDataHashTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> StrictMaybe TxAuxDataHash
ShelleyTxBodyRaw -> StrictMaybe TxAuxDataHash
stbrAuxDataHash ((RawType (TxBody ShelleyEra)
  -> StrictMaybe TxAuxDataHash -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) (StrictMaybe TxAuxDataHash))
-> (RawType (TxBody ShelleyEra)
    -> StrictMaybe TxAuxDataHash -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) (StrictMaybe TxAuxDataHash)
forall a b. (a -> b) -> a -> b
$
      \RawType (TxBody ShelleyEra)
txBodyRaw StrictMaybe TxAuxDataHash
auxDataHash -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrAuxDataHash = auxDataHash}
  {-# INLINEABLE auxDataHashTxBodyL #-}

  withdrawalsTxBodyL :: Lens' (TxBody ShelleyEra) Withdrawals
withdrawalsTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> Withdrawals
ShelleyTxBodyRaw -> Withdrawals
stbrWithdrawals ((RawType (TxBody ShelleyEra)
  -> Withdrawals -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) Withdrawals)
-> (RawType (TxBody ShelleyEra)
    -> Withdrawals -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) Withdrawals
forall a b. (a -> b) -> a -> b
$
      \RawType (TxBody ShelleyEra)
txBodyRaw Withdrawals
withdrawals -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrWithdrawals = withdrawals}
  {-# INLINEABLE withdrawalsTxBodyL #-}

  certsTxBodyL :: Lens' (TxBody ShelleyEra) (StrictSeq (TxCert ShelleyEra))
certsTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> StrictSeq (TxCert ShelleyEra)
ShelleyTxBodyRaw -> StrictSeq (TxCert ShelleyEra)
stbrCerts ((RawType (TxBody ShelleyEra)
  -> StrictSeq (TxCert ShelleyEra) -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) (StrictSeq (TxCert ShelleyEra)))
-> (RawType (TxBody ShelleyEra)
    -> StrictSeq (TxCert ShelleyEra) -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) (StrictSeq (TxCert ShelleyEra))
forall a b. (a -> b) -> a -> b
$
      \RawType (TxBody ShelleyEra)
txBodyRaw StrictSeq (TxCert ShelleyEra)
certs -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrCerts = certs}
  {-# INLINEABLE certsTxBodyL #-}

  getGenesisKeyHashCountTxBody :: TxBody ShelleyEra -> Int
getGenesisKeyHashCountTxBody = TxBody ShelleyEra -> Int
forall era. ShelleyEraTxBody era => TxBody era -> Int
getShelleyGenesisKeyHashCountTxBody

  upgradeTxBody :: EraTxBody (PreviousEra ShelleyEra) =>
TxBody (PreviousEra ShelleyEra)
-> Either (TxBodyUpgradeError ShelleyEra) (TxBody ShelleyEra)
upgradeTxBody =
    String
-> TxBody (PreviousEra ShelleyEra)
-> Either (TxBodyUpgradeError ShelleyEra) (TxBody ShelleyEra)
forall a. HasCallStack => String -> a
error (String
 -> TxBody (PreviousEra ShelleyEra)
 -> Either (TxBodyUpgradeError ShelleyEra) (TxBody ShelleyEra))
-> String
-> TxBody (PreviousEra ShelleyEra)
-> Either (TxBodyUpgradeError ShelleyEra) (TxBody ShelleyEra)
forall a b. (a -> b) -> a -> b
$
      String
"Calling this function will cause a compilation error, "
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"since there is no `EraTxBody` instance for `ByronEra`"

instance ShelleyEraTxBody ShelleyEra where
  ttlTxBodyL :: ExactEra ShelleyEra ShelleyEra => Lens' (TxBody ShelleyEra) SlotNo
ttlTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> SlotNo
ShelleyTxBodyRaw -> SlotNo
stbrTtl ((RawType (TxBody ShelleyEra)
  -> SlotNo -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) SlotNo)
-> (RawType (TxBody ShelleyEra)
    -> SlotNo -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) SlotNo
forall a b. (a -> b) -> a -> b
$ \RawType (TxBody ShelleyEra)
txBodyRaw SlotNo
ttl -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrTtl = ttl}
  {-# INLINEABLE ttlTxBodyL #-}

  updateTxBodyL :: Lens' (TxBody ShelleyEra) (StrictMaybe (Update ShelleyEra))
updateTxBodyL =
    forall era t a b.
(Era era, EncCBOR (RawType t), Memoized t) =>
(RawType t -> a) -> (RawType t -> b -> RawType t) -> Lens t t a b
lensMemoRawType @ShelleyEra RawType (TxBody ShelleyEra) -> StrictMaybe (Update ShelleyEra)
ShelleyTxBodyRaw -> StrictMaybe (Update ShelleyEra)
stbrUpdate ((RawType (TxBody ShelleyEra)
  -> StrictMaybe (Update ShelleyEra) -> RawType (TxBody ShelleyEra))
 -> Lens' (TxBody ShelleyEra) (StrictMaybe (Update ShelleyEra)))
-> (RawType (TxBody ShelleyEra)
    -> StrictMaybe (Update ShelleyEra) -> RawType (TxBody ShelleyEra))
-> Lens' (TxBody ShelleyEra) (StrictMaybe (Update ShelleyEra))
forall a b. (a -> b) -> a -> b
$ \RawType (TxBody ShelleyEra)
txBodyRaw StrictMaybe (Update ShelleyEra)
update -> RawType (TxBody ShelleyEra)
txBodyRaw {stbrUpdate = update}
  {-# INLINEABLE updateTxBodyL #-}

deriving newtype instance NoThunks (TxBody ShelleyEra)

deriving newtype instance NFData (TxBody ShelleyEra)

deriving instance Show (TxBody ShelleyEra)

deriving instance Eq (TxBody ShelleyEra)

deriving newtype instance DecCBOR (TxBody ShelleyEra)

-- | Pattern for use by external users
pattern ShelleyTxBody ::
  Set TxIn ->
  StrictSeq (TxOut ShelleyEra) ->
  StrictSeq (TxCert ShelleyEra) ->
  Withdrawals ->
  Coin ->
  SlotNo ->
  StrictMaybe (Update ShelleyEra) ->
  StrictMaybe TxAuxDataHash ->
  TxBody ShelleyEra
pattern $mShelleyTxBody :: forall {r}.
TxBody ShelleyEra
-> (Set TxIn
    -> StrictSeq (TxOut ShelleyEra)
    -> StrictSeq (TxCert ShelleyEra)
    -> Withdrawals
    -> Coin
    -> SlotNo
    -> StrictMaybe (Update ShelleyEra)
    -> StrictMaybe TxAuxDataHash
    -> r)
-> ((# #) -> r)
-> r
$bShelleyTxBody :: Set TxIn
-> StrictSeq (TxOut ShelleyEra)
-> StrictSeq (TxCert ShelleyEra)
-> Withdrawals
-> Coin
-> SlotNo
-> StrictMaybe (Update ShelleyEra)
-> StrictMaybe TxAuxDataHash
-> TxBody ShelleyEra
ShelleyTxBody
  { TxBody ShelleyEra -> Set TxIn
stbInputs
  , TxBody ShelleyEra -> StrictSeq (TxOut ShelleyEra)
stbOutputs
  , TxBody ShelleyEra -> StrictSeq (TxCert ShelleyEra)
stbCerts
  , TxBody ShelleyEra -> Withdrawals
stbWithdrawals
  , TxBody ShelleyEra -> Coin
stbTxFee
  , TxBody ShelleyEra -> SlotNo
stbTTL
  , TxBody ShelleyEra -> StrictMaybe (Update ShelleyEra)
stbUpdate
  , TxBody ShelleyEra -> StrictMaybe TxAuxDataHash
stbMDHash
  } <-
  ( getMemoRawType ->
      ShelleyTxBodyRaw
        { stbrInputs = stbInputs
        , stbrOutputs = stbOutputs
        , stbrCerts = stbCerts
        , stbrWithdrawals = stbWithdrawals
        , stbrFee = stbTxFee
        , stbrTtl = stbTTL
        , stbrUpdate = stbUpdate
        , stbrAuxDataHash = stbMDHash
        }
    )
  where
    ShelleyTxBody
      Set TxIn
inputs
      StrictSeq (TxOut ShelleyEra)
outputs
      StrictSeq (TxCert ShelleyEra)
certs
      Withdrawals
withdrawals
      Coin
fee
      SlotNo
ttl
      StrictMaybe (Update ShelleyEra)
update
      StrictMaybe TxAuxDataHash
auxDataHash =
        forall era t.
(Era era, EncCBOR (RawType t), Memoized t) =>
RawType t -> t
mkMemoizedEra @ShelleyEra (RawType (TxBody ShelleyEra) -> TxBody ShelleyEra)
-> RawType (TxBody ShelleyEra) -> TxBody ShelleyEra
forall a b. (a -> b) -> a -> b
$
          ShelleyTxBodyRaw
            { stbrInputs :: Set TxIn
stbrInputs = Set TxIn
inputs
            , stbrOutputs :: StrictSeq (TxOut ShelleyEra)
stbrOutputs = StrictSeq (TxOut ShelleyEra)
outputs
            , stbrCerts :: StrictSeq (TxCert ShelleyEra)
stbrCerts = StrictSeq (TxCert ShelleyEra)
certs
            , stbrWithdrawals :: Withdrawals
stbrWithdrawals = Withdrawals
withdrawals
            , stbrFee :: Coin
stbrFee = Coin
fee
            , stbrTtl :: SlotNo
stbrTtl = SlotNo
ttl
            , stbrUpdate :: StrictMaybe (Update ShelleyEra)
stbrUpdate = StrictMaybe (Update ShelleyEra)
update
            , stbrAuxDataHash :: StrictMaybe TxAuxDataHash
stbrAuxDataHash = StrictMaybe TxAuxDataHash
auxDataHash
            }

{-# COMPLETE ShelleyTxBody #-}

-- =========================================

type instance MemoHashIndex ShelleyTxBodyRaw = EraIndependentTxBody

instance HashAnnotated (TxBody ShelleyEra) EraIndependentTxBody where
  hashAnnotated :: TxBody ShelleyEra -> SafeHash EraIndependentTxBody
hashAnnotated = TxBody ShelleyEra -> SafeHash EraIndependentTxBody
TxBody ShelleyEra
-> SafeHash (MemoHashIndex (RawType (TxBody ShelleyEra)))
forall t. Memoized t => t -> SafeHash (MemoHashIndex (RawType t))
getMemoSafeHash

-- ===============================================================

-- | Count number of Genesis keys supplied in the `updateTxBodyL` field.
getShelleyGenesisKeyHashCountTxBody :: ShelleyEraTxBody era => TxBody era -> Int
getShelleyGenesisKeyHashCountTxBody :: forall era. ShelleyEraTxBody era => TxBody era -> Int
getShelleyGenesisKeyHashCountTxBody TxBody era
txBody =
  case TxBody era
txBody TxBody era
-> Getting
     (StrictMaybe (Update era)) (TxBody era) (StrictMaybe (Update era))
-> StrictMaybe (Update era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (Update era)) (TxBody era) (StrictMaybe (Update era))
forall era.
ShelleyEraTxBody era =>
Lens' (TxBody era) (StrictMaybe (Update era))
Lens' (TxBody era) (StrictMaybe (Update era))
updateTxBodyL of
    SJust (Update (ProposedPPUpdates Map (KeyHash 'Genesis) (PParamsUpdate era)
m) EpochNo
_) -> Map (KeyHash 'Genesis) (PParamsUpdate era) -> Int
forall k a. Map k a -> Int
Map.size Map (KeyHash 'Genesis) (PParamsUpdate era)
m
    StrictMaybe (Update era)
_ -> Int
0