Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR4: Empty payments smart constructors #459

Open
wants to merge 2 commits into
base: mm/tweaks-input-outputs-restructured
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
to pay back an existing output with a slight modification.
- A new tweak `modifySpendRedeemersOfTypeTweak` to apply an optional
modification of all redeemers of a certain type within the skeleton inputs.
- Two new helpers `paysScriptNoValue` and `paysScriptOnlyAddress` to allow
payments to script with 0-ADA value, to be used alongside `txOptEnsureMinAda =
True` to avoid specifying an explicit amount of ADA.

### Removed

Expand Down
49 changes: 48 additions & 1 deletion src/Cooked/Skeleton.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ module Cooked.Skeleton
someTxSkelRedeemer,
emptyTxSkelRedeemer,
toTypedRedeemer,
paysScriptNoValue,
paysScriptOnlyAddress,
)
where

Expand Down Expand Up @@ -910,7 +912,7 @@ txSkelOutTypedDatum = Api.fromBuiltinData . Api.getDatum <=< txSkelOutUntypedDat

-- ** Smart constructors for transaction outputs

-- | Pay a certain value to a public key.
-- | Pays a certain value to a public key.
paysPK :: (ToPubKeyHash a) => a -> Api.Value -> TxSkelOut
paysPK pkh value =
Pays
Expand Down Expand Up @@ -947,6 +949,51 @@ paysScript validator datum value =
(Nothing @(Script.Versioned Script.Script))
)

-- | Pays a script with a certain datum and a 0-ADA value. To be used with the
-- automated minimal ADA adjustment 'txOptEnsureMinAda = True'.
paysScriptNoValue ::
( Api.ToData (Script.DatumType a),
Show (Script.DatumType a),
Typeable (Script.DatumType a),
PlutusTx.Eq (Script.DatumType a),
PrettyCooked (Script.DatumType a),
Typeable a
) =>
Script.TypedValidator a ->
Script.DatumType a ->
TxSkelOut
paysScriptNoValue validator datum =
Pays
( ConcreteOutput
validator
Nothing
(TxSkelOutDatum datum)
(Script.ada 0)
(Nothing @(Script.Versioned Script.Script))
)

-- | Pays a script with no datum and a 0-ADA value. To be used with the
-- automated minimal ADA adjustment 'txOptEnsureMinAda = True'.
paysScriptOnlyAddress ::
( Api.ToData (Script.DatumType a),
Show (Script.DatumType a),
Typeable (Script.DatumType a),
PlutusTx.Eq (Script.DatumType a),
PrettyCooked (Script.DatumType a),
Typeable a
) =>
Script.TypedValidator a ->
TxSkelOut
paysScriptOnlyAddress validator =
Pays
( ConcreteOutput
validator
Nothing
TxSkelOutNoDatum
(Script.ada 0)
(Nothing @(Script.Versioned Script.Script))
)

-- | Pays a script a certain value with a certain inlined datum.
paysScriptInlineDatum ::
( Api.ToData (Script.DatumType a),
Expand Down
Loading