-
Notifications
You must be signed in to change notification settings - Fork 295
/
introspect-address.js
35 lines (32 loc) · 1.12 KB
/
introspect-address.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// @flow
import { spawnSync } from 'child_process';
import { MainIpcChannel } from './lib/MainIpcChannel';
import { INTROSPECT_ADDRESS_CHANNEL } from '../../common/ipc/api';
import type {
IntrospectAddressRendererRequest,
IntrospectAddressMainResponse,
} from '../../common/ipc/api';
// IpcChannel<Incoming, Outgoing>
export const introspectAddressChannel: MainIpcChannel<
IntrospectAddressRendererRequest,
IntrospectAddressMainResponse
> = new MainIpcChannel(INTROSPECT_ADDRESS_CHANNEL);
export const handleAddressIntrospectionRequests = () => {
introspectAddressChannel.onReceive(
({ input }: IntrospectAddressRendererRequest) =>
new Promise((resolve, reject) => {
const { stdout, stderr } = spawnSync(
'cardano-address',
['address', 'inspect'],
{ input }
);
if (stderr.toString() !== '') {
if (stderr.toString().match(/user error/g) !== null) {
return resolve('Invalid');
}
return reject(new Error(stderr.toString()));
}
return resolve({ introspection: JSON.parse(stdout.toString()) });
})
);
};