UNPKG

@savid/rlpx-pest

Version:

Get the [status](https://github.com/ethereum/devp2p/blob/master/caps/eth.md#status-0x00) of a [RLPx](https://github.com/ethereum/devp2p/blob/master/rlpx.md) peer via the [eth/66](https://eips.ethereum.org/EIPS/eip-2481) protocol.

42 lines 1.05 kB
import Peer from './peer.js'; export { PeerError } from './peer.js'; export default async ({ enode, timeout = 30000, }) => new Promise((res, rej) => { const url = new URL(enode); if (url.protocol !== 'enode:') { rej(new Error(`invalid enode protocol: ${url.protocol}`)); return; } let peer; let timer; let client; const cleanup = () => { clearTimeout(timer); peer.removeAllListeners(); peer.destroy(); }; timer = setTimeout(() => { cleanup(); rej(new Error('timeout')); }, timeout); peer = new Peer({ remoteId: Buffer.from(url.username, 'hex'), host: url.hostname, port: Number.parseInt(url.port), }); peer.on('err', (error) => { cleanup(); rej(error); }); peer.on('client', (c) => { client = c; }); peer.on('status', (status) => { cleanup(); res({ ...status, client, }); }); peer.init(); }); //# sourceMappingURL=index.js.map