You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGELOG.md
+37
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,43 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
80
80
81
81
### Removed
82
82
83
+
-**[IMPORTANT]** Removed use of conditional code rewriting based on `BROWSER_RUNTIME` env variable during bundling ([#1595](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1598))
84
+
85
+
This change simplifies the bundling process, but it requires a number of updates for all CTL-dependent projects:
86
+
87
+
- WebPack users should make this change to the webpack config:
88
+
89
+
```diff
90
+
plugins: [
91
+
- new webpack.DefinePlugin({
92
+
- BROWSER_RUNTIME: isBrowser
93
+
- }),
94
+
```
95
+
- Esbuild users should make this change:
96
+
97
+
```diff
98
+
const config = {
99
+
...
100
+
- define: {
101
+
- BROWSER_RUNTIME: isBrowser ? "true" : '""'
102
+
- },
103
+
```
104
+
105
+
- All users should update the runtime dependencies:
Copy file name to clipboardexpand all lines: doc/ctl-as-dependency.md
+3-11
Original file line number
Diff line number
Diff line change
@@ -6,25 +6,17 @@ CTL can be imported as an additional dependency into a Purescript project built
6
6
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
7
7
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8
8
9
-
-[Caveats](#caveats)
10
9
-[Using CTL's overlays](#using-ctls-overlays)
11
10
-[Upgrading CTL](#upgrading-ctl)
12
11
-[See also](#see-also)
13
12
14
13
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
15
14
16
-
## Caveats
17
-
18
-
The following caveats alway applies when using CTL from your project:
19
-
20
-
1. Only bundling with Webpack is supported (this is due to our internal dependency on `cardano-serialization-lib` which uses WASM with top-level `await`; only Webpack is reliably capable of bundling this properly)
21
-
2. The environment variable `BROWSER_RUNTIME` determines which version of `cardano-serialization-lib` is loaded by CTL, so you must use it as well (i.e. set it to `1` for the browser; leave it unset for NodeJS)
22
-
23
15
## Using CTL's overlays
24
16
25
17
CTL exposes two `overlay`s from its flake. You can use these in the Nix setup of your own project to use the same setup as we do, e.g. the same packages and PS builders:
26
18
27
-
-`overlays.purescript` contains Purescript builders to compile Purescript sources, build bundles with Webpack (`bundlePursProject`), run unit tests using NodeJS (`runPursTest`), and run CTL contracts on a private testnet using Plutip (`runPlutipTest`).
19
+
-`overlays.purescript` contains Purescript builders to compile Purescript sources, build bundles with Webpack/esbuild (`bundlePursProject`), run unit tests using NodeJS (`runPursTest`), and run CTL contracts on a private testnet using Plutip (`runPlutipTest`).
28
20
-`overlays.runtime` contains various packages and other tools used in CTL's runtime, including `ogmios`, `kupo`, and `plutip-server`. It also defines `buildCtlRuntime` and `launchCtlRuntime` to help you quickly launch all runtime services (see the [runtime docs](./runtime.md))
29
21
30
22
We've split the overlays into two components to allow users to more easily choose which parts of CTL's Nix infrastructure they would like to directly consume. For example, some users do not require a pre-packaged runtime and would prefer to build it themselves with more control over its components (e.g. by directly using `ogmios` from their own `inputs`). Such users might still like to use our `purescript` overlay -- splitting the `overlays` allows us to support this. `overlays.runtime` also contains several haskell.nix packages which may cause issues with `hackage.nix` versions in your own project.
@@ -80,9 +72,9 @@ Make sure to perform **all** of the following steps, otherwise you **will** enco
80
72
-That is, avoid using the `~` or `^` prefixes (e.g use versions like `"1.6.51"` instead of `"^1.6.51"`)
81
73
-If you're using a `package-lock.json` (which is _highly_ recommended), you can update the lockfile with `npm i --package-lock-only`
82
74
83
-
4.**Update your webpack config**
75
+
4.**Update your webpack/esbuild config**
84
76
85
-
-Sometimes the WebPack configuration also comes with breaking changes.Common source of problems are changes to `resolve.fallback`, `plugins`and`experiments` fields of the WebPack config.Use `git diff old-revision new-revision webpack.config.js` in the root of a cloned CTL repo, or use `git blame`.
77
+
-Sometimes the WebPackor esbuild configuration also comes with breaking changes.Use `git diff old-revision new-revision webpack.config.cjs` in the root of a cloned CTL repo, or use `git blame`.
Copy file name to clipboardexpand all lines: doc/development.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ To **build** the project **without bundling and for a NodeJS environment**:
77
77
-`npm run staking-test` to run [Plutip](./plutip-testing.md)-powered tests for ADA staking functionality - [entry point](../test/Plutip/Staking.purs)
78
78
-`npm run blockfrost-test` for [Blockfrost-powered tests](./blockfrost.md) (does not require a runtime, but needs [some setup](./blockfrost.md#setting-up-a-blockfrost-powered-test-suite)) - [entry point](../test/Blockfrost/Contract.purs)
79
79
-`npm run blockfrost-local-test` for self-hosted [Blockfrost-powered tests](./blockfrost.md) (requires a [local Blockfrost runtime](./blockfrost.md#running-blockfrost-locally)) - [entry point](../test/Blockfrost/Contract.purs)
80
-
-`npm run e2e-test` for [tests with a headless browser](./e2e-testing.md) (requires a runtime and the tests served via HTTP: `npm run start-runtime` and `npm run webpack-serve` or `esbuild-serve`)
80
+
-`npm run e2e-test` for [tests with a headless browser](./e2e-testing.md) (requires a runtime and the tests served via HTTP: `npm run start-runtime` and `npm run e2e-serve` or `esbuild-serve`)
81
81
82
82
#### With Nix
83
83
@@ -100,14 +100,14 @@ Here and below, `<SYSTEM>` should be replaced with [one of the supported systems
100
100
101
101
To run or build/bundle the project for the browser:
102
102
103
-
-`npm run webpack-serve` will start a Webpack development server at `localhost:4008`, which is required for [E2E tests](./e2e-testing.md)
103
+
-`npm run {webpack|esbuild}-serve` will start a Webpack development server at `localhost:4008`, which is required for [E2E tests](./e2e-testing.md)
104
104
-`npm run {webpack|esbuild}-bundle` will output a bundled example module to `dist` (or `nix build -L .#ctl-example-bundle-web-{webpack|esbuild}` to build an example module using Nix into `./result/`)
105
105
106
-
By default, Webpack will build a [Purescript module](../examples/ByUrl.purs) that serves multiple example `Contract`s depending on URL (see [here](./e2e-testing.md#serving-the-contract-to-be-tested)). You can point Webpack to another Purescript entrypoint by changing the `ps-bundle` variable in the Makefile or in the `main` argument in the flake's `packages.ctl-examples-bundle-web`.
106
+
By default, the bundler will build a [Purescript module](../examples/ByUrl.purs) that serves multiple example `Contract`s depending on URL (see [here](./e2e-testing.md#serving-the-contract-to-be-tested)). You can point the bundler to another Purescript entrypoint by changing the `ps-bundle` variable in the Makefile or in the `main` argument in the flake's `packages.ctl-examples-bundle-web`.
107
107
108
-
You will also need a light wallet extension pre-configured to run a `Contract`.
108
+
You will also need a light wallet extension pre-configured for the correct Cardano network to run a `Contract`.
109
109
110
-
**Note**: The `BROWSER_RUNTIME` environment variable must be set to `1` in order to build/bundle the project properly for the browser (e.g. `BROWSER_RUNTIME=1 webpack ...`). For Node environments, leave this variable unset.
110
+
**Note**: The `BROWSER_RUNTIME` environment variable must be set to `1` in order to build/bundle the project properly for the browser (e.g. `BROWSER_RUNTIME=1 webpack ...`). For NodeJS environments, leave this variable unset.
111
111
112
112
**Note**: The `KUPO_HOST` environment variable must be set to the base URL of the Kupo service in order to successfully serve the project for the browser (by default, `KUPO_HOST=http://localhost:1442`).
Copy file name to clipboardexpand all lines: doc/faq.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,9 @@ Another thing to keep in mind is that due to [min-ada requirements](https://docs
78
78
79
79
CTL does not consume wallet collateral normally, but it still can happen.
80
80
81
-
In order to get the collateral UTxO, CTL uses the wallet and then marks the returned UTxO as locked internally. But some wallets (e.g. Gero) do not return the collateral the moment it is set, waiting for Tx confirmation first. In case a collateral is set right before the contract is started, CTL can accidentally spend the collateral, because we rely on CTL's own query layer to get a list of available UTxOs, and the wallet state may lag behind it, not returning the collateral to filter out at that moment.
81
+
In order to get the collateral UTxO, CTL uses the wallet and then marks the returned UTxO as "locked" internally. But some wallets (e.g. Gero) do not return the collateral the moment it is set, waiting for Tx confirmation first. In case a collateral is set right before the contract is started, CTL can accidentally spend the collateral, because we rely on CTL's own query layer to get a list of available UTxOs without consulting with the wallet [in some cases](./query-layers.md), and the wallet state may lag behind the backend state.
82
+
83
+
It is impossible to lose the collateral UTxO funds completely, though, because CTL always uses [CIP-40 collateral return](https://cips.cardano.org/cip/CIP-0040).
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
16
16
@@ -31,7 +31,6 @@ The output file should be a Cardano envelope:
31
31
- An example of a Plutus exporter can be found [here](https://github.com/Mr-Andersen/ctl-multisign-mre/blob/main/onchain/exporter/Main.hs).
32
32
- For Plutarch, see [the-plutus-scaffold](https://github.com/mlabs-haskell/the-plutus-scaffold)'s [exporter](https://github.com/mlabs-haskell/the-plutus-scaffold/tree/main/onchain/exporter).
33
33
34
-
35
34
### Using Plutonomy
36
35
37
36
It makes sense to use [Plutonomy](https://github.com/well-typed/plutonomy) (an optimizer for UPLC) in the exporter:
To use your own scripts, compile them to any subdirectory in the root of your project (where `webpack.config.js` is located) and add a relative path to `webpack.config.js` under the `resolve.alias` section. In CTL, we have the `Scripts` alias for this purpose. Note the capitalization of `Scripts`: it is necessary to disambiguate it from local folders.
50
-
51
-
First, in your `webpack.config.js`, define an `alias` under `module.exports.resolve.alias` in order to `require` the compiled scripts from JS modules:
52
-
53
-
```javascript
54
-
constpath=require("path");
55
-
56
-
module.exports= {
57
-
// ...
58
-
resolve: {
59
-
modules: [process.env.NODE_PATH],
60
-
extensions: [".js"],
61
-
fallback: {
62
-
// ...
63
-
},
64
-
alias: {
65
-
// You should update this path to the location of your compiled scripts,
This way you avoid hardcoding your scripts directly to .purs files which could lead to synchronization issues should your scripts change.
112
-
113
-
**Note**: The `alias` method above will only work in the browser when bundling with Webpack. In order to load the scripts for both browser and NodeJS environments, you can use the `BROWSER_RUNTIME` environment variable like so:
114
-
115
-
```javascript
116
-
let script;
117
-
if (typeofBROWSER_RUNTIME!="undefined"&&BROWSER_RUNTIME) {
Note that the relative path passed to `path.resolve` for the NodeJS case starts from the `output` directory that the Purescript compiler produces.
131
-
132
46
## Serializing Plutus scripts
133
47
134
48
### PlutusTx
@@ -176,3 +90,7 @@ You can use [`ply`](https://github.com/mlabs-haskell/ply) and [`ply-ctl`](https:
176
90
### plutarch-ctl-bridge
177
91
178
92
You can use [`plutarch-ctl-bridge`](https://github.com/mlabs-haskell/plutarch-ctl-bridge) to generate Purescript types from your Haskell type definitions and typed script wrappers from parametrized Plutarch scripts. See [example module](https://github.com/mlabs-haskell/plutarch-ctl-bridge/blob/main/example/Main.hs).
93
+
94
+
## Importing serialized scripts
95
+
96
+
To use your own scripts, compile them to any subdirectory in the root of your project and either dynamically load them from file (NodeJS) or use your bundler to include them as fixtures into the bundle ([instructions for WebPack](https://webpack.js.org/guides/asset-modules/), [for esbuild](https://esbuild.github.io/content-types/#external-file)).
0 commit comments