Exemple #1
0
        private SerializedCallGraph SerializeCallingGraph(CallGraph graph)
        {
            var serializedCallGraph = new SerializedCallGraph();

            serializedCallGraph.Edges.AddRange(graph.Edges.Select(edge =>
                                                                  new GraphEdge {
                Source = edge.Source, Target = edge.Target
            }));
            serializedCallGraph.Vertices.AddRange(graph.Vertices);
            return(serializedCallGraph);
        }
Exemple #2
0
        /// <summary>
        /// calling graph is prepared for update contract code (check for DAG at that time)
        /// </summary>
        /// <param name="edges"></param>
        /// <returns></returns>
        /// <exception cref="FunctionMetadataException"></exception>
        private CallGraph BuildCallingGraph(SerializedCallGraph callGraph)
        {
            CallGraph graph = new CallGraph();

            graph.AddVertexRange(callGraph.Vertices);
            graph.AddEdgeRange(callGraph.Edges.Select(serializedEdge =>
                                                      new Edge <string>(serializedEdge.Source, serializedEdge.Target)));
            try
            {
                graph.TopologicalSort();
            }
            catch (NonAcyclicGraphException)
            {
                throw new FunctionMetadataException("The calling graph ISNOT DAG when restoring the calling graph according to the ContractMetadataTemplateMap from the database");
            }
            return(graph);
        }
Exemple #3
0
        bool IEquatable <SerializedCallGraph> .Equals(SerializedCallGraph other)
        {
            var edges = new RepeatedField <GraphEdge>();

            edges.AddRange(Edges.OrderBy(e => e.Source).ThenBy(e => e.Target));
            var otherEdges = new RepeatedField <GraphEdge>();

            otherEdges.AddRange(other.Edges.OrderBy(e => e.Source).ThenBy(e => e.Target));

            var vertices = new RepeatedField <string>();

            vertices.AddRange(Vertices.OrderBy(v => v));
            var otherVertices = new RepeatedField <string>();

            otherVertices.AddRange(other.Vertices.OrderBy(v => v));


            return(edges.Equals(otherEdges) && vertices.Equals(otherVertices));
        }