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

Fix transaction witness set 'attach' functions #1653

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 25 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,90 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [[v9.3.1]](#v931)
- [[Unreleased]](#unreleased)
- [Fixed](#fixed)
- [[v9.3.0]](#v930)
- [[v9.3.1]](#v931)
- [Fixed](#fixed-1)
- [[v9.3.0]](#v930)
- [Fixed](#fixed-2)
- [Changed](#changed)
- [[v9.2.0]](#v920)
- [Added](#added)
- [Changed](#changed-1)
- [Removed](#removed)
- [Fixed](#fixed-2)
- [Fixed](#fixed-3)
- [[v9.1.0]](#v910)
- [Added](#added-1)
- [Changed](#changed-2
- [Changed](#changed-2)
- [Removed](#removed-1)
- [Fixed](#fixed-3)
- [Fixed](#fixed-4)
- [[v9.0.0]](#v900)
- [Deprecated](#deprecated)
- [Added](#added-2)
- [Removed](#removed-2)
- [Changed](#changed-3)
- [Fixed](#fixed-4)
- [Fixed](#fixed-5)
- [[v8.0.0]](#v800)
- [Added](#added-3)
- [Changed](#changed-4)
- [Fixed](#fixed-5)
- [Fixed](#fixed-6)
- [Removed](#removed-3)
- [[v7.0.0]](#v700)
- [Added](#added-4)
- [Changed](#changed-5)
- [Fixed](#fixed-6)
- [Fixed](#fixed-7)
- [Removed](#removed-4)
- [[v6.0.0]](#v600)
- [Added](#added-5)
- [Changed](#changed-6)
- [Fixed](#fixed-7)
- [Fixed](#fixed-8)
- [Removed](#removed-5)
- [[v5.0.0]](#v500)
- [Added](#added-6)
- [Changed](#changed-7)
- [Removed](#removed-6)
- [Fixed](#fixed-8)
- [Fixed](#fixed-9)
- [Runtime Dependencies](#runtime-dependencies)
- [[v4.0.2] - 2023-01-17](#v402---2023-01-17)
- [Fixed](#fixed-9)
- [Fixed](#fixed-10)
- [[v4.0.1] - 2022-12-20](#v401---2022-12-20)
- [Added](#added-7)
- [[v4.0.0] - 2022-12-15](#v400---2022-12-15)
- [Added](#added-8)
- [Changed](#changed-8)
- [Removed](#removed-7)
- [Fixed](#fixed-10)
- [Fixed](#fixed-11)
- [Runtime Dependencies](#runtime-dependencies-1)
- [[3.0.0] - 2022-11-21](#300---2022-11-21)
- [Added](#added-9)
- [Changed](#changed-9)
- [Removed](#removed-8)
- [Fixed](#fixed-11)
- [Fixed](#fixed-12)
- [Runtime Dependencies](#runtime-dependencies-2)
- [[2.0.0] - 2022-09-12](#200---2022-09-12)
- [Added](#added-10)
- [Changed](#changed-10)
- [Removed](#removed-9)
- [Fixed](#fixed-12)
- [Fixed](#fixed-13)
- [[2.0.0-alpha] - 2022-07-05](#200-alpha---2022-07-05)
- [Added](#added-11)
- [Removed](#removed-10)
- [Changed](#changed-11)
- [Fixed](#fixed-13)
- [[1.1.0] - 2022-06-30](#110---2022-06-30)
- [Fixed](#fixed-14)
- [[1.0.1] - 2022-06-17](#101---2022-06-17)
- [[1.1.0] - 2022-06-30](#110---2022-06-30)
- [Fixed](#fixed-15)
- [[1.0.1] - 2022-06-17](#101---2022-06-17)
- [Fixed](#fixed-16)
- [[1.0.0] - 2022-06-10](#100---2022-06-10)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## [Unreleased]

### Fixed

- Fixed transaction witness set 'attach' functions. Previously, the updated witness set was incorrectly appended to the existing set, causing performance degradation when processing constraints for complex transactions. ([#1653](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1653))

## [v9.3.1]

### Fixed
Expand Down
43 changes: 16 additions & 27 deletions src/Internal/Transaction.purs
Original file line number Diff line number Diff line change
Expand Up @@ -90,43 +90,32 @@ setScriptDataHash costModels rs ds tx@(Transaction { body, witnessSet })
attachDatum :: PlutusData -> Transaction -> Transaction
attachDatum d = attachDatums [ d ]

attachDatums
:: Array PlutusData -> Transaction -> Transaction
attachDatums :: Array PlutusData -> Transaction -> Transaction
attachDatums [] tx = tx
attachDatums datums tx@(Transaction { witnessSet: TransactionWitnessSet ws }) =
do
updateTxWithWitnesses tx $ TransactionWitnessSet $ ws
{ plutusData = nub $ ws.plutusData <> datums }
updateTxWithWitnesses tx $ TransactionWitnessSet $ ws
{ plutusData = nub $ ws.plutusData <> datums
}

-- | Attach a `PlutusScript` to a transaction by modifying its existing witness
-- | set
attachPlutusScript
:: PlutusScript -> Transaction -> Transaction
attachPlutusScript :: PlutusScript -> Transaction -> Transaction
attachPlutusScript ps = attachPlutusScripts [ ps ]

attachPlutusScripts
:: Array PlutusScript
-> Transaction
-> Transaction
attachPlutusScripts :: Array PlutusScript -> Transaction -> Transaction
attachPlutusScripts ps tx@(Transaction { witnessSet: TransactionWitnessSet ws }) =
do
updateTxWithWitnesses tx
$ TransactionWitnessSet
$ ws { plutusScripts = nub $ ws.plutusScripts <> ps }
updateTxWithWitnesses tx $ TransactionWitnessSet $ ws
{ plutusScripts = nub $ ws.plutusScripts <> ps
}

-- | Attach a `NativeScript` to a transaction by modifying its existing witness
-- | set
attachNativeScript
:: NativeScript -> Transaction -> Transaction
attachNativeScript :: NativeScript -> Transaction -> Transaction
attachNativeScript ns tx@(Transaction { witnessSet: TransactionWitnessSet ws }) =
do
updateTxWithWitnesses tx
$ TransactionWitnessSet
$ ws { nativeScripts = nub $ ws.nativeScripts <> [ ns ] }
updateTxWithWitnesses tx $ TransactionWitnessSet $ ws
{ nativeScripts = nub $ ws.nativeScripts <> [ ns ]
}

updateTxWithWitnesses
:: Transaction
-> TransactionWitnessSet
-> Transaction
updateTxWithWitnesses tx@(Transaction t) ws =
over Transaction _ { witnessSet = t.witnessSet <> ws } tx
updateTxWithWitnesses :: Transaction -> TransactionWitnessSet -> Transaction
updateTxWithWitnesses tx ws =
over Transaction _ { witnessSet = ws } tx