Created
August 10, 2015 16:45
-
-
Save d11e9/394ba1d74a45610ec9ea 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
abi = [ | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "random", | |
"type": "bytes32" | |
}, | |
{ | |
"name": "blockNumber", | |
"type": "uint256" | |
}, | |
{ | |
"name": "heads", | |
"type": "address" | |
}, | |
{ | |
"name": "tails", | |
"type": "address" | |
} | |
], | |
"name": "prime", | |
"outputs": [ | |
{ | |
"name": "ok", | |
"type": "bool" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"name": "coinFlips", | |
"outputs": [ | |
{ | |
"name": "random", | |
"type": "bytes32" | |
}, | |
{ | |
"name": "blockNumber", | |
"type": "uint256" | |
}, | |
{ | |
"name": "value", | |
"type": "uint256" | |
}, | |
{ | |
"name": "heads", | |
"type": "address" | |
}, | |
{ | |
"name": "tails", | |
"type": "address" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "flipId", | |
"type": "uint256" | |
} | |
], | |
"name": "reveal", | |
"outputs": [ | |
{ | |
"name": "ok", | |
"type": "uint8" | |
} | |
], | |
"type": "function" | |
} | |
] | |
style = document.createElement( 'style') | |
style.innerHTML = """ | |
form { | |
padding: 1em; | |
} | |
button { | |
display: block; | |
} | |
} | |
""" | |
document.body.appendChild( style ) | |
for x in abi | |
if x.type is 'function' or x.type is 'constructor' | |
form = document.createElement 'form' | |
for i in x.inputs | |
if x.constant | |
input = document.createElement('div') | |
input.innerHTML = i.name | |
for o in x.outputs | |
console.log( o ) | |
input.innerHTML += " " + o.name + " (" + o.type + ")" | |
else | |
input = document.createElement('input') | |
input.placeholder = i.name + ' (' + i.type + ')'; | |
form.appendChild( input) | |
button = document.createElement( 'button' ) | |
button.type = "submit" | |
button.innerHTML = x.name | |
form.appendChild( button ) | |
console.log form | |
document.body.appendChild( form ) | |
else | |
console.log "Other", x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment