Smart filters: initiate transaction on certain condition in stream

0 votes
Hi,

I was playing around with the smart filter function and was wondering about this scanario:
Node 1 pulishes to a stream certain values, like energy meter data:
{
    "energy": 1000
}

is it possible to craft a filter whoch checks if the energy value is over a certain value and create a transaction from Node1 to Node2? Would it be a transaction or a stream filter, anyway?

something like
function filtertransaction()
{
    var item=getfilterstreamitem();

    var json=item.data.json;

    if (json.energy > 1000)
        // check if there are enough funds
        // if yes, create transaction
        return "Transaction from address XX to YY was successful";
}

Or do I have a complete misunderstanding here? Based on this question I am not completly sure: https://www.multichain.com/qa/26462/add-balance-to-a-especific-address-using-smart-filters

Thanks a lot in advance.

edit: the smart filter is working. I tested it with values smaller and bigger than 1000 and if smaller than 1000 adding an entry to the stream is refused. Now the question is, if I can craft a transaction for when the condition gets true?
asked 5 days ago by bbking
edited 5 days ago by bbking

1 Answer

0 votes

Smart filters are used to constrain/validate transactions or stream items, but they cannot initiate transactions.

So in your case you could use the smart filter to validate the stream items, but you would still need a separate external process to initiate the publishing of those items. You can either use polling to monitor the stream for the event you're waiting for, or take a look at the walletnotify runtime parameter.

answered 5 days ago by MultiChain
Thanks for clarifying this. Maybe I misplaced the term "Smart filter" with "Smart contract" - as I understand, "Smart contracts" can do that. Maybe some real world examples right next to the github code examples would be helpful to understand the possible use cases for some features of MultiChain.
It is so powerful that it requires a lot of imagination to think up even just a few usecases. The SAP usecase is very helpful though!
...