Skip to content

Instantly share code, notes, and snippets.

@jimscarver
Last active February 26, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimscarver/8e380de314b94e6badcebe12ff8bb120 to your computer and use it in GitHub Desktop.
Save jimscarver/8e380de314b94e6badcebe12ff8bb120 to your computer and use it in GitHub Desktop.
<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://35.234.124.72: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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment