Skip to content

Commit

Permalink
fix(address-introspection): refactor to spawning a child process
Browse files Browse the repository at this point in the history
Rather than the single line `exec`, this uses Node.js cross-platform API
to pass stdin
  • Loading branch information
rhyslbw committed Jul 10, 2020
1 parent 1fc63d0 commit 9f25d68
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions source/main/ipc/introspect-address.js
@@ -1,5 +1,5 @@
// @flow
import { exec } from 'child_process';
import { spawn } from 'child_process';
import { MainIpcChannel } from './lib/MainIpcChannel';
import { INTROSPECT_ADDRESS_CHANNEL } from '../../common/ipc/api';
import type {
Expand All @@ -18,23 +18,25 @@ export const handleAddressIntrospectionRequests = () => {
introspectAddressChannel.onReceive(
(request: IntrospectAddressRendererRequest) =>
new Promise((resolve, reject) => {
exec(
`echo ${request.input} | cardano-address address inspect`,
(error, stdout) => {
if (
error &&
error.message.match(
/user error \(Unrecognized address on standard input\)/g
) !== null
) {
return resolve('Invalid');
}
if (error) {
reject(error);
}
return resolve({ introspection: JSON.parse(stdout) });
const introspect = spawn('cardano-address', ['address', 'inspect']);

introspect.stderr.on('error', (error) => {
if (
error &&
error.message.match(
/user error \(Unrecognized address on standard input\)/g
) !== null
) {
return resolve('Invalid');
}
);
return reject(error)
});

introspect.stdout.on('data', (data) => {
return resolve({ introspection: JSON.parse(data) })
});

introspect.stdin.write(request.input)
})
);
};

0 comments on commit 9f25d68

Please sign in to comment.