public void TestProposalBuilderWithOutMetaInf() { InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.Create(); installProposalBuilder.ChaincodeLanguage(TransactionRequest.Type.GO_LANG); installProposalBuilder.ChaincodePath("github.com/example_cc"); installProposalBuilder.ChaincodeSource(SAMPLE_GO_CC.Locate()); installProposalBuilder.ChaincodeName("example_cc.go"); installProposalBuilder.ChaincodeVersion("1"); Channel channel = hfclient.NewChannel("testProposalBuilderWithOutMetaInf"); TransactionContext transactionContext = new TransactionContext(channel, TestUtils.TestUtils.GetMockUser("rick", "rickORG"), Factory.Instance.GetCryptoSuite()); installProposalBuilder.Context(transactionContext); Proposal proposal = installProposalBuilder.Build(); // Build it get the proposal. Then unpack it to see if it's what we expect. ChaincodeProposalPayload chaincodeProposalPayload = ChaincodeProposalPayload.Parser.ParseFrom(proposal.Payload); ChaincodeInvocationSpec chaincodeInvocationSpec = ChaincodeInvocationSpec.Parser.ParseFrom(chaincodeProposalPayload.Input); ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.ChaincodeSpec; ChaincodeInput input = chaincodeSpec.Input; ChaincodeDeploymentSpec chaincodeDeploymentSpec = ChaincodeDeploymentSpec.Parser.ParseFrom(input.Args[1]); ByteString codePackage = chaincodeDeploymentSpec.CodePackage; List <string> tarBytesToEntryArrayList = TestUtils.TestUtils.TarBytesToEntryArrayList(codePackage.ToByteArray()); List <string> expect = new List <string>() { "src/github.com/example_cc/example_cc.go" }; CollectionAssert.AreEquivalent(expect, tarBytesToEntryArrayList, "Tar in Install Proposal's codePackage does not have expected entries. "); }
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); }
public static ChaincodeDeploymentSpec CreateDeploymentSpec(ChaincodeSpec.Types.Type ccType, string name, string chaincodePath, string chaincodeVersion, List <string> args, byte[] codePackage) { Protos.Peer.ChaincodeID chaincodeID = new Protos.Peer.ChaincodeID { Name = name, Version = chaincodeVersion }; if (chaincodePath != null) { chaincodeID.Path = chaincodePath; } if (args == null) { args = new List <string>(); } // build chaincodeInput List <ByteString> argList = args.Select(ByteString.CopyFromUtf8).ToList(); ChaincodeInput chaincodeInput = new ChaincodeInput(); chaincodeInput.Args.AddRange(argList); // Construct the ChaincodeSpec ChaincodeSpec chaincodeSpec = new ChaincodeSpec { ChaincodeId = chaincodeID, Input = chaincodeInput, Type = ccType }; if (isDebugLevel) { StringBuilder sb = new StringBuilder(1000); sb.Append("ChaincodeDeploymentSpec chaincode cctype: ") .Append(ccType.ToString()) .Append(", name:") .Append(chaincodeID.Name) .Append(", path: ") .Append(chaincodeID.Path) .Append(", version: ") .Append(chaincodeID.Version); string sep = ""; sb.Append(" args("); foreach (ByteString x in argList) { sb.Append(sep).Append("\"").Append(x.ToStringUtf8().LogString()).Append("\""); sep = ", "; } sb.Append(")"); logger.Debug(sb.ToString()); } ChaincodeDeploymentSpec spec = new ChaincodeDeploymentSpec { ChaincodeSpec = chaincodeSpec, ExecEnv = ChaincodeDeploymentSpec.Types.ExecutionEnvironment.Docker }; if (codePackage != null) { spec.CodePackage = ByteString.CopyFrom(codePackage); } return(spec); }
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()); }