Skip to content

Instantly share code, notes, and snippets.

@Amxx
Last active May 2, 2020 17:09
Show Gist options
  • Save Amxx/7cdff7687cd7addaf075d3d7a1259126 to your computer and use it in GitHub Desktop.
Save Amxx/7cdff7687cd7addaf075d3d7a1259126 to your computer and use it in GitHub Desktop.
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