-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Validator): Validator on Ethereum-specific Ledger Plugin
Signed-off-by: Takuma TAKEUCHI <[email protected]>
- Loading branch information
Showing
38 changed files
with
1,399 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,6 @@ | ||
core/node_modules/ | ||
core/package-lock.json | ||
dependent/node_modules/ | ||
dependent/package-lock.json | ||
core/npm-debug.log | ||
|
17 changes: 17 additions & 0 deletions
17
packages/ledger-plugin/go-ethereum/validator/src/README.md
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,17 @@ | ||
<!-- | ||
Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
SPDX-License-Identifier: Apache-2.0 | ||
README.md | ||
--> | ||
# Validator of Ethereum-speicific Ledger Plugin | ||
|
||
## Assumption | ||
- A ledger (Ethereum node) to connect is already running | ||
- Specify URL of the ledger node to connect to in "provider" of "PluginConfig.js" | ||
|
||
## Execution | ||
<pre> | ||
cd core | ||
node ./bin/www.js | ||
</pre> |
16 changes: 16 additions & 0 deletions
16
packages/ledger-plugin/go-ethereum/validator/src/build/Dockerfile
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,16 @@ | ||
# Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
FROM hyperledger/fabric-ccenv:x86_64-1.0.4 | ||
#ENV http_proxy $HTTP_PROXY | ||
#ENV https_proxy $HTTP_PROXY | ||
#ENV HTTP_PROXY $HTTP_PROXY | ||
#ENV HTTPS_PROXY $HTTP_PROXY | ||
#ENV NO_PROXY "rest-server,ec1-connector,ec2-connector,geth1,geth2" | ||
RUN apt update | ||
RUN apt-get install -y screen | ||
RUN apt-get install -y npm | ||
#RUN npm -g config set proxy $HTTP_PROXY | ||
RUN npm -g install n | ||
RUN n --version | ||
RUN n 8.9.0 | ||
RUN npm -g install express |
10 changes: 10 additions & 0 deletions
10
packages/ledger-plugin/go-ethereum/validator/src/core/CA/connector.crt
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,10 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBdTCCARoCCQC/F+Mh551QzDAKBggqhkjOPQQDAjBCMQswCQYDVQQGEwJKUDEQ | ||
MA4GA1UECAwHZXNqbXMxMjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkg | ||
THRkMB4XDTE4MDYyNzA3MjIzNVoXDTI4MDYyNDA3MjIzNVowQjELMAkGA1UEBhMC | ||
SlAxEDAOBgNVBAgMB2Vzam1zMTIxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg | ||
UHR5IEx0ZDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABDPpSD2w0zrqJKraGD1b | ||
5Jq2sDuacThSUqi7fvz8oyrWtuKDjZ15zIaSOtak6XRxFh9V9Gokdg5GNbW/pTZc | ||
TuowCgYIKoZIzj0EAwIDSQAwRgIhAKH6ERsyd5bpEMIkY4clPqguwDWoTLk2VKq6 | ||
ONEhUqotAiEA4yJxGmZpFdRScG2gDUIF2VDeX+XfHdJI2J41hyW9/zI= | ||
-----END CERTIFICATE----- |
8 changes: 8 additions & 0 deletions
8
packages/ledger-plugin/go-ethereum/validator/src/core/CA/connector.csr
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,8 @@ | ||
-----BEGIN CERTIFICATE REQUEST----- | ||
MIH9MIGkAgEAMEIxCzAJBgNVBAYTAkpQMRAwDgYDVQQIDAdlc2ptczEyMSEwHwYD | ||
VQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjO | ||
PQMBBwNCAAQz6Ug9sNM66iSq2hg9W+SatrA7mnE4UlKou378/KMq1rbig42decyG | ||
kjrWpOl0cRYfVfRqJHYORjW1v6U2XE7qoAAwCgYIKoZIzj0EAwIDSAAwRQIgCUA1 | ||
B5mZK7Hx79J1xBb0MGwuoUkt4bGPXbHqWEMZXQMCIQCRgadPkrNw56+pT5MVxA5K | ||
vV6xTgmxUYrYnpkR4tptqQ== | ||
-----END CERTIFICATE REQUEST----- |
8 changes: 8 additions & 0 deletions
8
packages/ledger-plugin/go-ethereum/validator/src/core/CA/connector.priv
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,8 @@ | ||
-----BEGIN EC PARAMETERS----- | ||
BggqhkjOPQMBBw== | ||
-----END EC PARAMETERS----- | ||
-----BEGIN EC PRIVATE KEY----- | ||
MHcCAQEEICIlCfK3zMTFzUgdaj01LAHjJmHlbg6Xql9+i70iPz5EoAoGCCqGSM49 | ||
AwEHoUQDQgAEM+lIPbDTOuokqtoYPVvkmrawO5pxOFJSqLt+/PyjKta24oONnXnM | ||
hpI61qTpdHEWH1X0aiR2DkY1tb+lNlxO6g== | ||
-----END EC PRIVATE KEY----- |
41 changes: 41 additions & 0 deletions
41
packages/ledger-plugin/go-ethereum/validator/src/core/app.js
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,41 @@ | ||
/* | ||
* Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* app.js | ||
*/ | ||
|
||
/* Summary: | ||
* | ||
*/ | ||
|
||
var express = require('express'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
|
||
var app = express(); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
// error handler | ||
app.use(function(err, req, res, next) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
|
||
// render the error page | ||
res.status(err.status || 500); | ||
console.log(err); | ||
res.send(err); | ||
}); | ||
|
||
module.exports = app; |
18 changes: 18 additions & 0 deletions
18
packages/ledger-plugin/go-ethereum/validator/src/core/config/default.js
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,18 @@ | ||
/* | ||
* Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* default.js | ||
*/ | ||
|
||
module.exports = { | ||
// Defined value for the destination independent part. | ||
// Destination dependent definition values should be in lib/PluginConfig.js. | ||
"sslParam" : { | ||
"port" : 5050, | ||
"key" : './CA/connector.priv', | ||
"cert" : './CA/connector.crt' | ||
}, | ||
// Log level (trace/debug/info/warn/error/fatal) | ||
"logLevel" : "debug" | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/ledger-plugin/go-ethereum/validator/src/core/package.json
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,19 @@ | ||
{ | ||
"name": "connector", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./bin/www" | ||
}, | ||
"dependencies": { | ||
"body-parser": "~1.17.1", | ||
"config": "^1.26.1", | ||
"cookie-parser": "~1.4.3", | ||
"debug": "~4.1.1", | ||
"express": "~4.15.2", | ||
"log4js": "^3.0.6", | ||
"morgan": "~1.8.1", | ||
"serve-favicon": "~2.4.2", | ||
"socket.io": "^2.0.4" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/ledger-plugin/go-ethereum/validator/src/dependent/PluginConfig.js
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,18 @@ | ||
/* | ||
* Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* PluginConfig.js | ||
*/ | ||
|
||
/* | ||
* Summary: | ||
* Configuration file of cooperation server: a part dependent on end-chains | ||
* Definition values specific to the connection dependent part, etc. | ||
*/ | ||
|
||
module.exports = { | ||
// URL to operate and monitor | ||
//"provider" : 'http://geth1:8545' | ||
"provider" : 'http://localhost:8545' | ||
}; |
68 changes: 68 additions & 0 deletions
68
packages/ledger-plugin/go-ethereum/validator/src/dependent/PluginUtil.js
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,68 @@ | ||
/* | ||
* Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* PluginUtil.js | ||
*/ | ||
|
||
/* | ||
* Summary: | ||
* Cooperation server: utility library dependent on endchains | ||
* For example, implementing internal functions that should not be exposed as functions of server plugins. | ||
*/ | ||
|
||
/* | ||
* convNum | ||
* | ||
* @param {String/Number} value: The scientific string or numeric value to be converted. For numbers, it is returned as is. | ||
* @param {String/Number} default_value: The value to use if conversion was not possible. Text or number in scientific notation. Optional. | ||
* | ||
* @return {Number} The value converted to a number, or the default_value if the conversion failed. | ||
* | ||
* @desc exponentiation is also supported. The following formats are supported:. (value, default_value) | ||
* 3.78*10^14 | ||
* 3.78e14 | ||
*/ | ||
exports.convNum = function(value, default_value) { | ||
var retvalue = 0; | ||
var def_value = 0; | ||
|
||
switch(typeof(default_value)) { | ||
case "number": | ||
def_value = default_value; | ||
break; | ||
case "string": | ||
var def_value_str = default_value.replace(/\*10\^/g, "e"); | ||
def_value = parseFloat(def_value_str); | ||
break; | ||
default: // undefined should also be included here. | ||
// Fixed value because of cumbersome handling. | ||
def_value = 0; | ||
break; | ||
} // switch(typeof(default_value)) | ||
|
||
if(def_value==NaN) { // number is guaranteed. | ||
def_value = 0; | ||
} | ||
|
||
switch(typeof(value)) { | ||
case "number": | ||
retvalue = value; | ||
break; | ||
case "string": | ||
var value_str = value.replace(/\*10\^/g, "e"); | ||
retvalue = parseFloat(value_str); | ||
break; | ||
default: | ||
// Set default value. | ||
retvalue = def_value; | ||
break; | ||
} // switch(typeof(value)) | ||
|
||
if(retvalue==NaN) { // number is guaranteed. | ||
retvalue = def_value; | ||
} | ||
|
||
return retvalue; | ||
} | ||
|
118 changes: 118 additions & 0 deletions
118
packages/ledger-plugin/go-ethereum/validator/src/dependent/ServerMonitorPlugin.js
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,118 @@ | ||
/* | ||
* Copyright 2019-2020 Fujitsu Laboratories Ltd. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* ServerMonitorPlugin.js | ||
*/ | ||
|
||
/* | ||
* Summary: | ||
* Connector: monitoring class of a part dependent on end-chains | ||
* Used in the case of monitoring continuously. | ||
* Processing that ends with the acceptance of a single event is handled by a custom function implementation in server plugins. | ||
* Unlike server plugins, it basically does not handle its own functions. | ||
*/ | ||
|
||
// configuration file | ||
var SplugConfig = require('./PluginConfig.js'); | ||
var config = require('config'); | ||
// Log settings | ||
var log4js = require('log4js'); | ||
var logger = log4js.getLogger('ServerMonitorPlugin[' + process.pid + ']'); | ||
logger.level = config.logLevel; | ||
// Load libraries, SDKs, etc. according to specifications of endchains as needed | ||
var Web3 = require('web3'); | ||
|
||
/* | ||
* ServerMonitorPlugin | ||
* Class definitions of server monitoring | ||
*/ | ||
var ServerMonitorPlugin = class { | ||
/* | ||
* constructors | ||
*/ | ||
constructor(){ | ||
// Define dependent specific settings | ||
// Initialize monitored filter | ||
this._filterTable = {}; | ||
} | ||
|
||
/* | ||
* startMonitor | ||
* Start Monitoring | ||
* @param {string} clientId: Client ID from which monitoring start request was made | ||
* @param {function} cb: A callback function that receives monitoring results at any time. | ||
*/ | ||
startMonitor(clientId, cb) { | ||
logger.info('*** START MONITOR ***'); | ||
logger.info('Client ID :' + clientId); | ||
// Implement handling to receive events from an end-chain and return them in a callback function | ||
var filter = this._filterTable[clientId]; | ||
if (!filter) { | ||
logger.info('create new web3 filter and start watching.'); | ||
try { | ||
var web3 = new Web3(); | ||
var provider = new web3.providers.HttpProvider(SplugConfig.provider); | ||
web3.setProvider(provider); | ||
filter = web3.eth.filter("latest"); | ||
// filter should be managed by client ID | ||
// (You should never watch multiple urls from the same client) | ||
this._filterTable[clientId] = filter; | ||
filter.watch(function (error, blockHash) { | ||
if (!error) { | ||
console.log('##[HL-BC] Notify new block data(D2)'); | ||
var blockData = web3.eth.getBlock(blockHash, true); | ||
var trLength = blockData.transactions.length; | ||
logger.info(trLength + " transactions in block " + blockData.number); | ||
console.log('##[HL-BC] Validate transactions(D3)'); | ||
console.log('##[HL-BC] digital sign on valid transaction(D4)'); | ||
if (trLength > 0) { | ||
logger.info('*** SEND BLOCK DATA ***'); | ||
// Notify only if transaction exists | ||
var ret_obj = { | ||
"status" : 200, | ||
"blockData" : blockData | ||
}; | ||
cb(ret_obj); | ||
} | ||
} else { | ||
var err_obj = { | ||
"status" : 504, | ||
"errorDetail" : error | ||
}; | ||
cb(err_obj); | ||
} | ||
}); | ||
} catch (e) { | ||
var emsg = e.toString().replace(/Error: /g , ""); | ||
var err_obj = { | ||
"status" : 504, | ||
"errorDetail" : emsg | ||
}; | ||
cb(err_obj); | ||
} | ||
} else { | ||
logger.info('target filter has already start watching.'); | ||
} | ||
} | ||
|
||
/* | ||
* stopMonitor | ||
* monitoring stop | ||
* @param {string} clientId: Client ID from which monitoring stop request was made | ||
*/ | ||
stopMonitor(clientId) { | ||
// Implement a process to end EC monitoring | ||
var filter = this._filterTable[clientId]; | ||
if (filter) { | ||
// Stop the filter & Remove it from table | ||
logger.info('stop watching and remove filter.'); | ||
filter.stopWatching(); | ||
delete this._filterTable[clientId]; | ||
} | ||
} | ||
|
||
} /* class */ | ||
|
||
module.exports = ServerMonitorPlugin; | ||
|
Oops, something went wrong.