Last active
February 6, 2018 20:43
-
-
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
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
'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