-- | This module provides the description of a transaction skeleton. We have our
-- own representation of a transaction for many reasons. Here are some of them:
--
-- - our transaction skeletons are typed (datums, validators, outputs...)
--
-- - each transaction skeleton comes with its own set of generation options
--
-- - our transaction skeleton is by default anchored in the latest Cardano era
--
-- - each field in our transaction skeleton comes with a set of helpers and
-- - smart constructor to ease the transaction creation
--
-- - we can have default or automated behavior for the parts of the transactions
-- that are less relevant to testing, such as collaterals or fees
module Cooked.Skeleton
  ( module X,
    TxSkel (..),
    txSkelLabelL,
    txSkelOptsL,
    txSkelMintsL,
    txSkelValidityRangeL,
    txSkelProposalsL,
    txSkelSignatoriesL,
    txSkelInsL,
    txSkelInsReferenceL,
    txSkelOutsL,
    txSkelWithdrawalsL,
    txSkelCertificatesL,
    txSkelTemplate,
    txSkelKnownTxOutRefs,
    txSkelWithdrawnValue,
    txSkelWithdrawingScripts,
    txSkelValueInOutputs,
    txSkelInsReferenceInRedeemers,
    txSkelProposingScripts,
    txSkelMintingScripts,
    txSkelCertifyingScripts,
  )
where

import Cooked.Skeleton.Anchor as X
import Cooked.Skeleton.Certificate as X
import Cooked.Skeleton.Datum as X
import Cooked.Skeleton.Label as X
import Cooked.Skeleton.Mint as X
import Cooked.Skeleton.Option as X
import Cooked.Skeleton.Output as X
import Cooked.Skeleton.Proposal as X
import Cooked.Skeleton.Redeemer as X
import Cooked.Skeleton.Signatory as X
import Cooked.Skeleton.User as X
import Cooked.Skeleton.Value as X
import Cooked.Skeleton.Withdrawal as X
import Data.Default
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Set (Set)
import Data.Set qualified as Set
import Ledger.Slot qualified as Ledger
import Optics.Core
import Optics.TH
import Plutus.Script.Utils.Value qualified as Script
import PlutusLedgerApi.V3 qualified as Api

-- | A transaction skeleton. This is cooked-validators's variant of transaction
-- bodies, eventually translated to Cardano @TxBody@.
data TxSkel where
  TxSkel ::
    { -- | Labels do not influence the transaction generation at all; they are
      -- pretty-printed whenever cooked-validators prints a transaction, and can
      -- therefore make the output more informative.
      TxSkel -> Set TxSkelLabel
txSkelLabel :: Set TxSkelLabel,
      -- | Some options that control transaction generation.
      TxSkel -> TxSkelOpts
txSkelOpts :: TxSkelOpts,
      -- | Any value minted or burned by the transaction. You'll probably want
      -- to use 'Cooked.Skeleton.Mint.txSkelMintsFromList' to construct this.
      TxSkel -> TxSkelMints
txSkelMints :: TxSkelMints,
      -- | The signatories of the transaction. When auto-balancing is enabled,
      -- this list must contain at least one element, which is always expected
      -- to be case in practice anyway. By default, the first signatory will pay
      -- for fees and balancing. You can change that with
      -- 'Cooked.Skeleton.Option.txOptBalancingPolicy'.
      TxSkel -> [TxSkelSignatory]
txSkelSignatories :: [TxSkelSignatory],
      TxSkel -> SlotRange
txSkelValidityRange :: Ledger.SlotRange,
      -- | To each 'Api.TxOutRef' the transaction should consume, add a redeemer
      -- specifying how to spend it. You must make sure that
      --
      -- - On 'Api.TxOutRef's referencing UTxOs belonging to public keys, use
      --   the 'Cooked.Skeleton.Redeemer.emptyTxSkelRedeemer' smart constructor.
      --
      -- - On 'Api.TxOutRef's referencing UTxOs belonging to scripts, use
      --   the 'Cooked.Skeleton.Redeemer.someTxSkelRedeemer' smart constructor.
      TxSkel -> Map TxOutRef TxSkelRedeemer
txSkelIns :: Map Api.TxOutRef TxSkelRedeemer,
      -- | All outputs directly referenced by the transaction. Each of them will
      -- be directly translated into a Cardano reference input. Additional
      -- reference inputs can be found within the various redeemers of the
      -- skeleton to host reference scripts. Function
      -- 'txSkelInsReferenceInRedeemers' collects those all.
      TxSkel -> Set TxOutRef
txSkelInsReference :: Set Api.TxOutRef,
      -- | The outputs of the transaction. These will occur in exactly this
      -- order on the transaction.
      TxSkel -> [TxSkelOut]
txSkelOuts :: [TxSkelOut],
      -- | Possible proposals issued in this transaction to be voted on and
      -- possible enacted later on.
      TxSkel -> [TxSkelProposal]
txSkelProposals :: [TxSkelProposal],
      -- | Withdrawals performed by the transaction
      TxSkel -> TxSkelWithdrawals
txSkelWithdrawals :: TxSkelWithdrawals,
      -- | Certificates issued by the transaction
      TxSkel -> [TxSkelCertificate]
txSkelCertificates :: [TxSkelCertificate]
    } ->
    TxSkel
  deriving (Int -> TxSkel -> ShowS
[TxSkel] -> ShowS
TxSkel -> String
(Int -> TxSkel -> ShowS)
-> (TxSkel -> String) -> ([TxSkel] -> ShowS) -> Show TxSkel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxSkel -> ShowS
showsPrec :: Int -> TxSkel -> ShowS
$cshow :: TxSkel -> String
show :: TxSkel -> String
$cshowList :: [TxSkel] -> ShowS
showList :: [TxSkel] -> ShowS
Show, TxSkel -> TxSkel -> Bool
(TxSkel -> TxSkel -> Bool)
-> (TxSkel -> TxSkel -> Bool) -> Eq TxSkel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxSkel -> TxSkel -> Bool
== :: TxSkel -> TxSkel -> Bool
$c/= :: TxSkel -> TxSkel -> Bool
/= :: TxSkel -> TxSkel -> Bool
Eq)

-- | Focusing on the labels of a 'TxSkel'
makeLensesFor [("txSkelLabel", "txSkelLabelL")] ''TxSkel

-- | Focusing on the optics of a 'TxSkel'
makeLensesFor [("txSkelOpts", "txSkelOptsL")] ''TxSkel

-- | Focusing on the minted value of a 'TxSkel'
makeLensesFor [("txSkelMints", "txSkelMintsL")] ''TxSkel

-- | Focusing on the validity range of a 'TxSkel'
makeLensesFor [("txSkelValidityRange", "txSkelValidityRangeL")] ''TxSkel

-- | Focusing on the signatories of a 'TxSkel'
makeLensesFor [("txSkelSignatories", "txSkelSignatoriesL")] ''TxSkel

-- | Focusing on the inputs of a 'TxSkel'
makeLensesFor [("txSkelIns", "txSkelInsL")] ''TxSkel

-- | Focusing on the reference inputs of a 'TxSkel'
makeLensesFor [("txSkelInsReference", "txSkelInsReferenceL")] ''TxSkel

-- | Focusing on the outputs of a 'TxSkel'
makeLensesFor [("txSkelOuts", "txSkelOutsL")] ''TxSkel

-- | Focusing on the proposals of a 'TxSkel'
makeLensesFor [("txSkelProposals", "txSkelProposalsL")] ''TxSkel

-- | Focusing on the withdrawals of a 'TxSkel'
makeLensesFor [("txSkelWithdrawals", "txSkelWithdrawalsL")] ''TxSkel

-- | Focusing on the certificates of a 'TxSkel'
makeLensesFor [("txSkelCertificates", "txSkelCertificatesL")] ''TxSkel

-- | A lens to set or

-- | A convenience template of an empty transaction skeleton.
txSkelTemplate :: TxSkel
txSkelTemplate :: TxSkel
txSkelTemplate =
  TxSkel
    { txSkelLabel :: Set TxSkelLabel
txSkelLabel = Set TxSkelLabel
forall a. Monoid a => a
mempty,
      txSkelOpts :: TxSkelOpts
txSkelOpts = TxSkelOpts
forall a. Default a => a
def,
      txSkelMints :: TxSkelMints
txSkelMints = TxSkelMints
forall a. Monoid a => a
mempty,
      txSkelValidityRange :: SlotRange
txSkelValidityRange = SlotRange
forall a. Interval a
Api.always,
      txSkelSignatories :: [TxSkelSignatory]
txSkelSignatories = [TxSkelSignatory]
forall a. Monoid a => a
mempty,
      txSkelIns :: Map TxOutRef TxSkelRedeemer
txSkelIns = Map TxOutRef TxSkelRedeemer
forall a. Monoid a => a
mempty,
      txSkelInsReference :: Set TxOutRef
txSkelInsReference = Set TxOutRef
forall a. Monoid a => a
mempty,
      txSkelOuts :: [TxSkelOut]
txSkelOuts = [TxSkelOut]
forall a. Monoid a => a
mempty,
      txSkelProposals :: [TxSkelProposal]
txSkelProposals = [TxSkelProposal]
forall a. Monoid a => a
mempty,
      txSkelWithdrawals :: TxSkelWithdrawals
txSkelWithdrawals = TxSkelWithdrawals
forall a. Monoid a => a
mempty,
      txSkelCertificates :: [TxSkelCertificate]
txSkelCertificates = [TxSkelCertificate]
forall a. Monoid a => a
mempty
    }

-- | Returns the full value contained in the skeleton outputs
txSkelValueInOutputs :: TxSkel -> Api.Value
txSkelValueInOutputs :: TxSkel -> Value
txSkelValueInOutputs = Optic' A_Fold '[] TxSkel Value -> TxSkel -> Value
forall k a (is :: IxList) s.
(Is k A_Fold, Monoid a) =>
Optic' k is s a -> s -> a
foldOf (Lens' TxSkel [TxSkelOut]
txSkelOutsL Lens' TxSkel [TxSkelOut]
-> Optic A_Fold '[] [TxSkelOut] [TxSkelOut] TxSkelOut TxSkelOut
-> Optic A_Fold '[] TxSkel TxSkel TxSkelOut TxSkelOut
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Fold '[] [TxSkelOut] [TxSkelOut] TxSkelOut TxSkelOut
forall (f :: * -> *) a. Foldable f => Fold (f a) a
folded Optic A_Fold '[] TxSkel TxSkel TxSkelOut TxSkelOut
-> Optic A_Lens '[] TxSkelOut TxSkelOut Value Value
-> Optic' A_Fold '[] TxSkel Value
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens '[] TxSkelOut TxSkelOut Value Value
txSkelOutValueL)

-- | All 'Api.TxOutRef's in reference inputs from redeemers
txSkelInsReferenceInRedeemers :: TxSkel -> Set Api.TxOutRef
txSkelInsReferenceInRedeemers :: TxSkel -> Set TxOutRef
txSkelInsReferenceInRedeemers TxSkel {[TxSkelSignatory]
[TxSkelProposal]
[TxSkelCertificate]
[TxSkelOut]
Set TxOutRef
Set TxSkelLabel
Map TxOutRef TxSkelRedeemer
SlotRange
TxSkelOpts
TxSkelWithdrawals
TxSkelMints
txSkelLabel :: TxSkel -> Set TxSkelLabel
txSkelOpts :: TxSkel -> TxSkelOpts
txSkelMints :: TxSkel -> TxSkelMints
txSkelSignatories :: TxSkel -> [TxSkelSignatory]
txSkelValidityRange :: TxSkel -> SlotRange
txSkelIns :: TxSkel -> Map TxOutRef TxSkelRedeemer
txSkelInsReference :: TxSkel -> Set TxOutRef
txSkelOuts :: TxSkel -> [TxSkelOut]
txSkelProposals :: TxSkel -> [TxSkelProposal]
txSkelWithdrawals :: TxSkel -> TxSkelWithdrawals
txSkelCertificates :: TxSkel -> [TxSkelCertificate]
txSkelLabel :: Set TxSkelLabel
txSkelOpts :: TxSkelOpts
txSkelMints :: TxSkelMints
txSkelSignatories :: [TxSkelSignatory]
txSkelValidityRange :: SlotRange
txSkelIns :: Map TxOutRef TxSkelRedeemer
txSkelInsReference :: Set TxOutRef
txSkelOuts :: [TxSkelOut]
txSkelProposals :: [TxSkelProposal]
txSkelWithdrawals :: TxSkelWithdrawals
txSkelCertificates :: [TxSkelCertificate]
..} =
  [TxOutRef] -> Set TxOutRef
forall a. Ord a => [a] -> Set a
Set.fromList ([TxOutRef] -> Set TxOutRef) -> [TxOutRef] -> Set TxOutRef
forall a b. (a -> b) -> a -> b
$
    Optic' A_Fold '[] (Map TxOutRef TxSkelRedeemer) TxOutRef
-> Map TxOutRef TxSkelRedeemer -> [TxOutRef]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf ((Map TxOutRef TxSkelRedeemer -> [TxSkelRedeemer])
-> Getter (Map TxOutRef TxSkelRedeemer) [TxSkelRedeemer]
forall s a. (s -> a) -> Getter s a
to Map TxOutRef TxSkelRedeemer -> [TxSkelRedeemer]
forall k a. Map k a -> [a]
Map.elems Getter (Map TxOutRef TxSkelRedeemer) [TxSkelRedeemer]
-> Optic
     A_Traversal
     '[]
     [TxSkelRedeemer]
     [TxSkelRedeemer]
     TxSkelRedeemer
     TxSkelRedeemer
-> Optic
     A_Fold
     '[]
     (Map TxOutRef TxSkelRedeemer)
     (Map TxOutRef TxSkelRedeemer)
     TxSkelRedeemer
     TxSkelRedeemer
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Traversal
  '[]
  [TxSkelRedeemer]
  [TxSkelRedeemer]
  TxSkelRedeemer
  TxSkelRedeemer
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic
  A_Fold
  '[]
  (Map TxOutRef TxSkelRedeemer)
  (Map TxOutRef TxSkelRedeemer)
  TxSkelRedeemer
  TxSkelRedeemer
-> Optic
     An_AffineTraversal
     '[]
     TxSkelRedeemer
     TxSkelRedeemer
     TxOutRef
     TxOutRef
-> Optic' A_Fold '[] (Map TxOutRef TxSkelRedeemer) TxOutRef
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelRedeemer
  TxSkelRedeemer
  TxOutRef
  TxOutRef
txSkelRedeemerReferenceInputAT) Map TxOutRef TxSkelRedeemer
txSkelIns
      [TxOutRef] -> [TxOutRef] -> [TxOutRef]
forall a. Semigroup a => a -> a -> a
<> Optic' A_Traversal '[] [TxSkelProposal] TxOutRef
-> [TxSkelProposal] -> [TxOutRef]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Traversal
  [TxSkelProposal] [TxSkelProposal] TxSkelProposal TxSkelProposal
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Traversal
  [TxSkelProposal] [TxSkelProposal] TxSkelProposal TxSkelProposal
-> Optic
     An_AffineTraversal
     '[]
     TxSkelProposal
     TxSkelProposal
     (Maybe (User 'IsScript 'Redemption))
     (Maybe (User 'IsScript 'Redemption))
-> Optic
     A_Traversal
     '[]
     [TxSkelProposal]
     [TxSkelProposal]
     (Maybe (User 'IsScript 'Redemption))
     (Maybe (User 'IsScript 'Redemption))
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelProposal
  TxSkelProposal
  (Maybe (User 'IsScript 'Redemption))
  (Maybe (User 'IsScript 'Redemption))
forall (kind :: UserKind).
Typeable kind =>
AffineTraversal' TxSkelProposal (Maybe (User kind 'Redemption))
txSkelProposalMConstitutionAT Optic
  A_Traversal
  '[]
  [TxSkelProposal]
  [TxSkelProposal]
  (Maybe (User 'IsScript 'Redemption))
  (Maybe (User 'IsScript 'Redemption))
-> Optic
     A_Prism
     '[]
     (Maybe (User 'IsScript 'Redemption))
     (Maybe (User 'IsScript 'Redemption))
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
-> Optic
     A_Traversal
     '[]
     [TxSkelProposal]
     [TxSkelProposal]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Prism
  '[]
  (Maybe (User 'IsScript 'Redemption))
  (Maybe (User 'IsScript 'Redemption))
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
forall a b. Prism (Maybe a) (Maybe b) a b
_Just Optic
  A_Traversal
  '[]
  [TxSkelProposal]
  [TxSkelProposal]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
-> Optic
     A_Lens
     '[]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
     TxSkelRedeemer
     TxSkelRedeemer
-> Optic
     A_Traversal
     '[]
     [TxSkelProposal]
     [TxSkelProposal]
     TxSkelRedeemer
     TxSkelRedeemer
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
  TxSkelRedeemer
  TxSkelRedeemer
userTxSkelRedeemerL Optic
  A_Traversal
  '[]
  [TxSkelProposal]
  [TxSkelProposal]
  TxSkelRedeemer
  TxSkelRedeemer
-> Optic
     An_AffineTraversal
     '[]
     TxSkelRedeemer
     TxSkelRedeemer
     TxOutRef
     TxOutRef
-> Optic' A_Traversal '[] [TxSkelProposal] TxOutRef
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelRedeemer
  TxSkelRedeemer
  TxOutRef
  TxOutRef
txSkelRedeemerReferenceInputAT) [TxSkelProposal]
txSkelProposals
      [TxOutRef] -> [TxOutRef] -> [TxOutRef]
forall a. Semigroup a => a -> a -> a
<> Optic' A_Traversal '[] TxSkelMints TxOutRef
-> TxSkelMints -> [TxOutRef]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Iso' TxSkelMints [Mint]
txSkelMintsListI Iso' TxSkelMints [Mint]
-> Optic A_Traversal '[] [Mint] [Mint] Mint Mint
-> Optic A_Traversal '[] TxSkelMints TxSkelMints Mint Mint
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Traversal '[] [Mint] [Mint] Mint Mint
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic A_Traversal '[] TxSkelMints TxSkelMints Mint Mint
-> Optic
     A_Lens
     '[]
     Mint
     Mint
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
-> Optic
     A_Traversal
     '[]
     TxSkelMints
     TxSkelMints
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  Mint
  Mint
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
mintRedeemedScriptL Optic
  A_Traversal
  '[]
  TxSkelMints
  TxSkelMints
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
-> Optic
     A_Lens
     '[]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
     TxSkelRedeemer
     TxSkelRedeemer
-> Optic
     A_Traversal
     '[]
     TxSkelMints
     TxSkelMints
     TxSkelRedeemer
     TxSkelRedeemer
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
  TxSkelRedeemer
  TxSkelRedeemer
userTxSkelRedeemerL Optic
  A_Traversal
  '[]
  TxSkelMints
  TxSkelMints
  TxSkelRedeemer
  TxSkelRedeemer
-> Optic
     An_AffineTraversal
     '[]
     TxSkelRedeemer
     TxSkelRedeemer
     TxOutRef
     TxOutRef
-> Optic' A_Traversal '[] TxSkelMints TxOutRef
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelRedeemer
  TxSkelRedeemer
  TxOutRef
  TxOutRef
txSkelRedeemerReferenceInputAT) TxSkelMints
txSkelMints
      [TxOutRef] -> [TxOutRef] -> [TxOutRef]
forall a. Semigroup a => a -> a -> a
<> Optic' A_Traversal '[] TxSkelWithdrawals TxOutRef
-> TxSkelWithdrawals -> [TxOutRef]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Iso' TxSkelWithdrawals [Withdrawal]
txSkelWithdrawalsListI Iso' TxSkelWithdrawals [Withdrawal]
-> Optic
     A_Traversal '[] [Withdrawal] [Withdrawal] Withdrawal Withdrawal
-> Optic
     A_Traversal
     '[]
     TxSkelWithdrawals
     TxSkelWithdrawals
     Withdrawal
     Withdrawal
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Traversal '[] [Withdrawal] [Withdrawal] Withdrawal Withdrawal
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic
  A_Traversal
  '[]
  TxSkelWithdrawals
  TxSkelWithdrawals
  Withdrawal
  Withdrawal
-> Optic
     A_Lens
     '[]
     Withdrawal
     Withdrawal
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
-> Optic
     A_Traversal
     '[]
     TxSkelWithdrawals
     TxSkelWithdrawals
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  Withdrawal
  Withdrawal
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
withdrawalUserL Optic
  A_Traversal
  '[]
  TxSkelWithdrawals
  TxSkelWithdrawals
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
-> Optic
     An_AffineTraversal
     '[]
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
     TxSkelRedeemer
     TxSkelRedeemer
-> Optic
     A_Traversal
     '[]
     TxSkelWithdrawals
     TxSkelWithdrawals
     TxSkelRedeemer
     TxSkelRedeemer
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
  TxSkelRedeemer
  TxSkelRedeemer
forall (kind :: UserKind) (mode :: UserMode).
AffineTraversal' (User kind mode) TxSkelRedeemer
userTxSkelRedeemerAT Optic
  A_Traversal
  '[]
  TxSkelWithdrawals
  TxSkelWithdrawals
  TxSkelRedeemer
  TxSkelRedeemer
-> Optic
     An_AffineTraversal
     '[]
     TxSkelRedeemer
     TxSkelRedeemer
     TxOutRef
     TxOutRef
-> Optic' A_Traversal '[] TxSkelWithdrawals TxOutRef
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelRedeemer
  TxSkelRedeemer
  TxOutRef
  TxOutRef
txSkelRedeemerReferenceInputAT) TxSkelWithdrawals
txSkelWithdrawals
      [TxOutRef] -> [TxOutRef] -> [TxOutRef]
forall a. Semigroup a => a -> a -> a
<> Optic' A_Traversal '[] [TxSkelCertificate] TxOutRef
-> [TxSkelCertificate] -> [TxOutRef]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Traversal
  [TxSkelCertificate]
  [TxSkelCertificate]
  TxSkelCertificate
  TxSkelCertificate
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Traversal
  [TxSkelCertificate]
  [TxSkelCertificate]
  TxSkelCertificate
  TxSkelCertificate
-> Optic
     An_AffineTraversal
     '[]
     TxSkelCertificate
     TxSkelCertificate
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
-> Optic
     A_Traversal
     '[]
     [TxSkelCertificate]
     [TxSkelCertificate]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelCertificate
  TxSkelCertificate
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
forall (user :: UserKind).
Typeable user =>
AffineTraversal' TxSkelCertificate (User user 'Redemption)
txSkelCertificateOwnerAT Optic
  A_Traversal
  '[]
  [TxSkelCertificate]
  [TxSkelCertificate]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
-> Optic
     A_Lens
     '[]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
     TxSkelRedeemer
     TxSkelRedeemer
-> Optic
     A_Traversal
     '[]
     [TxSkelCertificate]
     [TxSkelCertificate]
     TxSkelRedeemer
     TxSkelRedeemer
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
  TxSkelRedeemer
  TxSkelRedeemer
userTxSkelRedeemerL Optic
  A_Traversal
  '[]
  [TxSkelCertificate]
  [TxSkelCertificate]
  TxSkelRedeemer
  TxSkelRedeemer
-> Optic
     An_AffineTraversal
     '[]
     TxSkelRedeemer
     TxSkelRedeemer
     TxOutRef
     TxOutRef
-> Optic' A_Traversal '[] [TxSkelCertificate] TxOutRef
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelRedeemer
  TxSkelRedeemer
  TxOutRef
  TxOutRef
txSkelRedeemerReferenceInputAT) [TxSkelCertificate]
txSkelCertificates

-- | All `Api.TxOutRef`s known by a given transaction skeleton. This includes
-- TxOutRef`s used as inputs of the skeleton and 'Api.TxOutRef's used as reference
-- inputs of the skeleton.  This does not include additional possible
-- 'Api.TxOutRef's used for balancing and additional 'Api.TxOutRef's used as collateral
-- inputs, as they are not part of the skeleton.
txSkelKnownTxOutRefs :: TxSkel -> Set Api.TxOutRef
txSkelKnownTxOutRefs :: TxSkel -> Set TxOutRef
txSkelKnownTxOutRefs skel :: TxSkel
skel@TxSkel {[TxSkelSignatory]
[TxSkelProposal]
[TxSkelCertificate]
[TxSkelOut]
Set TxOutRef
Set TxSkelLabel
Map TxOutRef TxSkelRedeemer
SlotRange
TxSkelOpts
TxSkelWithdrawals
TxSkelMints
txSkelLabel :: TxSkel -> Set TxSkelLabel
txSkelOpts :: TxSkel -> TxSkelOpts
txSkelMints :: TxSkel -> TxSkelMints
txSkelSignatories :: TxSkel -> [TxSkelSignatory]
txSkelValidityRange :: TxSkel -> SlotRange
txSkelIns :: TxSkel -> Map TxOutRef TxSkelRedeemer
txSkelInsReference :: TxSkel -> Set TxOutRef
txSkelOuts :: TxSkel -> [TxSkelOut]
txSkelProposals :: TxSkel -> [TxSkelProposal]
txSkelWithdrawals :: TxSkel -> TxSkelWithdrawals
txSkelCertificates :: TxSkel -> [TxSkelCertificate]
txSkelLabel :: Set TxSkelLabel
txSkelOpts :: TxSkelOpts
txSkelMints :: TxSkelMints
txSkelSignatories :: [TxSkelSignatory]
txSkelValidityRange :: SlotRange
txSkelIns :: Map TxOutRef TxSkelRedeemer
txSkelInsReference :: Set TxOutRef
txSkelOuts :: [TxSkelOut]
txSkelProposals :: [TxSkelProposal]
txSkelWithdrawals :: TxSkelWithdrawals
txSkelCertificates :: [TxSkelCertificate]
..} = TxSkel -> Set TxOutRef
txSkelInsReferenceInRedeemers TxSkel
skel Set TxOutRef -> Set TxOutRef -> Set TxOutRef
forall a. Semigroup a => a -> a -> a
<> Map TxOutRef TxSkelRedeemer -> Set TxOutRef
forall k a. Map k a -> Set k
Map.keysSet Map TxOutRef TxSkelRedeemer
txSkelIns Set TxOutRef -> Set TxOutRef -> Set TxOutRef
forall a. Semigroup a => a -> a -> a
<> Set TxOutRef
txSkelInsReference

-- | Returns the total value withdrawn in this 'TxSkel'
txSkelWithdrawnValue :: TxSkel -> Api.Value
txSkelWithdrawnValue :: TxSkel -> Value
txSkelWithdrawnValue = TxSkelWithdrawals -> Value
forall a. ToValue a => a -> Value
Script.toValue (TxSkelWithdrawals -> Value)
-> (TxSkel -> TxSkelWithdrawals) -> TxSkel -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxSkel -> TxSkelWithdrawals
txSkelWithdrawals

-- | Returns all the scripts involved in withdrawals in this 'TxSkel'
txSkelWithdrawingScripts :: TxSkel -> [VScript]
txSkelWithdrawingScripts :: TxSkel -> [VScript]
txSkelWithdrawingScripts = Optic' A_Traversal '[] TxSkel VScript -> TxSkel -> [VScript]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Lens' TxSkel TxSkelWithdrawals
txSkelWithdrawalsL Lens' TxSkel TxSkelWithdrawals
-> Iso' TxSkelWithdrawals [Withdrawal]
-> Optic A_Lens '[] TxSkel TxSkel [Withdrawal] [Withdrawal]
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Iso' TxSkelWithdrawals [Withdrawal]
txSkelWithdrawalsListI Optic A_Lens '[] TxSkel TxSkel [Withdrawal] [Withdrawal]
-> Optic
     A_Traversal '[] [Withdrawal] [Withdrawal] Withdrawal Withdrawal
-> Optic A_Traversal '[] TxSkel TxSkel Withdrawal Withdrawal
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Traversal '[] [Withdrawal] [Withdrawal] Withdrawal Withdrawal
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic A_Traversal '[] TxSkel TxSkel Withdrawal Withdrawal
-> Optic
     A_Lens
     '[]
     Withdrawal
     Withdrawal
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
-> Optic
     A_Traversal
     '[]
     TxSkel
     TxSkel
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  Withdrawal
  Withdrawal
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
withdrawalUserL Optic
  A_Traversal
  '[]
  TxSkel
  TxSkel
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
-> Optic
     An_AffineTraversal
     '[]
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
     VScript
     VScript
-> Optic' A_Traversal '[] TxSkel VScript
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
  VScript
  VScript
forall (kind :: UserKind) (mode :: UserMode).
AffineTraversal' (User kind mode) VScript
userVScriptAT)

-- | Returns all the scripts involved in proposals in this 'TxSkel'
txSkelProposingScripts :: TxSkel -> [VScript]
txSkelProposingScripts :: TxSkel -> [VScript]
txSkelProposingScripts = Optic' A_Traversal '[] TxSkel VScript -> TxSkel -> [VScript]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Lens' TxSkel [TxSkelProposal]
txSkelProposalsL Lens' TxSkel [TxSkelProposal]
-> Traversal
     [TxSkelProposal] [TxSkelProposal] TxSkelProposal TxSkelProposal
-> Optic
     A_Traversal '[] TxSkel TxSkel TxSkelProposal TxSkelProposal
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Traversal
  [TxSkelProposal] [TxSkelProposal] TxSkelProposal TxSkelProposal
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic A_Traversal '[] TxSkel TxSkel TxSkelProposal TxSkelProposal
-> Optic
     An_AffineTraversal
     '[]
     TxSkelProposal
     TxSkelProposal
     (Maybe (User 'IsScript 'Redemption))
     (Maybe (User 'IsScript 'Redemption))
-> Optic
     A_Traversal
     '[]
     TxSkel
     TxSkel
     (Maybe (User 'IsScript 'Redemption))
     (Maybe (User 'IsScript 'Redemption))
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  TxSkelProposal
  TxSkelProposal
  (Maybe (User 'IsScript 'Redemption))
  (Maybe (User 'IsScript 'Redemption))
forall (kind :: UserKind).
Typeable kind =>
AffineTraversal' TxSkelProposal (Maybe (User kind 'Redemption))
txSkelProposalMConstitutionAT Optic
  A_Traversal
  '[]
  TxSkel
  TxSkel
  (Maybe (User 'IsScript 'Redemption))
  (Maybe (User 'IsScript 'Redemption))
-> Optic
     A_Prism
     '[]
     (Maybe (User 'IsScript 'Redemption))
     (Maybe (User 'IsScript 'Redemption))
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
-> Optic
     A_Traversal
     '[]
     TxSkel
     TxSkel
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Prism
  '[]
  (Maybe (User 'IsScript 'Redemption))
  (Maybe (User 'IsScript 'Redemption))
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
forall a b. Prism (Maybe a) (Maybe b) a b
_Just Optic
  A_Traversal
  '[]
  TxSkel
  TxSkel
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
-> Optic
     A_Lens
     '[]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
     VScript
     VScript
-> Optic' A_Traversal '[] TxSkel VScript
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
  VScript
  VScript
forall (mode :: UserMode). Lens' (User 'IsScript mode) VScript
userVScriptL)

-- | Returns all the scripts involved in minting in this 'TxSkel'
txSkelMintingScripts :: TxSkel -> [VScript]
txSkelMintingScripts :: TxSkel -> [VScript]
txSkelMintingScripts = Optic' A_Traversal '[] TxSkel VScript -> TxSkel -> [VScript]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Lens' TxSkel TxSkelMints
txSkelMintsL Lens' TxSkel TxSkelMints
-> Iso' TxSkelMints [Mint]
-> Optic A_Lens '[] TxSkel TxSkel [Mint] [Mint]
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Iso' TxSkelMints [Mint]
txSkelMintsListI Optic A_Lens '[] TxSkel TxSkel [Mint] [Mint]
-> Optic A_Traversal '[] [Mint] [Mint] Mint Mint
-> Optic A_Traversal '[] TxSkel TxSkel Mint Mint
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Traversal '[] [Mint] [Mint] Mint Mint
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic A_Traversal '[] TxSkel TxSkel Mint Mint
-> Optic
     A_Lens
     '[]
     Mint
     Mint
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
-> Optic
     A_Traversal
     '[]
     TxSkel
     TxSkel
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  Mint
  Mint
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
mintRedeemedScriptL Optic
  A_Traversal
  '[]
  TxSkel
  TxSkel
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
-> Optic
     A_Lens
     '[]
     (User 'IsScript 'Redemption)
     (User 'IsScript 'Redemption)
     VScript
     VScript
-> Optic' A_Traversal '[] TxSkel VScript
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  '[]
  (User 'IsScript 'Redemption)
  (User 'IsScript 'Redemption)
  VScript
  VScript
forall (mode :: UserMode). Lens' (User 'IsScript mode) VScript
userVScriptL)

-- | Returns all the scripts involved in certificates in this 'TxSkel'
txSkelCertifyingScripts :: TxSkel -> [VScript]
txSkelCertifyingScripts :: TxSkel -> [VScript]
txSkelCertifyingScripts = Optic' A_Traversal '[] TxSkel VScript -> TxSkel -> [VScript]
forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf (Lens' TxSkel [TxSkelCertificate]
txSkelCertificatesL Lens' TxSkel [TxSkelCertificate]
-> Traversal
     [TxSkelCertificate]
     [TxSkelCertificate]
     TxSkelCertificate
     TxSkelCertificate
-> Optic
     A_Traversal '[] TxSkel TxSkel TxSkelCertificate TxSkelCertificate
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Traversal
  [TxSkelCertificate]
  [TxSkelCertificate]
  TxSkelCertificate
  TxSkelCertificate
forall (t :: * -> *) a b.
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic
  A_Traversal '[] TxSkel TxSkel TxSkelCertificate TxSkelCertificate
-> Optic
     An_AffineTraversal
     '[]
     TxSkelCertificate
     TxSkelCertificate
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
-> Optic
     A_Traversal
     '[]
     TxSkel
     TxSkel
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (user :: UserKind).
Typeable user =>
AffineTraversal' TxSkelCertificate (User user 'Redemption)
txSkelCertificateOwnerAT @IsEither Optic
  A_Traversal
  '[]
  TxSkel
  TxSkel
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
-> Optic
     An_AffineTraversal
     '[]
     (User 'IsEither 'Redemption)
     (User 'IsEither 'Redemption)
     VScript
     VScript
-> Optic' A_Traversal '[] TxSkel VScript
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  An_AffineTraversal
  '[]
  (User 'IsEither 'Redemption)
  (User 'IsEither 'Redemption)
  VScript
  VScript
forall (kind :: UserKind) (mode :: UserMode).
AffineTraversal' (User kind mode) VScript
userVScriptAT)