Skip to content

Instantly share code, notes, and snippets.

@raypulver
Last active February 6, 2018 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raypulver/bf46652a476249f4b8bdc6edca072fac to your computer and use it in GitHub Desktop.
Save raypulver/bf46652a476249f4b8bdc6edca072fac to your computer and use it in GitHub Desktop.
script to get a JSON snapshot of the balances for a particular token
'use strict';
const db = require('../lib/db');
const { argv } = require('yargs');
const {
method,
bindKey,
partialRight,
property
} = require('lodash');
const {
flow,
keyBy,
mapValues,
curryN,
map
} = require('lodash/fp');
const writeFile = curryN(2, require('fs-extra').writeFile);
const toPlain = method('get', { plain: true });
const mapToPlain = map(toPlain);
const jsonStringify = bindKey(JSON, 'stringify');
const prettyStringify = partialRight(jsonStringify, null, 1);
db.initializeDatabase().then(() => db.getModel('Token').findOne({
where: { symbol: argv._[0] }
})).then(flow(
toPlain,
property('address'),
method('toLowerCase')
))
.then((token) => db.getModel('Balance').findAll({
where: {
token
}
}))
.then(flow(
mapToPlain,
keyBy('address'),
mapValues(property('balance')),
prettyStringify
))
.then(writeFile(argv.o || 'balance-dump-' + argv._[0] + '.json'))
.then(db.close)
.catch(flow(
property('stack'),
console.error
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment