module Cooked.Skeleton.Output
(
IsTxSkelOutAllowedOwner (..),
PayableKind (..),
Payable (..),
TxSkelOut (..),
txSkelOutValueL,
txSkelOutValueAutoAdjustL,
txSkelOutDatumL,
txSkelOutMReferenceScriptL,
txSkelOutReferenceScriptAT,
txSkelOutMStakingCredentialL,
txSkelOutStakingCredentialAT,
txSkelOutCredentialG,
txSkelOutAddressG,
txSkelOutReferenceScriptHashAF,
txSkelOutOwnerL,
(<&&>),
receives,
)
where
import Cooked.Skeleton.Datum
import Cooked.Skeleton.Families
import Cooked.Skeleton.User
import Cooked.Skeleton.Value ()
import Cooked.Wallet
import Data.Kind
import Data.Typeable
import Optics.Core
import Optics.TH (makeLensesFor)
import Plutus.Script.Utils.Address qualified as Script
import Plutus.Script.Utils.Scripts qualified as Script
import Plutus.Script.Utils.V1.Typed qualified as Script (TypedValidator (..))
import Plutus.Script.Utils.V3.Typed qualified as Script
import Plutus.Script.Utils.Value qualified as Script
import PlutusLedgerApi.V1.Value qualified as Api
import PlutusLedgerApi.V3 qualified as Api
data TxSkelOut where
TxSkelOut ::
{
TxSkelOut -> User 'IsEither 'Allocation
txSkelOutOwner :: User IsEither Allocation,
TxSkelOut -> Maybe StakingCredential
txSkelOutStakingCredential :: Maybe Api.StakingCredential,
TxSkelOut -> TxSkelOutDatum
txSkelOutDatum :: TxSkelOutDatum,
TxSkelOut -> Value
txSkelOutValue :: Api.Value,
TxSkelOut -> Bool
txSkelOutValueAutoAdjust :: Bool,
TxSkelOut -> Maybe VScript
txSkelOutReferenceScript :: Maybe VScript
} ->
TxSkelOut
deriving (TxSkelOut -> TxSkelOut -> Bool
(TxSkelOut -> TxSkelOut -> Bool)
-> (TxSkelOut -> TxSkelOut -> Bool) -> Eq TxSkelOut
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxSkelOut -> TxSkelOut -> Bool
== :: TxSkelOut -> TxSkelOut -> Bool
$c/= :: TxSkelOut -> TxSkelOut -> Bool
/= :: TxSkelOut -> TxSkelOut -> Bool
Eq, Eq TxSkelOut
Eq TxSkelOut =>
(TxSkelOut -> TxSkelOut -> Ordering)
-> (TxSkelOut -> TxSkelOut -> Bool)
-> (TxSkelOut -> TxSkelOut -> Bool)
-> (TxSkelOut -> TxSkelOut -> Bool)
-> (TxSkelOut -> TxSkelOut -> Bool)
-> (TxSkelOut -> TxSkelOut -> TxSkelOut)
-> (TxSkelOut -> TxSkelOut -> TxSkelOut)
-> Ord TxSkelOut
TxSkelOut -> TxSkelOut -> Bool
TxSkelOut -> TxSkelOut -> Ordering
TxSkelOut -> TxSkelOut -> TxSkelOut
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 :: TxSkelOut -> TxSkelOut -> Ordering
compare :: TxSkelOut -> TxSkelOut -> Ordering
$c< :: TxSkelOut -> TxSkelOut -> Bool
< :: TxSkelOut -> TxSkelOut -> Bool
$c<= :: TxSkelOut -> TxSkelOut -> Bool
<= :: TxSkelOut -> TxSkelOut -> Bool
$c> :: TxSkelOut -> TxSkelOut -> Bool
> :: TxSkelOut -> TxSkelOut -> Bool
$c>= :: TxSkelOut -> TxSkelOut -> Bool
>= :: TxSkelOut -> TxSkelOut -> Bool
$cmax :: TxSkelOut -> TxSkelOut -> TxSkelOut
max :: TxSkelOut -> TxSkelOut -> TxSkelOut
$cmin :: TxSkelOut -> TxSkelOut -> TxSkelOut
min :: TxSkelOut -> TxSkelOut -> TxSkelOut
Ord, Int -> TxSkelOut -> ShowS
[TxSkelOut] -> ShowS
TxSkelOut -> String
(Int -> TxSkelOut -> ShowS)
-> (TxSkelOut -> String)
-> ([TxSkelOut] -> ShowS)
-> Show TxSkelOut
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxSkelOut -> ShowS
showsPrec :: Int -> TxSkelOut -> ShowS
$cshow :: TxSkelOut -> String
show :: TxSkelOut -> String
$cshowList :: [TxSkelOut] -> ShowS
showList :: [TxSkelOut] -> ShowS
Show)
makeLensesFor [("txSkelOutReferenceScript", "txSkelOutMReferenceScriptL")] ''TxSkelOut
txSkelOutReferenceScriptAT :: AffineTraversal' TxSkelOut VScript
txSkelOutReferenceScriptAT :: AffineTraversal' TxSkelOut VScript
txSkelOutReferenceScriptAT = Lens' TxSkelOut (Maybe VScript)
txSkelOutMReferenceScriptL Lens' TxSkelOut (Maybe VScript)
-> Optic
A_Prism NoIx (Maybe VScript) (Maybe VScript) VScript VScript
-> AffineTraversal' TxSkelOut 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_Prism NoIx (Maybe VScript) (Maybe VScript) VScript VScript
forall a b. Prism (Maybe a) (Maybe b) a b
_Just
txSkelOutReferenceScriptHashAF :: AffineFold TxSkelOut Api.ScriptHash
txSkelOutReferenceScriptHashAF :: AffineFold TxSkelOut ScriptHash
txSkelOutReferenceScriptHashAF = AffineTraversal' TxSkelOut VScript
txSkelOutReferenceScriptAT AffineTraversal' TxSkelOut VScript
-> Optic A_Getter NoIx VScript VScript ScriptHash ScriptHash
-> AffineFold TxSkelOut ScriptHash
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
% (VScript -> ScriptHash)
-> Optic A_Getter NoIx VScript VScript ScriptHash ScriptHash
forall s a. (s -> a) -> Getter s a
to VScript -> ScriptHash
forall a. ToScriptHash a => a -> ScriptHash
Script.toScriptHash
makeLensesFor [("txSkelOutStakingCredential", "txSkelOutMStakingCredentialL")] ''TxSkelOut
txSkelOutStakingCredentialAT :: AffineTraversal' TxSkelOut Api.StakingCredential
txSkelOutStakingCredentialAT :: AffineTraversal' TxSkelOut StakingCredential
txSkelOutStakingCredentialAT = Lens' TxSkelOut (Maybe StakingCredential)
txSkelOutMStakingCredentialL Lens' TxSkelOut (Maybe StakingCredential)
-> Optic
A_Prism
NoIx
(Maybe StakingCredential)
(Maybe StakingCredential)
StakingCredential
StakingCredential
-> AffineTraversal' TxSkelOut StakingCredential
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
NoIx
(Maybe StakingCredential)
(Maybe StakingCredential)
StakingCredential
StakingCredential
forall a b. Prism (Maybe a) (Maybe b) a b
_Just
makeLensesFor [("txSkelOutDatum", "txSkelOutDatumL")] ''TxSkelOut
makeLensesFor [("txSkelOutValue", "txSkelOutValueL")] ''TxSkelOut
makeLensesFor [("txSkelOutValueAutoAdjust", "txSkelOutValueAutoAdjustL")] ''TxSkelOut
makeLensesFor [("txSkelOutOwner", "txSkelOutOwnerL")] ''TxSkelOut
txSkelOutCredentialG :: Getter TxSkelOut Api.Credential
txSkelOutCredentialG :: Getter TxSkelOut Credential
txSkelOutCredentialG = (TxSkelOut -> Credential) -> Getter TxSkelOut Credential
forall s a. (s -> a) -> Getter s a
to ((TxSkelOut -> Credential) -> Getter TxSkelOut Credential)
-> (TxSkelOut -> Credential) -> Getter TxSkelOut Credential
forall a b. (a -> b) -> a -> b
$ \(TxSkelOut {User 'IsEither 'Allocation
txSkelOutOwner :: TxSkelOut -> User 'IsEither 'Allocation
txSkelOutOwner :: User 'IsEither 'Allocation
txSkelOutOwner}) -> User 'IsEither 'Allocation -> Credential
forall a. ToCredential a => a -> Credential
Script.toCredential User 'IsEither 'Allocation
txSkelOutOwner
txSkelOutAddressG :: Getter TxSkelOut Api.Address
txSkelOutAddressG :: Getter TxSkelOut Address
txSkelOutAddressG = (TxSkelOut -> Address) -> Getter TxSkelOut Address
forall s a. (s -> a) -> Getter s a
to ((TxSkelOut -> Address) -> Getter TxSkelOut Address)
-> (TxSkelOut -> Address) -> Getter TxSkelOut Address
forall a b. (a -> b) -> a -> b
$ \TxSkelOut
txSkelOut ->
Credential -> Maybe StakingCredential -> Address
Api.Address
(Getter TxSkelOut Credential -> TxSkelOut -> Credential
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Getter TxSkelOut Credential
txSkelOutCredentialG TxSkelOut
txSkelOut)
(Lens' TxSkelOut (Maybe StakingCredential)
-> TxSkelOut -> Maybe StakingCredential
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Lens' TxSkelOut (Maybe StakingCredential)
txSkelOutMStakingCredentialL TxSkelOut
txSkelOut)
instance Script.ToCredential TxSkelOut where
toCredential :: TxSkelOut -> Credential
toCredential = Getter TxSkelOut Credential -> TxSkelOut -> Credential
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Getter TxSkelOut Credential
txSkelOutCredentialG
instance Script.ToAddress TxSkelOut where
toAddress :: TxSkelOut -> Address
toAddress = Getter TxSkelOut Address -> TxSkelOut -> Address
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
view Getter TxSkelOut Address
txSkelOutAddressG
class IsTxSkelOutAllowedOwner a where
toPKHOrVScript :: a -> User IsEither Allocation
instance IsTxSkelOutAllowedOwner Api.PubKeyHash where
toPKHOrVScript :: PubKeyHash -> User 'IsEither 'Allocation
toPKHOrVScript = PubKeyHash -> User 'IsEither 'Allocation
forall pkh (a :: UserKind) (b :: UserMode).
(a ∈ '[ 'IsPubKey, 'IsEither], ToPubKeyHash pkh, Typeable pkh) =>
pkh -> User a b
UserPubKey
instance IsTxSkelOutAllowedOwner (User 'IsPubKey 'Allocation) where
toPKHOrVScript :: User 'IsPubKey 'Allocation -> User 'IsEither 'Allocation
toPKHOrVScript (UserPubKey pkh
pkh) = pkh -> User 'IsEither 'Allocation
forall pkh (a :: UserKind) (b :: UserMode).
(a ∈ '[ 'IsPubKey, 'IsEither], ToPubKeyHash pkh, Typeable pkh) =>
pkh -> User a b
UserPubKey pkh
pkh
instance IsTxSkelOutAllowedOwner Wallet where
toPKHOrVScript :: Wallet -> User 'IsEither 'Allocation
toPKHOrVScript = Wallet -> User 'IsEither 'Allocation
forall pkh (a :: UserKind) (b :: UserMode).
(a ∈ '[ 'IsPubKey, 'IsEither], ToPubKeyHash pkh, Typeable pkh) =>
pkh -> User a b
UserPubKey
instance IsTxSkelOutAllowedOwner VScript where
toPKHOrVScript :: VScript -> User 'IsEither 'Allocation
toPKHOrVScript = VScript -> User 'IsEither 'Allocation
forall script (a :: UserKind).
(a ∈ '[ 'IsScript, 'IsEither], ToVScript script,
Typeable script) =>
script -> User a 'Allocation
UserScript
instance (Typeable a) => IsTxSkelOutAllowedOwner (Script.TypedValidator a) where
toPKHOrVScript :: TypedValidator a -> User 'IsEither 'Allocation
toPKHOrVScript = TypedValidator a -> User 'IsEither 'Allocation
forall script (a :: UserKind).
(a ∈ '[ 'IsScript, 'IsEither], ToVScript script,
Typeable script) =>
script -> User a 'Allocation
UserScript
instance IsTxSkelOutAllowedOwner (Script.Versioned Script.Validator) where
toPKHOrVScript :: Versioned Validator -> User 'IsEither 'Allocation
toPKHOrVScript = Versioned Validator -> User 'IsEither 'Allocation
forall script (a :: UserKind).
(a ∈ '[ 'IsScript, 'IsEither], ToVScript script,
Typeable script) =>
script -> User a 'Allocation
UserScript
instance (Typeable a) => IsTxSkelOutAllowedOwner (Script.MultiPurposeScript a) where
toPKHOrVScript :: MultiPurposeScript a -> User 'IsEither 'Allocation
toPKHOrVScript = MultiPurposeScript a -> User 'IsEither 'Allocation
forall script (a :: UserKind).
(a ∈ '[ 'IsScript, 'IsEither], ToVScript script,
Typeable script) =>
script -> User a 'Allocation
UserScript
instance IsTxSkelOutAllowedOwner (User IsEither Allocation) where
toPKHOrVScript :: User 'IsEither 'Allocation -> User 'IsEither 'Allocation
toPKHOrVScript = User 'IsEither 'Allocation -> User 'IsEither 'Allocation
forall a. a -> a
id
data PayableKind where
IsDatum :: PayableKind
IsReferenceScript :: PayableKind
IsValue :: PayableKind
IsStakingCredential :: PayableKind
data Payable :: [PayableKind] -> Type where
VisibleHashedDatum :: (DatumConstrs a) => a -> Payable '[IsDatum]
InlineDatum :: (DatumConstrs a) => a -> Payable '[IsDatum]
HiddenHashedDatum :: (DatumConstrs a) => a -> Payable '[IsDatum]
ReferenceScript :: (ToVScript s) => s -> Payable '[IsReferenceScript]
Value :: (Script.ToValue a) => a -> Payable '[IsValue]
FixedValue :: (Script.ToValue a) => a -> Payable '[IsValue]
StakingCredential :: (Script.ToMaybeStakingCredential cred) => cred -> Payable '[IsStakingCredential]
PayableAnd :: (els ⩀ els') => Payable els -> Payable els' -> Payable (els ∪ els')
(<&&>) :: (els ⩀ els') => Payable els -> Payable els' -> Payable (els ∪ els')
<&&> :: forall (els :: [PayableKind]) (els' :: [PayableKind]).
(els ⩀ els') =>
Payable els -> Payable els' -> Payable (els ∪ els')
(<&&>) = Payable els -> Payable els' -> Payable (els ∪ els')
forall (els :: [PayableKind]) (els' :: [PayableKind]).
(els ⩀ els') =>
Payable els -> Payable els' -> Payable (els ∪ els')
PayableAnd
infix 1 `receives`
receives :: (IsTxSkelOutAllowedOwner owner) => owner -> Payable els -> TxSkelOut
receives :: forall owner (els :: [PayableKind]).
IsTxSkelOutAllowedOwner owner =>
owner -> Payable els -> TxSkelOut
receives (owner -> User 'IsEither 'Allocation
forall a.
IsTxSkelOutAllowedOwner a =>
a -> User 'IsEither 'Allocation
toPKHOrVScript -> User 'IsEither 'Allocation
owner) =
( Payable els -> TxSkelOut -> TxSkelOut
forall (els :: [PayableKind]).
Payable els -> TxSkelOut -> TxSkelOut
`go`
User 'IsEither 'Allocation
-> Maybe StakingCredential
-> TxSkelOutDatum
-> Value
-> Bool
-> Maybe VScript
-> TxSkelOut
TxSkelOut
User 'IsEither 'Allocation
owner
Maybe StakingCredential
forall a. Maybe a
Nothing
TxSkelOutDatum
defaultTxSkelDatum
Value
forall a. Monoid a => a
mempty
Bool
True
Maybe VScript
forall a. Maybe a
Nothing
)
where
go :: Payable els -> TxSkelOut -> TxSkelOut
go :: forall (els :: [PayableKind]).
Payable els -> TxSkelOut -> TxSkelOut
go (VisibleHashedDatum a
dat) = Lens' TxSkelOut TxSkelOutDatum
-> TxSkelOutDatum -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut TxSkelOutDatum
txSkelOutDatumL (a -> DatumKind -> TxSkelOutDatum
forall dat. DatumConstrs dat => dat -> DatumKind -> TxSkelOutDatum
SomeTxSkelOutDatum a
dat (DatumResolved -> DatumKind
Hashed DatumResolved
Resolved))
go (InlineDatum a
dat) = Lens' TxSkelOut TxSkelOutDatum
-> TxSkelOutDatum -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut TxSkelOutDatum
txSkelOutDatumL (a -> DatumKind -> TxSkelOutDatum
forall dat. DatumConstrs dat => dat -> DatumKind -> TxSkelOutDatum
SomeTxSkelOutDatum a
dat DatumKind
Inline)
go (HiddenHashedDatum a
dat) = Lens' TxSkelOut TxSkelOutDatum
-> TxSkelOutDatum -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut TxSkelOutDatum
txSkelOutDatumL (a -> DatumKind -> TxSkelOutDatum
forall dat. DatumConstrs dat => dat -> DatumKind -> TxSkelOutDatum
SomeTxSkelOutDatum a
dat (DatumResolved -> DatumKind
Hashed DatumResolved
NotResolved))
go (FixedValue (a -> Value
forall a. ToValue a => a -> Value
Script.toValue -> Value
v)) = Lens' TxSkelOut Value -> Value -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut Value
txSkelOutValueL Value
v (TxSkelOut -> TxSkelOut)
-> (TxSkelOut -> TxSkelOut) -> TxSkelOut -> TxSkelOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' TxSkelOut Bool -> Bool -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut Bool
txSkelOutValueAutoAdjustL Bool
False
go (Value (a -> Value
forall a. ToValue a => a -> Value
Script.toValue -> Value
v)) = Lens' TxSkelOut Value -> Value -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut Value
txSkelOutValueL Value
v (TxSkelOut -> TxSkelOut)
-> (TxSkelOut -> TxSkelOut) -> TxSkelOut -> TxSkelOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' TxSkelOut Bool -> Bool -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut Bool
txSkelOutValueAutoAdjustL Bool
True
go (ReferenceScript (s -> VScript
forall script. ToVScript script => script -> VScript
toVScript -> VScript
vScript)) = Lens' TxSkelOut (Maybe VScript)
-> Maybe VScript -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut (Maybe VScript)
txSkelOutMReferenceScriptL (VScript -> Maybe VScript
forall a. a -> Maybe a
Just VScript
vScript)
go (StakingCredential (cred -> Maybe StakingCredential
forall a.
ToMaybeStakingCredential a =>
a -> Maybe StakingCredential
Script.toMaybeStakingCredential -> Maybe StakingCredential
mStCred)) = Lens' TxSkelOut (Maybe StakingCredential)
-> Maybe StakingCredential -> TxSkelOut -> TxSkelOut
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Lens' TxSkelOut (Maybe StakingCredential)
txSkelOutMStakingCredentialL Maybe StakingCredential
mStCred
go (PayableAnd Payable els
p1 Payable els'
p2) = Payable els' -> TxSkelOut -> TxSkelOut
forall (els :: [PayableKind]).
Payable els -> TxSkelOut -> TxSkelOut
go Payable els'
p2 (TxSkelOut -> TxSkelOut)
-> (TxSkelOut -> TxSkelOut) -> TxSkelOut -> TxSkelOut
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Payable els -> TxSkelOut -> TxSkelOut
forall (els :: [PayableKind]).
Payable els -> TxSkelOut -> TxSkelOut
go Payable els
p1
defaultTxSkelDatum :: TxSkelOutDatum
defaultTxSkelDatum = case User 'IsEither 'Allocation
owner of
UserScript (script -> VScript
forall script. ToVScript script => script -> VScript
toVScript -> Script.Versioned Script
_ Language
v) | Language
v Language -> Language -> Bool
forall a. Ord a => a -> a -> Bool
<= Language
Script.PlutusV2 -> () -> DatumKind -> TxSkelOutDatum
forall dat. DatumConstrs dat => dat -> DatumKind -> TxSkelOutDatum
SomeTxSkelOutDatum () (DatumResolved -> DatumKind
Hashed DatumResolved
NotResolved)
User 'IsEither 'Allocation
_ -> TxSkelOutDatum
NoTxSkelOutDatum