Skip to content

Commit

Permalink
add some examples cases and move helper the utils from cardano-crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
OlofBlomqvist committed Jul 3, 2023
1 parent ff09704 commit 791a0bf
Show file tree
Hide file tree
Showing 41 changed files with 5,564 additions and 81,117 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.vscode
**/*/node_modules
12 changes: 12 additions & 0 deletions examples/deno/app.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const m = await import('npm:marlowe_lang@0.1.22-experimental1');

let redeemer = m.decode_marlowe_input_cbor_hex("9fd8799fd87a9fd8799f4763686f69636531d8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffff02ffffff")
let datum = m.decode_cborhex_marlowe_plutus_datum ("d8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffd8799f4040ffff1a002dc6c0a1d8799f4763686f69636531d8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffff02a01b0000018709761f88ffd87c9f9fd8799fd87a9fd8799f4763686f69636532d8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffff9fd8799f0304ffffffd87980ffff1b0000019ce9379560d87980ffff")

let simpleMarloweDslContract = "Close"
let json = m.marlowe_to_json(simpleMarloweDslContract)

console.log("dsl_to_json_encoded_contract",json)
console.log("Decoded redeemer",redeemer)
console.log("Decoded datum",datum)

21 changes: 21 additions & 0 deletions examples/deno/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "deno",
"version": "1.0.0",
"description": "```bash\r deno run --allow-net --allow-read --allow-sys --allow-env .\\index.js\r ```",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"marlowe_lang": "^0.1.22-experimental1"
}
}
78 changes: 78 additions & 0 deletions examples/deno/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Basic example of how to use marlowe_lang in Deno.

```bash
deno run --allow-net --allow-read --allow-sys --allow-env .\index.js
```

```
marlowe_lang utils initialized.
dsl_to_json_encoded_contract "close"
Decoded redeemer {
"Ok": [
{
"for_choice_id": {
"choice_owner": {
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
"choice_name": "choice1"
},
"input_that_chooses_num": 2
}
]
}
Decoded datum {
"marlowe_params": "",
"state": {
"accounts": [
[
[
{
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
{
"token_name": "",
"currency_symbol": ""
}
],
3000000
]
],
"choices": [
[
{
"choice_owner": {
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
"choice_name": "choice1"
},
2
]
],
"boundValues": [],
"minTime": 1679490949000
},
"contract": {
"when": [
{
"then": "close",
"case": {
"for_choice": {
"choice_owner": {
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
"choice_name": "choice2"
},
"choose_between": [
{
"to": 4,
"from": 3
}
]
}
}
],
"timeout_continuation": "close",
"timeout": 1773439260000
}
}
```
19 changes: 19 additions & 0 deletions examples/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<script type="module">
import init, {
marlowe_to_json
} from './path/to/marlowe_lang.js';
async function run() {
await init();
let example = marlowe_to_json("Close")
console.log("result",example)
}
run();
</script>
</body>

</html>
5 changes: 5 additions & 0 deletions examples/html/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Basic example how how to load marlowe_lang in browsers.

1. Use the build script for wasm_web
2. Host the resulting pkg_web together with the index.html (update as needed)
3. Profit?
45 changes: 0 additions & 45 deletions examples/index.html

This file was deleted.

16 changes: 0 additions & 16 deletions examples/node_app/app.js

This file was deleted.

11 changes: 11 additions & 0 deletions examples/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const m = require('marlowe_lang');

let redeemer = m.decode_marlowe_input_cbor_hex("9fd8799fd87a9fd8799f4763686f69636531d8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffff02ffffff")
let datum = m.decode_cborhex_marlowe_plutus_datum ("d8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffd8799f4040ffff1a002dc6c0a1d8799f4763686f69636531d8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffff02a01b0000018709761f88ffd87c9f9fd8799fd87a9fd8799f4763686f69636532d8799fd87980d8799fd8799f581c22584b09e116a2b98819723bbe6eb65d01e1edc225fc2a3e46884d58ffd8799fd8799fd8799f581cb1131cc98fc9ff8936a281874115fce0b73f99b40542172c8eb223b9ffffffffffff9fd8799f0304ffffffd87980ffff1b0000019ce9379560d87980ffff")

let simpleMarloweDslContract = "Close"
let json = m.marlowe_to_json(simpleMarloweDslContract)

console.log("dsl_to_json_encoded_contract",json)
console.log("Decoded redeemer",redeemer)
console.log("Decoded datum",datum)
21 changes: 21 additions & 0 deletions examples/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions examples/node_app/package.json → examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
"Olof Blomqvist <olof@twnet.se>"
],
"description": "experimental parser lib for Cardano Marlowe DSL",
"version": "0.1.12",
"version": "0.0.1",
"license": "SEE LICENSE IN licence",
"repository": {
"type": "git",
"url": "https://github.com/OlofBlomqvist/marlowe_rust"
},
"files": [
"marlowe_lang_bg.wasm",
"marlowe_lang.js",
"marlowe_lang.d.ts"
],
"module": "marlowe_lang.js",
"types": "marlowe_lang.d.ts",
"sideEffects": false,
"type": "module"
"dependencies": {
"marlowe_lang": "0.1.22-experimental1"
}
}
80 changes: 80 additions & 0 deletions examples/nodejs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Basic example for using marlowe_lang in a basic nodejs application

```bash
npm install
node .\index.js
```


```
marlowe_lang utils initialized.
dsl_to_json_encoded_contract "close"
Decoded redeemer {
"Ok": [
{
"for_choice_id": {
"choice_owner": {
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
"choice_name": "choice1"
},
"input_that_chooses_num": 2
}
]
}
Decoded datum {
"marlowe_params": "",
"state": {
"accounts": [
[
[
{
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
{
"token_name": "",
"currency_symbol": ""
}
],
3000000
]
],
"choices": [
[
{
"choice_owner": {
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
"choice_name": "choice1"
},
2
]
],
"boundValues": [],
"minTime": 1679490949000
},
"contract": {
"when": [
{
"then": "close",
"case": {
"for_choice": {
"choice_owner": {
"address": "addr_test1qq39sjcfuyt29wvgr9erh0nwkewsrc0dcgjlc237g6yy6k93zvwvnr7fl7yndg5psaq3tl8qkulendq9ggtjer4jywusugp3gf"
},
"choice_name": "choice2"
},
"choose_between": [
{
"to": 4,
"from": 3
}
]
}
}
],
"timeout_continuation": "close",
"timeout": 1773439260000
}
}
```
3 changes: 3 additions & 0 deletions examples/react/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
Loading

0 comments on commit 791a0bf

Please sign in to comment.