private static byte[] EncodeData <T>(T structure) { byte[] result = new byte[0]; byte[] part = null; foreach (var prop in structure.GetMemberProperties()) { // TODO: Support array types object val = prop.Item1.GetValue(structure); string memberType = prop.Item2.Type; PropertyInfo propInfo = prop.Item1; if (memberType == "address") { if (!(val is string)) { throw new MemberTypeException(propInfo.Name, memberType, propInfo.PropertyType); } part = new AddressTypeEncoder().Encode(val); } else if (memberType == "bytes") { if (!(val is byte[] value)) { throw new MemberTypeException(propInfo.Name, memberType, propInfo.PropertyType); } part = _keccak.CalculateHash(value); } else if (memberType == "string") { if (!(val is string str)) { throw new MemberTypeException(propInfo.Name, memberType, propInfo.PropertyType); } part = _keccak.CalculateHash(Encoding.UTF8.GetBytes(str)); } else if (memberType == "bool") { if (!(val is bool)) { throw new MemberTypeException(propInfo.Name, memberType, propInfo.PropertyType); } part = new BoolTypeEncoder().Encode(val); } else if (Util.IsValidIntegerAbiType(memberType, out int intSize, out bool signed)) { if (!Util.IsNumber(val)) { throw new MemberTypeException(propInfo.Name, memberType, propInfo.PropertyType); } part = new IntTypeEncoder(signed, (uint)intSize).Encode(val); }
public AddressType() : base("address") { //this will need to be only a string type one, converting to hex Decoder = new AddressTypeDecoder(); Encoder = new AddressTypeEncoder(); }