vechain / vechain-sdk-js

The official JavaScript SDK for VeChain.
19 stars 6 forks source link

🐛 [BUG] - filterEventLogs no longer supports address filters #968

Closed ifavo closed 3 weeks ago

ifavo commented 3 weeks ago

Description

With the changes introduced in https://github.com/vechain/vechain-sdk-js/issues/774 the topicHash became a mandatory argument for filterEventLogs.

Accessing all logs for certain addresses is no longer possible.

Reproduction URL

No response

Reproduction steps

This snippet worked before the change:

import { ThorClient } from '@vechain/sdk-network';
import { abi } from '@vechain/sdk-core';
const thor = ThorClient.fromUrl('https://mainnet.vechain.org');

// access logs for a contract
const logs = await thor.logs.filterEventLogs({
  options: {
    offset: 0,
    limit: 3,
  },
  criteriaSet: [
    {
      address: '0x0000000000000000000000000000456e65726779',
    },
  ],
  order: 'asc',
});
console.log(logs);

After the change with the modified argument fails:

import { ThorClient } from '@vechain/sdk-network';
import { abi } from '@vechain/sdk-core';
const thor = ThorClient.fromUrl('https://mainnet.vechain.org');

// access logs for a contract
const logs = await thor.logs.filterEventLogs({
  options: {
    offset: 0,
    limit: 3,
  },
  criteriaSet: [
    {
      criteria: {
        address: '0x0000000000000000000000000000456e65726779',
      },
    },
  ],
  order: 'asc',
});
console.log(logs);

it now fails with:

Error: Cannot read properties of undefined (reading 'topicHash')

Screenshots

![DESCRIPTION](LINK.png)

Logs

No response

OS

No response

ifavo commented 3 weeks ago

Looking at the code, I believe the issue might be this segment:

https://github.com/vechain/vechain-sdk-js/blob/90aa6236f2860256c33143ab442c009b65889fcc/packages/network/src/thor-client/logs/logs-module.ts#L78-L94

It looks like its checking for fragments not being nullish, but its always an array of undefined because of the map for the criterias:

https://github.com/vechain/vechain-sdk-js/blob/90aa6236f2860256c33143ab442c009b65889fcc/packages/network/src/thor-client/logs/logs-module.ts#L55-L57

ifavo commented 3 weeks ago

I see that the function is now called filterRawEventLogs – sorry for the confusion. May I suggest to document such name changes either in the PR or the release notes?

I checked PR, Release notes and issue comments and was unable to find that information.