How to deploy Smart filter code to Multichain ?

+2 votes

Dear Team,I have read all documentation regarding smart filter. I have read all posts but i am still not able to deploy my code to multichain.

This is my code 

function filterstreamitem() {

    var item = getfilterstreamitem();

 

    if (item.format != "json")

        return "Only JSON items are allowed";

 

    var json = item.data.json;

 

    if ((!json.hasOwnProperty("PersonName")) || (json.PersonName.length < 2))

        return "Item requires a PersonName";

    if ((!json.hasOwnProperty("PersonCnic")) || (json.PersonCnic.length != 2))

        return "Item requires a valid Person Cnic";

 

}

I have tried everything . i am on windows. My command is multichain-cli chain1 create streamfilter  filter1 "{}" 'code'   . I have tried one line with single quotes but my code is not being deployed. Each time getting errors. here is my stream data.

"data" : {
            "json" : {
                "_id" : "5ec77c6308108850902511f2",
                "PersonName" : "Testing prototype",
                "PersonCnic" : "3310062212345",
                "Hash" : "fe540724937edbcbd170d39d7a6ee70e9d429f2d"
            }
        },

 

Simple function. Please tell me exact how to run filter

asked Jun 7, 2020 by Huzaifa

1 Answer

0 votes

Your issue is simply with escaping on the Windows command line. You need to use double quotes ("") around parameters to multichain-cli which aren't a single word, and replace any " inside those parameters with \"

So on Windows an example would be:

multichain-cli chain1 create streamfilter  filter1 "{}" "function filterstreamitem() { return \"Reject all items\"; }"

answered Jun 9, 2020 by MultiChain
...