How to check if a key in a stream is updated.

+4 votes

Hi Team,
I am consuming data in a NodeJS service, in my use case I need to know about the keys which are updated in the last 10 days, how can I check if a Key is updated inside a Stream?

Thanks,

Shubham

asked Dec 21, 2022 by shubham-sap

1 Answer

0 votes

Assuming you want to do this for a particular key, you can use liststreamkeyitems with 1 for the count parameter. This will give you information about the last item, include its block's Unix-style timestamp in the blocktime field. If you pass true for verbose you will also see the time the node first saw the item, in the timereceived field. If these timestamps are within the last 10 days, you'll know that the key was updated in that period. If they are earlier (or there is no matching item) then you'll know that it was not updated in that period.

answered Dec 21, 2022 by MultiChain
Is there a way to apply any filter so that I can get the list of updated keys?
I'm afraid not, filters are for accepting/rejecting transactions/data, not analyzing the data that is there. But if you don't want to query keys individually using liststreamkeyitems, you have a few other options:

1) liststreamblockitems passing in a timestamp range like {"starttime":...,"endtime":...} in the second parameter. This will return a list of all items in the specified time range which you can then iterate over in your application to find the list of keys.

2) Use the walletnotify runtime parameter to trigger a script every time a transaction arrives which relates to an address in the wallet or a subscribed asset or stream. Your script maintains this list of recently updated keys.

3) Use a database feed (requires MultiChain Enterprise) to keep an external database synchronized with the content of a stream. This has support for PostgreSQL, MySQL/MariaDB and MongoDB out of the box and can be adapted for other database with some coding. See: https://github.com/MultiChain/multichain-feed-adapter
Thank you! this is great!
...