input-output-hk / marlowe-cardano

Marlowe smart contract language Cardano implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Programmatic approach to converting Marlowe into JSON

pablosymc opened this issue · comments

commented

Currently, the primary method for converting Marlowe into JSON involves using the Marlowe Playground (https://play.marlowe.iohk.io/#/). The process requires entering the code, clicking the "Send to Simulator" button, and then clicking the "Download as JSON" button.

Another way to generate this JSON is through the marlowe-cli template command. This command allows you to input parameters and designate the output contract and state file locations. However, what if one wants to develop a tool that takes in Marlowe code, outputs JSON from it, and can interact with the Marlowe Runtime REST API?

Based on my discussions in the Discord channel, Marlowe can be converted into JSON using the library available at https://github.com/input-output-hk/purescript-marlowe, as well as the Haskell library. However, these methods may present challenges to an average developer unfamiliar with these languages. It could be frustrating to rely on either the Playground or having to learn a language like Haskell or PureScript just to perform this conversion.

Given the ubiquity of JavaScript, it would be beneficial to have a package capable of converting Marlowe into JSON in an environment like NodeJS. Ideally, this package would offer the same functionality as the marlowe-cli template command. As an alternative approach, and since marlowe-cli already supports creating JSON from a Marlowe template, allowing us to specify a contract.marlowe file instead of a template could also be a viable solution. If necessary, one could create a wrapper around the command for further customization.

I should note that there is a CLI tool that does basically what i'm describing above https://github.com/OlofBlomqvist/marlowe_lang. It offers the ability to do something like:

marlowe_lang_cli contract from-file -i "SomeTimeout=1234,Price=123" contract.marlowe marlowe-dsl json

Would love for something like this to be supported with the marlowe-cli command!

This is a nice feature request. I'd hope we could get it expanded a bit so it can be a bidirectional tool.

marlowe -> json
json -> marlowe

I too was deep in the purescript and playground packages and quickly got lost in haskell. simple command line tool or (better yet, added to marlowe-cli) would be great.

Parsing and printing of Marlowe contracts in different formats has been added to the Marlowe command line tool. marlowe-cli format allows to parse and print a Marlowe contract in the following formats:

  • Json
  • Yaml
  • Marlowe

marlowe-cli format --help shows the help text for the command