-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@embark/nethermind): add Nethermind blockchain client plugin
- Loading branch information
1 parent
4190d5e
commit 6db8d87
Showing
23 changed files
with
1,022 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const WebSocket = require("ws"); | ||
const http = require("http"); | ||
const https = require("https"); | ||
|
||
const LIVENESS_CHECK=`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":42}`; | ||
|
||
const parseAndRespond = (data, cb) => { | ||
let resp; | ||
try { | ||
resp = JSON.parse(data); | ||
if (resp.error) { | ||
return cb(resp.error); | ||
} | ||
} catch (e) { | ||
return cb('Version data is not valid JSON'); | ||
} | ||
if (!resp || !resp.result) { | ||
return cb('No version returned'); | ||
} | ||
const [_, version, __] = resp.result.split('/'); | ||
cb(null, version); | ||
}; | ||
|
||
const testRpcWithEndpoint = (endpoint, cb) => { | ||
const options = { | ||
method: "POST", | ||
timeout: 1000, | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Content-Length": Buffer.byteLength(LIVENESS_CHECK) | ||
} | ||
}; | ||
|
||
let obj = http; | ||
if (endpoint.startsWith('https')) { | ||
obj = https; | ||
} | ||
|
||
const req = obj.request(endpoint, options, (res) => { | ||
let data = ""; | ||
res.on("data", chunk => { data += chunk; }); | ||
res.on("end", () => parseAndRespond(data, cb)); | ||
}); | ||
req.on("error", (e) => cb(e)); | ||
req.write(LIVENESS_CHECK); | ||
req.end(); | ||
}; | ||
|
||
const testWsEndpoint = (endpoint, cb) => { | ||
const conn = new WebSocket(endpoint); | ||
conn.on("message", (data) => { | ||
parseAndRespond(data, cb); | ||
conn.close(); | ||
}); | ||
conn.on("open", () => conn.send(LIVENESS_CHECK)); | ||
conn.on("error", (e) => cb(e)); | ||
}; | ||
|
||
module.exports = { | ||
testWsEndpoint, | ||
testRpcWithEndpoint | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
engine-strict = true | ||
package-lock = false | ||
save-exact = true | ||
scripts-prepend-node-path = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# `embark-nethermind` | ||
|
||
> Nethermind blockchain client plugin for Embark | ||
|
||
## Quick docs | ||
|
||
To configure the Netherminds client, you can use the Embark configs as always, or for more control, use the Nethermind config files. | ||
To change them, go in your Netherminds directory, then in `configs/`. There, you will see all the configuration files for the different networks. | ||
If you ever need to run a different network than dev, testnet or mainnet, you can change it in the Embark blockchain configuration by changing the `networkType` to the name of the config file, without the `.cfg`. | ||
Eg: For the Goerli network, just put `networkType: 'goerli` | ||
Note: The dev mode of Netherminds is called `ndm` and the config file is `ndm_consumer_local.cfg`. Using `miningMode: 'dev'` automatically translates to using that config file. | ||
|
||
## Websocket support | ||
|
||
Even though Nethermind supports Websocket connections, it does not support `eth_subscribe`, so you will not be able to use contract events. | ||
Also, please note that you will need to change the `endpoint` in the blockchain configuration to `ws://localhost:8545/ws/json-rpc` when working in local. Do change the port or the host to whatever you need. | ||
|
||
Visit [embark.status.im](https://embark.status.im/) to get started with | ||
[Embark](https://github.com/embark-framework/embark). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "embark-nethermind", | ||
"version": "5.0.0-alpha.9", | ||
"author": "Iuri Matias <iuri.matias@gmail.com>", | ||
"contributors": [], | ||
"description": "Nethermind blockchain client plugin for Embark", | ||
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/plugins/nethermind#readme", | ||
"bugs": "https://github.com/embark-framework/embark/issues", | ||
"keywords": [ | ||
"blockchain", | ||
"dapps", | ||
"ethereum", | ||
"serverless", | ||
"nethermind" | ||
], | ||
"files": [ | ||
"dist" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"directory": "packages/plugins/nethermind", | ||
"type": "git", | ||
"url": "https://github.com/embark-framework/embark.git" | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"embark-collective": { | ||
"build:node": true, | ||
"typecheck": true | ||
}, | ||
"scripts": { | ||
"_build": "npm run solo -- build", | ||
"_typecheck": "npm run solo -- typecheck", | ||
"ci": "npm run qa", | ||
"clean": "npm run reset", | ||
"lint": "eslint src/", | ||
"qa": "npm-run-all lint _typecheck _build", | ||
"reset": "npx rimraf dist embark-*.tgz package", | ||
"solo": "embark-solo" | ||
}, | ||
"eslintConfig": { | ||
"extends": "../../../.eslintrc.json" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime-corejs3": "7.7.4", | ||
"async": "2.6.1", | ||
"core-js": "3.4.3", | ||
"embark-core": "^5.0.0-alpha.9", | ||
"embark-i18n": "^5.0.0-alpha.5", | ||
"embark-utils": "^5.0.0-alpha.9", | ||
"fs-extra": "8.1.0", | ||
"netcat": "1.3.5", | ||
"semver": "5.6.0", | ||
"ws": "7.1.2" | ||
}, | ||
"devDependencies": { | ||
"embark-solo": "^5.0.0-alpha.5", | ||
"eslint": "5.7.0", | ||
"npm-run-all": "4.1.5", | ||
"rimraf": "3.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=10.17.0 <12.0.0", | ||
"npm": ">=6.11.3", | ||
"yarn": ">=1.19.1" | ||
} | ||
} |
Oops, something went wrong.