28 个版本

0.3.2 2024 年 5 月 21 日
0.3.0 2023 年 8 月 27 日
0.2.1 2023 年 8 月 3 日
0.2.0 2023 年 7 月 25 日
0.1.8 2022 年 7 月 26 日

#218 in 神奇豆

Download history 163/week @ 2024-05-18 7/week @ 2024-05-25 1/week @ 2024-06-08 154/week @ 2024-06-29 60/week @ 2024-07-27

208 次每月下载

自定义许可

7.5MB
9K SLoC

包含 (Rust 库, 7MB) pkg_wasi/libmarlowe_lang.rlib

Marlowe Lang

crates.io Documentation BuildAndTest npm version PyPI version

如果您只想从 cborHex 解码 marlowe 数据到 json,请访问此处

Marlowe 的 Rust 实现用于 Cardano 智能合约(金融合约)。请参阅 examples 目录以了解与 node/deno/react 等的用法。

请注意,尽管该软件包支持编码和解码链上数据,但该软件包专注于链下部分,使得在 Rust 中创建、管理和理解合约尽可能容易;不会支持创建实际交易。

也没有支持直接与任何 Cardano 或 Marlowe 基础设施通信 - 这纯粹是 Marlowe 的数据类型、语义和序列化的实现。

主要功能

  • 在以下之间编码/解码 Marlowe 类型:MarloweDSL/Rust/Json/CborHex
  • 列出合约中使用的合约参数(扩展 marlowe)
  • 合约参数的初始化(extended-marlowe)。

不稳定功能

  • 通过 'unstable' 功能启用。
  • 合约模拟(semantics::ContractInstance)
  • 列出预期的输入操作(semantics::ContractInstance)

消费库

此软件包可用于 Rust、React、Node、Python、Deno、wasmtime/wasmer 等,有关更多详细信息,请参阅 examples 目录。

命令行工具

安装

rustup default nightly
cargo install marlowe_lang

示例

marlowe_lang_cli -h

Usage: marlowe_lang_cli <COMMAND>

Commands:
  datum        Tools for working with datums
  state        Tools for working with state
  redeemer     Tools for working with inputs/redeemers (marlowe actions)
  contract     Tools for working with contracts
  plutus-data  Tools for working with unknown plutus data
  help         Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help information
  -V, --version  Print version information

marlowe_lang_cli 解码数据

./marlowe_lang datum from-string d8799fd8799f40ffd8799fa1d8799fd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffd8799f4040ffff1a002dc6c0a0a001ffd87c9f9fd8799fd8799fd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffd8799f581ca7f7e57db27c9e2f80c205ccb30f73e57f0ee8fc21aff7b86b5daf7845476c6f6265ffd87a9f19012cffffd87c9f9fd8799fd8799fd8799fd87a80d8799fd8799f581cfd37884bbd044c72e5f29de1b777a9c1c1d531773535cd5b55e2f6ffffd87a80ffffd8799fd87a80d8799fd8799f581cfd37884bbd044c72e5f29de1b777a9c1c1d531773535cd5b55e2f6ffffd87a80ffffd8799f581cecc8ad61b973946ee1cc666b259acabb3edf38a73f1b8779d93ba28a445377616effd87a9f1901f4ffffd87a9fd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffd87a9fd8799fd87a80d8799fd8799f581cfd37884bbd044c72e5f29de1b777a9c1c1d531773535cd5b55e2f6ffffd87a80ffffffd8799f581ca7f7e57db27c9e2f80c205ccb30f73e57f0ee8fc21aff7b86b5daf7845476c6f6265ffd87a9f19012cffd87a9fd8799fd87a80d8799fd8799f581cfd37884bbd044c72e5f29de1b777a9c1c1d531773535cd5b55e2f6ffffd87a80ffffd87a9fd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffffd8799f581cecc8ad61b973946ee1cc666b259acabb3edf38a73f1b8779d93ba28a445377616effd87a9f1901f4ffd87980ffffffff1b0000018386dd2358d87980ffffff1b000001838449f558d87980ffff cbor-hex detailed-text`

State: (MarloweDatumState Accounts([{ (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx"),(Token "" ""),3000000 },]) Bound_Values({}) Choices({}) MinTime(1))    

Continuation: Contract (Marlowe-DSL): When [ (Case (Deposit (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx") (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx") (Token "a7f7e57db27c9e2f80c205ccb30f73e57f0ee8fc21aff7b86b5daf78" "Globe") (Constant 300)) (When [ (Case (Deposit (Address "addr1v87n0zzth5zycuh972w7rdmh48qur4f3wu6ntn2m2h30dlchhlqt3") (Address "addr1v87n0zzth5zycuh972w7rdmh48qur4f3wu6ntn2m2h30dlchhlqt3") (Token "ecc8ad61b973946ee1cc666b259acabb3edf38a73f1b8779d93ba28a" "Swan") (Constant 500)) (Pay (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx") (Party (Address "addr1v87n0zzth5zycuh972w7rdmh48qur4f3wu6ntn2m2h30dlchhlqt3")) (Token "a7f7e57db27c9e2f80c205ccb30f73e57f0ee8fc21aff7b86b5daf78" "Globe") (Constant 300) (Pay (Address "addr1v87n0zzth5zycuh972w7rdmh48qur4f3wu6ntn2m2h30dlchhlqt3") (Party (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx")) (Token "ecc8ad61b973946ee1cc666b259acabb3edf38a73f1b8779d93ba28a" "Swan") (Constant 500) Close))) ] 1664414983000 Close)) ] 1664371783000 Close

marlowe_lang_cli 解码赎回者/输入操作

./marlowe_lang redeemer from-string 9fd8799fd8799fd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffd8799fd87a80d8799fd8799f581c1cb51be3ab4e4b540e86bd4c9be02682db8150f69c3cded2422cc1bfffd87a80ffffd8799f581ca7f7e57db27c9e2f80c205ccb30f73e57f0ee8fc21aff7b86b5daf7845476c6f6265ff19012cffffff cbor-hex marlowe-dsl

RESULT:
 (Deposit (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx") (Address "addr1vywt2xlr4d8yk4qws675exlqy6pdhq2s76wrehkjggkvr0czta9gx") (Token "a7f7e57db27c9e2f80c205ccb30f73e57f0ee8fc21aff7b86b5daf78" "Globe") 300)

marlowe_lang_cli 查询合约的预期输入

marlowe_lang_clicontract from-file .\test_data\swap.marlowe marlowe-dsl expected-actions -i "Timeout for Ada deposit=9999999999,Amount of Ada=4994,Amount of dollars=99,Timeout for dollar deposit=994"`
Log output:
--> INITIALIZED BY MARLOWE LANG STATE MACHINE AT 1672581873
--> Processing When contract

结果(当前合约状态)

{
  "WaitingForInput": [
    {
      "Deposit": {
        "who_is_expected_to_pay": {
          "role_token": "Ada provider"
        },
        "expected_asset_type": {
          "token_name": "",
          "currency_symbol": ""
        },
        "expected_amount": {
          "and": 4994,
          "add": 1000000
        },
        "expected_target_account": {
          "account": {
            "role_token": "Ada provider"
          }
        },
        "continuation": {
          "when": [
            ... // removed from example output for brevity 
          ],
          "timeout_continuation": "close",
          "timeout": 994
        }
      }
    }
  ]
}

依赖项

~9–13MB
~244K SLoC