harmony-one / sdk

Javascript SDK of Harmony protocol.
MIT License
92 stars 43 forks source link

Event subscription doesn't respect the event topics. #36

Open kraikov opened 4 years ago

kraikov commented 4 years ago

After calling a single function that emits a single event, all event subscriptions are emitting in the SDK.

For example: If I call a function newContract that emits a single event (NewContract) and I've subscribed for NewContract and Withdraw events, both event handlers are invoked for the newContract call.

        this.contract.events
            .NewContract()
            .on('data', (event) => {
                console.log(event);
            })
            .on('error', console.error);

        this.contract.events
            .Withdraw()
            .on('data', (event) => {
                console.log(event);
            })
            .on('error', console.error);
kraikov commented 4 years ago

This also breaks the SDK, because the decoder cannot decode the data. E.g. the decoder cannot decode the data for NewContract event when the Withdraw event data comes and vice versa.

image

gupadhyaya commented 4 years ago

@kraikov Interesting. This should have worked correctly, as decoding is based on the event format specified in the abi. Let me take a look. Thanks.

kraikov commented 4 years ago

Okay. Would be nice if there is a way to subscribe to all events or by given topics. I don't know how events are handled internally, but this could save network bandwidth.