Last active
August 29, 2015 14:20
-
-
Save tinybike/4360567641bb3b63ce82 to your computer and use it in GitHub Desktop.
Create markets on Augur
This file contains hidden or 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
| var EthRPC = require('ethrpc.js'); | |
| var ERRORS = { | |
| "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff": { | |
| code: -1, | |
| message: "bad input or parent doesn't exist" | |
| }, | |
| "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe": { | |
| code: -2, | |
| message: "too many events" | |
| }, | |
| "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe": { | |
| code: -3, | |
| message: "too many outcomes" | |
| }, | |
| "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc": { | |
| code: -4, | |
| message: "not enough money or market already exists" | |
| } | |
| }; | |
| var augur = { | |
| info: "0x910b359bb5b2c2857c1d3b7f207a08f3f25c4a8b", | |
| createMarket: "0x386acc6b970aea7c6f9b87e7622d2ae7c18d377a" | |
| }; | |
| function hexToAscii(hexx) { | |
| var hex = hexx.toString(); | |
| var substr, str = ''; | |
| var foundNonzero = 0; | |
| for (var i = 0; i < hex.length; i += 2) { | |
| substr = hex.substr(i, 2); | |
| if (foundNonzero > 1 || substr != '00') { | |
| str += String.fromCharCode(parseInt(substr, 16)); | |
| foundNonzero++; | |
| } | |
| } | |
| return str; | |
| } | |
| function createMarket(tx) { | |
| var tx_getDescription = { | |
| from: tx.from, | |
| to: augur.info, | |
| function: "getDescription", | |
| signature: "i" | |
| }; | |
| EthRPC.invoke(tx, function (call) { | |
| var marketID; | |
| if (call && call.result) { | |
| marketID = call.result; | |
| console.log("market-ID: ", marketID); | |
| if (ERRORS[marketID]) { | |
| console.log("error " + ERRORS[marketID].code.toString() + ": " + ERRORS[marketID].message); | |
| } else { | |
| tx.send = true; | |
| EthRPC.invoke(tx, function (sendTx) { | |
| var txhash; | |
| if (sendTx && sendTx.result) { | |
| txhash = sendTx.result; | |
| console.log("txhash: ", txhash); | |
| var pingTx = function () { | |
| EthRPC.getTx(txhash, function (getTx) { | |
| if (getTx && getTx.result) { | |
| // found it! | |
| tx_getDescription.params = marketID; | |
| EthRPC.invoke(tx_getDescription, function (getDescription) { | |
| var description = hexToAscii(getDescription.result); | |
| console.log("market: ", description); | |
| }); | |
| clearInterval(timer); | |
| } | |
| }); | |
| }; | |
| var timer = setInterval(pingTx, 6000); | |
| } | |
| }); | |
| } | |
| } | |
| }); | |
| } | |
| EthRPC.coinbase(function (coinbase) { | |
| createMarket({ | |
| from: coinbase.result, | |
| to: augur.createMarket, | |
| function: "createMarket", | |
| signature: "isiiia", | |
| params: [ | |
| 1010101, | |
| "lolfest redux", | |
| "0x1000000000000000", | |
| "0x2800000000000000000", | |
| "0x400000000000000", | |
| ["0xb2a6de45f349b5ac384b01a785e640f519f0a8597ab2031c964c7f572d96b13c", | |
| "0x4f37814757b7d0e2dde46de18bb4bf4a85e6716a06849d5cfcebf8f1d7270b12", | |
| "0x412b3c588f9be08d54e99bf5095ef910c5e84080f048e3af8a2718b7b693cb83"] | |
| ], | |
| gas: 3000000 | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment