input-output-hk / marlowe-ts-sdk

Marlowe TypeScript SDK
https://marlowe.iohk.io/
Apache License 2.0
22 stars 11 forks source link

Experimental feature: Add @marlowe.io/marlowe-template package #184

Closed hrajchert closed 9 months ago

hrajchert commented 9 months ago

When you create a Marlowe contract using the ts-sdk, it is common to have a template function that receives some Parameters/Schema/Blueprint and generates either a Contract or ContractBundleMap. When you want another participant to know if a given contract is an instance of your template, the other participant must have the same template function applied with the same parameters.

Sharing the template function is easy and generally solved by using the same web DAPP. The template parameters, on the other hand, need to be shared differently.

It is easy to see how this PR simplifies the Parameter sharing In the marlowe-object-flow.ts example changes. Before, we manually defined the type DelayPaymentScheme and two functions (extractSchemeFromTags and mkDelayPaymentTags) to decode and encode the Scheme as Tags. Now, we manually define the MarloweTemplate but we infer the DelayPaymentParameters type and the decoding and encoding function as Metadata are provided by the package.

Summary by CodeRabbit

Summary by CodeRabbit

coderabbitai[bot] commented 9 months ago

Walkthrough

This update introduces significant enhancements to the development environment and the core functionality of a TypeScript-based project. It focuses on improving debugging configurations, refining the handling and validation of data types, and advancing the project's architecture through the introduction of a new blueprint package. Additionally, the update modernizes the contract creation logic and payment scheme in a specific example, showcasing the practical application of the newly introduced concepts and tools.

Changes

Files Change Summary
.vscode/settings.json Added paths for blueprint dist and test-dist JS files to outFiles.
examples/nodejs/src/marlowe-object-flow.ts Updated contract logic, introduced Metadata type, and refined payment scheme with new identifiers.
jest.unit.config.js Added Jest unit test config for blueprint.
jsdelivr-npm-importmap.js Added entry for @marlowe.io/blueprint.
packages/adapter/src/bigint.ts Introduced BigIntOrNumber type and guard.
packages/blueprint/... (multiple files) Introduced the blueprint package with core functionality, codecs, and tests.
packages/runtime/core/src/... (address, metadata) Updated address validation and refined metadata types.

šŸ‡āœØ
In a world of code, where bugs often strode,
Came a blueprint, so bold, its story to be told.
With types so refined, and contracts designed,
A rabbit hopped along, improvements it aligned.
"To the future," it said, "with leaps, not dread,
For our code is now stronger, and far ahead."
šŸŒŸšŸ¾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

Tips ### Chat There are 3 ways to chat with CodeRabbit: - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit-tests for this file.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit tests for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository from git and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit tests.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - The JSON schema for the configuration file is available [here](https://coderabbit.ai/integrations/coderabbit-overrides.v2.json). - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json` ### CodeRabbit Discord Community Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback.