public CallGraph TryRemoveAndGetCallingGraph(Address contractAddress, CallGraph callingGraph, ContractMetadataTemplate contractMetadataTemplate) { foreach (var kvPair in contractMetadataTemplate.MethodMetadataTemplates) { var sourceFunc = Replacement.ReplaceValueIntoReplacement(kvPair.Key, Replacement.This, contractAddress.GetFormatted()); foreach (var calledFunc in kvPair.Value.CallingSet) { if (!calledFunc.Contains(Replacement.This)) { Replacement.TryGetReplacementWithIndex(calledFunc, 0, out var memberReplacement); var referenceAddress = contractMetadataTemplate.ContractReferences[ Replacement.Value( memberReplacement)]; //FunctionMetadataTemplate itself ensure this value exist var globalCalledFunc = Replacement.ReplaceValueIntoReplacement(calledFunc, memberReplacement, referenceAddress.GetFormatted()); if (!callingGraph.ContainsVertex(globalCalledFunc)) { throw new FunctionMetadataException( "Unknow reference of the foreign target in edge <" + sourceFunc + "," + calledFunc + "> when trying to add contract " + contractMetadataTemplate.FullName + " into calling graph, consider the target function does not exist in the metadata"); } callingGraph.RemoveEdge(new Edge <string>(sourceFunc, globalCalledFunc)); } } } foreach (var localVertex in contractMetadataTemplate.LocalCallingGraph.Vertices) { var globalVertex = Replacement.ReplaceValueIntoReplacement(localVertex, Replacement.This, contractAddress.GetFormatted()); callingGraph.AddVertex(globalVertex); foreach (var outEdge in contractMetadataTemplate.LocalCallingGraph.OutEdges(localVertex)) { var toVertex = Replacement.ReplaceValueIntoReplacement(outEdge.Target, Replacement.This, contractAddress.GetFormatted()); callingGraph.RemoveEdge(new Edge <string>(globalVertex, toVertex)); callingGraph.RemoveVertex(globalVertex); callingGraph.RemoveVertex(toVertex); } callingGraph.RemoveVertex(globalVertex); } return(callingGraph); }