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

Golang events are not parsed at all. #45

Open
coinsandsteeldev opened this issue Aug 24, 2018 · 7 comments
Open

Golang events are not parsed at all. #45

coinsandsteeldev opened this issue Aug 24, 2018 · 7 comments

Comments

@coinsandsteeldev
Copy link

This is Contract.cs method which is used to pre-process event before emitting it to listeners.

protected override ChainEventArgs TransformChainEvent(RawChainEventArgs e) {
    string jsonRpcEventString = Encoding.UTF8.GetString(e.Data);
    JsonRpcEvent jsonRpcEvent = JsonConvert.DeserializeObject<JsonRpcEvent>(jsonRpcEventString);
    byte[] eventData = Encoding.UTF8.GetBytes(jsonRpcEvent.Data);

    return new ChainEventArgs(
         e.ContractAddress,
         e.CallerAddress,
         e.BlockHeight,
         eventData,
         jsonRpcEvent.Method
    );
}

When i emit event in Go either using ctx.Emit() or ctx.EmitTopics() i have same result:

jsonRpcEventString has serialized json from Emit for instance

type AccountCreatedEvt struct {
	Test  string
	Test2 int
}

Will result as {"Test": "test", "Test2": 1488}. So the next line fails to deserialize
JsonRpcEvent jsonRpcEvent = JsonConvert.DeserializeObject<JsonRpcEvent>(jsonRpcEventString);

Resulting in converting null to byte[]

I wonder whether it is problem of Loom Node emitting event in the wrong format or something else.

@coinsandsteeldev
Copy link
Author

coinsandsteeldev commented Aug 24, 2018

I'm constrained by this issue a lot. And i think this is huge problem right now.

@mattkanwisher
Copy link
Contributor

@ZimM-LostPolygon will take a look at this, should have a new release this week

@coinsandsteeldev
Copy link
Author

It seems like we can emit anything we want in Go contract. And i think we need better approach to TransformChainEvent, i would make it injection, with some standard one by default. Right now if i want to have pure protobuf events i need to open source code of SDK and change it. So i would propose this simple change which will make life easier for future generations :)

@ZimM-LostPolygon
Copy link
Contributor

@coinsandsteeldev Not exactly sure I understand the issue. The first argument of ctx.Emit() or ctx.EmitTopics() goes into JsonRpcEvent.Data. And sure, you can put pretty much anything there. But you say that it replaces the complete RawChainEventArgs.Data?..

@coinsandsteeldev
Copy link
Author

coinsandsteeldev commented Nov 16, 2018

@ZimM-LostPolygon No it doesn't. It fails to parse JsonRpcEvent at all.

@coinsandsteeldev
Copy link
Author

Of course if you follow JsonRpcEvent layout it will be ok, but i don't think it is a way to go. It is fixed easily, and it is done in my own version of your SDK.

@ZimM-LostPolygon
Copy link
Contributor

Yep, I can confirm there is an issue. Meanwhile, you probably should subclass Contract and override TransformChainEvent.

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

3 participants