Exemplo n.º 1
0
 public ProposalBuilder CcType(ChaincodeSpec.Types.Type ctype)
 {
     ccType = ctype;
     return(this);
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private ChaincodeInvocationSpec CreateChaincodeInvocationSpec(Protos.Peer.ChaincodeID ccodeID, ChaincodeSpec.Types.Type langType)
        {
            List <ByteString> allArgs = new List <ByteString>();

            if (argList != null && argList.Count > 0)
            {
                // If we already have an argList then the Builder subclasses have already set the arguments
                // for chaincodeInput. Accept the list and pass it on to the chaincodeInput builder
                // TODO need to clean this logic up so that common protobuf struct builds are in one place
                allArgs = argList;
            }
            else if (request != null)
            {
                // if argList is empty and we have a Request, build the chaincodeInput args array from the Request args and argbytes lists
                allArgs.Add(ByteString.CopyFromUtf8(request.Fcn));
                List <string> args = request.Args;
                if (args != null && args.Count > 0)
                {
                    foreach (string arg in args)
                    {
                        allArgs.Add(ByteString.CopyFromUtf8(arg));
                    }
                }

                // TODO currently assume that chaincodeInput args are strings followed by byte[].
                // Either agree with Fabric folks that this will always be the case or modify all Builders to expect
                // a List of Objects and determine if each list item is a string or a byte array
                List <byte[]> argBytes = request.ArgsBytes;
                if (argBytes != null && argBytes.Count > 0)
                {
                    foreach (byte[] arg in argBytes)
                    {
                        allArgs.Add(ByteString.CopyFrom(arg));
                    }
                }
            }

            if (IS_DEBUG_LEVEL)
            {
                StringBuilder logout = new StringBuilder(1000);

                logout.Append($"ChaincodeInvocationSpec type: {langType.ToString()}, chaincode name: {ccodeID.Name}, chaincode path: {ccodeID.Path}, chaincode version: {ccodeID.Version}");

                string sep = "";
                logout.Append(" args(");

                foreach (ByteString x in allArgs)
                {
                    logout.Append(sep).Append("\"").Append(x.ToStringUtf8().LogString()).Append("\"");
                    sep = ", ";
                }

                logout.Append(")");

                logger.Debug(logout.ToString);
            }

            ChaincodeInput chaincodeInput = new ChaincodeInput();

            chaincodeInput.Args.AddRange(allArgs);
            ChaincodeSpec chaincodeSpec = new ChaincodeSpec {
                Type = langType, ChaincodeId = ccodeID, Input = chaincodeInput
            };

            return(new ChaincodeInvocationSpec {
                ChaincodeSpec = chaincodeSpec
            });
        }