Skip to content

Commit d446e1c

Browse files
committed
Merge branch 'develop' into dshuiski/conway
2 parents b7e009a + c027375 commit d446e1c

File tree

86 files changed

+2102
-3148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2102
-3148
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ node_modules
2929
plutip-server/dist-newstyle/
3030
plutip-server/dist/
3131
plutip-server/.stack-work/
32+
nixos.qcow2

CHANGELOG.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
88
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
99

10-
- [[Unreleased]](#unreleased)
10+
- [[v9.0.0]](#v900)
11+
- [Deprecated](#deprecated)
1112
- [Added](#added)
1213
- [Removed](#removed)
1314
- [Changed](#changed)
@@ -67,17 +68,37 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6768

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

70-
## [Unreleased]
71+
## [v9.0.0]
72+
73+
### Deprecated
74+
75+
> [!WARNING]
76+
> **IMPORTANT** Constraints interface (`Contract.TxConstraints` & `Contract.ScriptLookups`) has been deprecated and will be removed in a future version. Please use [`purescript-cardano-transaction-builder`](https://github.com/mlabs-haskell/purescript-cardano-transaction-builder) (via `Contract.Transaction.buildTx`) for new contracts. The motivation for deprecation is that it was unnecessarily complex, not flexible enough, and existed only because of the desire to provide code-level compatibility with PAB. See [this Catalyst proposal](https://cardano.ideascale.com/c/idea/101478) for more info.
7177
7278
### Added
7379

80+
- `Contract.Transaction.buildTx :: Array TransactionBuilderStep -> Contract Transaction` that provides a `Contract`-based interface for the [new transaction builder](https://github.com/mlabs-haskell/purescript-cardano-transaction-builder).
81+
- `Contract.Transaction.submitTxFromBuildPlan :: UtxoMap -> BalanceTxConstraintsBuilder -> Array TransactionBuilderStep -> Contract Transaction` - a convenience function that executes the whole transaction creation pipeline starting from a build plan for [the new transaction builder](https://github.com/mlabs-haskell/purescript-cardano-transaction-builder).
82+
- `Contract.ClientError.pprintClientError` to provide readable error reports.
83+
- `Contract.Staking.getStakeCredentialDelegationsAndRewards` utility function
84+
7485
### Removed
7586

76-
- `Contract.Scripts.applyArgs` - use `Cardano.Plutus.ApplyArgs.applyArgs` from [purescript-uplc-apply-args](https://github.com/mlabs-haskell/purescript-uplc-apply-args)
87+
- **IMPORTANT** `UnbalancedTx` type has been removed. This change was motivated by the fact that `UnbalancedTx` existed simply to tie together transaction building and balancing by keeping extra context. Now that transaction builder is placed in [its own package](https://github.com/mlabs-haskell/purescript-cardano-transaction-builder), there is no more need in `UnbalancedTx`, that is not used with the new builder.
88+
- **IMPORTANT** `balanceTxWithConstraints`, `balanceTxWithConstraintsE` - use `balanceTx`
89+
- **IMPORTANT** `balanceTxsWithConstraints` - use `balanceTxs`
90+
- **IMPORTANT** `withBalancedTxWithConstraints`, `withBalancedTxWithConstraints` - use `withBalancedTxs`
91+
- **IMPORTANT** `Contract.Scripts.applyArgs` - use `Cardano.Plutus.ApplyArgs.applyArgs` from [purescript-uplc-apply-args](https://github.com/mlabs-haskell/purescript-uplc-apply-args).
92+
- `Contract.Transaction.submitTxFromConstraintsReturningFee` - too niche use case to be allowed in the public API.
93+
- `Contract.Transaction` lens values. Use lenses from `Cardano.Types.Transaction`
7794

7895
### Changed
7996

8097
- Bumped Ogmios to version 6.0.3 ([#1626](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1626))
98+
- `Contract.Transaction.mkUnbalancedTx` now returns a tuple: a transaction and the UTxOs it used.
99+
- `Contract.Transaction.balanceTx` accepts two extra argument: a list of used UTxOs (set to `Data.Map.empty` if none of them are coming from the outside of the wallet) and balancer constraints (set to `mempty` if not needed)
100+
- Default synchronization parameters: all [wallet <-> query layer synchronization primitives](./doc/query-layers.md) are now off by default. The reason is that the runtime overhead made the users unhappy and it was not worth it for most of the users. If your dApp sends transactions in quick succession, consider enabling the synchronization again by using `softSynchronizationParams` (old behavior) or `strictSynchronizationParams`.
101+
- `BalanceTxConstraintsBuilder` has been renamed to `BalancerConstraints`. It is still available under the old name as a type synonym.
81102

82103
### Fixed
83104

Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ query-preprod-testnet-tip:
101101
CARDANO_NODE_SOCKET_PATH=${preprod-node-ipc}/node.socket cardano-cli query tip \
102102
--testnet-magic 1
103103

104-
run-ci-actions:
104+
run-ci-actions: run-template-checks
105105
nix build -L .#checks.x86_64-linux.formatting-check
106-
nix build -L .#checks.x86_64-linux.template-deps-json
107-
nix build -L .#checks.x86_64-linux.template-dhall-diff
108-
nix build -L .#checks.x86_64-linux.template-version
109106
nix build -L .#checks.x86_64-linux.ctl-unit-test
110107
nix build -L .#checks.x86_64-linux.ctl-e2e-test
111108
nix build -L .#checks.x86_64-linux.ctl-local-testnet-test

doc/babbage-features.md

+6-25
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,29 @@ This document is a reference/explainer for the new CTL APIs introduced for Babba
66
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
77
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
88

9-
- [Reference Inputs](#reference-inputs)
10-
- [Reference Scripts](#reference-scripts)
9+
- [Reference Inputs & Reference Scripts](#reference-inputs--reference-scripts)
1110
- [Inline Data](#inline-data)
1211
- [Collateral Output](#collateral-output)
1312

1413
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
15-
## Reference Inputs
14+
## Reference Inputs & Reference Scripts
1615

1716
[Reference inputs](https://cips.cardano.org/cip/CIP-0031#reference-inputs) allow looking at an output without spending it in Plutus scripts.
1817

19-
There are two ways to use an input as a reference in the constraints API:
20-
21-
1. via `mustReferenceOutput`, which allows Plutus scripts to access the information (e.g. datum, locked value) contained in the output.
22-
23-
[Usage example](../examples/PlutusV2/ReferenceInputs.purs)
24-
25-
2. by providing constraints which accept a value of the type `InputWithScriptRef` with the `RefInput` constructor. These allow scripts (validating or minting) to be reused by reference between multiple transactions without including them in those transactions, explained further in [Reference Scripts](#reference-scripts).
26-
27-
[Usage example](../examples/PlutusV2/ReferenceInputsAndScripts.purs)
28-
29-
## Reference Scripts
30-
3118
[Reference Scripts](https://cips.cardano.org/cip/CIP-0033) allows the use of scripts without attaching them to the transaction (and using a reference instead).
3219

33-
Reference scripts can be utilized in CTL by first creating a reference point for the script to be used later via `mustPayToScriptWithScriptRef` (or its variants).
20+
Reference scripts can be utilized in CTL by first creating a UTxO containing the script to be used later.
3421

35-
This constraint utilises a new `ScriptRef` type that includes either a native script or a Plutus script.
36-
37-
Then, `mustSpendScriptOutputUsingScriptRef` (or its variants) can be used to use a reference script. It accepts a value of type `InputWithScriptRef` that specifies whether the UTxO with the reference script should be spent or referenced.
38-
39-
[Usage example](../examples/PlutusV2/ReferenceScripts.purs)
22+
[Usage example](../examples/PlutusV2/ReferenceInputsAndScripts.purs)
4023

4124
## Inline Data
4225

4326
[CIP-32](https://cips.cardano.org/cip/CIP-0032) introduces the inline data feature that allows storing datum values directly in transaction outputs, instead of just the hashes.
4427

45-
In CTL, alternating between datum storage options can be achieved by specifying a `DatumPresence` value with constraints that accept it, like `mustPayToPubKeyWithDatum`.
46-
47-
[Usage example](../examples/PlutusV2/InlineDatum.purs)
48-
4928
## Collateral Output
5029

5130
[CIP-40](https://cips.cardano.org/cip/CIP-0040) introduces explicit collateral output. On validation failure, previously the entire collateral was consumed. Now, if excess collateral is supplied, even with native assets, the surplus can be returned on validation failure.
5231

5332
Collateral output is automatically added to transactions in CTL. To trigger a collateral return, the `mustNotBeValid` constraint should be explicitly specified, otherwise a script error would be detected earlier and the transaction will not be sent.
33+
34+
[Usage example](../examples/Lose7Ada.purs)

doc/balancing.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
22
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
33

4-
- [Configuring balancing process](#configuring-balancing-process)
4+
- [Configuring the balancing process](#configuring-the-balancing-process)
55
- [Balancer constraints](#balancer-constraints)
66
- [Concurrent spending](#concurrent-spending)
77
- [Balancing a Tx for other wallet](#balancing-a-tx-for-other-wallet)
@@ -10,7 +10,7 @@
1010

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

13-
# Configuring balancing process
13+
# Configuring the balancing process
1414

1515
Transaction balancing in Cardano is the process of finding a set of inputs and outputs that that sum up to zero, covering all the required fees for the transaction to be valid.
1616

@@ -37,7 +37,7 @@ Setting `mustUseUtxosAtAddress`, `mustSendChangeToAddress` and `mustUseCollatera
3737

3838
## Synchronization
3939

40-
Before balancing, CTL tries to synchronize the wallet state with the query layer, i.e. waits until all UTxOs that the wallet returns are visible in the query layer. Thus the situation when the query layer refuses to validate a Tx (either during ex-units evaluation or on Tx submission) is only possible due to a rollback or a synchronization timeout. Please see [our docs for query layer synchronization](./query-layers.md).
40+
It's possible to make CTL try to synchronize the wallet state with the query layer, i.e. wait until all UTxOs that the wallet returns are visible in the query layer. Thus the situation when the query layer refuses to validate a Tx (either during ex-units evaluation or on Tx submission) is only possible due to a rollback or a synchronization timeout. Please see [our docs for query layer synchronization](./query-layers.md).
4141

4242
## Balancing process limitations
4343

doc/development.md

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This document outlines development workflows for CTL itself. You may also wish t
2222
- [JS](#js)
2323
- [Switching development networks](#switching-development-networks)
2424
- [Maintaining the template](#maintaining-the-template)
25+
- [Updating the template](#updating-the-template)
2526

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

@@ -148,4 +149,13 @@ Set new `network.name` and `network.magic` in `runtime.nix`. Also see [Changing
148149

149150
[The template](../templates/ctl-scaffold/) must be kept up-to-date with the repo. Although there are some checks for common problems in CI, it's still possible to forget to update the `package-lock.json` file.
150151

152+
## Updating the template
153+
154+
1. Update the revision of CTL in the template's `flake.nix`
155+
2. Update the npm packages in the `package.json` (if needed)
156+
3. Run `npm i` to update the lockfile (if there are NPM dependency version changes)
157+
4. Update the revisions in the template's `packages.dhall` (CTL version must match the one in `flake.nix`)
158+
5. Run `spago2nix generate`
159+
6. Run `nix develop`
160+
151161
[This helper script](../scripts/template-check.sh) can be used to make sure the template can be initialized properly from a given revision.

doc/getting-started.md

+27-28
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ This guide will help you get started writing contracts with CTL. Please also see
1616
- [Executing contracts and the `ContractEnv`](#executing-contracts-and-the-contractenv)
1717
- [Making the `ContractEnv`](#making-the-contractenv)
1818
- [Building and submitting transactions](#building-and-submitting-transactions)
19-
- [Using compiled scripts](#using-compiled-scripts)
20-
- [Testing](#testing)
21-
- [Without a light wallet](#without-a-light-wallet)
22-
- [With a light wallet](#with-a-light-wallet)
23-
- [Cardano Testnet integration](#cardano-testnet-integration)
2419

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

@@ -56,7 +51,7 @@ You can learn more about using CTL as a dependency [here](./ctl-as-dependency.md
5651

5752
### Other prerequisites
5853

59-
You will also need to become familiar with [CTL's runtime](./runtime.md) as its runtime services are required for executing virtually all contracts.
54+
You will also need to become familiar with [CTL's runtime](./runtime.md) as its runtime services are required for executing virtually all contracts. If you want to avoid manual backend setup, use [blockfrost.io](./blockfrost.md).
6055

6156
## Importing CTL modules
6257

@@ -140,9 +135,13 @@ main = Contract.Monad.launchAff_ do -- we re-export this for you
140135
, kupoConfig: defaultKupoServerConfig
141136
}
142137
, networkId: TestnetId
143-
, logLevel: Trace
144138
, walletSpec: Just ConnectToNami
139+
, logLevel: Trace
145140
, customLogger: Nothing
141+
, suppressLogs: false
142+
, hooks: emptyHooks
143+
, timeParams: defaultTimeParams
144+
, synchronizationParams: defaultSynchronizationParams
146145
}
147146
runContract config someContract
148147
@@ -167,49 +166,49 @@ customOgmiosWsConfig =
167166

168167
Unlike PAB, CTL obscures less of the build-balance-sign-submit pipeline for transactions and most of the steps are called individually. The general workflow in CTL is similar to the following:
169168

170-
- Build a transaction using `Contract.ScriptLookups`, `Contract.TxConstraints` and `Contract.BalanceTxConstraints` (it is also possible to directly build a `Transaction` if you require even greater low-level control over the process, although we recommend the constraints/lookups approach for most users):
169+
- Build a transaction using [`cardano-transaction-builder`](https://github.com/mlabs-haskell/purescript-cardano-transaction-builder):
171170

172171
```purescript
173172
contract = do
174173
let
175-
constraints :: TxConstraints Unit Unit
176-
constraints =
177-
TxConstraints.mustPayToScript vhash unitDatum
178-
(Value.lovelaceValueOf $ BigInt.fromInt 2_000_000)
179-
180-
lookups :: ScriptLookups PlutusData
181-
lookups = ScriptLookups.validator validator
182-
183-
balanceTxConstraints :: BalanceTxConstraints.BalanceTxConstraintsBuilder
184-
balanceTxConstraints =
185-
BalanceTxConstraints.mustUseUtxosAtAddress address
186-
<> BalanceTxConstraints.mustSendChangeToAddress address
187-
<> BalanceTxConstraints.mustNotSpendUtxoWithOutRef nonSpendableOref
188-
189-
-- `liftedE` will throw a runtime exception on `Left`s
190-
unbalancedTx <- liftedE $ Lookups.mkUnbalancedTx lookups constraints
174+
plan =
175+
[ Pay $ TransactionOutput
176+
{ address: address
177+
, amount: Value.lovelaceValueOf $ BigNum.fromInt 1_000_000
178+
, datum: Just $ OutputDatumHash $ hashPlutusData PlutusData.unit
179+
, scriptRef: Nothing
180+
}
181+
]
182+
unbalancedTx <- buildTx plan
191183
...
192184
```
193185

194-
- Balance it using `Contract.Transaction.balanceTx` (or `Contract.Transaction.balanceTxWithConstraints` if you need to adjust the balancer behaviour) and then sign it using `signTransaction`:
186+
- Balance it using `Contract.Transaction.balanceTx`, and then sign it using `signTransaction`:
195187
```purescript
196188
contract = do
197189
...
190+
let
191+
balanceTxConstraints :: BalanceTxConstraints.BalanceTxConstraintsBuilder
192+
balanceTxConstraints =
193+
BalanceTxConstraints.mustUseUtxosAtAddress address
194+
<> BalanceTxConstraints.mustSendChangeToAddress address
195+
<> BalanceTxConstraints.mustNotSpendUtxoWithOutRef nonSpendableOref
198196
-- `liftedE` will throw a runtime exception on `Left`s
199197
balancedTx <-
200-
liftedE $ balanceTxWithConstraints unbalancedTx balanceTxConstraints
198+
balanceTx unbalancedTx usedUtxos balanceTxConstraints
201199
balancedSignedTx <- signTransaction balancedTx
202200
...
203201
```
204202

205-
- Submit using `Contract.Transaction.submit`:
203+
- Submit using `Contract.Transaction.submit` and await for confirmation using `awaitTxConfirmed`:
206204

207205
```purescript
208206
contract = do
209207
...
210208
txId <- submit balancedSignedTx
209+
awaitTxConfirmed txId
211210
logInfo' $ "Tx ID: " <> show txId
212-
```
211+
```
213212

214213
### Using compiled scripts
215214

0 commit comments

Comments
 (0)