Skip to content

Instantly share code, notes, and snippets.

@tinybike
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save tinybike/6aed2458750e00d7e79c to your computer and use it in GitHub Desktop.

Select an option

Save tinybike/6aed2458750e00d7e79c to your computer and use it in GitHub Desktop.
Get event info from Augur
var EthRPC = require('ethrpc.js');
var augur = {
info: "0x910b359bb5b2c2857c1d3b7f207a08f3f25c4a8b",
expiringEvents: "0x61d90fd4c1c3502646153003ec4d5c177de0fb58",
branches: "0x13dc5836cd5638d0b81a1ba8377a7852d41b5bbe",
events: "0xb71464588fc19165cbdd1e6e8150c40df544467b"
};
function parse_array(string, stride, init, bignum) {
stride = stride || 64;
var elements = (string.length - 2) / stride;
var array = Array(elements);
var position = init || 2;
for (var i = 0; i < elements; ++i) {
array[i] = "0x" + string.slice(position, position + stride);
if (bignum) {
array[i] = new BigNumber(array[i]);
}
position += stride;
}
return array;
}
function hexToAscii(hexx) {
var hex = hexx.toString();
var substr, str = '';
for (var i = 0; i < hex.length; i += 2) {
substr = hex.substr(i, 2);
if (substr != '00') {
str += String.fromCharCode(parseInt(substr, 16));
}
}
return str;
}
Array.prototype.loop = function (iterator) {
var list = this;
var n = list.length;
var i = -1;
var calls = 0;
var looping = false;
var iterate = function() {
calls -= 1;
i += 1;
if (i === n) return;
iterator(list[i], next);
};
var loop = function() {
if (looping) return;
looping = true;
while (calls > 0) iterate();
looping = false;
};
var next = function() {
calls += 1;
if (typeof setTimeout === 'undefined') loop();
else setTimeout(iterate, 1);
};
next();
};
EthRPC.coinbase(function (coinbase) {
var events = [
"0xb2a6de45f349b5ac384b01a785e640f519f0a8597ab2031c964c7f572d96b13c",
"0x4f37814757b7d0e2dde46de18bb4bf4a85e6716a06849d5cfcebf8f1d7270b12",
"0x412b3c588f9be08d54e99bf5095ef910c5e84080f048e3af8a2718b7b693cb83"
];
events.loop(function (thisEvent, nextEvent) {
EthRPC.invoke({
from: coinbase.result,
to: augur.events,
function: "getEventInfo",
signature: "i",
params: thisEvent
}, function (getEventInfo) {
var eventInfo = parse_array(getEventInfo.result);
console.log("event:", thisEvent);
console.log(" - branch:", parseInt(eventInfo[1]));
console.log(" - expirationDate:", parseInt(eventInfo[2]));
console.log(" - outcome:", parseInt(eventInfo[3]));
console.log(" - minValue:", parseInt(eventInfo[4]));
console.log(" - maxValue:", parseInt(eventInfo[5]));
console.log(" - numOutcomes:", parseInt(eventInfo[6]));
});
nextEvent();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment