private void CreateNetModeTransaction() { logger.Debug("NetModeTransaction"); LinkedList <string> modlist = new LinkedList <string>(); modlist.AddFirst("init"); iargList.ForEach(a => modlist.AddAfter(modlist.Last, a)); switch (chaincodeType) { case TransactionRequest.Type.JAVA: CcType(ChaincodeSpec.Types.Type.Java); break; case TransactionRequest.Type.NODE: CcType(ChaincodeSpec.Types.Type.Node); break; case TransactionRequest.Type.GO_LANG: CcType(ChaincodeSpec.Types.Type.Golang); break; default: throw new ArgumentException("Requested chaincode type is not supported: " + chaincodeType); } ChaincodeDeploymentSpec depspec = ProtoUtils.CreateDeploymentSpec(ccType, chaincodeName, chaincodePath, chaincodeVersion, modlist.ToList(), null); List <ByteString> argsList = new List <ByteString>(); argsList.Add(ByteString.CopyFromUtf8(action)); argsList.Add(ByteString.CopyFromUtf8(context.ChannelID)); argsList.Add(depspec.ToByteString()); if (chaincodePolicy != null) { argsList.Add(ByteString.CopyFrom(chaincodePolicy)); } else if (null != chaincodeCollectionConfiguration) { argsList.Add(ByteString.Empty); //place holder for chaincodePolicy } if (null != chaincodeCollectionConfiguration) { argsList.Add(ByteString.Empty); //escc name place holder argsList.Add(ByteString.Empty); //vscc name place holder argsList.Add(ByteString.CopyFrom(chaincodeCollectionConfiguration)); } Args(argsList); }
private void CreateNetModeTransaction() { logger.Debug("createNetModeTransaction"); if (null == chaincodeSource && chaincodeInputStream == null) { throw new ArgumentException("Missing chaincodeSource or chaincodeInputStream in InstallRequest"); } if (null != chaincodeSource && chaincodeInputStream != null) { throw new ArgumentException("Both chaincodeSource and chaincodeInputStream in InstallRequest were set. Specify one or the other"); } ChaincodeSpec.Types.Type ctyp; string projectSourceDir = null; string targetPathPrefix = null; string dplang; string metainf = null; if (null != chaincodeMetaInfLocation) { if (!Directory.Exists(chaincodeMetaInfLocation)) { throw new ArgumentException($"Directory to find chaincode META-INF {chaincodeMetaInfLocation} does not exist"); } /* * if (!chaincodeMetaInfLocation==null) { * throw new IllegalArgumentException(format("Directory to find chaincode META-INF %s is not a directory", chaincodeMetaInfLocation.getAbsolutePath())); * }*/ metainf = Path.Combine(chaincodeMetaInfLocation, "META-INF"); logger.Trace($"META-INF directory is {metainf}"); if (!Directory.Exists(metainf)) { throw new ArgumentException($"The META-INF directory does not exist in {chaincodeMetaInfLocation}"); } string[] files = Directory.GetFileSystemEntries(metainf).ToArray(); /* * if (files == null) { * throw new IllegalArgumentException("null for listFiles on: " + chaincodeMetaInfLocation.getAbsolutePath()); * } */ if (files.Length < 1) { throw new ArgumentException($"The META-INF directory {metainf} is empty."); } logger.Trace($"chaincode META-INF found {metainf}"); } switch (chaincodeLanguage) { case TransactionRequest.Type.GO_LANG: // chaincodePath is mandatory // chaincodeSource may be a File or InputStream // Verify that chaincodePath is being passed if (string.IsNullOrEmpty(chaincodePath)) { throw new ArgumentException("Missing chaincodePath in InstallRequest"); } dplang = "Go"; ctyp = ChaincodeSpec.Types.Type.Golang; if (null != chaincodeSource) { projectSourceDir = Path.Combine(chaincodeSource, "src", chaincodePath); targetPathPrefix = Path.Combine("src", chaincodePath); } break; case TransactionRequest.Type.JAVA: // chaincodePath is not applicable and must be null // chaincodeSource may be a File or InputStream // Verify that chaincodePath is null if (!string.IsNullOrEmpty(chaincodePath)) { throw new ArgumentException("chaincodePath must be null for Java chaincode"); } dplang = "Java"; ctyp = ChaincodeSpec.Types.Type.Java; if (null != chaincodeSource) { targetPathPrefix = "src"; projectSourceDir = chaincodeSource; } break; case TransactionRequest.Type.NODE: // chaincodePath is not applicable and must be null // chaincodeSource may be a File or InputStream // Verify that chaincodePath is null if (!string.IsNullOrEmpty(chaincodePath)) { throw new ArgumentException("chaincodePath must be null for Node chaincode"); } dplang = "Node"; ctyp = ChaincodeSpec.Types.Type.Node; if (null != chaincodeSource) { projectSourceDir = chaincodeSource; targetPathPrefix = "src"; //Paths.get("src", chaincodePath).toString(); } break; default: throw new ArgumentException("Unexpected chaincode language: " + chaincodeLanguage); } CcType(ctyp); byte[] data; string chaincodeID = chaincodeName + "::" + chaincodePath + "::" + chaincodeVersion; if (chaincodeSource != null) { if (!Directory.Exists(projectSourceDir)) { string message = "The project source directory does not exist: " + projectSourceDir; logger.Error(message); throw new ArgumentException(message); } /* * if (!projectSourceDir.isDirectory()) { * final String message = "The project source directory is not a directory: " + projectSourceDir.getAbsolutePath(); * logger.error(message); * throw new IllegalArgumentException(message); * } */ logger.Info($"Installing '{chaincodeID}' language {dplang} chaincode from directory: '{projectSourceDir}' with source location: '{targetPathPrefix}'. chaincodePath:'{chaincodePath}'", chaincodeID, dplang, projectSourceDir, targetPathPrefix, chaincodePath); // generate chaincode source tar data = Utils.GenerateTarGz(projectSourceDir, targetPathPrefix, metainf); if (null != diagnosticFileDumper) { logger.Trace($"Installing '{chaincodeID}' language {dplang} chaincode from directory: '{projectSourceDir}' with source location: '{targetPathPrefix}'. chaincodePath:'{chaincodePath}' tar file dump {diagnosticFileDumper.CreateDiagnosticTarFile(data)}"); } } else { logger.Info($"Installing '{chaincodeID}' language {dplang} chaincode chaincodePath:'{chaincodePath}' from input stream"); data = chaincodeInputStream.ToByteArray(); if (data.Length == 0) { throw new ArgumentException("Chaincode input stream was empty"); } if (null != diagnosticFileDumper) { logger.Trace($"Installing '{chaincodeID}' language {dplang} chaincode from input stream tar file dump {diagnosticFileDumper.CreateDiagnosticTarFile(data)}"); } } ChaincodeDeploymentSpec depspec = ProtoUtils.CreateDeploymentSpec(ctyp, chaincodeName, chaincodePath, chaincodeVersion, null, data); // set args AddArg(action); AddArg(depspec.ToByteString()); }