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.

35 lines 1.3 kB
import { strict as assert } from 'node:assert'; import { arrToBufArr, bufferToBigInt } from '@ethereumjs/util'; import RLP from 'rlp'; export default (callback) => ({ name: 'eth', version: 66, length: 17, constructor: class EthProtocol { handleMessage(code, message) { if (code !== 0x00) { callback(new Error(`invalid code: ${code}`)); return; } try { const payload = arrToBufArr(RLP.decode(Uint8Array.from(message))); assert.equal(payload.length, 6); assert.equal(payload[5].length, 2); callback(undefined, { networkId: bufferToBigInt(payload[1]), td: bufferToBigInt(payload[2]), bestHash: `0x${payload[3].toString('hex')}`, genesisHash: `0x${payload[4].toString('hex')}`, fork: { hash: `0x${payload[5][0].toString('hex')}`, next: `0x${payload[5][1].toString('hex') || '00'}`, }, }); } catch (err) { callback(new Error(`failed to decode RLP: ${err}`)); } } }, }); //# sourceMappingURL=eth66.js.map