Last active
February 25, 2020 21:15
-
-
Save tgrospic/017f51076179d817ee0f18eb0a25ce91 to your computer and use it in GitHub Desktop.
One click REV balance from the browser
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
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> |
@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
When I paste that in the url in the console I get: Unexpected token 'const'
What should I do?