16
16
17
17
const { CaliperUtils, ConfigUtil } = require ( '@hyperledger/caliper-core' ) ;
18
18
const ConnectorConfigurationFactory = require ( './connector-configuration/ConnectorConfigurationFactory' ) ;
19
- const ConfigValidator = require ( './configValidator.js' ) ;
20
- const Logger = CaliperUtils . getLogger ( 'fabric-connector' ) ;
19
+ const Logger = CaliperUtils . getLogger ( 'FabricConnectorFactory' ) ;
21
20
const semver = require ( 'semver' ) ;
22
21
23
- const LEGACY_V1_NODE_CONNECTOR = './connector-versions/v1/fabric.js' ;
24
- const LEGACY_V1_GATEWAY_CONNECTOR = './connector-versions/v1/fabric-gateway.js' ;
25
- const LEGACY_V2_GATEWAY_CONNECTOR = './connector-versions/v2/fabric-gateway.js' ;
26
-
27
22
const NEW_V1_NODE_CONNECTOR = './connector-versions/v1/FabricNonGateway.js' ;
28
23
const NEW_V1_GATEWAY_CONNECTOR = './connector-versions/v1/FabricGateway.js' ;
29
24
const NEW_V1_WALLET_FACADE_FACTORY = './connector-versions/v1/WalletFacadeFactory.js' ;
@@ -35,41 +30,29 @@ const NEW_V2_WALLET_FACADE_FACTORY = './connector-versions/v2/WalletFacadeFactor
35
30
* @returns {string } version
36
31
*/
37
32
const _determineInstalledNodeSDKVersion = ( ) => {
38
- let version ;
33
+
34
+ // Caliper can only work if you use bind and it will pull in fabric network even for non gateway 1.4
39
35
if ( CaliperUtils . moduleIsInstalled ( 'fabric-network' ) ) {
40
36
const packageVersion = require ( 'fabric-network/package' ) . version ;
41
- version = semver . coerce ( packageVersion ) ;
42
- } else if ( CaliperUtils . moduleIsInstalled ( 'fabric-client' ) ) {
43
- const packageVersion = require ( 'fabric-client/package' ) . version ;
44
- version = semver . coerce ( packageVersion ) ;
37
+ return semver . coerce ( packageVersion ) ;
45
38
} else {
46
- const msg = 'Unable to detect required Fabric binding packages' ;
47
- throw new Error ( msg ) ;
39
+ throw new Error ( 'Unable to detect required Fabric binding packages' ) ;
48
40
}
49
- return version ;
50
41
} ;
51
42
52
- const _loadAppropriateConnectorClass = ( installedNodeSDKVersion , useGateway , useLegacyVersion ) => {
43
+ const _loadAppropriateConnectorClass = ( installedNodeSDKVersion , useGateway ) => {
53
44
let connectorPath ;
54
45
let walletFacadeFactoryPath ;
55
46
56
47
if ( semver . satisfies ( installedNodeSDKVersion , '=1.x' ) ) {
57
48
if ( ! useGateway ) {
58
- if ( useLegacyVersion ) {
59
- connectorPath = LEGACY_V1_NODE_CONNECTOR ;
60
- } else {
61
- connectorPath = NEW_V1_NODE_CONNECTOR ;
62
- walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY ;
63
- }
49
+ connectorPath = NEW_V1_NODE_CONNECTOR ;
50
+ walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY ;
64
51
} else {
65
52
// gateway with default event handlers appears in SDK > 1.4.2
66
53
if ( semver . satisfies ( installedNodeSDKVersion , '>=1.4.2' ) ) {
67
- if ( useLegacyVersion ) {
68
- connectorPath = LEGACY_V1_GATEWAY_CONNECTOR ;
69
- } else {
70
- connectorPath = NEW_V1_GATEWAY_CONNECTOR ;
71
- walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY ;
72
- }
54
+ connectorPath = NEW_V1_GATEWAY_CONNECTOR ;
55
+ walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY ;
73
56
} else {
74
57
throw new Error ( 'Caliper currently only supports Fabric gateway based operation using Fabric-SDK 1.4.2 and higher. Please retry with a different SDK binding' ) ;
75
58
}
@@ -78,12 +61,8 @@ const _loadAppropriateConnectorClass = (installedNodeSDKVersion, useGateway, use
78
61
if ( ! useGateway ) {
79
62
throw new Error ( `Caliper currently only supports gateway based operation using the ${ installedNodeSDKVersion } Fabric-SDK. Please retry with the gateway flag` ) ;
80
63
} else {
81
- if ( useLegacyVersion ) {
82
- connectorPath = LEGACY_V2_GATEWAY_CONNECTOR ;
83
- } else {
84
- connectorPath = NEW_V2_GATEWAY_CONNECTOR ;
85
- walletFacadeFactoryPath = NEW_V2_WALLET_FACADE_FACTORY ;
86
- }
64
+ connectorPath = NEW_V2_GATEWAY_CONNECTOR ;
65
+ walletFacadeFactoryPath = NEW_V2_WALLET_FACADE_FACTORY ;
87
66
}
88
67
} else {
89
68
throw new Error ( `Installed SDK version ${ installedNodeSDKVersion } did not match any compatible Fabric connectors` ) ;
@@ -108,35 +87,21 @@ const connectorFactory = async (workerIndex) => {
108
87
109
88
const connectorConfigurationFile = CaliperUtils . resolvePath ( ConfigUtil . get ( ConfigUtil . keys . NetworkConfig ) ) ;
110
89
const loadedConnectorConfiguration = CaliperUtils . parseYaml ( connectorConfigurationFile ) ;
111
- const legacyVersion = loadedConnectorConfiguration . version === '1.0' ;
90
+ if ( loadedConnectorConfiguration . version === '1.0' ) {
91
+ throw new Error ( 'Network configuration version 1.0 is not supported anymore, please use version 2' ) ;
92
+ }
112
93
113
- if ( ! legacyVersion && ! semver . satisfies ( loadedConnectorConfiguration . version , '=2.0' ) ) {
94
+ if ( ! semver . satisfies ( loadedConnectorConfiguration . version , '=2.0' ) ) {
114
95
throw new Error ( `Unknown network configuration version ${ loadedConnectorConfiguration . version } specified` ) ;
115
96
}
116
97
117
98
const installedNodeSDKVersion = _determineInstalledNodeSDKVersion ( ) ;
118
99
const useGateway = ConfigUtil . get ( ConfigUtil . keys . Fabric . Gateway . Enabled , false ) ;
119
- const useDiscovery = ConfigUtil . get ( ConfigUtil . keys . Fabric . Gateway . Discovery , false ) ;
120
100
121
101
Logger . info ( `Initializing ${ useGateway ? 'gateway' : 'standard' } connector compatible with installed SDK: ${ installedNodeSDKVersion } ` ) ;
122
- const { fabricConnectorClass, walletFacadeFactoryClass} = _loadAppropriateConnectorClass ( installedNodeSDKVersion , useGateway , legacyVersion ) ;
123
-
124
- let fabricConnector ;
125
-
126
- if ( legacyVersion ) {
127
- ConfigValidator . validateNetwork ( loadedConnectorConfiguration , CaliperUtils . getFlowOptions ( ) , useDiscovery , useGateway ) ;
128
-
129
- fabricConnector = new fabricConnectorClass ( loadedConnectorConfiguration , workerIndex , 'fabric' ) ;
130
- if ( workerIndex > - 1 ) {
131
- // These connectors must have init called for both masters and workers
132
- // but for masters it will have already been called
133
- await fabricConnector . init ( true ) ;
134
- }
135
- } else {
136
- // use new connectors
137
- const connectorConfiguration = await new ConnectorConfigurationFactory ( ) . create ( connectorConfigurationFile , new walletFacadeFactoryClass ( ) ) ;
138
- fabricConnector = new fabricConnectorClass ( connectorConfiguration , workerIndex , 'fabric' ) ;
139
- }
102
+ const { fabricConnectorClass, walletFacadeFactoryClass} = _loadAppropriateConnectorClass ( installedNodeSDKVersion , useGateway ) ;
103
+ const connectorConfiguration = await new ConnectorConfigurationFactory ( ) . create ( connectorConfigurationFile , new walletFacadeFactoryClass ( ) ) ;
104
+ const fabricConnector = new fabricConnectorClass ( connectorConfiguration , workerIndex , 'fabric' ) ;
140
105
141
106
return fabricConnector ;
142
107
} ;
0 commit comments