liststreamkeys in filtercode.

+2 votes

I'm trying to implement my own filter code. In which I want to use liststreamkeyitems as function. since it needs two parameters stringName and keyName. So I tried using it as, liststreamkeyitems("stream1","key1"). Key1 is the key preset in stream1. So while executing this command, it is showing me error as lisstreamkeyitems is undefined. So to know the details of error I tried using teststreamfilters but there also I'm getting some syntacterror .

So I would like to request you if you could take any demo example and show me how to use teststreamfilters command and please also let me know the way I'm using liststreamkeyitems("stream1","key1"),  is right or not?

Testfilterstream executed command:

teststreamfilter "function filterstreamitem(){ var item= getfilterstreamitem(); if(item.keys.length<2) return 'At least two keys required';}" "3e0849da9671563be8d71fccf5f33b1c9aeacd681a354fc98350c874e867136c" 

O/P error:

Error parsing JSON:function filterstreamitem(){ var item= getfilterstreamitem(); if(item.keys.length<2) return 'At least two keys required';}

Since I was getting above error I tried using runstreamfilter,

runstreamfilter df1 "3e0849da9671563be8d71fccf5f33b1c9aeacd681a354fc98350c874e867136c"

But the output i got is,

Stream input is not found in this transaction

Why I'm getting above error is it bcz i have not passed vout in above line but how can i even pass vout i have not created transaction i have created stream1, which is already created and all i have is its transaction id. In stream how can we get vout?

Check the df1 code:

function filterstreamitem() { var item = getfilterstreamitem(); var keyinfo=liststreamkeyitems(item,"key1");var data=keyinfo.data;if(data>50) return "successful";else return "unsuccessful";}

did I use liststreamkeyitems function properly??

 

 

 

asked Apr 15, 2020 by user123

1 Answer

0 votes
There are two things here. First, you cannot currently use liststreamkeyitems in a stream filter, though we plan to change this in future. This page lists the callback functions you can currently use in filters:

https://www.multichain.com/developers/smart-filters/

Second, assuming you're using the command line on Linux, you need to put the filter code in single quotes. See the examples at the end of that same page.
answered Apr 17, 2020 by MultiChain
...