@@ -18,11 +18,8 @@ const AdminConnection = require('composer-admin').AdminConnection;
1818const BusinessNetworkCardStore = require ( 'composer-common' ) . BusinessNetworkCardStore ;
1919const BusinessNetworkConnection = require ( 'composer-client' ) . BusinessNetworkConnection ;
2020const fs = require ( 'fs' ) ;
21- const Logger = require ( 'composer-common' ) . Logger ;
2221const prompt = require ( 'prompt' ) ;
2322
24- const LOG = Logger . getLog ( 'CmdUtil' ) ;
25-
2623/**
2724 * Internal Utility Class
2825 * <p><a href="diagrams/util.svg"><img src="diagrams/util.svg" style="width:100%;"/></a></p>
@@ -114,7 +111,7 @@ class CmdUtil {
114111 const certificateFile = networkAdminCertificateFiles [ index ] ;
115112 const certificate = fs . readFileSync ( certificateFile , { encoding : 'utf8' } ) ;
116113 return {
117- name : networkAdmin ,
114+ userName : networkAdmin ,
118115 certificate
119116 } ;
120117
@@ -134,10 +131,10 @@ class CmdUtil {
134131 return networkAdmins . map ( ( networkAdmin , index ) => {
135132
136133 // Grab the secret for the network admin.
137- const secret = networkAdminEnrollSecrets [ index ] ;
134+ const enrollmentSecret = networkAdminEnrollSecrets [ index ] ;
138135 return {
139- name : networkAdmin ,
140- secret
136+ userName : networkAdmin ,
137+ enrollmentSecret
141138 } ;
142139
143140 } ) ;
@@ -155,6 +152,7 @@ class CmdUtil {
155152 const networkAdmins = CmdUtil . arrayify ( argv . networkAdmin ) ;
156153 const networkAdminCertificateFiles = CmdUtil . arrayify ( argv . networkAdminCertificateFile ) ;
157154 const networkAdminEnrollSecrets = CmdUtil . arrayify ( argv . networkAdminEnrollSecret ) ;
155+ const files = CmdUtil . arrayify ( argv . file ) ;
158156
159157 // It's valid not to specify any network administrators.
160158 if ( networkAdmins . length === 0 ) {
@@ -167,85 +165,32 @@ class CmdUtil {
167165 }
168166
169167 // Check that enough certificate files have been specified.
168+ let result ;
170169 if ( networkAdmins . length === networkAdminCertificateFiles . length ) {
171- return CmdUtil . parseNetworkAdminsWithCertificateFiles ( networkAdmins , networkAdminCertificateFiles ) ;
170+ result = CmdUtil . parseNetworkAdminsWithCertificateFiles ( networkAdmins , networkAdminCertificateFiles ) ;
172171 }
173172
174173 // 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 ) ;
177176 }
178177
179178 // 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+ }
183183
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 ;
209190 } ) ;
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 ;
246193
247- LOG . exit ( method , json ) ;
248- return json ;
249194 }
250195
251196 /**
0 commit comments