public TopicFilterContainer() { var indexedParameters = PropertiesExtractor .GetPropertiesWithParameterAttribute(typeof(T)) .Select(p => new TopicFilter(p, p.GetCustomAttribute <ParameterAttribute>())) .Where(p => p.ParameterAttribute?.Parameter.Indexed ?? false) .OrderBy(p => p.ParameterAttribute.Order) .ToArray(); Empty = indexedParameters.Length == 0; Topic1 = indexedParameters.Length > 0 ? indexedParameters[0] : TopicFilter.Empty; Topic2 = indexedParameters.Length > 1 ? indexedParameters[1] : TopicFilter.Empty; Topic3 = indexedParameters.Length > 2 ? indexedParameters[2] : TopicFilter.Empty; Topics = new [] { Topic1, Topic2, Topic3 }; }
public T DecodeTopics <T>(object[] topics, string data) where T : new() { var type = typeof(T); var result = new T(); var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(type); var indexedProperties = properties.Where(x => x.GetCustomAttribute <ParameterAttribute>(true).Parameter.Indexed == true).OrderBy(x => x.GetCustomAttribute <ParameterAttribute>(true).Order).ToArray(); var dataProperties = properties.Where(x => x.GetCustomAttribute <ParameterAttribute>(true).Parameter.Indexed == false).OrderBy(x => x.GetCustomAttribute <ParameterAttribute>(true).Order).ToArray(); var topicNumber = 0; foreach (var topic in topics) { //skip the first one as it is the signature if (topicNumber > 0) { var property = indexedProperties[topicNumber - 1]; var attribute = property.GetCustomAttribute <ParameterAttribute>(true); //skip dynamic types as the topic value is the sha3 keccak if (!attribute.Parameter.ABIType.IsDynamic()) { result = DecodeAttributes(topic.ToString(), result, property); } else { if (property.PropertyType != typeof(string)) { throw new Exception( "Indexed Dynamic Types (string, arrays) value is the Keccak SHA3 of the value, the property type of " + property.Name + "should be a string"); } #if DOTNET35 property.SetValue(result, topic.ToString(), null); #else property.SetValue(result, topic.ToString()); #endif } } topicNumber = topicNumber + 1; } result = DecodeAttributes(data, result, dataProperties.ToArray()); return(result); }
public T DecodeFunctionInput <T>(T functionInput, string sha3Signature, string data) { sha3Signature = sha3Signature.EnsureHexPrefix(); data = data.EnsureHexPrefix(); if ((data == "0x") || (data == sha3Signature)) { return(functionInput); } if (data.StartsWith(sha3Signature)) { data = data.Substring(sha3Signature.Length); } var type = typeof(T); var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(type); DecodeAttributes(data, functionInput, properties.ToArray()); return(functionInput); }
public T DecodeFunctionOutput <T>(T functionOutputResult, string output) { if (output == "0x") { return(functionOutputResult); } var type = typeof(T); var function = FunctionOutputAttribute.GetAttribute <T>(); if (function == null) { throw new ArgumentException("Generic Type should have a Function Ouput Attribute"); } var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(type); DecodeAttributes(output, functionOutputResult, properties.ToArray()); return(functionOutputResult); }
public T DecodeFunctionOutput <T>(T functionOutputResult, string output) { if (output == "0x") { return(functionOutputResult); } var type = typeof(T); var function = FunctionOutputAttribute.GetAttribute <T>(); if (function == null) { throw new ArgumentException($"Unable to decode to '{typeof(T).Name}' because the type does not apply attribute '[{nameof(FunctionOutputAttribute)}]'."); } var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(type); DecodeAttributes(output, functionOutputResult, properties.ToArray()); return(functionOutputResult); }
public T DecodeConstructorParameters <T>(T deploymentObject, string data) { var swarmExtractor = new ByteCodeSwarmExtractor(); if (swarmExtractor.HasSwarmAddress(data)) { return(DecodeConstructorParameters(deploymentObject, swarmExtractor.GetByteCodeIncludingSwarmAddressPart(data), data)); } else { var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(typeof(T)); if (properties.Any()) { throw new Exception( "Data supplied does not include a swarm address, to locate the constructor parameters"); } else { return(deploymentObject); } } }
public T DecodeConstructorParameters <T>(T deploymentObject, string deploymentByteCode, string data) { if (!deploymentByteCode.StartsWith("0x")) { deploymentByteCode = "0x" + deploymentByteCode; } if (!data.StartsWith("0x")) { data = "0x" + data; } if ((data == "0x") || (data == deploymentByteCode)) { return(deploymentObject); } if (data.StartsWith(deploymentByteCode)) { data = data.Substring(deploymentByteCode.Length); } var type = typeof(T); var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(type); return(DecodeAttributes <T>(data, deploymentObject, properties.ToArray())); }
public List <ParameterOutputProperty> GetParameterOutputsFromAttributes(Type type) { var properties = PropertiesExtractor.GetPropertiesWithParameterAttribute(type); return(GetParameterOutputsFromAttributes(properties.ToArray())); }