Created
September 13, 2022 20:06
-
-
Save bwbush/3713d51af8276a7c3a081f6c613c7a18 to your computer and use it in GitHub Desktop.
Demonstration that one cannot close a Marlowe contract while opening another in the same transaction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "8242e735-08b7-494c-9040-d4b752fd61a4", | |
"metadata": {}, | |
"source": [ | |
"# Running Marlowe with a Reference Script\n", | |
"\n", | |
"**Executive Summary**\n", | |
"\n", | |
"This example shows how to use the `marlowe-cli` and `cardano-cli` tools to submit Marlowe transactions that involve reference scripts. The `marlowe-cli` tool is used to generate the script, datum, and redeemers, while the `cardano-cli` tool is used to submit transactions and query the blockchain. Using a reference script significantly reduces the cost of a Marlowe transaction." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ee0c6658-db99-4ef1-918a-cd73aeda29ff", | |
"metadata": {}, | |
"source": [ | |
"## Preliminaries" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "13ae40be-3d3c-45a9-a766-f0380228e03d", | |
"metadata": {}, | |
"source": [ | |
"Record the versions of the tools used." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 70, | |
"id": "b0383ad0-f776-4eb2-95ef-c0184a19e741", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"cardano-cli 1.35.3 - linux-x86_64 - ghc-8.10\n", | |
"git rev 0000000000000000000000000000000000000000\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli --version" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 71, | |
"id": "69434d67-95cd-4e88-90e1-d752cb9f7e87", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"marlowe-cli 0.0.7.0\n" | |
] | |
} | |
], | |
"source": [ | |
"export PATH=/home/bbush/.cabal/bin:$PATH\n", | |
"marlowe-cli --version" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "06697dda-a867-4bc5-b5c7-001d03256138", | |
"metadata": {}, | |
"source": [ | |
"## 1. Select the network\n", | |
"\n", | |
"We use the `preview` network. See [the configuration files](https://book.world.dev.cardano.org/environments.html#preview-testnet) and use [faucet](https://faucet.preview.world.dev.cardano.org/basic-faucet)." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 72, | |
"id": "ba5d0bc3-c852-4587-b0b8-48a5d65d7847", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"export CARDANO_TESTNET_MAGIC=2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 73, | |
"id": "57e1813f-a614-4981-a016-aedb9684da47", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"export CARDANO_NODE_SOCKET_PATH=/extra/iohk/networks/preview/node.socket" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "120095ab-0c17-4aef-bd02-5a6e1e7a6e7d", | |
"metadata": {}, | |
"source": [ | |
"Find the current tip" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 74, | |
"id": "f5387df4-2cb8-480a-8fe6-b430cb85af02", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The tip of the blockchain is at slot 3095919.\n" | |
] | |
} | |
], | |
"source": [ | |
"TIP=$(cardano-cli query tip --testnet-magic \"$CARDANO_TESTNET_MAGIC\" | jq .slot)\n", | |
"echo \"The tip of the blockchain is at slot $TIP.\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "135364c2-1a93-4806-8aca-c26691a4d2f7", | |
"metadata": {}, | |
"source": [ | |
"Retrieve the protocol parameters." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 75, | |
"id": "ab70c275-d534-40a0-b514-3d1993d5ec2a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"cardano-cli query protocol-parameters --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --out-file reference-script.protocol" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "38eb8467-8233-45ce-8a4a-23aadcfd6e2c", | |
"metadata": {}, | |
"source": [ | |
"We've empirically determined the slotting parameters for this network." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 76, | |
"id": "94039778-2768-4bb2-8402-87fdd8f22de5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"SLOT_OFFSET=$((1660003200 * 1000)) # POSIX milliseconds for slot zero\n", | |
"SLOT_SPACING=1000 # milliseconds per slot" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 77, | |
"id": "6297879b-29c8-40d0-af85-425783a22b26", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1660003200000\n" | |
] | |
} | |
], | |
"source": [ | |
"echo $SLOT_OFFSET" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a941d9fa-8d96-4bc3-be45-cccfcf3af06f", | |
"metadata": {}, | |
"source": [ | |
"Convert a slot number to POSIX milliseconds." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 78, | |
"id": "f16e9a13-a5e0-4eed-9f65-d6c3af2cca0b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"function slot2time () {\n", | |
" echo $(($1 * SLOT_SPACING + SLOT_OFFSET))\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c9c76098-25da-420d-ae13-c567aaaa567c", | |
"metadata": {}, | |
"source": [ | |
"Convert POSIX milliseconds to a slot number." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 79, | |
"id": "82fba019-1cf4-43c8-baa8-9a0a1399ef0d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"function time2slot () {\n", | |
" echo $((($1 - SLOT_OFFSET) / SLOT_SPACING))\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "caedded9-7e2d-4c90-993c-e47c92168b77", | |
"metadata": {}, | |
"source": [ | |
"Test the time conversion functions." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 80, | |
"id": "56cb6200-5f92-42e6-9e28-b1b1230e5326", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1663099119000\n" | |
] | |
} | |
], | |
"source": [ | |
"NOW=$(slot2time $TIP)\n", | |
"echo $NOW" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 81, | |
"id": "e5a2f995-8a89-4b7a-940f-8a76dc5e1179", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Compare 3095919 to 3095919.\n" | |
] | |
} | |
], | |
"source": [ | |
"echo \"Compare $(time2slot $NOW) to $TIP.\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "27da618b-3c95-49a9-ad90-37398c03abda", | |
"metadata": {}, | |
"source": [ | |
"Define some time constants, for convenience." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 82, | |
"id": "6d0e7c40-273a-4e78-8197-aa10ed631f4a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"SECOND=1000 # milliseconds per second\n", | |
"MINUTE=$((60 * SECOND)) # milliseconds per minute\n", | |
"HOUR=$((60 * MINUTE)) # milliseconds per hour\n", | |
"DAY=$((24 * HOUR)) # milliseconds per day" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "3a4c2015-62ec-4434-959c-cc4df3ef3ac6", | |
"metadata": {}, | |
"source": [ | |
"Define a constant for Ada." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 83, | |
"id": "f809c11f-5411-4d67-a781-16ef0cdbd162", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ADA=1000000 # Lovelace per Ada" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "be518122-4b8b-4024-867a-0f0989aaf41d", | |
"metadata": {}, | |
"source": [ | |
"## 2. Select the signing and payment keys\n", | |
"\n", | |
"Use pre-existing stakeless keys for this example." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 84, | |
"id": "e34426b4-c24b-478e-b111-a6212b058764", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"PAYMENT_SKEY=/extra/iohk/networks/treasury/payment.skey\n", | |
"PAYMENT_VKEY=/extra/iohk/networks/treasury/payment.vkey" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "e613ac4e-a3a6-4023-9ef2-64461b20d310", | |
"metadata": {}, | |
"source": [ | |
"Compute the address." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 85, | |
"id": "cb55a5ca-a70c-41a7-80ae-9296e4f65cd9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"addr_test1vq9prvx8ufwutkwxx9cmmuuajaqmjqwujqlp9d8pvg6gupczgtm9j\n" | |
] | |
} | |
], | |
"source": [ | |
"ADDRESS_P=$(cardano-cli address build --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --payment-verification-key-file \"$PAYMENT_VKEY\")\n", | |
"echo $ADDRESS_P" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b68813f8-93e5-4be7-a729-1f105458f27b", | |
"metadata": {}, | |
"source": [ | |
"Compute the public key hash." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 86, | |
"id": "73a2ab58-de2b-4842-82d9-93eb9bf1f3c2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n" | |
] | |
} | |
], | |
"source": [ | |
"PUBKEYHASH_P=$(cardano-cli address key-hash --payment-verification-key-file \"$PAYMENT_VKEY\")\n", | |
"echo $PUBKEYHASH_P" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "cd85e76c-a335-4c32-a4d5-36ab4c1df93f", | |
"metadata": {}, | |
"source": [ | |
"Find a UTxO that we can use the fund the contract." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 87, | |
"id": "55626bf2-5740-46d4-8121-3d5aebfeb227", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"0e03dd60563721d860efd7e5a9ec22435ceb84e444bfc9d552a97e07203e0db3 0 189320941979 lovelace + TxOutDatumNone\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_P\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "f477d600-9393-40bd-97ef-db900b7393f5", | |
"metadata": {}, | |
"source": [ | |
"Select a UTxO to fund the later transactions." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 88, | |
"id": "717e7e15-b35c-44f4-83c5-018117d95f5b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"TX_0=\"0e03dd60563721d860efd7e5a9ec22435ceb84e444bfc9d552a97e07203e0db3#0\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ad2aa39f-2148-46ff-aa69-87e4585c7191", | |
"metadata": {}, | |
"source": [ | |
"## 3. Design the Marlowe contract\n", | |
"\n", | |
"For this demonstraction we just use a simple contract that involves two notifications and the refund of the Ada at the script address. Use the [Marlowe Playground](https://marlowe-playground-staging.plutus.aws.iohkdev.io/#/blockly) to create this contract and the \"Download JSON\" button to access the JSON representation of the contract.\n", | |
"\n", | |
"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9f230081-f390-472f-b3ac-51633b51323d", | |
"metadata": {}, | |
"source": [ | |
"We customize the downloaded JSON with our own timeout values." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 89, | |
"id": "f63ba44b-dec3-4797-a932-03f0e79ca7c4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1665691119000\n" | |
] | |
} | |
], | |
"source": [ | |
"TIMEOUT=$((NOW + 30 * DAY))\n", | |
"echo $TIMEOUT" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a16ad307-5abe-40be-aab0-c94979584ecb", | |
"metadata": {}, | |
"source": [ | |
"### 3.1. Creation" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "1b442906-ed7b-4298-b1d3-c213aae6922d", | |
"metadata": {}, | |
"source": [ | |
"The initial contract has two notifications." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 90, | |
"id": "18d03550-a9d4-476d-a49a-0fe959bfa91e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"timeout: 1665691119000\n", | |
"timeout_continuation: close\n", | |
"when:\n", | |
"- case:\n", | |
" notify_if: true\n", | |
" then:\n", | |
" timeout: 1665691119000\n", | |
" timeout_continuation: close\n", | |
" when:\n", | |
" - case:\n", | |
" notify_if: true\n", | |
" then: close\n" | |
] | |
} | |
], | |
"source": [ | |
"cat > reference-script-1.contract << EOI\n", | |
"{\n", | |
" \"when\" : [\n", | |
" {\n", | |
" \"case\" : { \"notify_if\" : true },\n", | |
" \"then\" : {\n", | |
" \"when\" : [\n", | |
" {\n", | |
" \"case\" : { \"notify_if\" : true },\n", | |
" \"then\" : \"close\"\n", | |
" }\n", | |
" ],\n", | |
" \"timeout\": $TIMEOUT,\n", | |
" \"timeout_continuation\" : \"close\"\n", | |
" }\n", | |
" }\n", | |
" ],\n", | |
" \"timeout\" : $TIMEOUT,\n", | |
" \"timeout_continuation\" : \"close\"\n", | |
"}\n", | |
"EOI\n", | |
"json2yaml reference-script-1.contract" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "861e6b77-4fea-4627-92cb-c61dea4b49b4", | |
"metadata": {}, | |
"source": [ | |
"We set the initial state to hold a small amount of Ada." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 91, | |
"id": "845a111f-e2e8-4f15-9bdd-1a2428d26e7b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ACCOUNT_LOVELACE=$((3 * ADA))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 92, | |
"id": "01a2d6de-e71a-408a-a238-91a3763d36f9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"accounts:\n", | |
"- - - pk_hash: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n", | |
" - currency_symbol: ''\n", | |
" token_name: ''\n", | |
" - 3000000\n", | |
"boundValues: []\n", | |
"choices: []\n", | |
"minTime: 1663099119000\n" | |
] | |
} | |
], | |
"source": [ | |
"cat << EOI > reference-script-1.state\n", | |
"{\n", | |
" \"accounts\" : [\n", | |
" [\n", | |
" [\n", | |
" { \"pk_hash\" : \"$PUBKEYHASH_P\" },\n", | |
" { \"currency_symbol\" : \"\", \"token_name\" : \"\" }\n", | |
" ],\n", | |
" $ACCOUNT_LOVELACE\n", | |
" ]\n", | |
" ],\n", | |
" \"choices\" : [],\n", | |
" \"boundValues\" : [],\n", | |
" \"minTime\" : $NOW\n", | |
"}\n", | |
"EOI\n", | |
"json2yaml reference-script-1.state" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "021e986d-a0dd-4ced-ab2b-0f3b98a330df", | |
"metadata": {}, | |
"source": [ | |
"### 3.2. First notification\n", | |
"\n", | |
"We send an `INotify` to the contract." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 93, | |
"id": "704e49cc-0eef-45c6-a87c-c374ebb6b3c6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"input_notify\n", | |
"...\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli input notify > reference-script-1.input\n", | |
"json2yaml reference-script-1.input" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "0b96ca03-adaa-44da-b47d-a9c5a841b66f", | |
"metadata": {}, | |
"source": [ | |
"The contract then becomes much simpler." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 94, | |
"id": "9d134a22-48ca-4614-96de-1f920156ee1d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"timeout: 1665691119000\n", | |
"timeout_continuation: close\n", | |
"when:\n", | |
"- case:\n", | |
" notify_if: true\n", | |
" then: close\n" | |
] | |
} | |
], | |
"source": [ | |
"cat > reference-script-2.contract << EOI\n", | |
"{\n", | |
" \"when\" : [\n", | |
" {\n", | |
" \"case\" : { \"notify_if\" : true },\n", | |
" \"then\" : \"close\"\n", | |
" }\n", | |
" ],\n", | |
" \"timeout\" : $TIMEOUT,\n", | |
" \"timeout_continuation\" : \"close\"\n", | |
"}\n", | |
"EOI\n", | |
"json2yaml reference-script-2.contract" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ec8808a6-365b-4324-b319-8fe39bdfb1a4", | |
"metadata": {}, | |
"source": [ | |
"We plan to submit the input within the following validity range." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 95, | |
"id": "94dcb267-6008-4419-b919-6d240f26993f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3095919 3113919\n" | |
] | |
} | |
], | |
"source": [ | |
"INVALID_BEFORE=$(time2slot $NOW)\n", | |
"INVALID_HEREAFTER=$(time2slot $((NOW + 5 * HOUR)))\n", | |
"echo \"$INVALID_BEFORE $INVALID_HEREAFTER\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "f88eadbc-df72-4231-b55c-823769e29edb", | |
"metadata": {}, | |
"source": [ | |
"This means that the state after the first input will be the same as the previous state, since no adjustment of `minTime` occurs due to this validity range." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 96, | |
"id": "32482236-24b5-42d0-afaf-01f296b94e38", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"accounts:\n", | |
"- - - pk_hash: 0a11b0c7e25dc5d9c63171bdf39d9741b901dc903e12b4e162348e07\n", | |
" - currency_symbol: ''\n", | |
" token_name: ''\n", | |
" - 3000000\n", | |
"boundValues: []\n", | |
"choices: []\n", | |
"minTime: 1663099119000\n" | |
] | |
} | |
], | |
"source": [ | |
"cat << EOI > reference-script-2.state\n", | |
"{\n", | |
" \"accounts\" : [\n", | |
" [\n", | |
" [\n", | |
" { \"pk_hash\" : \"$PUBKEYHASH_P\" },\n", | |
" { \"currency_symbol\" : \"\", \"token_name\" : \"\" }\n", | |
" ],\n", | |
" $ACCOUNT_LOVELACE\n", | |
" ]\n", | |
" ],\n", | |
" \"choices\" : [],\n", | |
" \"boundValues\" : [],\n", | |
" \"minTime\" : $NOW\n", | |
"}\n", | |
"EOI\n", | |
"json2yaml reference-script-2.state" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6b4b340f-a073-453e-87da-f0749fecf917", | |
"metadata": { | |
"tags": [] | |
}, | |
"source": [ | |
"### 3.3. Second notification and closure\n", | |
"\n", | |
"We send another `INotify` to the contract, which causes it to close." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 97, | |
"id": "5178199e-9d70-4739-b7d6-ad7abb3fbb3c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"input_notify\n", | |
"...\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli input notify > reference-script-2.input\n", | |
"json2yaml reference-script-2.input" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "f227d39e-d885-4667-9ebe-4ca9d0d10236", | |
"metadata": {}, | |
"source": [ | |
"The contract just becomes `Close`." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 98, | |
"id": "11cb3278-a0bf-4268-b99b-65e4e44adc19", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"close\n", | |
"...\n" | |
] | |
} | |
], | |
"source": [ | |
"cat > reference-script-3.contract << EOI\n", | |
"\"close\"\n", | |
"EOI\n", | |
"json2yaml reference-script-3.contract" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9918a92c-2206-43f6-a612-006fa22cb24a", | |
"metadata": {}, | |
"source": [ | |
"The state becomes empty." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 99, | |
"id": "22ac5352-e534-4158-b08a-4beb7e870b09", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"accounts: []\n", | |
"boundValues: []\n", | |
"choices: []\n", | |
"minTime: 1663099119000\n" | |
] | |
} | |
], | |
"source": [ | |
"cat << EOI > reference-script-3.state\n", | |
"{\n", | |
" \"accounts\" : [],\n", | |
" \"choices\" : [],\n", | |
" \"boundValues\" : [],\n", | |
" \"minTime\" : $NOW\n", | |
"}\n", | |
"EOI\n", | |
"json2yaml reference-script-3.state" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "0cef9780-cf87-43c2-a5e5-88a9773eff7f", | |
"metadata": {}, | |
"source": [ | |
"## 4. Run the transactions" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "61e7a525-e807-4ae5-8310-c0c5ccdddf25", | |
"metadata": {}, | |
"source": [ | |
"### 4.1 Store the reference script on chain" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "313ad5c7-eadc-478b-9b5a-73c2dcae79f2", | |
"metadata": {}, | |
"source": [ | |
"Compute the address of the Marlowe validator." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 100, | |
"id": "8144d440-c70e-4d82-8288-e2444b7577eb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"addr_test1wqzuhefwzq4259vk0d8hmaw6gmc43ag2xju0u8ydmw8s7zqy9m35h\n" | |
] | |
} | |
], | |
"source": [ | |
"ADDRESS_S=$(marlowe-cli contract address)\n", | |
"echo $ADDRESS_S" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a38f3400-8d38-4a20-9a26-a734d4845ddd", | |
"metadata": {}, | |
"source": [ | |
"Export the Marlowe validator itself." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 101, | |
"id": "bb523912-409d-412c-b7c0-9a95ee14f403", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"addr_test1wqzuhefwzq4259vk0d8hmaw6gmc43ag2xju0u8ydmw8s7zqy9m35h\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli contract validator --out-file reference-script.plutus" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 102, | |
"id": "b9be3e5c-e368-48f8-86e4-f930bca00eec", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{\n", | |
" \"type\": \"PlutusScriptV2\",\n", | |
" \"description\": \"\",\n", | |
" \"cborHex\": \"59319159318e01000033232323322323232323232323232323232323233223232323232323232323232323322323232323232323232332233223232323232323322323232323232323232323232332233223232323232323232323232323232323232323232323232323232323232323232323232323322323232323232323232323232323232323232323223222232325335333222350032232322350062323232323223353235001223500223223355335333573466e2000400c22c04228044c0d0c8488c00400ccd542180400c00454cd4ccd5cd19b88001501008b0108a0113034332212233002004003501033550860100300113322122330010040033355086015002001350112222333308901004003002500623033122222300200622533335333333305308c01002001010006509d01509d01130341222220051303412222200313034122222004222221533500513333038004003002001153333335015221303b03c13501822225335333355307612001505e2209701004096011303d03e1333303c0080070060052221303c03d2221303c03d222221303e03f2221303c03d15335333573466e2400540382240422004540384004cc8848cc00400c008d4d401c88888888888801488d400" | |
] | |
} | |
], | |
"source": [ | |
"head -c 1000 reference-script.plutus" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ee5c6fdc-24c2-42ba-8c18-93e5a3d1b534", | |
"metadata": {}, | |
"source": [ | |
"Build the transaction to store the reference script for Marlowe on the blockchain." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 103, | |
"id": "4c620edd-882d-4280-9430-40550d9a8fca", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Estimated transaction fee: Lovelace 724521\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction build --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --babbage-era \\\n", | |
" --protocol-params-file reference-script.protocol \\\n", | |
" --tx-in \"$TX_0\" \\\n", | |
" --tx-out \"$ADDRESS_P+$((60 * ADA))\" \\\n", | |
" --tx-out-reference-script-file reference-script.plutus \\\n", | |
" --change-address \"$ADDRESS_P\" \\\n", | |
" --out-file tx-1.raw" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "d2632e9c-4463-44d9-8acf-de02f3fa9364", | |
"metadata": {}, | |
"source": [ | |
"Sign the transaction." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 104, | |
"id": "cfbf1cc5-dc09-4bd1-99f4-f5ae6d5ffa87", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"cardano-cli transaction sign --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-body-file tx-1.raw \\\n", | |
" --signing-key-file \"$PAYMENT_SKEY\" \\\n", | |
" --out-file tx-1.signed" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "d06e2f6a-2885-47d4-8288-c187ee5a3f07", | |
"metadata": {}, | |
"source": [ | |
"Submit the transaction, and wait for it to be confirmed." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 105, | |
"id": "75bf591a-33a9-4ba0-aa50-cc8cbca5a755", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Transaction successfully submitted.\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction submit --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-file tx-1.signed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 106, | |
"id": "6ef38473-43ef-4907-891b-063e585c2e60", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"4212b8d9e2d22f3aa462e4046a672cfabeec76569d46d8df0032805c69f27582 0 189260217458 lovelace + TxOutDatumNone\n", | |
"4212b8d9e2d22f3aa462e4046a672cfabeec76569d46d8df0032805c69f27582 1 60000000 lovelace + TxOutDatumNone\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_P\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "96a40bbd-20d9-4de7-82ec-3e220a4ebcd3", | |
"metadata": {}, | |
"source": [ | |
"Record the transaction ID and the ID of the UTxO holding the reference script." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 107, | |
"id": "160147b2-0cce-4273-94bd-186a1cc48355", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"TX_1=4212b8d9e2d22f3aa462e4046a672cfabeec76569d46d8df0032805c69f27582\n", | |
"TX_S=\"$TX_1#1\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "57d145ca-05b2-491a-be9d-f8dc9a83f28f", | |
"metadata": {}, | |
"source": [ | |
"### 4.2. Creation\n", | |
"\n", | |
"Bundle the contract and state, computing the datum and script." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 108, | |
"id": "b4eec428-ee73-43b4-b40d-9f8c877053cf", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Bare-validator cost: ExBudget {exBudgetCPU = ExCPU 18515100, exBudgetMemory = ExMemory 80600}\n", | |
"Validator size: 12689\n", | |
"Datum size: 139\n", | |
"Redeemer size: 3\n", | |
"Total size: 12831\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli contract marlowe --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --contract-file reference-script-1.contract \\\n", | |
" --state-file reference-script-1.state \\\n", | |
" --out-file reference-script-1.marlowe \\\n", | |
" --print-stats" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "cc9182ef-94f8-41bf-9776-00135165832f", | |
"metadata": {}, | |
"source": [ | |
"Extract the datum." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 109, | |
"id": "1117eb26-7106-4859-865f-a59c2192178d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"jq '.datum.json' reference-script-1.marlowe > reference-script-1.datum" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "89f3a698-2d30-417c-a4ae-448ee004413b", | |
"metadata": {}, | |
"source": [ | |
"Build the transaction to create the Marlowe contract." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 110, | |
"id": "a126d8da-30f9-44da-ba99-d336a79ed1af", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Estimated transaction fee: Lovelace 175005\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction build --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --babbage-era \\\n", | |
" --protocol-params-file reference-script.protocol \\\n", | |
" --tx-in \"$TX_1#0\" \\\n", | |
" --tx-out \"$ADDRESS_S+$ACCOUNT_LOVELACE\" \\\n", | |
" --tx-out-datum-embed-file reference-script-1.datum \\\n", | |
" --change-address \"$ADDRESS_P\" \\\n", | |
" --out-file tx-2.raw" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "586f5c59-4337-440f-a5f7-6a62ce9a0592", | |
"metadata": {}, | |
"source": [ | |
"Sign the transaction." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 111, | |
"id": "0bf36fa8-ab0d-4a83-88dc-609477df69d4", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"cardano-cli transaction sign --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-body-file tx-2.raw \\\n", | |
" --signing-key-file \"$PAYMENT_SKEY\" \\\n", | |
" --out-file tx-2.signed" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c5bd18cc-e683-4464-8b44-a657492e2703", | |
"metadata": {}, | |
"source": [ | |
"Submit the transaction." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 112, | |
"id": "50066674-2088-437e-9555-c68d1e4aa717", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Transaction successfully submitted.\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction submit --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-file tx-2.signed" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "1bddb83f-cb4d-44ab-ac9d-8624fb05eefa", | |
"metadata": {}, | |
"source": [ | |
"Wait for the transaction to be confirmed. (One can check the node logs to see when the confirmation has occurred.)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "df448c2b-e60d-4920-a78c-e61e051eae71", | |
"metadata": {}, | |
"source": [ | |
"See that the change has been received" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 113, | |
"id": "153f2874-af6d-4a48-a5d7-1433c1827409", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"4212b8d9e2d22f3aa462e4046a672cfabeec76569d46d8df0032805c69f27582 1 60000000 lovelace + TxOutDatumNone\n", | |
"959e6fc3e5dd53d895812b1c169b9c07bd44fae29de568a4d9b2e90e97588079 0 189257042453 lovelace + TxOutDatumNone\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_P\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "3c511e3f-9dbc-45bc-a53b-e1134ef646b3", | |
"metadata": {}, | |
"source": [ | |
"Record the transaction ID." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 114, | |
"id": "d60f8afb-9848-4c4d-8e03-e47674b650a9", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"TX_2=959e6fc3e5dd53d895812b1c169b9c07bd44fae29de568a4d9b2e90e97588079" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "02277513-e597-4055-a413-1f4a4625a22b", | |
"metadata": {}, | |
"source": [ | |
"View the transaction at the script address." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 115, | |
"id": "0747c02c-0d3f-4934-bbe8-bda57be70ed8", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"959e6fc3e5dd53d895812b1c169b9c07bd44fae29de568a4d9b2e90e97588079 1 3000000 lovelace + TxOutDatumHash ScriptDataInBabbageEra \"58f2ef575fc5499c83649b184ec0fa241d7ff9911efc6eaef0d378a29fd8327d\"\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_S\" | sed -n -e \"1,2p;/^$TX_2/p\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "1cc04f20-1e34-4af7-bfae-27b0b4e203a5", | |
"metadata": {}, | |
"source": [ | |
"### 4.3. First notification\n", | |
"\n", | |
"Bundle the contract and state, computing the redeemer, datum, and script." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 116, | |
"id": "ed96f465-d8e7-43d0-ab48-fb27dab83e0a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Bare-validator cost: ExBudget {exBudgetCPU = ExCPU 18515100, exBudgetMemory = ExMemory 80600}\n", | |
"Validator size: 12689\n", | |
"Datum size: 109\n", | |
"Redeemer size: 11\n", | |
"Total size: 12809\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli contract marlowe --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --input-file reference-script-1.input \\\n", | |
" --contract-file reference-script-2.contract \\\n", | |
" --state-file reference-script-2.state \\\n", | |
" --out-file reference-script-2.marlowe \\\n", | |
" --print-stats" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7bb78626-c98b-452a-9a0c-30fb5bbb2061", | |
"metadata": {}, | |
"source": [ | |
"Extract the redeemer." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 117, | |
"id": "658412ac-9893-4a34-94fd-4e6d348de111", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"jq '.redeemer.json' reference-script-2.marlowe > reference-script-1.redeemer" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "90e04d69-8e29-4989-9903-a0fda986f55c", | |
"metadata": {}, | |
"source": [ | |
"Extract the datum." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 118, | |
"id": "540eee65-f569-4a53-ab48-e2451dc37846", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"jq '.datum.json' reference-script-2.marlowe > reference-script-2.datum" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "096d57db-fbc4-4819-a6a2-feadae1ef793", | |
"metadata": {}, | |
"source": [ | |
"Build the transaction" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 119, | |
"id": "6907c408-bcb5-4e20-94f6-15a1172253c6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Estimated transaction fee: Lovelace 432682\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction build --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --babbage-era \\\n", | |
" --protocol-params-file reference-script.protocol \\\n", | |
" --tx-in-collateral \"$TX_2#0\" \\\n", | |
" --tx-in \"$TX_2#0\" \\\n", | |
" --tx-in \"$TX_2#1\" \\\n", | |
" --spending-tx-in-reference \"$TX_S\" \\\n", | |
" --spending-plutus-script-v2 \\\n", | |
" --spending-reference-tx-in-datum-file reference-script-1.datum \\\n", | |
" --spending-reference-tx-in-redeemer-file reference-script-1.redeemer \\\n", | |
" --tx-out \"$ADDRESS_S+$ACCOUNT_LOVELACE\" \\\n", | |
" --tx-out-datum-embed-file reference-script-2.datum \\\n", | |
" --change-address \"$ADDRESS_P\" \\\n", | |
" --required-signer \"$PAYMENT_SKEY\" \\\n", | |
" --invalid-before \"$INVALID_BEFORE\" \\\n", | |
" --invalid-hereafter \"$INVALID_HEREAFTER\" \\\n", | |
" --out-file tx-3.raw" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "474a8dff-6d3f-4394-b8f5-920511830fe9", | |
"metadata": {}, | |
"source": [ | |
"Sign and submit the transaction." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 120, | |
"id": "c17aa203-c7fc-4e1f-9650-253f4c27ab59", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"cardano-cli transaction sign --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-body-file tx-3.raw \\\n", | |
" --signing-key-file \"$PAYMENT_SKEY\" \\\n", | |
" --out-file tx-3.signed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 121, | |
"id": "bb205a2b-a36f-4969-bc7c-f26792751e78", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Transaction successfully submitted.\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction submit --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-file tx-3.signed" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "faecd776-adf9-4a0e-98ca-a0b5c18b3b64", | |
"metadata": {}, | |
"source": [ | |
"Wait for the transaction to be confirmed. (One can check the node logs to see when the confirmation has occurred.)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "38944a01-5457-42be-92f2-b8d8092a9a03", | |
"metadata": {}, | |
"source": [ | |
"See that the change has been received" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 122, | |
"id": "d60ba964-117e-463c-a5b8-92fc7350e52a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"4212b8d9e2d22f3aa462e4046a672cfabeec76569d46d8df0032805c69f27582 1 60000000 lovelace + TxOutDatumNone\n", | |
"683bd9547b9609c5e20aa02c6a60d0ce957b7b2e2d5d8f7b33b179b88810777a 0 189256609771 lovelace + TxOutDatumNone\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_P\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "5f6f4d38-5e18-4b21-ac68-2d2ba517a964", | |
"metadata": {}, | |
"source": [ | |
"Record the transaction ID." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 123, | |
"id": "eff58c73-91a2-4631-9607-d12e3c6e06b7", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"TX_3=683bd9547b9609c5e20aa02c6a60d0ce957b7b2e2d5d8f7b33b179b88810777a" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "37477102-7bc3-4d8b-95c5-dfd151528069", | |
"metadata": {}, | |
"source": [ | |
"View the transaction at the script address." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 124, | |
"id": "1ad5757b-aa88-4bdd-8cf3-2e3de1504549", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"683bd9547b9609c5e20aa02c6a60d0ce957b7b2e2d5d8f7b33b179b88810777a 1 3000000 lovelace + TxOutDatumHash ScriptDataInBabbageEra \"e592f6d141000e448f8875d0ea9b6501504b6516bb1f2bf0c3ef58568af2ab77\"\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_S\" | sed -n -e \"1,2p;/^$TX_2/p;/^$TX_3/p\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "98991b6b-09a5-48b3-9582-805288182d82", | |
"metadata": {}, | |
"source": [ | |
"### 4.4. Second notification\n", | |
"\n", | |
"Bundle the contract and state, computing the redeemer, datum, and script." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 125, | |
"id": "337c32fb-2201-4cf7-a6b7-a0b5a4947d2a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Bare-validator cost: ExBudget {exBudgetCPU = ExCPU 18515100, exBudgetMemory = ExMemory 80600}\n", | |
"Validator size: 12689\n", | |
"Datum size: 30\n", | |
"Redeemer size: 11\n", | |
"Total size: 12730\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli contract marlowe --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --input-file reference-script-2.input \\\n", | |
" --contract-file reference-script-3.contract \\\n", | |
" --state-file reference-script-3.state \\\n", | |
" --out-file reference-script-3.marlowe \\\n", | |
" --print-stats" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b45580ba-6cf0-4ed7-8adc-aa1253966327", | |
"metadata": {}, | |
"source": [ | |
"Extract the redeemer." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 126, | |
"id": "4cd84732-95a4-422c-9d40-b1dd330a6ada", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"jq '.redeemer.json' reference-script-3.marlowe > reference-script-2.redeemer" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "3d8c7bd9-85e5-4b6e-8fcd-d119c67d180c", | |
"metadata": {}, | |
"source": [ | |
"No datum is needed because the contract does not continue." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c8dce40e-4b4a-4c01-84e3-cebf6c7f5a28", | |
"metadata": {}, | |
"source": [ | |
"Attempt to close this contract while creating a new one. This should fail with the `L2` validation error." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 127, | |
"id": "c808a913-eac5-4bc3-b96b-dd0799f9b745", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Command failed: transaction build Error: The following scripts have execution failures:\n", | |
"the script for transaction input 1 (in the order of the TxIds) failed with: \n", | |
"The Plutus script evaluation failed: An error has occurred: User error:\n", | |
"The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.\n", | |
"Script debugging logs: L2\n", | |
"PT5\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"ename": "", | |
"evalue": "1", | |
"output_type": "error", | |
"traceback": [] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction build --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --babbage-era \\\n", | |
" --protocol-params-file reference-script.protocol \\\n", | |
" --tx-in-collateral \"$TX_3#0\" \\\n", | |
" --tx-in \"$TX_3#0\" \\\n", | |
" --tx-in \"$TX_3#1\" \\\n", | |
" --spending-tx-in-reference \"$TX_S\" \\\n", | |
" --spending-plutus-script-v2 \\\n", | |
" --spending-reference-tx-in-datum-file reference-script-2.datum \\\n", | |
" --spending-reference-tx-in-redeemer-file reference-script-2.redeemer \\\n", | |
" --tx-out \"$ADDRESS_S+$ACCOUNT_LOVELACE\" \\\n", | |
" --tx-out-datum-embed-file reference-script-1.datum \\\n", | |
" --tx-out \"$ADDRESS_P+$ACCOUNT_LOVELACE\" \\\n", | |
" --change-address \"$ADDRESS_P\" \\\n", | |
" --required-signer \"$PAYMENT_SKEY\" \\\n", | |
" --invalid-before \"$INVALID_BEFORE\" \\\n", | |
" --invalid-hereafter \"$INVALID_HEREAFTER\" \\\n", | |
" --out-file tx-4.raw" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7da04797-7c40-4974-9b9d-e920499136e0", | |
"metadata": {}, | |
"source": [ | |
"Build the transaction" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 128, | |
"id": "2bbd753f-787b-4093-9c5e-8c30840e7c45", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Estimated transaction fee: Lovelace 398276\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction build --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --babbage-era \\\n", | |
" --protocol-params-file reference-script.protocol \\\n", | |
" --tx-in-collateral \"$TX_3#0\" \\\n", | |
" --tx-in \"$TX_3#0\" \\\n", | |
" --tx-in \"$TX_3#1\" \\\n", | |
" --spending-tx-in-reference \"$TX_S\" \\\n", | |
" --spending-plutus-script-v2 \\\n", | |
" --spending-reference-tx-in-datum-file reference-script-2.datum \\\n", | |
" --spending-reference-tx-in-redeemer-file reference-script-2.redeemer \\\n", | |
" --tx-out \"$ADDRESS_P+$ACCOUNT_LOVELACE\" \\\n", | |
" --change-address \"$ADDRESS_P\" \\\n", | |
" --required-signer \"$PAYMENT_SKEY\" \\\n", | |
" --invalid-before \"$INVALID_BEFORE\" \\\n", | |
" --invalid-hereafter \"$INVALID_HEREAFTER\" \\\n", | |
" --out-file tx-4.raw" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "90bb0abb-d8b7-450c-ab46-a5dab558ec21", | |
"metadata": {}, | |
"source": [ | |
"Sign and submit the transaction." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 129, | |
"id": "9fcfe7b1-a883-455b-b981-7336a8571f9e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"cardano-cli transaction sign --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-body-file tx-4.raw \\\n", | |
" --signing-key-file \"$PAYMENT_SKEY\" \\\n", | |
" --out-file tx-4.signed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 130, | |
"id": "f6effc77-71f6-497e-a132-b52201211ca0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Transaction successfully submitted.\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli transaction submit --testnet-magic \"$CARDANO_TESTNET_MAGIC\" \\\n", | |
" --tx-file tx-4.signed" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "922c5f8c-30bb-45f4-ad54-ade542f8c5a1", | |
"metadata": {}, | |
"source": [ | |
"Wait for the transaction to be confirmed. (One can check the node logs to see when the confirmation has occurred.)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c3b07c80-90fc-4284-b5e4-29a8aa352f50", | |
"metadata": {}, | |
"source": [ | |
"See that the payment and change have been received" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 131, | |
"id": "80170ce2-a63b-45ff-b467-aa5331a96cd1", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"4212b8d9e2d22f3aa462e4046a672cfabeec76569d46d8df0032805c69f27582 1 60000000 lovelace + TxOutDatumNone\n", | |
"e0e6b52205730358e7594c31eeecddfcf19dbc3aadc279f9e0d3badcc4a722e6 0 189256211495 lovelace + TxOutDatumNone\n", | |
"e0e6b52205730358e7594c31eeecddfcf19dbc3aadc279f9e0d3badcc4a722e6 1 3000000 lovelace + TxOutDatumNone\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_P\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ba99abd9-d450-4096-b173-a0d71ee014c0", | |
"metadata": {}, | |
"source": [ | |
"Record the transaction ID." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 133, | |
"id": "e76404ed-d1a9-44a8-be9e-513c79c41dce", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"TX_4=e0e6b52205730358e7594c31eeecddfcf19dbc3aadc279f9e0d3badcc4a722e6" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "22de8040-aa3a-4c20-badf-a7b4f1746381", | |
"metadata": {}, | |
"source": [ | |
"Verify that this contract has no UTxO at the script address." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 134, | |
"id": "ecee0272-6a14-44dd-afa8-f233729c55fb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_S\" | sed -n -e \"1,2p;/^$TX_2/p;/^$TX_3/p;/^$TX_4/p\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "87f069a4-e96f-4147-9ced-dfe8e5cd46cf", | |
"metadata": {}, | |
"source": [ | |
"### 4.5 Cleanup" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 135, | |
"id": "43c675a9-620d-4e92-9663-00dc66f3f256", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"TxId \"60e9f929fb9969c12797b32eb8b3bdd8cffb0f0bfc72a180b380d1a74a848640\"\n" | |
] | |
} | |
], | |
"source": [ | |
"marlowe-cli util clean --required-signer \"$PAYMENT_SKEY\" \\\n", | |
" --change-address \"$ADDRESS_P\" \\\n", | |
" --out-file /dev/null \\\n", | |
" --submit 600" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 136, | |
"id": "4c1e7c24-4378-472a-9337-dfa650611406", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" TxHash TxIx Amount\n", | |
"--------------------------------------------------------------------------------------\n", | |
"60e9f929fb9969c12797b32eb8b3bdd8cffb0f0bfc72a180b380d1a74a848640 0 189319033542 lovelace + TxOutDatumNone\n" | |
] | |
} | |
], | |
"source": [ | |
"cardano-cli query utxo --testnet-magic \"$CARDANO_TESTNET_MAGIC\" --address \"$ADDRESS_P\"" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Bash - Marlowe", | |
"language": "bash", | |
"name": "bash_marlowe" | |
}, | |
"language_info": { | |
"codemirror_mode": "shell", | |
"file_extension": ".sh", | |
"mimetype": "text/x-sh", | |
"name": "/nix/store/zwjm0gln1vk7x1akpyz0yxjsd1yc46gi-bash-5.1-p16/bin/bash" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment