Skip to content

Instantly share code, notes, and snippets.

@bwbush
Last active May 24, 2023 02:06
Show Gist options
  • Save bwbush/b45b117225e9319b0374331088a7fafa to your computer and use it in GitHub Desktop.
Save bwbush/b45b117225e9319b0374331088a7fafa to your computer and use it in GitHub Desktop.
Using Marlowe REST API from Python without other Cardano tools
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "f22023f5-1c0a-42ab-bbb8-f577cb6d5c6a",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2121e776-aed1-46c1-af66-6105c04f23b7",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import http.client\n",
"import json"
]
},
{
"cell_type": "markdown",
"id": "30150d08-b669-4479-94a3-d83a1c3ece40",
"metadata": {},
"source": [
"## Connections"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "077165d6-e072-4370-bf1d-d271202cdbc2",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b9c48872-2fb0-47a8-8ddf-e66cf3fd5d7b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"signingConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13779)"
]
},
{
"cell_type": "markdown",
"id": "74a7d819-dee6-4483-ac5f-357d4b86f865",
"metadata": {},
"source": [
"## Keys and addresses"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d30003d5-1790-4f39-bd26-d02eb9c90373",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"partyAddress = \"addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs\"\n",
"partyKey = {\n",
" \"type\": \"PaymentSigningKeyShelley_ed25519\",\n",
" \"description\": \"Payment Signing Key\",\n",
" \"cborHex\": \"5820bb921c6af621b3336460e6df335d73d4d91012718240bb95dd0301fd9aa5b5e6\"\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "12ec9d0d-1ba4-4e79-a186-4c05ceb69091",
"metadata": {},
"source": [
"## Contract"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "0db225c8-c210-4a22-9d94-e87d93c63a3e",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'when': [{'then': {'when': [{'then': {'when': [{'then': 'close',\n",
" 'case': {'notify_if': True}}],\n",
" 'timeout_continuation': 'close',\n",
" 'timeout': 1685111280000},\n",
" 'case': {'for_choice': {'choice_owner': {'address': 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'},\n",
" 'choice_name': 'Release'},\n",
" 'choose_between': [{'to': 1, 'from': 1}]}}],\n",
" 'timeout_continuation': 'close',\n",
" 'timeout': 1685024580000},\n",
" 'case': {'party': {'address': 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'},\n",
" 'of_token': {'token_name': '', 'currency_symbol': ''},\n",
" 'into_account': {'address': 'addr_test1vrztl2rnzc47vt3llpzgh73lut3q3q3cer49qp9agsntaqgdxlyaw'},\n",
" 'deposits': 10000000}}],\n",
" 'timeout_continuation': 'close',\n",
" 'timeout': 1684937880000}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract = {\"when\":[{\"then\":{\"when\":[{\"then\":{\"when\":[{\"then\":\"close\",\"case\":{\"notify_if\":True}}],\"timeout_continuation\":\"close\",\"timeout\":1685111280000},\"case\":{\"for_choice\":{\"choice_owner\":{\"address\":\"addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs\"},\"choice_name\":\"Release\"},\"choose_between\":[{\"to\":1,\"from\":1}]}}],\"timeout_continuation\":\"close\",\"timeout\":1685024580000},\"case\":{\"party\":{\"address\":\"addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs\"},\"of_token\":{\"token_name\":\"\",\"currency_symbol\":\"\"},\"into_account\":{\"address\":\"addr_test1vrztl2rnzc47vt3llpzgh73lut3q3q3cer49qp9agsntaqgdxlyaw\"},\"deposits\":10000000}}],\"timeout_continuation\":\"close\",\"timeout\":1684937880000}\n",
"contract"
]
},
{
"cell_type": "markdown",
"id": "a95ccfd0-e15d-4954-9a2a-1050911d2e0a",
"metadata": {},
"source": [
"## Transaction 1. Create"
]
},
{
"cell_type": "markdown",
"id": "16d5bbbe-7bac-4f81-bd4d-b20f2ab1e33c",
"metadata": {},
"source": [
"### Call endpoint to build creation transaction"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "fc51e733-3643-478d-96c3-850387211301",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a11280da-4240-4c82-acd9-fd5f7443c3cf",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'links': {'contract': 'contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231'},\n",
" 'resource': {'contractId': '1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a#1',\n",
" 'txBody': {'cborHex': '86a4008182582012abc261317d32c561050d05dba4fd2b880538ec41e331271ee4848789d05b25000182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a087bd3e6a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a001e84800282005820a10bfb9106a6faf7ba77592d438bda4bd019cd33aa71fd954f0a9853a5bdd831021a0002d5e50b582067aa14f520459dae714839cd931c1627ac8965c515ab0002a4f59b42cb9145019fff81d8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980ffff80f5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}}}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"POST\",\n",
" \"/contracts\",\n",
" json.dumps({\n",
" 'version' : 'v1',\n",
" 'contract' : contract,\n",
" 'roles' : None,\n",
" 'minUTxODeposit' : 2000000,\n",
" 'metadata' : {},\n",
" 'tags' : {}\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'X-Change-Address' : 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'\n",
" }\n",
")\n",
"response1 = json.loads(marloweConnection.getresponse().read().decode())\n",
"response1"
]
},
{
"cell_type": "markdown",
"id": "ef35de82-04df-4dca-bb58-0721df4231e3",
"metadata": {},
"source": [
"### Find contract ID"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c3c28892-5284-4011-a263-4fe649e8dd7a",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a#1'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contractId = response1[\"resource\"][\"contractId\"]\n",
"contractId"
]
},
{
"cell_type": "markdown",
"id": "d2d307d1-c941-4791-8f20-bf2bb622343e",
"metadata": {},
"source": [
"### Find contract endpoint"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "ef4add22-5bec-4862-bec7-84a6f6e23933",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'/contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contractPath = \"/\" + response1[\"links\"][\"contract\"]\n",
"contractPath"
]
},
{
"cell_type": "markdown",
"id": "64c6c002-f1cf-4d64-91f7-2c8af6a23112",
"metadata": {},
"source": [
"### Extract unsigned transaction body"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "047cd17c-5a95-4665-a734-858b1d36bfae",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '86a4008182582012abc261317d32c561050d05dba4fd2b880538ec41e331271ee4848789d05b25000182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a087bd3e6a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a001e84800282005820a10bfb9106a6faf7ba77592d438bda4bd019cd33aa71fd954f0a9853a5bdd831021a0002d5e50b582067aa14f520459dae714839cd931c1627ac8965c515ab0002a4f59b42cb9145019fff81d8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980ffff80f5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx1unsigned = response1[\"resource\"][\"txBody\"]\n",
"tx1unsigned"
]
},
{
"cell_type": "markdown",
"id": "ebf54fbc-cc96-4212-8877-f16724241211",
"metadata": {},
"source": [
"### Call endpoint to sign transaction"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "a8911a36-2dc6-4a8f-aad4-7ab40796b236",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"signingConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13779)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "1cb9ef0f-c8f1-4660-bf92-63ce8e159253",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'tx': {'cborHex': '84a4008182582012abc261317d32c561050d05dba4fd2b880538ec41e331271ee4848789d05b25000182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a087bd3e6a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a001e84800282005820a10bfb9106a6faf7ba77592d438bda4bd019cd33aa71fd954f0a9853a5bdd831021a0002d5e50b582067aa14f520459dae714839cd931c1627ac8965c515ab0002a4f59b42cb914501a20081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840cd9a07114b9561b5e937c14133ca724f68d6da31fb232c9bea042cca63341146df9125349690754171b30057a3eac1633fd88da0ae51c90fc9d9b2fe895cab050481d8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980fffff5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'},\n",
" 'txId': '1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a'}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"signingConnection.request(\n",
" \"POST\",\n",
" \"/sign\",\n",
" json.dumps({\n",
" 'body' : tx1unsigned,\n",
" 'paymentKeys' : [partyKey],\n",
" 'paymentExtendedKeys' : []\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'Accept' : 'application/json'\n",
" }\n",
")\n",
"signResponse1 = json.loads(signingConnection.getresponse().read().decode())\n",
"signResponse1"
]
},
{
"cell_type": "markdown",
"id": "917d1454-4019-4280-8c56-ea51cdafd4b4",
"metadata": {},
"source": [
"### Extract the text envelope for the signed transaction"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0f463097-455a-494a-a30e-18a2cc81b14b",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '84a4008182582012abc261317d32c561050d05dba4fd2b880538ec41e331271ee4848789d05b25000182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a087bd3e6a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a001e84800282005820a10bfb9106a6faf7ba77592d438bda4bd019cd33aa71fd954f0a9853a5bdd831021a0002d5e50b582067aa14f520459dae714839cd931c1627ac8965c515ab0002a4f59b42cb914501a20081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840cd9a07114b9561b5e937c14133ca724f68d6da31fb232c9bea042cca63341146df9125349690754171b30057a3eac1633fd88da0ae51c90fc9d9b2fe895cab050481d8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980fffff5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx1 = signResponse1[\"tx\"]\n",
"tx1"
]
},
{
"cell_type": "markdown",
"id": "4eea664a-a7d3-4600-8503-1326ec67514d",
"metadata": {},
"source": [
"### Call the endpoint to submit the transaction"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "8106dab7-46c3-4c06-8cdc-19624dba8605",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ef113871-afe0-472d-8ed2-04a9d4543a49",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"202"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"PUT\",\n",
" contractPath,\n",
" json.dumps(tx1),\n",
" {\n",
" 'Content-Type' : 'application/json'\n",
" }\n",
")\n",
"marloweConnection.getresponse().status"
]
},
{
"cell_type": "markdown",
"id": "9624b245-2d0c-4843-9ee8-102053fc7b2a",
"metadata": {},
"source": [
"### Poll to see if the transaction has been confirmed"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "b487281f-0b83-49a0-b6ff-cdc3ed3f3081",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "97c94e29-0d86-4cc4-84d7-ccfa827bbac6",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'submitted'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" contractPath\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "de510c99-3958-439f-b222-ec831340826f",
"metadata": {},
"source": [
"Wait a little while and then try again."
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "91ed2328-5460-4979-a526-b263a28e2f21",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c4d40aa6-271e-40c5-bd40-c0761f11b4f5",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'confirmed'"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" contractPath\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "cc0013e1-cc4c-4923-976a-7cccf48e79bd",
"metadata": {},
"source": [
"## Transaction 2. Deposit"
]
},
{
"cell_type": "markdown",
"id": "e6022e1b-5c64-457d-b87a-e86f14262e2e",
"metadata": {
"tags": []
},
"source": [
"<font color=\"red\">Note that this step is slightly different from the \"create\" case.</a>"
]
},
{
"cell_type": "markdown",
"id": "da6b94d6-06a9-4344-94ad-0bb7e1a71023",
"metadata": {},
"source": [
"### Call endpoint to build deposit transaction"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "e3ce4655-72a4-4c7a-aa46-fbeae6da140c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "80db1507-8e89-4e83-b1c4-f0ef052114b3",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'links': {'transaction': 'contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231/transactions/8362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c'},\n",
" 'resource': {'contractId': '1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a#1',\n",
" 'transactionId': '8362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c',\n",
" 'txBody': {'cborHex': '86ab00828258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a008258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a010d818258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07da26b0a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b000282005820454b7189fbcbc1359ba63f81a97d926586bdb88d55e1625733975f5b36bef4d910a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a086e31d5111a000da211021a000916b6031a01be6418081a01bd73600e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b582006dd8eda86eda4f8f4bde8d3fddb2ed3b346724f270452e4a2470747f393e21e9fff82d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffd8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980ffff818400019fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ff1a00989680ffffff821a004a22621a4d3ee5b8f5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}}}"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"POST\",\n",
" contractPath + \"/transactions\",\n",
" json.dumps({\n",
" 'version' : 'v1',\n",
" 'inputs' : [{\n",
" 'input_from_party' : {'address' : 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'},\n",
" 'that_deposits' : 10000000,\n",
" 'of_token' : {'currency_symbol' : '', 'token_name' : ''},\n",
" 'into_account' : {'address' : 'addr_test1vrztl2rnzc47vt3llpzgh73lut3q3q3cer49qp9agsntaqgdxlyaw'}\n",
" }],\n",
" 'metadata' : {},\n",
" 'tags' : {}\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'X-Change-Address' : 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'\n",
" }\n",
")\n",
"response2 = json.loads(marloweConnection.getresponse().read().decode())\n",
"response2"
]
},
{
"cell_type": "markdown",
"id": "a586cba7-7873-4fe9-99dd-be5ed1240665",
"metadata": {},
"source": [
"### Find transaction endpoint"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "ae81bc9e-1627-4265-a3ff-5e57dd468ae9",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'/contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231/transactions/8362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c'"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"transaction2path = \"/\" + response2[\"links\"][\"transaction\"]\n",
"transaction2path"
]
},
{
"cell_type": "markdown",
"id": "e3f48ead-115c-4ecc-b508-4c7fc6e8b9b1",
"metadata": {},
"source": [
"### Extract unsigned transaction body"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "bb2c4d93-559b-4293-96c2-b101fa58d241",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '86ab00828258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a008258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a010d818258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07da26b0a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b000282005820454b7189fbcbc1359ba63f81a97d926586bdb88d55e1625733975f5b36bef4d910a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a086e31d5111a000da211021a000916b6031a01be6418081a01bd73600e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b582006dd8eda86eda4f8f4bde8d3fddb2ed3b346724f270452e4a2470747f393e21e9fff82d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffd8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980ffff818400019fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ff1a00989680ffffff821a004a22621a4d3ee5b8f5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx2unsigned = response2[\"resource\"][\"txBody\"]\n",
"tx2unsigned"
]
},
{
"cell_type": "markdown",
"id": "5e2933fa-51e7-4493-87d8-4e4bc3ddeba5",
"metadata": {},
"source": [
"### Call endpoint to sign transaction"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "a8320951-3450-4bd1-a549-e25ccaa823b2",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"signingConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13779)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "bc22b55c-5842-4edd-844b-f6b334a037a6",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'tx': {'cborHex': '84ab00828258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a008258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a010d818258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07da26b0a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b000282005820454b7189fbcbc1359ba63f81a97d926586bdb88d55e1625733975f5b36bef4d910a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a086e31d5111a000da211021a000916b6031a01be6418081a01bd73600e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b582006dd8eda86eda4f8f4bde8d3fddb2ed3b346724f270452e4a2470747f393e21ea30081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840b5a1d98db8e488c70fd49e1565aed8dead484de6169f4e9ef3c133f7d09323022181d31b118b98e36c8ed1d89569f317509307d541039ab5e56a559d38c47f020482d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffd8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980ffff05818400019fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ff1a00989680ffffff821a004a22621a4d3ee5b8f5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'},\n",
" 'txId': '8362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c'}"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"signingConnection.request(\n",
" \"POST\",\n",
" \"/sign\",\n",
" json.dumps({\n",
" 'body' : tx2unsigned,\n",
" 'paymentKeys' : [partyKey],\n",
" 'paymentExtendedKeys' : []\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'Accept' : 'application/json'\n",
" }\n",
")\n",
"signResponse2 = json.loads(signingConnection.getresponse().read().decode())\n",
"signResponse2"
]
},
{
"cell_type": "markdown",
"id": "a8749169-76b0-4d67-889a-554ff76b27ce",
"metadata": {},
"source": [
"### Extract the text envelope for the signed transaction"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "9da73ba4-0ed4-44f8-9475-4b920b263f59",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '84ab00828258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a008258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a010d818258201f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07da26b0a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b000282005820454b7189fbcbc1359ba63f81a97d926586bdb88d55e1625733975f5b36bef4d910a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a086e31d5111a000da211021a000916b6031a01be6418081a01bd73600e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b582006dd8eda86eda4f8f4bde8d3fddb2ed3b346724f270452e4a2470747f393e21ea30081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840b5a1d98db8e488c70fd49e1565aed8dead484de6169f4e9ef3c133f7d09323022181d31b118b98e36c8ed1d89569f317509307d541039ab5e56a559d38c47f020482d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffd8799fd8799f40ffd8799fa1d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480a0a000ffd87c9f9fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffd87a9f1a00989680ffffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffffff1b000001884e1fb1c0d87980ffff05818400019fd8799fd8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ff1a00989680ffffff821a004a22621a4d3ee5b8f5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx2 = signResponse2[\"tx\"]\n",
"tx2"
]
},
{
"cell_type": "markdown",
"id": "7f442691-72b7-462f-8705-77be44d0352b",
"metadata": {},
"source": [
"### Call the endpoint to submit the transaction"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "8db2a9bb-91b5-43fe-8e16-7f5bc8249bdd",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "a43da742-d848-4e9d-a817-e4e79a217ac9",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"202"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"PUT\",\n",
" transaction2path,\n",
" json.dumps(tx2),\n",
" {\n",
" 'Content-Type' : 'application/json'\n",
" }\n",
")\n",
"marloweConnection.getresponse().status"
]
},
{
"cell_type": "markdown",
"id": "0193d4b6-6ddf-41e8-a533-e35e543b9ebc",
"metadata": {},
"source": [
"### Poll to see if the transaction has been confirmed"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "11e186b1-437f-403d-8fac-493e687e7959",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "f2d577a7-f859-49ca-8770-6464b4889ab1",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'submitted'"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" transaction2path\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "04986a1f-0c81-480b-9c2b-aee6c0181ad2",
"metadata": {},
"source": [
"Wait a little while and then try again."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "bd3e4c3a-4237-46b3-a2a6-24f2abf1a0e0",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "b7be2931-ca8b-4cfa-ba59-7e3b5dec0b8b",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'confirmed'"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" transaction2path\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "781cfbf4-278b-4533-829e-f43f4f420dba",
"metadata": {},
"source": [
"## Transaction 3. Choice"
]
},
{
"cell_type": "markdown",
"id": "2469e0a8-89c6-4f8b-80bc-1903ec5a7e5e",
"metadata": {},
"source": [
"### Call endpoint to build deposit transaction"
]
},
{
"cell_type": "markdown",
"id": "2955b801-7079-4096-8aee-f4ecf225d767",
"metadata": {
"tags": []
},
"source": [
"<font color=\"red\">Note that only this step is different from the \"deposit\" case. Everything else is the same.</a>"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "cc1afc6b-41bd-473d-9ad7-d49df4b7685e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "594d5c3f-41b8-4d7f-ab83-86ce7a5da937",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'links': {'transaction': 'contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231/transactions/ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d'},\n",
" 'resource': {'contractId': '1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a#1',\n",
" 'transactionId': 'ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d',\n",
" 'txBody': {'cborHex': '86ab00828258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c008258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c010d818258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07d19f48a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b00028200582041aa23a6d57929147f5e1c799e2160b706f378db5c13da24860e2ebfcbeab87010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07cd5b94111a000ccb1c021a00088768031a01bfb6c4081a01bd736e0e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b5820d80b17158938966f91087de2955aef4e444c5f883f7e84e388c892e942446e2a9fff82d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffd8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffff818400019fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01ffffff821a00444ada1a46744f7ef5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}}}"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"POST\",\n",
" contractPath + \"/transactions\",\n",
" json.dumps({\n",
" 'version' : 'v1',\n",
" 'inputs' : [{\n",
" 'input_that_chooses_num' : 1,\n",
" 'for_choice_id' : {\n",
" 'choice_name' : 'Release',\n",
" 'choice_owner' : {'address' : 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'}\n",
" }\n",
" }],\n",
" 'metadata' : {},\n",
" 'tags' : {}\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'X-Change-Address' : 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'\n",
" }\n",
")\n",
"response3 = json.loads(marloweConnection.getresponse().read().decode())\n",
"response3"
]
},
{
"cell_type": "markdown",
"id": "373b8f59-d622-4e76-9dfa-5a141f92e319",
"metadata": {},
"source": [
"### Find transaction endpoint"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "6b370ef2-9d79-482b-91ec-c0caaf02cbf4",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'/contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231/transactions/ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d'"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"transaction3path = \"/\" + response3[\"links\"][\"transaction\"]\n",
"transaction3path"
]
},
{
"cell_type": "markdown",
"id": "61b182bd-ce3e-41ab-bffc-204520cb088b",
"metadata": {},
"source": [
"### Extract unsigned transaction body"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "b620b704-62be-4cb7-9a7f-4fc0baa29296",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '86ab00828258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c008258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c010d818258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07d19f48a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b00028200582041aa23a6d57929147f5e1c799e2160b706f378db5c13da24860e2ebfcbeab87010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07cd5b94111a000ccb1c021a00088768031a01bfb6c4081a01bd736e0e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b5820d80b17158938966f91087de2955aef4e444c5f883f7e84e388c892e942446e2a9fff82d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffd8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffff818400019fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01ffffff821a00444ada1a46744f7ef5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx3unsigned = response3[\"resource\"][\"txBody\"]\n",
"tx3unsigned"
]
},
{
"cell_type": "markdown",
"id": "eebbaa98-fe36-4c9b-8d46-1f898dfdf2fd",
"metadata": {},
"source": [
"### Call endpoint to sign transaction"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "ac1accbd-bc2f-49dd-8a47-24ada3fdde8b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"signingConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13779)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "a3f2fb4d-b925-4b62-9a60-7981166a3aba",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'tx': {'cborHex': '84ab00828258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c008258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c010d818258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07d19f48a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b00028200582041aa23a6d57929147f5e1c799e2160b706f378db5c13da24860e2ebfcbeab87010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07cd5b94111a000ccb1c021a00088768031a01bfb6c4081a01bd736e0e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b5820d80b17158938966f91087de2955aef4e444c5f883f7e84e388c892e942446e2aa30081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840d32cc239c706ab63b0bcda37d4e30429de4ab8074b6a8ae4a6cd6edddcf2c29053216facbdebb681c84b88ae639120b2d73b005e53e4ea4320f0e59240fbcb000482d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffd8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffff05818400019fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01ffffff821a00444ada1a46744f7ef5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'},\n",
" 'txId': 'ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d'}"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"signingConnection.request(\n",
" \"POST\",\n",
" \"/sign\",\n",
" json.dumps({\n",
" 'body' : tx3unsigned,\n",
" 'paymentKeys' : [partyKey],\n",
" 'paymentExtendedKeys' : []\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'Accept' : 'application/json'\n",
" }\n",
")\n",
"signResponse3 = json.loads(signingConnection.getresponse().read().decode())\n",
"signResponse3"
]
},
{
"cell_type": "markdown",
"id": "c61804bc-1796-4bbf-a21d-34f8ba0816da",
"metadata": {},
"source": [
"### Extract the text envelope for the signed transaction"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "c51333df-41c0-4e6c-a9a5-bcbb2444310d",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '84ab00828258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c008258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c010d818258208362d91088ce6ea0810eee59dfa4e8bf4923ec2280b0477c2794f0995344d55c0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010182a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07d19f48a300581d702ed2631dbb277c84334453c5c437b86325d371f0835a28b910a91a6e011a00b71b00028200582041aa23a6d57929147f5e1c799e2160b706f378db5c13da24860e2ebfcbeab87010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07cd5b94111a000ccb1c021a00088768031a01bfb6c4081a01bd736e0e81581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f8890b5820d80b17158938966f91087de2955aef4e444c5f883f7e84e388c892e942446e2aa30081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840d32cc239c706ab63b0bcda37d4e30429de4ab8074b6a8ae4a6cd6edddcf2c29053216facbdebb681c84b88ae639120b2d73b005e53e4ea4320f0e59240fbcb000482d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffd8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a0a01b000001884a736300ffd87c9f9fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff9fd8799f0101ffffffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffffff1b00000188534aa1a0d87980ffff05818400019fd8799fd87a9fd8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01ffffff821a00444ada1a46744f7ef5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'}"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx3 = signResponse3[\"tx\"]\n",
"tx3"
]
},
{
"cell_type": "markdown",
"id": "eb9cb71f-de04-4516-bb95-6ef4acd59149",
"metadata": {},
"source": [
"### Call the endpoint to submit the transaction"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "045b670c-cc8a-46e6-b2bf-d6ac35b40609",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "542a3baa-e964-4e89-afaf-e14720a0699a",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"202"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"PUT\",\n",
" transaction3path,\n",
" json.dumps(tx3),\n",
" {\n",
" 'Content-Type' : 'application/json'\n",
" }\n",
")\n",
"marloweConnection.getresponse().status"
]
},
{
"cell_type": "markdown",
"id": "846c3a63-cc99-48be-93fc-2c064a61b61d",
"metadata": {},
"source": [
"### Poll to see if the transaction has been confirmed"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "f83247e5-39ff-4483-9f82-745db501e47e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "f5c3863a-2ad0-4343-9a1e-1f87caae1a07",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'submitted'"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" transaction3path\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "a1731d58-c1b4-43a5-9a4c-023b27f70b6f",
"metadata": {},
"source": [
"Wait a little while and then try again."
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "9ac1355a-8af1-413e-ba0b-e5ec6ff72e12",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "27be942f-7857-4529-a57b-ef7e2640be6c",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'confirmed'"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" transaction3path\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "1654fa2f-3de7-417e-b928-dc7d79a77572",
"metadata": {},
"source": [
"## Transaction 4. Notify"
]
},
{
"cell_type": "markdown",
"id": "0e7b9fab-a1bb-4a47-b90e-6eb8d468789d",
"metadata": {},
"source": [
"### Call endpoint to build notify transaction"
]
},
{
"cell_type": "markdown",
"id": "be5fad92-82fd-4e09-8d75-eb3863a3de87",
"metadata": {
"tags": []
},
"source": [
"<font color=\"red\">Note that only this step is different from the \"deposit\" and \"choice\" cases. Everything else is the same.</a>"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "016a7365-9689-41f2-9817-4c42e265bc35",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "fbe7ac45-0867-49f2-9f91-2fc9e4fccad8",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'links': {'transaction': 'contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231/transactions/eb51145f0b356300695abe2613cc7f0f04c3f77bb4b4d423eba03c5f1f7985d5'},\n",
" 'resource': {'contractId': '1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a#1',\n",
" 'transactionId': 'eb51145f0b356300695abe2613cc7f0f04c3f77bb4b4d423eba03c5f1f7985d5',\n",
" 'txBody': {'cborHex': '86aa0082825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d00825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d010d81825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010183a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c9993ea200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a001e8480a200581d60c4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81011a0098968010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c59639111a000c090f021a0008060a031a01c10970081a01bd73820b5820ebfb38ad2a75bae49ad54fd4641f968bf752f824cfbe2152dd597d2d5a1279b89fff81d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffff818400019fd8799fd87b80ffff821a004204cc1a4350e46ef5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}}}"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"POST\",\n",
" contractPath + \"/transactions\",\n",
" json.dumps({\n",
" 'version' : 'v1',\n",
" 'inputs' : [\"input_notify\"],\n",
" 'metadata' : {},\n",
" 'tags' : {}\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'X-Change-Address' : 'addr_test1vp28qhdavped0rwr24ww8fmstr727a5ln7vrshlvq7cl3zgn0uaxs'\n",
" }\n",
")\n",
"response4 = json.loads(marloweConnection.getresponse().read().decode())\n",
"response4"
]
},
{
"cell_type": "markdown",
"id": "11a7c5e2-a29b-4210-a7fe-e3fe74c661dd",
"metadata": {},
"source": [
"### Find transaction endpoint"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "81e2624b-9553-466e-aa56-6f36c136a6a2",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'/contracts/1f9f6a3a06a862ab6ca73134ba0295f6e2acd0ca8f7f59b2ea133c6a0061790a%231/transactions/eb51145f0b356300695abe2613cc7f0f04c3f77bb4b4d423eba03c5f1f7985d5'"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"transaction4path = \"/\" + response4[\"links\"][\"transaction\"]\n",
"transaction4path"
]
},
{
"cell_type": "markdown",
"id": "8266234a-2fd6-4321-88c0-0344b552ea17",
"metadata": {},
"source": [
"### Extract unsigned transaction body"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "05706a0b-9fac-4d35-9999-7e2a2c7b65af",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '86aa0082825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d00825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d010d81825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010183a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c9993ea200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a001e8480a200581d60c4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81011a0098968010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c59639111a000c090f021a0008060a031a01c10970081a01bd73820b5820ebfb38ad2a75bae49ad54fd4641f968bf752f824cfbe2152dd597d2d5a1279b89fff81d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffff818400019fd8799fd87b80ffff821a004204cc1a4350e46ef5f6',\n",
" 'description': '',\n",
" 'type': 'TxBodyBabbage'}"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx4unsigned = response4[\"resource\"][\"txBody\"]\n",
"tx4unsigned"
]
},
{
"cell_type": "markdown",
"id": "5e9d1529-8730-445c-93e5-061eee36e451",
"metadata": {},
"source": [
"### Call endpoint to sign transaction"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "f129ebe5-4bf3-45e4-bad5-194f0bc7de71",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"signingConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13779)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "8ac49a3f-d043-4e33-ba5b-066b9ecd1662",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'tx': {'cborHex': '84aa0082825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d00825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d010d81825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010183a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c9993ea200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a001e8480a200581d60c4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81011a0098968010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c59639111a000c090f021a0008060a031a01c10970081a01bd73820b5820ebfb38ad2a75bae49ad54fd4641f968bf752f824cfbe2152dd597d2d5a1279b8a30081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840f3a55f0585142c53ee69e190b9fb845c97d68df505aa565729358ec8d31eeb8805364046a4d254e379da95ef2f1da71aa2efd3c9fa7c96f6b0cb5c10bc111a040481d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffff05818400019fd8799fd87b80ffff821a004204cc1a4350e46ef5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'},\n",
" 'txId': 'eb51145f0b356300695abe2613cc7f0f04c3f77bb4b4d423eba03c5f1f7985d5'}"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"signingConnection.request(\n",
" \"POST\",\n",
" \"/sign\",\n",
" json.dumps({\n",
" 'body' : tx4unsigned,\n",
" 'paymentKeys' : [partyKey],\n",
" 'paymentExtendedKeys' : []\n",
" }),\n",
" {\n",
" 'Content-Type' : 'application/json',\n",
" 'Accept' : 'application/json'\n",
" }\n",
")\n",
"signResponse4 = json.loads(signingConnection.getresponse().read().decode())\n",
"signResponse4"
]
},
{
"cell_type": "markdown",
"id": "629c33db-3912-4965-9374-46ccea8b68d5",
"metadata": {},
"source": [
"### Extract the text envelope for the signed transaction"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "047df7eb-0ff5-4903-b68e-1c359363154a",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'cborHex': '84aa0082825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d00825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d010d81825820ef60792945e75a7e5c6d618df3d1129b7d0ce13ae76ccd87240b10ea2508ab3d0012818258209a8a6f387a3330b4141e1cb019380b9ac5c72151c0abc52aa4266245d3c555cd010183a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c9993ea200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a001e8480a200581d60c4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81011a0098968010a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a07c59639111a000c090f021a0008060a031a01c10970081a01bd73820b5820ebfb38ad2a75bae49ad54fd4641f968bf752f824cfbe2152dd597d2d5a1279b8a30081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c5840f3a55f0585142c53ee69e190b9fb845c97d68df505aa565729358ec8d31eeb8805364046a4d254e379da95ef2f1da71aa2efd3c9fa7c96f6b0cb5c10bc111a040481d8799fd8799f40ffd8799fa2d8799fd8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffd8799f4040ffff1a001e8480d8799fd8799fd87980d8799fd8799f581cc4bfa873162be62e3ff8448bfa3fe2e2088238c8ea5004bd4426be81ffd87a80ffffd8799f4040ffff1a00989680a1d8799f4752656c65617365d8799fd87980d8799fd8799f581c54705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889ffd87a80ffffff01a01b000001884a7399b0ffd87c9f9fd8799fd87b9fd9050280ffd87980ffff1b0000018858759180d87980ffff05818400019fd8799fd87b80ffff821a004204cc1a4350e46ef5f6',\n",
" 'description': '',\n",
" 'type': 'Tx BabbageEra'}"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx4 = signResponse4[\"tx\"]\n",
"tx4"
]
},
{
"cell_type": "markdown",
"id": "90402505-46d2-4825-96a1-e9a6fc349d54",
"metadata": {},
"source": [
"### Call the endpoint to submit the transaction"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "77f5a04f-824e-42f5-b1a1-639811621626",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "6ff72a47-aec8-4a50-b23b-dbbcd9372701",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"202"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"PUT\",\n",
" transaction4path,\n",
" json.dumps(tx4),\n",
" {\n",
" 'Content-Type' : 'application/json'\n",
" }\n",
")\n",
"marloweConnection.getresponse().status"
]
},
{
"cell_type": "markdown",
"id": "8d01b35e-193e-4915-b478-c8c0e98a33c9",
"metadata": {},
"source": [
"### Poll to see if the transaction has been confirmed"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "cf9fc19c-fbd6-439a-8680-950509d92030",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "90f51d80-ee19-4410-a14d-b2ad91b0eaf7",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'submitted'"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" transaction4path\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
},
{
"cell_type": "markdown",
"id": "1e0debc6-1800-4acf-87e7-4ef0d90c0f4d",
"metadata": {},
"source": [
"Wait a little while and then try again."
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "680e3f79-5004-447e-b026-e37535e591bb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Re-open the connect because it is not being kept alive.\n",
"marloweConnection = http.client.HTTPConnection(\"services.marlowe.run\", 13780)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "b74cdea2-988d-43ba-b0d0-f2d8afb9e1ea",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'confirmed'"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"marloweConnection.request(\n",
" \"GET\",\n",
" transaction4path\n",
")\n",
"json.loads(marloweConnection.getresponse().read().decode())[\"resource\"][\"status\"]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment