{"id":24551948,"url":"https://github.com/mlabs-haskell/lambda-buffers-for-cardano","last_synced_at":"2025-04-15T22:20:35.886Z","repository":{"id":206998300,"uuid":"713950200","full_name":"mlabs-haskell/lambda-buffers-for-cardano","owner":"mlabs-haskell","description":"LambdaBuffers Cardano Demo","archived":false,"fork":false,"pushed_at":"2025-04-14T06:36:07.000Z","size":1086,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-14T07:37:36.297Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlabs-haskell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-03T15:26:15.000Z","updated_at":"2025-04-14T06:36:10.000Z","dependencies_parsed_at":"2024-02-23T15:25:22.725Z","dependency_job_id":"b3063063-4920-44d7-b61a-1d62cd6d9dca","html_url":"https://github.com/mlabs-haskell/lambda-buffers-for-cardano","commit_stats":null,"previous_names":["mlabs-haskell/lambdabuffers-cardano-demo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Flambda-buffers-for-cardano","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Flambda-buffers-for-cardano/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Flambda-buffers-for-cardano/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Flambda-buffers-for-cardano/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlabs-haskell","download_url":"https://codeload.github.com/mlabs-haskell/lambda-buffers-for-cardano/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249161929,"owners_count":21222570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-23T01:19:30.928Z","updated_at":"2025-04-15T22:20:35.869Z","avatar_url":"https://github.com/mlabs-haskell.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LambdaBuffers Cardano Demo\n\nThis repository serves to demonstrate how to use the\n[LambdaBuffers](https://github.com/mlabs-haskell/lambda-buffers) toolkit for\nsharing types and their semantics between supported language environments\nPlutarch, PlutusTx, Purescript (with Cardano Transaction Library), Haskell,\nRust, and TypeScript.\n\nHowever, it can also serve as a scaffold for a typical Cardano dApp project\nthat uses LambdaBuffers.\n\n## Getting started\n\nThis repo relies on Nix and Direnv for seamless, reproducible and shareable\nbuilds and development environments. Please see the\n[LambdaBuffers: Getting started](https://mlabs-haskell.github.io/lambda-buffers/getting-started.html)\nchapter to help you set up these tools.\n\n## Overview\n\nThe (mono)repo has several key directories and sub-projects, namely `api`,\n`validation` and `transactions`.\n\n### API\n\nThe [api](api) directory contains the LambdaBuffers .lbf schemas where the\nPlutus and configuration types are specified for seamless sharing between\nproject components.\n\nNote the [api/build.nix](api/build.nix) file which is where the build recipes\nare specified for the .lbf schemas.\n\nYou can simply inspect the packages created by these build recipes with Nix.\nFor example, to inspect the Haskell package created by the aforementioned\nbuild recipe, you can execute the following.\n\n```shell\n$ nix build .#lbf-demo-plutus-api-haskell\n$ find result/autogen/\nresult/autogen/\nresult/autogen/LambdaBuffers\nresult/autogen/LambdaBuffers/Demo\nresult/autogen/LambdaBuffers/Demo/Plutus.hs\n```\n\nYou shouldn't ever need to do this, but it's always good to know how to peek\nunder the hood when problems inevitably arise.\n\n### Validation\n\nThe [validation](validation) directory contains the Plutus scripts that validate\nPlutus Protocol transactions (see [transactions](#transactions)).\n\nThis is traditionally called 'onchain' in other project templates, but I found it\npersonally beneficial to rename these project constituents to make their meaning\nmore clear and explicit.\n\nThis directory further contains two sub-projects, namely\n[validation/demo-plutarch](validation/demo-plutarch) and\n[validation/demo-plutustx](validation/demo-plutustx) that implement the same\nvalidation logic, but in Plutarch and PlutusTx respectively.\n\nThese projects implement the same Plutus protocol validation that consists of a\nsingle Equality Validator. This validator has a single 'spend' rule that checks\nwhether the spent Eq Validator UTxO contains a [EqDatum](api/Demo/Plutus.lbf)\nequal or not equal to the [EqDatum](api/Demo/Plutus.lbf) specified in the\n[EqRedeemer](api/Demo/Plutus.lbf).\n\nAs is the case throughout this monorepo, the build.nix file contains the build\nspecification parts of which can be inspected by simply using Nix:\n\n```shell\n# Build the Demo Json configuration that contains the Eq Validator compiled from\n# the Plutarch specification.\n$ nix build .#demo-plutarch-config\n$ less result\n# Build the Demo Json configuration that contains the Eq Validator compiled from\n# the PlutusTx specification.\n$ nix build .#demo-plutustx-config\n$ less result\n```\n\nThese configurations files are used by 'transactions' components that use the\nscripts contained within.\n\n### Transactions\n\nThe [transactions](transactions) directory contains the transaction building\ncomponents implemented various supported transaction building environments.\nCurrently, we demonstrate transaction building with the following systems:\n\n- PureScript with Cardano Transaction Lib in\n  [transactions/demo-ctl](transactions/demo-ctl).\n\n- JavaScript (TypeScript) with Cardano Serialization Lib in\n  [transactions/demo-typescript](transactions/demo-typescript).\n\n- Rust with [tx-village](https://github.com/mlabs-haskell/tx-village) in\n  [transactions/demo-rust](transactions/demo-rust).\n\n- Haskell using Plutus Ledger API types to build data structures suitable for\n  tx-village in [transactions/demo-haskell](transactions/demo-haskell) which\n  uses a Rust CLI to tx-village in\n  [transactions/demo-tx-village](transactions/demo-tx-village).\n\nThe transaction building is traditionally bundled in `offchain` directories of\nvarious project scaffolds, however, I found it useful to further delineate\ndifferent parts of any given Cardano dApp project in several sub-parts. Along\nwith 'transactions' one would need 'query' which is a component that serves to\norchestrate fetching of the context necessary to build transactions. However,\nowing to the simplicity of this Protocol, the query component is simply included\nwithin the transaction building projects.\n\nThere are 3 transactions in this Protocol as follows.\n\n1. `create-value-tx` that stores an [EqDatum](api/Demo/Plutus.lbf) at the Eq\n   validator,\n2. `inputs-is-equal-tx` that spends a UTxO at the Eq validator and checks whether\n   the [EqDatum](api/Demo/Plutus.lbf) spent is the same as the one provided in the\n   redeemer,\n3. `inputs-is-not-equal-tx` that spends a UTxO at the Eq validator and checks\n   whether the [EqDatum](api/Demo/Plutus.lbf) spent is different as the one\n   provided in the redeemer.\n\nEach of the projects has a testsuite which spawns a new Cardano network (using\ncardano-devnet) and supporting services (Ogmios, and Kupo for PureScript with\nCTL), builds the Protocol transactions in proper order and eventually signs and\nsubmits them.\n\nThe testsuite tries the same protocol flow with both configurations coming from\nPlutarch and PlutusTx scripts where the testsuite executes the following:\n\n1. Build and submit a `create-value-tx` transaction to store a EqDatum at an Eq\n   validator.\n\n2. Build and submit a `inputs-is-equal-tx` transaction to check the EqDatum is the\n   same as the one provided in the redeemer\n\n3. Build and submit another `create-value-tx` transaction to store a EqDatum at an\n   Eq validator.\n\n4. Build and submit a `inputs-is-not-equal-tx` transaction to check the EqDatum is\n   not the same as the one provided in the redeemer\n\nAs is the case throughout this monorepo, the build.nix file contains the build\nspecification parts of which can be inspected by simply using Nix.\n\n#### Testsuites\n\nTestsuites use [process-compose](https://github.com/F1bonacc1/process-compose) to manage the runtime dependencies, such as\ncardano-node, ogmios, etc. required for the tests. These can all be executed\neither by a nix command, like\n\n```shell\n$ nix build .#checks.x86_64-linux.demo-rust-checks -L\n...\n```\n\nor by entering the direnv shell of the given project, and executing the process\ncompose command exposed by Nix:\n\n```shell\n$ cd transactions/demo-rust\n$ pc-demo-rust-tests --keep-project\n...\n```\n\n##### PureScript\n\nThe transactions in this Protocol are implemented in\n[transactions/demo-ctl/src/Demo/Transactions.purs](transactions/demo-ctl/src/Demo/Transactions.purs).\n\nThe testsuite can be executed with the following commands.\n\n```shell\n# Run the CTL check\n$ nix build .#checks.x86_64-linux.demo-ctl-checks -L\n...\n```\n\nor\n\n```shell\n$ cd transactions/demo-ctl\n$ pc-demo-ctl-tests --keep-project\n...\n```\n\n##### Rust\n\nThe transactions in this Protocol are implemented in [transactions/demo-rust/src/lib.rs](transactions/demo-rust/src/lib.rs).\n\nThe testsuite can be executed with the following commands.\n\n```shell\n# Run the Rust check\n$ nix build .#checks.x86_64-linux.demo-rust-checks -L\n...\n```\n\nor\n\n```shell\n$ cd transactions/demo-rust\n$ pc-demo-rust-tests --keep-project\n...\n```\n\n##### JavaScript (TypeScript)\n\nThe transactions in this Protocol are implemented in [transactions/demo-typescript/src/lib/index.ts](transactions/demo-typescript/src/lib/index.ts).\n\nThe testsuite can be executed with the following commands.\n\n```shell\n# Run the TypeScript check\n$ nix build .#checks.x86_64-linux.demo-typescript-checks -L\n...\n```\n\nor\n\n```shell\n$ cd transactions/demo-typescript\n$ pc-demo-typescript-tests --keep-project\n...\n```\n\n##### Haskell and Rust's tx-village library\n\nThe Haskell implementation of the transactions for the Protocol differs from the\nprevious projects in the sense that all of the previous projects built and\nsubmitted transactions themselves.\nThe Haskell project instead only builds an intermediate data structure, a\n`TxInfo`, which contains sufficient information to build the transactions of the\nproject.\nThe `TxInfo` may then be encoded to JSON using LambdaBuffers and is provided to\nthe `demo-tx-village` Rust CLI which builds a transaction from the `TxInfo` and\nsubmits the transaction.\n\nThe Haskell implementation for building `TxInfo`s of the transactions for the\nProtocol can be found in [transactions/demo-haskell/src/Process.hs](transactions/demo-haskell/src/Process.hs).\n\nThe Rust implementation for building transactions given a `TxInfo` from the\nHaskell project can be found in [transactions/demo-tx-village/src/build_and_submit.rs](transactions/demo-tx-village/src/build_and_submit.rs).\n\nThe testsuite which runs the integration test of piping Haskell's `TxInfo`s to\nRust, and building and submitting the transactions to the blockchain can be\nexecuted with the following commands.\n\n```shell\n# Run the Rust check\n$ nix build .#checks.x86_64-linux.demo-tx-village-checks -L\n...\n```\n\nor\n\n```shell\n$ cd transactions/demo-tx-village\n$ pc-demo-tx-village-tests --keep-project\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlabs-haskell%2Flambda-buffers-for-cardano","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlabs-haskell%2Flambda-buffers-for-cardano","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlabs-haskell%2Flambda-buffers-for-cardano/lists"}