public static string GetEntrySignature(ABI.Types.Entry entry) { string signature = entry.Name + "("; StringBuilder builder = new StringBuilder(); foreach (ABI.Types.Entry.Types.Param param in entry.Inputs) { if (builder.Length > 0) { builder.Append(","); } builder.Append(param.Type); } signature += builder.ToString() + ")"; return(signature); }
private static bool IsConstant(ABI abi, byte[] selector) { bool result = false; if (selector == null || selector.Length != 4 || abi.Entrys.Count == 0) { return(false); } for (int i = 0; i < abi.Entrys.Count; i++) { ABI.Types.Entry entry = abi.Entrys[i]; if (entry.Type != ABI.Types.Entry.Types.EntryType.Function) { continue; } int input_count = entry.Inputs.Count; StringBuilder sb = new StringBuilder(); sb.Append(entry.Name); sb.Append("("); for (int k = 0; k < input_count; k++) { var param = entry.Inputs[k]; sb.Append(param.Type); if (k + 1 < input_count) { sb.Append(","); } } sb.Append(")"); byte[] func_selector = new byte[4]; Array.Copy(Hash.SHA3(sb.ToString().ToBytes()), 0, func_selector, 0, 4); if (func_selector.SequenceEqual(selector)) { result = entry.Constant == true || entry.StateMutability.Equals(StateMutabilityType.View); } } return(result); }