Last active
February 26, 2020 16:07
-
-
Save jimscarver/8e380de314b94e6badcebe12ff8bb120 to your computer and use it in GitHub Desktop.
This file contains 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
<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