@@ -18,11 +18,8 @@ const AdminConnection = require('composer-admin').AdminConnection;
18
18
const BusinessNetworkCardStore = require ( 'composer-common' ) . BusinessNetworkCardStore ;
19
19
const BusinessNetworkConnection = require ( 'composer-client' ) . BusinessNetworkConnection ;
20
20
const fs = require ( 'fs' ) ;
21
- const Logger = require ( 'composer-common' ) . Logger ;
22
21
const prompt = require ( 'prompt' ) ;
23
22
24
- const LOG = Logger . getLog ( 'CmdUtil' ) ;
25
-
26
23
/**
27
24
* Internal Utility Class
28
25
* <p><a href="diagrams/util.svg"><img src="diagrams/util.svg" style="width:100%;"/></a></p>
@@ -114,7 +111,7 @@ class CmdUtil {
114
111
const certificateFile = networkAdminCertificateFiles [ index ] ;
115
112
const certificate = fs . readFileSync ( certificateFile , { encoding : 'utf8' } ) ;
116
113
return {
117
- name : networkAdmin ,
114
+ userName : networkAdmin ,
118
115
certificate
119
116
} ;
120
117
@@ -134,10 +131,10 @@ class CmdUtil {
134
131
return networkAdmins . map ( ( networkAdmin , index ) => {
135
132
136
133
// Grab the secret for the network admin.
137
- const secret = networkAdminEnrollSecrets [ index ] ;
134
+ const enrollmentSecret = networkAdminEnrollSecrets [ index ] ;
138
135
return {
139
- name : networkAdmin ,
140
- secret
136
+ userName : networkAdmin ,
137
+ enrollmentSecret
141
138
} ;
142
139
143
140
} ) ;
@@ -155,6 +152,7 @@ class CmdUtil {
155
152
const networkAdmins = CmdUtil . arrayify ( argv . networkAdmin ) ;
156
153
const networkAdminCertificateFiles = CmdUtil . arrayify ( argv . networkAdminCertificateFile ) ;
157
154
const networkAdminEnrollSecrets = CmdUtil . arrayify ( argv . networkAdminEnrollSecret ) ;
155
+ const files = CmdUtil . arrayify ( argv . file ) ;
158
156
159
157
// It's valid not to specify any network administrators.
160
158
if ( networkAdmins . length === 0 ) {
@@ -167,85 +165,32 @@ class CmdUtil {
167
165
}
168
166
169
167
// Check that enough certificate files have been specified.
168
+ let result ;
170
169
if ( networkAdmins . length === networkAdminCertificateFiles . length ) {
171
- return CmdUtil . parseNetworkAdminsWithCertificateFiles ( networkAdmins , networkAdminCertificateFiles ) ;
170
+ result = CmdUtil . parseNetworkAdminsWithCertificateFiles ( networkAdmins , networkAdminCertificateFiles ) ;
172
171
}
173
172
174
173
// Check that enough enrollment secrets have been specified.
175
- if ( networkAdmins . length === networkAdminEnrollSecrets . length ) {
176
- return CmdUtil . parseNetworkAdminsWithEnrollSecrets ( networkAdmins , networkAdminEnrollSecrets ) ;
174
+ else if ( networkAdmins . length === networkAdminEnrollSecrets . length ) {
175
+ result = CmdUtil . parseNetworkAdminsWithEnrollSecrets ( networkAdmins , networkAdminEnrollSecrets ) ;
177
176
}
178
177
179
178
// Not enough certificate files or enrollment secrets!
180
- throw new Error ( 'You must specify certificate files or enrollment secrets for all network administrators' ) ;
181
-
182
- }
179
+ else {
180
+ console . log ( JSON . stringify ( argv , null , 4 ) ) ;
181
+ throw new Error ( 'You must specify certificate files or enrollment secrets for all network administrators' ) ;
182
+ }
183
183
184
- /**
185
- * Build the bootstrap transactions for any business network administrators specified on the command line.
186
- * @param {BusinessNetworkDefinition } businessNetworkDefinitinon The business network definition.
187
- * @param {Object } argv The command line arguments as parsed by yargs.
188
- * @return {Object[] } The bootstrap transactions.
189
- */
190
- static buildBootstrapTransactions ( businessNetworkDefinitinon , argv ) {
191
- const method = 'buildBootstrapTransactions' ;
192
- LOG . entry ( method , businessNetworkDefinitinon , argv ) ;
193
-
194
- // Grab the useful things from the business network definition.
195
- const factory = businessNetworkDefinitinon . getFactory ( ) ;
196
- const serializer = businessNetworkDefinitinon . getSerializer ( ) ;
197
-
198
- // Parse the network administrators.
199
- const networkAdmins = CmdUtil . parseNetworkAdmins ( argv ) ;
200
-
201
- // Convert the network administrators into add participant transactions.
202
- const addParticipantTransactions = networkAdmins . map ( ( networkAdmin ) => {
203
- const participant = factory . newResource ( 'org.hyperledger.composer.system' , 'NetworkAdmin' , networkAdmin . name ) ;
204
- const targetRegistry = factory . newRelationship ( 'org.hyperledger.composer.system' , 'ParticipantRegistry' , participant . getFullyQualifiedType ( ) ) ;
205
- const addParticipantTransaction = factory . newTransaction ( 'org.hyperledger.composer.system' , 'AddParticipant' ) ;
206
- Object . assign ( addParticipantTransaction , {
207
- resources : [ participant ] ,
208
- targetRegistry
184
+ // If any files specified, check we have enough, and merge them into the result.
185
+ if ( files . length && files . length !== result . length ) {
186
+ throw new Error ( 'If you specify a network administrators card file name, you must specify one for all network administrators' ) ;
187
+ } else if ( files . length ) {
188
+ files . forEach ( ( file , index ) => {
189
+ result [ index ] . file = file ;
209
190
} ) ;
210
- LOG . debug ( method , 'Created bootstrap transaction to add participant' , addParticipantTransaction ) ;
211
- return addParticipantTransaction ;
212
- } ) ;
213
-
214
- // Convert the network administrators into issue or bind identity transactions.
215
- const identityTransactions = networkAdmins . map ( ( networkAdmin ) => {
216
-
217
- // Handle a certificate which requires a bind identity transaction.
218
- let identityTransaction ;
219
- if ( networkAdmin . certificate ) {
220
- identityTransaction = factory . newTransaction ( 'org.hyperledger.composer.system' , 'BindIdentity' ) ;
221
- Object . assign ( identityTransaction , {
222
- participant : factory . newRelationship ( 'org.hyperledger.composer.system' , 'NetworkAdmin' , networkAdmin . name ) ,
223
- certificate : networkAdmin . certificate
224
- } ) ;
225
- LOG . debug ( method , 'Created bootstrap transaction to bind identity' , identityTransaction ) ;
226
- }
227
-
228
- // Handle an enrollment secret which requires an issue identity transactiom.
229
- if ( networkAdmin . secret ) {
230
- identityTransaction = factory . newTransaction ( 'org.hyperledger.composer.system' , 'IssueIdentity' ) ;
231
- Object . assign ( identityTransaction , {
232
- participant : factory . newRelationship ( 'org.hyperledger.composer.system' , 'NetworkAdmin' , networkAdmin . name ) ,
233
- identityName : networkAdmin . name
234
- } ) ;
235
- LOG . debug ( method , 'Created bootstrap transaction to issue identity' , identityTransaction ) ;
236
- }
237
- return identityTransaction ;
238
-
239
- } ) ;
240
-
241
- // Serialize all of the transactions into a single array.
242
- const transactions = addParticipantTransactions . concat ( identityTransactions ) ;
243
- const json = transactions . map ( ( transaction ) => {
244
- return serializer . toJSON ( transaction ) ;
245
- } ) ;
191
+ }
192
+ return result ;
246
193
247
- LOG . exit ( method , json ) ;
248
- return json ;
249
194
}
250
195
251
196
/**
0 commit comments