Skip to content

Commit

Permalink
Marleon deployment over IPFS.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Sep 28, 2023
1 parent 36caadd commit 4dceb77
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 49 deletions.
20 changes: 15 additions & 5 deletions lessons/08-cip45/marleon.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="view.css" type="text/css" rel="stylesheet"/>
<script src="controller.js" type="application/javascript"> </script>
<title>Donate via Marleon</title>
<title>Send Tokens via Marleon</title>
</head>
<body id="uiBody" style="color:darkblue;background-color:aliceblue;font-size:smaller" onload="Controller.initialize()">
<h1>Donate via Marleon</h1>
<body id="uiBody" onload="Controller.initialize()">
<h1>Send Tokens via Marleon</h1>
<p>Marleon is a Marlowe contract for sending tokens to the holder of a Marlowe role token.</p>
<ol>
<li>Paste the CardanoConnect address <span id="uiMeerkat"></span> into the <code>ConnectionId</code> field on the <code>CardanoConnect</code> settings page of your CIP45-enabled wallet.</li>
<li>You will donate <input id="uiFundingAmount" type="number" min="2000000" value="2000000" onchange="Controller.makeContract()"/> testnet lovelace (1 ada = 1,000,000 lovelace) to the holder of the NFT with policy ID <span id="uiRecipientPolicy"></span> and token name <span id="uiRecipientName"></span>.</li>
<li id="uiInstructionsCIP45">Paste the CardanoConnect address <span id="uiMeerkat"></span> into the <code>ConnectionId</code> field on the <code>CardanoConnect</code> settings page of your CIP45-enabled wallet.</li>
<li>You will donate <input id="uiFundingAmount" type="number" min="2000000" value="2000000" onchange="Controller.makeContract()"/> lovelace (1 ada = 1,000,000 lovelace) to the holder of the NFT with policy ID <span id="uiRecipientPolicy"></span> and token name <span id="uiRecipientName"></span>.</li>
<li><button id="uiCreate" type="button" onclick="Controller.createContract()">Create the contract</button> for making the donation via Marlowe.</li>
<li>Sign the creation transaction in your CIP45 wallet.</li>
<li>Wait for the creation transaction to be confirmed: <span id="uiContractId" style="font-family:monospace"></span></li>
Expand All @@ -23,6 +23,16 @@ <h1>Donate via Marleon</h1>
<li>Thank you for donating test ada!</li>
</ol>
<p><em id="uiMessage"/></p>
<hr/>
<div style="font-size:smaller">
<p>The URL for Marlowe Runtime and the recipient's role token policy ID and asset name are specified as parameters to this page's URL.</p>
<ul>
<li><code>runtimeUrl=</code> the URL for the Marlowe Runtime instance.</li>
<li><code>recipientPolicy=</code> the policy ID for the recipient of the funds.</li>
<li><code>recipientName=</code> the asset name for the recipient of the funds.</li>
</ul>
<p>On <code>mainnet</code>, for example, one can use an <a href="https://mint.handle.me/" target="marlowe">Ada Handle</a> (policy ID <code>f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a</code>) or an <a href="https://www.adadomains.io/" target="marlowe">Ada Domain</a> (policy ID <code>fc411f546d01e88a822200243769bbc1e1fbdde8fa0f6c5179934edb</code>) for the recipient. Note that for an Ada Handle do not include the <code>$</code> prefix in the asset name and for an Ada Domain do not include the <code>.ada</code> suffix in the asset name. The holder of the handle or domain can redeem the funds from the Marlowe payout address using their NFT using the <a href="https://github.com/input-output-hk/marlowe-payouts" target="marlowe">Marlowe Payouts</a> dapp.</p>
</div>
<ul style="display:none">
<li id="uiWallet"/>
<li id="uiRuntime"/>
Expand Down
111 changes: 67 additions & 44 deletions lessons/08-cip45/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {bech32} from "bech32"
let cardanoScanUrl = null
let marloweScanUrl = null

// Whether to use CIP45.
const useCIP45 = false

// Connection to the CIP30 wallet.
let wallet = null

Expand Down Expand Up @@ -199,13 +202,13 @@ export async function createContract() {
if (res.resource.safetyErrors.length > 0) {
report("Refusing to create contract with safety errors: " + res.resource.safetyErrors.map(x => x.detail).join(" "))
} else {
uiFundingPolicy.disabled = true
uiFundingName.disabled = true
uiFundingAmount.disabled = true
uiDepositTime.disabled = true
setContract(res.resource.contractId)
contractUrl = uiRuntime.innerText + "/" + res.links.contract
const followup = function() {
uiFundingPolicy.disabled = true
uiFundingName.disabled = true
uiFundingAmount.disabled = true
uiDepositTime.disabled = true
uiCreate.disabled = true
uiDeposit.disabled = false
setTx(uiCreateTx, contractId.replace(/#.*$/, ""))
Expand Down Expand Up @@ -256,6 +259,10 @@ export async function depositFunds() {
]
, function(tx) {
return function() {
uiFundingPolicy.disabled = false
uiFundingName.disabled = false
uiFundingAmount.disabled = false
uiDepositTime.disabled = false
uiCreate.disabled = false
uiDeposit.disabled = true
setTx(uiDepositTx, tx)
Expand Down Expand Up @@ -368,46 +375,62 @@ export async function initialize() {
uiCreate.disabled = true
uiDeposit.disabled = true

const dAppConnect = new CardanoPeerConnect.DAppPeerConnect({
dAppInfo: {
name: "Marlowe CIP45 Example",
url: "https://examples.marlowe.app:8080/cip45.html"
},
onApiInject: function(name, addr) {
status("CardanoConnect API injected for wallet \"" + name + "\".")
cardano[name].enable().then(function(n) {
wallet = n
wallet.getChangeAddress().then(function(a) {
setAddress(a)
makeContract()
uiCreate.disabled = false
}).catch(function(error) {
uiCreate.disabled = true
report(error)
})
}).catch(function(error) {
report(error)
})
},
onApiEject: function(name, addr) {
status("CardanoConnect API ejected for wallet \"" + name + "\".")
},
verifyConnection: function(walletInfo, callback) {
status("Verifying connection for wallet \"" + walletInfo.name + "\" at " + walletInfo.address + ".")
callback(true, true)
},
onConnect: function(addr, walletInfo) {
uiWallet.innerText = addr
status("Connected to wallet at " + addr + ".")
uiCreate.disabled = true
},
onDisconnect: function() {
uiWallet.innerText = ""
status("Disconnected from wallet.")
uiCreate.disabled = true
},
})
uiMeerkat.innerText = dAppConnect.getAddress()
if (useCIP45) {
const dAppConnect = new CardanoPeerConnect.DAppPeerConnect({
dAppInfo: {
name: "Marlowe CIP45 Example",
url: "https://examples.marlowe.app:8080/cip45.html"
},
onApiInject: function(name, addr) {
status("CardanoConnect API injected for wallet \"" + name + "\".")
cardano[name].enable().then(function(n) {
wallet = n
wallet.getChangeAddress().then(function(a) {
setAddress(a)
makeContract()
uiCreate.disabled = false
}).catch(function(error) {
uiCreate.disabled = true
report(error)
})
}).catch(function(error) {
report(error)
})
},
onApiEject: function(name, addr) {
status("CardanoConnect API ejected for wallet \"" + name + "\".")
},
verifyConnection: function(walletInfo, callback) {
status("Verifying connection for wallet \"" + walletInfo.name + "\" at " + walletInfo.address + ".")
callback(true, true)
},
onConnect: function(addr, walletInfo) {
uiWallet.innerText = addr
status("Connected to wallet at " + addr + ".")
uiCreate.disabled = true
},
onDisconnect: function() {
uiWallet.innerText = ""
status("Disconnected from wallet.")
uiCreate.disabled = true
},
})
uiMeerkat.innerText = dAppConnect.getAddress()
} else {
uiInstructionsCIP45.style.display = "none"
cardano.eternl.enable().then(function(n) {
wallet = n
wallet.getChangeAddress().then(function(a) {
setAddress(a)
makeContract()
uiCreate.disabled = false
}).catch(function(error) {
report(error)
})
}).catch(function(error) {
report(error)
})
}

}

Expand Down

0 comments on commit 4dceb77

Please sign in to comment.