-- | This modules provides a variety of options associated with a
-- 'Cooked.Skeleton.TxSkel'. These options mostly revolves around customizing
-- the default behavior of cooked-validators's transaction generation mechanism.
module Cooked.Skeleton.Option
  ( -- * Data types
    UserConstraints,
    BalanceOutputPolicy (..),
    FeePolicy (..),
    BalancingPolicy (..),
    BalancingUtxos (..),
    CollateralUtxos (..),
    TxSkelOpts (..),

    -- * Optics
    txSkelOptModTxL,
    txSkelOptAutoSlotIncreaseL,
    txSkelOptBalancingPolicyL,
    txSkelOptBalanceOutputPolicyL,
    txSkelOptFeePolicyL,
    txSkelOptBalancingUtxosL,
    txSkelOptModParamsL,
    txSkelOptCollateralUtxosL,
    txSkelOptDeferPhase2FailuresDuringBalancingL,
    txSkelOptMaxNbOfBalancingUtxosL,

    -- * Utilities
    txSkelOptAddModTx,
    txSkelOptAddModParams,
  )
where

import Cardano.Api qualified as Cardano
import Cardano.Node.Emulator qualified as Emulator
import Data.Default
import Data.Set (Set)
import Data.Typeable
import Optics.Core
import Optics.TH
import Plutus.Script.Utils.Address qualified as Script
import PlutusLedgerApi.V3 qualified as Api

-- | Set of constraints that need to be satisfied by users in options
type UserConstraints pkh = (Script.ToPubKeyHash pkh, Show pkh, Eq pkh, Typeable pkh)

-- | What fee policy to use in the transaction.
data FeePolicy
  = -- | Use automatic fee computation. If balancing is activated, an optimal
    -- fee will be computed based on the transaction and existing utxos in the
    -- balancing user. Otherwise, the maximum transaction fee will be applied.
    AutoFeeComputation
  | -- | Provide a fee to the transaction. If the autobalancing is activated, it
    -- will be attempted around this fee, which might lead to failure if it is
    -- too low, otherwise, this fee will be given to transaction generation.
    ManualFee Integer
  deriving (FeePolicy -> FeePolicy -> Bool
(FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool) -> Eq FeePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FeePolicy -> FeePolicy -> Bool
== :: FeePolicy -> FeePolicy -> Bool
$c/= :: FeePolicy -> FeePolicy -> Bool
/= :: FeePolicy -> FeePolicy -> Bool
Eq, Eq FeePolicy
Eq FeePolicy =>
(FeePolicy -> FeePolicy -> Ordering)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> FeePolicy)
-> (FeePolicy -> FeePolicy -> FeePolicy)
-> Ord FeePolicy
FeePolicy -> FeePolicy -> Bool
FeePolicy -> FeePolicy -> Ordering
FeePolicy -> FeePolicy -> FeePolicy
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
$ccompare :: FeePolicy -> FeePolicy -> Ordering
compare :: FeePolicy -> FeePolicy -> Ordering
$c< :: FeePolicy -> FeePolicy -> Bool
< :: FeePolicy -> FeePolicy -> Bool
$c<= :: FeePolicy -> FeePolicy -> Bool
<= :: FeePolicy -> FeePolicy -> Bool
$c> :: FeePolicy -> FeePolicy -> Bool
> :: FeePolicy -> FeePolicy -> Bool
$c>= :: FeePolicy -> FeePolicy -> Bool
>= :: FeePolicy -> FeePolicy -> Bool
$cmax :: FeePolicy -> FeePolicy -> FeePolicy
max :: FeePolicy -> FeePolicy -> FeePolicy
$cmin :: FeePolicy -> FeePolicy -> FeePolicy
min :: FeePolicy -> FeePolicy -> FeePolicy
Ord, Int -> FeePolicy -> ShowS
[FeePolicy] -> ShowS
FeePolicy -> String
(Int -> FeePolicy -> ShowS)
-> (FeePolicy -> String)
-> ([FeePolicy] -> ShowS)
-> Show FeePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FeePolicy -> ShowS
showsPrec :: Int -> FeePolicy -> ShowS
$cshow :: FeePolicy -> String
show :: FeePolicy -> String
$cshowList :: [FeePolicy] -> ShowS
showList :: [FeePolicy] -> ShowS
Show)

instance Default FeePolicy where
  def :: FeePolicy
def = FeePolicy
AutoFeeComputation

-- | Whether to adjust a potentially existing output to the balancing user
-- with the change during transaction balancing.
data BalanceOutputPolicy
  = -- | Try to adjust an existing public key output with the change. If no
    -- suitable output can be found, create a new change output.
    AdjustExistingOutput
  | -- | Do not change the existing outputs, always create a new change output.
    DontAdjustExistingOutput
  deriving (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
(BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> Eq BalanceOutputPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
== :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c/= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
/= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
Eq, Eq BalanceOutputPolicy
Eq BalanceOutputPolicy =>
(BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy
    -> BalanceOutputPolicy -> BalanceOutputPolicy)
-> (BalanceOutputPolicy
    -> BalanceOutputPolicy -> BalanceOutputPolicy)
-> Ord BalanceOutputPolicy
BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering
BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
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
$ccompare :: BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering
compare :: BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering
$c< :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
< :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c<= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
<= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c> :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
> :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c>= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
>= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$cmax :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
max :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
$cmin :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
min :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
Ord, Int -> BalanceOutputPolicy -> ShowS
[BalanceOutputPolicy] -> ShowS
BalanceOutputPolicy -> String
(Int -> BalanceOutputPolicy -> ShowS)
-> (BalanceOutputPolicy -> String)
-> ([BalanceOutputPolicy] -> ShowS)
-> Show BalanceOutputPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BalanceOutputPolicy -> ShowS
showsPrec :: Int -> BalanceOutputPolicy -> ShowS
$cshow :: BalanceOutputPolicy -> String
show :: BalanceOutputPolicy -> String
$cshowList :: [BalanceOutputPolicy] -> ShowS
showList :: [BalanceOutputPolicy] -> ShowS
Show)

instance Default BalanceOutputPolicy where
  def :: BalanceOutputPolicy
def = BalanceOutputPolicy
AdjustExistingOutput

-- | Which UTxOs to use when balancing. Note that utxos that are already known
-- by the skeleton being balanced (in the sense of
-- `Cooked.Skeleton.txSkelKnownTxOutRefs`, i.e. inputs and reference inputs)
-- will be filtered out during balancing.
data BalancingUtxos
  = -- | Use all UTxOs containing only a Value (no datum, no staking credential,
    -- and no reference script) belonging to the balancing user.
    BalancingUtxosFromBalancingUser
  | -- | Use the provided UTxOs. UTxOs belonging to scripts will be filtered out.
    BalancingUtxosFromSet (Set Api.TxOutRef)
  deriving (BalancingUtxos -> BalancingUtxos -> Bool
(BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool) -> Eq BalancingUtxos
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BalancingUtxos -> BalancingUtxos -> Bool
== :: BalancingUtxos -> BalancingUtxos -> Bool
$c/= :: BalancingUtxos -> BalancingUtxos -> Bool
/= :: BalancingUtxos -> BalancingUtxos -> Bool
Eq, Eq BalancingUtxos
Eq BalancingUtxos =>
(BalancingUtxos -> BalancingUtxos -> Ordering)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> BalancingUtxos)
-> (BalancingUtxos -> BalancingUtxos -> BalancingUtxos)
-> Ord BalancingUtxos
BalancingUtxos -> BalancingUtxos -> Bool
BalancingUtxos -> BalancingUtxos -> Ordering
BalancingUtxos -> BalancingUtxos -> BalancingUtxos
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
$ccompare :: BalancingUtxos -> BalancingUtxos -> Ordering
compare :: BalancingUtxos -> BalancingUtxos -> Ordering
$c< :: BalancingUtxos -> BalancingUtxos -> Bool
< :: BalancingUtxos -> BalancingUtxos -> Bool
$c<= :: BalancingUtxos -> BalancingUtxos -> Bool
<= :: BalancingUtxos -> BalancingUtxos -> Bool
$c> :: BalancingUtxos -> BalancingUtxos -> Bool
> :: BalancingUtxos -> BalancingUtxos -> Bool
$c>= :: BalancingUtxos -> BalancingUtxos -> Bool
>= :: BalancingUtxos -> BalancingUtxos -> Bool
$cmax :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
max :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
$cmin :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
min :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
Ord, Int -> BalancingUtxos -> ShowS
[BalancingUtxos] -> ShowS
BalancingUtxos -> String
(Int -> BalancingUtxos -> ShowS)
-> (BalancingUtxos -> String)
-> ([BalancingUtxos] -> ShowS)
-> Show BalancingUtxos
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BalancingUtxos -> ShowS
showsPrec :: Int -> BalancingUtxos -> ShowS
$cshow :: BalancingUtxos -> String
show :: BalancingUtxos -> String
$cshowList :: [BalancingUtxos] -> ShowS
showList :: [BalancingUtxos] -> ShowS
Show)

instance Default BalancingUtxos where
  def :: BalancingUtxos
def = BalancingUtxos
BalancingUtxosFromBalancingUser

-- | Whether to balance the transaction or not, and which user to use to
-- provide outputs for balancing.
data BalancingPolicy where
  -- | Balance with the first signatory of the list of signatories
  BalanceWithFirstSignatory :: BalancingPolicy
  -- | Balance using a given user
  BalanceWith :: (UserConstraints pkh) => pkh -> BalancingPolicy
  -- | Do not perform balancing at all
  DoNotBalance :: BalancingPolicy

instance Eq BalancingPolicy where
  BalancingPolicy
DoNotBalance == :: BalancingPolicy -> BalancingPolicy -> Bool
== BalancingPolicy
DoNotBalance = Bool
True
  BalancingPolicy
BalanceWithFirstSignatory == BalancingPolicy
BalanceWithFirstSignatory = Bool
True
  BalanceWith pkh
pkh == BalanceWith pkh
pkh1 = pkh -> PubKeyHash
forall a. ToPubKeyHash a => a -> PubKeyHash
Script.toPubKeyHash pkh
pkh PubKeyHash -> PubKeyHash -> Bool
forall a. Eq a => a -> a -> Bool
== pkh -> PubKeyHash
forall a. ToPubKeyHash a => a -> PubKeyHash
Script.toPubKeyHash pkh
pkh1
  BalancingPolicy
_ == BalancingPolicy
_ = Bool
False

deriving instance Show BalancingPolicy

instance Default BalancingPolicy where
  def :: BalancingPolicy
def = BalancingPolicy
BalanceWithFirstSignatory

-- | Describe which UTxOs to use as collaterals
data CollateralUtxos where
  -- | Rely on automated computation with only-value UTxOs from the balancing
  -- user. Return collaterals will be sent to this user.
  CollateralUtxosFromBalancingUser :: CollateralUtxos
  -- | Rely on automated computation with only-value UTxOs from a given
  -- user. Return collaterals will be sent to this user.
  CollateralUtxosFromUser :: (UserConstraints pkh) => pkh -> CollateralUtxos
  -- | Manually provide a set of candidate UTxOs to be used as collaterals
  -- alongside a user to send return collaterals back to.
  CollateralUtxosFromSet :: (UserConstraints pkh) => Set Api.TxOutRef -> pkh -> CollateralUtxos

instance Eq CollateralUtxos where
  CollateralUtxosFromSet Set TxOutRef
set0 pkh
pkh == :: CollateralUtxos -> CollateralUtxos -> Bool
== CollateralUtxosFromSet Set TxOutRef
set1 pkh
pkh1 =
    pkh -> PubKeyHash
forall a. ToPubKeyHash a => a -> PubKeyHash
Script.toPubKeyHash pkh
pkh PubKeyHash -> PubKeyHash -> Bool
forall a. Eq a => a -> a -> Bool
== pkh -> PubKeyHash
forall a. ToPubKeyHash a => a -> PubKeyHash
Script.toPubKeyHash pkh
pkh1 Bool -> Bool -> Bool
&& Set TxOutRef
set0 Set TxOutRef -> Set TxOutRef -> Bool
forall a. Eq a => a -> a -> Bool
== Set TxOutRef
set1
  CollateralUtxosFromUser pkh
pkh == CollateralUtxosFromUser pkh
pkh1 = pkh -> PubKeyHash
forall a. ToPubKeyHash a => a -> PubKeyHash
Script.toPubKeyHash pkh
pkh PubKeyHash -> PubKeyHash -> Bool
forall a. Eq a => a -> a -> Bool
== pkh -> PubKeyHash
forall a. ToPubKeyHash a => a -> PubKeyHash
Script.toPubKeyHash pkh
pkh1
  CollateralUtxos
CollateralUtxosFromBalancingUser == CollateralUtxos
CollateralUtxosFromBalancingUser = Bool
True
  CollateralUtxos
_ == CollateralUtxos
_ = Bool
False

deriving instance Show CollateralUtxos

instance Default CollateralUtxos where
  def :: CollateralUtxos
def = CollateralUtxos
CollateralUtxosFromBalancingUser

-- | Set of options to modify the behavior of generating and validating some
-- transaction.
data TxSkelOpts = TxSkelOpts
  { -- | Whether to increase the slot counter automatically on transaction
    -- submission.  This is useful for modelling transactions that could be
    -- submitted in parallel in reality, so there should be no explicit ordering
    -- of what comes first.
    --
    -- Default is @True@.
    TxSkelOpts -> Bool
txSkelOptAutoSlotIncrease :: Bool,
    -- | Applies an arbitrary modification to a transaction after it has been
    -- potentially adjusted and balanced. The name of this option contains
    -- /unsafe/ to draw attention to the fact that modifying a transaction at
    -- that stage might make it invalid. Still, this offers a hook for being
    -- able to alter a transaction in unforeseen ways. It is mostly used to test
    -- contracts that have been written for custom PABs.
    --
    -- One interesting use of this function is to observe a transaction just
    -- before it is being sent for validation, with
    --
    -- > txSkelOptModTx = [RawModTx Debug.Trace.traceShowId]
    --
    -- The leftmost function in the list is applied first.
    --
    -- Default is @[]@.
    TxSkelOpts -> Tx ConwayEra -> Tx ConwayEra
txSkelOptModTx :: Cardano.Tx Cardano.ConwayEra -> Cardano.Tx Cardano.ConwayEra,
    -- | Whether to balance the transaction or not, and which user should
    -- provide/reclaim the missing and surplus value.
    --
    -- If you decide to set @txSkelOptBalance = DoNotBalance@ you will have trouble
    -- satisfying the balancing equation by hand unless you use @ManualFee@.
    --
    -- Default is 'BalanceWithFirstSignatory'
    TxSkelOpts -> BalancingPolicy
txSkelOptBalancingPolicy :: BalancingPolicy,
    -- | The fee to use when balancing the transaction
    --
    -- Default is 'AutoFeeComputation'
    TxSkelOpts -> FeePolicy
txSkelOptFeePolicy :: FeePolicy,
    -- | The 'BalanceOutputPolicy' to apply when balancing the transaction.
    --
    -- Default is 'AdjustExistingOutput'.
    TxSkelOpts -> BalanceOutputPolicy
txSkelOptBalanceOutputPolicy :: BalanceOutputPolicy,
    -- | Which UTxOs to use during balancing. This can either be a precise list,
    -- or rely on automatic searches for utxos with values only belonging to the
    -- balancing user.
    --
    -- Default is 'BalancingUtxosFromBalancingUser'.
    TxSkelOpts -> BalancingUtxos
txSkelOptBalancingUtxos :: BalancingUtxos,
    -- | Apply an arbitrary modification to the protocol parameters that are
    -- used to balance and submit the transaction. This is obviously a very
    -- unsafe thing to do if you want to preserve compatibility with the actual
    -- chain. It is useful mainly for testing purposes, when you might want to
    -- use extremely big transactions or transactions that exhaust the maximum
    -- execution budget. Such a thing could be accomplished with
    --
    -- > txSkelOptModParams = Just $ ModParams increaseTransactionLimits
    --
    -- for example.
    --
    -- Default is 'Nothing'.
    TxSkelOpts -> Params -> Params
txSkelOptModParams :: Emulator.Params -> Emulator.Params,
    -- | Which utxos to use as collaterals. They can be given manually, or
    -- computed automatically from a given, or the balancing, user.
    --
    -- Default is 'CollateralUtxosFromBalancingUser'
    TxSkelOpts -> CollateralUtxos
txSkelOptCollateralUtxos :: CollateralUtxos,
    -- | Whether to defer validation failures occurring during balancing
    -- (specifically during the computation of execution units) to the actual
    -- later submission of the transaction.
    --
    -- When set to @False@: the phase 2 validation failures will be caught as
    -- early as possible, typically during balancing when the execution units
    -- are computed. This will shortcut the whole balancing process which
    -- iterates the body generation, and thus increase performances (by 40%). As
    -- a result, the balanced `Cooked.Skeleton.TxSkel` will never be computed
    -- and thus will be absent from the log, which is the only downside.
    --
    -- When set to @True@: the phase 2 validation erros will be ignored during
    -- the balancing process. This will result in a worst performance (40%), but
    -- will allow the log to display a balanced version of the failing
    -- `Cooked.Skeleton.TxSkel`, which might be useful. Only use this when
    -- debugging complicated phase 2 failures which require a precise view of
    -- the balanced `Cooked.Skeleton.TxSkel` sent for validation.
    --
    -- Default is `False`
    TxSkelOpts -> Bool
txSkelOptDeferPhase2FailuresDuringBalancing :: Bool,
    -- | The optional maximum number of Utxos that can be used during
    -- balancing. The algorithm which selects Utxos when permorming balancing is
    -- greedy. In the default use case where the are only a few wallets and
    -- Utxos (the most common case for testing purpose), this is fine. However,
    -- if the amount of candidate Utxos is big (let's say, bigger than 15), this
    -- is problematic. Use this option to limit the number of Utxos that can be
    -- used during the balancing process.
    --
    -- Alternatively, this can also be used to pilot balancing in some way. For
    -- instance, setting this option to @Just 1@ will result in a single Utxo
    -- added in the inputs of the transaction, if such a Utxo exist.
    --
    -- Default is @Nothing@
    TxSkelOpts -> Maybe Integer
txSkelOptMaxNbOfBalancingUtxos :: Maybe Integer
  }

-- | Comparing 'TxSkelOpts' is possible as long as we ignore modifications to the
-- generated transaction and the parameters.
instance Eq TxSkelOpts where
  (TxSkelOpts Bool
slotIncrease Tx ConwayEra -> Tx ConwayEra
_ BalancingPolicy
balancingPol FeePolicy
feePol BalanceOutputPolicy
balOutputPol BalancingUtxos
balUtxos Params -> Params
_ CollateralUtxos
colUtxos Bool
deferFailures Maybe Integer
maxNbBalUtxos)
    == :: TxSkelOpts -> TxSkelOpts -> Bool
== (TxSkelOpts Bool
slotIncrease' Tx ConwayEra -> Tx ConwayEra
_ BalancingPolicy
balancingPol' FeePolicy
feePol' BalanceOutputPolicy
balOutputPol' BalancingUtxos
balUtxos' Params -> Params
_ CollateralUtxos
colUtxos' Bool
deferFailures' Maybe Integer
maxNbBalUtxos') =
      Bool
slotIncrease Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
slotIncrease'
        Bool -> Bool -> Bool
&& BalancingPolicy
balancingPol BalancingPolicy -> BalancingPolicy -> Bool
forall a. Eq a => a -> a -> Bool
== BalancingPolicy
balancingPol'
        Bool -> Bool -> Bool
&& FeePolicy
feePol FeePolicy -> FeePolicy -> Bool
forall a. Eq a => a -> a -> Bool
== FeePolicy
feePol'
        Bool -> Bool -> Bool
&& BalanceOutputPolicy
balOutputPol BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
forall a. Eq a => a -> a -> Bool
== BalanceOutputPolicy
balOutputPol'
        Bool -> Bool -> Bool
&& BalancingUtxos
balUtxos BalancingUtxos -> BalancingUtxos -> Bool
forall a. Eq a => a -> a -> Bool
== BalancingUtxos
balUtxos'
        Bool -> Bool -> Bool
&& CollateralUtxos
colUtxos CollateralUtxos -> CollateralUtxos -> Bool
forall a. Eq a => a -> a -> Bool
== CollateralUtxos
colUtxos'
        Bool -> Bool -> Bool
&& Bool
deferFailures Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
deferFailures'
        Bool -> Bool -> Bool
&& Maybe Integer
maxNbBalUtxos Maybe Integer -> Maybe Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Integer
maxNbBalUtxos'

-- | Showing 'TxSkelOpts' is possible as long as we ignore modifications to the
-- generated transaction and the parameters.
instance Show TxSkelOpts where
  show :: TxSkelOpts -> String
show (TxSkelOpts Bool
slotIncrease Tx ConwayEra -> Tx ConwayEra
_ BalancingPolicy
balancingPol FeePolicy
feePol BalanceOutputPolicy
balOutputPol BalancingUtxos
balUtxos Params -> Params
_ CollateralUtxos
colUtxos Bool
deferFailures Maybe Integer
maxNbBalUtxos) =
    [String] -> String
forall a. Show a => a -> String
show [Bool -> String
forall a. Show a => a -> String
show Bool
slotIncrease, BalancingPolicy -> String
forall a. Show a => a -> String
show BalancingPolicy
balancingPol, FeePolicy -> String
forall a. Show a => a -> String
show FeePolicy
feePol, BalanceOutputPolicy -> String
forall a. Show a => a -> String
show BalanceOutputPolicy
balOutputPol, BalancingUtxos -> String
forall a. Show a => a -> String
show BalancingUtxos
balUtxos, CollateralUtxos -> String
forall a. Show a => a -> String
show CollateralUtxos
colUtxos, Bool -> String
forall a. Show a => a -> String
show Bool
deferFailures, Maybe Integer -> String
forall a. Show a => a -> String
show Maybe Integer
maxNbBalUtxos]

-- | A lens to get or set the automatic slot increase option
makeLensesFor [("txSkelOptAutoSlotIncrease", "txSkelOptAutoSlotIncreaseL")] ''TxSkelOpts

-- | A lens to get or set the Cardano transaction modifications option
makeLensesFor [("txSkelOptModTx", "txSkelOptModTxL")] ''TxSkelOpts

-- | A lens to get or set the balancing policy option
makeLensesFor [("txSkelOptBalancingPolicy", "txSkelOptBalancingPolicyL")] ''TxSkelOpts

-- | A lens to get or set the fee policy option
makeLensesFor [("txSkelOptFeePolicy", "txSkelOptFeePolicyL")] ''TxSkelOpts

-- | A lens to get or set the handling of balancing outputs option
makeLensesFor [("txSkelOptBalanceOutputPolicy", "txSkelOptBalanceOutputPolicyL")] ''TxSkelOpts

-- | A lens to get or set the balancing utxos option
makeLensesFor [("txSkelOptBalancingUtxos", "txSkelOptBalancingUtxosL")] ''TxSkelOpts

-- | A lens to get or set the changes to protocol parameters option
makeLensesFor [("txSkelOptModParams", "txSkelOptModParamsL")] ''TxSkelOpts

-- | A lens to get or set the collateral utxos option
makeLensesFor [("txSkelOptCollateralUtxos", "txSkelOptCollateralUtxosL")] ''TxSkelOpts

-- | A lens to get or set the deferring of the failures option
makeLensesFor [("txSkelOptDeferPhase2FailuresDuringBalancing", "txSkelOptDeferPhase2FailuresDuringBalancingL")] ''TxSkelOpts

-- | A lens to get or set the max nb of balancing Utxos option
makeLensesFor [("txSkelOptMaxNbOfBalancingUtxos", "txSkelOptMaxNbOfBalancingUtxosL")] ''TxSkelOpts

instance Default TxSkelOpts where
  def :: TxSkelOpts
def =
    TxSkelOpts
      { txSkelOptAutoSlotIncrease :: Bool
txSkelOptAutoSlotIncrease = Bool
True,
        txSkelOptModTx :: Tx ConwayEra -> Tx ConwayEra
txSkelOptModTx = Tx ConwayEra -> Tx ConwayEra
forall a. a -> a
id,
        txSkelOptBalancingPolicy :: BalancingPolicy
txSkelOptBalancingPolicy = BalancingPolicy
forall a. Default a => a
def,
        txSkelOptBalanceOutputPolicy :: BalanceOutputPolicy
txSkelOptBalanceOutputPolicy = BalanceOutputPolicy
forall a. Default a => a
def,
        txSkelOptFeePolicy :: FeePolicy
txSkelOptFeePolicy = FeePolicy
forall a. Default a => a
def,
        txSkelOptBalancingUtxos :: BalancingUtxos
txSkelOptBalancingUtxos = BalancingUtxos
forall a. Default a => a
def,
        txSkelOptModParams :: Params -> Params
txSkelOptModParams = Params -> Params
forall a. a -> a
id,
        txSkelOptCollateralUtxos :: CollateralUtxos
txSkelOptCollateralUtxos = CollateralUtxos
forall a. Default a => a
def,
        txSkelOptDeferPhase2FailuresDuringBalancing :: Bool
txSkelOptDeferPhase2FailuresDuringBalancing = Bool
False,
        txSkelOptMaxNbOfBalancingUtxos :: Maybe Integer
txSkelOptMaxNbOfBalancingUtxos = Maybe Integer
forall a. Maybe a
Nothing
      }

-- | Appends a transaction modification to the given 'TxSkelOpts'
txSkelOptAddModTx :: (Cardano.Tx Cardano.ConwayEra -> Cardano.Tx Cardano.ConwayEra) -> TxSkelOpts -> TxSkelOpts
txSkelOptAddModTx :: (Tx ConwayEra -> Tx ConwayEra) -> TxSkelOpts -> TxSkelOpts
txSkelOptAddModTx Tx ConwayEra -> Tx ConwayEra
modTx = Lens' TxSkelOpts (Tx ConwayEra -> Tx ConwayEra)
-> ((Tx ConwayEra -> Tx ConwayEra) -> Tx ConwayEra -> Tx ConwayEra)
-> TxSkelOpts
-> TxSkelOpts
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Lens' TxSkelOpts (Tx ConwayEra -> Tx ConwayEra)
txSkelOptModTxL (Tx ConwayEra -> Tx ConwayEra
modTx (Tx ConwayEra -> Tx ConwayEra)
-> (Tx ConwayEra -> Tx ConwayEra) -> Tx ConwayEra -> Tx ConwayEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)

-- | Appends a parameters modification to the given 'TxSkelOpts'
txSkelOptAddModParams :: (Emulator.Params -> Emulator.Params) -> TxSkelOpts -> TxSkelOpts
txSkelOptAddModParams :: (Params -> Params) -> TxSkelOpts -> TxSkelOpts
txSkelOptAddModParams Params -> Params
modParams = Lens' TxSkelOpts (Params -> Params)
-> ((Params -> Params) -> Params -> Params)
-> TxSkelOpts
-> TxSkelOpts
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Lens' TxSkelOpts (Params -> Params)
txSkelOptModParamsL (Params -> Params
modParams (Params -> Params) -> (Params -> Params) -> Params -> Params
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)