Skip to content

Instantly share code, notes, and snippets.

@tgrospic
Last active February 25, 2020 21:15
Show Gist options
  • Save tgrospic/017f51076179d817ee0f18eb0a25ce91 to your computer and use it in GitHub Desktop.
Save tgrospic/017f51076179d817ee0f18eb0a25ce91 to your computer and use it in GitHub Desktop.
One click REV balance from the browser
data:text/html,<script>
const revBalance = addr => `
new return, rl(\`rho:registry:lookup\`), RevVaultCh, vaultCh in {
rl!(\`rho:rchain:revVault\`, *RevVaultCh) |
for (@(_, RevVault) <- RevVaultCh) {
@RevVault!("findOrCreate", "${addr}", *vaultCh) |
for (@maybeVault <- vaultCh) {
match maybeVault {
(true, vault) => @vault!("balance", *return)
(false, err) => return!(err)
}
}
}
}
`
const url = 'http://104.197.246.182:40403/api/explore-deploy'
const addr = prompt('Please enter REV address', '<REV address>')
const req = {method: 'POST', body: revBalance(addr)}
const render = msg => document.body.innerHTML = `<h1>${msg}</h1>`
const readRes = ({expr: [r]}) => {
console.log("Result", r)
const bal = r.ExprInt && r.ExprInt.data
const err = r.ExprString && r.ExprString.data
return typeof bal === 'number' ? `Balance: ${bal * 10e-9}` : `ERROR: ${err}`
}
fetch(url, req).then(r => r.json())
.then(readRes).then(render).catch(render)
</script>
@tgrospic
Copy link
Author

@jimscarver I'm not sure. Chrome supports JS with const definition. You can try replacing const with let or var constructs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment