-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation for sending endorser proposal
To test, set up a network from the feature/convergence branch using a v1.0 docker-compose such as bddtests/bdd-docker/docker-compose-next-4.yml. Make sure to map the ports by adding the "ports" section. If you can't get this working in a native docker, you can run it inside vagrant. Run "node test/unit/endorser-tests.js" In response to comments: - merged the latest from master (changes from CR 1477) Change-Id: Icee9600580be1dd42c1d1b44d57906bf84c06c94 Signed-off-by: Jim Zhang <[email protected]>
- Loading branch information
1 parent
c5dd336
commit 25cbf0e
Showing
11 changed files
with
949 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var gulp = require('gulp'); | ||
var eslint = require('gulp-eslint'); | ||
|
||
gulp.task('lint', function () { | ||
return gulp.src(['**/*.js', '!node_modules/**', '!docs/**']) | ||
.pipe(eslint( | ||
{ | ||
env: ['es6', 'node'], | ||
extends: 'eslint:recommended', | ||
parserOptions: { | ||
sourceType: 'module' | ||
}, | ||
rules: { | ||
indent: ['error', 'tab'], | ||
'linebreak-style': ['error', 'unix'], | ||
quotes: ['error', 'single'], | ||
semi: ['error', 'always'] | ||
} | ||
} | ||
)) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
}); |
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 |
---|---|---|
@@ -1,32 +1,9 @@ | ||
var requireDir = require('require-dir'); | ||
var gulp = require('gulp'); | ||
|
||
// Require all tasks in gulp/tasks, including subfolders | ||
requireDir('./build/tasks', { recurse: true }); | ||
|
||
var gulp = require('gulp'); | ||
var eslint = require('gulp-eslint'); | ||
|
||
gulp.task('lint', function () { | ||
return gulp.src(['**/*.js', '!node_modules/**', '!docs/**']) | ||
.pipe(eslint( | ||
{ | ||
env: ['es6', 'node'], | ||
extends: 'eslint:recommended', | ||
parserOptions: { | ||
sourceType: 'module' | ||
}, | ||
rules: { | ||
indent: ['error', 'tab'], | ||
'linebreak-style': ['error', 'unix'], | ||
quotes: ['error', 'single'], | ||
semi: ['error', 'always'] | ||
} | ||
} | ||
)) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
}); | ||
|
||
gulp.task('default', ['lint'], function () { | ||
// This will only run if the lint task is successful... | ||
}); |
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,82 @@ | ||
/* | ||
Copyright 2016 IBM All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var api = require('./api.js'); | ||
var utils = require('./utils.js'); | ||
var grpc = require('grpc'); | ||
|
||
var _fabricProto = grpc.load(__dirname + '/protos/fabric_next.proto').protos; | ||
|
||
/** | ||
* The Peer class represents a peer in the target blockchain network to which | ||
* HFC sends endorsement proposals, transaction ordering or query requests. | ||
* | ||
* @class | ||
*/ | ||
var Peer = class { | ||
|
||
/** | ||
* Constructs a Peer given its endpoint configuration settings | ||
* and returns the new Peer. | ||
* | ||
* @param {string} url The URL with format of "grpcs://host:port". | ||
* @param {Chain} chain The chain of which this peer is a member. | ||
* @param {string} pem The certificate file, in PEM format, | ||
* to use with the gRPC protocol (that is, with TransportCredentials). | ||
* Required when using the grpcs protocol. | ||
*/ | ||
constructor(url) { | ||
this._url = url; | ||
this._ep = new utils.Endpoint(url, null); | ||
this._endorserClient = new _fabricProto.Endorser(this._ep.addr, this._ep.creds); | ||
} | ||
|
||
/** | ||
* Get the URL of the peer. | ||
* @returns {string} Get the URL associated with the peer. | ||
*/ | ||
getUrl() { | ||
return this._url; | ||
} | ||
|
||
/** | ||
* Send an endorsement proposal to an endorser. | ||
* | ||
* @param {Object} proposal A proposal of type Proposal | ||
* @returns Promise for a ProposalResponse | ||
*/ | ||
sendProposal(proposal) { | ||
var self = this; | ||
|
||
// Send the transaction to the peer node via grpc | ||
// The rpc specification on the peer side is: | ||
// rpc ProcessProposal(Proposal) returns (ProposalResponse) {} | ||
return new Promise(function(resolve, reject) { | ||
self._endorserClient.processProposal(proposal, function (err, response) { | ||
if (err) { | ||
reject(new Error(err)); | ||
} | ||
|
||
console.log('Response code:' + JSON.stringify(response.response.status)); | ||
resolve(response.response.status); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = Peer; |
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
Oops, something went wrong.