Skip to content

Commit

Permalink
Update capability
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Nov 29, 2017
1 parent d752f85 commit 86013db
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
9 changes: 8 additions & 1 deletion flow-typed/ethereumjs-devp2p.js
Expand Up @@ -33,10 +33,17 @@ declare module 'ethereumjs-devp2p' {
port: number
};

declare type EjsDevP2pCapability$Status = {
bestHash: Buffer,
genesisHash: Buffer,
networkId: number,
td: Buffer
};

declare interface EjsDevP2pCapability {
_handleMessage (code: number, data: Buffer): any;
getVersion (): number;
sendStatus (status: string): any;
sendStatus (status: EjsDevP2pCapability$Status): any;
sendMessage (code: number, payload: Array<Buffer>): any;
}

Expand Down
11 changes: 0 additions & 11 deletions package.json
Expand Up @@ -5,17 +5,6 @@
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "ISC",
"private": true,
"engines": {
"node": ">=8.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/polkadot-js/client.git"
},
"bugs": {
"url": "https://github.com/polkadot-js/client/issues"
},
"homepage": "https://github.com/polkadot-js/client#readme",
"workspaces": [
"packages/*"
],
Expand Down
15 changes: 8 additions & 7 deletions packages/client-p2p/src/protocol/devp2p.js
@@ -1,8 +1,9 @@
// ISC, Copyright 2017 Jaco Greeff
// @flow

import type { EjsDevP2pCapability, EjsDevP2pRlpx$Capability, EjsDevP2pRlpx$Node } from 'ethereumjs-devp2p';
import type { EjsDevP2pCapability, EjsDevP2pCapability$Status, EjsDevP2pRlpx$Capability, EjsDevP2pRlpx$Node } from 'ethereumjs-devp2p';

const numberToBuffer = require('@polkadot/util/number/toBuffer');
const EthDevP2p = require('ethereumjs-devp2p');

const ProtocolBase = require('./base');
Expand All @@ -26,15 +27,15 @@ class DevP2pImpl extends ProtocolBase implements EjsDevP2pCapability {
super.receive(code, data);
}

sendStatus (status: any): any {
sendStatus ({ bestHash, genesisHash, networkId, td }: EjsDevP2pCapability$Status): any {
super.send(
EthDevP2p.ETH.MESSAGE_CODES.STATUS,
[
EthDevP2p._util.int2buffer(this._version),
EthDevP2p._util.int2buffer(status.networkId),
status.td,
status.bestHash,
status.genesisHash
numberToBuffer(this._version),
numberToBuffer(networkId),
td,
bestHash,
genesisHash
]
);
}
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Expand Up @@ -111,6 +111,14 @@
bn.js "^4.11.8"
keccak "^1.3.0"

"@polkadot/util@^0.5.20":
version "0.5.20"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.5.20.tgz#9c93c3e7b3bb600847f8665897aacc9c56fe5feb"
dependencies:
babel-runtime "^6.26.0"
bn.js "^4.11.8"
keccak "^1.3.0"

JSONStream@^1.0.4:
version "1.3.1"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.1.tgz#707f761e01dae9e16f1bcf93703b78c70966579a"
Expand Down

0 comments on commit 86013db

Please sign in to comment.