Last active
May 2, 2020 17:09
-
-
Save Amxx/7cdff7687cd7addaf075d3d7a1259126 to your computer and use it in GitHub Desktop.
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
process.stdin.setEncoding('utf-8'); | |
const readline = require('readline').createInterface({ input: process.stdin }); | |
const buffer = []; | |
const uniqueBy = (array, selector) => array | |
.map(selector) | |
.filter((e, i, a) => a.indexOf(e) === i) | |
.map(v => array.find(e => selector(e) === v)); | |
readline.on('line', (line) => buffer.push(line)); | |
readline.on('close', () => { | |
const abi = JSON.parse(buffer.join('\n')); | |
console.log(JSON.stringify([ | |
abi.find(({type}) => type === 'constructor'), // constructor | |
abi.find(({type}) => type === 'receive' ), // receive | |
abi.find(({type}) => type === 'fallback' ), // fallback | |
...uniqueBy(abi.filter(({type}) => type === 'function'), e => e.signature), // functions | |
...uniqueBy(abi.filter(({type}) => type === 'event' ), e => e.signature), // events | |
].filter(Boolean))) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment