Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization error on multiple types #64

Open
alexhaloETH opened this issue Aug 23, 2024 · 1 comment
Open

Deserialization error on multiple types #64

alexhaloETH opened this issue Aug 23, 2024 · 1 comment

Comments

@alexhaloETH
Copy link

Currently there is an issue with deserializing u128 and structs

U128
There are currently two way to temporeraly get around this issue

  1. change the line 130 in the model.cs to "u128" => new FieldElement(value.value.ToObject()), and make all the u128 in the models into fieldelements and it will save all the u128 into hex (this is what i have done)

  2. create a fucntion such as
    ` public static BigInteger HexToBigInteger(string hexString)
    {
    if (hexString.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
    {
    hexString = hexString.Substring(2);
    }

     hexString = hexString.TrimStart('0');
     byte[] bytes = new byte[hexString.Length / 2 + hexString.Length % 2];
     for (int index = 0; index < bytes.Length; index++)
     {
         string byteValue = hexString.Length % 2 != 0 && index == 0
             ? hexString.Substring(0, 1)
             : hexString.Substring(index * 2 - (hexString.Length % 2 == 0 ? 0 : 1), 2);
    
         bytes[bytes.Length - index - 1] = Convert.ToByte(byteValue, 16);
     }
    
     return new BigInteger(bytes.Concat(new byte[] { 0 }).ToArray());
    

    }`
    to turn the hex given to a bigint (havent tried this yet)

STRUCTS

Structs in the function HandleField get passed empty, for example for this code here

` else if (ty is Model.Struct struct_)
{
var instance = Activator.CreateInstance(type);
var fields = type.GetFields();

            foreach (var field in fields)
            {
                Debug.Log($"Field: {field.Name}");  //attack
                Debug.Log($"Field type: {field.FieldType}"); //System.Byte
            }

            Debug.Log("printing the members:");
            foreach (var member in struct_.members)
            {
                Debug.Log($"Member: {member.Key}"); //id
                Debug.Log($"Member type: {member.Value}"); //System.Byte
            }

            foreach (var field in fields)
            {
                field.SetValue(instance, HandleField(field.FieldType, struct_.members[field.Name]));
            }

            return instance;
        }`

the first loop would print the correct names but the second one is empty therefore giving a dict not found error,
Currently i have no fix for this so i have just added a simple check before starting the function

if (member is Model.Struct) { continue; }

@ScottyDavies
Copy link

Hello @alexhaloETH Please can you assign this task to me so I can start working on it immediately?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants