예제 #1
0
        public ProposalBuilder Request(TransactionRequest req)
        {
            request = req;

            chaincodeID = req.ChaincodeID.FabricChaincodeID;

            switch (req.ChaincodeLanguage)
            {
            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: " + req.ChaincodeLanguage);
            }

            transientMap = req.TransientMap;
            return(this);
        }
예제 #2
0
        private Proposal CreateFabricProposal(string chID, Protos.Peer.ChaincodeID ccodeID)
        {
            if (null == transientMap)
            {
                transientMap = new Dictionary <string, byte[]>();
            }

            if (IS_DEBUG_LEVEL)
            {
                foreach (KeyValuePair <string, byte[]> tme in transientMap)
                {
                    logger.Debug($"transientMap('{tme.Key.LogString()}', '{Encoding.UTF8.GetString(tme.Value).LogString()}'))");
                }
            }

            ChaincodeHeaderExtension chaincodeHeaderExtension = new ChaincodeHeaderExtension {
                ChaincodeId = ccodeID
            };

            ChannelHeader chainHeader = ProtoUtils.CreateChannelHeader(HeaderType.EndorserTransaction, context.TxID, chID, context.Epoch, context.FabricTimestamp, chaincodeHeaderExtension, null);

            ChaincodeInvocationSpec chaincodeInvocationSpec = CreateChaincodeInvocationSpec(ccodeID, ccType);

            ChaincodeProposalPayload payload = new ChaincodeProposalPayload {
                Input = chaincodeInvocationSpec.ToByteString()
            };

            foreach (KeyValuePair <string, byte[]> pair in transientMap)
            {
                payload.TransientMap.Add(pair.Key, ByteString.CopyFrom(pair.Value));
            }
            Header header = new Header {
                SignatureHeader = ProtoUtils.GetSignatureHeaderAsByteString(context), ChannelHeader = chainHeader.ToByteString()
            };

            return(new Proposal {
                Header = header.ToByteString(), Payload = payload.ToByteString()
            });
        }
예제 #3
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);
        }
예제 #4
0
 public ChaincodeID()
 {
     FabricChaincodeID = new Protos.Peer.ChaincodeID();
 }
예제 #5
0
 public ChaincodeID(Protos.Peer.ChaincodeID chaincodeID)
 {
     FabricChaincodeID = chaincodeID;
 }
예제 #6
0
 public ProposalBuilder ChaincodeID(Protos.Peer.ChaincodeID ccodeID)
 {
     chaincodeID = ccodeID;
     return(this);
 }
예제 #7
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
            });
        }