Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 04a9d05

Browse files
committed
FAB-985 Implement official SDK API design
FAB-985 Stub out functions still to be implemented and move existing functions to classes as described by the documentation link in the issue. - New Client class is added as main API entry and allows an application to have more than one instance - Chain class is modified to become the main class for submitting proposals and transactions - Member is deleted and replaced by new class User Patch 3: further refactoring and restoring "endorser-tests.js" to work again Patch 4: restored "headless-tests.js" Patch 5: restored "orderer-tests.js", "orderer-chain-tests.js", "chain-fabriccop-tests.js" and "end-to-end.js" Patch 6: merged with latest in master Change-Id: Icd03dd0bcb5c913276aa4879593ad66e6e824bc6 Signed-off-by: cdaughtr <cdaughtr@us.ibm.com> Signed-off-by: Jim Zhang <jzhang@us.ibm.com>
1 parent fecedd7 commit 04a9d05

21 files changed

+1763
-1621
lines changed

build/tasks/doc.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ gulp.task('doc', function () {
2525
'hfc/lib/impl/FileKeyValueStore.js',
2626
'hfc/lib/impl/CryptoSuite_ECDSA_AES.js',
2727
'hfc/lib/impl/ecdsa/key.js',
28-
'hfc/lib/impl/FabricCOPImpl.js',
2928
'hfc/lib/Chain.js',
30-
'hfc/lib/Member.js',
3129
'hfc/lib/Peer.js',
32-
'hfc/lib/X509Certificate.js'
30+
'hfc/lib/User.js',
31+
'hfc/lib/Client.js',
32+
'hfc/lib/X509Certificate.js',
33+
'hfc-cop/index.js',
34+
'hfc-cop/lib/FabricCOPImpl.js'
3335
], {read: false})
3436
.pipe(jsdoc())
3537
.pipe(gulp.dest('./docs/gen'));

build/tasks/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ gulp.task('test', ['pre-test'], function() {
2222
'test/unit/chain-fabriccop-tests.js',
2323
'test/unit/endorser-tests.js',
2424
'test/unit/orderer-tests.js',
25-
'test/unit/orderer-member-tests.js',
25+
'test/unit/orderer-chain-tests.js',
2626
'test/unit/end-to-end.js',
2727
'test/unit/headless-tests.js'
2828
])

build/tasks/watch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ gulp.task('watch', function () {
99
.pipe(gulp.dest('hfc-cop/'));
1010

1111
watch([
12-
'hfc/lib/**/*',
1312
'hfc/index.js',
1413
'hfc/config/**/*',
15-
'hfc-cop/lib/**/*',
16-
'hfc-cop/config/**/*'
14+
'hfc/lib/**/*',
15+
'hfc-cop/index.js',
16+
'hfc-cop/config/**/*',
17+
'hfc-cop/lib/**/*'
1718
], { ignoreInitial: false, base: './' })
1819
.pipe(debug())
1920
.pipe(gulp.dest('node_modules'));

hfc-cop/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2016 IBM All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* This is the pluggable module for the "hfc-cop" (Hyperledger Fabric Client Membership Services
19+
* aka "COP") package. COP is not an acronym. The name was selected because:
20+
* - it provides police-like security functionality for Hyperledger Fabric, and
21+
* - it is shorter and easier to say and write “COP” rather than “Membership Services"
22+
*
23+
* @module hfc-cop
24+
*/

hfc-cop/lib/FabricCOPImpl.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var logger = utils.getLogger('FabricCOPImpl.js');
3131

3232
/**
3333
* This is an implementation of the member service client which communicates with the Fabric COP server.
34-
*
3534
* @class
3635
*/
3736
var FabricCOPServices = class {

hfc/index.js

Lines changed: 1 addition & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -21,206 +21,4 @@
2121
* @module hfc
2222
*/
2323

24-
var util = require('util');
25-
var Chain = require('./lib/Chain.js');
26-
var Config = require('./lib/Config.js');
27-
var Peer = require('./lib/Peer.js');
28-
var utils = require('./lib/utils.js');
29-
30-
var _chains = {};
31-
32-
/**
33-
* Create a new chain. If it already exists, throws an Error.
34-
* @param name {string} Name of the chain. It can be any name and has value only for the client.
35-
*
36-
* @returns [Chain]{@link module:api.Chain} a new instance of the Chain class
37-
*/
38-
module.exports.newChain = function(name) {
39-
var chain = _chains[name];
40-
41-
if (chain)
42-
throw new Error(util.format('Chain %s already exists', name));
43-
44-
chain = new Chain(name);
45-
46-
_chains[name] = chain;
47-
return chain;
48-
};
49-
50-
/**
51-
* Get a chain. If it doesn't yet exist and 'create' is true, create it.
52-
* @param {string} chainName The name of the chain to get or create.
53-
* @param {boolean} create If the chain doesn't already exist, specifies whether to create it.
54-
* @returns {Chain} Returns the chain, or null if it doesn't exist and create is false.
55-
*/
56-
module.exports.getChain = function(chainName, create) {
57-
var chain = _chains[chainName];
58-
59-
if (!chain && create) {
60-
chain = this.newChain(chainName);
61-
}
62-
63-
return chain;
64-
};
65-
66-
/**
67-
* Constructs and returns a Peer given its endpoint configuration settings.
68-
*
69-
* @param {string} url The URL with format of "grpcs://host:port".
70-
* @param {Object} opts The options for the connection to the peer.
71-
* @returns {Peer} Returns the new peer.
72-
*/
73-
module.exports.getPeer = function(url, opts) {
74-
var peer = new Peer(url, opts);
75-
76-
return peer;
77-
};
78-
79-
80-
/**
81-
* Obtains an instance of the [KeyValueStore]{@link module:api.KeyValueStore} class. By default
82-
* it returns the built-in implementation, which is based on files ([FileKeyValueStore]{@link module:api.FileKeyValueStore}).
83-
* This can be overriden with an environment variable KEY_VALUE_STORE, the value of which is the
84-
* full path of a CommonJS module for the alternative implementation.
85-
*
86-
* @param {Object} options is whatever the implementation requires for initializing the instance. For the built-in
87-
* file-based implementation, this requires a single property "path" to the top-level folder for the store
88-
* @returns [KeyValueStore]{@link module:api.KeyValueStore} an instance of the KeyValueStore implementation
89-
*/
90-
module.exports.newKeyValueStore = function(options) {
91-
return utils.newKeyValueStore(options);
92-
};
93-
94-
/**
95-
* Configures a logger for the entire HFC SDK to use and override the default logger. Unless this method is called,
96-
* HFC uses a default logger (based on winston). When using the built-in "winston" based logger, use the environment
97-
* variable HFC_LOGGING to pass in configurations in the following format:
98-
*
99-
* {
100-
* 'error': 'error.log', // 'error' logs are printed to file 'error.log' relative of the current working dir for node.js
101-
* 'debug': '/tmp/myapp/debug.log', // 'debug' and anything more critical ('info', 'warn', 'error') can also be an absolute path
102-
* 'info': 'console' // 'console' is a keyword for logging to console
103-
* }
104-
*
105-
* @param {Object} logger a logger instance that defines the following methods: debug(), info(), warn(), error() with
106-
* string interpolation methods like [util.format]{@link https://nodejs.org/api/util.html#util_util_format_format}.
107-
*/
108-
module.exports.setLogger = function(logger) {
109-
var err = '';
110-
111-
if (typeof logger.debug !== 'function') {
112-
err += 'debug() ';
113-
}
114-
115-
if (typeof logger.info !== 'function') {
116-
err += 'info() ';
117-
}
118-
119-
if (typeof logger.warn !== 'function') {
120-
err += 'warn() ';
121-
}
122-
123-
if (typeof logger.error !== 'function' ) {
124-
err += 'error()';
125-
}
126-
127-
if (err !== '') {
128-
throw new Error('The "logger" parameter must be an object that implements the following methods, which are missing: ' + err);
129-
}
130-
131-
if (global.hfc) {
132-
global.hfc.logger = logger;
133-
} else {
134-
global.hfc = {
135-
logger: logger
136-
};
137-
}
138-
};
139-
140-
/**
141-
* Adds a file to the top of the list of configuration setting files that are
142-
* part of the hierarchical configuration.
143-
* These files will override the default settings and be overriden by environment,
144-
* command line arguments, and settings programmatically set into configuration settings.
145-
*
146-
* hierarchy search order:
147-
* 1. memory - all settings added with utils.setConfigSetting(name,value)
148-
* 2. Command-line arguments
149-
* 3. Environment variables (names will be change from AAA-BBB to aaa-bbb)
150-
* 4. Custom Files - all files added with the addConfigFile(path)
151-
* will be ordered by when added, were last one added will override previously added files
152-
* 5. The file located at 'config/default.json' with default settings
153-
*
154-
* @param {String} path - The path to the file to be added to the top of list of configuration files
155-
*/
156-
module.exports.addConfigFile = function(path) {
157-
158-
utils.addConfigFile(path);
159-
};
160-
161-
/**
162-
* Adds a setting to override all settings that are
163-
* part of the hierarchical configuration.
164-
*
165-
* hierarchy search order:
166-
* 1. memory - settings added with this call
167-
* 2. Command-line arguments
168-
* 3. Environment variables (names will be change from AAA-BBB to aaa-bbb)
169-
* 4. Custom Files - all files added with the addConfigFile(path)
170-
* will be ordered by when added, were last one added will override previously added files
171-
* 5. The file located at 'config/default.json' with default settings
172-
*
173-
* @param {String} name - The name of a setting
174-
* @param {Object} value - The value of a setting
175-
*/
176-
module.exports.setConfigSetting = function(name, value) {
177-
178-
utils.setConfigSetting(name, value);
179-
};
180-
181-
/**
182-
* Retrieves a setting from the hierarchical configuration and if not found
183-
* will return the provided default value.
184-
*
185-
* hierarchy search order:
186-
* 1. memory - settings added with utils.setConfigSetting(name,value)
187-
* 2. Command-line arguments
188-
* 3. Environment variables (names will be change from AAA-BBB to aaa-bbb)
189-
* 4. Custom Files - all files added with the addConfigFile(path)
190-
* will be ordered by when added, were last one added will override previously added files
191-
* 5. The file located at 'config/default.json' with default settings
192-
*
193-
* @param {String} name - The name of a setting
194-
* @param {Object} default_value - The value of a setting if not found in the hierarchical configuration
195-
*/
196-
module.exports.getConfigSetting = function(name, default_value) {
197-
198-
return utils.getConfigSetting(name, default_value);
199-
};
200-
201-
/**
202-
* Builds an unique transaction ID based on the values in
203-
* the request object.
204-
*
205-
* @param {Object} request - An object with the values to be used
206-
* to build an unique transaction ID.
207-
* @returns {String} An unique transaction ID
208-
*/
209-
module.exports.buildTransactionID = function(request) {
210-
211-
return utils.buildTransactionID(request);
212-
};
213-
214-
/**
215-
* Gets a random number for a one time use
216-
*
217-
* @param {int} length - Optional value to control the length of the number.
218-
* The configuration setting 'nonce-size' will be used if not
219-
* passed in.
220-
* @return {int} Random number of the specified length
221-
*/
222-
module.exports.getNonce = function(length) {
223-
224-
return utils.buildTransactionID(length);
225-
};
226-
24+
module.exports = require('./lib/Client.js');

0 commit comments

Comments
 (0)