Пример #1
0
        public static IEnumerable <GeneratedEventMetadata> Parse(string contractName, string @namespace, SolcNet.DataDescription.Output.Contract contract)
        {
            foreach (var item in contract.Abi)
            {
                if (item.Type == AbiType.Event)
                {
                    // Check if this event name is overloaded (duplicate events with same name but different types).
                    var isOverloaded = contract.Abi
                                       .Where(i => i.Type == AbiType.Event)
                                       .Where(i => i.Name == item.Name)
                                       .Where(i => !ReferenceEquals(i, item))
                                       .Any();

                    string eventName;

                    if (isOverloaded)
                    {
                        string GetInputTypeName(string type)
                        {
                            // Format an array type def into name without symbols,
                            // supporting dynamic and fixed sized types such as:
                            // uint32[5][7][9] -> uint32Array5Array7Array9
                            // uint32[5][][9] -> uint32Array5ArrayArray9
                            // TODO: there is probably a regex to do this better.
                            return(type
                                   .Replace("[]", "Array", StringComparison.Ordinal)
                                   .Trim('[', ']')
                                   .Replace("[", "Array", StringComparison.Ordinal)
                                   .Replace("]", string.Empty, StringComparison.Ordinal));
                        }

                        // If the event is overloaded, append the event data types to the name.
                        eventName = item.Name + "_" + string.Join("_", item.Inputs.Select(i => GetInputTypeName(i.Type)));
                    }
                    else
                    {
                        eventName = ReservedKeywords.EscapeIdentifier(item.Name);
                    }

                    string eventSignatureHash = AbiSignature.GetSignatureHash(item);
                    yield return(new GeneratedEventMetadata
                    {
                        AbiItem = item,
                        EventSignatureHash = eventSignatureHash,
                        ClrTypeName = eventName,
                        ClrTypeFullName = $"{@namespace}.{contractName}.{eventName}",
                        IndexedArgsCounts = item.Inputs.Count(a => a.Indexed.GetValueOrDefault()),
                    });
                }
            }
        }
Пример #2
0
 public static IEnumerable <GeneratedEventMetadata> Parse(string contractName, string @namespace, SolcNet.DataDescription.Output.Contract contract)
 {
     foreach (var item in contract.Abi)
     {
         if (item.Type == AbiType.Event)
         {
             string eventSignatureHash = AbiSignature.GetSignatureHash(item);
             yield return(new GeneratedEventMetadata
             {
                 EventSignatureHash = eventSignatureHash,
                 EventClrTypeName = $"{@namespace}.{contractName}.{item.Name}",
                 IndexedArgsCounts = item.Inputs.Count(a => a.Indexed.GetValueOrDefault())
             });
         }
     }
 }