{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}

module Byron.Spec.Ledger.UTxO where

import Byron.Spec.Ledger.Core hiding ((<|))
import Byron.Spec.Ledger.Update (FactorA (..), FactorB (..), PParams (PParams), _factorA, _factorB)
import Data.AbstractSize (HasTypeReps, abstractSize)
import Data.Data (Data, Typeable)
import Data.Hashable (Hashable)
import qualified Data.Hashable as H
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Data.Typeable (typeOf)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks (..))
import Numeric.Natural (Natural)

-- | A unique ID of a transaction, which is computable from the transaction.
newtype TxId = TxId {TxId -> Hash
getTxId :: Hash}
  deriving stock (Int -> TxId -> ShowS
[TxId] -> ShowS
TxId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxId] -> ShowS
$cshowList :: [TxId] -> ShowS
show :: TxId -> String
$cshow :: TxId -> String
showsPrec :: Int -> TxId -> ShowS
$cshowsPrec :: Int -> TxId -> ShowS
Show, forall x. Rep TxId x -> TxId
forall x. TxId -> Rep TxId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TxId x -> TxId
$cfrom :: forall x. TxId -> Rep TxId x
Generic, Typeable TxId
TxId -> DataType
TxId -> Constr
(forall b. Data b => b -> b) -> TxId -> TxId
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TxId -> u
forall u. (forall d. Data d => d -> u) -> TxId -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxId -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxId -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxId
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxId -> c TxId
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxId)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxId)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxId -> m TxId
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxId -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxId -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> TxId -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TxId -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxId -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxId -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxId -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxId -> r
gmapT :: (forall b. Data b => b -> b) -> TxId -> TxId
$cgmapT :: (forall b. Data b => b -> b) -> TxId -> TxId
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxId)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxId)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxId)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxId)
dataTypeOf :: TxId -> DataType
$cdataTypeOf :: TxId -> DataType
toConstr :: TxId -> Constr
$ctoConstr :: TxId -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxId
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxId
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxId -> c TxId
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxId -> c TxId
Data, Typeable)
  deriving newtype (TxId -> TxId -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxId -> TxId -> Bool
$c/= :: TxId -> TxId -> Bool
== :: TxId -> TxId -> Bool
$c== :: TxId -> TxId -> Bool
Eq, Eq TxId
TxId -> TxId -> Bool
TxId -> TxId -> Ordering
TxId -> TxId -> TxId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TxId -> TxId -> TxId
$cmin :: TxId -> TxId -> TxId
max :: TxId -> TxId -> TxId
$cmax :: TxId -> TxId -> TxId
>= :: TxId -> TxId -> Bool
$c>= :: TxId -> TxId -> Bool
> :: TxId -> TxId -> Bool
$c> :: TxId -> TxId -> Bool
<= :: TxId -> TxId -> Bool
$c<= :: TxId -> TxId -> Bool
< :: TxId -> TxId -> Bool
$c< :: TxId -> TxId -> Bool
compare :: TxId -> TxId -> Ordering
$ccompare :: TxId -> TxId -> Ordering
Ord, Eq TxId
Int -> TxId -> Int
TxId -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: TxId -> Int
$chash :: TxId -> Int
hashWithSalt :: Int -> TxId -> Int
$chashWithSalt :: Int -> TxId -> Int
Hashable, Context -> TxId -> IO (Maybe ThunkInfo)
Proxy TxId -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy TxId -> String
$cshowTypeOf :: Proxy TxId -> String
wNoThunks :: Context -> TxId -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> TxId -> IO (Maybe ThunkInfo)
noThunks :: Context -> TxId -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> TxId -> IO (Maybe ThunkInfo)
NoThunks)
  deriving anyclass (TxId -> Seq TypeRep
forall a. (a -> Seq TypeRep) -> HasTypeReps a
typeReps :: TxId -> Seq TypeRep
$ctypeReps :: TxId -> Seq TypeRep
HasTypeReps)

-- | The input of a UTxO.
--
--      * __TODO__ - is it okay to use list indices instead of implementing the Ix Type?
data TxIn = TxIn TxId Natural
  deriving
    ( Int -> TxIn -> ShowS
[TxIn] -> ShowS
TxIn -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxIn] -> ShowS
$cshowList :: [TxIn] -> ShowS
show :: TxIn -> String
$cshow :: TxIn -> String
showsPrec :: Int -> TxIn -> ShowS
$cshowsPrec :: Int -> TxIn -> ShowS
Show
    , TxIn -> TxIn -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxIn -> TxIn -> Bool
$c/= :: TxIn -> TxIn -> Bool
== :: TxIn -> TxIn -> Bool
$c== :: TxIn -> TxIn -> Bool
Eq
    , Eq TxIn
TxIn -> TxIn -> Bool
TxIn -> TxIn -> Ordering
TxIn -> TxIn -> TxIn
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TxIn -> TxIn -> TxIn
$cmin :: TxIn -> TxIn -> TxIn
max :: TxIn -> TxIn -> TxIn
$cmax :: TxIn -> TxIn -> TxIn
>= :: TxIn -> TxIn -> Bool
$c>= :: TxIn -> TxIn -> Bool
> :: TxIn -> TxIn -> Bool
$c> :: TxIn -> TxIn -> Bool
<= :: TxIn -> TxIn -> Bool
$c<= :: TxIn -> TxIn -> Bool
< :: TxIn -> TxIn -> Bool
$c< :: TxIn -> TxIn -> Bool
compare :: TxIn -> TxIn -> Ordering
$ccompare :: TxIn -> TxIn -> Ordering
Ord
    , forall x. Rep TxIn x -> TxIn
forall x. TxIn -> Rep TxIn x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TxIn x -> TxIn
$cfrom :: forall x. TxIn -> Rep TxIn x
Generic
    , Eq TxIn
Int -> TxIn -> Int
TxIn -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: TxIn -> Int
$chash :: TxIn -> Int
hashWithSalt :: Int -> TxIn -> Int
$chashWithSalt :: Int -> TxIn -> Int
Hashable
    , TxIn -> Seq TypeRep
forall a. (a -> Seq TypeRep) -> HasTypeReps a
typeReps :: TxIn -> Seq TypeRep
$ctypeReps :: TxIn -> Seq TypeRep
HasTypeReps
    , Typeable TxIn
TxIn -> DataType
TxIn -> Constr
(forall b. Data b => b -> b) -> TxIn -> TxIn
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TxIn -> u
forall u. (forall d. Data d => d -> u) -> TxIn -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxIn -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxIn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxIn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxIn -> c TxIn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxIn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxIn)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxIn -> m TxIn
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxIn -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxIn -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> TxIn -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TxIn -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxIn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxIn -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxIn -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxIn -> r
gmapT :: (forall b. Data b => b -> b) -> TxIn -> TxIn
$cgmapT :: (forall b. Data b => b -> b) -> TxIn -> TxIn
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxIn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxIn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxIn)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxIn)
dataTypeOf :: TxIn -> DataType
$cdataTypeOf :: TxIn -> DataType
toConstr :: TxIn -> Constr
$ctoConstr :: TxIn -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxIn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxIn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxIn -> c TxIn
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxIn -> c TxIn
Data
    , Typeable
    , Context -> TxIn -> IO (Maybe ThunkInfo)
Proxy TxIn -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy TxIn -> String
$cshowTypeOf :: Proxy TxIn -> String
wNoThunks :: Context -> TxIn -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> TxIn -> IO (Maybe ThunkInfo)
noThunks :: Context -> TxIn -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> TxIn -> IO (Maybe ThunkInfo)
NoThunks
    )

-- | The output of a UTxO.
data TxOut = TxOut
  { TxOut -> Addr
addr :: Addr
  , TxOut -> Lovelace
value :: Lovelace
  }
  deriving
    ( Int -> TxOut -> ShowS
[TxOut] -> ShowS
TxOut -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxOut] -> ShowS
$cshowList :: [TxOut] -> ShowS
show :: TxOut -> String
$cshow :: TxOut -> String
showsPrec :: Int -> TxOut -> ShowS
$cshowsPrec :: Int -> TxOut -> ShowS
Show
    , TxOut -> TxOut -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxOut -> TxOut -> Bool
$c/= :: TxOut -> TxOut -> Bool
== :: TxOut -> TxOut -> Bool
$c== :: TxOut -> TxOut -> Bool
Eq
    , Eq TxOut
TxOut -> TxOut -> Bool
TxOut -> TxOut -> Ordering
TxOut -> TxOut -> TxOut
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TxOut -> TxOut -> TxOut
$cmin :: TxOut -> TxOut -> TxOut
max :: TxOut -> TxOut -> TxOut
$cmax :: TxOut -> TxOut -> TxOut
>= :: TxOut -> TxOut -> Bool
$c>= :: TxOut -> TxOut -> Bool
> :: TxOut -> TxOut -> Bool
$c> :: TxOut -> TxOut -> Bool
<= :: TxOut -> TxOut -> Bool
$c<= :: TxOut -> TxOut -> Bool
< :: TxOut -> TxOut -> Bool
$c< :: TxOut -> TxOut -> Bool
compare :: TxOut -> TxOut -> Ordering
$ccompare :: TxOut -> TxOut -> Ordering
Ord
    , forall x. Rep TxOut x -> TxOut
forall x. TxOut -> Rep TxOut x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TxOut x -> TxOut
$cfrom :: forall x. TxOut -> Rep TxOut x
Generic
    , Eq TxOut
Int -> TxOut -> Int
TxOut -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: TxOut -> Int
$chash :: TxOut -> Int
hashWithSalt :: Int -> TxOut -> Int
$chashWithSalt :: Int -> TxOut -> Int
Hashable
    , TxOut -> Seq TypeRep
forall a. (a -> Seq TypeRep) -> HasTypeReps a
typeReps :: TxOut -> Seq TypeRep
$ctypeReps :: TxOut -> Seq TypeRep
HasTypeReps
    , Typeable TxOut
TxOut -> DataType
TxOut -> Constr
(forall b. Data b => b -> b) -> TxOut -> TxOut
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TxOut -> u
forall u. (forall d. Data d => d -> u) -> TxOut -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxOut -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxOut -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxOut
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxOut -> c TxOut
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxOut)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxOut)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxOut -> m TxOut
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxOut -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxOut -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> TxOut -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TxOut -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxOut -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxOut -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxOut -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxOut -> r
gmapT :: (forall b. Data b => b -> b) -> TxOut -> TxOut
$cgmapT :: (forall b. Data b => b -> b) -> TxOut -> TxOut
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxOut)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxOut)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxOut)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxOut)
dataTypeOf :: TxOut -> DataType
$cdataTypeOf :: TxOut -> DataType
toConstr :: TxOut -> Constr
$ctoConstr :: TxOut -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxOut
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxOut
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxOut -> c TxOut
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxOut -> c TxOut
Data
    , Typeable
    , Context -> TxOut -> IO (Maybe ThunkInfo)
Proxy TxOut -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy TxOut -> String
$cshowTypeOf :: Proxy TxOut -> String
wNoThunks :: Context -> TxOut -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> TxOut -> IO (Maybe ThunkInfo)
noThunks :: Context -> TxOut -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> TxOut -> IO (Maybe ThunkInfo)
NoThunks
    )

-- | The unspent transaction outputs.
newtype UTxO = UTxO
  { UTxO -> Map TxIn TxOut
unUTxO :: Map TxIn TxOut
  }
  deriving stock (Int -> UTxO -> ShowS
[UTxO] -> ShowS
UTxO -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UTxO] -> ShowS
$cshowList :: [UTxO] -> ShowS
show :: UTxO -> String
$cshow :: UTxO -> String
showsPrec :: Int -> UTxO -> ShowS
$cshowsPrec :: Int -> UTxO -> ShowS
Show, Typeable UTxO
UTxO -> DataType
UTxO -> Constr
(forall b. Data b => b -> b) -> UTxO -> UTxO
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> UTxO -> u
forall u. (forall d. Data d => d -> u) -> UTxO -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTxO -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTxO -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UTxO
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UTxO -> c UTxO
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UTxO)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTxO)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UTxO -> m UTxO
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UTxO -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UTxO -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> UTxO -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> UTxO -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTxO -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTxO -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTxO -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTxO -> r
gmapT :: (forall b. Data b => b -> b) -> UTxO -> UTxO
$cgmapT :: (forall b. Data b => b -> b) -> UTxO -> UTxO
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTxO)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTxO)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UTxO)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c UTxO)
dataTypeOf :: UTxO -> DataType
$cdataTypeOf :: UTxO -> DataType
toConstr :: UTxO -> Constr
$ctoConstr :: UTxO -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UTxO
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c UTxO
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UTxO -> c UTxO
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UTxO -> c UTxO
Data, Typeable)
  deriving newtype (UTxO -> UTxO -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UTxO -> UTxO -> Bool
$c/= :: UTxO -> UTxO -> Bool
== :: UTxO -> UTxO -> Bool
$c== :: UTxO -> UTxO -> Bool
Eq, (Ord (Domain UTxO), Ord (Range UTxO)) => UTxO -> UTxO -> UTxO
Ord (Domain UTxO) => Domain UTxO -> UTxO -> UTxO
Ord (Domain UTxO) => UTxO -> Set (Domain UTxO)
Ord (Range UTxO) => UTxO -> Set (Range UTxO)
Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
Ord (Range UTxO) => UTxO -> Range UTxO -> UTxO
Domain UTxO -> Range UTxO -> UTxO
forall n. Integral n => UTxO -> n
forall m.
(Domain m -> Range m -> m)
-> (Ord (Domain m) => m -> Set (Domain m))
-> (Ord (Range m) => m -> Set (Range m))
-> (forall (f :: * -> *).
    (Ord (Domain m), Foldable f) =>
    f (Domain m) -> m -> m)
-> (forall (f :: * -> *).
    (Ord (Domain m), Foldable f) =>
    f (Domain m) -> m -> m)
-> (forall (f :: * -> *).
    (Ord (Domain m), Foldable f) =>
    f (Domain m) -> m -> m)
-> (forall (f :: * -> *).
    (Ord (Domain m), Foldable f) =>
    f (Domain m) -> m -> m)
-> (Ord (Range m) => m -> Set (Range m) -> m)
-> (Ord (Range m) => m -> Set (Range m) -> m)
-> (Ord (Range m) => m -> Set (Range m) -> m)
-> (Ord (Range m) => m -> Set (Range m) -> m)
-> ((Ord (Domain m), Ord (Range m)) => m -> m -> m)
-> (forall (f :: * -> *).
    (Ord (Domain m), Ord (Range m), Foldable f) =>
    m -> f (Domain m, Range m) -> m)
-> (Ord (Domain m) => Domain m -> m -> m)
-> (Ord (Range m) => m -> Range m -> m)
-> (Ord (Range m) => m -> Range m -> m)
-> (forall n. Integral n => m -> n)
-> Relation m
forall (f :: * -> *).
(Ord (Domain UTxO), Ord (Range UTxO), Foldable f) =>
UTxO -> f (Domain UTxO, Range UTxO) -> UTxO
forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
size :: forall n. Integral n => UTxO -> n
$csize :: forall n. Integral n => UTxO -> n
▷>= :: Ord (Range UTxO) => UTxO -> Range UTxO -> UTxO
$c▷>= :: Ord (Range UTxO) => UTxO -> Range UTxO -> UTxO
▷<= :: Ord (Range UTxO) => UTxO -> Range UTxO -> UTxO
$c▷<= :: Ord (Range UTxO) => UTxO -> Range UTxO -> UTxO
<=◁ :: Ord (Domain UTxO) => Domain UTxO -> UTxO -> UTxO
$c<=◁ :: Ord (Domain UTxO) => Domain UTxO -> UTxO -> UTxO
⨃ :: forall (f :: * -> *).
(Ord (Domain UTxO), Ord (Range UTxO), Foldable f) =>
UTxO -> f (Domain UTxO, Range UTxO) -> UTxO
$c⨃ :: forall (f :: * -> *).
(Ord (Domain UTxO), Ord (Range UTxO), Foldable f) =>
UTxO -> f (Domain UTxO, Range UTxO) -> UTxO
∪ :: (Ord (Domain UTxO), Ord (Range UTxO)) => UTxO -> UTxO -> UTxO
$c∪ :: (Ord (Domain UTxO), Ord (Range UTxO)) => UTxO -> UTxO -> UTxO
|/> :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
$c|/> :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
⋫ :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
$c⋫ :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
|> :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
$c|> :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
▷ :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
$c▷ :: Ord (Range UTxO) => UTxO -> Set (Range UTxO) -> UTxO
</| :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
$c</| :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
⋪ :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
$c⋪ :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
<| :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
$c<| :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
◁ :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
$c◁ :: forall (f :: * -> *).
(Ord (Domain UTxO), Foldable f) =>
f (Domain UTxO) -> UTxO -> UTxO
range :: Ord (Range UTxO) => UTxO -> Set (Range UTxO)
$crange :: Ord (Range UTxO) => UTxO -> Set (Range UTxO)
dom :: Ord (Domain UTxO) => UTxO -> Set (Domain UTxO)
$cdom :: Ord (Domain UTxO) => UTxO -> Set (Domain UTxO)
singleton :: Domain UTxO -> Range UTxO -> UTxO
$csingleton :: Domain UTxO -> Range UTxO -> UTxO
Relation, NonEmpty UTxO -> UTxO
UTxO -> UTxO -> UTxO
forall b. Integral b => b -> UTxO -> UTxO
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> UTxO -> UTxO
$cstimes :: forall b. Integral b => b -> UTxO -> UTxO
sconcat :: NonEmpty UTxO -> UTxO
$csconcat :: NonEmpty UTxO -> UTxO
<> :: UTxO -> UTxO -> UTxO
$c<> :: UTxO -> UTxO -> UTxO
Semigroup, Semigroup UTxO
UTxO
[UTxO] -> UTxO
UTxO -> UTxO -> UTxO
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [UTxO] -> UTxO
$cmconcat :: [UTxO] -> UTxO
mappend :: UTxO -> UTxO -> UTxO
$cmappend :: UTxO -> UTxO -> UTxO
mempty :: UTxO
$cmempty :: UTxO
Monoid, Context -> UTxO -> IO (Maybe ThunkInfo)
Proxy UTxO -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy UTxO -> String
$cshowTypeOf :: Proxy UTxO -> String
wNoThunks :: Context -> UTxO -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> UTxO -> IO (Maybe ThunkInfo)
noThunks :: Context -> UTxO -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> UTxO -> IO (Maybe ThunkInfo)
NoThunks)

-- | Apply function uniformly across all outputs
mapUTxOValues :: (Lovelace -> Lovelace) -> UTxO -> UTxO
mapUTxOValues :: (Lovelace -> Lovelace) -> UTxO -> UTxO
mapUTxOValues Lovelace -> Lovelace
f (UTxO Map TxIn TxOut
utxo) = Map TxIn TxOut -> UTxO
UTxO (TxOut -> TxOut
f' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map TxIn TxOut
utxo)
  where
    f' :: TxOut -> TxOut
    f' :: TxOut -> TxOut
f' (TxOut Addr
addr Lovelace
value) = Addr -> Lovelace -> TxOut
TxOut Addr
addr (Lovelace -> Lovelace
f Lovelace
value)

addValue :: TxOut -> Lovelace -> TxOut
addValue :: TxOut -> Lovelace -> TxOut
addValue tx :: TxOut
tx@TxOut {Lovelace
value :: Lovelace
value :: TxOut -> Lovelace
value} Lovelace
d = TxOut
tx {value :: Lovelace
value = Lovelace
value forall a. Num a => a -> a -> a
+ Lovelace
d}

-- | Construct a UTxO from initial TxOuts
fromTxOuts :: [TxOut] -> UTxO
fromTxOuts :: [TxOut] -> UTxO
fromTxOuts = Map TxIn TxOut -> UTxO
UTxO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\TxOut
out -> (TxId -> Natural -> TxIn
TxIn (TxOut -> TxId
mkId TxOut
out) Natural
0, TxOut
out))
  where
    mkId :: TxOut -> TxId
mkId = Hash -> TxId
TxId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasHash a => a -> Hash
hash forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut -> Addr
addr

-- | A raw transaction
data TxBody = TxBody
  { TxBody -> [TxIn]
inputs :: [TxIn]
  , TxBody -> [TxOut]
outputs :: [TxOut]
  }
  deriving
    ( TxBody -> TxBody -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TxBody -> TxBody -> Bool
$c/= :: TxBody -> TxBody -> Bool
== :: TxBody -> TxBody -> Bool
$c== :: TxBody -> TxBody -> Bool
Eq
    , Int -> TxBody -> ShowS
[TxBody] -> ShowS
TxBody -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxBody] -> ShowS
$cshowList :: [TxBody] -> ShowS
show :: TxBody -> String
$cshow :: TxBody -> String
showsPrec :: Int -> TxBody -> ShowS
$cshowsPrec :: Int -> TxBody -> ShowS
Show
    , Eq TxBody
TxBody -> TxBody -> Bool
TxBody -> TxBody -> Ordering
TxBody -> TxBody -> TxBody
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TxBody -> TxBody -> TxBody
$cmin :: TxBody -> TxBody -> TxBody
max :: TxBody -> TxBody -> TxBody
$cmax :: TxBody -> TxBody -> TxBody
>= :: TxBody -> TxBody -> Bool
$c>= :: TxBody -> TxBody -> Bool
> :: TxBody -> TxBody -> Bool
$c> :: TxBody -> TxBody -> Bool
<= :: TxBody -> TxBody -> Bool
$c<= :: TxBody -> TxBody -> Bool
< :: TxBody -> TxBody -> Bool
$c< :: TxBody -> TxBody -> Bool
compare :: TxBody -> TxBody -> Ordering
$ccompare :: TxBody -> TxBody -> Ordering
Ord
    , forall x. Rep TxBody x -> TxBody
forall x. TxBody -> Rep TxBody x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TxBody x -> TxBody
$cfrom :: forall x. TxBody -> Rep TxBody x
Generic
    , Eq TxBody
Int -> TxBody -> Int
TxBody -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: TxBody -> Int
$chash :: TxBody -> Int
hashWithSalt :: Int -> TxBody -> Int
$chashWithSalt :: Int -> TxBody -> Int
Hashable
    , TxBody -> Seq TypeRep
forall a. (a -> Seq TypeRep) -> HasTypeReps a
typeReps :: TxBody -> Seq TypeRep
$ctypeReps :: TxBody -> Seq TypeRep
HasTypeReps
    , Typeable TxBody
TxBody -> DataType
TxBody -> Constr
(forall b. Data b => b -> b) -> TxBody -> TxBody
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> TxBody -> u
forall u. (forall d. Data d => d -> u) -> TxBody -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxBody -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxBody -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxBody
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxBody -> c TxBody
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxBody)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxBody)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> TxBody -> m TxBody
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxBody -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> TxBody -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> TxBody -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> TxBody -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxBody -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TxBody -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxBody -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TxBody -> r
gmapT :: (forall b. Data b => b -> b) -> TxBody -> TxBody
$cgmapT :: (forall b. Data b => b -> b) -> TxBody -> TxBody
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxBody)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TxBody)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxBody)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c TxBody)
dataTypeOf :: TxBody -> DataType
$cdataTypeOf :: TxBody -> DataType
toConstr :: TxBody -> Constr
$ctoConstr :: TxBody -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxBody
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TxBody
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxBody -> c TxBody
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> TxBody -> c TxBody
Data
    , Typeable
    , Context -> TxBody -> IO (Maybe ThunkInfo)
Proxy TxBody -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy TxBody -> String
$cshowTypeOf :: Proxy TxBody -> String
wNoThunks :: Context -> TxBody -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> TxBody -> IO (Maybe ThunkInfo)
noThunks :: Context -> TxBody -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> TxBody -> IO (Maybe ThunkInfo)
NoThunks
    )

txid :: TxBody -> TxId
txid :: TxBody -> TxId
txid = Hash -> TxId
TxId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasHash a => a -> Hash
hash

-- | Total value of a transaction.
txValue :: TxBody -> Lovelace
txValue :: TxBody -> Lovelace
txValue TxBody {[TxOut]
outputs :: [TxOut]
outputs :: TxBody -> [TxOut]
outputs} = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TxOut -> Lovelace
value [TxOut]
outputs

-- | Compute the UTxO inputs of a transaction.
txins :: TxBody -> [TxIn]
txins :: TxBody -> [TxIn]
txins = TxBody -> [TxIn]
inputs

-- | Compute the UTxO outputs of a transaction.
txouts :: TxBody -> UTxO
txouts :: TxBody -> UTxO
txouts TxBody
tx =
  Map TxIn TxOut -> UTxO
UTxO forall a b. (a -> b) -> a -> b
$
    forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
      [(TxId -> Natural -> TxIn
TxIn TxId
transId Natural
idx, TxOut
out) | (TxOut
out, Natural
idx) <- forall a b. [a] -> [b] -> [(a, b)]
zip (TxBody -> [TxOut]
outputs TxBody
tx) [Natural
0 ..]]
  where
    transId :: TxId
transId = TxBody -> TxId
txid TxBody
tx

-- | Determine the total balance contained in the UTxO.
balance :: UTxO -> Lovelace
balance :: UTxO -> Lovelace
balance (UTxO Map TxIn TxOut
utxo) = forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl' Lovelace -> TxOut -> Lovelace
addValues forall a. Monoid a => a
mempty Map TxIn TxOut
utxo
  where
    addValues :: Lovelace -> TxOut -> Lovelace
addValues Lovelace
b (TxOut Addr
_ Lovelace
a) = Lovelace
b forall a. Semigroup a => a -> a -> a
<> Lovelace
a

instance Byron.Spec.Ledger.Core.HasHash TxBody where
  hash :: TxBody -> Hash
hash = Maybe Int -> Hash
Hash forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Hashable a => a -> Int
H.hash

---------------------------------------------------------------------------------
-- UTxO transitions
---------------------------------------------------------------------------------

pcMinFee :: PParams -> Tx -> Lovelace
pcMinFee :: PParams -> Tx -> Lovelace
pcMinFee PParams {_factorA :: PParams -> FactorA
_factorA = FactorA Int
a, _factorB :: PParams -> FactorB
_factorB = FactorB Int
b} Tx
tx =
  forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Int
a forall a. Num a => a -> a -> a
+ Int
b forall a. Num a => a -> a -> a
* Tx -> Int
txsize Tx
tx

txsize :: Tx -> Int
txsize :: Tx -> Int
txsize = forall a. HasTypeReps a => AccountingMap -> a -> Int
abstractSize AccountingMap
costs
  where
    costs :: AccountingMap
costs =
      forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
        [ (forall a. Typeable a => a -> TypeRep
typeOf (forall a. HasCallStack => a
undefined :: TxIn), Int
1)
        , (forall a. Typeable a => a -> TypeRep
typeOf (forall a. HasCallStack => a
undefined :: TxOut), Int
1)
        , (forall a. Typeable a => a -> TypeRep
typeOf (forall a. HasCallStack => a
undefined :: Wit), Int
1)
        ]

---------------------------------------------------------------------------------
-- UTxO transitions
---------------------------------------------------------------------------------

-- | Proof/Witness that a transaction is authorized by the given key holder.
data Wit = Wit VKey (Sig TxBody)
  deriving
    ( Int -> Wit -> ShowS
[Wit] -> ShowS
Wit -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Wit] -> ShowS
$cshowList :: [Wit] -> ShowS
show :: Wit -> String
$cshow :: Wit -> String
showsPrec :: Int -> Wit -> ShowS
$cshowsPrec :: Int -> Wit -> ShowS
Show
    , Wit -> Wit -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Wit -> Wit -> Bool
$c/= :: Wit -> Wit -> Bool
== :: Wit -> Wit -> Bool
$c== :: Wit -> Wit -> Bool
Eq
    , Eq Wit
Wit -> Wit -> Bool
Wit -> Wit -> Ordering
Wit -> Wit -> Wit
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Wit -> Wit -> Wit
$cmin :: Wit -> Wit -> Wit
max :: Wit -> Wit -> Wit
$cmax :: Wit -> Wit -> Wit
>= :: Wit -> Wit -> Bool
$c>= :: Wit -> Wit -> Bool
> :: Wit -> Wit -> Bool
$c> :: Wit -> Wit -> Bool
<= :: Wit -> Wit -> Bool
$c<= :: Wit -> Wit -> Bool
< :: Wit -> Wit -> Bool
$c< :: Wit -> Wit -> Bool
compare :: Wit -> Wit -> Ordering
$ccompare :: Wit -> Wit -> Ordering
Ord
    , forall x. Rep Wit x -> Wit
forall x. Wit -> Rep Wit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Wit x -> Wit
$cfrom :: forall x. Wit -> Rep Wit x
Generic
    , Eq Wit
Int -> Wit -> Int
Wit -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: Wit -> Int
$chash :: Wit -> Int
hashWithSalt :: Int -> Wit -> Int
$chashWithSalt :: Int -> Wit -> Int
Hashable
    , Wit -> Seq TypeRep
forall a. (a -> Seq TypeRep) -> HasTypeReps a
typeReps :: Wit -> Seq TypeRep
$ctypeReps :: Wit -> Seq TypeRep
HasTypeReps
    , Typeable Wit
Wit -> DataType
Wit -> Constr
(forall b. Data b => b -> b) -> Wit -> Wit
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Wit -> u
forall u. (forall d. Data d => d -> u) -> Wit -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wit -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wit -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Wit
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wit -> c Wit
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Wit)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Wit)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Wit -> m Wit
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Wit -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Wit -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Wit -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Wit -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wit -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Wit -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wit -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Wit -> r
gmapT :: (forall b. Data b => b -> b) -> Wit -> Wit
$cgmapT :: (forall b. Data b => b -> b) -> Wit -> Wit
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Wit)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Wit)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Wit)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Wit)
dataTypeOf :: Wit -> DataType
$cdataTypeOf :: Wit -> DataType
toConstr :: Wit -> Constr
$ctoConstr :: Wit -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Wit
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Wit
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wit -> c Wit
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Wit -> c Wit
Data
    , Typeable
    , Context -> Wit -> IO (Maybe ThunkInfo)
Proxy Wit -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy Wit -> String
$cshowTypeOf :: Proxy Wit -> String
wNoThunks :: Context -> Wit -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> Wit -> IO (Maybe ThunkInfo)
noThunks :: Context -> Wit -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> Wit -> IO (Maybe ThunkInfo)
NoThunks
    )

-- | A fully formed transaction.
data Tx = Tx
  { Tx -> TxBody
body :: TxBody
  , Tx -> [Wit]
witnesses :: [Wit]
  }
  deriving
    ( Int -> Tx -> ShowS
[Tx] -> ShowS
Tx -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tx] -> ShowS
$cshowList :: [Tx] -> ShowS
show :: Tx -> String
$cshow :: Tx -> String
showsPrec :: Int -> Tx -> ShowS
$cshowsPrec :: Int -> Tx -> ShowS
Show
    , Tx -> Tx -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tx -> Tx -> Bool
$c/= :: Tx -> Tx -> Bool
== :: Tx -> Tx -> Bool
$c== :: Tx -> Tx -> Bool
Eq
    , forall x. Rep Tx x -> Tx
forall x. Tx -> Rep Tx x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Tx x -> Tx
$cfrom :: forall x. Tx -> Rep Tx x
Generic
    , Eq Tx
Int -> Tx -> Int
Tx -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: Tx -> Int
$chash :: Tx -> Int
hashWithSalt :: Int -> Tx -> Int
$chashWithSalt :: Int -> Tx -> Int
Hashable
    , Tx -> Seq TypeRep
forall a. (a -> Seq TypeRep) -> HasTypeReps a
typeReps :: Tx -> Seq TypeRep
$ctypeReps :: Tx -> Seq TypeRep
HasTypeReps
    , Typeable Tx
Tx -> DataType
Tx -> Constr
(forall b. Data b => b -> b) -> Tx -> Tx
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Tx -> u
forall u. (forall d. Data d => d -> u) -> Tx -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tx -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tx -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Tx
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Tx -> c Tx
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Tx)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Tx)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Tx -> m Tx
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Tx -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Tx -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Tx -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Tx -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tx -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tx -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tx -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tx -> r
gmapT :: (forall b. Data b => b -> b) -> Tx -> Tx
$cgmapT :: (forall b. Data b => b -> b) -> Tx -> Tx
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Tx)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Tx)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Tx)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Tx)
dataTypeOf :: Tx -> DataType
$cdataTypeOf :: Tx -> DataType
toConstr :: Tx -> Constr
$ctoConstr :: Tx -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Tx
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Tx
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Tx -> c Tx
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Tx -> c Tx
Data
    , Typeable
    , Context -> Tx -> IO (Maybe ThunkInfo)
Proxy Tx -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy Tx -> String
$cshowTypeOf :: Proxy Tx -> String
wNoThunks :: Context -> Tx -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> Tx -> IO (Maybe ThunkInfo)
noThunks :: Context -> Tx -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> Tx -> IO (Maybe ThunkInfo)
NoThunks
    )

instance HasHash [Tx] where
  hash :: [Tx] -> Hash
hash = Maybe Int -> Hash
Hash forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Hashable a => a -> Int
H.hash

-- | Create a witness for transaction
makeWitness :: KeyPair -> TxBody -> Wit
makeWitness :: KeyPair -> TxBody -> Wit
makeWitness KeyPair
keys TxBody
tx = VKey -> Sig TxBody -> Wit
Wit (KeyPair -> VKey
vKey KeyPair
keys) (forall a. SKey -> a -> Sig a
sign (KeyPair -> SKey
sKey KeyPair
keys) TxBody
tx)

makeTxWits :: UTxO -> TxBody -> Tx
makeTxWits :: UTxO -> TxBody -> Tx
makeTxWits (UTxO Map TxIn TxOut
utxo) TxBody
tx =
  Tx
    { body :: TxBody
body = TxBody
tx
    , witnesses :: [Wit]
witnesses = [Wit]
wits
    }
  where
    getKey :: TxIn -> KeyPair
getKey TxIn
txin =
      let TxOut (Addr (VKey Owner
o)) Lovelace
_ =
            forall a. a -> Maybe a -> a
fromMaybe
              (forall a. HasCallStack => String -> a
error String
"makeTxWits: Missing output for transaction input")
              forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup TxIn
txin Map TxIn TxOut
utxo
       in SKey -> VKey -> KeyPair
KeyPair (Owner -> SKey
SKey Owner
o) (Owner -> VKey
VKey Owner
o)
    keys :: [KeyPair]
keys = TxIn -> KeyPair
getKey forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TxBody -> [TxIn]
inputs TxBody
tx
    wits :: [Wit]
wits = KeyPair -> TxBody -> Wit
makeWitness forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [KeyPair]
keys forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure TxBody
tx