Last active
April 3, 2018 07:37
-
-
Save benjaminion/7e2b3f8968c68e147c47c30e144e09ce to your computer and use it in GitHub Desktop.
Get `entrants_` list from the theCyberGatekeeper contract. Run with `node get_entrants.js`. Insert a node's RPC or IPC interface before using - Infura is convenient, and you can leave that in place if you like.
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
// Prints out all members of the `entrants_` list in order of appearance | |
// from the theCyberGateKeeper contract. | |
// Insert a node's RPC or IPC interface | |
const RPC_URL = 'https://mainnet.infura.io/'; | |
// The theCyberGateway contract | |
const CONTRACT = "0x44919b8026f38D70437A8eB3BE47B06aB1c3E4Bf"; | |
const IDX = "0000000000000000000000000000000000000000000000000000000000000001"; | |
const Web3 = require('web3'); | |
const web3 = new Web3(RPC_URL); | |
main(); | |
// Async so we can use await... | |
async function main() | |
{ | |
// The number of entrants is stored at 0x00..01 | |
// Entrant 0 is at keccack256(0x00..01) + 0 | |
// Entrant 1 is at keccack256(0x00..01) + 1 | |
// Entrant n is at keccack256(0x00..01) + n | |
// Get number of entrants | |
var num = await web3.eth.getStorageAt(CONTRACT, IDX) | |
.then(ret => {return parseInt(ret)}); | |
console.log("Number of entrants: " + num); | |
// Asynchronously fetch all the entrants from the contract storage | |
var p = []; | |
var accts = []; | |
var n = web3.utils.keccak256("0x" + IDX).slice(-64); | |
for (let i = 0; i < num; i++) { | |
p.push(web3.eth.getStorageAt(CONTRACT, "0x" + n) | |
.then(ret => {accts[i] = "0x" + ret.slice(-40)})); | |
n = incHex(n); | |
} | |
// Output entrants in order of entry | |
await Promise.all(p) | |
.then(ret => { | |
for (let i = 0; i < num; i++) { console.log(accts[i]) } | |
}); | |
} | |
// Recursively increment a hexadecimal string | |
// Wraps-round on overflow | |
function incHex(n) | |
{ | |
if (n.length === 0) | |
return n; | |
var inc = (parseInt(n.slice(-1),16) + 1).toString(16).slice(-1); | |
return inc === '0' | |
? incHex(n.slice(0,-1)) + inc | |
: n.slice(0,-1) + inc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment