diff --git a/server/web3tools/app.js b/server/web3tools/app.js index 21bec0e..eb9638f 100644 --- a/server/web3tools/app.js +++ b/server/web3tools/app.js @@ -6,7 +6,7 @@ const event = require('j7/event'); const config = require('j7/config'); const bchelper = require('common/bchelper'); -function jsonToCsv(fileName, data, fields) { +function jsonToCsvOld(fileName, data, fields) { let out = ''; fields.forEach( (field) => { @@ -27,6 +27,40 @@ function jsonToCsv(fileName, data, fields) { fs.writeFileSync(fileName, out); } +function jsonToCsv(fileName, data, fields) { + let out = ''; + const csvFields = [ + ['chain', '', 42161], + ['to', 'address', ''], + ['type', '', 2], + ['address', '', '0x79fc2a4216A1e595DBD09D13c4B4bD3B095d5bb2'], + ['from', '', ''], + ['amount', '', ''], + ['tokenid', 'token_id', ''] + ]; + csvFields.forEach( + (field) => { + out += field[0] + ','; + } + ); + out += '\n'; + data.forEach( + (row) => { + csvFields.forEach( + (field) => { + if (row[field[1]]) { + out += row[field[1]] + ','; + } else { + out += field[2] + ','; + } + } + ); + out += '\n'; + } + ); + fs.writeFileSync(fileName, out); +} + const heroList = [30100, 30300, 30400, 30500, 30600, 30800, 30900]; const airDropDate = utils.getArgv('f'); const json = utils.readJsonFromFile