stream filters with dynamic configuration

+1 vote
Hi,

when using stream filters is it possible to somehow access dynamically some kind of configuration and with that do the validation in the filter?

e.g. JSON configuration to validate items published to itemstream is stored in a configurationstream. Can this be somehow accessed in the streamfilter coding or how can this be solved? Is there another way to write dynamic stream filters?

Thanks!
asked Feb 15, 2019 by ironmanager

1 Answer

0 votes

First it would be very interesting to know the use case for this (in technical terms, no need to share the application information), to see how it could best be covered in future. In particular, who is able to change this configuration, and what kind of information does it contain?

Anyway for now there is no neat solution for this kind of need. But there are a couple of workarounds where you can have global state which is tracked by every node, and accessible for reading from a stream callback:

  • For simple boolean configurations, you can grant/revoke a custom permission (high1, etc...) to a particular address and check that permission in the filter using verifypermission.
  • For general JSON configurations, create an asset which is open for reissuance, and use issuemore to update that asset's metadata. This metadata will be accessible in the filter using getassetinfo. You probably don't want to use this for metadata that changes more than (say) 100 times in total, because of the time it will take to build the callback response.
answered Feb 18, 2019 by MultiChain
For example I write into a stream some JSON data which I want to validate
e.g.

{
 name:"John",
 birthday :"01.01.1980"
 items: [{"Product1":"xy"},{"Product2":"z"}]
}

and I want to validate the items with metadata that is stored somwhere else e.g.. in another stream or config file or database.

e.g. validate birthday
or name should be 10 letters at least and in other cases/region/countries etc. 20 letters  etc.
items should have at least 3 items but for another Name/Customer/Region/country etc. it should have more

metadata e.g:

{
id:"germany",
namelength: 10,
itemcount: 3,
birthdayformat: "dd.mm.yyyy"
},
{
id:"us",
namelength: 20,
itemcount: 5,
birthdayformat: "mm.dd.yyyy"
}
Is it expected that these rules will change over time, and if so how frequently?
thanks for your fast reply. I think they will be changed for every new customer/address who gets access to the node and stream.
I thought about storing the validation info into another stream with a customer ID and then getting that config for that ID. So here the config changes but not that often.
Another idea would be to have a config only stored initially in a stream when starting a new multichain network which then won't change and other customers can read it.
So if the configuration doesn't change, it can just be hard-coded into the stream filter as a variable. It will then be easily readable by any user using the getfiltercode command.

If the configuration does change, your best bet is probably the issuemore workaround suggested above. It's not pretty, and it will start to slow down after many changes, but it should work fine. Be sure to call getassetinfo from the filter with verbose=true, and to get the "details" from the last issuance in the list.
I should add that we're thinking about a better solution for this scenario in future.
thanks! It would be great if there is something in the future
...