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

Indexed string in event cannot be parsed #57

Closed
greenkiller opened this issue Jun 29, 2016 · 10 comments
Closed

Indexed string in event cannot be parsed #57

greenkiller opened this issue Jun 29, 2016 · 10 comments
Labels

Comments

@greenkiller
Copy link

greenkiller commented Jun 29, 2016

Hi,

I deployed a straight forward smart contract as below and used GetAllChanges to get all events from block 0. GetAllChanges functions throws overflow exception when I tried to get the MultipliedLog event :
Value was either too large or too small for an Int32

My testing shows that it happens when I put a "indexed" keyword after a string. Is it expected?
event Multiplied(uint indexed a, uint indexed result, string hello);
event MultipliedLog(uint indexed a, address indexed sender, string indexed hello);

@juanfranblanco
Copy link
Member

juanfranblanco commented Jun 29, 2016

Thanks for the clarification... can you post your Event DTO?

@juanfranblanco
Copy link
Member

Also please raise another issue if it is changed :) (obviously not now)

@greenkiller
Copy link
Author

greenkiller commented Jun 30, 2016

Hi Juan,

Here is the DTO for them. Thanks.

public class EventMultipliedSenderLog
{
    [Nethereum.ABI.FunctionEncoding.Attributes.Parameter("uint", "a", 1, true)]
    public int A { get; set; }

    [Nethereum.ABI.FunctionEncoding.Attributes.Parameter("address", "sender", 2, true)]
    public string Sender { get; set; }

    [Nethereum.ABI.FunctionEncoding.Attributes.Parameter("string", "hello", 3, true)]
    public string Hello { get; set; }
}

public class EventMultiplied
{
    [Nethereum.ABI.FunctionEncoding.Attributes.Parameter("uint", "a", 1, true)]
    public int A { get; set; }

    [Nethereum.ABI.FunctionEncoding.Attributes.Parameter("uint", "result", 2, true)]
    public int Result { get; set; }

    [Nethereum.ABI.FunctionEncoding.Attributes.Parameter("string", "hello", 3, false)]
    public string Hello { get; set; }
}

@greenkiller
Copy link
Author

greenkiller commented Jun 30, 2016

The C# code to get the events:

            var multipliedEvent = contract.GetEvent("MultipliedLog");
            var filterAll = await multipliedEvent.CreateFilterAsync(new Nethereum.RPC.Eth.DTOs.BlockParameter(0));
            var eventLogsAll = await multipliedEvent.GetAllChanges<EventMultiplied2>(filterAll);

Event Multiplied (with DTO EventMultiplied) works well. The only difference I can find is the "indexed" string.

@juanfranblanco
Copy link
Member

Short story, retrieving the indexed values for dynamic types (strings, arrays) is not supported.
Long story:
The topics for indexed types if dynamics are stored as the SHA3 Keccak value (so they can be indexed and searched by matching the value).
Work around:
Use a bytes32, or don't index strings if you just want the data

@juanfranblanco
Copy link
Member

So for example if you look at the index topic for "Hello world" it retrieves ed6c11b0b5b808960df26f5bfc471d04c1995b0ffd2055925ad1be28d6baadfd

@juanfranblanco
Copy link
Member

Keeping it open as I need to validate the data part

@greenkiller
Copy link
Author

I see. Thanks.

@juanfranblanco
Copy link
Member

juanfranblanco commented Jun 30, 2016

I have just pushed a fix which will allow to have indexed dynamic types as part of the Event DTO, mainly they will store the sha3 keccak string. This will prevent an error to be thrown, when decoding.

A further solution for your problem if you want to have the index and value of the string will be to have 2 event parameters, 1 for the index and another for the value.

@greenkiller
Copy link
Author

Thanks for the prompt solution Juan!

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

No branches or pull requests

2 participants