tronprotocol / tron-grid

10 stars 13 forks source link

'since' parameter in events fetching is not working #6

Closed gkonst closed 5 years ago

gkonst commented 5 years ago

According to this doc https://developers.tron.network/docs/testnet-protocol parameter 'since' in https://api.trongrid.io/event/contract/ request should limit the response to only events with 'block_timestamp' higher than 'since' value. But currently it's not working, for example for this request https://api.trongrid.io/event/contract/THCS2G33reng9TyGHARDQHGPAbCkP9xg5q?since=1561779730000, I receive events which have 'block_timestamp' value lower than 'since' value. image Also logic of 'since' argument is not predictable at all - for example if I give too old 'since' value I'll receive empty response.

As a result we are not able to fetch only fresh events - we always receive all events since the beginning and we have to fetch several pages and filter out already processed events in our app and this takes significant amount of time.

shenyongri110 commented 5 years ago

@gkonst Thanks for your comment. Since we support ascending and descending sort right now, so we update some parameters based on original request. Here are some updated instruction and example, please take a look. For your case, you can use ascending sort to get higher timestamp data.

1. api.trongrid.io/event/contract params update instruction:

since=1551779730000 data start from specific timestamp

sort: by default is descending or pass "sort=-block_timestamp" (descending) sort=block_timestamp (ascending)

2. examples 1)if not pass sort param https://api.trongrid.io/event/contract/THCS2G33reng9TyGHARDQHGPAbCkP9xg5q?since=1551779730000 data return (Z-A)

2)pass sort=-block_timestamp https://api.trongrid.io/event/contract/THCS2G33reng9TyGHARDQHGPAbCkP9xg5q?since=1551779730000&sort=-block_timestamp data return (Z-A) and start from since timestamp

3)pass sort=block_timestamp https://api.trongrid.io/event/contract/THCS2G33reng9TyGHARDQHGPAbCkP9xg5q?since=155177320000&sort=block_timestamp data return (A-Z) and start from since timestamp

4)(not pass since or since=0) and not sort https://api.trongrid.io/event/contract/THCS2G33reng9TyGHARDQHGPAbCkP9xg5q data from latest event and order by (Z-A)

tycm4109 commented 5 years ago

@gkonst Hi Konstantin, thank you for bringing this to our notice. The developers hub has now been updated to have greater clarification regarding the value passed in: https://developers.tron.network/docs/testnet-protocol. As my colleague @shenyongri110 mentioned, in your example, the call would return all events occurring before (and at) your specified timestamp. Thanks.

gkonst commented 5 years ago

Thanks @tmao1129 and @shenyongri110 ! Now it's clear, but name 'since' looks confusing for me in such interpretation as it by default means actually 'before'. Maybe it's better to rename it somehow to avoid confusion?

shenyongri110 commented 5 years ago

@gkonst Yes, we will discuss and see if it's necessary to change another name, because we need to consider all developers who have used 'since' for a while. But currently you can use either 'since' or 'fromTimestamp' if you think 'since' is confused. 'fromTimestamp' should also work as well.

gkonst commented 5 years ago

Ok, thanks!