Last active
August 29, 2015 14:20
-
-
Save tinybike/0563d1cb7db68a692b15 to your computer and use it in GitHub Desktop.
Create events 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 augur = { | |
| info: "0x910b359bb5b2c2857c1d3b7f207a08f3f25c4a8b", | |
| createEvent: "0xcae6d5912033d66650894e2ae8c2f7502eaba15c" | |
| }; | |
| 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 createEvent(tx) { | |
| var tx_getDescription = { | |
| from: tx.from, | |
| to: augur.info, | |
| function: "getDescription", | |
| signature: "i" | |
| }; | |
| EthRPC.invoke(tx, function (call) { | |
| var eventID; | |
| if (call && call.result) { | |
| eventID = call.result; | |
| console.log("event-ID: ", eventID); | |
| 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 = eventID; | |
| EthRPC.invoke(tx_getDescription, function (getDescription) { | |
| var description = hexToAscii(getDescription.result); | |
| console.log("event: ", description); | |
| }); | |
| clearInterval(timer); | |
| } | |
| }); | |
| }; | |
| var timer = setInterval(pingTx, 6000); | |
| } | |
| }); | |
| } | |
| }); | |
| } | |
| EthRPC.coinbase(function (coinbase) { | |
| createEvent({ | |
| from: coinbase.result, | |
| to: augur.createEvent, | |
| function: "createEvent", | |
| signature: "isiiii", | |
| params: [1010101, "augur ragefest", 250000, 1, 2, 2], | |
| gas: 2500000 | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment