Skip to content

Commit

Permalink
new empty value payment helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontin committed Feb 14, 2025
1 parent a951b00 commit a2a29db
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
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

0 comments on commit a2a29db

Please sign in to comment.