@@ -147,7 +147,6 @@ import {
147
147
formatCactiFullBlockResponse ,
148
148
formatCactiTransactionsBlockResponse ,
149
149
} from "./get-block/cacti-block-formatters" ;
150
-
151
150
import { GetBlockEndpointV1 } from "./get-block/get-block-endpoint-v1" ;
152
151
import { GetChainInfoEndpointV1 } from "./get-chain-info/get-chain-info-endpoint-v1" ;
153
152
import { querySystemChainCode } from "./common/query-system-chain-code" ;
@@ -159,17 +158,17 @@ import {
159
158
} from "./common/utils" ;
160
159
import { findAndReplaceFabricLoggingSpec } from "./common/find-and-replace-fabric-logging-spec" ;
161
160
import { deployContractGoSourceImplFabricV256 } from "./deploy-contract-go-source/deploy-contract-go-source-impl-fabric-v2-5-6" ;
162
- import { Observable , ReplaySubject } from "rxjs" ;
163
161
164
162
const { loadFromConfig } = require ( "fabric-network/lib/impl/ccp/networkconfig" ) ;
165
163
assertFabricFunctionIsAvailable ( loadFromConfig , "loadFromConfig" ) ;
164
+ import { Observable , ReplaySubject } from "rxjs" ;
165
+
166
166
167
167
export interface IRunTxReqWithTxId {
168
168
request : RunTransactionRequest ;
169
169
transactionId : string ;
170
170
timestamp : Date ;
171
171
}
172
-
173
172
/**
174
173
* Constant value holding the default $GOPATH in the Fabric CLI container as
175
174
* observed on fabric deployments that are produced by the official examples
@@ -197,11 +196,9 @@ export interface IPluginLedgerConnectorFabricOptions
197
196
cliContainerGoPath ?: string ;
198
197
cliContainerEnv : NodeJS . ProcessEnv ;
199
198
pluginRegistry : PluginRegistry ;
200
- sshConfig ?: SshConfig ;
201
- sshConfigB64 ?: string ;
199
+ sshConfig : SshConfig ;
202
200
readonly sshDebugOn ?: boolean ;
203
- connectionProfile ?: ConnectionProfile ;
204
- connectionProfileB64 ?: string ;
201
+ connectionProfile : ConnectionProfile ;
205
202
prometheusExporter ?: PrometheusExporter ;
206
203
discoveryOptions ?: GatewayDiscoveryOptions ;
207
204
eventHandlerOptions ?: GatewayEventHandlerOptions ;
@@ -229,8 +226,6 @@ export class PluginLedgerConnectorFabric
229
226
private readonly peerBinary : string ;
230
227
private readonly goBinary : string ;
231
228
private readonly cliContainerGoPath : string ;
232
- private readonly sshConfig : SshConfig ;
233
- private readonly connectionProfile : ConnectionProfile ;
234
229
public prometheusExporter : PrometheusExporter ;
235
230
private endpoints : IWebServiceEndpoint [ ] | undefined ;
236
231
private readonly secureIdentity : SecureIdentityProviders ;
@@ -254,6 +249,7 @@ export class PluginLedgerConnectorFabric
254
249
Checks . truthy ( opts . instanceId , `${ fnTag } options.instanceId` ) ;
255
250
Checks . truthy ( opts . peerBinary , `${ fnTag } options.peerBinary` ) ;
256
251
Checks . truthy ( opts . pluginRegistry , `${ fnTag } options.pluginRegistry` ) ;
252
+ Checks . truthy ( opts . connectionProfile , `${ fnTag } options.connectionProfile` ) ;
257
253
this . prometheusExporter =
258
254
opts . prometheusExporter ||
259
255
new PrometheusExporter ( { pollingIntervalInMin : 1 } ) ;
@@ -289,33 +285,9 @@ export class PluginLedgerConnectorFabric
289
285
} ) ;
290
286
this . certStore = new CertDatastore ( opts . pluginRegistry ) ;
291
287
292
- if ( this . opts . connectionProfile ) {
293
- this . connectionProfile = this . opts . connectionProfile ;
294
- } else if ( this . opts . connectionProfileB64 ) {
295
- const connectionProfileBuffer = Buffer . from (
296
- this . opts . connectionProfileB64 ,
297
- "base64" ,
298
- ) ;
299
- const connectionProfileString = connectionProfileBuffer . toString ( "utf-8" ) ;
300
- this . connectionProfile = JSON . parse ( connectionProfileString ) ;
301
- } else {
302
- throw new Error (
303
- "Cannot instantiate Fabric connector without connection profile." ,
304
- ) ;
305
- }
306
-
307
288
this . sshDebugOn = opts . sshDebugOn === true ;
308
- if ( this . opts . sshConfig ) {
309
- this . sshConfig = this . opts . sshConfig ;
310
- } else if ( this . opts . sshConfigB64 ) {
311
- const sshConfigBuffer = Buffer . from ( this . opts . sshConfigB64 , "base64" ) ;
312
- const sshConfigString = sshConfigBuffer . toString ( "utf-8" ) ;
313
- this . sshConfig = JSON . parse ( sshConfigString ) ;
314
- } else {
315
- throw new Error ( "Cannot instantiate Fabric connector without SSH config" ) ;
316
- }
317
289
if ( this . sshDebugOn ) {
318
- this . sshConfig = this . enableSshDebugLogs ( this . sshConfig ) ;
290
+ this . opts . sshConfig = this . enableSshDebugLogs ( this . opts . sshConfig ) ;
319
291
}
320
292
321
293
this . signCallback = opts . signCallback ;
@@ -348,10 +320,6 @@ export class PluginLedgerConnectorFabric
348
320
return `@hyperledger/cactus-plugin-ledger-connector-fabric` ;
349
321
}
350
322
351
- public getTxSubjectObservable ( ) : Observable < IRunTxReqWithTxId > {
352
- return this . txSubject . asObservable ( ) ;
353
- }
354
-
355
323
public async onPluginInit ( ) : Promise < unknown > {
356
324
return ;
357
325
}
@@ -366,6 +334,10 @@ export class PluginLedgerConnectorFabric
366
334
return consensusHasTransactionFinality ( currentConsensusAlgorithmFamily ) ;
367
335
}
368
336
337
+ public getTxSubjectObservable ( ) : Observable < IRunTxReqWithTxId > {
338
+ return this . txSubject . asObservable ( ) ;
339
+ }
340
+
369
341
private enableSshDebugLogs ( cfg : SshConfig ) : SshConfig {
370
342
const fnTag = `${ this . className } #decorateSshConfigWithLogger()` ;
371
343
Checks . truthy ( cfg , `${ fnTag } cfg must be truthy.` ) ;
@@ -382,6 +354,7 @@ export class PluginLedgerConnectorFabric
382
354
sshCmdOptions : SSHExecCommandOptions ,
383
355
) : Promise < SSHExecCommandResponse > {
384
356
this . log . debug ( `${ label } CMD: ${ cmd } ` ) ;
357
+
385
358
const cmdRes = await ssh . execCommand ( cmd , sshCmdOptions ) ;
386
359
this . log . debug ( `${ label } CMD Response .code: %o` , cmdRes . code ) ;
387
360
this . log . debug ( `${ label } CMD Response .signal: %o` , cmdRes . signal ) ;
@@ -401,11 +374,11 @@ export class PluginLedgerConnectorFabric
401
374
req : DeployContractV1Request ,
402
375
) : Promise < DeployContractV1Response > {
403
376
const fnTag = `${ this . className } #deployContract()` ;
404
- const { log } = this ;
377
+ const { log, opts } = this ;
405
378
406
379
const ssh = new NodeSSH ( ) ;
407
380
this . log . debug ( `${ fnTag } Establishing SSH connection to peer...` ) ;
408
- await ssh . connect ( this . sshConfig ) ;
381
+ await ssh . connect ( opts . sshConfig ) ;
409
382
this . log . debug ( `${ fnTag } Established SSH connection to peer OK.` ) ;
410
383
411
384
if ( req . collectionsConfigFile ) {
@@ -706,7 +679,6 @@ export class PluginLedgerConnectorFabric
706
679
log,
707
680
opts : this . opts ,
708
681
dockerBinary : this . dockerBinary ,
709
- sshConfig : this . sshConfig ,
710
682
className : this . className ,
711
683
} ;
712
684
return deployContractGoSourceImplFabricV256 ( ctx , req ) ;
@@ -951,7 +923,7 @@ export class PluginLedgerConnectorFabric
951
923
return createGateway ( {
952
924
logLevel : this . opts . logLevel ,
953
925
pluginRegistry : this . opts . pluginRegistry ,
954
- defaultConnectionProfile : this . connectionProfile ,
926
+ defaultConnectionProfile : this . opts . connectionProfile ,
955
927
defaultDiscoveryOptions : this . opts . discoveryOptions || {
956
928
enabled : true ,
957
929
asLocalhost : true ,
@@ -976,8 +948,7 @@ export class PluginLedgerConnectorFabric
976
948
protected async createGatewayLegacy (
977
949
signingCredential : FabricSigningCredential ,
978
950
) : Promise < Gateway > {
979
- const { eventHandlerOptions : eho } = this . opts ;
980
- const connectionProfile = this . connectionProfile ;
951
+ const { connectionProfile, eventHandlerOptions : eho } = this . opts ;
981
952
982
953
const iType = signingCredential . type || FabricSigningCredentialType . X509 ;
983
954
@@ -1191,7 +1162,6 @@ export class PluginLedgerConnectorFabric
1191
1162
) : Promise < RunTransactionResponse > {
1192
1163
const fnTag = `${ this . className } #transact()` ;
1193
1164
this . log . debug ( "%s ENTER" , fnTag ) ;
1194
-
1195
1165
const {
1196
1166
channelName,
1197
1167
contractName,
@@ -1261,7 +1231,6 @@ export class PluginLedgerConnectorFabric
1261
1231
const transactionProposal = await contract . createTransaction ( fnName ) ;
1262
1232
transactionProposal . setEndorsingPeers ( endorsingTargets ) ;
1263
1233
out = await transactionProposal . setTransient ( transientMap ) . submit ( ) ;
1264
- transactionId = transactionProposal . getTransactionId ( ) ;
1265
1234
break ;
1266
1235
}
1267
1236
default : {
@@ -1270,17 +1239,6 @@ export class PluginLedgerConnectorFabric
1270
1239
}
1271
1240
}
1272
1241
1273
- // create IRunTxReqWithTxId for transaction monitoring
1274
- const receiptData : IRunTxReqWithTxId = {
1275
- request : req ,
1276
- transactionId : transactionId == "" ? uuidv4 ( ) : transactionId ,
1277
- timestamp : new Date ( ) ,
1278
- } ;
1279
- this . log . debug (
1280
- `IRunTxReqWithTxId created with ID: ${ receiptData . transactionId } ` ,
1281
- ) ;
1282
- this . txSubject . next ( receiptData ) ;
1283
-
1284
1242
const res : RunTransactionResponse = {
1285
1243
functionOutput : this . convertToTransactionResponseType (
1286
1244
out ,
@@ -1319,7 +1277,7 @@ export class PluginLedgerConnectorFabric
1319
1277
public async createCaClient ( caId : string ) : Promise < FabricCAServices > {
1320
1278
const fnTag = `${ this . className } #createCaClient()` ;
1321
1279
try {
1322
- const ccp = this . connectionProfile ;
1280
+ const ccp = this . opts . connectionProfile ;
1323
1281
if ( ! ccp . certificateAuthorities ) {
1324
1282
throw new Error ( `${ fnTag } conn. profile certificateAuthorities falsy.` ) ;
1325
1283
}
@@ -1724,7 +1682,7 @@ export class PluginLedgerConnectorFabric
1724
1682
this . log . debug ( "Create Fabric Client without a signer with ID" , clientId ) ;
1725
1683
const client = new Client ( clientId ) ;
1726
1684
// Use fabric SDK methods for parsing connection profile into Client structure
1727
- await loadFromConfig ( client , this . connectionProfile ) ;
1685
+ await loadFromConfig ( client , this . opts . connectionProfile ) ;
1728
1686
1729
1687
// Create user
1730
1688
const user = User . createUser ( "" , "" , signerMspID , signerCertificate ) ;
@@ -1937,4 +1895,4 @@ export class PluginLedgerConnectorFabric
1937
1895
}
1938
1896
}
1939
1897
}
1940
- }
1898
+ }
0 commit comments